Search in sources :

Example 1 with EntityCopyObserver

use of org.hibernate.event.spi.EntityCopyObserver in project hibernate-orm by hibernate.

the class DefaultMergeEventListener method onMerge.

/**
 * Handle the given merge event.
 *
 * @param event The merge event to be handled.
 */
public void onMerge(MergeEvent event) throws HibernateException {
    final EntityCopyObserver entityCopyObserver = createEntityCopyObserver(event.getSession().getFactory());
    final MergeContext mergeContext = new MergeContext(event.getSession(), entityCopyObserver);
    try {
        onMerge(event, mergeContext);
        entityCopyObserver.topLevelMergeComplete(event.getSession());
    } finally {
        entityCopyObserver.clear();
        mergeContext.clear();
    }
}
Also used : EntityCopyObserver(org.hibernate.event.spi.EntityCopyObserver) MergeContext(org.hibernate.event.spi.MergeContext)

Example 2 with EntityCopyObserver

use of org.hibernate.event.spi.EntityCopyObserver in project hibernate-orm by hibernate.

the class EntityCopyObserverFactoryInitiator method initiateService.

@Override
public EntityCopyObserverFactory initiateService(final Map<String, Object> configurationValues, final ServiceRegistryImplementor registry) {
    final Object value = getConfigurationValue(configurationValues);
    if (value.equals(EntityCopyNotAllowedObserver.SHORT_NAME) || value.equals(EntityCopyNotAllowedObserver.class.getName())) {
        LOG.debugf("Configured EntityCopyObserver strategy: %s", EntityCopyNotAllowedObserver.SHORT_NAME);
        return EntityCopyNotAllowedObserver.FACTORY_OF_SELF;
    } else if (value.equals(EntityCopyAllowedObserver.SHORT_NAME) || value.equals(EntityCopyAllowedObserver.class.getName())) {
        LOG.debugf("Configured EntityCopyObserver strategy: %s", EntityCopyAllowedObserver.SHORT_NAME);
        return EntityCopyAllowedObserver.FACTORY_OF_SELF;
    } else if (value.equals(EntityCopyAllowedLoggedObserver.SHORT_NAME) || value.equals(EntityCopyAllowedLoggedObserver.class.getName())) {
        LOG.debugf("Configured EntityCopyObserver strategy: %s", EntityCopyAllowedLoggedObserver.SHORT_NAME);
        return EntityCopyAllowedLoggedObserver.FACTORY_OF_SELF;
    } else {
        // We load an "example instance" just to get its Class;
        // this might look excessive, but it also happens to test eagerly (at boot) that we can actually construct these
        // and that they are indeed of the right type.
        EntityCopyObserver exampleInstance = registry.getService(StrategySelector.class).resolveStrategy(EntityCopyObserver.class, value);
        Class<?> observerType = exampleInstance.getClass();
        LOG.debugf("Configured EntityCopyObserver is a custom implementation of type %s", observerType.getName());
        return new EntityObserversFactoryFromClass(observerType);
    }
}
Also used : EntityCopyObserver(org.hibernate.event.spi.EntityCopyObserver) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector)

Example 3 with EntityCopyObserver

use of org.hibernate.event.spi.EntityCopyObserver 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)

Aggregations

EntityCopyObserver (org.hibernate.event.spi.EntityCopyObserver)3 Serializable (java.io.Serializable)1 MethodHandles (java.lang.invoke.MethodHandles)1 Map (java.util.Map)1 CompletionStage (java.util.concurrent.CompletionStage)1 AssertionFailure (org.hibernate.AssertionFailure)1 Hibernate (org.hibernate.Hibernate)1 HibernateException (org.hibernate.HibernateException)1 ObjectDeletedException (org.hibernate.ObjectDeletedException)1 StaleObjectStateException (org.hibernate.StaleObjectStateException)1 WrongClassException (org.hibernate.WrongClassException)1 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)1 EnhancementAsProxyLazinessInterceptor (org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor)1 CascadePoint (org.hibernate.engine.internal.CascadePoint)1 EntityEntry (org.hibernate.engine.spi.EntityEntry)1 EntityKey (org.hibernate.engine.spi.EntityKey)1 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)1 PersistentAttributeInterceptable (org.hibernate.engine.spi.PersistentAttributeInterceptable)1 PersistentAttributeInterceptor (org.hibernate.engine.spi.PersistentAttributeInterceptor)1 SelfDirtinessTracker (org.hibernate.engine.spi.SelfDirtinessTracker)1