minor code changes

This commit is contained in:
Gavin 2022-12-28 12:42:55 +01:00 committed by Gavin King
parent 60884a4c3a
commit cc46b622be
2 changed files with 54 additions and 49 deletions

View File

@ -9,7 +9,6 @@
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Collections;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -25,18 +24,20 @@
import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.IdentitySet; import org.hibernate.internal.util.collections.IdentitySet;
import org.hibernate.pretty.MessageHelper;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import static java.util.Collections.emptySet;
import static org.hibernate.pretty.MessageHelper.infoString;
/** /**
* Tracks unresolved entity insert actions. * Tracks unresolved entity insert actions.
* * <p>
* An entity insert action is unresolved if the entity * An entity insert action is unresolved if the entity
* to be inserted has at least one non-nullable association with * to be inserted has at least one non-nullable association with
* an unsaved transient entity, and the foreign key points to that * an unsaved transient entity, and the foreign key points to that
* unsaved transient entity. * unsaved transient entity.
* * <p>
* These references must be resolved before an insert action can be * These references must be resolved before an insert action can be
* executed. * executed.
* *
@ -134,11 +135,11 @@ private void logCannotResolveNonNullableTransientDependencies(SharedSessionContr
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( transientEntityName ) .getEntityDescriptor( transientEntityName )
.getIdentifier( transientEntity, session ); .getIdentifier( transientEntity, session );
final String transientEntityString = MessageHelper.infoString( transientEntityName, transientEntityId ); final String transientEntityString = infoString( transientEntityName, transientEntityId );
final Set<String> dependentEntityStrings = new TreeSet<>(); final Set<String> dependentEntityStrings = new TreeSet<>();
final Set<String> nonNullableTransientPropertyPaths = new TreeSet<>(); final Set<String> nonNullableTransientPropertyPaths = new TreeSet<>();
for ( AbstractEntityInsertAction dependentAction : entry.getValue() ) { for ( AbstractEntityInsertAction dependentAction : entry.getValue() ) {
dependentEntityStrings.add( MessageHelper.infoString( dependentAction.getEntityName(), dependentAction.getId() ) ); dependentEntityStrings.add( infoString( dependentAction.getEntityName(), dependentAction.getId() ) );
for ( String path : dependenciesByAction.get( dependentAction ).getNonNullableTransientPropertyPaths( transientEntity ) ) { for ( String path : dependenciesByAction.get( dependentAction ).getNonNullableTransientPropertyPaths( transientEntity ) ) {
final String fullPath = dependentAction.getEntityName() + '.' + path; final String fullPath = dependentAction.getEntityName() + '.' + path;
nonNullableTransientPropertyPaths.add( fullPath ); nonNullableTransientPropertyPaths.add( fullPath );
@ -196,51 +197,52 @@ public Set<AbstractEntityInsertAction> resolveDependentActions(Object managedEnt
if ( traceEnabled ) { if ( traceEnabled ) {
LOG.tracev( LOG.tracev(
"No unresolved entity inserts that depended on [{0}]", "No unresolved entity inserts that depended on [{0}]",
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ) infoString( entityEntry.getEntityName(), entityEntry.getId() )
); );
} }
// NOTE EARLY EXIT! return emptySet();
return Collections.emptySet();
} }
final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>( ); else {
if ( traceEnabled ) { final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>( );
LOG.tracev( if ( traceEnabled ) {
"Unresolved inserts before resolving [{0}]: [{1}]",
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ),
toString()
);
}
for ( AbstractEntityInsertAction dependentAction : dependentActions ) {
if ( traceEnabled ) {
LOG.tracev( LOG.tracev(
"Resolving insert [{0}] dependency on [{1}]", "Unresolved inserts before resolving [{0}]: [{1}]",
MessageHelper.infoString( dependentAction.getEntityName(), dependentAction.getId() ), infoString( entityEntry.getEntityName(), entityEntry.getId() ),
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ) toString()
); );
} }
final NonNullableTransientDependencies dependencies = dependenciesByAction.get( dependentAction ); for ( AbstractEntityInsertAction dependentAction : dependentActions ) {
dependencies.resolveNonNullableTransientEntity( managedEntity );
if ( dependencies.isEmpty() ) {
if ( traceEnabled ) { if ( traceEnabled ) {
LOG.tracev( LOG.tracev(
"Resolving insert [{0}] (only depended on [{1}])", "Resolving insert [{0}] dependency on [{1}]",
dependentAction, infoString( dependentAction.getEntityName(), dependentAction.getId() ),
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ) infoString( entityEntry.getEntityName(), entityEntry.getId() )
); );
} }
// dependentAction only depended on managedEntity.. final NonNullableTransientDependencies dependencies = dependenciesByAction.get( dependentAction );
dependenciesByAction.remove( dependentAction ); dependencies.resolveNonNullableTransientEntity( managedEntity );
resolvedActions.add( dependentAction ); if ( dependencies.isEmpty() ) {
if ( traceEnabled ) {
LOG.tracev(
"Resolving insert [{0}] (only depended on [{1}])",
dependentAction,
infoString( entityEntry.getEntityName(), entityEntry.getId() )
);
}
// dependentAction only depended on managedEntity..
dependenciesByAction.remove( dependentAction );
resolvedActions.add( dependentAction );
}
} }
if ( traceEnabled ) {
LOG.tracev(
"Unresolved inserts after resolving [{0}]: [{1}]",
infoString( entityEntry.getEntityName(), entityEntry.getId() ),
toString()
);
}
return resolvedActions;
} }
if ( traceEnabled ) {
LOG.tracev(
"Unresolved inserts after resolving [{0}]: [{1}]",
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ),
toString()
);
}
return resolvedActions;
} }
/** /**

View File

@ -19,9 +19,11 @@
/** /**
* Do we have a dirty collection here? * Do we have a dirty collection here?
* 1. if it is a new application-instantiated collection, return true (does not occur anymore!) * <ol>
* 2. if it is a component, recurse * <li>If it's a new application-instantiated collection, return true. (Does not occur anymore!)
* 3. if it is a wrappered collection, ask the collection entry * <li>If it's an embeddable, recurse.
* <li>If it is a wrappered collection, ask the collection entry.
* </ol>
* *
* @author Gavin King * @author Gavin King
*/ */
@ -60,18 +62,19 @@ Object processCollection(Object collection, CollectionType type) throws Hibernat
} }
else { else {
if ( interceptor != null && !interceptor.isAttributeLoaded( type.getName() ) ) { if ( interceptor != null && !interceptor.isAttributeLoaded( type.getName() ) ) {
return null; return null; //NOTE: EARLY EXIT!
}
else {
// if not wrapped yet, it's dirty
// (this can't occur, because we now always call wrap() before getting here)
// return ( ! (obj instanceof PersistentCollection) )
// ? true : searchForDirtyCollections( (PersistentCollection) obj, type );
persistentCollection = (PersistentCollection<?>) collection;
} }
// if not wrapped yet, its dirty (this can't occur, because
// we now always call wrap() before getting to here)
// return ( ! (obj instanceof PersistentCollection) ) ?
//true : searchForDirtyCollections( (PersistentCollection) obj, type );
persistentCollection = (PersistentCollection<?>) collection;
} }
if ( persistentCollection.isDirty() ) { //we need to check even if it was not initialized, because of delayed adds! if ( persistentCollection.isDirty() ) { //we need to check even if it was not initialized, because of delayed adds!
dirty = true; dirty = true;
return null; //NOTE: EARLY EXIT!
} }
} }