Java Code Examples for org.hibernate.engine.spi.EntityEntry#getLockMode()

The following examples show how to use org.hibernate.engine.spi.EntityEntry#getLockMode() . 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: SessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LockMode getCurrentLockMode(Object object) throws HibernateException {
	checkOpen();
	checkTransactionSynchStatus();
	if ( object == null ) {
		throw new NullPointerException( "null object passed to getCurrentLockMode()" );
	}
	if ( object instanceof HibernateProxy ) {
		object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation( this );
		if ( object == null ) {
			return LockMode.NONE;
		}
	}
	EntityEntry e = persistenceContext.getEntry( object );
	if ( e == null ) {
		throw new TransientObjectException( "Given object not associated with the session" );
	}
	if ( e.getStatus() != Status.MANAGED ) {
		throw new ObjectDeletedException(
				"The given object was deleted",
				e.getId(),
				e.getPersister().getEntityName()
		);
	}
	return e.getLockMode();
}
 
Example 2
Source File: DefaultPostLoadEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPostLoad(PostLoadEvent event) {
	final Object entity = event.getEntity();

	callbackRegistry.postLoad( entity );

	final EntityEntry entry = event.getSession().getPersistenceContext().getEntry( entity );
	if ( entry == null ) {
		throw new AssertionFailure( "possible non-threadsafe access to the session" );
	}

	final LockMode lockMode = entry.getLockMode();
	if ( LockMode.PESSIMISTIC_FORCE_INCREMENT.equals( lockMode ) ) {
		final EntityPersister persister = entry.getPersister();
		final Object nextVersion = persister.forceVersionIncrement(
				entry.getId(),
				entry.getVersion(),
				event.getSession()
		);
		entry.forceLocked( entity, nextVersion );
	}
	else if ( LockMode.OPTIMISTIC_FORCE_INCREMENT.equals( lockMode ) ) {
		final EntityIncrementVersionProcess incrementVersion = new EntityIncrementVersionProcess( entity, entry );
		event.getSession().getActionQueue().registerProcess( incrementVersion );
	}
	else if ( LockMode.OPTIMISTIC.equals( lockMode ) ) {
		final EntityVerifyVersionProcess verifyVersion = new EntityVerifyVersionProcess( entity, entry );
		event.getSession().getActionQueue().registerProcess( verifyVersion );
	}

	if ( event.getPersister().implementsLifecycle() ) {
		//log.debug( "calling onLoad()" );
		( (Lifecycle) event.getEntity() ).onLoad( event.getSession(), event.getId() );
	}

}