Java Code Examples for org.hibernate.persister.entity.EntityPersister.afterReassociate()

The following are Jave code examples for showing how to use afterReassociate() of the org.hibernate.persister.entity.EntityPersister class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: DefaultSaveOrUpdateEventListener.java   View Source Code Vote up 4 votes
protected void performUpdate(
		SaveOrUpdateEvent event,
		Object entity,
		EntityPersister persister) throws HibernateException {

	final boolean traceEnabled = LOG.isTraceEnabled();
	if ( traceEnabled && !persister.isMutable() ) {
		LOG.trace( "Immutable instance passed to performUpdate()" );
	}

	if ( traceEnabled ) {
		LOG.tracev(
				"Updating {0}",
				MessageHelper.infoString( persister, event.getRequestedId(), event.getSession().getFactory() )
		);
	}

	final EventSource source = event.getSession();
	final EntityKey key = source.generateEntityKey( event.getRequestedId(), persister );

	source.getPersistenceContext().checkUniqueness( key, entity );

	if ( invokeUpdateLifecycle( entity, persister, source ) ) {
		reassociate( event, event.getObject(), event.getRequestedId(), persister );
		return;
	}

	// this is a transient object with existing persistent state not loaded by the session

	new OnUpdateVisitor( source, event.getRequestedId(), entity ).process( entity, persister );

	// TODO: put this stuff back in to read snapshot from
	// the second-level cache (needs some extra work)
	/*Object[] cachedState = null;

       if ( persister.hasCache() ) {
       	CacheEntry entry = (CacheEntry) persister.getCache()
       			.get( event.getRequestedId(), source.getTimestamp() );
           cachedState = entry==null ?
           		null :
           		entry.getState(); //TODO: half-assemble this stuff
       }*/

	source.getPersistenceContext().addEntity(
			entity,
			( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ),
			null, // cachedState,
			key,
			persister.getVersion( entity ),
			LockMode.NONE,
			true,
			persister,
			false,
			true // assume true, since we don't really know, and it doesn't matter
	);

	persister.afterReassociate( entity, source );

	if ( traceEnabled ) {
		LOG.tracev(
				"Updating {0}", MessageHelper.infoString(
				persister,
				event.getRequestedId(),
				source.getFactory()
		)
		);
	}

	cascadeOnUpdate( event, persister, entity );
}
 
Example 2
Project: lams   File: AbstractReassociateEventListener.java   View Source Code Vote up 4 votes
/**
 * Associates a given entity (either transient or associated with another session) to
 * the given session.
 *
 * @param event The event triggering the re-association
 * @param object The entity to be associated
 * @param id The id of the entity.
 * @param persister The entity's persister instance.
 *
 * @return An EntityEntry representing the entity within this session.
 */
protected final EntityEntry reassociate(AbstractEvent event, Object object, Serializable id, EntityPersister persister) {

	if ( log.isTraceEnabled() ) {
		log.tracev(
				"Reassociating transient instance: {0}",
				MessageHelper.infoString( persister, id, event.getSession().getFactory() )
		);
	}

	final EventSource source = event.getSession();
	final EntityKey key = source.generateEntityKey( id, persister );

	source.getPersistenceContext().checkUniqueness( key, object );

	//get a snapshot
	Object[] values = persister.getPropertyValues( object );
	TypeHelper.deepCopy(
			values,
			persister.getPropertyTypes(),
			persister.getPropertyUpdateability(),
			values,
			source
	);
	Object version = Versioning.getVersion( values, persister );

	EntityEntry newEntry = source.getPersistenceContext().addEntity(
			object,
			( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ),
			values,
			key,
			version,
			LockMode.NONE,
			true,
			persister,
			false,
			true //will be ignored, using the existing Entry instead
	);

	new OnLockVisitor( source, id, object ).process( object, persister );

	persister.afterReassociate( object, source );

	return newEntry;

}