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();
}
}
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);
}
}
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();
});
}
Aggregations