Search in sources :

Example 6 with MergeEvent

use of org.hibernate.event.spi.MergeEvent in project hibernate-reactive by hibernate.

the class DefaultReactiveMergeEventListener method reactiveOnMerge.

/**
 * Handle the given merge event.
 *
 * @param event The merge event to be handled.
 */
@Override
public CompletionStage<Void> reactiveOnMerge(MergeEvent event) throws HibernateException {
    final EntityCopyObserver entityCopyObserver = createEntityCopyObserver(event.getSession().getFactory());
    final MergeContext mergeContext = new MergeContext(event.getSession(), entityCopyObserver);
    return reactiveOnMerge(event, mergeContext).thenAccept(v -> entityCopyObserver.topLevelMergeComplete(event.getSession())).whenComplete((v, e) -> {
        entityCopyObserver.clear();
        mergeContext.clear();
    });
}
Also used : CascadingAction(org.hibernate.reactive.engine.impl.CascadingAction) AssertionFailure(org.hibernate.AssertionFailure) EntityPersister(org.hibernate.persister.entity.EntityPersister) EventSource(org.hibernate.event.spi.EventSource) Log(org.hibernate.reactive.logging.impl.Log) PersistenceContext(org.hibernate.engine.spi.PersistenceContext) ForeignKeyDirection(org.hibernate.type.ForeignKeyDirection) MergeEvent(org.hibernate.event.spi.MergeEvent) LoggerFactory(org.hibernate.reactive.logging.impl.LoggerFactory) MergeContext(org.hibernate.event.internal.MergeContext) ObjectDeletedException(org.hibernate.ObjectDeletedException) TO_PARENT(org.hibernate.type.ForeignKeyDirection.TO_PARENT) HibernateProxy(org.hibernate.proxy.HibernateProxy) FROM_PARENT(org.hibernate.type.ForeignKeyDirection.FROM_PARENT) PersistentAttributeInterceptor(org.hibernate.engine.spi.PersistentAttributeInterceptor) Map(java.util.Map) EventUtil(org.hibernate.event.internal.EventUtil) Cascade(org.hibernate.reactive.engine.impl.Cascade) CompletionStages.voidFuture(org.hibernate.reactive.util.impl.CompletionStages.voidFuture) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ReactiveSession(org.hibernate.reactive.session.ReactiveSession) LazyInitializer(org.hibernate.proxy.LazyInitializer) PersistentAttributeInterceptable(org.hibernate.engine.spi.PersistentAttributeInterceptable) EntityTypes(org.hibernate.reactive.engine.impl.EntityTypes) MethodHandles(java.lang.invoke.MethodHandles) StaleObjectStateException(org.hibernate.StaleObjectStateException) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) TypeHelper(org.hibernate.type.TypeHelper) EntityKey(org.hibernate.engine.spi.EntityKey) EntityCopyObserver(org.hibernate.event.spi.EntityCopyObserver) ServiceRegistry(org.hibernate.service.ServiceRegistry) Serializable(java.io.Serializable) CompletionStage(java.util.concurrent.CompletionStage) EntityCopyObserverFactory(org.hibernate.event.spi.EntityCopyObserverFactory) ReactiveMergeEventListener(org.hibernate.reactive.event.ReactiveMergeEventListener) MergeEventListener(org.hibernate.event.spi.MergeEventListener) EntityEntry(org.hibernate.engine.spi.EntityEntry) CompletionStages.loop(org.hibernate.reactive.util.impl.CompletionStages.loop) WrongClassException(org.hibernate.WrongClassException) CascadePoint(org.hibernate.engine.internal.CascadePoint) EntityState(org.hibernate.event.internal.EntityState) EnhancementAsProxyLazinessInterceptor(org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) HibernateException(org.hibernate.HibernateException) Hibernate(org.hibernate.Hibernate) SelfDirtinessTracker(org.hibernate.engine.spi.SelfDirtinessTracker) DETACHED(org.hibernate.event.internal.EntityState.DETACHED) EntityCopyObserver(org.hibernate.event.spi.EntityCopyObserver) MergeContext(org.hibernate.event.internal.MergeContext)

Example 7 with MergeEvent

use of org.hibernate.event.spi.MergeEvent in project hibernate-reactive by hibernate.

the class DefaultReactiveMergeEventListener method entityIsPersistent.

protected CompletionStage<Void> entityIsPersistent(MergeEvent event, MergeContext copyCache) {
    LOG.trace("Ignoring persistent instance");
    // TODO: check that entry.getIdentifier().equals(requestedId)
    final Object entity = event.getEntity();
    final EventSource source = event.getSession();
    final EntityPersister persister = source.getEntityPersister(event.getEntityName(), entity);
    // before cascade!
    copyCache.put(entity, entity, true);
    return cascadeOnMerge(source, persister, entity, copyCache).thenCompose(v -> fetchAndCopyValues(persister, entity, entity, source, copyCache)).thenAccept(v -> event.setResult(entity));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) CascadingAction(org.hibernate.reactive.engine.impl.CascadingAction) AssertionFailure(org.hibernate.AssertionFailure) EntityPersister(org.hibernate.persister.entity.EntityPersister) EventSource(org.hibernate.event.spi.EventSource) Log(org.hibernate.reactive.logging.impl.Log) PersistenceContext(org.hibernate.engine.spi.PersistenceContext) ForeignKeyDirection(org.hibernate.type.ForeignKeyDirection) MergeEvent(org.hibernate.event.spi.MergeEvent) LoggerFactory(org.hibernate.reactive.logging.impl.LoggerFactory) MergeContext(org.hibernate.event.internal.MergeContext) ObjectDeletedException(org.hibernate.ObjectDeletedException) TO_PARENT(org.hibernate.type.ForeignKeyDirection.TO_PARENT) HibernateProxy(org.hibernate.proxy.HibernateProxy) FROM_PARENT(org.hibernate.type.ForeignKeyDirection.FROM_PARENT) PersistentAttributeInterceptor(org.hibernate.engine.spi.PersistentAttributeInterceptor) Map(java.util.Map) EventUtil(org.hibernate.event.internal.EventUtil) Cascade(org.hibernate.reactive.engine.impl.Cascade) CompletionStages.voidFuture(org.hibernate.reactive.util.impl.CompletionStages.voidFuture) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ReactiveSession(org.hibernate.reactive.session.ReactiveSession) LazyInitializer(org.hibernate.proxy.LazyInitializer) PersistentAttributeInterceptable(org.hibernate.engine.spi.PersistentAttributeInterceptable) EntityTypes(org.hibernate.reactive.engine.impl.EntityTypes) MethodHandles(java.lang.invoke.MethodHandles) StaleObjectStateException(org.hibernate.StaleObjectStateException) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) TypeHelper(org.hibernate.type.TypeHelper) EntityKey(org.hibernate.engine.spi.EntityKey) EntityCopyObserver(org.hibernate.event.spi.EntityCopyObserver) ServiceRegistry(org.hibernate.service.ServiceRegistry) Serializable(java.io.Serializable) CompletionStage(java.util.concurrent.CompletionStage) EntityCopyObserverFactory(org.hibernate.event.spi.EntityCopyObserverFactory) ReactiveMergeEventListener(org.hibernate.reactive.event.ReactiveMergeEventListener) MergeEventListener(org.hibernate.event.spi.MergeEventListener) EntityEntry(org.hibernate.engine.spi.EntityEntry) CompletionStages.loop(org.hibernate.reactive.util.impl.CompletionStages.loop) WrongClassException(org.hibernate.WrongClassException) CascadePoint(org.hibernate.engine.internal.CascadePoint) EntityState(org.hibernate.event.internal.EntityState) EnhancementAsProxyLazinessInterceptor(org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) HibernateException(org.hibernate.HibernateException) Hibernate(org.hibernate.Hibernate) SelfDirtinessTracker(org.hibernate.engine.spi.SelfDirtinessTracker) DETACHED(org.hibernate.event.internal.EntityState.DETACHED) EventSource(org.hibernate.event.spi.EventSource)

Example 8 with MergeEvent

use of org.hibernate.event.spi.MergeEvent in project BridgeServer2 by Sage-Bionetworks.

the class TagEventListenerTest method onMerge.

@Test
public void onMerge() throws HibernateException {
    MergeEvent event = new MergeEvent(new Tag("value"), null);
    event.setEntity(new Tag("value"));
    listener.onMerge(event);
    verify(cacheProvider).removeObject(CacheKey.tagList());
}
Also used : MergeEvent(org.hibernate.event.spi.MergeEvent) Tag(org.sagebionetworks.bridge.models.Tag) Test(org.testng.annotations.Test)

Example 9 with MergeEvent

use of org.hibernate.event.spi.MergeEvent in project BridgeServer2 by Sage-Bionetworks.

the class TagEventListenerTest method onMergeWithCopiedAlreadyNotTag.

@Test
public void onMergeWithCopiedAlreadyNotTag() throws HibernateException {
    MergeEvent event = new MergeEvent(new HibernateAssessment(), null);
    event.setEntity(new HibernateAssessment());
    listener.onMerge(event, null);
    verify(cacheProvider, never()).removeObject(CacheKey.tagList());
}
Also used : MergeEvent(org.hibernate.event.spi.MergeEvent) HibernateAssessment(org.sagebionetworks.bridge.models.assessments.HibernateAssessment) Test(org.testng.annotations.Test)

Example 10 with MergeEvent

use of org.hibernate.event.spi.MergeEvent in project BridgeServer2 by Sage-Bionetworks.

the class TagEventListenerTest method onMergeNotTag.

@Test
public void onMergeNotTag() throws HibernateException {
    MergeEvent event = new MergeEvent(new HibernateAssessment(), null);
    event.setEntity(new HibernateAssessment());
    listener.onMerge(event);
    verify(cacheProvider, never()).removeObject(CacheKey.tagList());
}
Also used : MergeEvent(org.hibernate.event.spi.MergeEvent) HibernateAssessment(org.sagebionetworks.bridge.models.assessments.HibernateAssessment) Test(org.testng.annotations.Test)

Aggregations

MergeEvent (org.hibernate.event.spi.MergeEvent)10 Serializable (java.io.Serializable)4 MethodHandles (java.lang.invoke.MethodHandles)4 Map (java.util.Map)4 CompletionStage (java.util.concurrent.CompletionStage)4 AssertionFailure (org.hibernate.AssertionFailure)4 Hibernate (org.hibernate.Hibernate)4 HibernateException (org.hibernate.HibernateException)4 ObjectDeletedException (org.hibernate.ObjectDeletedException)4 StaleObjectStateException (org.hibernate.StaleObjectStateException)4 WrongClassException (org.hibernate.WrongClassException)4 EnhancementAsProxyLazinessInterceptor (org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor)4 CascadePoint (org.hibernate.engine.internal.CascadePoint)4 EntityEntry (org.hibernate.engine.spi.EntityEntry)4 EntityKey (org.hibernate.engine.spi.EntityKey)4 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)4 PersistentAttributeInterceptable (org.hibernate.engine.spi.PersistentAttributeInterceptable)4 PersistentAttributeInterceptor (org.hibernate.engine.spi.PersistentAttributeInterceptor)4 SelfDirtinessTracker (org.hibernate.engine.spi.SelfDirtinessTracker)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4