use of org.hibernate.reactive.logging.impl.Log in project hibernate-reactive by hibernate.
the class ReactiveCollectionUpdateAction method reactiveExecute.
@Override
public CompletionStage<Void> reactiveExecute() {
final Serializable key = getKey();
final SharedSessionContractImplementor session = getSession();
final ReactiveCollectionPersister reactivePersister = (ReactiveCollectionPersister) getPersister();
final CollectionPersister corePersister = getPersister();
final PersistentCollection collection = getCollection();
final boolean affectedByFilters = corePersister.isAffectedByEnabledFilters(session);
preUpdate();
CompletionStage<Void> updateStage = CompletionStages.voidFuture();
// And then make sure that each operations is executed in its own stage maintaining the same order as in ORM
if (!collection.wasInitialized()) {
// The collection should still be dirty.
if (!collection.isDirty()) {
throw new AssertionFailure("collection is not dirty");
}
// do nothing - we only need to notify the cache...
} else if (!affectedByFilters && collection.empty()) {
if (!emptySnapshot) {
updateStage = updateStage.thenCompose(v -> reactivePersister.removeReactive(key, session)).thenAccept(count -> {
/* We don't care, maybe we can log it as debug */
});
}
} else if (collection.needsRecreate(corePersister)) {
if (affectedByFilters) {
throw LOG.cannotRecreateCollectionWhileFilterIsEnabled(collectionInfoString(corePersister, collection, key, session));
}
if (!emptySnapshot) {
updateStage = updateStage.thenCompose(v -> reactivePersister.removeReactive(key, session)).thenAccept(count -> {
/* We don't care, maybe we can log it as debug */
});
}
return updateStage.thenCompose(v -> reactivePersister.recreateReactive(collection, key, session).thenAccept(ignore -> {
session.getPersistenceContextInternal().getCollectionEntry(collection).afterAction(collection);
evict();
postUpdate();
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if (statistics.isStatisticsEnabled()) {
statistics.updateCollection(corePersister.getRole());
}
}));
} else {
updateStage = updateStage.thenCompose(v -> reactivePersister.reactiveDeleteRows(collection, key, session)).thenCompose(v -> reactivePersister.reactiveUpdateRows(collection, key, session)).thenCompose(v -> reactivePersister.reactiveInsertRows(collection, key, session));
}
return updateStage.thenAccept(v -> {
session.getPersistenceContextInternal().getCollectionEntry(collection).afterAction(collection);
evict();
postUpdate();
final StatisticsImplementor statistics = session.getFactory().getStatistics();
if (statistics.isStatisticsEnabled()) {
statistics.updateCollection(corePersister.getRole());
}
});
}
Aggregations