ruby-plsql 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +30 -0
  3. data/.github/stale.yml +37 -0
  4. data/.rubocop.yml +153 -0
  5. data/.travis.yml +20 -6
  6. data/.travis/oracle/download.sh +9 -10
  7. data/.travis/oracle/install.sh +6 -6
  8. data/Gemfile +13 -9
  9. data/History.txt +26 -0
  10. data/README.md +9 -5
  11. data/Rakefile +31 -26
  12. data/VERSION +1 -1
  13. data/Vagrantfile +2 -2
  14. data/gemfiles/Gemfile.activerecord-5.0 +21 -0
  15. data/gemfiles/Gemfile.activerecord-5.1 +21 -0
  16. data/gemfiles/Gemfile.activerecord-5.2 +21 -0
  17. data/lib/plsql/connection.rb +16 -18
  18. data/lib/plsql/helpers.rb +1 -3
  19. data/lib/plsql/jdbc_connection.rb +66 -61
  20. data/lib/plsql/oci8_patches.rb +2 -2
  21. data/lib/plsql/oci_connection.rb +51 -69
  22. data/lib/plsql/package.rb +5 -8
  23. data/lib/plsql/procedure.rb +75 -78
  24. data/lib/plsql/procedure_call.rb +498 -501
  25. data/lib/plsql/schema.rb +95 -100
  26. data/lib/plsql/sequence.rb +10 -13
  27. data/lib/plsql/sql_statements.rb +9 -11
  28. data/lib/plsql/table.rb +59 -63
  29. data/lib/plsql/type.rb +71 -76
  30. data/lib/plsql/variable.rb +89 -94
  31. data/lib/plsql/version.rb +1 -1
  32. data/lib/plsql/view.rb +16 -19
  33. data/ruby-plsql.gemspec +41 -37
  34. data/spec/plsql/connection_spec.rb +67 -67
  35. data/spec/plsql/package_spec.rb +15 -15
  36. data/spec/plsql/procedure_spec.rb +286 -233
  37. data/spec/plsql/schema_spec.rb +22 -23
  38. data/spec/plsql/sequence_spec.rb +2 -2
  39. data/spec/plsql/sql_statements_spec.rb +5 -5
  40. data/spec/plsql/table_spec.rb +77 -77
  41. data/spec/plsql/type_spec.rb +23 -29
  42. data/spec/plsql/variable_spec.rb +59 -59
  43. data/spec/plsql/version_spec.rb +4 -4
  44. data/spec/plsql/view_spec.rb +42 -42
  45. data/spec/spec_helper.rb +37 -29
  46. data/spec/support/test_db.rb +12 -13
  47. metadata +44 -26
  48. data/.travis/oracle/LICENSE +0 -5
  49. data/.travis/oracle/README.md +0 -64
  50. data/.travis/oracle/download.js +0 -100
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.0
@@ -25,11 +25,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
25
25
  config.vm.provision :shell, inline: "mkdir -p /opt/oracle"
26
26
  config.vm.provision :shell, inline: "unzip -o -q -d /opt/oracle /vagrant/oracle-xe-11.2.0-1.0.x86_64.rpm.zip"
27
27
  config.vm.provision :shell, inline: "cd /opt/oracle/Disk1 && rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm"
28
- config.vm.provision :shell, inline: %q{sed -i -E "s/<value required>/oracle/" /opt/oracle/Disk1/response/xe.rsp}
28
+ config.vm.provision :shell, inline: 'sed -i -E "s/<value required>/oracle/" /opt/oracle/Disk1/response/xe.rsp'
29
29
  config.vm.provision :shell, inline: "/etc/init.d/oracle-xe configure responseFile=/opt/oracle/Disk1/response/xe.rsp >> /opt/oracle/XEsilentinstall.log"
30
30
  config.vm.provision :shell, inline: ". /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh"
31
31
  config.vm.provision :shell, inline: "touch /etc/profile.d/oracle_profile.sh && cat /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh >> /etc/profile.d/oracle_profile.sh"
32
- config.vm.provision :shell, inline: %q{sed -i -E "s/HOST = [^)]+/HOST = $HOSTNAME/g" /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora}
32
+ config.vm.provision :shell, inline: 'sed -i -E "s/HOST = [^)]+/HOST = $HOSTNAME/g" /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora'
33
33
  config.vm.provision :shell, inline: %q{sed -i -E "s/<ORACLE_BASE>/\/u01\/app\/oracle/" /u01/app/oracle/product/11.2.0/xe/dbs/init.ora}
34
34
 
35
35
  # Change password for Oracle user
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'juwelier', '~> 2.0'
5
+ gem 'rspec_junit_formatter'
6
+ end
7
+
8
+ group :test, :development do
9
+ gem 'rake', '>= 10.0'
10
+ gem 'rspec', '~> 3.1'
11
+
12
+ unless ENV['NO_ACTIVERECORD']
13
+ gem 'activerecord', '~> 5.0.0'
14
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.7.0'
15
+ gem 'simplecov', '>= 0'
16
+ end
17
+
18
+ platforms :ruby, :mswin, :mingw do
19
+ gem 'ruby-oci8', '~> 2.1'
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'juwelier', '~> 2.0'
5
+ gem 'rspec_junit_formatter'
6
+ end
7
+
8
+ group :test, :development do
9
+ gem 'rake', '>= 10.0'
10
+ gem 'rspec', '~> 3.1'
11
+
12
+ unless ENV['NO_ACTIVERECORD']
13
+ gem 'activerecord', '~> 5.1.0'
14
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.8.0'
15
+ gem 'simplecov', '>= 0'
16
+ end
17
+
18
+ platforms :ruby, :mswin, :mingw do
19
+ gem 'ruby-oci8', '~> 2.1'
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'juwelier', '~> 2.0'
5
+ gem 'rspec_junit_formatter'
6
+ end
7
+
8
+ group :test, :development do
9
+ gem 'rake', '>= 10.0'
10
+ gem 'rspec', '~> 3.1'
11
+
12
+ unless ENV['NO_ACTIVERECORD']
13
+ gem 'activerecord', '~> 5.2.0.beta'
14
+ gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0.beta'
15
+ gem 'simplecov', '>= 0'
16
+ end
17
+
18
+ platforms :ruby, :mswin, :mingw do
19
+ gem 'ruby-oci8', '~> 2.1'
20
+ end
21
+ end
@@ -25,14 +25,14 @@ module PLSQL
25
25
 
26
26
  def self.create_new(params) #:nodoc:
27
27
  conn = case driver_type
28
- when :oci
29
- OCIConnection.create_raw(params)
30
- when :jdbc
31
- JDBCConnection.create_raw(params)
32
- else
33
- raise ArgumentError, "Unknown raw driver"
28
+ when :oci
29
+ OCIConnection.create_raw(params)
30
+ when :jdbc
31
+ JDBCConnection.create_raw(params)
32
+ else
33
+ raise ArgumentError, "Unknown raw driver"
34
34
  end
35
- conn.set_time_zone(params[:time_zone]||ENV['ORA_SDTZ'])
35
+ conn.set_time_zone(params[:time_zone] || ENV["ORA_SDTZ"])
36
36
  conn
37
37
  end
38
38
 
@@ -66,7 +66,7 @@ module PLSQL
66
66
  def jdbc?
67
67
  @raw_driver == :jdbc
68
68
  end
69
-
69
+
70
70
  def logoff #:nodoc:
71
71
  # Rollback any uncommited transactions
72
72
  rollback
@@ -99,14 +99,14 @@ module PLSQL
99
99
  end
100
100
 
101
101
  def select_first(sql, *bindvars) #:nodoc:
102
- cursor = cursor_from_query(sql, bindvars, :prefetch_rows => 1)
102
+ cursor = cursor_from_query(sql, bindvars, prefetch_rows: 1)
103
103
  cursor.fetch
104
104
  ensure
105
105
  cursor.close rescue nil
106
106
  end
107
107
 
108
108
  def select_hash_first(sql, *bindvars) #:nodoc:
109
- cursor = cursor_from_query(sql, bindvars, :prefetch_rows => 1)
109
+ cursor = cursor_from_query(sql, bindvars, prefetch_rows: 1)
110
110
  cursor.fetch_hash
111
111
  ensure
112
112
  cursor.close rescue nil
@@ -183,7 +183,7 @@ module PLSQL
183
183
  # this implementation is overriden in OCI connection with faster native OCI method
184
184
  def describe_synonym(schema_name, synonym_name) #:nodoc:
185
185
  select_first(
186
- "SELECT table_owner, table_name FROM all_synonyms WHERE owner = :owner AND synonym_name = :synonym_name",
186
+ "SELECT table_owner, table_name FROM all_synonyms WHERE owner = :owner AND synonym_name = :synonym_name",
187
187
  schema_name.to_s.upcase, synonym_name.to_s.upcase)
188
188
  end
189
189
 
@@ -198,7 +198,7 @@ module PLSQL
198
198
  end
199
199
 
200
200
  # Set time zone
201
- def set_time_zone(time_zone=nil)
201
+ def set_time_zone(time_zone = nil)
202
202
  exec("alter session set time_zone = '#{time_zone}'") if time_zone
203
203
  end
204
204
 
@@ -207,12 +207,12 @@ module PLSQL
207
207
  select_first("SELECT SESSIONTIMEZONE FROM dual")[0]
208
208
  end
209
209
 
210
- RUBY_TEMP_TABLE_PREFIX = 'ruby_'
210
+ RUBY_TEMP_TABLE_PREFIX = "ruby_"
211
211
 
212
212
  # Drop all ruby temporary tables that are used for calling packages with table parameter types defined in packages
213
213
  def drop_all_ruby_temporary_tables
214
214
  select_all("SELECT table_name FROM user_tables WHERE temporary='Y' AND table_name LIKE :table_name",
215
- RUBY_TEMP_TABLE_PREFIX.upcase+'%').each do |row|
215
+ RUBY_TEMP_TABLE_PREFIX.upcase + "%").each do |row|
216
216
  exec "TRUNCATE TABLE #{row[0]}"
217
217
  exec "DROP TABLE #{row[0]}"
218
218
  end
@@ -221,12 +221,10 @@ module PLSQL
221
221
  # Drop ruby temporary tables created in current session that are used for calling packages with table parameter types defined in packages
222
222
  def drop_session_ruby_temporary_tables
223
223
  select_all("SELECT table_name FROM user_tables WHERE temporary='Y' AND table_name LIKE :table_name",
224
- RUBY_TEMP_TABLE_PREFIX.upcase+"#{session_id}_%").each do |row|
224
+ RUBY_TEMP_TABLE_PREFIX.upcase + "#{session_id}_%").each do |row|
225
225
  exec "TRUNCATE TABLE #{row[0]}"
226
226
  exec "DROP TABLE #{row[0]}"
227
227
  end
228
228
  end
229
-
230
229
  end
231
-
232
- end
230
+ end
@@ -1,9 +1,7 @@
1
1
  module PLSQL #:nodoc:
2
2
  module ArrayHelpers #:nodoc:
3
-
4
3
  def self.to_hash(keys, values) #:nodoc:
5
4
  (0...keys.size).inject({}) { |hash, i| hash[keys[i]] = values[i]; hash }
6
5
  end
7
-
8
6
  end
9
- end
7
+ end
@@ -5,21 +5,31 @@ begin
5
5
  # ojdbc6.jar or ojdbc5.jar file should be in JRUBY_HOME/lib or should be in ENV['PATH'] or load path
6
6
 
7
7
  java_version = java.lang.System.getProperty("java.version")
8
- ojdbc_jar = if java_version =~ /^1.5/
9
- "ojdbc5.jar"
10
- elsif java_version >= '1.6'
11
- "ojdbc6.jar"
8
+ ojdbc_jars = if java_version =~ /^1.5/
9
+ %w(ojdbc5.jar)
10
+ elsif java_version =~ /^1.6/
11
+ %w(ojdbc6.jar)
12
+ elsif java_version >= "1.7"
13
+ # Oracle 11g client ojdbc6.jar is also compatible with Java 1.7
14
+ # Oracle 12c client provides new ojdbc7.jar
15
+ %w(ojdbc7.jar ojdbc6.jar)
12
16
  else
13
- nil
17
+ []
14
18
  end
15
19
 
16
- unless ENV_JAVA['java.class.path'] =~ Regexp.new(ojdbc_jar)
20
+ if ENV_JAVA["java.class.path"] !~ Regexp.new(ojdbc_jars.join("|"))
17
21
  # On Unix environment variable should be PATH, on Windows it is sometimes Path
18
- env_path = (ENV["PATH"] || ENV["Path"] || '').split(/[:;]/)
22
+ env_path = (ENV["PATH"] || ENV["Path"] || "").split(File::PATH_SEPARATOR)
19
23
  # Look for JDBC driver at first in lib subdirectory (application specific JDBC file version)
20
24
  # then in Ruby load path and finally in environment PATH
21
- if ojdbc_jar_path = ['./lib'].concat($LOAD_PATH).concat(env_path).find{|d| File.exists?(File.join(d,ojdbc_jar))}
22
- require File.join(ojdbc_jar_path,ojdbc_jar)
25
+ ["./lib"].concat($LOAD_PATH).concat(env_path).detect do |dir|
26
+ # check any compatible JDBC driver in the priority order
27
+ ojdbc_jars.any? do |ojdbc_jar|
28
+ if File.exists?(file_path = File.join(dir, ojdbc_jar))
29
+ require file_path
30
+ true
31
+ end
32
+ end
23
33
  end
24
34
  end
25
35
 
@@ -32,15 +42,14 @@ begin
32
42
 
33
43
  rescue LoadError, NameError
34
44
  # JDBC driver is unavailable.
35
- raise LoadError, "ERROR: ruby-plsql could not load Oracle JDBC driver. Please install #{ojdbc_jar || "Oracle JDBC"} library."
45
+ raise LoadError, "ERROR: ruby-plsql could not load Oracle JDBC driver. Please install #{ojdbc_jars.empty? ? "Oracle JDBC" : ojdbc_jars.join(' or ') } library."
36
46
  end
37
47
 
38
48
  module PLSQL
39
49
  class JDBCConnection < Connection #:nodoc:
40
-
41
50
  def self.create_raw(params)
42
51
  database = params[:database]
43
- url = if ENV['TNS_ADMIN'] && database && !params[:host] && !params[:url]
52
+ url = if ENV["TNS_ADMIN"] && database && !params[:host] && !params[:url]
44
53
  "jdbc:oracle:thin:@#{database}"
45
54
  else
46
55
  database = ":#{database}" unless database.match(/^(\:|\/)/)
@@ -49,7 +58,7 @@ module PLSQL
49
58
  new(java.sql.DriverManager.getConnection(url, params[:username], params[:password]))
50
59
  end
51
60
 
52
- def set_time_zone(time_zone=nil)
61
+ def set_time_zone(time_zone = nil)
53
62
  raw_connection.setSessionTimeZone(time_zone) if time_zone
54
63
  end
55
64
 
@@ -90,7 +99,6 @@ module PLSQL
90
99
  end
91
100
 
92
101
  class CallableStatement #:nodoc:
93
-
94
102
  def initialize(conn, sql)
95
103
  @sql = sql
96
104
  @connection = conn
@@ -107,11 +115,11 @@ module PLSQL
107
115
  if metadata[:in_out] =~ /OUT/
108
116
  @out_types[arg] = type || ora_value.class
109
117
  @out_index[arg] = bind_param_index(arg)
110
- if ['TABLE','VARRAY','OBJECT','XMLTYPE'].include?(metadata[:data_type])
111
- @statement.registerOutParameter(@out_index[arg], @connection.get_java_sql_type(ora_value,type),
118
+ if ["TABLE", "VARRAY", "OBJECT", "XMLTYPE"].include?(metadata[:data_type])
119
+ @statement.registerOutParameter(@out_index[arg], @connection.get_java_sql_type(ora_value, type),
112
120
  metadata[:sql_type_name])
113
121
  else
114
- @statement.registerOutParameter(@out_index[arg],@connection.get_java_sql_type(ora_value,type))
122
+ @statement.registerOutParameter(@out_index[arg], @connection.get_java_sql_type(ora_value, type))
115
123
  end
116
124
  end
117
125
  end
@@ -130,11 +138,11 @@ module PLSQL
130
138
 
131
139
  private
132
140
 
133
- def bind_param_index(key)
134
- return key if key.kind_of? Integer
135
- key = ":#{key.to_s}" unless key.to_s =~ /^:/
136
- @params.index(key)+1
137
- end
141
+ def bind_param_index(key)
142
+ return key if key.kind_of? Integer
143
+ key = ":#{key.to_s}" unless key.to_s =~ /^:/
144
+ @params.index(key) + 1
145
+ end
138
146
  end
139
147
 
140
148
  class Cursor #:nodoc:
@@ -150,11 +158,11 @@ module PLSQL
150
158
  @column_count = @metadata.getColumnCount
151
159
  @column_type_names = [nil] # column numbering starts at 1
152
160
  (1..@column_count).each do |i|
153
- @column_type_names << {:type_name => @metadata.getColumnTypeName(i), :sql_type => @metadata.getColumnType(i)}
161
+ @column_type_names << { type_name: @metadata.getColumnTypeName(i), sql_type: @metadata.getColumnType(i) }
154
162
  end
155
163
  end
156
164
 
157
- def self.new_from_query(conn, sql, bindvars=[], options={})
165
+ def self.new_from_query(conn, sql, bindvars = [], options = {})
158
166
  stmt = conn.prepare_statement(sql, *bindvars)
159
167
  if prefetch_rows = options[:prefetch_rows]
160
168
  stmt.setRowPrefetch(prefetch_rows)
@@ -194,14 +202,14 @@ module PLSQL
194
202
  CallableStatement.new(self, sql)
195
203
  end
196
204
 
197
- def cursor_from_query(sql, bindvars=[], options={})
205
+ def cursor_from_query(sql, bindvars = [], options = {})
198
206
  Cursor.new_from_query(self, sql, bindvars, options)
199
207
  end
200
208
 
201
209
  def prepare_statement(sql, *bindvars)
202
210
  stmt = raw_connection.prepareStatement(sql)
203
211
  bindvars.each_with_index do |bv, i|
204
- set_bind_variable(stmt, i+1, ruby_value_to_ora_value(bv))
212
+ set_bind_variable(stmt, i + 1, ruby_value_to_ora_value(bv))
205
213
  end
206
214
  stmt
207
215
  end
@@ -209,7 +217,7 @@ module PLSQL
209
217
  def prepare_call(sql, *bindvars)
210
218
  stmt = raw_connection.prepareCall(sql)
211
219
  bindvars.each_with_index do |bv, i|
212
- set_bind_variable(stmt, i+1, bv)
220
+ set_bind_variable(stmt, i + 1, bv)
213
221
  end
214
222
  stmt
215
223
  end
@@ -240,7 +248,7 @@ module PLSQL
240
248
  java.sql.Types::NVARCHAR => String,
241
249
  java.sql.Types::LONGVARCHAR => String,
242
250
  java.sql.Types::NUMERIC => BigDecimal,
243
- java.sql.Types::INTEGER => Fixnum,
251
+ java.sql.Types::INTEGER => Integer,
244
252
  java.sql.Types::DATE => Time,
245
253
  java.sql.Types::TIMESTAMP => Time,
246
254
  Java::oracle.jdbc.OracleTypes::TIMESTAMPTZ => Time,
@@ -256,8 +264,8 @@ module PLSQL
256
264
  RUBY_CLASS_TO_SQL_TYPE[type || value.class] || java.sql.Types::VARCHAR
257
265
  end
258
266
 
259
- def set_bind_variable(stmt, i, value, type=nil, length=nil, metadata={})
260
- key = i.kind_of?(Integer) ? nil : i.to_s.gsub(':','')
267
+ def set_bind_variable(stmt, i, value, type = nil, length = nil, metadata = {})
268
+ key = i.kind_of?(Integer) ? nil : i.to_s.gsub(":", "")
261
269
  type_symbol = (!value.nil? && type ? type : value.class).to_s.to_sym
262
270
  case type_symbol
263
271
  when :Fixnum, :Bignum, :Integer
@@ -277,10 +285,10 @@ module PLSQL
277
285
  when :Time, :'Java::JavaSql::Timestamp'
278
286
  stmt.send("setTimestamp#{key && "AtName"}", key || i, value)
279
287
  when :NilClass
280
- if ['TABLE', 'VARRAY', 'OBJECT','XMLTYPE'].include?(metadata[:data_type])
288
+ if ["TABLE", "VARRAY", "OBJECT", "XMLTYPE"].include?(metadata[:data_type])
281
289
  stmt.send("setNull#{key && "AtName"}", key || i, get_java_sql_type(value, type),
282
290
  metadata[:sql_type_name])
283
- elsif metadata[:data_type] == 'REF CURSOR'
291
+ elsif metadata[:data_type] == "REF CURSOR"
284
292
  # TODO: cannot bind NULL value to cursor parameter, getting error
285
293
  # java.sql.SQLException: Unsupported feature: sqlType=-10
286
294
  # Currently do nothing and assume that NULL values will not be passed to IN parameters
@@ -309,7 +317,7 @@ module PLSQL
309
317
  stmt.getFloat(i)
310
318
  when :BigDecimal
311
319
  bd = stmt.getBigDecimal(i)
312
- bd && BigDecimal.new(bd.to_s)
320
+ bd && BigDecimal(bd.to_s)
313
321
  when :String
314
322
  stmt.getString(i)
315
323
  when :'Java::OracleSql::CLOB'
@@ -336,7 +344,6 @@ module PLSQL
336
344
  end
337
345
 
338
346
  def result_set_to_ruby_data_type(column_type, column_type_name)
339
-
340
347
  end
341
348
 
342
349
  def plsql_to_ruby_data_type(metadata)
@@ -351,7 +358,7 @@ module PLSQL
351
358
  when "NUMBER"
352
359
  [BigDecimal, nil]
353
360
  when "NATURAL", "NATURALN", "POSITIVE", "POSITIVEN", "SIGNTYPE", "SIMPLE_INTEGER", "PLS_INTEGER", "BINARY_INTEGER"
354
- [Fixnum, nil]
361
+ [Integer, nil]
355
362
  when "DATE"
356
363
  [DateTime, nil]
357
364
  when "TIMESTAMP", "TIMESTAMP WITH TIME ZONE", "TIMESTAMP WITH LOCAL TIME ZONE"
@@ -367,10 +374,10 @@ module PLSQL
367
374
  end
368
375
  end
369
376
 
370
- def ruby_value_to_ora_value(value, type=nil, metadata={})
377
+ def ruby_value_to_ora_value(value, type = nil, metadata = {})
371
378
  type ||= value.class
372
379
  case type.to_s.to_sym
373
- when :Fixnum
380
+ when :Integer
374
381
  value
375
382
  when :String
376
383
  value.to_s
@@ -419,9 +426,9 @@ module PLSQL
419
426
  elem_list = value.map do |elem|
420
427
  case elem_type
421
428
  when Java::oracle.jdbc.OracleTypes::ARRAY
422
- ruby_value_to_ora_value(elem, Java::OracleSql::ARRAY, :sql_type_name => elem_type_name)
429
+ ruby_value_to_ora_value(elem, Java::OracleSql::ARRAY, sql_type_name: elem_type_name)
423
430
  when Java::oracle.jdbc.OracleTypes::STRUCT
424
- ruby_value_to_ora_value(elem, Java::OracleSql::STRUCT, :sql_type_name => elem_type_name)
431
+ ruby_value_to_ora_value(elem, Java::OracleSql::STRUCT, sql_type_name: elem_type_name)
425
432
  else
426
433
  ruby_value_to_ora_value(elem)
427
434
  end
@@ -435,7 +442,7 @@ module PLSQL
435
442
  struct_metadata = descriptor.getMetaData
436
443
  struct_fields = (1..descriptor.getLength).inject({}) do |hash, i|
437
444
  hash[struct_metadata.getColumnName(i).downcase.to_sym] =
438
- {:type => struct_metadata.getColumnType(i), :type_name => struct_metadata.getColumnTypeName(i)}
445
+ { type: struct_metadata.getColumnType(i), type_name: struct_metadata.getColumnTypeName(i) }
439
446
  hash
440
447
  end
441
448
  object_attrs = java.util.HashMap.new
@@ -444,10 +451,10 @@ module PLSQL
444
451
  case field[:type]
445
452
  when Java::oracle.jdbc.OracleTypes::ARRAY
446
453
  # nested collection
447
- object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value, Java::OracleSql::ARRAY, :sql_type_name => field[:type_name]))
454
+ object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value, Java::OracleSql::ARRAY, sql_type_name: field[:type_name]))
448
455
  when Java::oracle.jdbc.OracleTypes::STRUCT
449
456
  # nested object type
450
- object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value, Java::OracleSql::STRUCT, :sql_type_name => field[:type_name]))
457
+ object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value, Java::OracleSql::STRUCT, sql_type_name: field[:type_name]))
451
458
  else
452
459
  object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value))
453
460
  end
@@ -468,7 +475,7 @@ module PLSQL
468
475
  when Float, BigDecimal
469
476
  ora_number_to_ruby_number(value)
470
477
  when Java::JavaMath::BigDecimal
471
- value && ora_number_to_ruby_number(BigDecimal.new(value.to_s))
478
+ value && ora_number_to_ruby_number(BigDecimal(value.to_s))
472
479
  when Java::OracleSql::DATE
473
480
  if value
474
481
  d = value.dateValue
@@ -493,12 +500,12 @@ module PLSQL
493
500
  String.from_java_bytes(value.getBytes(1, value.length))
494
501
  end
495
502
  when Java::OracleSql::ARRAY
496
- value.getArray.map{|e| ora_value_to_ruby_value(e)}
503
+ value.getArray.map { |e| ora_value_to_ruby_value(e) }
497
504
  when Java::OracleSql::STRUCT
498
505
  descriptor = value.getDescriptor
499
506
  struct_metadata = descriptor.getMetaData
500
- field_names = (1..descriptor.getLength).map {|i| struct_metadata.getColumnName(i).downcase.to_sym}
501
- field_values = value.getAttributes.map{|e| ora_value_to_ruby_value(e)}
507
+ field_names = (1..descriptor.getLength).map { |i| struct_metadata.getColumnName(i).downcase.to_sym }
508
+ field_values = value.getAttributes.map { |e| ora_value_to_ruby_value(e) }
502
509
  ArrayHelpers::to_hash(field_names, field_values)
503
510
  when Java::java.sql.ResultSet
504
511
  Cursor.new(self, value)
@@ -523,23 +530,21 @@ module PLSQL
523
530
 
524
531
  private
525
532
 
526
- def java_date(value)
527
- value && Java::oracle.sql.DATE.new(value.strftime("%Y-%m-%d %H:%M:%S"))
528
- end
529
-
530
- def java_timestamp(value)
531
- value && Java::java.sql.Timestamp.new(value.year-1900, value.month-1, value.day, value.hour, value.min, value.sec, value.usec * 1000)
532
- end
533
+ def java_date(value)
534
+ value && Java::oracle.sql.DATE.new(value.strftime("%Y-%m-%d %H:%M:%S"))
535
+ end
533
536
 
534
- def java_bigdecimal(value)
535
- value && java.math.BigDecimal.new(value.to_s)
536
- end
537
+ def java_timestamp(value)
538
+ value && Java::java.sql.Timestamp.new(value.year - 1900, value.month - 1, value.day, value.hour, value.min, value.sec, value.usec * 1000)
539
+ end
537
540
 
538
- def ora_number_to_ruby_number(num)
539
- # return BigDecimal instead of Float to avoid rounding errors
540
- num == (num_to_i = num.to_i) ? num_to_i : (num.is_a?(BigDecimal) ? num : BigDecimal.new(num.to_s))
541
- end
541
+ def java_bigdecimal(value)
542
+ value && java.math.BigDecimal.new(value.to_s)
543
+ end
542
544
 
545
+ def ora_number_to_ruby_number(num)
546
+ # return BigDecimal instead of Float to avoid rounding errors
547
+ num == (num_to_i = num.to_i) ? num_to_i : (num.is_a?(BigDecimal) ? num : BigDecimal(num.to_s))
548
+ end
543
549
  end
544
-
545
550
  end