Search in sources :

Example 6 with ReactiveSession

use of org.hibernate.reactive.session.ReactiveSession in project hibernate-reactive by hibernate.

the class Cascade method deleteOrphans.

/**
 * Delete any entities that were removed from the collection
 */
private void deleteOrphans(String entityName, PersistentCollection pc) throws HibernateException {
    // TODO: suck this logic into the collection!
    final Collection<?> orphans;
    if (pc.wasInitialized()) {
        final CollectionEntry ce = eventSource.getPersistenceContextInternal().getCollectionEntry(pc);
        if (ce == null) {
            return;
        }
        orphans = ce.getOrphans(entityName, pc);
    } else {
        orphans = pc.getQueuedOrphans(entityName);
    }
    ReactiveSession session = (ReactiveSession) eventSource;
    stage = stage.thenCompose(v -> loop(orphans, Objects::nonNull, orphan -> {
        LOG.tracev("Deleting orphaned entity instance: {0}", entityName);
        return session.reactiveRemove(orphan, false, new IdentitySet());
    }));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EventSource(org.hibernate.event.spi.EventSource) CollectionType(org.hibernate.type.CollectionType) CollectionEntry(org.hibernate.engine.spi.CollectionEntry) Log(org.hibernate.reactive.logging.impl.Log) EntityType(org.hibernate.type.EntityType) PersistenceContext(org.hibernate.engine.spi.PersistenceContext) ForeignKeyDirection(org.hibernate.type.ForeignKeyDirection) LoggerFactory(org.hibernate.reactive.logging.impl.LoggerFactory) PersistentCollection(org.hibernate.collection.spi.PersistentCollection) HibernateProxy(org.hibernate.proxy.HibernateProxy) CompositeType(org.hibernate.type.CompositeType) IdentitySet(org.hibernate.internal.util.collections.IdentitySet) LazyAttributeLoadingInterceptor(org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor) Status(org.hibernate.engine.spi.Status) CompletionStages.voidFuture(org.hibernate.reactive.util.impl.CompletionStages.voidFuture) ReactiveSession(org.hibernate.reactive.session.ReactiveSession) Iterator(java.util.Iterator) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) CacheMode(org.hibernate.CacheMode) Objects(java.util.Objects) MessageHelper.infoString(org.hibernate.pretty.MessageHelper.infoString) CompletionStage(java.util.concurrent.CompletionStage) CascadeStyle(org.hibernate.engine.spi.CascadeStyle) EntityEntry(org.hibernate.engine.spi.EntityEntry) CompletionStages.loop(org.hibernate.reactive.util.impl.CompletionStages.loop) CascadePoint(org.hibernate.engine.internal.CascadePoint) HibernateException(org.hibernate.HibernateException) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) AssociationType(org.hibernate.type.AssociationType) Hibernate(org.hibernate.Hibernate) Type(org.hibernate.type.Type) ReactiveSession(org.hibernate.reactive.session.ReactiveSession) CollectionEntry(org.hibernate.engine.spi.CollectionEntry) IdentitySet(org.hibernate.internal.util.collections.IdentitySet) Objects(java.util.Objects)

Aggregations

ReactiveSession (org.hibernate.reactive.session.ReactiveSession)6 CompletionStage (java.util.concurrent.CompletionStage)4 EntityEntry (org.hibernate.engine.spi.EntityEntry)4 EntityPersister (org.hibernate.persister.entity.EntityPersister)4 MethodHandles (java.lang.invoke.MethodHandles)3 Hibernate (org.hibernate.Hibernate)3 HibernateException (org.hibernate.HibernateException)3 CascadePoint (org.hibernate.engine.internal.CascadePoint)3 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)3 EventSource (org.hibernate.event.spi.EventSource)3 HibernateProxy (org.hibernate.proxy.HibernateProxy)3 Log (org.hibernate.reactive.logging.impl.Log)3 LoggerFactory (org.hibernate.reactive.logging.impl.LoggerFactory)3 CompletionStages.loop (org.hibernate.reactive.util.impl.CompletionStages.loop)3 CompletionStages.voidFuture (org.hibernate.reactive.util.impl.CompletionStages.voidFuture)3 ForeignKeyDirection (org.hibernate.type.ForeignKeyDirection)3 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Objects (java.util.Objects)2 AssertionFailure (org.hibernate.AssertionFailure)2