Skip to content

Commit 699730c

Browse files
committed
typesafe logging in TemporaryTableHelper
1 parent b1f63ee commit 699730c

File tree

3 files changed

+67
-41
lines changed

3 files changed

+67
-41
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/HANAServerConfiguration.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
1616
import org.hibernate.internal.util.StringHelper;
1717
import org.hibernate.internal.util.config.ConfigurationHelper;
18+
import org.jboss.logging.Logger;
1819

1920
import static org.hibernate.cfg.DialectSpecificSettings.HANA_MAX_LOB_PREFETCH_SIZE;
20-
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
2121

2222
/**
2323
* Utility class that extracts some initial configuration from the database for {@link HANADialect}.
@@ -58,9 +58,8 @@ public static HANAServerConfiguration fromDialectResolutionInfo(DialectResolutio
5858
}
5959
catch (SQLException e) {
6060
// Ignore
61-
CORE_LOGGER.debug(
62-
"An error occurred while trying to determine the database version.",
63-
e );
61+
Logger.getLogger( HANAServerConfiguration.class )
62+
.debug( "An error occurred while trying to determine the database version.", e );
6463
}
6564

6665
if (databaseMajorVersion > 0 && databaseMajorVersion < 4) {
@@ -75,9 +74,8 @@ public static HANAServerConfiguration fromDialectResolutionInfo(DialectResolutio
7574
}
7675
catch (SQLException e) {
7776
// Ignore
78-
CORE_LOGGER.debug(
79-
"An error occurred while trying to determine the value of the HANA parameter indexserver.ini / session / max_lob_prefetch_size.",
80-
e );
77+
Logger.getLogger( HANAServerConfiguration.class )
78+
.debug( "An error occurred while trying to determine the value of the HANA parameter indexserver.ini / session / max_lob_prefetch_size", e );
8179
}
8280
}
8381
else {
@@ -113,7 +111,8 @@ public static DatabaseVersion determineDatabaseVersion(DialectResolutionInfo inf
113111
}
114112
catch (SQLException e) {
115113
// Ignore
116-
CORE_LOGGER.debug( "An error occurred while trying to determine the HANA Cloud version.", e );
114+
Logger.getLogger( HANAServerConfiguration.class )
115+
.debug( "An error occurred while trying to determine the HANA Cloud version.", e );
117116
}
118117
}
119118
return databaseVersion == null

hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTableHelper.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
import java.sql.PreparedStatement;
99
import java.sql.SQLException;
1010
import java.sql.SQLWarning;
11-
import java.sql.Statement;
1211
import java.util.function.Function;
1312

1413
import org.hibernate.engine.jdbc.internal.FormatStyle;
15-
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
1614
import org.hibernate.engine.jdbc.spi.JdbcServices;
1715
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
18-
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
1916
import org.hibernate.engine.spi.SessionFactoryImplementor;
2017
import org.hibernate.engine.spi.SharedSessionContractImplementor;
2118
import org.hibernate.jdbc.AbstractReturningWork;
@@ -59,28 +56,25 @@ public TemporaryTableCreationWork(
5956

6057
@Override
6158
public Boolean execute(Connection connection) {
62-
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
63-
59+
final var jdbcServices = sessionFactory.getJdbcServices();
6460
try {
6561
final String creationCommand = exporter.getSqlCreateCommand( temporaryTable );
6662
logStatement( creationCommand, jdbcServices );
67-
68-
try (Statement statement = connection.createStatement()) {
63+
try ( var statement = connection.createStatement() ) {
6964
statement.executeUpdate( creationCommand );
7065
jdbcServices.getSqlExceptionHelper().handleAndClearWarnings( statement, WARNING_HANDLER );
7166
return Boolean.TRUE;
7267
}
7368
catch (SQLException e) {
74-
CORE_LOGGER.debugf(
75-
"Unable to create temporary table [%s]; `%s` failed : %s",
69+
CORE_LOGGER.unableToCreateTempTable(
7670
temporaryTable.getQualifiedTableName(),
7771
creationCommand,
78-
e.getMessage()
72+
e
7973
);
8074
}
8175
}
8276
catch( Exception e ) {
83-
CORE_LOGGER.debugf( "Error creating temporary table(s) : %s", e.getMessage() );
77+
CORE_LOGGER.errorCreatingTempTable( e );
8478
}
8579
return Boolean.FALSE;
8680
}
@@ -116,27 +110,25 @@ public TemporaryTableDropWork(
116110

117111
@Override
118112
public void execute(Connection connection) {
119-
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
120-
113+
final var jdbcServices = sessionFactory.getJdbcServices();
121114
try {
122115
final String dropCommand = exporter.getSqlDropCommand( temporaryTable );
123116
logStatement( dropCommand, jdbcServices );
124-
125-
try (Statement statement = connection.createStatement()) {
117+
try ( var statement = connection.createStatement() ) {
126118
statement.executeUpdate( dropCommand );
127-
jdbcServices.getSqlExceptionHelper().handleAndClearWarnings( statement, WARNING_HANDLER );
119+
jdbcServices.getSqlExceptionHelper()
120+
.handleAndClearWarnings( statement, WARNING_HANDLER );
128121
}
129122
catch (SQLException e) {
130-
CORE_LOGGER.debugf(
131-
"Unable to drop temporary table [%s]; `%s` failed : %s",
123+
CORE_LOGGER.unableToDropTempTable(
132124
temporaryTable.getQualifiedTableName(),
133125
dropCommand,
134-
e.getMessage()
126+
e
135127
);
136128
}
137129
}
138130
catch( Exception e ) {
139-
CORE_LOGGER.debugf( "Error dropping temporary table(s) : %s", e.getMessage() );
131+
CORE_LOGGER.errorDroppingTempTable( e );
140132
}
141133
}
142134
}
@@ -150,7 +142,7 @@ public static void cleanTemporaryTableRows(
150142
TemporaryTableExporter exporter,
151143
Function<SharedSessionContractImplementor,String> sessionUidAccess,
152144
SharedSessionContractImplementor session) {
153-
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
145+
final var jdbcCoordinator = session.getJdbcCoordinator();
154146
PreparedStatement preparedStatement = null;
155147
try {
156148
final String sql = exporter.getSqlTruncateCommand( temporaryTable, sessionUidAccess, session );
@@ -201,7 +193,7 @@ protected void logWarning(String description, String message) {
201193

202194

203195
private static void logStatement(String sql, JdbcServices jdbcServices) {
204-
final SqlStatementLogger statementLogger = jdbcServices.getSqlStatementLogger();
205-
statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
196+
jdbcServices.getSqlStatementLogger()
197+
.logStatement( sql, FormatStyle.BASIC.getFormatter() );
206198
}
207199
}

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ void missingArguments(
122122
void propertiesNotFound();
123123

124124
@LogMessage(level = WARN)
125-
@Message(value = "Recognized obsolete hibernate namespace %s. Use namespace %s instead. Refer to Hibernate 3.6 Migration Guide",
125+
@Message(
126+
value = """
127+
Recognized obsolete hibernate namespace %s.\
128+
Use namespace %s instead. Refer to Hibernate 3.6 Migration Guide""",
126129
id = 223)
127130
void recognizedObsoleteHibernateNamespace(String oldHibernateNamespace, String hibernateNamespace);
128131

@@ -245,7 +248,10 @@ void missingArguments(
245248
void unableToRunSchemaUpdate(@Cause Exception e);
246249

247250
@LogMessage(level = WARN)
248-
@Message(value = "The %s.%s.%s version of H2 implements temporary table creation such that it commits current transaction; multi-table, bulk HQL/JPQL will not work properly",
251+
@Message(
252+
value = """
253+
The %s.%s.%s version of H2 implements temporary table creation such that it commits current transaction;\
254+
multi-table, bulk HQL/JPQL will not work properly""",
249255
id = 393)
250256
void unsupportedMultiTableBulkHqlJpaql(int majorVersion, int minorVersion, int buildId);
251257

@@ -267,17 +273,19 @@ void missingArguments(
267273

268274
@LogMessage(level = WARN)
269275
@Message(
270-
value = "Dialect [%s] limits the number of elements in an IN predicate to %s entries. " +
271-
"However, the given parameter list [%s] contained %s entries, which will likely cause failures " +
272-
"to execute the query in the database",
276+
value = """
277+
Dialect [%s] limits the number of elements in an IN predicate to %s entries. \
278+
However, the given parameter list [%s] contained %s entries, which will likely cause failures \
279+
to execute the query in the database""",
273280
id = 443
274281
)
275282
void tooManyInExpressions(String dialectName, int limit, String paramName, int size);
276283

277284
@LogMessage(level = WARN)
278285
@Message(
279-
value = "Encountered request for locking however dialect reports that database prefers locking be done in a " +
280-
"separate select (follow-on locking); results will be locked after initial query executes",
286+
value = """
287+
Encountered request for locking however dialect reports that database prefers locking be done in a \
288+
separate select (follow-on locking); results will be locked after initial query executes""",
281289
id = 444
282290
)
283291
void usingFollowOnLocking();
@@ -299,7 +307,11 @@ void missingArguments(
299307
void unsuccessfulSchemaManagementCommand(String command);
300308

301309
@LogMessage(level = WARN)
302-
@Message(value = "A ManagedEntity was associated with a stale PersistenceContext. A ManagedEntity may only be associated with one PersistenceContext at a time; %s", id = 480)
310+
@Message(
311+
value = """
312+
A ManagedEntity was associated with a stale PersistenceContext.\
313+
A ManagedEntity may only be associated with one PersistenceContext at a time; %s""",
314+
id = 480)
303315
void stalePersistenceContextInEntityEntry(String msg);
304316

305317
@LogMessage(level = ERROR)
@@ -333,7 +345,10 @@ void missingArguments(
333345
void ignoreImmutablePropertyModification(String propertyName, String entityName);
334346

335347
@LogMessage(level = WARN)
336-
@Message(value = "Multiple configuration properties defined to create schema. Choose at most one among 'jakarta.persistence.create-database-schemas' or 'hibernate.hbm2ddl.create_namespaces'.", id = 504)
348+
@Message(value = """
349+
Multiple configuration properties defined to create schema.\
350+
Choose at most one among 'jakarta.persistence.create-database-schemas' or 'hibernate.hbm2ddl.create_namespaces'.""",
351+
id = 504)
337352
void multipleSchemaCreationSettingsDefined();
338353

339354
@LogMessage(level = WARN)
@@ -345,7 +360,11 @@ void missingArguments(
345360
void fetchModeJoinWithLazyWarning(String role);
346361

347362
@LogMessage(level = WARN)
348-
@Message(value = "The %2$s version for [%s] is no longer supported, hence certain features may not work properly. The minimum supported version is %3$s. Check the community dialects project for available legacy versions.", id = 511)
363+
@Message(
364+
value = """
365+
The %2$s version for [%s] is no longer supported, hence certain features may not work properly.\
366+
The minimum supported version is %3$s. Check the community dialects project for available legacy versions.""",
367+
id = 511)
349368
void unsupportedDatabaseVersion(String databaseName, String actualVersion, String minimumVersion);
350369

351370
@LogMessage(level = DEBUG)
@@ -386,4 +405,20 @@ void illegalArgumentOnStaticMetamodelFieldInjection(
386405
void unableToLocateStaticMetamodelField(
387406
String name,
388407
String name2);
408+
409+
@LogMessage(level = DEBUG)
410+
@Message( id = 6001, value = "Error creating temp table" )
411+
void errorCreatingTempTable(@Cause Exception e);
412+
413+
@LogMessage(level = DEBUG)
414+
@Message( id = 6002, value = "Unable to create temporary table [%s]: '%s' failed" )
415+
void unableToCreateTempTable(String qualifiedTableName, String creationCommand, @Cause SQLException e);
416+
417+
@LogMessage(level = DEBUG)
418+
@Message( id = 6003, value = "Error dropping temp table" )
419+
void errorDroppingTempTable(@Cause Exception e);
420+
421+
@LogMessage(level = DEBUG)
422+
@Message( id = 6004, value = "Unable to drop temporary table [%s]: '%s' failed" )
423+
void unableToDropTempTable(String qualifiedTableName, String creationCommand, @Cause SQLException e);
389424
}

0 commit comments

Comments
 (0)