Skip to content

Commit ad525a6

Browse files
committed
misc things in engine
1 parent d7b5bd3 commit ad525a6

File tree

3 files changed

+22
-46
lines changed

3 files changed

+22
-46
lines changed

hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractTransactionCompletionProcessQueue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
abstract class AbstractTransactionCompletionProcessQueue<T extends CompletionCallback> {
2020
SharedSessionContractImplementor session;
21-
// Concurrency handling required when transaction completion process is dynamically registered
22-
// inside event listener (HHH-7478).
21+
// Concurrency handling required when the transaction completion process
22+
// is dynamically registered inside an event listener (HHH-7478).
2323
ConcurrentLinkedQueue<@NonNull T> processes = new ConcurrentLinkedQueue<>();
2424

2525
AbstractTransactionCompletionProcessQueue(SharedSessionContractImplementor session) {

hibernate-core/src/main/java/org/hibernate/engine/internal/AfterTransactionCompletionProcessQueue.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
package org.hibernate.engine.internal;
66

77
import org.hibernate.HibernateException;
8-
import org.hibernate.action.internal.BulkOperationCleanupAction;
8+
import org.hibernate.action.internal.BulkOperationCleanupAction.BulkOperationCleanUpAfterTransactionCompletionProcess;
99
import org.hibernate.cache.CacheException;
10-
import org.hibernate.engine.spi.SessionFactoryImplementor;
1110
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1211
import org.hibernate.engine.spi.TransactionCompletionCallbacks.AfterCompletionCallback;
1312

1413
import java.util.HashSet;
15-
import java.util.Iterator;
1614
import java.util.Set;
1715

1816
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
17+
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
1918

2019
/**
2120
* Encapsulates behavior needed for after transaction processing
@@ -54,20 +53,20 @@ void afterTransactionCompletion(boolean success) {
5453
}
5554
}
5655

57-
final SessionFactoryImplementor factory = session.getFactory();
56+
final var factory = session.getFactory();
5857
if ( factory.getSessionFactoryOptions().isQueryCacheEnabled() ) {
5958
factory.getCache().getTimestampsCache()
60-
.invalidate( querySpacesToInvalidate.toArray( new String[0] ), session );
59+
.invalidate( querySpacesToInvalidate.toArray( EMPTY_STRING_ARRAY ), session );
6160
}
6261
querySpacesToInvalidate.clear();
6362
}
6463

6564
void executePendingBulkOperationCleanUpActions() {
6665
boolean hasPendingBulkOperationCleanUpActions = false;
67-
Iterator<AfterCompletionCallback> iterator = processes.iterator();
66+
var iterator = processes.iterator();
6867
while ( iterator.hasNext() ) {
69-
AfterCompletionCallback process = iterator.next();
70-
if ( process instanceof BulkOperationCleanupAction.BulkOperationCleanUpAfterTransactionCompletionProcess ) {
68+
var process = iterator.next();
69+
if ( process instanceof BulkOperationCleanUpAfterTransactionCompletionProcess ) {
7170
try {
7271
hasPendingBulkOperationCleanUpActions = true;
7372
process.doAfterTransactionCompletion( true, session );
@@ -87,11 +86,10 @@ void executePendingBulkOperationCleanUpActions() {
8786
}
8887

8988
if ( hasPendingBulkOperationCleanUpActions ) {
90-
if ( session.getFactory().getSessionFactoryOptions().isQueryCacheEnabled() ) {
91-
session.getFactory().getCache().getTimestampsCache().invalidate(
92-
querySpacesToInvalidate.toArray( new String[0] ),
93-
session
94-
);
89+
final var factory = session.getFactory();
90+
if ( factory.getSessionFactoryOptions().isQueryCacheEnabled() ) {
91+
factory.getCache().getTimestampsCache().
92+
invalidate( querySpacesToInvalidate.toArray( EMPTY_STRING_ARRAY ), session );
9593
}
9694
querySpacesToInvalidate.clear();
9795
}

hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,15 @@ class StatefulPersistenceContext implements PersistenceContext {
8989

9090
private static final int INIT_COLL_SIZE = 8;
9191

92-
/*
93-
Eagerly Initialized Fields
94-
the following fields are used in all circumstances, and are not worth (or not suited) to being converted into lazy
95-
*/
92+
// Eagerly initialized fields. The following fields are used in every circumstance
93+
// and are not worth (or not suited) to being converted to lazy initialization.
94+
9695
private final SharedSessionContractImplementor session;
9796
private EntityEntryContext entityEntryContext;
9897

99-
/*
100-
Everything else below should be carefully initialized only on first need;
101-
this optimisation is very effective as null checks are free, while allocation costs
102-
are very often the dominating cost of an application using ORM.
103-
This is not general advice, but it's worth the added maintenance burden in this case
104-
as this is a very central component of our library.
105-
*/
98+
// Everything else below should be carefully initialized only on first need.
99+
// This optimization is very effective as null checks are free, while allocation
100+
// costs are very often the dominating cost of an application using ORM.
106101

107102
// Loaded entity instances, by EntityKey
108103
private HashMap<EntityKey, EntityHolderImpl> entitiesByKey;
@@ -113,8 +108,7 @@ the following fields are used in all circumstances, and are not worth (or not su
113108
// Loaded entity instances, by EntityUniqueKey
114109
private HashMap<EntityUniqueKey, Object> entitiesByUniqueKey;
115110

116-
117-
// Snapshots of current database state for entities
111+
// Snapshots of the current database state for entities
118112
// that have *not* been loaded
119113
private HashMap<EntityKey, Object> entitySnapshotsByKey;
120114

@@ -136,7 +130,7 @@ the following fields are used in all circumstances, and are not worth (or not su
136130
// Set of EntityKeys of deleted unloaded proxies
137131
private HashSet<EntityKey> deletedUnloadedEntityKeys;
138132

139-
// properties that we have tried to load, and not found in the database
133+
// properties that we have tried to load and not found in the database
140134
private HashSet<AssociationKey> nullAssociations;
141135

142136
// A list of collection wrappers that were instantiating during result set
@@ -209,14 +203,6 @@ public boolean hasLoadContext() {
209203
return loadContexts != null;
210204
}
211205

212-
// @Override
213-
// public void addUnownedCollection(CollectionKey key, PersistentCollection collection) {
214-
// if ( unownedCollections == null ) {
215-
// unownedCollections = CollectionHelper.mapOfSize( INIT_COLL_SIZE );
216-
// }
217-
// unownedCollections.put( key, collection );
218-
// }
219-
//
220206
@Override
221207
public PersistentCollection<?> useUnownedCollection(CollectionKey key) {
222208
return unownedCollections == null ? null : unownedCollections.remove( key );
@@ -935,7 +921,7 @@ else if ( ownerPersister.isInstance( key ) ) {
935921
}
936922
else {
937923
// b) try by EntityKey, which means we need to resolve owner-key -> collection-key
938-
// IMPL NOTE : yes if we get here this impl is very non-performant, but PersistenceContext
924+
// IMPL NOTE: yes if we get here this impl is very non-performant, but PersistenceContext
939925
// was never designed to handle this case; adding that capability for real means splitting
940926
// the notions of:
941927
// 1) collection key
@@ -1228,14 +1214,6 @@ public Object removeProxy(EntityKey key) {
12281214
return removeProxyByKey( key );
12291215
}
12301216

1231-
// @Override
1232-
// public HashSet getNullifiableEntityKeys() {
1233-
// if ( nullifiableEntityKeys == null ) {
1234-
// nullifiableEntityKeys = new HashSet<>();
1235-
// }
1236-
// return nullifiableEntityKeys;
1237-
// }
1238-
12391217
/**
12401218
* @deprecated this will be removed: it provides too wide access, making it hard to optimise the internals
12411219
* for specific access needs. Consider using #iterateEntities instead.

0 commit comments

Comments
 (0)