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()));
}
Aggregations