final Type[] types = persister.getPropertyTypes(); final boolean[] nullability = persister.getPropertyNullability(); final NonNullableTransientDependencies nonNullableTransientEntities = new NonNullableTransientDependencies(); for ( int i = 0; i < types.length; i++ ) { collectNonNullableTransientEntities( ); return nonNullableTransientEntities.isEmpty() ? null : nonNullableTransientEntities;
dependenciesByAction.get( firstDependentAction ); final Object firstTransientDependency = nonNullableTransientDependencies.getNonNullableTransientEntities().iterator().next(); final String firstPropertyPath = nonNullableTransientDependencies.getNonNullableTransientPropertyPaths( firstTransientDependency ).iterator().next();
/** * Add an unresolved insert action. * * @param insert - unresolved insert action. * @param dependencies - non-nullable transient dependencies * (must be non-null and non-empty). * * @throws IllegalArgumentException if {@code dependencies is null or empty}. */ public void addUnresolvedEntityInsertAction(AbstractEntityInsertAction insert, NonNullableTransientDependencies dependencies) { if ( dependencies == null || dependencies.isEmpty() ) { throw new IllegalArgumentException( "Attempt to add an unresolved insert action that has no non-nullable transient entities." ); } if ( LOG.isTraceEnabled() ) { LOG.tracev( "Adding insert with non-nullable, transient entities; insert=[{0}], dependencies=[{1}]", insert, dependencies.toLoggableString( insert.getSession() ) ); } dependenciesByAction.put( insert, dependencies ); addDependenciesByTransientEntity( insert, dependencies ); }
dependencies.resolveNonNullableTransientEntity( managedEntity ); if ( dependencies.isEmpty() ) { if ( traceEnabled ) { LOG.tracev(
@Override public String toString() { final StringBuilder sb = new StringBuilder( getClass().getSimpleName() ) .append( '[' ); for ( Map.Entry<AbstractEntityInsertAction,NonNullableTransientDependencies> entry : dependenciesByAction.entrySet() ) { final AbstractEntityInsertAction insert = entry.getKey(); final NonNullableTransientDependencies dependencies = entry.getValue(); sb.append( "[insert=" ) .append( insert ) .append( " dependencies=[" ) .append( dependencies.toLoggableString( insert.getSession() ) ) .append( "]" ); } sb.append( ']'); return sb.toString(); }
@SuppressWarnings({ "unchecked" }) private void addDependenciesByTransientEntity(AbstractEntityInsertAction insert, NonNullableTransientDependencies dependencies) { for ( Object transientEntity : dependencies.getNonNullableTransientEntities() ) { Set<AbstractEntityInsertAction> dependentActions = dependentActionsByTransientEntity.get( transientEntity ); if ( dependentActions == null ) { dependentActions = new IdentitySet(); dependentActionsByTransientEntity.put( transientEntity, dependentActions ); } dependentActions.add( insert ); } }
private void logCannotResolveNonNullableTransientDependencies(SharedSessionContractImplementor session) { for ( Map.Entry<Object,Set<AbstractEntityInsertAction>> entry : dependentActionsByTransientEntity.entrySet() ) { final Object transientEntity = entry.getKey(); final String transientEntityName = session.guessEntityName( transientEntity ); final Serializable transientEntityId = session.getFactory().getMetamodel().entityPersister( transientEntityName ).getIdentifier( transientEntity, session ); final String transientEntityString = MessageHelper.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() ) ); for ( String path : dependenciesByAction.get( dependentAction ).getNonNullableTransientPropertyPaths( transientEntity ) ) { final String fullPath = dependentAction.getEntityName() + '.' + path; nonNullableTransientPropertyPaths.add( fullPath ); } } LOG.cannotResolveNonNullableTransientDependencies( transientEntityString, dependentEntityStrings, nonNullableTransientPropertyPaths ); } }
/** * Add an unresolved insert action. * * @param insert - unresolved insert action. * @param dependencies - non-nullable transient dependencies * (must be non-null and non-empty). * * @throws IllegalArgumentException if {@code dependencies is null or empty}. */ public void addUnresolvedEntityInsertAction(AbstractEntityInsertAction insert, NonNullableTransientDependencies dependencies) { if ( dependencies == null || dependencies.isEmpty() ) { throw new IllegalArgumentException( "Attempt to add an unresolved insert action that has no non-nullable transient entities." ); } if ( LOG.isTraceEnabled() ) { LOG.tracev( "Adding insert with non-nullable, transient entities; insert=[{0}], dependencies=[{1}]", insert, dependencies.toLoggableString( insert.getSession() ) ); } dependenciesByAction.put( insert, dependencies ); addDependenciesByTransientEntity( insert, dependencies ); }
dependencies.resolveNonNullableTransientEntity( managedEntity ); if ( dependencies.isEmpty() ) { if ( traceEnabled ) { LOG.tracev(
private void addInsertAction(AbstractEntityInsertAction insert) { if ( insert.isEarlyInsert() ) { // For early inserts, must execute inserts before finding non-nullable transient entities. // TODO: find out why this is necessary LOG.tracev( "Executing inserts before finding non-nullable transient entities for early insert: [{0}]", insert ); executeInserts(); } NonNullableTransientDependencies nonNullableTransientDependencies = insert.findNonNullableTransientEntities(); if ( nonNullableTransientDependencies == null ) { LOG.tracev( "Adding insert with no non-nullable, transient entities: [{0}]", insert ); addResolvedEntityInsertAction( insert ); } else { if ( LOG.isTraceEnabled() ) { LOG.tracev( "Adding insert with non-nullable, transient entities; insert=[{0}], dependencies=[{1}]", insert, nonNullableTransientDependencies.toLoggableString( insert.getSession() ) ); } if( unresolvedInsertions == null ) { unresolvedInsertions = new UnresolvedEntityInsertActions(); } unresolvedInsertions.addUnresolvedEntityInsertAction( insert, nonNullableTransientDependencies ); } }
@SuppressWarnings({ "unchecked" }) private void addDependenciesByTransientEntity(AbstractEntityInsertAction insert, NonNullableTransientDependencies dependencies) { for ( Object transientEntity : dependencies.getNonNullableTransientEntities() ) { Set<AbstractEntityInsertAction> dependentActions = dependentActionsByTransientEntity.get( transientEntity ); if ( dependentActions == null ) { dependentActions = new IdentitySet(); dependentActionsByTransientEntity.put( transientEntity, dependentActions ); } dependentActions.add( insert ); } }
private void logCannotResolveNonNullableTransientDependencies(SessionImplementor session) { for ( Map.Entry<Object,Set<AbstractEntityInsertAction>> entry : dependentActionsByTransientEntity.entrySet() ) { Object transientEntity = entry.getKey(); String transientEntityName = session.guessEntityName( transientEntity ); Serializable transientEntityId = session.getFactory().getEntityPersister( transientEntityName ).getIdentifier( transientEntity, session ); String transientEntityString = MessageHelper.infoString( transientEntityName, transientEntityId ); Set<String> dependentEntityStrings = new TreeSet<String>(); Set<String> nonNullableTransientPropertyPaths = new TreeSet<String>(); for ( AbstractEntityInsertAction dependentAction : entry.getValue() ) { dependentEntityStrings.add( MessageHelper.infoString( dependentAction.getEntityName(), dependentAction.getId() ) ); for ( String path : dependenciesByAction.get( dependentAction ).getNonNullableTransientPropertyPaths( transientEntity ) ) { String fullPath = new StringBuilder( dependentAction.getEntityName().length() + path.length() + 1 ) .append( dependentAction.getEntityName() ) .append( '.' ) .append( path ) .toString(); nonNullableTransientPropertyPaths.add( fullPath ); } } LOG.cannotResolveNonNullableTransientDependencies( transientEntityString, dependentEntityStrings, nonNullableTransientPropertyPaths ); } }
/** * Add an unresolved insert action. * * @param insert - unresolved insert action. * @param dependencies - non-nullable transient dependencies * (must be non-null and non-empty). * * @throws IllegalArgumentException if {@code dependencies is null or empty}. */ public void addUnresolvedEntityInsertAction(AbstractEntityInsertAction insert, NonNullableTransientDependencies dependencies) { if ( dependencies == null || dependencies.isEmpty() ) { throw new IllegalArgumentException( "Attempt to add an unresolved insert action that has no non-nullable transient entities." ); } if ( LOG.isTraceEnabled() ) { LOG.tracev( "Adding insert with non-nullable, transient entities; insert=[{0}], dependencies=[{1}]", insert, dependencies.toLoggableString( insert.getSession() ) ); } dependenciesByAction.put( insert, dependencies ); addDependenciesByTransientEntity( insert, dependencies ); }
dependenciesByAction.get( firstDependentAction ); Object firstTransientDependency = nonNullableTransientDependencies.getNonNullableTransientEntities().iterator().next(); String firstPropertyPath = nonNullableTransientDependencies.getNonNullableTransientPropertyPaths( firstTransientDependency ).iterator().next(); throw new TransientPropertyValueException( "Not-null property references a transient value - transient instance must be saved before current operation",
final NonNullableTransientDependencies nonNullableTransientEntities = new NonNullableTransientDependencies(); final Nullifier nullifier = new Nullifier( entity, false, isEarlyInsert, session ); final EntityTypeDescriptor descriptor = session.getEntityDescriptor( entityName, entity ); return nonNullableTransientEntities.isEmpty() ? null : nonNullableTransientEntities;
dependencies.resolveNonNullableTransientEntity( managedEntity ); if ( dependencies.isEmpty() ) { if ( LOG.isTraceEnabled() ) { LOG.tracev(
@Override public String toString() { StringBuilder sb = new StringBuilder( getClass().getSimpleName() ) .append( '[' ); for ( Map.Entry<AbstractEntityInsertAction,NonNullableTransientDependencies> entry : dependenciesByAction.entrySet() ) { AbstractEntityInsertAction insert = entry.getKey(); NonNullableTransientDependencies dependencies = entry.getValue(); sb.append( "[insert=" ) .append( insert ) .append( " dependencies=[" ) .append( dependencies.toLoggableString( insert.getSession() ) ) .append( "]" ); } sb.append( ']'); return sb.toString(); }
@SuppressWarnings({ "unchecked" }) private void addDependenciesByTransientEntity(AbstractEntityInsertAction insert, NonNullableTransientDependencies dependencies) { for ( Object transientEntity : dependencies.getNonNullableTransientEntities() ) { Set<AbstractEntityInsertAction> dependentActions = dependentActionsByTransientEntity.get( transientEntity ); if ( dependentActions == null ) { dependentActions = new IdentitySet(); dependentActionsByTransientEntity.put( transientEntity, dependentActions ); } dependentActions.add( insert ); } }
private void logCannotResolveNonNullableTransientDependencies(SessionImplementor session) { for ( Map.Entry<Object,Set<AbstractEntityInsertAction>> entry : dependentActionsByTransientEntity.entrySet() ) { Object transientEntity = entry.getKey(); String transientEntityName = session.guessEntityName( transientEntity ); Serializable transientEntityId = session.getFactory().getEntityPersister( transientEntityName ).getIdentifier( transientEntity, session ); String transientEntityString = MessageHelper.infoString( transientEntityName, transientEntityId ); Set<String> dependentEntityStrings = new TreeSet<String>(); Set<String> nonNullableTransientPropertyPaths = new TreeSet<String>(); for ( AbstractEntityInsertAction dependentAction : entry.getValue() ) { dependentEntityStrings.add( MessageHelper.infoString( dependentAction.getEntityName(), dependentAction.getId() ) ); for ( String path : dependenciesByAction.get( dependentAction ).getNonNullableTransientPropertyPaths( transientEntity ) ) { String fullPath = new StringBuilder( dependentAction.getEntityName().length() + path.length() + 1 ) .append( dependentAction.getEntityName() ) .append( '.' ) .append( path ) .toString(); nonNullableTransientPropertyPaths.add( fullPath ); } } LOG.cannotResolveNonNullableTransientDependencies( transientEntityString, dependentEntityStrings, nonNullableTransientPropertyPaths ); } }