Skip to content

Commit 605b5cb

Browse files
committed
more improvements to JDBC-related logging
1 parent 4b60941 commit 605b5cb

File tree

9 files changed

+57
-33
lines changed

9 files changed

+57
-33
lines changed

hibernate-core/src/main/java/org/hibernate/engine/jdbc/JdbcLogging.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,40 +140,48 @@ public interface JdbcLogging extends BasicLogger {
140140
id = 100018)
141141
void logDriverInfo(String name, String version, int major, int minor, int jdbcMajor, int jdbcMinor);
142142

143-
@LogMessage(level = TRACE)
144-
@Message(value = "Unable to reset connection back to auto-commit", id = 100019)
145-
void unableToResetAutoCommit(@Cause Exception ignored);
146-
147143
@LogMessage(level = INFO)
148144
@Message(value = "Unable to release isolated connection", id = 100020)
149145
void unableToReleaseIsolatedConnection(@Cause Exception ignored);
150146

147+
@LogMessage(level = DEBUG)
148+
@Message(value = "Unable to release connection", id = 100021)
149+
void unableToReleaseConnection(@Cause Exception ignored);
150+
151151
@LogMessage(level = INFO)
152-
@Message(value = "Unable to roll back isolated connection on exception ", id = 100021)
152+
@Message(value = "Unable to roll back isolated connection on exception ", id = 100022)
153153
void unableToRollBackIsolatedConnection(@Cause Exception ignored);
154154

155+
@LogMessage(level = TRACE)
156+
@Message(value = "Unable to reset connection back to auto-commit enabled", id = 100040)
157+
void unableToResetAutoCommitEnabled(@Cause Exception ignored);
158+
159+
@LogMessage(level = TRACE)
160+
@Message(value = "Unable to reset connection back to auto-commit disabled", id = 100041)
161+
void unableToResetAutoCommitDisabled(@Cause Exception ignored);
162+
155163
@LogMessage(level = DEBUG)
156-
@Message(value = "Using default JDBC fetch size: %s", id = 100022)
164+
@Message(value = "Using default JDBC fetch size: %s", id = 100122)
157165
void usingFetchSize(int fetchSize);
158166

159167
@LogMessage(level = WARN)
160-
@Message(value = "Low default JDBC fetch size: %s (consider setting 'hibernate.jdbc.fetch_size')", id = 100023)
168+
@Message(value = "Low default JDBC fetch size: %s (consider setting 'hibernate.jdbc.fetch_size')", id = 100123)
161169
void warnLowFetchSize(int fetchSize);
162170

163171
@LogMessage(level = TRACE)
164-
@Message(value = "JDBC fetch size: %s", id = 100024)
172+
@Message(value = "JDBC fetch size: %s", id = 100124)
165173
void fetchSize(int fetchSize);
166174

167175
@LogMessage(level = DEBUG)
168-
@Message(value = "Low JDBC fetch size: %s (consider setting 'hibernate.jdbc.fetch_size')", id = 100025)
176+
@Message(value = "Low JDBC fetch size: %s (consider setting 'hibernate.jdbc.fetch_size')", id = 100125)
169177
void lowFetchSize(int fetchSize);
170178

171179
@LogMessage(level = TRACE)
172-
@Message(value = "Setting JDBC fetch size: %s", id = 100026)
180+
@Message(value = "Setting JDBC fetch size: %s", id = 100126)
173181
void settingFetchSize(int fetchSize);
174182

175183
@LogMessage(level = TRACE)
176-
@Message(value = "Setting JDBC query timeout: %s", id = 100027)
184+
@Message(value = "Setting JDBC query timeout: %s", id = 100127)
177185
void settingQueryTimeout(int timeout);
178186

179187
@LogMessage(level = WARN)

hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/ExtractedDatabaseMetaDataImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import java.sql.ResultSet;
1010
import java.sql.SQLException;
1111
import java.sql.Statement;
12-
import java.util.Collections;
1312
import java.util.List;
14-
import java.util.stream.Collectors;
1513

1614
import org.hibernate.HibernateException;
1715
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
@@ -22,7 +20,9 @@
2220
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
2321
import org.hibernate.tool.schema.extract.spi.SequenceInformation;
2422

23+
import static java.util.Collections.emptyList;
2524
import static java.util.stream.StreamSupport.stream;
25+
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
2626

2727
/**
2828
* Standard implementation of {@link ExtractedDatabaseMetaData}
@@ -189,7 +189,7 @@ public synchronized List<SequenceInformation> getSequenceInformationList() {
189189
return sequenceInformationList;
190190
}
191191
else {
192-
return Collections.emptyList();
192+
return emptyList();
193193
}
194194
}
195195

@@ -335,7 +335,7 @@ private List<SequenceInformation> sequenceInformationList() {
335335
try {
336336
connection = connectionAccess.obtainConnection();
337337
return stream( sequenceInformation( connection, jdbcEnvironment ).spliterator(), false )
338-
.collect( Collectors.toList() );
338+
.toList();
339339
}
340340
catch (SQLException e) {
341341
throw new HibernateException( "Could not fetch the SequenceInformation from the database", e );
@@ -346,7 +346,7 @@ private List<SequenceInformation> sequenceInformationList() {
346346
connectionAccess.releaseConnection( connection );
347347
}
348348
catch (SQLException exception) {
349-
//ignored
349+
JDBC_MESSAGE_LOGGER.unableToReleaseConnection( exception );
350350
}
351351
}
352352
}

hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/GlobalTemporaryTableStrategy.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.hibernate.query.sqm.mutation.spi.AfterUseAction;
2020
import org.jboss.logging.Logger;
2121

22+
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
23+
2224
/**
2325
* Strategy based on ANSI SQL's definition of a "global temporary table".
2426
*
@@ -91,7 +93,8 @@ public void prepare(MappingModelCreationProcess mappingModelCreationProcess, Jdb
9193
try {
9294
connectionAccess.releaseConnection( connection );
9395
}
94-
catch (SQLException ignore) {
96+
catch (SQLException exception) {
97+
JDBC_MESSAGE_LOGGER.unableToReleaseConnection( exception );
9598
}
9699
}
97100
}
@@ -132,7 +135,8 @@ public void release(SessionFactoryImplementor sessionFactory, JdbcConnectionAcce
132135
try {
133136
connectionAccess.releaseConnection( connection );
134137
}
135-
catch (SQLException ignore) {
138+
catch (SQLException exception) {
139+
JDBC_MESSAGE_LOGGER.unableToReleaseConnection( exception );
136140
}
137141
}
138142
}

hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/PersistentTableStrategy.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.hibernate.query.sqm.mutation.spi.AfterUseAction;
2020
import org.jboss.logging.Logger;
2121

22+
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
23+
2224
/**
2325
* This is a strategy that mimics temporary tables for databases which do not support
2426
* temporary tables. It follows a pattern similar to the ANSI SQL definition of global
@@ -116,7 +118,8 @@ public void prepare(
116118
try {
117119
connectionAccess.releaseConnection( connection );
118120
}
119-
catch (SQLException ignore) {
121+
catch (SQLException exception) {
122+
JDBC_MESSAGE_LOGGER.unableToReleaseConnection( exception );
120123
}
121124
}
122125
}
@@ -156,7 +159,8 @@ public void release(
156159
try {
157160
connectionAccess.releaseConnection( connection );
158161
}
159-
catch (SQLException ignore) {
162+
catch (SQLException exception) {
163+
JDBC_MESSAGE_LOGGER.unableToReleaseConnection( exception );
160164
}
161165
}
162166
}

hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcIsolationDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private static void resetAutoCommit(boolean transacted, boolean wasAutoCommit, C
120120
connection.setAutoCommit( true );
121121
}
122122
catch ( Exception exception ) {
123-
JDBC_MESSAGE_LOGGER.unableToResetAutoCommit( exception );
123+
JDBC_MESSAGE_LOGGER.unableToResetAutoCommitEnabled( exception );
124124
}
125125
}
126126
}

hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import org.hibernate.service.ServiceRegistry;
1616
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
1717

18+
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
19+
1820
/**
1921
* @author Steve Ebersole
2022
*/
@@ -109,7 +111,8 @@ public void cleanup() {
109111
try {
110112
jdbcConnectionAccess.releaseConnection( jdbcConnection );
111113
}
112-
catch (SQLException ignore) {
114+
catch (SQLException exception) {
115+
JDBC_MESSAGE_LOGGER.unableToReleaseConnection( exception );
113116
}
114117
}
115118
}

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/DdlTransactionIsolatorProvidedConnectionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public void release() {
6868
// and we don't have access to it upon releasing via the DdlTransactionIsolatorProvidedConnectionImpl.
6969
connectionAccess.releaseConnection( null );
7070
}
71-
catch (SQLException ignored) {
72-
JDBC_MESSAGE_LOGGER.unableToReleaseIsolatedConnection( ignored );
71+
catch (SQLException exception) {
72+
JDBC_MESSAGE_LOGGER.unableToReleaseIsolatedConnection( exception );
7373
}
7474
}
7575
}

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/JdbcConnectionAccessConnectionProviderImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import org.jboss.logging.Logger;
1515

16+
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
17+
1618
/**
1719
* Implementation of JdbcConnectionAccess for use in cases where we
1820
* leverage a ConnectionProvider for access to JDBC Connections.
@@ -43,14 +45,14 @@ public JdbcConnectionAccessConnectionProviderImpl(ConnectionProvider connectionP
4345
try {
4446
jdbcConnection.setAutoCommit( true );
4547
}
46-
catch (SQLException e) {
48+
catch (SQLException exception) {
4749
throw new PersistenceException(
4850
String.format(
4951
"Could not set provided connection [%s] to auto-commit mode" +
5052
" (needed for schema generation)",
5153
jdbcConnection
5254
),
53-
e
55+
exception
5456
);
5557
}
5658
}
@@ -88,8 +90,8 @@ public void releaseConnection(Connection connection) throws SQLException {
8890
jdbcConnection.setAutoCommit( false );
8991
}
9092
}
91-
catch (SQLException e) {
92-
log.info( "Was unable to reset JDBC connection to no longer be in auto-commit mode" );
93+
catch (SQLException exception) {
94+
JDBC_MESSAGE_LOGGER.unableToResetAutoCommitDisabled( exception );
9395
}
9496
}
9597

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/exec/JdbcConnectionAccessProvidedConnectionImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import org.jboss.logging.Logger;
1414

15+
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
16+
1517
/**
1618
* Implementation of JdbcConnectionAccess for cases where we are provided
1719
* a JDBC Connection to use.
@@ -34,14 +36,14 @@ public JdbcConnectionAccessProvidedConnectionImpl(Connection jdbcConnection) {
3436
try {
3537
jdbcConnection.setAutoCommit( true );
3638
}
37-
catch (SQLException e) {
39+
catch (SQLException exception) {
3840
throw new PersistenceException(
3941
String.format(
4042
"Could not set provided connection [%s] to auto-commit mode" +
4143
" (needed for schema generation)",
4244
jdbcConnection
4345
),
44-
e
46+
exception
4547
);
4648
}
4749
}
@@ -61,16 +63,17 @@ public Connection obtainConnection() throws SQLException {
6163

6264
@Override
6365
public void releaseConnection(Connection connection) throws SQLException {
64-
// NOTE : reset auto-commit, but *do not* close the Connection. The application handed us this connection
66+
// NOTE: reset auto-commit, but *do not* close the Connection.
67+
// The application handed us this connection.
6568

6669
if ( !wasInitiallyAutoCommit ) {
6770
try {
6871
if ( jdbcConnection.getAutoCommit() ) {
6972
jdbcConnection.setAutoCommit( false );
7073
}
7174
}
72-
catch (SQLException e) {
73-
log.info( "Was unable to reset JDBC connection to no longer be in auto-commit mode" );
75+
catch (SQLException exception) {
76+
JDBC_MESSAGE_LOGGER.unableToResetAutoCommitDisabled( exception );
7477
}
7578
}
7679
}

0 commit comments

Comments
 (0)