Skip to content

fix: module/class lookup deprecation #1192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/java/arjdbc/ArJdbcModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private static IRubyObject loadDriver(final ThreadContext context, final IRubyOb

final RubyModule jdbc = runtime.getModule("Jdbc");
if ( jdbc != null ) { // Jdbc::MySQL
final RubyModule constant = (RubyModule) jdbc.getConstantAt(constName);
final RubyModule constant = (RubyModule) jdbc.getConstant(constName);
if ( constant != null ) { // ::Jdbc::MySQL.load_driver :
if ( constant.respondsTo("load_driver") ) {
IRubyObject result = constant.callMethod("load_driver");
Expand Down
4 changes: 2 additions & 2 deletions src/java/arjdbc/jdbc/JdbcResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class JdbcResult extends RubyObject {
protected JdbcResult(ThreadContext context, RubyClass clazz, RubyJdbcConnection connection, ResultSet resultSet) throws SQLException {
super(context.runtime, clazz);

values = context.runtime.newArray();
values = RubyArray.newArray(context.runtime);
this.connection = connection;

final ResultSetMetaData resultMetaData = resultSet.getMetaData();
Expand Down Expand Up @@ -111,7 +111,7 @@ private void processResultSet(final ThreadContext context, final ResultSet resul
row[i] = connection.jdbcToRuby(context, runtime, i + 1, columnTypes[i], resultSet); // Result Set is 1 based
}

values.append(RubyArray.newArrayNoCopy(context.runtime, row));
values.push(RubyArray.newArrayNoCopy(context.runtime, row));
}
}

Expand Down
68 changes: 34 additions & 34 deletions src/java/arjdbc/jdbc/RubyJdbcConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public class RubyJdbcConnection extends RubyObject {

protected RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
super(runtime, metaClass);
attributeClass = runtime.getModule("ActiveModel").getClass("Attribute");
timeZoneClass = runtime.getModule("ActiveSupport").getClass("TimeWithZone");
attributeClass = (RubyClass) runtime.getModule("ActiveModel").getConstant("Attribute");
timeZoneClass = (RubyClass) runtime.getModule("ActiveSupport").getConstant("TimeWithZone");
}

private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
Expand All @@ -153,39 +153,39 @@ public static RubyClass createJdbcConnectionClass(final Ruby runtime) {
}

public static RubyClass getJdbcConnection(final Ruby runtime) {
return (RubyClass) getConnectionAdapters(runtime).getConstantAt("JdbcConnection");
return (RubyClass) getConnectionAdapters(runtime).getConstant("JdbcConnection");
}

protected static RubyModule ActiveRecord(ThreadContext context) {
return context.runtime.getModule("ActiveRecord");
}

public static RubyClass getBase(final Ruby runtime) {
return (RubyClass) runtime.getModule("ActiveRecord").getConstantAt("Base");
return (RubyClass) runtime.getModule("ActiveRecord").getConstant("Base");
}

/**
* @param runtime
* @return <code>ActiveRecord::Result</code>
*/
public static RubyClass getResult(final Ruby runtime) {
return (RubyClass) runtime.getModule("ActiveRecord").getConstantAt("Result");
return (RubyClass) runtime.getModule("ActiveRecord").getConstant("Result");
}

/**
* @param runtime
* @return <code>ActiveRecord::ConnectionAdapters</code>
*/
public static RubyModule getConnectionAdapters(final Ruby runtime) {
return (RubyModule) runtime.getModule("ActiveRecord").getConstantAt("ConnectionAdapters");
return (RubyModule) runtime.getModule("ActiveRecord").getConstant("ConnectionAdapters");
}

/**
* @param runtime
* @return <code>ActiveRecord::ConnectionAdapters::IndexDefinition</code>
*/
protected static RubyClass getIndexDefinition(final Ruby runtime) {
return getConnectionAdapters(runtime).getClass("IndexDefinition");
return (RubyClass) getConnectionAdapters(runtime).getConstant("IndexDefinition");
}

/**
Expand All @@ -194,31 +194,31 @@ protected static RubyClass getIndexDefinition(final Ruby runtime) {
* @note only since AR 4.2
*/
protected static RubyClass getForeignKeyDefinition(final Ruby runtime) {
return getConnectionAdapters(runtime).getClass("ForeignKeyDefinition");
return (RubyClass) getConnectionAdapters(runtime).getConstant("ForeignKeyDefinition");
}

/**
* @param runtime
* @return <code>ActiveRecord::JDBCError</code>
*/
protected static RubyClass getJDBCError(final Ruby runtime) {
return runtime.getModule("ActiveRecord").getClass("JDBCError");
return (RubyClass) runtime.getModule("ActiveRecord").getConstant("JDBCError");
}

/**
* @param runtime
* @return <code>ActiveRecord::ConnectionNotEstablished</code>
*/
protected static RubyClass getConnectionNotEstablished(final Ruby runtime) {
return runtime.getModule("ActiveRecord").getClass("ConnectionNotEstablished");
return (RubyClass) runtime.getModule("ActiveRecord").getConstant("ConnectionNotEstablished");
}

/**
* @param runtime
* @return <code>ActiveRecord::NoDatabaseError</code>
*/
protected static RubyClass getNoDatabaseError(final Ruby runtime) {
return runtime.getModule("ActiveRecord").getClass("NoDatabaseError");
return (RubyClass) runtime.getModule("ActiveRecord").getConstant("NoDatabaseError");
}

/**
Expand Down Expand Up @@ -351,7 +351,7 @@ protected void setTransactionIsolation(final ThreadContext context, final Connec
connection.setTransactionIsolation(level);
}
catch (SQLException e) {
RubyClass txError = ActiveRecord(context).getClass("TransactionIsolationError");
RubyClass txError = (RubyClass) ActiveRecord(context).getConstant("TransactionIsolationError");
if ( txError != null ) throw wrapException(context, txError, e);
throw e; // let it roll - will be wrapped into a JDBCError (non 4.0)
}
Expand Down Expand Up @@ -485,7 +485,7 @@ protected void releaseSavepoint(final Connection connection, final Savepoint sav
}

protected static RuntimeException newSavepointNotSetError(final ThreadContext context, final IRubyObject name, final String op) {
RubyClass StatementInvalid = ActiveRecord(context).getClass("StatementInvalid");
RubyClass StatementInvalid = (RubyClass) ActiveRecord(context).getConstant("StatementInvalid");
return context.runtime.newRaiseException(StatementInvalid, "could not " + op + " savepoint: '" + name + "' (not set)");
}

Expand All @@ -495,13 +495,13 @@ public IRubyObject marked_savepoint_names(final ThreadContext context) {
@SuppressWarnings("unchecked")
final Map<IRubyObject, Savepoint> savepoints = getSavepoints(false);
if ( savepoints != null ) {
final RubyArray names = context.runtime.newArray(savepoints.size());
final RubyArray names = RubyArray.newArray(context.runtime, savepoints.size());
for ( Map.Entry<IRubyObject, ?> entry : savepoints.entrySet() ) {
names.append( entry.getKey() ); // keys are RubyString instances
names.push( entry.getKey() ); // keys are RubyString instances
}
return names;
}
return context.runtime.newEmptyArray();
return RubyArray.newEmptyArray(context.runtime);
}

protected Map<IRubyObject, Savepoint> getSavepoints(final ThreadContext context) {
Expand Down Expand Up @@ -1071,7 +1071,7 @@ private IRubyObject doExecuteQueryRaw(final ThreadContext context,
if (hasResult) {
return mapToRawResult(context, connection, statement.getResultSet(), false);
}
return context.runtime.newEmptyArray();
return RubyArray.newEmptyArray(context.runtime);
}
catch (final SQLException e) {
debugErrorSQL(context, query);
Expand Down Expand Up @@ -1238,7 +1238,7 @@ public IRubyObject supported_data_types(final ThreadContext context) throws SQLE
public IRubyObject primary_keys(ThreadContext context, IRubyObject tableName) throws SQLException {
@SuppressWarnings("unchecked")
List<IRubyObject> primaryKeys = (List) primaryKeys(context, tableName.toString());
return context.runtime.newArray(primaryKeys);
return RubyArray.newArray(context.runtime, primaryKeys);
}

protected static final int PRIMARY_KEYS_COLUMN_NAME = 4;
Expand Down Expand Up @@ -1422,11 +1422,11 @@ context, caseConvertIdentifierForRails(metaData, columnName)
// orders, (since AR 3.2) where, type, using (AR 4.0)
};

indexes.append( IndexDefinition.newInstance(context, args, Block.NULL_BLOCK) ); // IndexDefinition.new
indexes.push( IndexDefinition.newInstance(context, args, Block.NULL_BLOCK) ); // IndexDefinition.new
}

// one or more columns can be associated with an index
if ( currentColumns != null ) currentColumns.append(rubyColumnName);
if ( currentColumns != null ) currentColumns.push(rubyColumnName);
}

return indexes;
Expand All @@ -1437,7 +1437,7 @@ context, caseConvertIdentifierForRails(metaData, columnName)

protected RubyClass getIndexDefinition(final ThreadContext context) {
final RubyClass adapterClass = adapter.getMetaClass();
IRubyObject IDef = adapterClass.getConstantAt("IndexDefinition");
IRubyObject IDef = adapterClass.getConstant("IndexDefinition");
return IDef != null ? (RubyClass) IDef : getIndexDefinition(context.runtime);
}

Expand Down Expand Up @@ -1493,7 +1493,7 @@ protected IRubyObject foreignKeys(final ThreadContext context, final String tabl
fKeys.add( FKDefinition.newInstance(context, from_table, to_table, options, Block.NULL_BLOCK) ); // ForeignKeyDefinition.new
}

return runtime.newArray(fKeys);
return RubyArray.newArray(runtime, fKeys);

} finally { close(fkInfoSet); }
});
Expand All @@ -1511,7 +1511,7 @@ protected String extractForeignKeyRule(final int rule) {

protected RubyClass getForeignKeyDefinition(final ThreadContext context) {
final RubyClass adapterClass = adapter.getMetaClass();
IRubyObject FKDef = adapterClass.getConstantAt("ForeignKeyDefinition");
IRubyObject FKDef = adapterClass.getConstant("ForeignKeyDefinition");
return FKDef != null ? (RubyClass) FKDef : getForeignKeyDefinition(context.runtime);
}

Expand Down Expand Up @@ -2008,10 +2008,10 @@ protected IRubyObject mapToResult(final ThreadContext context, final Connection
final ResultSet resultSet, final ColumnData[] columns) throws SQLException {
final Ruby runtime = context.runtime;

final RubyArray resultRows = runtime.newArray();
final RubyArray resultRows = RubyArray.newArray(runtime);

while (resultSet.next()) {
resultRows.append(mapRow(context, runtime, columns, resultSet, this));
resultRows.push(mapRow(context, runtime, columns, resultSet, this));
}

return newResult(context, columns, resultRows);
Expand Down Expand Up @@ -2372,7 +2372,7 @@ protected IRubyObject arrayToRuby(final ThreadContext context,
try {
if ( value == null ) return context.nil;

final RubyArray array = runtime.newArray();
final RubyArray array = RubyArray.newArray(runtime);

final ResultSet arrayResult = value.getResultSet(); // 1: index, 2: value
final int baseType = value.getBaseType();
Expand All @@ -2393,7 +2393,7 @@ protected IRubyObject arrayToRuby(final ThreadContext context,
}

while ( arrayResult.next() ) {
array.append( jdbcToRuby(context, runtime, 2, baseType, arrayResult) );
array.push( jdbcToRuby(context, runtime, 2, baseType, arrayResult) );
}
arrayResult.close();

Expand Down Expand Up @@ -3077,7 +3077,7 @@ protected RubyArray mapTables(final ThreadContext context, final Connection conn
final RubyArray tables = RubyArray.newArray(context.runtime);
while ( tablesSet.next() ) {
String name = tablesSet.getString(TABLES_TABLE_NAME);
tables.append( cachedString(context, caseConvertIdentifierForRails(connection, name)) );
tables.push( cachedString(context, caseConvertIdentifierForRails(connection, name)) );
}
return tables;
}
Expand Down Expand Up @@ -3158,7 +3158,7 @@ protected RubyArray mapColumnsResult(final ThreadContext context,
final IRubyObject[] args = new IRubyObject[] {
columnName, defaultValue, type_metadata, nullable, tableName
};
columns.append( Column.newInstance(context, args, Block.NULL_BLOCK) );
columns.push( Column.newInstance(context, args, Block.NULL_BLOCK) );
}
return columns;
}
Expand Down Expand Up @@ -3230,10 +3230,10 @@ protected final IRubyObject doMapGeneratedKeys(final Ruby runtime,
}
}

final RubyArray keys = runtime.newArray();
if ( firstKey != null ) keys.append(firstKey); // singleResult == null
final RubyArray keys = RubyArray.newArray(runtime);
if ( firstKey != null ) keys.push(firstKey); // singleResult == null
while ( next ) {
keys.append( mapGeneratedKey(runtime, genKeys) );
keys.push( mapGeneratedKey(runtime, genKeys) );
next = genKeys.next();
}
return keys;
Expand Down Expand Up @@ -3266,11 +3266,11 @@ private IRubyObject mapToRawResult(final ThreadContext context,
final ColumnData[] columns = extractColumns(context, connection, resultSet, downCase);

final Ruby runtime = context.runtime;
final RubyArray results = runtime.newArray();
final RubyArray results = RubyArray.newArray(runtime);
// [ { 'col1': 1, 'col2': 2 }, { 'col1': 3, 'col2': 4 } ]

while ( resultSet.next() ) {
results.append(mapRawRow(context, runtime, columns, resultSet, this));
results.push(mapRawRow(context, runtime, columns, resultSet, this));
}
return results;
}
Expand Down
Loading