Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,7 @@ public interface JdbcLogging extends BasicLogger {
@Message(value = "Could not obtain connection to query JDBC database metadata", id = 100046)
void unableToObtainConnectionToQueryMetadata(@Cause Exception e);

@LogMessage(level = TRACE)
@Message(value = "AutoCommit was initially %s", id = 100047)
void initialAutoCommit(boolean wasInitiallyAutoCommit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ static Logger subLogger(String subName) {
return Logger.getLogger( subLoggerName( subName ) );
}

static <T> T subLogger(String subName, Class<T> loggerJavaType) {
return Logger.getMessageLogger( MethodHandles.lookup(), loggerJavaType, subLoggerName( subName ) );
}

@LogMessage(level = ERROR)
@Message(value = "Error in named query: %s", id = 90003001)
void namedQueryError(String queryName, @Cause HibernateException e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.hibernate.resource.jdbc.spi.PhysicalJdbcTransaction;
import org.hibernate.resource.transaction.spi.TransactionStatus;

import static org.hibernate.resource.jdbc.internal.LogicalConnectionLogging.LOGGER;
import static org.hibernate.resource.jdbc.internal.LogicalConnectionLogging.CONNECTION_LOGGER;

/**
* Base support for {@link LogicalConnection} implementations
Expand Down Expand Up @@ -64,9 +64,9 @@ public void afterTransaction() {
public void begin() {
try {
if ( !doConnectionsFromProviderHaveAutoCommitDisabled() ) {
LOGGER.preparingToBeginViaSetAutoCommitFalse();
CONNECTION_LOGGER.preparingToBeginViaSetAutoCommitFalse();
getConnectionForTransactionManagement().setAutoCommit( false );
LOGGER.transactionBegunViaSetAutoCommitFalse();
CONNECTION_LOGGER.transactionBegunViaSetAutoCommitFalse();
}
status = TransactionStatus.ACTIVE;
}
Expand All @@ -78,7 +78,7 @@ public void begin() {
@Override
public void commit() {
try {
LOGGER.preparingToCommitViaConnectionCommit();
CONNECTION_LOGGER.preparingToCommitViaConnectionCommit();
status = TransactionStatus.COMMITTING;
if ( isPhysicallyConnected() ) {
getConnectionForTransactionManagement().commit();
Expand All @@ -87,7 +87,7 @@ public void commit() {
errorIfClosed();
}
status = TransactionStatus.COMMITTED;
LOGGER.transactionCommittedViaConnectionCommit();
CONNECTION_LOGGER.transactionCommittedViaConnectionCommit();
}
catch( SQLException e ) {
status = TransactionStatus.FAILED_COMMIT;
Expand All @@ -104,20 +104,20 @@ protected void afterCompletion() {
protected void resetConnection(boolean initiallyAutoCommit) {
try {
if ( initiallyAutoCommit ) {
LOGGER.reenablingAutoCommitAfterJdbcTransaction();
CONNECTION_LOGGER.reenablingAutoCommitAfterJdbcTransaction();
getConnectionForTransactionManagement().setAutoCommit( true );
status = TransactionStatus.NOT_ACTIVE;
}
}
catch ( Exception e ) {
LOGGER.couldNotReEnableAutoCommit( e );
CONNECTION_LOGGER.couldNotReEnableAutoCommit( e );
}
}

@Override
public void rollback() {
try {
LOGGER.preparingToRollbackViaConnectionRollback();
CONNECTION_LOGGER.preparingToRollbackViaConnectionRollback();
status = TransactionStatus.ROLLING_BACK;
if ( isPhysicallyConnected() ) {
getConnectionForTransactionManagement().rollback();
Expand All @@ -126,7 +126,7 @@ public void rollback() {
errorIfClosed();
}
status = TransactionStatus.ROLLED_BACK;
LOGGER.transactionRolledBackViaConnectionRollback();
CONNECTION_LOGGER.transactionRolledBackViaConnectionRollback();
}
catch( SQLException e ) {
status = TransactionStatus.FAILED_ROLLBACK;
Expand All @@ -141,7 +141,7 @@ protected static boolean determineInitialAutoCommitMode(Connection providedConne
return providedConnection.getAutoCommit();
}
catch (SQLException e) {
LOGGER.unableToAscertainInitialAutoCommit();
CONNECTION_LOGGER.unableToAscertainInitialAutoCommit();
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@Internal
public interface LogicalConnectionLogging extends BasicLogger {
String LOGGER_NAME = SubSystemLogging.BASE + ".resource.jdbc";
LogicalConnectionLogging LOGGER = Logger.getMessageLogger(
LogicalConnectionLogging CONNECTION_LOGGER = Logger.getMessageLogger(
MethodHandles.lookup(), LogicalConnectionLogging.class, LOGGER_NAME
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.hibernate.ConnectionReleaseMode.AFTER_STATEMENT;
import static org.hibernate.ConnectionReleaseMode.BEFORE_TRANSACTION_COMPLETION;
import static org.hibernate.ConnectionReleaseMode.ON_CLOSE;
import static org.hibernate.resource.jdbc.internal.LogicalConnectionLogging.LOGGER;
import static org.hibernate.resource.jdbc.internal.LogicalConnectionLogging.CONNECTION_LOGGER;
import static org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION;

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ public LogicalConnectionManagedImpl(JdbcSessionOwner sessionOwner, ResourceRegis
}

if ( sessionOwner.getJdbcSessionContext().doesConnectionProviderDisableAutoCommit() ) {
LOGGER.connectionProviderDisablesAutoCommitEnabled();
CONNECTION_LOGGER.connectionProviderDisablesAutoCommitEnabled();
}
}

Expand Down Expand Up @@ -131,10 +131,10 @@ public void afterStatement() {
super.afterStatement();
if ( connectionHandlingMode.getReleaseMode() == AFTER_STATEMENT ) {
if ( getResourceRegistry().hasRegisteredResources() ) {
LOGGER.skipConnectionReleaseAfterStatementDueToResources( hashCode() );
CONNECTION_LOGGER.skipConnectionReleaseAfterStatementDueToResources( hashCode() );
}
else {
LOGGER.initiatingConnectionReleaseAfterStatement( hashCode() );
CONNECTION_LOGGER.initiatingConnectionReleaseAfterStatement( hashCode() );
releaseConnectionIfNeeded();
}
}
Expand All @@ -144,7 +144,7 @@ public void afterStatement() {
public void beforeTransactionCompletion() {
super.beforeTransactionCompletion();
if ( connectionHandlingMode.getReleaseMode() == BEFORE_TRANSACTION_COMPLETION ) {
LOGGER.initiatingConnectionReleaseBeforeTransactionCompletion( hashCode() );
CONNECTION_LOGGER.initiatingConnectionReleaseBeforeTransactionCompletion( hashCode() );
releaseConnectionIfNeeded();
}
}
Expand All @@ -157,7 +157,7 @@ public void afterTransaction() {
// - AFTER_STATEMENT cases that were circumvented due to held resources
// - BEFORE_TRANSACTION_COMPLETION cases that were circumvented because a rollback occurred
// (we don't get a beforeTransactionCompletion event on rollback).
LOGGER.initiatingConnectionReleaseAfterTransaction( hashCode() );
CONNECTION_LOGGER.initiatingConnectionReleaseAfterTransaction( hashCode() );
releaseConnectionIfNeeded();
}
}
Expand Down Expand Up @@ -238,7 +238,7 @@ private void beforeRelease() {
jdbcSessionOwner.beforeReleaseConnection( physicalConnection );
}
catch (SQLException e) {
LOGGER.errorBeforeReleasingJdbcConnection( hashCode(), e );
CONNECTION_LOGGER.errorBeforeReleasingJdbcConnection( hashCode(), e );
}
}

Expand All @@ -256,14 +256,14 @@ public static LogicalConnectionManagedImpl deserialize(ObjectInputStream ois, Jd
public Connection close() {
if ( !closed ) {
getResourceRegistry().releaseResources();
LOGGER.closingLogicalConnection( hashCode() );
CONNECTION_LOGGER.closingLogicalConnection( hashCode() );
try {
releaseConnectionIfNeeded();
}
finally {
// no matter what
closed = true;
LOGGER.logicalConnectionClosed( hashCode() );
CONNECTION_LOGGER.logicalConnectionClosed( hashCode() );
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.io.ObjectOutputStream;
import java.sql.Connection;

import static org.hibernate.resource.jdbc.internal.LogicalConnectionLogging.LOGGER;
import static org.hibernate.resource.jdbc.internal.LogicalConnectionLogging.CONNECTION_LOGGER;
import org.hibernate.resource.jdbc.ResourceRegistry;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;

Expand Down Expand Up @@ -51,15 +51,15 @@ public boolean isOpen() {

@Override
public Connection close() {
LOGGER.closingLogicalConnection();
CONNECTION_LOGGER.closingLogicalConnection();
getResourceRegistry().releaseResources();
try {
return providedConnection;
}
finally {
providedConnection = null;
closed = true;
LOGGER.logicalConnectionClosed();
CONNECTION_LOGGER.logicalConnectionClosed();
}
}

Expand Down Expand Up @@ -107,15 +107,15 @@ public void manualReconnect(Connection connection) {
}
else if ( connection == providedConnection ) {
// likely an unmatched reconnect call (no matching disconnect call)
LOGGER.reconnectingSameConnectionAlreadyConnected();
CONNECTION_LOGGER.reconnectingSameConnectionAlreadyConnected();
}
else if ( providedConnection != null ) {
throw new IllegalArgumentException(
"Cannot reconnect to a new user-supplied connection because currently connected; must disconnect before reconnecting."
);
}
providedConnection = connection;
LOGGER.manuallyReconnectedLogicalConnection();
CONNECTION_LOGGER.manuallyReconnectedLogicalConnection();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public void prepare() {
@Override
public void accept(String command) {
try {
writer().write( command );
writer().write( System.lineSeparator() );
writer().flush();
final var writer = writer();
writer.write( command );
writer.write( System.lineSeparator() );
writer.flush();
}
catch (IOException e) {
throw new CommandAcceptanceException( "Could not write \"" + command + "\" to target script file", e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ public void accept(String command) {
getSqlStatementLogger().logStatement( command, FormatStyle.NONE.getFormatter() );

try {
final Statement jdbcStatement = jdbcStatement();
jdbcStatement.execute( command );
final var statement = jdbcStatement();
statement.execute( command );

try {
SQLWarning warnings = jdbcStatement.getWarnings();
SQLWarning warnings = statement.getWarnings();
if ( warnings != null) {
getSqlExceptionHelper().logAndClearWarnings( jdbcStatement );
getSqlExceptionHelper().logAndClearWarnings( statement );
}
}
catch( SQLException e ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public void prepare() {

@Override
public void accept(String command) {
if ( delimiter != null ) {
command += delimiter;
}
scriptTarget.accept( command );
scriptTarget.accept( delimiter == null ? command : command + delimiter );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public void prepare() {
@Override
@AllowSysOut
public void accept(String command) {
if ( delimiter != null ) {
command += delimiter;
}
System.out.println( command );
System.out.println( delimiter == null ? command : command + delimiter );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;

import org.jboss.logging.Logger;

import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_LOGGER;

/**
Expand All @@ -22,7 +20,6 @@
* @author Steve Ebersole
*/
public class JdbcConnectionAccessConnectionProviderImpl implements JdbcConnectionAccess {
private static final Logger LOG = Logger.getLogger( JdbcConnectionAccessConnectionProviderImpl.class );

private final ConnectionProvider connectionProvider;
private final Connection jdbcConnection;
Expand All @@ -32,7 +29,7 @@ public JdbcConnectionAccessConnectionProviderImpl(ConnectionProvider connectionP
this.connectionProvider = connectionProvider;

try {
this.jdbcConnection = connectionProvider.getConnection();
jdbcConnection = connectionProvider.getConnection();
}
catch (SQLException e) {
throw new PersistenceException( "Unable to obtain JDBC Connection", e );
Expand Down Expand Up @@ -61,7 +58,7 @@ public JdbcConnectionAccessConnectionProviderImpl(ConnectionProvider connectionP
wasInitiallyAutoCommit = false;
}

LOG.tracef( "wasInitiallyAutoCommit=%s", wasInitiallyAutoCommit );
JDBC_LOGGER.initialAutoCommit( wasInitiallyAutoCommit );
this.wasInitiallyAutoCommit = wasInitiallyAutoCommit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;

import org.jboss.logging.Logger;

import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_LOGGER;

/**
Expand All @@ -21,7 +19,6 @@
* @author Steve Ebersole
*/
public class JdbcConnectionAccessProvidedConnectionImpl implements JdbcConnectionAccess {
private static final Logger LOG = Logger.getLogger( JdbcConnectionAccessProvidedConnectionImpl.class );

private final Connection jdbcConnection;
private final boolean wasInitiallyAutoCommit;
Expand Down Expand Up @@ -52,7 +49,7 @@ public JdbcConnectionAccessProvidedConnectionImpl(Connection jdbcConnection) {
wasInitiallyAutoCommit = false;
}

LOG.tracef( "wasInitiallyAutoCommit=%s", wasInitiallyAutoCommit );
JDBC_LOGGER.initialAutoCommit( wasInitiallyAutoCommit );
this.wasInitiallyAutoCommit = wasInitiallyAutoCommit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public List<String> extract(Function<Reader, List<String>> extractor) {
final List<String>[] lists = new List[inputs.length];
int size = 0;
for ( int i = 0; i < inputs.length; i++ ) {
final AbstractScriptSourceInput scriptSourceInput = inputs[i];
final var scriptSourceInput = inputs[i];
if ( scriptSourceInput.exists() ) {
final Reader reader = scriptSourceInput.prepareReader();
final var reader = scriptSourceInput.prepareReader();
try {
CORE_LOGGER.executingScript( scriptSourceInput.getScriptDescription() );
lists[i] = extractor.apply( reader );
Expand All @@ -62,8 +62,8 @@ public List<String> extract(Function<Reader, List<String>> extractor) {

@Override
public boolean containsScript(URL url) {
for ( int i = 0; i < inputs.length; i++ ) {
if ( inputs[i].containsScript( url ) ) {
for ( var input : inputs ) {
if ( input.containsScript( url ) ) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ private static Reader toReader(File file, String charsetName) {
LOG.warnf( "Specified schema generation script file [%s] did not exist for reading", file );
return new Reader() {
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
public int read(char[] cbuf, int off, int len) {
return -1;
}

@Override
public void close() throws IOException {
public void close() {
}
};
}
Expand Down
Loading