Search in sources :

Example 1 with EntityIncrementVersionProcess

use of org.hibernate.action.internal.EntityIncrementVersionProcess in project hibernate-orm by hibernate.

the class OptimisticForceIncrementLockingStrategy method lock.

@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
    if (!lockable.isVersioned()) {
        throw new HibernateException("[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]");
    }
    final EntityEntry entry = session.getPersistenceContext().getEntry(object);
    // Register the EntityIncrementVersionProcess action to run just prior to transaction commit.
    ((EventSource) session).getActionQueue().registerProcess(new EntityIncrementVersionProcess(object, entry));
}
Also used : EntityEntry(org.hibernate.engine.spi.EntityEntry) HibernateException(org.hibernate.HibernateException) EntityIncrementVersionProcess(org.hibernate.action.internal.EntityIncrementVersionProcess)

Example 2 with EntityIncrementVersionProcess

use of org.hibernate.action.internal.EntityIncrementVersionProcess in project hibernate-orm by hibernate.

the class DefaultPostLoadEventListener method onPostLoad.

@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());
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityEntry(org.hibernate.engine.spi.EntityEntry) AssertionFailure(org.hibernate.AssertionFailure) EntityVerifyVersionProcess(org.hibernate.action.internal.EntityVerifyVersionProcess) Lifecycle(org.hibernate.classic.Lifecycle) LockMode(org.hibernate.LockMode) EntityIncrementVersionProcess(org.hibernate.action.internal.EntityIncrementVersionProcess)

Aggregations

EntityIncrementVersionProcess (org.hibernate.action.internal.EntityIncrementVersionProcess)2 EntityEntry (org.hibernate.engine.spi.EntityEntry)2 AssertionFailure (org.hibernate.AssertionFailure)1 HibernateException (org.hibernate.HibernateException)1 LockMode (org.hibernate.LockMode)1 EntityVerifyVersionProcess (org.hibernate.action.internal.EntityVerifyVersionProcess)1 Lifecycle (org.hibernate.classic.Lifecycle)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1