activerecord-jdbc-alt-adapter 72.0.0.rc3-java → 80.0.0.rc1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +23 -16
  3. data/.github/workflows/ruby.yml +123 -18
  4. data/.mise.toml +3 -0
  5. data/Gemfile +43 -48
  6. data/README.md +3 -2
  7. data/RUNNING_TESTS.md +9 -1
  8. data/Rakefile +63 -15
  9. data/activerecord-jdbc-adapter.gemspec +2 -2
  10. data/activerecord-jdbc-alt-adapter.gemspec +1 -1
  11. data/lib/arjdbc/abstract/core.rb +0 -17
  12. data/lib/arjdbc/abstract/database_statements.rb +23 -19
  13. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  14. data/lib/arjdbc/mssql/adapter.rb +11 -11
  15. data/lib/arjdbc/mssql/database_statements.rb +32 -29
  16. data/lib/arjdbc/mssql/explain_support.rb +6 -1
  17. data/lib/arjdbc/mssql/quoting.rb +9 -0
  18. data/lib/arjdbc/mssql.rb +1 -1
  19. data/lib/arjdbc/postgresql/adapter.rb +4 -1
  20. data/lib/arjdbc/postgresql/database_statements.rb +45 -0
  21. data/lib/arjdbc/postgresql/schema_statements.rb +17 -0
  22. data/lib/arjdbc/sqlite3/adapter.rb +51 -7
  23. data/lib/arjdbc/sqlite3/database_statements.rb +26 -0
  24. data/lib/arjdbc/version.rb +1 -1
  25. data/pom.xml +3 -3
  26. data/rakelib/02-test.rake +1 -1
  27. data/rakelib/db.rake +5 -3
  28. data/rakelib/rails.rake +0 -1
  29. data/src/java/arjdbc/ArJdbcModule.java +13 -10
  30. data/src/java/arjdbc/db2/DB2Module.java +4 -4
  31. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +8 -9
  32. data/src/java/arjdbc/h2/H2Module.java +2 -1
  33. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +8 -7
  34. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +5 -6
  35. data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +4 -3
  36. data/src/java/arjdbc/jdbc/DriverWrapper.java +13 -8
  37. data/src/java/arjdbc/jdbc/JdbcResult.java +10 -7
  38. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +176 -155
  39. data/src/java/arjdbc/mssql/MSSQLModule.java +3 -3
  40. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +15 -9
  41. data/src/java/arjdbc/mysql/MySQLModule.java +3 -3
  42. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +25 -23
  43. data/src/java/arjdbc/oracle/OracleModule.java +2 -3
  44. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +22 -18
  45. data/src/java/arjdbc/postgresql/PostgreSQLModule.java +2 -3
  46. data/src/java/arjdbc/postgresql/PostgreSQLResult.java +24 -12
  47. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +25 -12
  48. data/src/java/arjdbc/sqlite3/SQLite3Module.java +2 -3
  49. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +78 -29
  50. data/src/java/arjdbc/util/DateTimeUtils.java +7 -5
  51. data/src/java/arjdbc/util/ObjectSupport.java +2 -2
  52. data/src/java/arjdbc/util/StringHelper.java +1 -1
  53. metadata +7 -6
  54. data/.travis.yml +0 -128
@@ -31,6 +31,7 @@ import java.io.InputStreamReader;
31
31
  import java.io.PrintStream;
32
32
  import java.io.Reader;
33
33
  import java.io.StringReader;
34
+ import java.lang.reflect.InvocationTargetException;
34
35
  import java.math.BigDecimal;
35
36
  import java.math.BigInteger;
36
37
  import java.sql.Array;
@@ -109,6 +110,14 @@ import arjdbc.util.StringCache;
109
110
  import static arjdbc.jdbc.DataSourceConnectionFactory.*;
110
111
  import static arjdbc.util.StringHelper.*;
111
112
  import static org.jruby.RubyTime.getLocalTimeZone;
113
+ import static org.jruby.api.Access.getModule;
114
+ import static org.jruby.api.Access.objectClass;
115
+ import static org.jruby.api.Convert.asFixnum;
116
+ import static org.jruby.api.Convert.toInt;
117
+ import static org.jruby.api.Create.allocArray;
118
+ import static org.jruby.api.Create.newArray;
119
+ import static org.jruby.api.Create.newArrayNoCopy;
120
+ import static org.jruby.api.Create.newEmptyArray;
112
121
 
113
122
 
114
123
  /**
@@ -135,8 +144,9 @@ public class RubyJdbcConnection extends RubyObject {
135
144
 
136
145
  protected RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
137
146
  super(runtime, metaClass);
138
- attributeClass = runtime.getModule("ActiveModel").getClass("Attribute");
139
- timeZoneClass = runtime.getModule("ActiveSupport").getClass("TimeWithZone");
147
+ var context = runtime.getCurrentContext();
148
+ attributeClass = getModule(context, "ActiveModel").getClass(context, "Attribute");
149
+ timeZoneClass = getModule(context, "ActiveSupport").getClass(context, "TimeWithZone");
140
150
  }
141
151
 
142
152
  private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
@@ -146,87 +156,92 @@ public class RubyJdbcConnection extends RubyObject {
146
156
  };
147
157
 
148
158
  public static RubyClass createJdbcConnectionClass(final Ruby runtime) {
149
- final RubyClass JdbcConnection = getConnectionAdapters(runtime).
150
- defineClassUnder("JdbcConnection", runtime.getObject(), ALLOCATOR);
151
- JdbcConnection.defineAnnotatedMethods(RubyJdbcConnection.class);
152
- return JdbcConnection;
159
+ var context = runtime.getCurrentContext();
160
+ return getConnectionAdapters(context).
161
+ defineClassUnder(context, "JdbcConnection", runtime.getObject(), ALLOCATOR).
162
+ defineMethods(context, RubyJdbcConnection.class);
153
163
  }
154
164
 
155
- public static RubyClass getJdbcConnection(final Ruby runtime) {
156
- return (RubyClass) getConnectionAdapters(runtime).getConstantAt("JdbcConnection");
165
+ public static RubyClass getJdbcConnection(ThreadContext context) {
166
+ return getConnectionAdapters(context).getClass(context, "JdbcConnection");
157
167
  }
158
168
 
159
169
  protected static RubyModule ActiveRecord(ThreadContext context) {
160
- return context.runtime.getModule("ActiveRecord");
170
+ return getModule(context, "ActiveRecord");
161
171
  }
162
172
 
163
- public static RubyClass getBase(final Ruby runtime) {
164
- return (RubyClass) runtime.getModule("ActiveRecord").getConstantAt("Base");
173
+ @Deprecated
174
+ public static RubyClass getBase(ThreadContext context) {
175
+ return getModule(context, "ActiveRecord").getClass("Base");
165
176
  }
166
177
 
167
178
  /**
168
- * @param runtime
179
+ * @param context the thread context
169
180
  * @return <code>ActiveRecord::Result</code>
170
181
  */
171
- public static RubyClass getResult(final Ruby runtime) {
172
- return (RubyClass) runtime.getModule("ActiveRecord").getConstantAt("Result");
182
+ public static RubyClass getResult(ThreadContext context) {
183
+ return getModule(context, "ActiveRecord").getClass(context, "Result");
173
184
  }
174
185
 
175
186
  /**
176
- * @param runtime
187
+ * @param context the thread context
177
188
  * @return <code>ActiveRecord::ConnectionAdapters</code>
178
189
  */
179
- public static RubyModule getConnectionAdapters(final Ruby runtime) {
180
- return (RubyModule) runtime.getModule("ActiveRecord").getConstantAt("ConnectionAdapters");
190
+ public static RubyModule getConnectionAdapters(ThreadContext context) {
191
+ return getModule(context, "ActiveRecord").getModule(context, "ConnectionAdapters");
181
192
  }
182
193
 
183
194
  /**
184
- * @param runtime
195
+ * resolve <code>ActiveRecord::ConnectionAdapters::IndexDefinition</code>.
196
+ *
197
+ * @param context the thread context
185
198
  * @return <code>ActiveRecord::ConnectionAdapters::IndexDefinition</code>
186
199
  */
187
- protected static RubyClass getIndexDefinition(final Ruby runtime) {
188
- return getConnectionAdapters(runtime).getClass("IndexDefinition");
200
+ protected static RubyClass indexDefinition(ThreadContext context) {
201
+ return getConnectionAdapters(context).getClass(context, "IndexDefinition");
189
202
  }
190
203
 
191
204
  /**
192
- * @param runtime
205
+ * resolve <code>ActiveRecord::ConnectionAdapters::ForeignKeyDefinition</code>.
206
+ *
207
+ * @param context the thread context.
193
208
  * @return <code>ActiveRecord::ConnectionAdapters::ForeignKeyDefinition</code>
194
209
  * @note only since AR 4.2
195
210
  */
196
- protected static RubyClass getForeignKeyDefinition(final Ruby runtime) {
197
- return getConnectionAdapters(runtime).getClass("ForeignKeyDefinition");
211
+ protected static RubyClass foreignKeyDefinition(ThreadContext context) {
212
+ return getConnectionAdapters(context).getClass(context, "ForeignKeyDefinition");
198
213
  }
199
214
 
200
215
  /**
201
- * @param runtime
216
+ * @param context the thread context
202
217
  * @return <code>ActiveRecord::JDBCError</code>
203
218
  */
204
- protected static RubyClass getJDBCError(final Ruby runtime) {
205
- return runtime.getModule("ActiveRecord").getClass("JDBCError");
219
+ protected static RubyClass getJDBCError(ThreadContext context) {
220
+ return getModule(context, "ActiveRecord").getClass(context, "JDBCError");
206
221
  }
207
222
 
208
223
  /**
209
- * @param runtime
224
+ * @param context the thread context
210
225
  * @return <code>ActiveRecord::ConnectionNotEstablished</code>
211
226
  */
212
- protected static RubyClass getConnectionNotEstablished(final Ruby runtime) {
213
- return runtime.getModule("ActiveRecord").getClass("ConnectionNotEstablished");
227
+ protected static RubyClass getConnectionNotEstablished(ThreadContext context) {
228
+ return getModule(context, "ActiveRecord").getClass(context, "ConnectionNotEstablished");
214
229
  }
215
230
 
216
231
  /**
217
- * @param runtime
232
+ * @param context the thread context
218
233
  * @return <code>ActiveRecord::NoDatabaseError</code>
219
234
  */
220
- protected static RubyClass getNoDatabaseError(final Ruby runtime) {
221
- return runtime.getModule("ActiveRecord").getClass("NoDatabaseError");
235
+ protected static RubyClass getNoDatabaseError(ThreadContext context) {
236
+ return getModule(context, "ActiveRecord").getClass(context, "NoDatabaseError");
222
237
  }
223
238
 
224
239
  /**
225
- * @param runtime
240
+ * @param context the thread context
226
241
  * @return <code>ActiveRecord::TransactionIsolationError</code>
227
242
  */
228
- protected static RubyClass getTransactionIsolationError(final Ruby runtime) {
229
- return (RubyClass) runtime.getModule("ActiveRecord").getConstant("TransactionIsolationError");
243
+ protected static RubyClass getTransactionIsolationError(ThreadContext context) {
244
+ return getModule(context, "ActiveRecord").getClass(context, "TransactionIsolationError");
230
245
  }
231
246
 
232
247
  @JRubyMethod(name = "transaction_isolation", alias = "get_transaction_isolation")
@@ -351,7 +366,7 @@ public class RubyJdbcConnection extends RubyObject {
351
366
  connection.setTransactionIsolation(level);
352
367
  }
353
368
  catch (SQLException e) {
354
- RubyClass txError = ActiveRecord(context).getClass("TransactionIsolationError");
369
+ RubyClass txError = ActiveRecord(context).getClass(context, "TransactionIsolationError");
355
370
  if ( txError != null ) throw wrapException(context, txError, e);
356
371
  throw e; // let it roll - will be wrapped into a JDBCError (non 4.0)
357
372
  }
@@ -485,7 +500,7 @@ public class RubyJdbcConnection extends RubyObject {
485
500
  }
486
501
 
487
502
  protected static RuntimeException newSavepointNotSetError(final ThreadContext context, final IRubyObject name, final String op) {
488
- RubyClass StatementInvalid = ActiveRecord(context).getClass("StatementInvalid");
503
+ RubyClass StatementInvalid = ActiveRecord(context).getClass(context, "StatementInvalid");
489
504
  return context.runtime.newRaiseException(StatementInvalid, "could not " + op + " savepoint: '" + name + "' (not set)");
490
505
  }
491
506
 
@@ -495,13 +510,13 @@ public class RubyJdbcConnection extends RubyObject {
495
510
  @SuppressWarnings("unchecked")
496
511
  final Map<IRubyObject, Savepoint> savepoints = getSavepoints(false);
497
512
  if ( savepoints != null ) {
498
- final RubyArray names = context.runtime.newArray(savepoints.size());
513
+ final RubyArray names = allocArray(context, savepoints.size());
499
514
  for ( Map.Entry<IRubyObject, ?> entry : savepoints.entrySet() ) {
500
- names.append( entry.getKey() ); // keys are RubyString instances
515
+ names.append(context, entry.getKey()); // keys are RubyString instances
501
516
  }
502
517
  return names;
503
518
  }
504
- return context.runtime.newEmptyArray();
519
+ return newEmptyArray(context);
505
520
  }
506
521
 
507
522
  protected Map<IRubyObject, Savepoint> getSavepoints(final ThreadContext context) {
@@ -562,7 +577,7 @@ public class RubyJdbcConnection extends RubyObject {
562
577
 
563
578
  IRubyObject jdbcFetchSize = getConfigValue(context, "jdbc_fetch_size");
564
579
  if (jdbcFetchSize != context.nil) {
565
- this.fetchSize = RubyNumeric.fix2int(jdbcFetchSize);
580
+ this.fetchSize = toInt(context, jdbcFetchSize);
566
581
  }
567
582
  }
568
583
 
@@ -1021,7 +1036,7 @@ public class RubyJdbcConnection extends RubyObject {
1021
1036
  switch (args.length) {
1022
1037
  case 2:
1023
1038
  if (args[1] instanceof RubyNumeric) { // (sql, max_rows)
1024
- maxRows = RubyNumeric.fix2int(args[1]);
1039
+ maxRows = toInt(context, args[1]);
1025
1040
  binds = null;
1026
1041
  } else { // (sql, binds)
1027
1042
  maxRows = 0;
@@ -1029,7 +1044,7 @@ public class RubyJdbcConnection extends RubyObject {
1029
1044
  }
1030
1045
  break;
1031
1046
  case 3: // (sql, max_rows, binds)
1032
- maxRows = RubyNumeric.fix2int(args[1]);
1047
+ maxRows = toInt(context, args[1]);
1033
1048
  binds = (RubyArray) TypeConverter.checkArrayType(context, args[2]);
1034
1049
  break;
1035
1050
  default: // (sql) 1-arg
@@ -1071,7 +1086,7 @@ public class RubyJdbcConnection extends RubyObject {
1071
1086
  if (hasResult) {
1072
1087
  return mapToRawResult(context, connection, statement.getResultSet(), false);
1073
1088
  }
1074
- return context.runtime.newEmptyArray();
1089
+ return newEmptyArray(context);
1075
1090
  }
1076
1091
  catch (final SQLException e) {
1077
1092
  debugErrorSQL(context, query);
@@ -1238,7 +1253,7 @@ public class RubyJdbcConnection extends RubyObject {
1238
1253
  public IRubyObject primary_keys(ThreadContext context, IRubyObject tableName) throws SQLException {
1239
1254
  @SuppressWarnings("unchecked")
1240
1255
  List<IRubyObject> primaryKeys = (List) primaryKeys(context, tableName.toString());
1241
- return context.runtime.newArray(primaryKeys);
1256
+ return newArray(context, primaryKeys);
1242
1257
  }
1243
1258
 
1244
1259
  protected static final int PRIMARY_KEYS_COLUMN_NAME = 4;
@@ -1386,7 +1401,7 @@ public class RubyJdbcConnection extends RubyObject {
1386
1401
  final List<RubyString> primaryKeys = primaryKeys(context, connection, table);
1387
1402
 
1388
1403
  ResultSet indexInfoSet = null;
1389
- final RubyArray indexes = RubyArray.newArray(runtime, 8);
1404
+ final RubyArray indexes = allocArray(context, 8);
1390
1405
  try {
1391
1406
  final DatabaseMetaData metaData = connection.getMetaData();
1392
1407
  indexInfoSet = metaData.getIndexInfo(table.catalog, table.schema, table.name, false, true);
@@ -1418,15 +1433,15 @@ public class RubyJdbcConnection extends RubyObject {
1418
1433
  cachedString(context, indexTableName), // table_name
1419
1434
  cachedString(context, indexName), // index_name
1420
1435
  nonUnique ? context.fals : context.tru, // unique
1421
- currentColumns = RubyArray.newArray(runtime, 4) // [] column names
1436
+ currentColumns = allocArray(context, 4) // [] column names
1422
1437
  // orders, (since AR 3.2) where, type, using (AR 4.0)
1423
1438
  };
1424
1439
 
1425
- indexes.append( IndexDefinition.newInstance(context, args, Block.NULL_BLOCK) ); // IndexDefinition.new
1440
+ indexes.append(context, IndexDefinition.newInstance(context, args, Block.NULL_BLOCK)); // IndexDefinition.new
1426
1441
  }
1427
1442
 
1428
1443
  // one or more columns can be associated with an index
1429
- if ( currentColumns != null ) currentColumns.append(rubyColumnName);
1444
+ if ( currentColumns != null ) currentColumns.append(context, rubyColumnName);
1430
1445
  }
1431
1446
 
1432
1447
  return indexes;
@@ -1436,9 +1451,8 @@ public class RubyJdbcConnection extends RubyObject {
1436
1451
  }
1437
1452
 
1438
1453
  protected RubyClass getIndexDefinition(final ThreadContext context) {
1439
- final RubyClass adapterClass = adapter.getMetaClass();
1440
- IRubyObject IDef = adapterClass.getConstantAt("IndexDefinition");
1441
- return IDef != null ? (RubyClass) IDef : getIndexDefinition(context.runtime);
1454
+ var IDef = adapter.getMetaClass().getClass(context, "IndexDefinition");
1455
+ return IDef != null ? IDef : indexDefinition(context);
1442
1456
  }
1443
1457
 
1444
1458
  @JRubyMethod
@@ -1493,7 +1507,7 @@ public class RubyJdbcConnection extends RubyObject {
1493
1507
  fKeys.add( FKDefinition.newInstance(context, from_table, to_table, options, Block.NULL_BLOCK) ); // ForeignKeyDefinition.new
1494
1508
  }
1495
1509
 
1496
- return runtime.newArray(fKeys);
1510
+ return newArray(context, fKeys);
1497
1511
 
1498
1512
  } finally { close(fkInfoSet); }
1499
1513
  });
@@ -1511,8 +1525,8 @@ public class RubyJdbcConnection extends RubyObject {
1511
1525
 
1512
1526
  protected RubyClass getForeignKeyDefinition(final ThreadContext context) {
1513
1527
  final RubyClass adapterClass = adapter.getMetaClass();
1514
- IRubyObject FKDef = adapterClass.getConstantAt("ForeignKeyDefinition");
1515
- return FKDef != null ? (RubyClass) FKDef : getForeignKeyDefinition(context.runtime);
1528
+ var FKDef = adapterClass.getClass(context, "ForeignKeyDefinition");
1529
+ return FKDef != null ? FKDef : foreignKeyDefinition(context);
1516
1530
  }
1517
1531
 
1518
1532
 
@@ -1619,7 +1633,7 @@ public class RubyJdbcConnection extends RubyObject {
1619
1633
  }
1620
1634
  setStatementParameter(context, context.runtime, connection, statement, 2, idValue, idColumn);
1621
1635
  */
1622
- return statement.executeUpdate();
1636
+ return (Integer) statement.executeUpdate();
1623
1637
  }
1624
1638
  finally { close(statement); }
1625
1639
  });
@@ -1700,7 +1714,7 @@ public class RubyJdbcConnection extends RubyObject {
1700
1714
  return block.call(context, JavaUtil.convertJavaToRuby(context.runtime, metaData));
1701
1715
  }
1702
1716
  catch (SQLException e) {
1703
- throw wrapSQLException(context, getJDBCError(context.runtime), e, null);
1717
+ throw wrapSQLException(context, getJDBCError(context), e, null);
1704
1718
  }
1705
1719
  finally { close(connection); }
1706
1720
  }
@@ -1766,9 +1780,8 @@ public class RubyJdbcConnection extends RubyObject {
1766
1780
  final IRubyObject driver_instance = getConfigValue(context, "driver_instance");
1767
1781
 
1768
1782
  if ( url.isNil() || ( driver.isNil() && driver_instance.isNil() ) ) {
1769
- final Ruby runtime = context.runtime;
1770
- final RubyClass errorClass = getConnectionNotEstablished( runtime );
1771
- throw runtime.newRaiseException(errorClass, "adapter requires :driver class and jdbc :url");
1783
+ final RubyClass errorClass = getConnectionNotEstablished(context);
1784
+ throw context.runtime.newRaiseException(errorClass, "adapter requires :driver class and jdbc :url");
1772
1785
  }
1773
1786
 
1774
1787
  final String jdbcURL = buildURL(context, url);
@@ -1824,6 +1837,10 @@ public class RubyJdbcConnection extends RubyObject {
1824
1837
  }
1825
1838
  catch (SecurityException e) {
1826
1839
  throw wrapException(context, context.runtime.getSecurityError(), e);
1840
+ } catch (InvocationTargetException e) {
1841
+ throw wrapException(context, context.runtime.getNameError(), e, "invalid invocation target for " + driver);
1842
+ } catch (NoSuchMethodException e) {
1843
+ throw wrapException(context, context.runtime.getNameError(), e, "cannot find constructor for " + driver);
1827
1844
  }
1828
1845
  }
1829
1846
 
@@ -2008,10 +2025,10 @@ public class RubyJdbcConnection extends RubyObject {
2008
2025
  final ResultSet resultSet, final ColumnData[] columns) throws SQLException {
2009
2026
  final Ruby runtime = context.runtime;
2010
2027
 
2011
- final RubyArray resultRows = runtime.newArray();
2028
+ final RubyArray resultRows = newArray(context);
2012
2029
 
2013
2030
  while (resultSet.next()) {
2014
- resultRows.append(mapRow(context, runtime, columns, resultSet, this));
2031
+ resultRows.append(context, mapRow(context, runtime, columns, resultSet, this));
2015
2032
  }
2016
2033
 
2017
2034
  return newResult(context, columns, resultRows);
@@ -2163,7 +2180,7 @@ public class RubyJdbcConnection extends RubyObject {
2163
2180
  static {
2164
2181
  final String dateTimeRaw = SafePropertyAccessor.getProperty("arjdbc.datetime.raw");
2165
2182
  if ( dateTimeRaw != null ) {
2166
- rawDateTime = Boolean.parseBoolean(dateTimeRaw);
2183
+ rawDateTime = (Boolean) Boolean.parseBoolean(dateTimeRaw);
2167
2184
  }
2168
2185
  // NOTE: we do this since it will have a different value depending on
2169
2186
  // AR version - since 4.0 false by default otherwise will be true ...
@@ -2178,7 +2195,7 @@ public class RubyJdbcConnection extends RubyObject {
2178
2195
  @JRubyMethod(name = "raw_date_time=", meta = true)
2179
2196
  public static IRubyObject setRawDateTime(final IRubyObject self, final IRubyObject value) {
2180
2197
  if ( value instanceof RubyBoolean ) {
2181
- rawDateTime = ((RubyBoolean) value).isTrue();
2198
+ rawDateTime = (Boolean) value.isTrue();
2182
2199
  }
2183
2200
  else {
2184
2201
  rawDateTime = value.isNil() ? null : Boolean.TRUE;
@@ -2244,7 +2261,7 @@ public class RubyJdbcConnection extends RubyObject {
2244
2261
  static {
2245
2262
  final String booleanRaw = SafePropertyAccessor.getProperty("arjdbc.boolean.raw");
2246
2263
  if ( booleanRaw != null ) {
2247
- rawBoolean = Boolean.parseBoolean(booleanRaw);
2264
+ rawBoolean = (Boolean) Boolean.parseBoolean(booleanRaw);
2248
2265
  }
2249
2266
  }
2250
2267
 
@@ -2257,7 +2274,7 @@ public class RubyJdbcConnection extends RubyObject {
2257
2274
  @JRubyMethod(name = "raw_boolean=", meta = true)
2258
2275
  public static IRubyObject setRawBoolean(final IRubyObject self, final IRubyObject value) {
2259
2276
  if ( value instanceof RubyBoolean ) {
2260
- rawBoolean = ((RubyBoolean) value).isTrue();
2277
+ rawBoolean = (Boolean) value.isTrue();
2261
2278
  }
2262
2279
  else {
2263
2280
  rawBoolean = value.isNil() ? null : Boolean.TRUE;
@@ -2372,7 +2389,7 @@ public class RubyJdbcConnection extends RubyObject {
2372
2389
  try {
2373
2390
  if ( value == null ) return context.nil;
2374
2391
 
2375
- final RubyArray array = runtime.newArray();
2392
+ final RubyArray array = newArray(context);
2376
2393
 
2377
2394
  final ResultSet arrayResult = value.getResultSet(); // 1: index, 2: value
2378
2395
  final int baseType = value.getBaseType();
@@ -2393,7 +2410,7 @@ public class RubyJdbcConnection extends RubyObject {
2393
2410
  }
2394
2411
 
2395
2412
  while ( arrayResult.next() ) {
2396
- array.append( jdbcToRuby(context, runtime, 2, baseType, arrayResult) );
2413
+ array.append(context, jdbcToRuby(context, runtime, 2, baseType, arrayResult));
2397
2414
  }
2398
2415
  arrayResult.close();
2399
2416
 
@@ -2453,7 +2470,7 @@ public class RubyJdbcConnection extends RubyObject {
2453
2470
 
2454
2471
  // All the set methods were calling this first so save a method call in the nil case
2455
2472
  if ( value == context.nil ) {
2456
- statement.setNull(index, type);
2473
+ setNullParameter(context, connection, statement, index, type);
2457
2474
  return;
2458
2475
  }
2459
2476
 
@@ -2517,40 +2534,47 @@ public class RubyJdbcConnection extends RubyObject {
2517
2534
  }
2518
2535
  }
2519
2536
 
2537
+ protected void setNullParameter(final ThreadContext context,
2538
+ final Connection connection, final PreparedStatement statement,
2539
+ final int index, final int type) throws SQLException {
2540
+ // statement.setObject(index, null);
2541
+ statement.setNull(index, type);
2542
+ }
2543
+
2520
2544
  protected static final Map<String, Integer> JDBC_TYPE_FOR = new HashMap<>(32, 1);
2521
2545
  static {
2522
- JDBC_TYPE_FOR.put("string", Types.VARCHAR);
2523
- JDBC_TYPE_FOR.put("text", Types.CLOB);
2524
- JDBC_TYPE_FOR.put("integer", Types.INTEGER);
2525
- JDBC_TYPE_FOR.put("float", Types.FLOAT);
2526
- JDBC_TYPE_FOR.put("real", Types.REAL);
2527
- JDBC_TYPE_FOR.put("decimal", Types.DECIMAL);
2528
- JDBC_TYPE_FOR.put("date", Types.DATE);
2529
- JDBC_TYPE_FOR.put("time", Types.TIME);
2530
- JDBC_TYPE_FOR.put("datetime", Types.TIMESTAMP);
2531
- JDBC_TYPE_FOR.put("timestamp", Types.TIMESTAMP);
2532
- JDBC_TYPE_FOR.put("boolean", Types.BOOLEAN);
2533
- JDBC_TYPE_FOR.put("array", Types.ARRAY);
2534
- JDBC_TYPE_FOR.put("xml", Types.SQLXML);
2546
+ JDBC_TYPE_FOR.put("string", Integer.valueOf(Types.VARCHAR));
2547
+ JDBC_TYPE_FOR.put("text", Integer.valueOf(Types.CLOB));
2548
+ JDBC_TYPE_FOR.put("integer", Integer.valueOf(Types.INTEGER));
2549
+ JDBC_TYPE_FOR.put("float", Integer.valueOf(Types.FLOAT));
2550
+ JDBC_TYPE_FOR.put("real", Integer.valueOf(Types.REAL));
2551
+ JDBC_TYPE_FOR.put("decimal", Integer.valueOf(Types.DECIMAL));
2552
+ JDBC_TYPE_FOR.put("date", Integer.valueOf(Types.DATE));
2553
+ JDBC_TYPE_FOR.put("time", Integer.valueOf(Types.TIME));
2554
+ JDBC_TYPE_FOR.put("datetime", Integer.valueOf(Types.TIMESTAMP));
2555
+ JDBC_TYPE_FOR.put("timestamp", Integer.valueOf(Types.TIMESTAMP));
2556
+ JDBC_TYPE_FOR.put("boolean", Integer.valueOf(Types.BOOLEAN));
2557
+ JDBC_TYPE_FOR.put("array", Integer.valueOf(Types.ARRAY));
2558
+ JDBC_TYPE_FOR.put("xml", Integer.valueOf(Types.SQLXML));
2535
2559
 
2536
2560
  // also mapping standard SQL names :
2537
- JDBC_TYPE_FOR.put("bit", Types.BIT);
2538
- JDBC_TYPE_FOR.put("tinyint", Types.TINYINT);
2539
- JDBC_TYPE_FOR.put("smallint", Types.SMALLINT);
2540
- JDBC_TYPE_FOR.put("bigint", Types.BIGINT);
2541
- JDBC_TYPE_FOR.put("int", Types.INTEGER);
2542
- JDBC_TYPE_FOR.put("double", Types.DOUBLE);
2543
- JDBC_TYPE_FOR.put("numeric", Types.NUMERIC);
2544
- JDBC_TYPE_FOR.put("char", Types.CHAR);
2545
- JDBC_TYPE_FOR.put("varchar", Types.VARCHAR);
2546
- JDBC_TYPE_FOR.put("binary", Types.BINARY);
2547
- JDBC_TYPE_FOR.put("varbinary", Types.VARBINARY);
2561
+ JDBC_TYPE_FOR.put("bit", Integer.valueOf(Types.BIT));
2562
+ JDBC_TYPE_FOR.put("tinyint", Integer.valueOf(Types.TINYINT));
2563
+ JDBC_TYPE_FOR.put("smallint", Integer.valueOf(Types.SMALLINT));
2564
+ JDBC_TYPE_FOR.put("bigint", Integer.valueOf(Types.BIGINT));
2565
+ JDBC_TYPE_FOR.put("int", Integer.valueOf(Types.INTEGER));
2566
+ JDBC_TYPE_FOR.put("double", Integer.valueOf(Types.DOUBLE));
2567
+ JDBC_TYPE_FOR.put("numeric", Integer.valueOf(Types.NUMERIC));
2568
+ JDBC_TYPE_FOR.put("char", Integer.valueOf(Types.CHAR));
2569
+ JDBC_TYPE_FOR.put("varchar", Integer.valueOf(Types.VARCHAR));
2570
+ JDBC_TYPE_FOR.put("binary", Integer.valueOf(Types.BINARY));
2571
+ JDBC_TYPE_FOR.put("varbinary", Integer.valueOf(Types.VARBINARY));
2548
2572
  //JDBC_TYPE_FOR.put("struct", Types.STRUCT);
2549
- JDBC_TYPE_FOR.put("blob", Types.BLOB);
2550
- JDBC_TYPE_FOR.put("clob", Types.CLOB);
2551
- JDBC_TYPE_FOR.put("nchar", Types.NCHAR);
2552
- JDBC_TYPE_FOR.put("nvarchar", Types.NVARCHAR);
2553
- JDBC_TYPE_FOR.put("nclob", Types.NCLOB);
2573
+ JDBC_TYPE_FOR.put("blob", Integer.valueOf(Types.BLOB));
2574
+ JDBC_TYPE_FOR.put("clob", Integer.valueOf(Types.CLOB));
2575
+ JDBC_TYPE_FOR.put("nchar", Integer.valueOf(Types.NCHAR));
2576
+ JDBC_TYPE_FOR.put("nvarchar", Integer.valueOf(Types.NVARCHAR));
2577
+ JDBC_TYPE_FOR.put("nclob", Integer.valueOf(Types.NCLOB));
2554
2578
  }
2555
2579
 
2556
2580
  protected int jdbcTypeForAttribute(final ThreadContext context,
@@ -2659,7 +2683,7 @@ public class RubyJdbcConnection extends RubyObject {
2659
2683
  }
2660
2684
 
2661
2685
  protected DateTimeZone getDefaultTimeZone(final ThreadContext context) {
2662
- return isDefaultTimeZoneUTC(context) ? DateTimeZone.UTC : getLocalTimeZone(context.runtime); // handles ENV['TZ']
2686
+ return isDefaultTimeZoneUTC(context) ? DateTimeZone.UTC : getLocalTimeZone(context); // handles ENV['TZ']
2663
2687
  }
2664
2688
 
2665
2689
  private String default_timezone(final ThreadContext context) {
@@ -2676,13 +2700,13 @@ public class RubyJdbcConnection extends RubyObject {
2676
2700
  final IRubyObject attribute, final int type) throws SQLException {
2677
2701
 
2678
2702
  if ( value instanceof RubyBignum ) { // e.g. HSQLDB / H2 report JDBC type 4
2679
- setBigIntegerParameter(context, connection, statement, index, (RubyBignum) value, attribute, type);
2703
+ setBigIntegerParameter(context, connection, statement, index, value, attribute, type);
2680
2704
  }
2681
2705
  else if ( value instanceof RubyNumeric ) {
2682
2706
  statement.setLong(index, RubyNumeric.num2long(value));
2683
2707
  }
2684
2708
  else {
2685
- statement.setLong(index, value.convertToInteger("to_i").getLongValue());
2709
+ statement.setLong(index, value.convertToInteger("to_i").asLong(context));
2686
2710
  }
2687
2711
  }
2688
2712
 
@@ -2691,14 +2715,14 @@ public class RubyJdbcConnection extends RubyObject {
2691
2715
  final int index, final IRubyObject value,
2692
2716
  final IRubyObject attribute, final int type) throws SQLException {
2693
2717
 
2694
- if ( value instanceof RubyBignum ) {
2695
- setLongOrDecimalParameter(statement, index, ((RubyBignum) value).getValue());
2718
+ if ( value instanceof RubyBignum bignum) {
2719
+ setLongOrDecimalParameter(statement, index, bignum.getValue());
2696
2720
  }
2697
- else if ( value instanceof RubyFixnum ) {
2698
- statement.setLong(index, ((RubyFixnum) value).getLongValue());
2721
+ else if (value instanceof RubyFixnum fixnum) {
2722
+ statement.setLong(index, fixnum.getValue());
2699
2723
  }
2700
2724
  else {
2701
- setLongOrDecimalParameter(statement, index, value.convertToInteger("to_i").getBigIntegerValue());
2725
+ setLongOrDecimalParameter(statement, index, value.convertToInteger("to_i").asBigInteger(context));
2702
2726
  }
2703
2727
  }
2704
2728
 
@@ -2718,11 +2742,11 @@ public class RubyJdbcConnection extends RubyObject {
2718
2742
  final int index, final IRubyObject value,
2719
2743
  final IRubyObject attribute, final int type) throws SQLException {
2720
2744
 
2721
- if ( value instanceof RubyNumeric ) {
2722
- statement.setDouble(index, ((RubyNumeric) value).getDoubleValue());
2745
+ if ( value instanceof RubyNumeric numeric) {
2746
+ statement.setDouble(index, numeric.asDouble(context));
2723
2747
  }
2724
2748
  else {
2725
- statement.setDouble(index, value.convertToFloat().getDoubleValue());
2749
+ statement.setDouble(index, value.convertToFloat().asDouble(context));
2726
2750
  }
2727
2751
  }
2728
2752
 
@@ -2731,19 +2755,18 @@ public class RubyJdbcConnection extends RubyObject {
2731
2755
  final int index, final IRubyObject value,
2732
2756
  final IRubyObject attribute, final int type) throws SQLException {
2733
2757
 
2734
- if (value instanceof RubyBigDecimal) {
2735
- statement.setBigDecimal(index, ((RubyBigDecimal) value).getValue());
2758
+ if (value instanceof RubyBigDecimal bigdecimal) {
2759
+ statement.setBigDecimal(index, bigdecimal.getValue());
2736
2760
  }
2737
- else if ( value instanceof RubyInteger ) {
2738
- statement.setBigDecimal(index, new BigDecimal(((RubyInteger) value).getBigIntegerValue()));
2761
+ else if ( value instanceof RubyInteger integer) {
2762
+ statement.setBigDecimal(index, new BigDecimal(integer.asBigInteger(context)));
2739
2763
  }
2740
- else if ( value instanceof RubyNumeric ) {
2741
- statement.setDouble(index, ((RubyNumeric) value).getDoubleValue());
2764
+ else if ( value instanceof RubyNumeric numeric) {
2765
+ statement.setDouble(index, numeric.asDouble(context));
2742
2766
  }
2743
2767
  else { // e.g. `BigDecimal '42.00000000000000000001'`
2744
- Ruby runtime = context.runtime;
2745
2768
  statement.setBigDecimal(index,
2746
- RubyBigDecimal.newInstance(context, runtime.getModule("BigDecimal"), value, RubyFixnum.zero(runtime)).getValue());
2769
+ RubyBigDecimal.newInstance(context, getModule(context, "BigDecimal"), value, asFixnum(context, 0)).getValue());
2747
2770
  }
2748
2771
  }
2749
2772
 
@@ -2802,7 +2825,7 @@ public class RubyJdbcConnection extends RubyObject {
2802
2825
  final int index, IRubyObject value,
2803
2826
  final IRubyObject attribute, final int type) throws SQLException {
2804
2827
 
2805
- if ( ! "Date".equals(value.getMetaClass().getName()) && value.respondsTo("to_date") ) {
2828
+ if ( ! "Date".equals(value.getMetaClass().getName(context)) && value.respondsTo("to_date") ) {
2806
2829
  value = value.callMethod(context, "to_date");
2807
2830
  }
2808
2831
 
@@ -2929,7 +2952,7 @@ public class RubyJdbcConnection extends RubyObject {
2929
2952
  protected Connection getConnectionInternal(final boolean required) throws SQLException {
2930
2953
  Connection connection = getConnectionImpl();
2931
2954
  if (connection == null && required) {
2932
- if (!connected) handleNotConnected(); // raise ConnectionNotEstablished
2955
+ if (!connected) handleNotConnected(getRuntime().getCurrentContext()); // raise ConnectionNotEstablished
2933
2956
  synchronized (this) {
2934
2957
  connection = getConnectionImpl();
2935
2958
  if ( connection == null ) {
@@ -2941,10 +2964,9 @@ public class RubyJdbcConnection extends RubyObject {
2941
2964
  return connection;
2942
2965
  }
2943
2966
 
2944
- private void handleNotConnected() {
2945
- final Ruby runtime = getRuntime();
2946
- final RubyClass errorClass = getConnectionNotEstablished( runtime );
2947
- throw runtime.newRaiseException(errorClass, "no connection available");
2967
+ private void handleNotConnected(ThreadContext context) {
2968
+ final RubyClass errorClass = getConnectionNotEstablished(context);
2969
+ throw context.runtime.newRaiseException(errorClass, "no connection available");
2948
2970
  }
2949
2971
 
2950
2972
  /**
@@ -3010,7 +3032,7 @@ public class RubyJdbcConnection extends RubyObject {
3010
3032
  protected int getAliveTimeout(final ThreadContext context) {
3011
3033
  if ( aliveTimeout == Integer.MIN_VALUE ) {
3012
3034
  final IRubyObject timeout = getConfigValue(context, "connection_alive_timeout");
3013
- return aliveTimeout = timeout == context.nil ? 0 : RubyInteger.fix2int(timeout);
3035
+ aliveTimeout = timeout == context.nil ? 0 : toInt(context, timeout);
3014
3036
  }
3015
3037
  return aliveTimeout;
3016
3038
  }
@@ -3027,7 +3049,7 @@ public class RubyJdbcConnection extends RubyObject {
3027
3049
  @Override
3028
3050
  @JRubyMethod
3029
3051
  @SuppressWarnings("unchecked")
3030
- public IRubyObject inspect() {
3052
+ public IRubyObject inspect(ThreadContext context) {
3031
3053
  final ArrayList<Variable<String>> varList = new ArrayList<>(2);
3032
3054
  final Connection connection = getConnectionImpl();
3033
3055
  varList.add(new VariableEntry<>( "connection", connection == null ? "null" : connection.toString() ));
@@ -3083,10 +3105,10 @@ public class RubyJdbcConnection extends RubyObject {
3083
3105
  protected RubyArray mapTables(final ThreadContext context, final Connection connection,
3084
3106
  final String catalog, final String schemaPattern, final String tablePattern,
3085
3107
  final ResultSet tablesSet) throws SQLException {
3086
- final RubyArray tables = RubyArray.newArray(context.runtime);
3108
+ final RubyArray tables = newArray(context);
3087
3109
  while ( tablesSet.next() ) {
3088
3110
  String name = tablesSet.getString(TABLES_TABLE_NAME);
3089
- tables.append( cachedString(context, caseConvertIdentifierForRails(connection, name)) );
3111
+ tables.append(context, cachedString(context, caseConvertIdentifierForRails(connection, name)));
3090
3112
  }
3091
3113
  return tables;
3092
3114
  }
@@ -3151,7 +3173,7 @@ public class RubyJdbcConnection extends RubyObject {
3151
3173
 
3152
3174
  final Ruby runtime = context.runtime;
3153
3175
 
3154
- final RubyArray columns = RubyArray.newArray(runtime);
3176
+ final RubyArray columns = newArray(context);
3155
3177
  while ( results.next() ) {
3156
3178
  final String colName = results.getString(COLUMN_NAME);
3157
3179
  final RubyString columnName = cachedString(context, caseConvertIdentifierForRails(metaData, colName));
@@ -3168,7 +3190,7 @@ public class RubyJdbcConnection extends RubyObject {
3168
3190
  final IRubyObject[] args = new IRubyObject[] {
3169
3191
  columnName, defaultValue, type_metadata, nullable, tableName
3170
3192
  };
3171
- columns.append( Column.newInstance(context, args, Block.NULL_BLOCK) );
3193
+ columns.append(context, Column.newInstance(context, args, Block.NULL_BLOCK));
3172
3194
  }
3173
3195
  return columns;
3174
3196
  }
@@ -3198,7 +3220,7 @@ public class RubyJdbcConnection extends RubyObject {
3198
3220
  }
3199
3221
 
3200
3222
  protected IRubyObject mapGeneratedKeys(
3201
- final Ruby runtime, final Connection connection,
3223
+ ThreadContext context, final Connection connection,
3202
3224
  final Statement statement, final Boolean singleResult)
3203
3225
  throws SQLException {
3204
3226
  if ( supportsGeneratedKeys(connection) ) {
@@ -3207,8 +3229,8 @@ public class RubyJdbcConnection extends RubyObject {
3207
3229
  genKeys = statement.getGeneratedKeys();
3208
3230
  // drivers might report a non-result statement without keys
3209
3231
  // e.g. on derby with SQL: 'SET ISOLATION = SERIALIZABLE'
3210
- if ( genKeys == null ) return runtime.getNil();
3211
- return doMapGeneratedKeys(runtime, genKeys, singleResult);
3232
+ if ( genKeys == null ) return context.nil;
3233
+ return doMapGeneratedKeys(context, genKeys, singleResult);
3212
3234
  }
3213
3235
  catch (SQLFeatureNotSupportedException e) {
3214
3236
  return null; // statement.getGeneratedKeys()
@@ -3218,7 +3240,7 @@ public class RubyJdbcConnection extends RubyObject {
3218
3240
  return null; // not supported
3219
3241
  }
3220
3242
 
3221
- protected final IRubyObject doMapGeneratedKeys(final Ruby runtime,
3243
+ protected final IRubyObject doMapGeneratedKeys(ThreadContext context,
3222
3244
  final ResultSet genKeys, final Boolean singleResult)
3223
3245
  throws SQLException {
3224
3246
 
@@ -3229,28 +3251,28 @@ public class RubyJdbcConnection extends RubyObject {
3229
3251
  // singleResult == null - guess if only single key returned
3230
3252
  if ( singleResult == null || singleResult) {
3231
3253
  if ( next ) {
3232
- firstKey = mapGeneratedKey(runtime, genKeys);
3254
+ firstKey = mapGeneratedKey(context, genKeys);
3233
3255
  if ( singleResult != null || ! genKeys.next() ) {
3234
3256
  return firstKey;
3235
3257
  }
3236
3258
  next = true; // 2nd genKeys.next() returned true
3237
3259
  }
3238
3260
  else {
3239
- /* if ( singleResult != null ) */ return runtime.getNil();
3261
+ /* if ( singleResult != null ) */ return context.nil;
3240
3262
  }
3241
3263
  }
3242
3264
 
3243
- final RubyArray keys = runtime.newArray();
3244
- if ( firstKey != null ) keys.append(firstKey); // singleResult == null
3265
+ final RubyArray keys = newArray(context);
3266
+ if (firstKey != null) keys.append(context, firstKey); // singleResult == null
3245
3267
  while ( next ) {
3246
- keys.append( mapGeneratedKey(runtime, genKeys) );
3268
+ keys.append(context, mapGeneratedKey(context, genKeys));
3247
3269
  next = genKeys.next();
3248
3270
  }
3249
3271
  return keys;
3250
3272
  }
3251
3273
 
3252
- protected IRubyObject mapGeneratedKey(final Ruby runtime, final ResultSet genKeys) throws SQLException {
3253
- return runtime.newFixnum(genKeys.getLong(1));
3274
+ protected IRubyObject mapGeneratedKey(ThreadContext context, final ResultSet genKeys) throws SQLException {
3275
+ return asFixnum(context, genKeys.getLong(1));
3254
3276
  }
3255
3277
 
3256
3278
  private transient Boolean supportsGeneratedKeys;
@@ -3258,7 +3280,7 @@ public class RubyJdbcConnection extends RubyObject {
3258
3280
  protected boolean supportsGeneratedKeys(final Connection connection) throws SQLException {
3259
3281
  Boolean supportsGeneratedKeys = this.supportsGeneratedKeys;
3260
3282
  if (supportsGeneratedKeys == null) {
3261
- supportsGeneratedKeys = this.supportsGeneratedKeys = connection.getMetaData().supportsGetGeneratedKeys();
3283
+ supportsGeneratedKeys = this.supportsGeneratedKeys = (Boolean) connection.getMetaData().supportsGetGeneratedKeys();
3262
3284
  }
3263
3285
  return supportsGeneratedKeys;
3264
3286
  }
@@ -3275,12 +3297,11 @@ public class RubyJdbcConnection extends RubyObject {
3275
3297
 
3276
3298
  final ColumnData[] columns = extractColumns(context, connection, resultSet, downCase);
3277
3299
 
3278
- final Ruby runtime = context.runtime;
3279
- final RubyArray results = runtime.newArray();
3300
+ final RubyArray results = newArray(context);
3280
3301
  // [ { 'col1': 1, 'col2': 2 }, { 'col1': 3, 'col2': 4 } ]
3281
3302
 
3282
3303
  while ( resultSet.next() ) {
3283
- results.append(mapRawRow(context, runtime, columns, resultSet, this));
3304
+ results.append(context, mapRawRow(context, context.runtime, columns, resultSet, this));
3284
3305
  }
3285
3306
  return results;
3286
3307
  }
@@ -3351,7 +3372,7 @@ public class RubyJdbcConnection extends RubyObject {
3351
3372
 
3352
3373
  final Connection connection = getConnectionInternal(false); // getConnection()
3353
3374
  if ( connection == null ) {
3354
- if ( ! connected ) handleNotConnected(); // raise ConnectionNotEstablished
3375
+ if ( ! connected ) handleNotConnected(context); // raise ConnectionNotEstablished
3355
3376
  throw new NoConnectionException();
3356
3377
  }
3357
3378
  gotConnection = true;
@@ -3465,7 +3486,7 @@ public class RubyJdbcConnection extends RubyObject {
3465
3486
  return wrapException(context, context.runtime.getRuntimeError(), exception);
3466
3487
  }
3467
3488
  // NOTE: compat - maybe makes sense or maybe not (e.g. IOException) :
3468
- return wrapException(context, getJDBCError(runtime), exception);
3489
+ return wrapException(context, getJDBCError(context), exception);
3469
3490
  }
3470
3491
 
3471
3492
  public static RaiseException wrapException(final ThreadContext context,
@@ -3481,7 +3502,7 @@ public class RubyJdbcConnection extends RubyObject {
3481
3502
  }
3482
3503
 
3483
3504
  protected RaiseException wrapException(final ThreadContext context, final SQLException exception, String message) {
3484
- return wrapSQLException(context, getJDBCError(context.runtime), exception, message);
3505
+ return wrapSQLException(context, getJDBCError(context), exception, message);
3485
3506
  }
3486
3507
 
3487
3508
  protected RaiseException wrapException(final ThreadContext context, final RubyClass errorClass, final SQLException exception) {
@@ -3502,8 +3523,8 @@ public class RubyJdbcConnection extends RubyObject {
3502
3523
  }
3503
3524
 
3504
3525
  protected final RaiseException newNoDatabaseError(final SQLException ex) {
3505
- final Ruby runtime = getRuntime();
3506
- return wrapException(runtime.getCurrentContext(), getNoDatabaseError(runtime), ex);
3526
+ var context = getRuntime().getCurrentContext();
3527
+ return wrapException(context, getNoDatabaseError(context), ex);
3507
3528
  }
3508
3529
 
3509
3530
  private IRubyObject convertJavaToRuby(final Object object) {
@@ -3562,14 +3583,14 @@ public class RubyJdbcConnection extends RubyObject {
3562
3583
  row[i] = connection.jdbcToRuby(context, runtime, column.index, column.type, resultSet);
3563
3584
  }
3564
3585
 
3565
- return RubyArray.newArrayNoCopy(context.runtime, row);
3586
+ return newArrayNoCopy(context, row);
3566
3587
  }
3567
3588
 
3568
3589
  private static IRubyObject mapRawRow(final ThreadContext context, final Ruby runtime,
3569
3590
  final ColumnData[] columns, final ResultSet resultSet,
3570
3591
  final RubyJdbcConnection connection) throws SQLException {
3571
3592
 
3572
- final RubyHash row = new RubyHash(runtime, columns.length);
3593
+ final RubyHash row = RubyHash.newHash(runtime);
3573
3594
 
3574
3595
  for ( int i = 0; i < columns.length; i++ ) {
3575
3596
  final ColumnData column = columns[i];
@@ -3583,13 +3604,13 @@ public class RubyJdbcConnection extends RubyObject {
3583
3604
  }
3584
3605
 
3585
3606
  protected static IRubyObject newResult(final ThreadContext context, ColumnData[] columns, IRubyObject rows) {
3586
- final RubyClass Result = getResult(context.runtime);
3607
+ final RubyClass Result = getResult(context);
3587
3608
  return Result.newInstance(context, columnsToArray(context, columns), rows, Block.NULL_BLOCK); // Result.new
3588
3609
  }
3589
3610
 
3590
3611
  protected static IRubyObject newEmptyResult(final ThreadContext context) {
3591
- final RubyClass Result = getResult(context.runtime);
3592
- return Result.newInstance(context, RubyArray.newEmptyArray(context.runtime), RubyArray.newEmptyArray(context.runtime), Block.NULL_BLOCK); // Result.new
3612
+ final RubyClass Result = getResult(context);
3613
+ return Result.newInstance(context, newEmptyArray(context), newEmptyArray(context), Block.NULL_BLOCK); // Result.new
3593
3614
  }
3594
3615
 
3595
3616
  private static RubyArray columnsToArray(ThreadContext context, ColumnData[] columns) {
@@ -3597,7 +3618,7 @@ public class RubyJdbcConnection extends RubyObject {
3597
3618
 
3598
3619
  for ( int i = 0; i < columns.length; i++ ) cols[i] = columns[i].getName(context);
3599
3620
 
3600
- return RubyArray.newArrayNoCopy(context.runtime, cols);
3621
+ return newArrayNoCopy(context, cols);
3601
3622
  }
3602
3623
 
3603
3624
  protected static final class TableName {