Skip to content

Commit cc46b62

Browse files
committed
minor code changes
1 parent 60884a4 commit cc46b62

File tree

2 files changed

+54
-49
lines changed

2 files changed

+54
-49
lines changed

hibernate-core/src/main/java/org/hibernate/action/internal/UnresolvedEntityInsertActions.java

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.io.IOException;
1010
import java.io.ObjectInputStream;
1111
import java.io.ObjectOutputStream;
12-
import java.util.Collections;
1312
import java.util.IdentityHashMap;
1413
import java.util.Map;
1514
import java.util.Set;
@@ -25,18 +24,20 @@
2524
import org.hibernate.event.spi.EventSource;
2625
import org.hibernate.internal.CoreMessageLogger;
2726
import org.hibernate.internal.util.collections.IdentitySet;
28-
import org.hibernate.pretty.MessageHelper;
2927

3028
import org.jboss.logging.Logger;
3129

30+
import static java.util.Collections.emptySet;
31+
import static org.hibernate.pretty.MessageHelper.infoString;
32+
3233
/**
3334
* Tracks unresolved entity insert actions.
34-
*
35+
* <p>
3536
* An entity insert action is unresolved if the entity
3637
* to be inserted has at least one non-nullable association with
3738
* an unsaved transient entity, and the foreign key points to that
3839
* unsaved transient entity.
39-
*
40+
* <p>
4041
* These references must be resolved before an insert action can be
4142
* executed.
4243
*
@@ -134,11 +135,11 @@ private void logCannotResolveNonNullableTransientDependencies(SharedSessionContr
134135
.getMappingMetamodel()
135136
.getEntityDescriptor( transientEntityName )
136137
.getIdentifier( transientEntity, session );
137-
final String transientEntityString = MessageHelper.infoString( transientEntityName, transientEntityId );
138+
final String transientEntityString = infoString( transientEntityName, transientEntityId );
138139
final Set<String> dependentEntityStrings = new TreeSet<>();
139140
final Set<String> nonNullableTransientPropertyPaths = new TreeSet<>();
140141
for ( AbstractEntityInsertAction dependentAction : entry.getValue() ) {
141-
dependentEntityStrings.add( MessageHelper.infoString( dependentAction.getEntityName(), dependentAction.getId() ) );
142+
dependentEntityStrings.add( infoString( dependentAction.getEntityName(), dependentAction.getId() ) );
142143
for ( String path : dependenciesByAction.get( dependentAction ).getNonNullableTransientPropertyPaths( transientEntity ) ) {
143144
final String fullPath = dependentAction.getEntityName() + '.' + path;
144145
nonNullableTransientPropertyPaths.add( fullPath );
@@ -196,51 +197,52 @@ public Set<AbstractEntityInsertAction> resolveDependentActions(Object managedEnt
196197
if ( traceEnabled ) {
197198
LOG.tracev(
198199
"No unresolved entity inserts that depended on [{0}]",
199-
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() )
200+
infoString( entityEntry.getEntityName(), entityEntry.getId() )
200201
);
201202
}
202-
// NOTE EARLY EXIT!
203-
return Collections.emptySet();
204-
}
205-
final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>( );
206-
if ( traceEnabled ) {
207-
LOG.tracev(
208-
"Unresolved inserts before resolving [{0}]: [{1}]",
209-
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ),
210-
toString()
211-
);
203+
return emptySet();
212204
}
213-
for ( AbstractEntityInsertAction dependentAction : dependentActions ) {
214-
if ( traceEnabled ) {
205+
else {
206+
final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>( );
207+
if ( traceEnabled ) {
215208
LOG.tracev(
216-
"Resolving insert [{0}] dependency on [{1}]",
217-
MessageHelper.infoString( dependentAction.getEntityName(), dependentAction.getId() ),
218-
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() )
209+
"Unresolved inserts before resolving [{0}]: [{1}]",
210+
infoString( entityEntry.getEntityName(), entityEntry.getId() ),
211+
toString()
219212
);
220213
}
221-
final NonNullableTransientDependencies dependencies = dependenciesByAction.get( dependentAction );
222-
dependencies.resolveNonNullableTransientEntity( managedEntity );
223-
if ( dependencies.isEmpty() ) {
214+
for ( AbstractEntityInsertAction dependentAction : dependentActions ) {
224215
if ( traceEnabled ) {
225216
LOG.tracev(
226-
"Resolving insert [{0}] (only depended on [{1}])",
227-
dependentAction,
228-
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() )
217+
"Resolving insert [{0}] dependency on [{1}]",
218+
infoString( dependentAction.getEntityName(), dependentAction.getId() ),
219+
infoString( entityEntry.getEntityName(), entityEntry.getId() )
229220
);
230221
}
231-
// dependentAction only depended on managedEntity..
232-
dependenciesByAction.remove( dependentAction );
233-
resolvedActions.add( dependentAction );
222+
final NonNullableTransientDependencies dependencies = dependenciesByAction.get( dependentAction );
223+
dependencies.resolveNonNullableTransientEntity( managedEntity );
224+
if ( dependencies.isEmpty() ) {
225+
if ( traceEnabled ) {
226+
LOG.tracev(
227+
"Resolving insert [{0}] (only depended on [{1}])",
228+
dependentAction,
229+
infoString( entityEntry.getEntityName(), entityEntry.getId() )
230+
);
231+
}
232+
// dependentAction only depended on managedEntity..
233+
dependenciesByAction.remove( dependentAction );
234+
resolvedActions.add( dependentAction );
235+
}
234236
}
237+
if ( traceEnabled ) {
238+
LOG.tracev(
239+
"Unresolved inserts after resolving [{0}]: [{1}]",
240+
infoString( entityEntry.getEntityName(), entityEntry.getId() ),
241+
toString()
242+
);
243+
}
244+
return resolvedActions;
235245
}
236-
if ( traceEnabled ) {
237-
LOG.tracev(
238-
"Unresolved inserts after resolving [{0}]: [{1}]",
239-
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ),
240-
toString()
241-
);
242-
}
243-
return resolvedActions;
244246
}
245247

246248
/**

hibernate-core/src/main/java/org/hibernate/event/internal/DirtyCollectionSearchVisitor.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
/**
2121
* Do we have a dirty collection here?
22-
* 1. if it is a new application-instantiated collection, return true (does not occur anymore!)
23-
* 2. if it is a component, recurse
24-
* 3. if it is a wrappered collection, ask the collection entry
22+
* <ol>
23+
* <li>If it's a new application-instantiated collection, return true. (Does not occur anymore!)
24+
* <li>If it's an embeddable, recurse.
25+
* <li>If it is a wrappered collection, ask the collection entry.
26+
* </ol>
2527
*
2628
* @author Gavin King
2729
*/
@@ -60,18 +62,19 @@ Object processCollection(Object collection, CollectionType type) throws Hibernat
6062
}
6163
else {
6264
if ( interceptor != null && !interceptor.isAttributeLoaded( type.getName() ) ) {
63-
return null;
65+
return null; //NOTE: EARLY EXIT!
66+
}
67+
else {
68+
// if not wrapped yet, it's dirty
69+
// (this can't occur, because we now always call wrap() before getting here)
70+
// return ( ! (obj instanceof PersistentCollection) )
71+
// ? true : searchForDirtyCollections( (PersistentCollection) obj, type );
72+
persistentCollection = (PersistentCollection<?>) collection;
6473
}
65-
// if not wrapped yet, its dirty (this can't occur, because
66-
// we now always call wrap() before getting to here)
67-
// return ( ! (obj instanceof PersistentCollection) ) ?
68-
//true : searchForDirtyCollections( (PersistentCollection) obj, type );
69-
persistentCollection = (PersistentCollection<?>) collection;
7074
}
7175

7276
if ( persistentCollection.isDirty() ) { //we need to check even if it was not initialized, because of delayed adds!
7377
dirty = true;
74-
return null; //NOTE: EARLY EXIT!
7578
}
7679
}
7780

0 commit comments

Comments
 (0)