Search in sources :

Example 1 with SqmMultiTableMutationStrategy

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);
    }
}
Also used : SqmUpdateStatement(org.hibernate.query.sqm.tree.update.SqmUpdateStatement) EntityPersister(org.hibernate.persister.entity.EntityPersister) SqmMultiTableMutationStrategy(org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy)

Example 2 with SqmMultiTableMutationStrategy

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);
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SqmMultiTableMutationStrategy(org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy)

Example 3 with SqmMultiTableMutationStrategy

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!");
    });
}
Also used : StrategySelectionException(org.hibernate.boot.registry.selector.spi.StrategySelectionException) Constructor(java.lang.reflect.Constructor) Dialect(org.hibernate.dialect.Dialect) SqmMultiTableMutationStrategy(org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy) HibernateException(org.hibernate.HibernateException) StrategySelectionException(org.hibernate.boot.registry.selector.spi.StrategySelectionException)

Example 4 with SqmMultiTableMutationStrategy

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);
}
Also used : RootClass(org.hibernate.mapping.RootClass) SqmMultiTableMutationStrategy(org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) InFlightEntityMappingType(org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType)

Example 5 with SqmMultiTableMutationStrategy

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);
}
Also used : RuntimeModelCreationContext(org.hibernate.metamodel.spi.RuntimeModelCreationContext) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) SqmMultiTableMutationStrategy(org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices)

Aggregations

SqmMultiTableMutationStrategy (org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy)5 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 Constructor (java.lang.reflect.Constructor)1 HibernateException (org.hibernate.HibernateException)1 StrategySelectionException (org.hibernate.boot.registry.selector.spi.StrategySelectionException)1 SessionFactoryOptions (org.hibernate.boot.spi.SessionFactoryOptions)1 Dialect (org.hibernate.dialect.Dialect)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 RootClass (org.hibernate.mapping.RootClass)1 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)1 InFlightEntityMappingType (org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType)1 RuntimeModelCreationContext (org.hibernate.metamodel.spi.RuntimeModelCreationContext)1 SqmUpdateStatement (org.hibernate.query.sqm.tree.update.SqmUpdateStatement)1