4343
4444import arjdbc .jdbc .RubyJdbcConnection ;
4545import 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 ;
4649
4750/**
4851 * ::ArJdbc
5255public class ArJdbcModule {
5356
5457 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 );
5862 }
5963
6064 public static RubyModule get (final Ruby runtime ) {
@@ -142,7 +146,7 @@ public static IRubyObject load_java_part(final ThreadContext context,
142146 catch (NoSuchMethodException e ) {
143147 // "old" e.g. MySQLRubyJdbcConnection.createMySQLJdbcConnectionClass(runtime, jdbcConnection)
144148 connection .getMethod ("create" + moduleName + "JdbcConnectionClass" , Ruby .class , RubyClass .class ).
145- invoke (null , runtime , getJdbcConnection (runtime ));
149+ invoke (null , runtime , getJdbcConnection (context ));
146150 }
147151 }
148152 }
@@ -162,20 +166,19 @@ public static IRubyObject load_java_part(final ThreadContext context,
162166 */
163167 @ JRubyMethod (name = "modules" , meta = true )
164168 public static IRubyObject modules (final ThreadContext context , final IRubyObject self ) {
165- final Ruby runtime = context .getRuntime ();
166169 final RubyModule arJdbc = (RubyModule ) self ;
167170
168171 final Collection <String > constants = arJdbc .getConstantNames ();
169- final RubyArray modules = runtime . newArray ( constants .size () );
172+ final RubyArray modules = allocArray ( context , constants .size ());
170173
171174 for ( final String name : constants ) {
172- final IRubyObject constant = arJdbc .getConstant (name , false );
175+ final IRubyObject constant = arJdbc .getConstant (context , name , false );
173176 // isModule: return false for Ruby Classes
174177 if ( constant != null && constant .isModule () ) {
175178 if ( "Util" .equals (name ) ) continue ;
176179 if ( "SerializedAttributesHelper" .equals (name ) ) continue ; // deprecated
177180 if ( "Version" .equals (name ) ) continue ; // deprecated
178- modules .append ( constant );
181+ modules .append (context , constant );
179182 }
180183 }
181184 return modules ;
@@ -230,9 +233,9 @@ private static IRubyObject loadDriver(final ThreadContext context, final IRubyOb
230233 return null ;
231234 }
232235
233- final RubyModule jdbc = runtime . getModule ("Jdbc" );
236+ final RubyModule jdbc = getModule (context , "Jdbc" );
234237 if ( jdbc != null ) { // Jdbc::MySQL
235- final RubyModule constant = ( RubyModule ) jdbc .getConstantAt ( constName );
238+ final RubyModule constant = jdbc .getModule ( context , constName );
236239 if ( constant != null ) { // ::Jdbc::MySQL.load_driver :
237240 if ( constant .respondsTo ("load_driver" ) ) {
238241 IRubyObject result = constant .callMethod ("load_driver" );
0 commit comments