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

The following examples show how to use org.hibernate.persister.entity.EntityPersister#findModified() . 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: DefaultFlushEntityEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected boolean handleInterception(FlushEntityEvent event) {
	SessionImplementor session = event.getSession();
	EntityEntry entry = event.getEntityEntry();
	EntityPersister persister = entry.getPersister();
	Object entity = event.getEntity();
	
	//give the Interceptor a chance to modify property values
	final Object[] values = event.getPropertyValues();
	final boolean intercepted = invokeInterceptor( session, entity, entry, values, persister );

	//now we might need to recalculate the dirtyProperties array
	if ( intercepted && event.isDirtyCheckPossible() && !event.isDirtyCheckHandledByInterceptor() ) {
		int[] dirtyProperties;
		if ( event.hasDatabaseSnapshot() ) {
			dirtyProperties = persister.findModified( event.getDatabaseSnapshot(), values, entity, session );
		}
		else {
			dirtyProperties = persister.findDirty( values, entry.getLoadedState(), entity, session );
		}
		event.setDirtyProperties(dirtyProperties);
	}
	
	return intercepted;
}
 
Example 2
Source File: OptimisticLockingChildUpdatesRootVersionTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
private boolean updated(FlushEntityEvent event) {
    final EntityEntry entry = event.getEntityEntry();
    final Object entity = event.getEntity();

    int[] dirtyProperties;
    EntityPersister persister = entry.getPersister();
    final Object[] values = event.getPropertyValues();
    SessionImplementor session = event.getSession();

    if ( event.hasDatabaseSnapshot() ) {
        dirtyProperties = persister.findModified( event.getDatabaseSnapshot(), values, entity, session );
    }
    else {
        dirtyProperties = persister.findDirty( values, entry.getLoadedState(), entity, session );
    }

    return dirtyProperties != null;
}
 
Example 3
Source File: OptimisticLockingBidirectionalChildUpdatesRootVersionTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
private boolean updated(FlushEntityEvent event) {
    final EntityEntry entry = event.getEntityEntry();
    final Object entity = event.getEntity();

    int[] dirtyProperties;
    EntityPersister persister = entry.getPersister();
    final Object[] values = event.getPropertyValues();
    SessionImplementor session = event.getSession();

    if ( event.hasDatabaseSnapshot() ) {
        dirtyProperties = persister.findModified( event.getDatabaseSnapshot(), values, entity, session );
    }
    else {
        dirtyProperties = persister.findDirty( values, entry.getLoadedState(), entity, session );
    }

    return dirtyProperties != null;
}
 
Example 4
Source File: DefaultFlushEntityEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Perform a dirty check, and attach the results to the event
 */
protected void dirtyCheck(FlushEntityEvent event) throws HibernateException {
	
	final Object entity = event.getEntity();
	final Object[] values = event.getPropertyValues();
	final SessionImplementor session = event.getSession();
	final EntityEntry entry = event.getEntityEntry();
	final EntityPersister persister = entry.getPersister();
	final Serializable id = entry.getId();
	final Object[] loadedState = entry.getLoadedState();

	int[] dirtyProperties = session.getInterceptor().findDirty( 
			entity, 
			id, 
			values, 
			loadedState, 
			persister.getPropertyNames(), 
			persister.getPropertyTypes() 
		);
	
	event.setDatabaseSnapshot(null);

	final boolean interceptorHandledDirtyCheck;
	boolean cannotDirtyCheck;
	
	if ( dirtyProperties==null ) {
		// Interceptor returned null, so do the dirtycheck ourself, if possible
		interceptorHandledDirtyCheck = false;
		
		cannotDirtyCheck = loadedState==null; // object loaded by update()
		if ( !cannotDirtyCheck ) {
			// dirty check against the usual snapshot of the entity
			dirtyProperties = persister.findDirty( values, loadedState, entity, session );
			
		}
		else {
			// dirty check against the database snapshot, if possible/necessary
			final Object[] databaseSnapshot = getDatabaseSnapshot(session, persister, id);
			if ( databaseSnapshot != null ) {
				dirtyProperties = persister.findModified(databaseSnapshot, values, entity, session);
				cannotDirtyCheck = false;
				event.setDatabaseSnapshot(databaseSnapshot);
			}
		}
	}
	else {
		// the Interceptor handled the dirty checking
		cannotDirtyCheck = false;
		interceptorHandledDirtyCheck = true;
	}
	
	event.setDirtyProperties(dirtyProperties);
	event.setDirtyCheckHandledByInterceptor(interceptorHandledDirtyCheck);
	event.setDirtyCheckPossible(!cannotDirtyCheck);
	
}