Skip to content

Commit

Permalink
Mysql, fix active? method, it was forcing to reconnect when it should…
Browse files Browse the repository at this point in the history
… not
  • Loading branch information
JesseChavez committed Aug 6, 2024
1 parent c24b09b commit cb0498d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/arjdbc/abstract/database_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def convert_legacy_binds_to_attributes(binds)
end
end

def raw_execute(sql, name, async: false, allow_retry: false, materialize_transactions: false)
def raw_execute(sql, name, async: false, allow_retry: false, materialize_transactions: true)
log(sql, name, async: async) do
with_raw_connection(allow_retry: allow_retry, materialize_transactions: materialize_transactions) do |conn|
conn.execute(sql)
Expand Down
2 changes: 1 addition & 1 deletion lib/arjdbc/mysql/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _quote(value)
#++

def active?
!(@raw_connection.nil? || @raw_connection.closed?) && @lock.synchronize { @raw_connection&.execute_query("/* ping */ SELECT 1") } || false
!(@raw_connection.nil? || @raw_connection.closed?) && @lock.synchronize { @raw_connection&.ping } || false
end

alias :reset! :reconnect!
Expand Down
11 changes: 11 additions & 0 deletions src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ protected DriverWrapper newDriverWrapper(final ThreadContext context, final Stri
return driverWrapper;
}

@JRubyMethod(name = "ping")
public RubyBoolean db_ping(final ThreadContext context) {
final Connection connection = getConnection(true);
if (connection == null) return context.fals;

// NOTE: It seems only `connection.isValid(aliveTimeout)` is needed
// for JDBC 4.0 and up. https://jira.mariadb.org/browse/CONJ-51

return context.runtime.newBoolean(isConnectionValid(context, connection));
}

private static transient Class MYSQL_CONNECTION;
private static transient Boolean MYSQL_CONNECTION_FOUND;

Expand Down

0 comments on commit cb0498d

Please sign in to comment.