Search in sources :

Example 1 with LockEvent

use of org.hibernate.event.spi.LockEvent in project hibernate-reactive by hibernate.

the class DefaultReactiveLockEventListener method reactiveOnLock.

private CompletionStage<Void> reactiveOnLock(LockEvent event, Object entity) {
    SessionImplementor source = event.getSession();
    PersistenceContext persistenceContext = source.getPersistenceContextInternal();
    EntityEntry entry = persistenceContext.getEntry(entity);
    CompletionStage<EntityEntry> stage;
    if (entry == null) {
        final EntityPersister persister = source.getEntityPersister(event.getEntityName(), entity);
        final Serializable id = persister.getIdentifier(entity, source);
        stage = ForeignKeys.isNotTransient(event.getEntityName(), entity, Boolean.FALSE, source).thenApply(trans -> {
            if (!trans) {
                throw new TransientObjectException("cannot lock an unsaved transient instance: " + persister.getEntityName());
            }
            EntityEntry e = reassociate(event, entity, id, persister);
            cascadeOnLock(event, persister, entity);
            return e;
        });
    } else {
        stage = completedFuture(entry);
    }
    return stage.thenCompose(e -> upgradeLock(entity, e, event.getLockOptions(), event.getSession()));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) ReactiveEntityPersister(org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister) CompletionStages.completedFuture(org.hibernate.reactive.util.impl.CompletionStages.completedFuture) EntityPersister(org.hibernate.persister.entity.EntityPersister) EventSource(org.hibernate.event.spi.EventSource) EntityDataAccess(org.hibernate.cache.spi.access.EntityDataAccess) Log(org.hibernate.reactive.logging.impl.Log) PersistenceContext(org.hibernate.engine.spi.PersistenceContext) LoggerFactory(org.hibernate.reactive.logging.impl.LoggerFactory) ObjectDeletedException(org.hibernate.ObjectDeletedException) LockEvent(org.hibernate.event.spi.LockEvent) Cascade(org.hibernate.reactive.engine.impl.Cascade) Status(org.hibernate.engine.spi.Status) CompletionStages.voidFuture(org.hibernate.reactive.util.impl.CompletionStages.voidFuture) ReactiveSession(org.hibernate.reactive.session.ReactiveSession) LockMode(org.hibernate.LockMode) LockOptions(org.hibernate.LockOptions) LockEventListener(org.hibernate.event.spi.LockEventListener) ReactiveEntityIncrementVersionProcess(org.hibernate.reactive.engine.impl.ReactiveEntityIncrementVersionProcess) MethodHandles(java.lang.invoke.MethodHandles) ForeignKeys(org.hibernate.reactive.engine.impl.ForeignKeys) ReactiveEntityVerifyVersionProcess(org.hibernate.reactive.engine.impl.ReactiveEntityVerifyVersionProcess) Serializable(java.io.Serializable) TransientObjectException(org.hibernate.TransientObjectException) MessageHelper.infoString(org.hibernate.pretty.MessageHelper.infoString) SoftLock(org.hibernate.cache.spi.access.SoftLock) CascadingActions(org.hibernate.reactive.engine.impl.CascadingActions) CompletionStage(java.util.concurrent.CompletionStage) ReactiveLockEventListener(org.hibernate.reactive.event.ReactiveLockEventListener) AbstractReassociateEventListener(org.hibernate.event.internal.AbstractReassociateEventListener) EntityEntry(org.hibernate.engine.spi.EntityEntry) CascadePoint(org.hibernate.engine.internal.CascadePoint) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) ReactiveEntityPersister(org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister) HibernateException(org.hibernate.HibernateException) TransientObjectException(org.hibernate.TransientObjectException) EntityEntry(org.hibernate.engine.spi.EntityEntry) Serializable(java.io.Serializable) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) PersistenceContext(org.hibernate.engine.spi.PersistenceContext)

Aggregations

Serializable (java.io.Serializable)1 MethodHandles (java.lang.invoke.MethodHandles)1 CompletionStage (java.util.concurrent.CompletionStage)1 HibernateException (org.hibernate.HibernateException)1 LockMode (org.hibernate.LockMode)1 LockOptions (org.hibernate.LockOptions)1 ObjectDeletedException (org.hibernate.ObjectDeletedException)1 TransientObjectException (org.hibernate.TransientObjectException)1 EntityDataAccess (org.hibernate.cache.spi.access.EntityDataAccess)1 SoftLock (org.hibernate.cache.spi.access.SoftLock)1 CascadePoint (org.hibernate.engine.internal.CascadePoint)1 EntityEntry (org.hibernate.engine.spi.EntityEntry)1 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)1 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)1 Status (org.hibernate.engine.spi.Status)1 AbstractReassociateEventListener (org.hibernate.event.internal.AbstractReassociateEventListener)1 EventSource (org.hibernate.event.spi.EventSource)1 LockEvent (org.hibernate.event.spi.LockEvent)1 LockEventListener (org.hibernate.event.spi.LockEventListener)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1