use of org.hibernate.reactive.engine.impl.ReactiveEntityVerifyVersionProcess in project hibernate-reactive by hibernate.
the class DefaultReactiveLockEventListener method upgradeLock.
/**
* Performs a pessimistic lock upgrade on a given entity, if needed.
*
* @param object The entity for which to upgrade the lock.
* @param entry The entity's EntityEntry instance.
* @param lockOptions contains the requested lock mode.
* @param source The session which is the source of the event being processed.
*/
protected CompletionStage<Void> upgradeLock(Object object, EntityEntry entry, LockOptions lockOptions, EventSource source) {
LockMode requestedLockMode = lockOptions.getLockMode();
if (requestedLockMode.greaterThan(entry.getLockMode())) {
if (entry.getStatus() != Status.MANAGED) {
throw new ObjectDeletedException("attempted to lock a deleted instance", entry.getId(), entry.getPersister().getEntityName());
}
if (LOG.isTraceEnabled()) {
LOG.tracev("Locking {0} in mode: {1}", infoString(entry.getPersister(), entry.getId(), source.getFactory()), requestedLockMode);
}
switch(requestedLockMode) {
case OPTIMISTIC:
((ReactiveSession) source).getReactiveActionQueue().registerProcess(new ReactiveEntityVerifyVersionProcess(object));
entry.setLockMode(requestedLockMode);
return voidFuture();
case OPTIMISTIC_FORCE_INCREMENT:
((ReactiveSession) source).getReactiveActionQueue().registerProcess(new ReactiveEntityIncrementVersionProcess(object));
entry.setLockMode(requestedLockMode);
return voidFuture();
default:
return doUpgradeLock(object, entry, lockOptions, source);
}
} else {
return voidFuture();
}
}
use of org.hibernate.reactive.engine.impl.ReactiveEntityVerifyVersionProcess in project hibernate-reactive by hibernate.
the class DefaultReactivePostLoadEventListener method onPostLoad.
@Override
public void onPostLoad(PostLoadEvent event) {
final Object entity = event.getEntity();
callbackRegistry.postLoad(entity);
final SessionImplementor session = event.getSession();
final EntityEntry entry = session.getPersistenceContextInternal().getEntry(entity);
if (entry == null) {
throw new AssertionFailure("possible non-threadsafe access to the session");
}
LockMode lockMode = entry.getLockMode();
if (LockMode.OPTIMISTIC_FORCE_INCREMENT.equals(lockMode)) {
((ReactiveSession) session).getReactiveActionQueue().registerProcess(new ReactiveEntityIncrementVersionProcess(entity));
} else if (LockMode.OPTIMISTIC.equals(lockMode)) {
((ReactiveSession) session).getReactiveActionQueue().registerProcess(new ReactiveEntityVerifyVersionProcess(entity));
}
}
Aggregations