use of org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister in project hibernate-reactive by hibernate.
the class ReactiveStatelessSessionImpl method reactiveRefresh.
@Override
public CompletionStage<Void> reactiveRefresh(Object entity, LockMode lockMode) {
final ReactiveEntityPersister persister = getEntityPersister(null, entity);
final Serializable id = persister.getIdentifier(entity, this);
if (persister.canWriteToCache()) {
final EntityDataAccess cacheAccess = persister.getCacheAccessStrategy();
if (cacheAccess != null) {
final Object ck = cacheAccess.generateCacheKey(id, persister, getFactory(), getTenantIdentifier());
cacheAccess.evict(ck);
}
}
String previousFetchProfile = getLoadQueryInfluencers().getInternalFetchProfile();
getLoadQueryInfluencers().setInternalFetchProfile("refresh");
return persister.reactiveLoad(id, entity, getNullSafeLockOptions(lockMode), this).thenAccept(result -> {
if (getPersistenceContext().isLoadFinished()) {
getPersistenceContext().clear();
}
UnresolvableObjectException.throwIfNull(result, id, persister.getEntityName());
}).whenComplete((v, e) -> getLoadQueryInfluencers().setInternalFetchProfile(previousFetchProfile));
}
use of org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister in project hibernate-reactive by hibernate.
the class ReactiveStatelessSessionImpl method reactiveDelete.
@Override
public CompletionStage<Void> reactiveDelete(Object entity) {
checkOpen();
ReactiveEntityPersister persister = getEntityPersister(null, entity);
Serializable id = persister.getIdentifier(entity, this);
Object version = persister.getVersion(entity);
return persister.deleteReactive(id, version, entity, this);
}
use of org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister in project hibernate-reactive by hibernate.
the class ReactiveStatelessSessionImpl method executeReactiveUpdate.
/**
* @param entity a detached entity or initialized proxy
*
* @return a void stage
*/
private CompletionStage<Void> executeReactiveUpdate(Object entity) {
ReactiveEntityPersister persister = getEntityPersister(null, entity);
Serializable id = persister.getIdentifier(entity, this);
Object[] state = persister.getPropertyValues(entity);
Object oldVersion;
if (persister.isVersioned()) {
oldVersion = persister.getVersion(entity);
Object newVersion = Versioning.increment(oldVersion, persister.getVersionType(), this);
Versioning.setVersion(state, newVersion, persister);
persister.setPropertyValues(entity, state);
} else {
oldVersion = null;
}
return persister.updateReactive(id, state, null, false, null, oldVersion, entity, null, this);
}
use of org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister in project hibernate-reactive by hibernate.
the class ReactiveStatelessSessionImpl method reactiveFetch.
@Override
@SuppressWarnings("unchecked")
public <T> CompletionStage<T> reactiveFetch(T association, boolean unproxy) {
checkOpen();
PersistenceContext persistenceContext = getPersistenceContext();
if (association instanceof HibernateProxy) {
LazyInitializer initializer = ((HibernateProxy) association).getHibernateLazyInitializer();
if (!initializer.isUninitialized()) {
return completedFuture(unproxy ? (T) initializer.getImplementation() : association);
} else {
String entityName = initializer.getEntityName();
Serializable id = initializer.getIdentifier();
ReactiveEntityPersister persister = (ReactiveEntityPersister) getFactory().getMetamodel().entityPersister(entityName);
initializer.setSession(this);
persistenceContext.beforeLoad();
return persister.reactiveLoad(id, initializer.getImplementation(), LockOptions.NONE, this).whenComplete((v, e) -> {
persistenceContext.afterLoad();
if (persistenceContext.isLoadFinished()) {
persistenceContext.clear();
}
}).thenApply(entity -> {
checkEntityFound(this, entityName, id, entity);
initializer.setImplementation(entity);
initializer.unsetSession();
return unproxy ? (T) entity : association;
});
}
} else if (association instanceof PersistentCollection) {
PersistentCollection persistentCollection = (PersistentCollection) association;
if (persistentCollection.wasInitialized()) {
return completedFuture(association);
} else {
ReactiveCollectionPersister persister = (ReactiveCollectionPersister) getFactory().getMetamodel().collectionPersister(persistentCollection.getRole());
Serializable key = persistentCollection.getKey();
persistenceContext.addUninitializedCollection(persister, persistentCollection, key);
persistentCollection.setCurrentSession(this);
return persister.reactiveInitialize(key, this).whenComplete((v, e) -> {
if (persistenceContext.isLoadFinished()) {
persistenceContext.clear();
}
}).thenApply(v -> association);
}
} else {
return completedFuture(association);
}
}
use of org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister in project hibernate-reactive by hibernate.
the class ReactiveStatelessSessionImpl method reactiveInsert.
@Override
public CompletionStage<Void> reactiveInsert(Object entity) {
checkOpen();
ReactiveEntityPersister persister = getEntityPersister(null, entity);
return generateId(entity, persister, this, this).thenCompose(id -> {
Object[] state = persister.getPropertyValues(entity);
if (persister.isVersioned()) {
boolean substitute = Versioning.seedVersion(state, persister.getVersionProperty(), persister.getVersionType(), this);
if (substitute) {
persister.setPropertyValues(entity, state);
}
}
if (persister.isIdentifierAssignedByInsert()) {
return persister.insertReactive(state, entity, this).thenAccept(generatedId -> assignIdIfNecessary(entity, generatedId, persister, this));
} else {
id = assignIdIfNecessary(id, entity, persister, this);
persister.setIdentifier(entity, id, this);
return persister.insertReactive(id, state, entity, this);
}
});
}
Aggregations