use of org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy in project hibernate-orm by hibernate.
the class QuerySqmImpl method buildUpdateQueryPlan.
private NonSelectQueryPlan buildUpdateQueryPlan() {
// noinspection rawtypes
final SqmUpdateStatement sqmUpdate = (SqmUpdateStatement) getSqmStatement();
final String entityNameToUpdate = sqmUpdate.getTarget().getReferencedPathSource().getHibernateEntityName();
final EntityPersister entityDescriptor = getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(entityNameToUpdate);
final SqmMultiTableMutationStrategy multiTableStrategy = entityDescriptor.getSqmMultiTableMutationStrategy();
if (multiTableStrategy == null) {
return new SimpleUpdateQueryPlan(sqmUpdate, domainParameterXref);
} else {
return new MultiTableUpdateQueryPlan(sqmUpdate, domainParameterXref, multiTableStrategy);
}
}
use of org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy in project hibernate-orm by hibernate.
the class QuerySqmImpl method buildConcreteDeleteQueryPlan.
private NonSelectQueryPlan buildConcreteDeleteQueryPlan(@SuppressWarnings("rawtypes") SqmDeleteStatement sqmDelete) {
final EntityDomainType<?> entityDomainType = sqmDelete.getTarget().getReferencedPathSource();
final String entityNameToDelete = entityDomainType.getHibernateEntityName();
final EntityPersister entityDescriptor = getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(entityNameToDelete);
final SqmMultiTableMutationStrategy multiTableStrategy = entityDescriptor.getSqmMultiTableMutationStrategy();
if (multiTableStrategy == null) {
return new SimpleDeleteQueryPlan(entityDescriptor, sqmDelete, domainParameterXref);
} else {
return new MultiTableDeleteQueryPlan(sqmDelete, domainParameterXref, multiTableStrategy);
}
}
use of org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy in project hibernate-orm by hibernate.
the class SessionFactoryOptionsBuilder method resolveSqmMutationStrategy.
@SuppressWarnings("unchecked")
private SqmMultiTableMutationStrategy resolveSqmMutationStrategy(String strategyName, StandardServiceRegistry serviceRegistry, StrategySelector strategySelector) {
if (strategyName == null) {
return null;
}
return strategySelector.resolveStrategy(SqmMultiTableMutationStrategy.class, strategyName, (SqmMultiTableMutationStrategy) null, strategyClass -> {
Constructor<SqmMultiTableMutationStrategy> dialectConstructor = null;
Constructor<SqmMultiTableMutationStrategy> emptyConstructor = null;
// todo (6.0) : formalize the allowed constructor parameterizations
for (Constructor<?> declaredConstructor : strategyClass.getDeclaredConstructors()) {
final Class<?>[] parameterTypes = declaredConstructor.getParameterTypes();
if (parameterTypes.length == 1 && parameterTypes[0] == Dialect.class) {
dialectConstructor = (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
break;
} else if (parameterTypes.length == 0) {
emptyConstructor = (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
}
}
try {
if (dialectConstructor != null) {
return dialectConstructor.newInstance(serviceRegistry.getService(JdbcServices.class).getDialect());
} else if (emptyConstructor != null) {
return emptyConstructor.newInstance();
}
} catch (Exception e) {
throw new StrategySelectionException(String.format("Could not instantiate named strategy class [%s]", strategyClass.getName()), e);
}
throw new IllegalArgumentException("Cannot instantiate the class [" + strategyClass.getName() + "] because it does not have a constructor that accepts a dialect or an empty constructor!");
});
}
use of org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy in project hibernate-orm by hibernate.
the class AbstractEntityPersister method interpretSqmMultiTableStrategy.
protected static SqmMultiTableMutationStrategy interpretSqmMultiTableStrategy(AbstractEntityPersister entityMappingDescriptor, MappingModelCreationProcess creationProcess) {
assert entityMappingDescriptor.hasMultipleTables();
EntityMappingType superMappingType = entityMappingDescriptor.getSuperMappingType();
if (superMappingType != null) {
SqmMultiTableMutationStrategy sqmMultiTableMutationStrategy = superMappingType.getSqmMultiTableMutationStrategy();
if (sqmMultiTableMutationStrategy != null) {
return sqmMultiTableMutationStrategy;
}
}
// we need the boot model so we can have access to the Table
final RootClass entityBootDescriptor = (RootClass) creationProcess.getCreationContext().getBootModel().getEntityBinding(entityMappingDescriptor.getRootEntityName());
return SqmMutationStrategyHelper.resolveStrategy(entityBootDescriptor, entityMappingDescriptor, creationProcess);
}
use of org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy in project hibernate-orm by hibernate.
the class SqmMutationStrategyHelper method resolveStrategy.
/**
* Standard resolution of SqmMutationStrategy to use for a given
* entity hierarchy.
*/
public static SqmMultiTableMutationStrategy resolveStrategy(RootClass entityBootDescriptor, EntityMappingType rootEntityDescriptor, MappingModelCreationProcess creationProcess) {
final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext();
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory();
final SessionFactoryOptions options = sessionFactory.getSessionFactoryOptions();
final SqmMultiTableMutationStrategy specifiedStrategy = options.getCustomSqmMultiTableMutationStrategy();
if (specifiedStrategy != null) {
return specifiedStrategy;
}
return sessionFactory.getServiceRegistry().getService(JdbcServices.class).getJdbcEnvironment().getDialect().getFallbackSqmMutationStrategy(rootEntityDescriptor, creationContext);
}
Aggregations