Skip to content

Commit 99764ca

Browse files
committed
make ModelMutationLogging typesafe
1 parent 6954401 commit 99764ca

15 files changed

+177
-97
lines changed

hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,17 @@ public void addToBatch(JdbcValueBindings jdbcValueBindings, TableInclusionChecke
115115
if ( inclusionChecker != null
116116
&& !inclusionChecker.include( statementDetails.getMutatingTableDetails() ) ) {
117117
if ( loggerTraceEnabled ) {
118-
MODEL_MUTATION_LOGGER.tracef(
119-
"Skipping addBatch for table: %s (batch position %s)",
118+
MODEL_MUTATION_LOGGER.skippingAddBatchForTable(
120119
statementDetails.getMutatingTableDetails().getTableName(),
121120
batchPosition+1
122121
);
123122
}
124123
}
125124
else {
125+
MODEL_MUTATION_LOGGER.addBatchForTable(
126+
statementDetails.getMutatingTableDetails().getTableName(),
127+
batchPosition+1
128+
);
126129
//noinspection resource
127130
final var statement = statementDetails.resolveStatement();
128131
final String sqlString = statementDetails.getSqlString();

hibernate-core/src/main/java/org/hibernate/engine/jdbc/mutation/internal/AbstractMutationExecutor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ protected void performNonBatchedMutation(
115115
final TableMapping tableDetails = statementDetails.getMutatingTableDetails();
116116
if ( inclusionChecker != null && !inclusionChecker.include( tableDetails ) ) {
117117
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
118-
MODEL_MUTATION_LOGGER.tracef(
119-
"Skipping execution of secondary insert: %s",
120-
tableDetails.getTableName()
121-
);
118+
MODEL_MUTATION_LOGGER.skippingSecondaryInsert( tableDetails.getTableName() );
122119
}
123120
return;
124121
}

hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -724,31 +724,31 @@ private NamedQueryMemento<?> getNamedQueryMemento(MetadataImplementor bootModel)
724724

725725
protected void logStaticSQL() {
726726
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
727-
MODEL_MUTATION_LOGGER.tracef( "Static SQL for collection: %s", getRole() );
727+
MODEL_MUTATION_LOGGER.staticSqlForCollection( getRole() );
728728

729729
final var rowMutationOperations = getRowMutationOperations();
730730

731731
final var insertRowOperation = rowMutationOperations.getInsertRowOperation();
732732
final String insertRowSql = insertRowOperation != null ? insertRowOperation.getSqlString() : null;
733733
if ( insertRowSql != null ) {
734-
MODEL_MUTATION_LOGGER.tracef( " Row insert: %s", insertRowSql );
734+
MODEL_MUTATION_LOGGER.collectionRowInsert( insertRowSql );
735735
}
736736

737737
final var updateRowOperation = rowMutationOperations.getUpdateRowOperation();
738738
final String updateRowSql = updateRowOperation != null ? updateRowOperation.getSqlString() : null;
739739
if ( updateRowSql != null ) {
740-
MODEL_MUTATION_LOGGER.tracef( " Row update: %s", updateRowSql );
740+
MODEL_MUTATION_LOGGER.collectionRowUpdate( updateRowSql );
741741
}
742742

743743
final var deleteRowOperation = rowMutationOperations.getDeleteRowOperation();
744744
final String deleteRowSql = deleteRowOperation != null ? deleteRowOperation.getSqlString() : null;
745745
if ( deleteRowSql != null ) {
746-
MODEL_MUTATION_LOGGER.tracef( " Row delete: %s", deleteRowSql );
746+
MODEL_MUTATION_LOGGER.collectionRowDelete( deleteRowSql );
747747
}
748748

749749
final String deleteAllSql = getRemoveCoordinator().getSqlString();
750750
if ( deleteAllSql != null ) {
751-
MODEL_MUTATION_LOGGER.tracef( " One-shot delete: %s", deleteAllSql );
751+
MODEL_MUTATION_LOGGER.collectionOneShotDelete( deleteAllSql );
752752
}
753753
}
754754
}

hibernate-core/src/main/java/org/hibernate/persister/collection/mutation/AbstractUpdateRowsCoordinator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public CollectionMutationTarget getMutationTarget() {
4141

4242
@Override
4343
public void updateRows(Object key, PersistentCollection<?> collection, SharedSessionContractImplementor session) {
44-
MODEL_MUTATION_LOGGER.tracef( "Updating collection rows - %s#%s", mutationTarget.getRolePath(), key );
44+
MODEL_MUTATION_LOGGER.updatingCollectionRows( mutationTarget.getRolePath(), key );
4545

4646
// update all the modified entries
4747
int count = doUpdate( key, collection, session );
4848

49-
MODEL_MUTATION_LOGGER.tracef( "Updated %s collection rows - %s#%s", count, mutationTarget.getRolePath(), key );
49+
MODEL_MUTATION_LOGGER.updatedCollectionRows( count, mutationTarget.getRolePath(), key );
5050
}
5151

5252
protected abstract int doUpdate(Object key, PersistentCollection<?> collection, SharedSessionContractImplementor session);

hibernate-core/src/main/java/org/hibernate/persister/collection/mutation/DeleteRowsCoordinatorStandard.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ public void deleteRows(PersistentCollection<?> collection, Object key, SharedSes
6060
}
6161

6262
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
63-
MODEL_MUTATION_LOGGER.tracef(
64-
"Deleting removed collection rows - %s : %s",
65-
mutationTarget.getRolePath(),
66-
key
67-
);
63+
MODEL_MUTATION_LOGGER.deletingRemovedCollectionRows( mutationTarget.getRolePath(), key );
6864
}
6965

7066
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
@@ -80,7 +76,7 @@ public void deleteRows(PersistentCollection<?> collection, Object key, SharedSes
8076

8177
final Iterator<?> deletes = collection.getDeletes( collectionDescriptor, !deleteByIndex );
8278
if ( !deletes.hasNext() ) {
83-
MODEL_MUTATION_LOGGER.trace( "No rows to delete" );
79+
MODEL_MUTATION_LOGGER.noRowsToDelete();
8480
return;
8581
}
8682

@@ -105,8 +101,7 @@ public void deleteRows(PersistentCollection<?> collection, Object key, SharedSes
105101
deletionCount++;
106102
}
107103

108-
MODEL_MUTATION_LOGGER.tracef( "Done deleting %s collection rows : %s",
109-
deletionCount, mutationTarget.getRolePath() );
104+
MODEL_MUTATION_LOGGER.doneDeletingCollectionRows( deletionCount, mutationTarget.getRolePath() );
110105
}
111106
finally {
112107
mutationExecutor.release();

hibernate-core/src/main/java/org/hibernate/persister/collection/mutation/DeleteRowsCoordinatorTablePerSubclass.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,15 @@ public CollectionMutationTarget getMutationTarget() {
5656
@Override
5757
public void deleteRows(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session) {
5858
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
59-
MODEL_MUTATION_LOGGER.tracef(
60-
"Deleting removed collection rows - %s : %s",
61-
mutationTarget.getRolePath(),
62-
key
63-
);
59+
MODEL_MUTATION_LOGGER.deletingRemovedCollectionRows( mutationTarget.getRolePath(), key );
6460
}
6561

6662
final PluralAttributeMapping pluralAttribute = mutationTarget.getTargetPart();
6763
final CollectionPersister collectionDescriptor = pluralAttribute.getCollectionDescriptor();
6864

6965
final Iterator<?> deletes = collection.getDeletes( collectionDescriptor, !deleteByIndex );
7066
if ( !deletes.hasNext() ) {
71-
MODEL_MUTATION_LOGGER.trace( "No rows to delete" );
67+
MODEL_MUTATION_LOGGER.noRowsToDelete();
7268
return;
7369
}
7470
final MutationExecutor[] executors = new MutationExecutor[subclassEntries.length];
@@ -108,8 +104,7 @@ public void deleteRows(PersistentCollection<?> collection, Object key, SharedSes
108104
deletionCount++;
109105
}
110106

111-
MODEL_MUTATION_LOGGER.tracef( "Done deleting %s collection rows : %s",
112-
deletionCount, mutationTarget.getRolePath() );
107+
MODEL_MUTATION_LOGGER.doneDeletingCollectionRows( deletionCount, mutationTarget.getRolePath() );
113108
}
114109
finally {
115110
for ( MutationExecutor executor : executors ) {

hibernate-core/src/main/java/org/hibernate/persister/collection/mutation/InsertRowsCoordinatorStandard.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ public void insertRows(
6666
}
6767

6868
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
69-
MODEL_MUTATION_LOGGER.tracef(
70-
"Inserting collection rows - %s : %s",
71-
mutationTarget.getRolePath(),
72-
id
73-
);
69+
MODEL_MUTATION_LOGGER.insertingNewCollectionRows( mutationTarget.getRolePath(), id );
7470
}
7571

7672
final PluralAttributeMapping pluralAttribute = mutationTarget.getTargetPart();
@@ -87,11 +83,7 @@ public void insertRows(
8783
final Iterator<?> entries = collection.entries( collectionDescriptor );
8884
collection.preInsert( collectionDescriptor );
8985
if ( !entries.hasNext() ) {
90-
MODEL_MUTATION_LOGGER.tracef(
91-
"No collection rows to insert - %s : %s",
92-
mutationTarget.getRolePath(),
93-
id
94-
);
86+
MODEL_MUTATION_LOGGER.noCollectionRowsToInsert( mutationTarget.getRolePath(), id );
9587
return;
9688
}
9789

@@ -118,8 +110,7 @@ public void insertRows(
118110
entryCount++;
119111
}
120112

121-
MODEL_MUTATION_LOGGER.tracef( "Done inserting %s collection rows : %s",
122-
entryCount, mutationTarget.getRolePath() );
113+
MODEL_MUTATION_LOGGER.doneInsertingCollectionRows( entryCount, mutationTarget.getRolePath() );
123114

124115
}
125116
finally {

hibernate-core/src/main/java/org/hibernate/persister/collection/mutation/InsertRowsCoordinatorTablePerSubclass.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,8 @@ public void insertRows(
6565
Object id,
6666
EntryFilter entryChecker,
6767
SharedSessionContractImplementor session) {
68-
final boolean loggerTraceEnabled = MODEL_MUTATION_LOGGER.isTraceEnabled();
69-
if ( loggerTraceEnabled ) {
70-
MODEL_MUTATION_LOGGER.tracef(
71-
"Inserting collection rows - %s : %s",
72-
mutationTarget.getRolePath(),
73-
id
74-
);
68+
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
69+
MODEL_MUTATION_LOGGER.insertingNewCollectionRows( mutationTarget.getRolePath(), id );
7570
}
7671

7772
final PluralAttributeMapping pluralAttribute = mutationTarget.getTargetPart();
@@ -80,13 +75,7 @@ public void insertRows(
8075
final Iterator<?> entries = collection.entries( collectionDescriptor );
8176
collection.preInsert( collectionDescriptor );
8277
if ( !entries.hasNext() ) {
83-
if ( loggerTraceEnabled ) {
84-
MODEL_MUTATION_LOGGER.tracef(
85-
"No collection rows to insert - %s : %s",
86-
mutationTarget.getRolePath(),
87-
id
88-
);
89-
}
78+
MODEL_MUTATION_LOGGER.noCollectionRowsToInsert( mutationTarget.getRolePath(), id );
9079
return;
9180
}
9281
final MutationExecutor[] executors = new MutationExecutor[subclassEntries.length];
@@ -125,13 +114,7 @@ public void insertRows(
125114
entryCount++;
126115
}
127116

128-
if ( loggerTraceEnabled ) {
129-
MODEL_MUTATION_LOGGER.tracef(
130-
"Done inserting %s collection rows: %s",
131-
entryCount,
132-
mutationTarget.getRolePath()
133-
);
134-
}
117+
MODEL_MUTATION_LOGGER.doneInsertingCollectionRows( entryCount, mutationTarget.getRolePath() );
135118

136119
}
137120
finally {

hibernate-core/src/main/java/org/hibernate/persister/collection/mutation/RemoveCoordinatorStandard.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ public String getSqlString() {
7373
@Override
7474
public void deleteAllRows(Object key, SharedSessionContractImplementor session) {
7575
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
76-
MODEL_MUTATION_LOGGER.tracef(
77-
"Deleting collection - %s : %s",
78-
mutationTarget.getRolePath(),
79-
key
80-
);
76+
MODEL_MUTATION_LOGGER.removingCollection( mutationTarget.getRolePath(), key );
8177
}
8278

8379
if ( operationGroup == null ) {

hibernate-core/src/main/java/org/hibernate/persister/collection/mutation/RemoveCoordinatorTablePerSubclass.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ public String getSqlString() {
6464
@Override
6565
public void deleteAllRows(Object key, SharedSessionContractImplementor session) {
6666
if ( MODEL_MUTATION_LOGGER.isTraceEnabled() ) {
67-
MODEL_MUTATION_LOGGER.tracef(
68-
"Deleting collection - %s : %s",
69-
mutationTarget.getRolePath(),
70-
key
71-
);
67+
MODEL_MUTATION_LOGGER.removingCollection( mutationTarget.getRolePath(), key );
7268
}
7369

7470
MutationOperationGroup[] operationGroups = this.operationGroups;

0 commit comments

Comments
 (0)