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.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
@ -25,18 +24,20 @@ import org.hibernate.engine.spi.Status;
import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.IdentitySet;
import org.hibernate.pretty.MessageHelper;
import org.jboss.logging.Logger;
import static java.util.Collections.emptySet;
import static org.hibernate.pretty.MessageHelper.infoString;
/**
* Tracks unresolved entity insert actions.
*
* <p>
* An entity insert action is unresolved if the entity
* to be inserted has at least one non-nullable association with
* an unsaved transient entity, and the foreign key points to that
* unsaved transient entity.
*
* <p>
* These references must be resolved before an insert action can be
* executed.
*
@ -134,11 +135,11 @@ public class UnresolvedEntityInsertActions {
.getMappingMetamodel()
.getEntityDescriptor( transientEntityName )
.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> nonNullableTransientPropertyPaths = new TreeSet<>();
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 ) ) {
final String fullPath = dependentAction.getEntityName() + '.' + path;
nonNullableTransientPropertyPaths.add( fullPath );
@ -196,51 +197,52 @@ public class UnresolvedEntityInsertActions {
if ( traceEnabled ) {
LOG.tracev(
"No unresolved entity inserts that depended on [{0}]",
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() )
infoString( entityEntry.getEntityName(), entityEntry.getId() )
);
}
// NOTE EARLY EXIT!
return Collections.emptySet();
return emptySet();
}
final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>( );
if ( traceEnabled ) {
LOG.tracev(
"Unresolved inserts before resolving [{0}]: [{1}]",
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() ),
toString()
);
}
for ( AbstractEntityInsertAction dependentAction : dependentActions ) {
if ( traceEnabled ) {
else {
final Set<AbstractEntityInsertAction> resolvedActions = new IdentitySet<>( );
if ( traceEnabled ) {
LOG.tracev(
"Resolving insert [{0}] dependency on [{1}]",
MessageHelper.infoString( dependentAction.getEntityName(), dependentAction.getId() ),
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() )
"Unresolved inserts before resolving [{0}]: [{1}]",
infoString( entityEntry.getEntityName(), entityEntry.getId() ),
toString()
);
}
final NonNullableTransientDependencies dependencies = dependenciesByAction.get( dependentAction );
dependencies.resolveNonNullableTransientEntity( managedEntity );
if ( dependencies.isEmpty() ) {
for ( AbstractEntityInsertAction dependentAction : dependentActions ) {
if ( traceEnabled ) {
LOG.tracev(
"Resolving insert [{0}] (only depended on [{1}])",
dependentAction,
MessageHelper.infoString( entityEntry.getEntityName(), entityEntry.getId() )
"Resolving insert [{0}] dependency on [{1}]",
infoString( dependentAction.getEntityName(), dependentAction.getId() ),
infoString( entityEntry.getEntityName(), entityEntry.getId() )
);
}
// dependentAction only depended on managedEntity..
dependenciesByAction.remove( dependentAction );
resolvedActions.add( dependentAction );
final NonNullableTransientDependencies dependencies = dependenciesByAction.get( dependentAction );
dependencies.resolveNonNullableTransientEntity( managedEntity );
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 @@ import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttrib
/**
* Do we have a dirty collection here?
* 1. if it is a new application-instantiated collection, return true (does not occur anymore!)
* 2. if it is a component, recurse
* 3. if it is a wrappered collection, ask the collection entry
* <ol>
* <li>If it's a new application-instantiated collection, return true. (Does not occur anymore!)
* <li>If it's an embeddable, recurse.
* <li>If it is a wrappered collection, ask the collection entry.
* </ol>
*
* @author Gavin King
*/
@ -60,18 +62,19 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor {
}
else {
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!
dirty = true;
return null; //NOTE: EARLY EXIT!
}
}