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 @@ package org.hibernate.action.internal;
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.engine.spi.Status;
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 @@ public class UnresolvedEntityInsertActions {
.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,17 +197,17 @@ public class UnresolvedEntityInsertActions {
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();
} }
else {
final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>( ); final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>( );
if ( traceEnabled ) { if ( traceEnabled ) {
LOG.tracev( LOG.tracev(
"Unresolved inserts before resolving [{0}]: [{1}]", "Unresolved inserts before resolving [{0}]: [{1}]",
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ), infoString( entityEntry.getEntityName(), entityEntry.getId() ),
toString() toString()
); );
} }
@ -214,8 +215,8 @@ public class UnresolvedEntityInsertActions {
if ( traceEnabled ) { if ( traceEnabled ) {
LOG.tracev( LOG.tracev(
"Resolving insert [{0}] dependency on [{1}]", "Resolving insert [{0}] dependency on [{1}]",
MessageHelper.infoString( dependentAction.getEntityName(), dependentAction.getId() ), infoString( dependentAction.getEntityName(), dependentAction.getId() ),
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ) infoString( entityEntry.getEntityName(), entityEntry.getId() )
); );
} }
final NonNullableTransientDependencies dependencies = dependenciesByAction.get( dependentAction ); final NonNullableTransientDependencies dependencies = dependenciesByAction.get( dependentAction );
@ -225,7 +226,7 @@ public class UnresolvedEntityInsertActions {
LOG.tracev( LOG.tracev(
"Resolving insert [{0}] (only depended on [{1}])", "Resolving insert [{0}] (only depended on [{1}])",
dependentAction, dependentAction,
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ) infoString( entityEntry.getEntityName(), entityEntry.getId() )
); );
} }
// dependentAction only depended on managedEntity.. // dependentAction only depended on managedEntity..
@ -236,12 +237,13 @@ public class UnresolvedEntityInsertActions {
if ( traceEnabled ) { if ( traceEnabled ) {
LOG.tracev( LOG.tracev(
"Unresolved inserts after resolving [{0}]: [{1}]", "Unresolved inserts after resolving [{0}]: [{1}]",
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ), infoString( entityEntry.getEntityName(), entityEntry.getId() ),
toString() toString()
); );
} }
return resolvedActions; return resolvedActions;
} }
}
/** /**
* Clear this {@link UnresolvedEntityInsertActions}. * Clear this {@link UnresolvedEntityInsertActions}.

View File

@ -19,9 +19,11 @@ import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttrib
/** /**
* 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 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor {
} }
else { else {
if ( interceptor != null && !interceptor.isAttributeLoaded( type.getName() ) ) { if ( interceptor != null && !interceptor.isAttributeLoaded( type.getName() ) ) {
return null; return null; //NOTE: EARLY EXIT!
} }
// if not wrapped yet, its dirty (this can't occur, because else {
// we now always call wrap() before getting to here) // if not wrapped yet, it's dirty
// return ( ! (obj instanceof PersistentCollection) ) ? // (this can't occur, because we now always call wrap() before getting here)
//true : searchForDirtyCollections( (PersistentCollection) obj, type ); // return ( ! (obj instanceof PersistentCollection) )
// ? true : searchForDirtyCollections( (PersistentCollection) obj, type );
persistentCollection = (PersistentCollection<?>) collection; 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!
} }
} }