use of org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy in project hibernate-orm by hibernate.
the class SqmMutationStrategyHelper method resolveInsertStrategy.
/**
* Standard resolution of SqmInsertStrategy to use for a given
* entity hierarchy.
*/
public static SqmMultiTableInsertStrategy resolveInsertStrategy(RootClass entityBootDescriptor, EntityMappingType rootEntityDescriptor, MappingModelCreationProcess creationProcess) {
final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext();
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory();
final SessionFactoryOptions options = sessionFactory.getSessionFactoryOptions();
final SqmMultiTableInsertStrategy specifiedStrategy = options.getCustomSqmMultiTableInsertStrategy();
if (specifiedStrategy != null) {
return specifiedStrategy;
}
return sessionFactory.getServiceRegistry().getService(JdbcServices.class).getJdbcEnvironment().getDialect().getFallbackSqmInsertStrategy(rootEntityDescriptor, creationContext);
}
use of org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy in project hibernate-orm by hibernate.
the class SessionFactoryOptionsBuilder method resolveSqmInsertStrategy.
@SuppressWarnings("unchecked")
private SqmMultiTableInsertStrategy resolveSqmInsertStrategy(String strategyName, StandardServiceRegistry serviceRegistry, StrategySelector strategySelector) {
if (strategyName == null) {
return null;
}
return strategySelector.resolveStrategy(SqmMultiTableInsertStrategy.class, strategyName, (SqmMultiTableInsertStrategy) null, strategyClass -> {
Constructor<SqmMultiTableInsertStrategy> dialectConstructor = null;
Constructor<SqmMultiTableInsertStrategy> 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<SqmMultiTableInsertStrategy>) declaredConstructor;
break;
} else if (parameterTypes.length == 0) {
emptyConstructor = (Constructor<SqmMultiTableInsertStrategy>) 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.SqmMultiTableInsertStrategy in project hibernate-orm by hibernate.
the class QuerySqmImpl method buildInsertQueryPlan.
private NonSelectQueryPlan buildInsertQueryPlan() {
// noinspection rawtypes
final SqmInsertStatement sqmInsert = (SqmInsertStatement) getSqmStatement();
final String entityNameToInsert = sqmInsert.getTarget().getReferencedPathSource().getHibernateEntityName();
final EntityPersister entityDescriptor = getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(entityNameToInsert);
final SqmMultiTableInsertStrategy multiTableStrategy = entityDescriptor.getSqmMultiTableInsertStrategy();
if (multiTableStrategy == null || isSimpleValuesInsert(sqmInsert, entityDescriptor)) {
return new SimpleInsertQueryPlan(sqmInsert, domainParameterXref);
} else {
return new MultiTableInsertQueryPlan(sqmInsert, domainParameterXref, multiTableStrategy);
}
}
Aggregations