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

The following examples show how to use org.hibernate.persister.entity.EntityPersister#hasCollections() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultReactiveFlushEntityEventListener.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean wrapCollections(
		EventSource session,
		EntityPersister persister,
		Type[] types,
		Object[] values
) {
	if ( persister.hasCollections() ) {

		// wrap up any new collections directly referenced by the object
		// or its components

		// NOTE: we need to do the wrap here even if its not "dirty",
		// because collections need wrapping but changes to _them_
		// don't dirty the container. Also, for versioned data, we
		// need to wrap before calling searchForDirtyCollections

		WrapVisitor visitor = new WrapVisitor( session );
		// substitutes into values by side-effect
		visitor.processEntityPropertyValues( values, types );
		return visitor.isSubstitutionRequired();
	}
	else {
		return false;
	}
}
 
Example 2
Source File: DefaultFlushEntityEventListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private boolean wrapCollections(
		EventSource session,
		EntityPersister persister,
		Type[] types,
		Object[] values
) {
	if ( persister.hasCollections() ) {

		// wrap up any new collections directly referenced by the object
		// or its components

		// NOTE: we need to do the wrap here even if its not "dirty",
		// because collections need wrapping but changes to _them_
		// don't dirty the container. Also, for versioned data, we
		// need to wrap before calling searchForDirtyCollections

		WrapVisitor visitor = new WrapVisitor( session );
		// substitutes into values by side-effect
		visitor.processEntityPropertyValues( values, types );
		return visitor.isSubstitutionRequired();
	}
	else {
		return false;
	}
}
 
Example 3
Source File: DefaultEvictEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void doEvict(
	final Object object, 
	final EntityKey key, 
	final EntityPersister persister,
	final EventSource session) throws HibernateException {

	if ( log.isTraceEnabled() ) {
		log.trace( "evicting " + MessageHelper.infoString(persister) );
	}

	// remove all collections for the entity from the session-level cache
	if ( persister.hasCollections() ) {
		new EvictVisitor( session ).process( object, persister );
	}

	new Cascade( CascadingAction.EVICT, Cascade.AFTER_EVICT, session )
			.cascade( persister, object );
}
 
Example 4
Source File: DefaultFlushEntityEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean wrapCollections(
		EventSource session,
		EntityPersister persister,
		Type[] types,
		Object[] values
) {
	if ( persister.hasCollections() ) {

		// wrap up any new collections directly referenced by the object
		// or its components

		// NOTE: we need to do the wrap here even if its not "dirty",
		// because collections need wrapping but changes to _them_
		// don't dirty the container. Also, for versioned data, we
		// need to wrap before calling searchForDirtyCollections

		WrapVisitor visitor = new WrapVisitor(session);
		// substitutes into values by side-effect
		visitor.processEntityPropertyValues(values, types);
		return visitor.isSubstitutionRequired();
	}
	else {
		return false;
	}
}
 
Example 5
Source File: DefaultReactiveFlushEntityEventListener.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Flushes a single entity's state to the database, by scheduling
 * an update action, if necessary
 */
public void onFlushEntity(FlushEntityEvent event) throws HibernateException {
	final Object entity = event.getEntity();
	final EntityEntry entry = event.getEntityEntry();
	final EventSource session = event.getSession();
	final EntityPersister persister = entry.getPersister();
	final Status status = entry.getStatus();
	final Type[] types = persister.getPropertyTypes();

	final boolean mightBeDirty = entry.requiresDirtyCheck( entity );

	final Object[] values = getValues( entity, entry, mightBeDirty, session );

	event.setPropertyValues( values );

	//TODO: avoid this for non-new instances where mightBeDirty==false
	boolean substitute = wrapCollections( session, persister, types, values );

	if ( isUpdateNecessary( event, mightBeDirty ) ) {
		substitute = scheduleUpdate( event ) || substitute;
	}

	if ( status != Status.DELETED ) {
		// now update the object .. has to be outside the main if block above (because of collections)
		if ( substitute ) {
			persister.setPropertyValues( entity, values );
		}

		// Search for collections by reachability, updating their role.
		// We don't want to touch collections reachable from a deleted object
		if ( persister.hasCollections() ) {
			new FlushVisitor( session, entity ).processEntityPropertyValues( values, types );
		}
	}
}
 
Example 6
Source File: DefaultEvictEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void doEvict(
		final Object object,
		final EntityKey key,
		final EntityPersister persister,
		final EventSource session)
		throws HibernateException {

	if ( LOG.isTraceEnabled() ) {
		LOG.tracev( "Evicting {0}", MessageHelper.infoString( persister ) );
	}

	if ( persister.hasNaturalIdentifier() ) {
		session.getPersistenceContext().getNaturalIdHelper().handleEviction(
				object,
				persister,
				key.getIdentifier()
		);
	}

	// remove all collections for the entity from the session-level cache
	if ( persister.hasCollections() ) {
		new EvictVisitor( session, object ).process( object, persister );
	}

	// remove any snapshot, not really for memory management purposes, but
	// rather because it might now be stale, and there is no longer any
	// EntityEntry to take precedence
	// This is now handled by removeEntity()
	//session.getPersistenceContext().removeDatabaseSnapshot(key);
	
	session.getPersistenceContext().removeEntity( key );
	session.getPersistenceContext().removeEntry( object );

	Cascade.cascade( CascadingActions.EVICT, CascadePoint.AFTER_EVICT, session, persister, object );
}
 
Example 7
Source File: DefaultFlushEntityEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Flushes a single entity's state to the database, by scheduling
 * an update action, if necessary
 */
public void onFlushEntity(FlushEntityEvent event) throws HibernateException {
	final Object entity = event.getEntity();
	final EntityEntry entry = event.getEntityEntry();
	final EventSource session = event.getSession();
	final EntityPersister persister = entry.getPersister();
	final Status status = entry.getStatus();
	final Type[] types = persister.getPropertyTypes();

	final boolean mightBeDirty = entry.requiresDirtyCheck( entity );

	final Object[] values = getValues( entity, entry, mightBeDirty, session );

	event.setPropertyValues( values );

	//TODO: avoid this for non-new instances where mightBeDirty==false
	boolean substitute = wrapCollections( session, persister, types, values );

	if ( isUpdateNecessary( event, mightBeDirty ) ) {
		substitute = scheduleUpdate( event ) || substitute;
	}

	if ( status != Status.DELETED ) {
		// now update the object .. has to be outside the main if block above (because of collections)
		if ( substitute ) {
			persister.setPropertyValues( entity, values );
		}

		// Search for collections by reachability, updating their role.
		// We don't want to touch collections reachable from a deleted object
		if ( persister.hasCollections() ) {
			new FlushVisitor( session, entity ).processEntityPropertyValues( values, types );
		}
	}

}
 
Example 8
Source File: DefaultFlushEntityEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Flushes a single entity's state to the database, by scheduling
 * an update action, if necessary
 */
public void onFlushEntity(FlushEntityEvent event) throws HibernateException {
	final Object entity = event.getEntity();
	final EntityEntry entry = event.getEntityEntry();
	final EventSource session = event.getSession();
	final EntityPersister persister = entry.getPersister();
	final Status status = entry.getStatus();
	final EntityMode entityMode = session.getEntityMode();
	final Type[] types = persister.getPropertyTypes();

	final boolean mightBeDirty = entry.requiresDirtyCheck(entity);

	final Object[] values = getValues( entity, entry, entityMode, mightBeDirty, session );

	event.setPropertyValues(values);

	//TODO: avoid this for non-new instances where mightBeDirty==false
	boolean substitute = wrapCollections( session, persister, types, values);

	if ( isUpdateNecessary( event, mightBeDirty ) ) {
		substitute = scheduleUpdate( event ) || substitute;
	}

	if ( status != Status.DELETED ) {
		// now update the object .. has to be outside the main if block above (because of collections)
		if (substitute) persister.setPropertyValues( entity, values, entityMode );

		// Search for collections by reachability, updating their role.
		// We don't want to touch collections reachable from a deleted object
		if ( persister.hasCollections() ) {
			new FlushVisitor(session, entity).processEntityPropertyValues(values, types);
		}
	}

}
 
Example 9
Source File: DefaultReactiveFlushEntityEventListener.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean isCollectionDirtyCheckNecessary(EntityPersister persister, Status status) {
	return ( status == Status.MANAGED || status == Status.READ_ONLY ) &&
			persister.isVersioned() &&
			persister.hasCollections();
}
 
Example 10
Source File: DefaultFlushEntityEventListener.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private boolean isCollectionDirtyCheckNecessary(EntityPersister persister, Status status) {
	return ( status == Status.MANAGED || status == Status.READ_ONLY ) &&
			persister.isVersioned() &&
			persister.hasCollections();
}
 
Example 11
Source File: AbstractSaveEventListener.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Performs all the actual work needed to save an entity (well to get the save moved to
 * the execution queue).
 *
 * @param entity The entity to be saved
 * @param key The id to be used for saving the entity (or null, in the case of identity columns)
 * @param persister The entity's persister instance.
 * @param useIdentityColumn Should an identity column be used for id generation?
 * @param anything Generally cascade-specific information.
 * @param source The session which is the source of the current event.
 * @param requiresImmediateIdAccess Is access to the identifier required immediately
 * after the completion of the save?  persist(), for example, does not require this...
 *
 * @return The id used to save the entity; may be null depending on the
 *         type of id generator used and the requiresImmediateIdAccess value
 */
protected Serializable performSaveOrReplicate(
		Object entity,
		EntityKey key,
		EntityPersister persister,
		boolean useIdentityColumn,
		Object anything,
		EventSource source,
		boolean requiresImmediateIdAccess) {

	Serializable id = key == null ? null : key.getIdentifier();

	boolean shouldDelayIdentityInserts = shouldDelayIdentityInserts( requiresImmediateIdAccess, source );

	// Put a placeholder in entries, so we don't recurse back and try to save() the
	// same object again. QUESTION: should this be done before onSave() is called?
	// likewise, should it be done before onUpdate()?
	EntityEntry original = source.getPersistenceContext().addEntry(
			entity,
			Status.SAVING,
			null,
			null,
			id,
			null,
			LockMode.WRITE,
			useIdentityColumn,
			persister,
			false
	);

	cascadeBeforeSave( source, persister, entity, anything );

	Object[] values = persister.getPropertyValuesToInsert( entity, getMergeMap( anything ), source );
	Type[] types = persister.getPropertyTypes();

	boolean substitute = substituteValuesIfNecessary( entity, id, values, persister, source );

	if ( persister.hasCollections() ) {
		substitute = substitute || visitCollectionsBeforeSave( entity, id, values, types, source );
	}

	if ( substitute ) {
		persister.setPropertyValues( entity, values );
	}

	TypeHelper.deepCopy(
			values,
			types,
			persister.getPropertyUpdateability(),
			values,
			source
	);

	AbstractEntityInsertAction insert = addInsertAction(
			values, id, entity, persister, useIdentityColumn, source, shouldDelayIdentityInserts
	);

	// postpone initializing id in case the insert has non-nullable transient dependencies
	// that are not resolved until cascadeAfterSave() is executed
	cascadeAfterSave( source, persister, entity, anything );
	if ( useIdentityColumn && insert.isEarlyInsert() ) {
		if ( !EntityIdentityInsertAction.class.isInstance( insert ) ) {
			throw new IllegalStateException(
					"Insert should be using an identity column, but action is of unexpected type: " +
							insert.getClass().getName()
			);
		}
		id = ((EntityIdentityInsertAction) insert).getGeneratedId();

		insert.handleNaturalIdPostSaveNotifications( id );
	}

	EntityEntry newEntry = source.getPersistenceContext().getEntry( entity );

	if ( newEntry != original ) {
		EntityEntryExtraState extraState = newEntry.getExtraState( EntityEntryExtraState.class );
		if ( extraState == null ) {
			newEntry.addExtraState( original.getExtraState( EntityEntryExtraState.class ) );
		}
	}

	return id;
}
 
Example 12
Source File: DefaultFlushEntityEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean isCollectionDirtyCheckNecessary(EntityPersister persister, Status status) {
	return status==Status.MANAGED && 
			persister.isVersioned() && 
			persister.hasCollections();
}