activerecord-jdbc-alt-adapter 72.1.0-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 (53) 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 +21 -18
  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 +30 -28
  16. data/lib/arjdbc/mssql/explain_support.rb +6 -1
  17. data/lib/arjdbc/mssql.rb +1 -1
  18. data/lib/arjdbc/postgresql/adapter.rb +4 -1
  19. data/lib/arjdbc/postgresql/database_statements.rb +45 -0
  20. data/lib/arjdbc/postgresql/schema_statements.rb +17 -0
  21. data/lib/arjdbc/sqlite3/adapter.rb +51 -7
  22. data/lib/arjdbc/sqlite3/database_statements.rb +26 -0
  23. data/lib/arjdbc/version.rb +1 -1
  24. data/pom.xml +3 -3
  25. data/rakelib/02-test.rake +1 -1
  26. data/rakelib/db.rake +5 -3
  27. data/rakelib/rails.rake +0 -1
  28. data/src/java/arjdbc/ArJdbcModule.java +13 -10
  29. data/src/java/arjdbc/db2/DB2Module.java +4 -4
  30. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +8 -9
  31. data/src/java/arjdbc/h2/H2Module.java +2 -1
  32. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +8 -7
  33. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +5 -6
  34. data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +4 -3
  35. data/src/java/arjdbc/jdbc/DriverWrapper.java +13 -8
  36. data/src/java/arjdbc/jdbc/JdbcResult.java +10 -7
  37. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +168 -154
  38. data/src/java/arjdbc/mssql/MSSQLModule.java +3 -3
  39. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +13 -9
  40. data/src/java/arjdbc/mysql/MySQLModule.java +3 -3
  41. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +25 -23
  42. data/src/java/arjdbc/oracle/OracleModule.java +2 -3
  43. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +22 -18
  44. data/src/java/arjdbc/postgresql/PostgreSQLModule.java +2 -3
  45. data/src/java/arjdbc/postgresql/PostgreSQLResult.java +24 -12
  46. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +16 -12
  47. data/src/java/arjdbc/sqlite3/SQLite3Module.java +2 -3
  48. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +78 -29
  49. data/src/java/arjdbc/util/DateTimeUtils.java +7 -5
  50. data/src/java/arjdbc/util/ObjectSupport.java +2 -2
  51. data/src/java/arjdbc/util/StringHelper.java +1 -1
  52. metadata +7 -6
  53. data/.travis.yml +0 -128
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArJdbc
4
+ module SQLite3
5
+ module DatabaseStatements
6
+ private
7
+
8
+ def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch:)
9
+ result = raw_connection.execute(sql)
10
+
11
+ count = 0
12
+ count = result.count if result.respond_to?(:count)
13
+
14
+ verified!
15
+ notification_payload[:row_count] = count
16
+ result
17
+ end
18
+
19
+ def cast_result(raw_result)
20
+ return ActiveRecord::Result.empty if raw_result.nil?
21
+
22
+ raw_result
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArJdbc
4
- VERSION = "72.1.0"
4
+ VERSION = "80.0.0.rc1"
5
5
  end
data/pom.xml CHANGED
@@ -12,7 +12,7 @@
12
12
  <url>http://github.com/jruby/activerecord-jdbc-adapter/wiki</url>
13
13
 
14
14
  <properties>
15
- <jruby.version>9.2.6.0</jruby.version>
15
+ <jruby.version>10.0.0.1</jruby.version>
16
16
  </properties>
17
17
 
18
18
  <issueManagement>
@@ -103,8 +103,8 @@
103
103
  <artifactId>maven-compiler-plugin</artifactId>
104
104
  <version>2.5.1</version>
105
105
  <configuration>
106
- <source>1.8</source>
107
- <target>1.8</target>
106
+ <source>21</source>
107
+ <target>21</target>
108
108
  </configuration>
109
109
  </plugin>
110
110
  </plugins>
data/rakelib/02-test.rake CHANGED
@@ -36,7 +36,7 @@ def test_task_for(adapter, options = {})
36
36
  test_task.libs = []
37
37
  if defined?(JRUBY_VERSION)
38
38
  test_task.libs << 'lib'
39
- test_task.libs << "jdbc-#{driver}/lib" if driver && File.exists?("jdbc-#{driver}/lib")
39
+ test_task.libs << "jdbc-#{driver}/lib" if driver && File.exist?("jdbc-#{driver}/lib")
40
40
  test_task.libs.push *FileList["activerecord-jdbc#{adapter}*/lib"]
41
41
  end
42
42
  test_task.libs << 'test'
data/rakelib/db.rake CHANGED
@@ -39,7 +39,7 @@ GRANT ALL PRIVILEGES ON `test\_%`.* TO #{MYSQL_CONFIG[:username]}@localhost;
39
39
  task :postgresql do
40
40
  require File.expand_path('../../test/shared_helper', __FILE__)
41
41
  fail 'could not create test database: psql executable not found' unless psql = which('psql')
42
- fail 'could not create test database: missing "postgres" role' unless PostgresHelper.postgres_role?
42
+ fail 'could not create test database: missing "arjdbc" role' unless PostgresHelper.postgres_role?
43
43
 
44
44
  load 'test/db/postgres_config.rb' # rescue nil
45
45
  puts POSTGRES_CONFIG.inspect if $VERBOSE
@@ -53,11 +53,13 @@ CREATE DATABASE #{POSTGRES_CONFIG[:database]} OWNER #{POSTGRES_CONFIG[:username]
53
53
  ENCODING '#{POSTGRES_CONFIG[:encoding]}' LC_COLLATE '#{POSTGRES_CONFIG[:collate]}' LC_CTYPE '#{POSTGRES_CONFIG[:collate]}';
54
54
  SQL
55
55
 
56
- params = { '-U' => ENV['PSQL_USER'] || 'postgres' }
56
+ params = { '-U' => ENV['PGUSER'] || 'arjdbc', '-d' => 'postgres' }
57
+ params['-h'] = ENV['PGHOST'] if ENV['PGHOST']
58
+ params['-p'] = ENV['PGPORT'] if ENV['PGPORT']
57
59
  params['-q'] = nil unless $VERBOSE
58
60
 
59
61
  puts "Creating PostgreSQL (test) database: #{POSTGRES_CONFIG[:database]}"
60
- sh "cat #{script.path} | #{psql} #{params.to_a.join(' ')}", verbose: $VERBOSE
62
+ sh "PGPASSWORD=#{ENV['PGPASSWORD'] || 'arjdbc'} cat #{script.path} | #{psql} #{params.to_a.join(' ')}", verbose: $VERBOSE
61
63
  end
62
64
  task postgres: :postgresql
63
65
 
data/rakelib/rails.rake CHANGED
@@ -58,7 +58,6 @@ namespace :rails do
58
58
  ruby_opts_string += " -C \"#{ar_path}\""
59
59
  ruby_opts_string += " -rbundler/setup"
60
60
  ruby_opts_string += " -rminitest -rminitest/excludes" unless ENV['NO_EXCLUDES'].eql?('true')
61
- ruby_opts_string += " -rmonkey_patches"
62
61
  file_list = ENV["TEST"] ? FileList[ ENV["TEST"].split(',') ] : test_files_finder.call
63
62
  file_list_string = file_list.map { |fn| "\"#{fn}\"" }.join(' ')
64
63
  # test_loader_code = "-e \"ARGV.each{|f| require f}\"" # :direct
@@ -43,6 +43,9 @@ import org.jruby.util.ByteList;
43
43
 
44
44
  import arjdbc.jdbc.RubyJdbcConnection;
45
45
  import static arjdbc.jdbc.RubyJdbcConnection.getJdbcConnection;
46
+ import static org.jruby.api.Access.getModule;
47
+ import static org.jruby.api.Access.objectClass;
48
+ import static org.jruby.api.Create.allocArray;
46
49
 
47
50
  /**
48
51
  * ::ArJdbc
@@ -52,9 +55,10 @@ import static arjdbc.jdbc.RubyJdbcConnection.getJdbcConnection;
52
55
  public class ArJdbcModule {
53
56
 
54
57
  public static RubyModule load(final Ruby runtime) {
55
- final RubyModule arJdbc = runtime.getOrCreateModule("ArJdbc");
56
- arJdbc.defineAnnotatedMethods( ArJdbcModule.class );
57
- return arJdbc;
58
+ var context = runtime.getCurrentContext();
59
+ return objectClass(context).
60
+ defineModuleUnder(context, "ArJdbc").
61
+ defineMethods(context, ArJdbcModule.class);
58
62
  }
59
63
 
60
64
  public static RubyModule get(final Ruby runtime) {
@@ -142,7 +146,7 @@ public class ArJdbcModule {
142
146
  catch (NoSuchMethodException e) {
143
147
  // "old" e.g. MySQLRubyJdbcConnection.createMySQLJdbcConnectionClass(runtime, jdbcConnection)
144
148
  connection.getMethod("create" + moduleName + "JdbcConnectionClass", Ruby.class, RubyClass.class).
145
- invoke(null, runtime, getJdbcConnection(runtime));
149
+ invoke(null, runtime, getJdbcConnection(context));
146
150
  }
147
151
  }
148
152
  }
@@ -162,20 +166,19 @@ public class ArJdbcModule {
162
166
  */
163
167
  @JRubyMethod(name = "modules", meta = true)
164
168
  public static IRubyObject modules(final ThreadContext context, final IRubyObject self) {
165
- final Ruby runtime = context.getRuntime();
166
169
  final RubyModule arJdbc = (RubyModule) self;
167
170
 
168
171
  final Collection<String> constants = arJdbc.getConstantNames();
169
- final RubyArray modules = runtime.newArray( constants.size() );
172
+ final RubyArray modules = allocArray(context, constants.size());
170
173
 
171
174
  for ( final String name : constants ) {
172
- final IRubyObject constant = arJdbc.getConstant(name, false);
175
+ final IRubyObject constant = arJdbc.getConstant(context, name, false);
173
176
  // isModule: return false for Ruby Classes
174
177
  if ( constant != null && constant.isModule() ) {
175
178
  if ( "Util".equals(name) ) continue;
176
179
  if ( "SerializedAttributesHelper".equals(name) ) continue; // deprecated
177
180
  if ( "Version".equals(name) ) continue; // deprecated
178
- modules.append( constant );
181
+ modules.append(context, constant);
179
182
  }
180
183
  }
181
184
  return modules;
@@ -230,9 +233,9 @@ public class ArJdbcModule {
230
233
  return null;
231
234
  }
232
235
 
233
- final RubyModule jdbc = runtime.getModule("Jdbc");
236
+ final RubyModule jdbc = getModule(context, "Jdbc");
234
237
  if ( jdbc != null ) { // Jdbc::MySQL
235
- final RubyModule constant = (RubyModule) jdbc.getConstantAt(constName);
238
+ final RubyModule constant = jdbc.getModule(context, constName);
236
239
  if ( constant != null ) { // ::Jdbc::MySQL.load_driver :
237
240
  if ( constant.respondsTo("load_driver") ) {
238
241
  IRubyObject result = constant.callMethod("load_driver");
@@ -26,6 +26,7 @@ package arjdbc.db2;
26
26
  import static arjdbc.util.QuotingUtils.BYTES_0;
27
27
  import static arjdbc.util.QuotingUtils.BYTES_1;
28
28
  import static arjdbc.util.QuotingUtils.quoteSingleQuotesWithFallback;
29
+ import static org.jruby.api.Create.newString;
29
30
 
30
31
  import org.jruby.Ruby;
31
32
  import org.jruby.RubyModule;
@@ -42,9 +43,8 @@ import org.jruby.runtime.builtin.IRubyObject;
42
43
  public class DB2Module {
43
44
 
44
45
  public static RubyModule load(final RubyModule arJdbc) {
45
- RubyModule db2 = arJdbc.defineModuleUnder("DB2");
46
- db2.defineAnnotatedMethods( DB2Module.class );
47
- return db2;
46
+ var context = arJdbc.getRuntime().getCurrentContext();
47
+ return arJdbc.defineModuleUnder(context, "DB2").defineMethods(context, DB2Module.class);
48
48
  }
49
49
 
50
50
  public static RubyModule load(final Ruby runtime) {
@@ -63,7 +63,7 @@ public class DB2Module {
63
63
  public static IRubyObject quoted_true(
64
64
  final ThreadContext context,
65
65
  final IRubyObject self) {
66
- return RubyString.newString(context.runtime, BYTES_1);
66
+ return newString(context, BYTES_1);
67
67
  }
68
68
 
69
69
  @JRubyMethod(name = "quoted_false", required = 0, frame = false)
@@ -54,17 +54,16 @@ public class DB2RubyJdbcConnection extends RubyJdbcConnection {
54
54
  super(runtime, metaClass);
55
55
  }
56
56
 
57
- public static RubyClass createDB2JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
58
- RubyClass clazz = getConnectionAdapters(runtime).
59
- defineClassUnder("DB2JdbcConnection", jdbcConnection, ALLOCATOR);
60
- clazz.defineAnnotatedMethods(DB2RubyJdbcConnection.class);
61
-
62
- return clazz;
57
+ public static RubyClass createDB2JdbcConnectionClass(ThreadContext context, RubyClass jdbcConnection) {
58
+ return getConnectionAdapters(context).
59
+ defineClassUnder(context, "DB2JdbcConnection", jdbcConnection, ALLOCATOR).
60
+ defineMethods(context, DB2RubyJdbcConnection.class);
63
61
  }
64
62
 
65
63
  public static RubyClass load(final Ruby runtime) {
66
- RubyClass jdbcConnection = getJdbcConnection(runtime);
67
- return createDB2JdbcConnectionClass(runtime, jdbcConnection);
64
+ var context = runtime.getCurrentContext();
65
+ RubyClass jdbcConnection = getJdbcConnection(context);
66
+ return createDB2JdbcConnectionClass(context, jdbcConnection);
68
67
  }
69
68
 
70
69
  protected static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
@@ -112,7 +111,7 @@ public class DB2RubyJdbcConnection extends RubyJdbcConnection {
112
111
  try {
113
112
  statement = connection.prepareStatement("VALUES IDENTITY_VAL_LOCAL()");
114
113
  genKeys = statement.executeQuery();
115
- return doMapGeneratedKeys(context.runtime, genKeys, true);
114
+ return doMapGeneratedKeys(context, genKeys, true);
116
115
  }
117
116
  catch (final SQLException e) {
118
117
  debugMessage(context.runtime, "failed to get generated keys: ", e);
@@ -37,7 +37,8 @@ import org.jruby.RubyModule;
37
37
  public class H2Module {
38
38
 
39
39
  public static RubyModule load(final RubyModule arJdbc) {
40
- RubyModule h2 = arJdbc.defineModuleUnder("H2");
40
+ var context = arJdbc.getRuntime().getCurrentContext();
41
+ RubyModule h2 = arJdbc.defineModuleUnder(context, "H2");
41
42
  // NOTE: currently no Java implemented Ruby methods
42
43
  // h2.defineAnnotatedMethods( H2Module.class );
43
44
  return h2;
@@ -28,9 +28,11 @@ package arjdbc.h2;
28
28
  import java.sql.Connection;
29
29
  import java.sql.SQLException;
30
30
 
31
+ import arjdbc.db2.DB2RubyJdbcConnection;
31
32
  import org.jruby.Ruby;
32
33
  import org.jruby.RubyClass;
33
34
  import org.jruby.runtime.ObjectAllocator;
35
+ import org.jruby.runtime.ThreadContext;
34
36
  import org.jruby.runtime.builtin.IRubyObject;
35
37
 
36
38
  /**
@@ -45,16 +47,15 @@ public class H2RubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection {
45
47
  super(runtime, metaClass);
46
48
  }
47
49
 
48
- public static RubyClass createH2JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
49
- RubyClass clazz = getConnectionAdapters(runtime).
50
- defineClassUnder("H2JdbcConnection", jdbcConnection, ALLOCATOR);
51
- clazz.defineAnnotatedMethods(H2RubyJdbcConnection.class);
52
- return clazz;
50
+ public static RubyClass createH2JdbcConnectionClass(ThreadContext context, RubyClass jdbcConnection) {
51
+ return getConnectionAdapters(context).
52
+ defineClassUnder(context, "H2JdbcConnection", jdbcConnection, ALLOCATOR).
53
+ defineMethods(context, H2RubyJdbcConnection.class);
53
54
  }
54
55
 
55
56
  public static RubyClass load(final Ruby runtime) {
56
- RubyClass jdbcConnection = getJdbcConnection(runtime);
57
- return createH2JdbcConnectionClass(runtime, jdbcConnection);
57
+ var context = runtime.getCurrentContext();
58
+ return createH2JdbcConnectionClass(context, getJdbcConnection(context));
58
59
  }
59
60
 
60
61
  protected static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
@@ -28,10 +28,10 @@ package arjdbc.hsqldb;
28
28
  import static arjdbc.util.QuotingUtils.BYTES_0;
29
29
  import static arjdbc.util.QuotingUtils.BYTES_1;
30
30
  import static arjdbc.util.QuotingUtils.quoteSingleQuotesWithFallback;
31
+ import static org.jruby.api.Create.newString;
31
32
 
32
33
  import org.jruby.Ruby;
33
34
  import org.jruby.RubyModule;
34
- import org.jruby.RubyString;
35
35
  import org.jruby.anno.JRubyMethod;
36
36
  import org.jruby.runtime.ThreadContext;
37
37
  import org.jruby.runtime.builtin.IRubyObject;
@@ -39,9 +39,8 @@ import org.jruby.runtime.builtin.IRubyObject;
39
39
  public class HSQLDBModule {
40
40
 
41
41
  public static RubyModule load(final RubyModule arJdbc) {
42
- RubyModule hsqldb = arJdbc.defineModuleUnder("HSQLDB");
43
- hsqldb.defineAnnotatedMethods( HSQLDBModule.class );
44
- return hsqldb;
42
+ var context = arJdbc.getRuntime().getCurrentContext();
43
+ return arJdbc.defineModuleUnder(context, "HSQLDB").defineMethods(context, HSQLDBModule.class);
45
44
  }
46
45
 
47
46
  public static RubyModule load(final Ruby runtime) {
@@ -60,14 +59,14 @@ public class HSQLDBModule {
60
59
  public static IRubyObject quoted_true(
61
60
  final ThreadContext context,
62
61
  final IRubyObject self) {
63
- return RubyString.newString(context.getRuntime(), BYTES_1);
62
+ return newString(context, BYTES_1);
64
63
  }
65
64
 
66
65
  @JRubyMethod(name = "quoted_false", required = 0, frame = false)
67
66
  public static IRubyObject quoted_false(
68
67
  final ThreadContext context,
69
68
  final IRubyObject self) {
70
- return RubyString.newString(context.getRuntime(), BYTES_0);
69
+ return newString(context, BYTES_0);
71
70
  }
72
71
 
73
72
  }
@@ -36,6 +36,7 @@ import org.jruby.util.SafePropertyAccessor;
36
36
 
37
37
  import static arjdbc.jdbc.RubyJdbcConnection.getConnectionNotEstablished;
38
38
  import static arjdbc.jdbc.RubyJdbcConnection.wrapException;
39
+ import static org.jruby.api.Access.runtimeErrorClass;
39
40
 
40
41
  /**
41
42
  *
@@ -103,7 +104,7 @@ final class DataSourceConnectionFactory implements ConnectionFactory {
103
104
  if ( ! ( bound instanceof DataSource ) ) {
104
105
  if ( bound == null ) throw new NameNotFoundException(); // unlikely to happen
105
106
  final String msg = "bound object at '" + name + "' is not a " + DataSource.class.getName() + " but a " + bound.getClass().getName() + "\n" + bound;
106
- throw wrapException(context, getConnectionNotEstablished(context.runtime), new ClassCastException(msg), msg);
107
+ throw wrapException(context, getConnectionNotEstablished(context), new ClassCastException(msg), msg);
107
108
  }
108
109
  return (DataSource) bound;
109
110
  }
@@ -124,10 +125,10 @@ final class DataSourceConnectionFactory implements ConnectionFactory {
124
125
  else {
125
126
  message = "unable to lookup data source - name: '" + name + "' not found";
126
127
  }
127
- throw wrapException(context, getConnectionNotEstablished(context.runtime), e, message);
128
+ throw wrapException(context, getConnectionNotEstablished(context), e, message);
128
129
  }
129
130
  catch (NamingException e) {
130
- throw wrapException(context, context.runtime.getRuntimeError(), e);
131
+ throw wrapException(context, runtimeErrorClass(context), e);
131
132
  }
132
133
  }
133
134
 
@@ -23,6 +23,7 @@
23
23
  */
24
24
  package arjdbc.jdbc;
25
25
 
26
+ import java.lang.reflect.InvocationTargetException;
26
27
  import java.sql.Connection;
27
28
  import java.sql.Driver;
28
29
  import java.sql.SQLException;
@@ -45,7 +46,7 @@ public class DriverWrapper {
45
46
  private final Properties properties;
46
47
 
47
48
  DriverWrapper(final Ruby runtime, final String name, final Properties properties)
48
- throws ClassCastException, InstantiationException, IllegalAccessException {
49
+ throws ClassCastException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
49
50
  this.driver = allocateDriver( loadDriver(runtime, name) );
50
51
  this.properties = properties == null ? new Properties() : properties;
51
52
  }
@@ -59,18 +60,22 @@ public class DriverWrapper {
59
60
  }
60
61
 
61
62
  private Driver allocateDriver(final Class<? extends Driver> driverClass)
62
- throws InstantiationException, IllegalAccessException {
63
- return driverClass.newInstance();
63
+ throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
64
+ return driverClass.getDeclaredConstructor().newInstance();
64
65
  }
65
66
 
66
67
  protected static Class<? extends Driver> loadDriver(final Ruby runtime, final String name)
67
68
  throws ClassCastException {
68
- @SuppressWarnings("unchecked")
69
- Class<? extends Driver> klass = runtime.getJavaSupport().loadJavaClassVerbose(name);
70
- if ( ! Driver.class.isAssignableFrom(klass) ) {
71
- throw new ClassCastException(klass + " is not assignable from " + Driver.class);
69
+ try {
70
+ @SuppressWarnings("unchecked")
71
+ Class<? extends Driver> klass = (Class<? extends Driver>) runtime.getJavaSupport().loadJavaClass(name);
72
+ if ( ! Driver.class.isAssignableFrom(klass) ) {
73
+ throw new ClassCastException(klass + " is not assignable from " + Driver.class);
74
+ }
75
+ return klass;
76
+ } catch (ClassNotFoundException e) {
77
+ throw new RuntimeException("Cannot load driver class: " + name, e);
72
78
  }
73
- return klass;
74
79
  }
75
80
 
76
81
  public Connection connect(final String url, final String user, final String pass)
@@ -14,6 +14,10 @@ import org.jruby.runtime.Block;
14
14
  import org.jruby.runtime.ThreadContext;
15
15
  import org.jruby.runtime.builtin.IRubyObject;
16
16
 
17
+ import static org.jruby.api.Create.newArray;
18
+ import static org.jruby.api.Create.newArrayNoCopy;
19
+ import static org.jruby.api.Create.newHash;
20
+
17
21
  /**
18
22
  * This is a base Result class to be returned as the "raw" result.
19
23
  * It should be overridden for specific adapters to manage type maps
@@ -31,7 +35,7 @@ public class JdbcResult extends RubyObject {
31
35
  protected JdbcResult(ThreadContext context, RubyClass clazz, RubyJdbcConnection connection, ResultSet resultSet) throws SQLException {
32
36
  super(context.runtime, clazz);
33
37
 
34
- values = context.runtime.newArray();
38
+ values = newArray(context);
35
39
  this.connection = connection;
36
40
 
37
41
  final ResultSetMetaData resultMetaData = resultSet.getMetaData();
@@ -86,7 +90,7 @@ public class JdbcResult extends RubyObject {
86
90
 
87
91
  for (int i = 0; i < tuples.length; i++) {
88
92
  RubyArray currentRow = (RubyArray) values.eltInternal(i);
89
- RubyHash hash = RubyHash.newHash(context.runtime);
93
+ RubyHash hash = newHash(context);
90
94
  for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
91
95
  hash.fastASet(columnNames[columnIndex], currentRow.eltInternal(columnIndex));
92
96
  }
@@ -101,17 +105,16 @@ public class JdbcResult extends RubyObject {
101
105
  * @throws SQLException throws!
102
106
  */
103
107
  private void processResultSet(final ThreadContext context, final ResultSet resultSet) throws SQLException {
104
- Ruby runtime = context.runtime;
105
108
  int columnCount = columnNames.length;
106
109
 
107
110
  while (resultSet.next()) {
108
111
  final IRubyObject[] row = new IRubyObject[columnCount];
109
112
 
110
113
  for (int i = 0; i < columnCount; i++) {
111
- row[i] = connection.jdbcToRuby(context, runtime, i + 1, columnTypes[i], resultSet); // Result Set is 1 based
114
+ row[i] = connection.jdbcToRuby(context, context.runtime, i + 1, columnTypes[i], resultSet); // Result Set is 1 based
112
115
  }
113
116
 
114
- values.append(RubyArray.newArrayNoCopy(context.runtime, row));
117
+ values.append(context, newArrayNoCopy(context, row));
115
118
  }
116
119
  }
117
120
 
@@ -122,9 +125,9 @@ public class JdbcResult extends RubyObject {
122
125
  * @throws SQLException can be caused by postgres generating its type map
123
126
  */
124
127
  public IRubyObject toARResult(final ThreadContext context) throws SQLException {
125
- final RubyClass Result = RubyJdbcConnection.getResult(context.runtime);
128
+ final RubyClass Result = RubyJdbcConnection.getResult(context);
126
129
  // FIXME: Is this broken? no copy of an array AR::Result can modify? or should it be frozen?
127
- final RubyArray rubyColumnNames = RubyArray.newArrayNoCopy(context.runtime, getColumnNames());
130
+ final RubyArray rubyColumnNames = newArrayNoCopy(context, getColumnNames());
128
131
  return Result.newInstance(context, rubyColumnNames, values, columnTypeMap(context), Block.NULL_BLOCK);
129
132
  }
130
133
  }