Skip to content

Commit 64d7849

Browse files
committed
finish cleaning up use of CoreMessageLogger
and fix some impact on tests
1 parent f71d2a9 commit 64d7849

File tree

38 files changed

+190
-567
lines changed

38 files changed

+190
-567
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/HSQLLegacyDialect.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
5151
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
5252
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
53-
import org.hibernate.internal.CoreMessageLogger;
5453
import org.hibernate.internal.util.JdbcExceptionHelper;
5554
import org.hibernate.internal.util.ReflectHelper;
5655
import org.hibernate.metamodel.mapping.EntityMappingType;
@@ -79,7 +78,6 @@
7978
import org.hibernate.type.spi.TypeConfiguration;
8079
import org.jboss.logging.Logger;
8180

82-
import java.lang.invoke.MethodHandles;
8381
import java.sql.DatabaseMetaData;
8482
import java.sql.SQLException;
8583
import java.sql.Types;
@@ -100,11 +98,7 @@
10098
*/
10199
public class HSQLLegacyDialect extends Dialect {
102100

103-
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
104-
MethodHandles.lookup(),
105-
CoreMessageLogger.class,
106-
org.hibernate.community.dialect.HSQLLegacyDialect.class.getName()
107-
);
101+
private static final Logger LOG = Logger.getLogger( HSQLLegacyDialect.class );
108102

109103
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate( this );
110104
private final HSQLIdentityColumnSupport identityColumnSupport;
@@ -762,7 +756,7 @@ private ReadUncommittedLockingStrategy(EntityPersister lockable, LockMode lockMo
762756
public void lock(Object id, Object version, Object object, int timeout, SharedSessionContractImplementor session)
763757
throws StaleObjectStateException, JDBCException {
764758
if ( getLockMode().greaterThan( LockMode.READ ) ) {
765-
LOG.hsqldbSupportsOnlyReadCommittedIsolation();
759+
LOG.warn( "HSQLDB supports only READ_UNCOMMITTED isolation" );
766760
}
767761
super.lock( id, version, object, timeout, session );
768762
}

hibernate-core/src/main/java/org/hibernate/boot/SchemaAutoTooling.java

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

1010
import java.util.Locale;
1111

12+
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_AUTO;
13+
1214
/**
1315
* Defines the possible values for {@value AvailableSettings#HBM2DDL_AUTO}.
1416
*
@@ -65,15 +67,13 @@ public static SchemaAutoTooling interpret(String configurationValue) {
6567
return null;
6668
}
6769
else {
68-
for ( SchemaAutoTooling value : values() ) {
70+
for ( var value : values() ) {
6971
if ( value.externalForm().equals( configurationValue ) ) {
7072
return value;
7173
}
7274
}
73-
throw new HibernateException(
74-
"Unrecognized " + AvailableSettings.HBM2DDL_AUTO + " value: '" + configurationValue
75-
+ "'. Supported values include 'create', 'create-drop', 'create-only', 'drop', 'update', 'none' and 'validate'."
76-
);
75+
throw new HibernateException( "Unrecognized " + HBM2DDL_AUTO + " value: '" + configurationValue
76+
+ "' (supported values include 'create', 'create-drop', 'create-only', 'drop', 'update', 'none', and 'validate')" );
7777
}
7878
}
7979
}

hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
import org.checkerframework.checker.nullness.qual.NonNull;
2020
import org.checkerframework.checker.nullness.qual.Nullable;
21+
import org.hibernate.result.internal.OutputsImpl;
22+
import org.jboss.logging.Logger;
2123

2224
import static org.hibernate.engine.internal.CacheHelper.fromSharedCache;
23-
import static org.hibernate.internal.CoreMessageLogger.LOGGER;
2425
import static org.hibernate.internal.util.collections.CollectionHelper.linkedMapOfSize;
2526
import static org.hibernate.internal.util.collections.CollectionHelper.linkedSetOfSize;
2627
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;
@@ -37,6 +38,8 @@
3738
*/
3839
public class BatchFetchQueue {
3940

41+
private static final Logger LOG = Logger.getLogger( OutputsImpl.class );
42+
4043
private final PersistenceContext context;
4144

4245
/**
@@ -106,8 +109,8 @@ public void addSubselect(EntityKey key, SubselectFetch subquery) {
106109
}
107110

108111
final var previous = subselectsByEntityKey.put( key, subquery );
109-
if ( previous != null && LOGGER.isDebugEnabled() ) {
110-
LOGGER.tracef(
112+
if ( previous != null && LOG.isDebugEnabled() ) {
113+
LOG.tracef(
111114
"SubselectFetch previously registered with BatchFetchQueue for '%s.s'",
112115
key.getEntityName(),
113116
key.getIdentifier()
@@ -129,6 +132,10 @@ public void removeSubselect(EntityKey key) {
129132

130133
// entity batch support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131134

135+
private LoadQueryInfluencers getLoadQueryInfluencers() {
136+
return context.getSession().getLoadQueryInfluencers();
137+
}
138+
132139
/**
133140
* If an EntityKey represents a batch loadable entity, add
134141
* it to the queue.
@@ -140,7 +147,7 @@ public void removeSubselect(EntityKey key) {
140147
* already associated with the {@link PersistenceContext}.
141148
*/
142149
public void addBatchLoadableEntityKey(EntityKey key) {
143-
if ( key.isBatchLoadable( context.getSession().getLoadQueryInfluencers() ) ) {
150+
if ( key.isBatchLoadable( getLoadQueryInfluencers() ) ) {
144151
if ( batchLoadableEntityKeys == null ) {
145152
batchLoadableEntityKeys = mapOfSize( 12 );
146153
}
@@ -156,7 +163,7 @@ public void addBatchLoadableEntityKey(EntityKey key) {
156163
* if necessary
157164
*/
158165
public void removeBatchLoadableEntityKey(EntityKey key) {
159-
if ( key.isBatchLoadable( context.getSession().getLoadQueryInfluencers() )
166+
if ( key.isBatchLoadable( getLoadQueryInfluencers() )
160167
&& batchLoadableEntityKeys != null ) {
161168
final var entityKeys = batchLoadableEntityKeys.get( key.getEntityName() );
162169
if ( entityKeys != null ) {
@@ -169,7 +176,7 @@ public void removeBatchLoadableEntityKey(EntityKey key) {
169176
* Intended for test usage. Really has no use-case in Hibernate proper.
170177
*/
171178
public boolean containsEntityKey(EntityKey key) {
172-
if ( key.isBatchLoadable( context.getSession().getLoadQueryInfluencers() )
179+
if ( key.isBatchLoadable( getLoadQueryInfluencers() )
173180
&& batchLoadableEntityKeys != null ) {
174181
final var entityKeys = batchLoadableEntityKeys.get( key.getEntityName() );
175182
if ( entityKeys != null ) {
@@ -196,22 +203,25 @@ public <T> void collectBatchLoadableEntityIds(
196203
if ( batchLoadableEntityKeys != null ) {
197204
final var entityKeys = batchLoadableEntityKeys.get( entityDescriptor.getEntityName() );
198205
if ( entityKeys != null ) {
206+
final var session = context.getSession();
199207
final var identifierMapping = entityDescriptor.getIdentifierMapping();
200208
int batchPosition = 1;
201209
int end = -1;
202210
boolean checkForEnd = false;
203211
for ( var entityKey : entityKeys ) {
204212
if ( checkForEnd && batchPosition == end ) {
205213
// the first id found after the given id
206-
return;
207-
}
208-
else if ( identifierMapping.areEqual( loadingId, entityKey.getIdentifier(),
209-
context.getSession() ) ) {
210-
end = batchPosition;
214+
return; // end the loop
211215
}
212-
else if ( !isCached( entityKey, entityDescriptor.getEntityPersister() ) ) {
213-
//noinspection unchecked
214-
collector.accept( batchPosition++, (T) entityKey.getIdentifier() );
216+
else {
217+
final Object identifier = entityKey.getIdentifier();
218+
if ( identifierMapping.areEqual( loadingId, identifier, session ) ) {
219+
end = batchPosition;
220+
}
221+
else if ( !isCached( entityKey, entityDescriptor.getEntityPersister() ) ) {
222+
//noinspection unchecked
223+
collector.accept( batchPosition++, (T) identifier );
224+
}
215225
}
216226

217227
if ( batchPosition == domainBatchSize ) {
@@ -296,13 +306,13 @@ public void addBatchLoadableCollection(PersistentCollection<?> collection, Colle
296306
* need to batch fetch it anymore, remove it from the queue
297307
* if necessary
298308
*/
299-
public void removeBatchLoadableCollection(CollectionEntry ce) {
300-
final var persister = ce.getLoadedPersister();
309+
public void removeBatchLoadableCollection(CollectionEntry collectionEntry) {
310+
final var persister = collectionEntry.getLoadedPersister();
301311
assert persister != null : "@AssumeAssertion(nullness)";
302312
if ( batchLoadableCollections != null ) {
303313
final var map = batchLoadableCollections.get( persister.getRole() );
304314
if ( map != null ) {
305-
map.remove( ce );
315+
map.remove( collectionEntry );
306316
}
307317
}
308318
}
@@ -328,9 +338,9 @@ public <T> void collectBatchLoadableCollectionKeys(
328338
int end = -1;
329339
boolean checkForEnd = false;
330340
for ( var me : map.entrySet() ) {
331-
final CollectionEntry ce = me.getKey();
341+
final var ce = me.getKey();
332342
final Object loadedKey = ce.getLoadedKey();
333-
final PersistentCollection<?> collection = me.getValue();
343+
final var collection = me.getValue();
334344

335345
// the loadedKey of the collectionEntry might be null as it might have been reset to null
336346
// (see for example Collections.processDereferencedCollection()
@@ -397,9 +407,9 @@ else if ( !isCached( loadedKey, pluralAttributeMapping.getCollectionDescriptor()
397407
final var map = batchLoadableCollections.get( collectionPersister.getRole() );
398408
if ( map != null ) {
399409
for ( var me : map.entrySet() ) {
400-
final CollectionEntry ce = me.getKey();
401-
final Object loadedKey = ce.getLoadedKey();
402-
final PersistentCollection<?> collection = me.getValue();
410+
final var collectionEntry = me.getKey();
411+
final Object loadedKey = collectionEntry.getLoadedKey();
412+
final var collection = me.getValue();
403413

404414
// the loadedKey of the collectionEntry might be null as it might have been reset to null
405415
// (see for example Collections.processDereferencedCollection()

hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceGeneratorLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public interface SequenceGeneratorLogger extends BasicLogger {
3535
String NAME = SubSystemLogging.BASE + ".id.table";
3636

37-
SequenceGeneratorLogger SEQUENCE_GENERATOR_MESSAGE_LOGGER = Logger.getMessageLogger(
37+
SequenceGeneratorLogger SEQUENCE_GENERATOR_LOGGER = Logger.getMessageLogger(
3838
MethodHandles.lookup(),
3939
SequenceGeneratorLogger.class,
4040
NAME

hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.hibernate.cfg.MappingSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY;
3838
import static org.hibernate.id.IdentifierGeneratorHelper.getNamingStrategy;
3939
import static org.hibernate.id.enhanced.OptimizerFactory.determineImplicitOptimizerName;
40-
import static org.hibernate.id.enhanced.SequenceGeneratorLogger.SEQUENCE_GENERATOR_MESSAGE_LOGGER;
40+
import static org.hibernate.id.enhanced.SequenceGeneratorLogger.SEQUENCE_GENERATOR_LOGGER;
4141
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
4242
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
4343
import static org.hibernate.internal.util.config.ConfigurationHelper.getInt;
@@ -214,7 +214,7 @@ public void configure(GeneratorCreationContext creationContext, Properties param
214214
&& optimizationStrategy.isPooled()
215215
&& !dialect.getSequenceSupport().supportsPooledSequences() ) {
216216
forceTableUse = true;
217-
SEQUENCE_GENERATOR_MESSAGE_LOGGER.forcingTableUse();
217+
SEQUENCE_GENERATOR_LOGGER.forcingTableUse();
218218
}
219219

220220
this.databaseStructure = buildDatabaseStructure(
@@ -292,13 +292,13 @@ private int validatedIncrementSize(
292292
case NONE -> incrementSize;
293293
case FIX -> {
294294
// log at TRACE level
295-
SEQUENCE_GENERATOR_MESSAGE_LOGGER.sequenceIncrementSizeMismatchFixed(
295+
SEQUENCE_GENERATOR_LOGGER.sequenceIncrementSizeMismatchFixed(
296296
databaseSequenceName, incrementSize, dbIncrementValue );
297297
yield dbIncrementValue;
298298
}
299299
case LOG -> {
300300
// log at WARN level
301-
SEQUENCE_GENERATOR_MESSAGE_LOGGER.sequenceIncrementSizeMismatch(
301+
SEQUENCE_GENERATOR_LOGGER.sequenceIncrementSizeMismatch(
302302
databaseSequenceName, incrementSize, dbIncrementValue );
303303
yield incrementSize;
304304
}
@@ -448,7 +448,7 @@ protected OptimizerDescriptor determineOptimizationStrategy(Properties params, i
448448
protected int determineAdjustedIncrementSize(OptimizerDescriptor optimizationStrategy, int incrementSize) {
449449
if ( optimizationStrategy == StandardOptimizerDescriptor.NONE ) {
450450
if ( incrementSize < -1 ) {
451-
SEQUENCE_GENERATOR_MESSAGE_LOGGER.honoringOptimizerSetting(
451+
SEQUENCE_GENERATOR_LOGGER.honoringOptimizerSetting(
452452
StandardOptimizerDescriptor.NONE.getExternalName(),
453453
INCREMENT_PARAM,
454454
incrementSize,
@@ -458,7 +458,7 @@ protected int determineAdjustedIncrementSize(OptimizerDescriptor optimizationStr
458458
return -1;
459459
}
460460
else if ( incrementSize > 1 ) {
461-
SEQUENCE_GENERATOR_MESSAGE_LOGGER.honoringOptimizerSetting(
461+
SEQUENCE_GENERATOR_LOGGER.honoringOptimizerSetting(
462462
StandardOptimizerDescriptor.NONE.getExternalName(),
463463
INCREMENT_PARAM,
464464
incrementSize,

hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import static org.hibernate.boot.model.internal.GeneratorBinder.applyIfNotEmpty;
4747
import static org.hibernate.cfg.MappingSettings.TABLE_GENERATOR_STORE_LAST_USED;
4848
import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN;
49-
import static org.hibernate.id.enhanced.TableGeneratorLogger.TABLE_GENERATOR_MESSAGE_LOGGER;
49+
import static org.hibernate.id.enhanced.TableGeneratorLogger.TABLE_GENERATOR_LOGGER;
5050
import static org.hibernate.id.IdentifierGeneratorHelper.getNamingStrategy;
5151
import static org.hibernate.id.enhanced.OptimizerFactory.determineImplicitOptimizerName;
5252
import static org.hibernate.internal.util.StringHelper.isEmpty;
@@ -454,7 +454,7 @@ protected String determineSegmentValue(Properties params) {
454454
protected String determineDefaultSegmentValue(Properties params) {
455455
final boolean preferSegmentPerEntity = getBoolean( CONFIG_PREFER_SEGMENT_PER_ENTITY, params );
456456
final String defaultToUse = preferSegmentPerEntity ? params.getProperty( TABLE ) : DEF_SEGMENT_VALUE;
457-
TABLE_GENERATOR_MESSAGE_LOGGER.usingDefaultIdGeneratorSegmentValue(
457+
TABLE_GENERATOR_LOGGER.usingDefaultIdGeneratorSegmentValue(
458458
qualifiedTableName.render(), segmentColumnName, defaultToUse );
459459
return defaultToUse;
460460
}
@@ -549,15 +549,15 @@ private IntegralDataTypeHolder nextValue(
549549
final IntegralDataTypeHolder value = makeValue();
550550
int rows;
551551
do {
552-
TABLE_GENERATOR_MESSAGE_LOGGER.retrievingCurrentValueForSegment( segmentValue );
552+
TABLE_GENERATOR_LOGGER.retrievingCurrentValueForSegment( segmentValue );
553553
try ( var prepareStatement = prepareStatement( connection, selectQuery, logger, listener, session ) ) {
554554
prepareStatement.setString( 1, segmentValue );
555555
final var resultSet = executeQuery( prepareStatement, listener, selectQuery, session );
556556
if ( !resultSet.next() ) {
557557
final long initializationValue = storeLastUsedValue ? initialValue - 1 : initialValue;
558558
value.initialize( initializationValue );
559559

560-
TABLE_GENERATOR_MESSAGE_LOGGER.insertingInitialValueForSegment( value, segmentValue );
560+
TABLE_GENERATOR_LOGGER.insertingInitialValueForSegment( value, segmentValue );
561561
try ( PreparedStatement statement = prepareStatement( connection, insertQuery, logger, listener, session ) ) {
562562
statement.setString( 1, segmentValue );
563563
value.bind( statement, 2 );
@@ -577,7 +577,7 @@ private IntegralDataTypeHolder nextValue(
577577
resultSet.close();
578578
}
579579
catch (SQLException e) {
580-
TABLE_GENERATOR_MESSAGE_LOGGER.unableToReadOrInitializeHiValue( physicalTableName.render(), e );
580+
TABLE_GENERATOR_LOGGER.unableToReadOrInitializeHiValue( physicalTableName.render(), e );
581581
throw e;
582582
}
583583

@@ -588,15 +588,15 @@ private IntegralDataTypeHolder nextValue(
588588
else {
589589
updateValue.increment();
590590
}
591-
TABLE_GENERATOR_MESSAGE_LOGGER.updatingCurrentValueForSegment( updateValue, segmentValue );
591+
TABLE_GENERATOR_LOGGER.updatingCurrentValueForSegment( updateValue, segmentValue );
592592
try ( var statement = prepareStatement( connection, updateQuery, logger, listener, session ) ) {
593593
updateValue.bind( statement, 1 );
594594
value.bind( statement, 2 );
595595
statement.setString( 3, segmentValue );
596596
rows = executeUpdate( statement, listener, updateQuery, session );
597597
}
598598
catch (SQLException e) {
599-
TABLE_GENERATOR_MESSAGE_LOGGER.unableToUpdateHiValue( physicalTableName.render(), e );
599+
TABLE_GENERATOR_LOGGER.unableToUpdateHiValue( physicalTableName.render(), e );
600600
throw e;
601601
}
602602
}

hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGeneratorLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
public interface TableGeneratorLogger extends BasicLogger {
3939
String NAME = SubSystemLogging.BASE + ".id.table";
4040

41-
TableGeneratorLogger TABLE_GENERATOR_MESSAGE_LOGGER = Logger.getMessageLogger(
41+
TableGeneratorLogger TABLE_GENERATOR_LOGGER = Logger.getMessageLogger(
4242
MethodHandles.lookup(),
4343
TableGeneratorLogger.class,
4444
NAME

hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
import static org.hibernate.LockMode.PESSIMISTIC_WRITE;
3939
import static org.hibernate.id.IdentifierGeneratorHelper.getIntegralDataTypeHolder;
40-
import static org.hibernate.id.enhanced.TableGeneratorLogger.TABLE_GENERATOR_MESSAGE_LOGGER;
40+
import static org.hibernate.id.enhanced.TableGeneratorLogger.TABLE_GENERATOR_LOGGER;
4141

4242
/**
4343
* Describes a table used to mimic sequence behavior
@@ -185,7 +185,7 @@ public IntegralDataTypeHolder execute(Connection connection) throws SQLException
185185
selectRS.close();
186186
}
187187
catch (SQLException sqle) {
188-
TABLE_GENERATOR_MESSAGE_LOGGER.unableToReadHiValue( physicalTableName.render(), sqle );
188+
TABLE_GENERATOR_LOGGER.unableToReadHiValue( physicalTableName.render(), sqle );
189189
throw sqle;
190190
}
191191

@@ -204,7 +204,7 @@ public IntegralDataTypeHolder execute(Connection connection) throws SQLException
204204
rows = executeUpdate( updatePS, statsCollector, updateQuery, session );
205205
}
206206
catch (SQLException e) {
207-
TABLE_GENERATOR_MESSAGE_LOGGER.unableToUpdateHiValue( physicalTableName.render(), e );
207+
TABLE_GENERATOR_LOGGER.unableToUpdateHiValue( physicalTableName.render(), e );
208208
throw e;
209209
}
210210
} while ( rows == 0 );

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public interface CoreMessageLogger extends BasicLogger {
5252

5353
String NAME = SubSystemLogging.BASE + ".core";
5454

55-
Logger LOGGER = Logger.getLogger( NAME );
5655
CoreMessageLogger CORE_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, NAME );
5756

5857
@LogMessage(level = INFO)
@@ -90,10 +89,6 @@ void expectedType(String name,
9089
+ " to unsafe use of the session): %s", id = 99)
9190
void failed(Throwable throwable);
9291

93-
@LogMessage(level = WARN)
94-
@Message(value = "HSQLDB supports only READ_UNCOMMITTED isolation", id = 118)
95-
void hsqldbSupportsOnlyReadCommittedIsolation();
96-
9792
@LogMessage(level = ERROR)
9893
@Message(value = "IllegalArgumentException in class: %s, getter method of property: %s", id = 122)
9994
void illegalPropertyGetterArgument(String name, String propertyName);

0 commit comments

Comments
 (0)