/** * Associates the specified merge entity with the specified managed entity result in this MergeContext. * If this MergeContext already contains a cross-reference for <code>mergeEntity</code> when this * method is called, then <code>managedEntity</code> must be the same as what is already associated * with <code>mergeEntity</code>. * <p/> * This method assumes that the merge process is not yet operating on <code>mergeEntity</code>. * Later when <code>mergeEntity</code> enters the merge process, {@link #setOperatedOn(Object, boolean)} * should be called. * <p/> * @param mergeEntity the merge entity; must be non-null * @param managedEntity the managed entity result; must be non-null * @return previous managed entity associated with specified merge entity, or null if * there was no mapping for mergeEntity. * @throws NullPointerException if mergeEntity or managedEntity is null * @throws IllegalArgumentException if <code>managedEntity</code> is not the same as the previous * managed entity associated with <code>merge entity</code> * @throws IllegalStateException if internal cross-references are out of sync, */ public Object put(Object mergeEntity, Object managedEntity) { return put( mergeEntity, managedEntity, Boolean.FALSE ); }
/** * Copies all of the mappings from the specified Map to this MergeContext. * The key and value for each entry in <code>map</code> is subject to the same * restrictions as {@link #put(Object mergeEntity, Object managedEntity)}. * * This method assumes that the merge process is not yet operating on any merge entity * * @param map keys and values must be non-null * @throws NullPointerException if any key or value is null * @throws IllegalArgumentException if a key in <code>map</code> was already in this MergeContext * but associated value in <code>map</code> is different from the previous value in this MergeContext. * @throws IllegalStateException if internal cross-references are out of sync, */ public void putAll(Map map) { for ( Object o : map.entrySet() ) { Entry entry = (Entry) o; put( entry.getKey(), entry.getValue() ); } }
protected void entityIsPersistent(MergeEvent event, Map copyCache) { LOG.trace( "Ignoring persistent instance" ); //TODO: check that entry.getIdentifier().equals(requestedId) final Object entity = event.getEntity(); final EventSource source = event.getSession(); final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity ); ( (MergeContext) copyCache ).put( entity, entity, true ); //before cascade! cascadeOnMerge( source, persister, entity, copyCache ); copyValues( persister, entity, entity, source, copyCache ); event.setResult( entity ); }
protected void entityIsTransient(MergeEvent event, Map copyCache) { LOG.trace( "Merging transient instance" ); final Object entity = event.getEntity(); final EventSource source = event.getSession(); final String entityName = event.getEntityName(); final EntityPersister persister = source.getEntityPersister( entityName, entity ); final Serializable id = persister.hasIdentifierProperty() ? persister.getIdentifier( entity, source ) : null; if ( copyCache.containsKey( entity ) ) { persister.setIdentifier( copyCache.get( entity ), id, source ); } else { ( (MergeContext) copyCache ).put( entity, source.instantiate( persister, id ), true ); //before cascade! } final Object copy = copyCache.get( entity ); // cascade first, so that all unsaved objects get their // copy created before we actually copy //cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE); super.cascadeBeforeSave( source, persister, entity, copyCache ); copyValues( persister, entity, copy, source, copyCache, ForeignKeyDirection.FROM_PARENT ); saveTransientEntity( copy, entityName, event.getRequestedId(), source, copyCache ); // cascade first, so that all unsaved objects get their // copy created before we actually copy super.cascadeAfterSave( source, persister, entity, copyCache ); copyValues( persister, entity, copy, source, copyCache, ForeignKeyDirection.TO_PARENT ); event.setResult( copy ); }
( (MergeContext) copyCache ).put( entity, result, true ); //before cascade!
/** * Associates the specified merge entity with the specified managed entity result in this MergeContext. * If this MergeContext already contains a cross-reference for <code>mergeEntity</code> when this * method is called, then <code>managedEntity</code> must be the same as what is already associated * with <code>mergeEntity</code>. * <p/> * This method assumes that the merge process is not yet operating on <code>mergeEntity</code>. * Later when <code>mergeEntity</code> enters the merge process, {@link #setOperatedOn(Object, boolean)} * should be called. * <p/> * @param mergeEntity the merge entity; must be non-null * @param managedEntity the managed entity result; must be non-null * @return previous managed entity associated with specified merge entity, or null if * there was no mapping for mergeEntity. * @throws NullPointerException if mergeEntity or managedEntity is null * @throws IllegalArgumentException if <code>managedEntity</code> is not the same as the previous * managed entity associated with <code>merge entity</code> * @throws IllegalStateException if internal cross-references are out of sync, */ public Object put(Object mergeEntity, Object managedEntity) { return put( mergeEntity, managedEntity, Boolean.FALSE ); }
/** * Copies all of the mappings from the specified Map to this MergeContext. * The key and value for each entry in <code>map</code> is subject to the same * restrictions as {@link #put(Object mergeEntity, Object managedEntity)}. * * This method assumes that the merge process is not yet operating on any merge entity * * @param map keys and values must be non-null * @throws NullPointerException if any key or value is null * @throws IllegalArgumentException if a key in <code>map</code> was already in this MergeContext * but associated value in <code>map</code> is different from the previous value in this MergeContext. * @throws IllegalStateException if internal cross-references are out of sync, */ public void putAll(Map map) { for ( Object o : map.entrySet() ) { Entry entry = (Entry) o; put( entry.getKey(), entry.getValue() ); } }
protected void entityIsPersistent(MergeEvent event, Map copyCache) { LOG.trace( "Ignoring persistent instance" ); //TODO: check that entry.getIdentifier().equals(requestedId) final Object entity = event.getEntity(); final EventSource source = event.getSession(); final EntityTypeDescriptor entityDescriptor = source.getEntityDescriptor( event.getEntityName(), entity ); ( (MergeContext) copyCache ).put( entity, entity, true ); //before cascade! cascadeOnMerge( source, entityDescriptor, entity, copyCache ); copyValues( entityDescriptor, entity, entity, source, copyCache ); event.setResult( entity ); }
protected void entityIsTransient(MergeEvent event, Map copyCache) { LOG.trace( "Merging transient instance" ); final Object entity = event.getEntity(); final EventSource source = event.getSession(); final String entityName = event.getEntityName(); final EntityTypeDescriptor entityDescriptor = source.getEntityDescriptor( entityName, entity ); final Object id = EntityIdentifierSimple.class.isInstance( entityDescriptor.getHierarchy().getIdentifierDescriptor() ) ? entityDescriptor.getIdentifier( entity, source ) : null; if ( copyCache.containsKey( entity ) ) { entityDescriptor.setIdentifier( copyCache.get( entity ), id, source ); } else { ( (MergeContext) copyCache ).put( entity, source.instantiate( entityDescriptor, id ), true ); //before cascade! } final Object copy = copyCache.get( entity ); // cascade first, so that all unsaved objects get their // copy created before we actually copy //cascadeOnMerge(event, entityDescriptor, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE); super.cascadeBeforeSave( source, entityDescriptor, entity, copyCache ); copyValues( entityDescriptor, entity, copy, source, copyCache, ForeignKeyDirection.FROM_PARENT ); saveTransientEntity( copy, entityName, event.getRequestedId(), source, copyCache ); // cascade first, so that all unsaved objects get their // copy created before we actually copy super.cascadeAfterSave( source, entityDescriptor, entity, copyCache ); copyValues( entityDescriptor, entity, copy, source, copyCache, ForeignKeyDirection.TO_PARENT ); event.setResult( copy ); }
( (MergeContext) copyCache ).put( entity, result, true ); //before cascade!