diff --git a/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java index c186ac15c0..529c9060ef 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java @@ -24,7 +24,6 @@ import org.hibernate.dialect.function.SQLFunction; import org.hibernate.jpa.spi.JpaCompliance; import org.hibernate.loader.BatchFetchStyle; import org.hibernate.proxy.EntityNotFoundDelegate; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.tuple.entity.EntityTuplizer; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java index 109f278fe5..340d429a3b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java @@ -60,7 +60,7 @@ import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode; import org.hibernate.query.criteria.LiteralHandlingMode; import org.hibernate.query.hql.SemanticQueryProducer; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.query.sqm.produce.function.SqmFunctionRegistry; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; @@ -212,7 +212,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { // Queries private SemanticQueryProducer semanticQueryProducer; - private SqmMutationStrategy sqmMutationStrategy; + private SqmMultiTableMutationStrategy sqmMultiTableMutationStrategy; + private SqmFunctionRegistry sqmFunctionRegistry; private Boolean useOfJdbcNamedParametersEnabled; private Map querySubstitutions; private boolean namedQueryStartupCheckingEnabled; @@ -383,7 +384,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { ) ); - this.sqmMutationStrategy = resolveSqmMutationStrategy( + this.sqmMultiTableMutationStrategy = resolveSqmMutationStrategy( sqmMutationStrategyImplName, serviceRegistry, strategySelector @@ -565,7 +566,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { } } - private SqmMutationStrategy resolveSqmMutationStrategy( + private SqmMultiTableMutationStrategy resolveSqmMutationStrategy( String strategyName, StandardServiceRegistry serviceRegistry, StrategySelector strategySelector) { @@ -575,13 +576,13 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { //noinspection Convert2Lambda return strategySelector.resolveDefaultableStrategy( - SqmMutationStrategy.class, + SqmMultiTableMutationStrategy.class, strategyName, - new Callable() { + new Callable() { @Override - public SqmMutationStrategy call() throws Exception { + public SqmMultiTableMutationStrategy call() throws Exception { final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); - return (SqmMutationStrategy) classLoaderService.classForName( strategyName ).newInstance(); + return (SqmMultiTableMutationStrategy) classLoaderService.classForName( strategyName ).newInstance(); } } ); @@ -836,8 +837,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { } @Override - public SqmMutationStrategy getSqmMutationStrategy() { - return sqmMutationStrategy; + public SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy() { + return sqmMultiTableMutationStrategy; } @Override @@ -847,7 +848,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { @Override public SqmFunctionRegistry getSqmFunctionRegistry() { - throw new NotYetImplementedFor6Exception( getClass() ); + return this.sqmFunctionRegistry; } @Override @@ -1211,6 +1212,10 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { this.statelessInterceptorSupplier = statelessInterceptorSupplier; } + public void applySqmFunctionRegistry(SqmFunctionRegistry sqmFunctionRegistry) { + this.sqmFunctionRegistry = sqmFunctionRegistry; + } + public void applyStatementInspector(StatementInspector statementInspector) { this.statementInspector = statementInspector; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java index c5dcab2c49..165752cbaf 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java @@ -90,6 +90,11 @@ import org.hibernate.engine.transaction.jta.platform.internal.WebSphereJtaPlatfo import org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform; import org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; +import org.hibernate.query.sqm.mutation.internal.cte.CteBasedMutationStrategy; +import org.hibernate.query.sqm.mutation.internal.idtable.GlobalTemporaryTableStrategy; +import org.hibernate.query.sqm.mutation.internal.idtable.LocalTemporaryTableStrategy; +import org.hibernate.query.sqm.mutation.internal.idtable.PersistentTableStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; @@ -158,7 +163,7 @@ public class StrategySelectorBuilder { addDialects( strategySelector ); addJtaPlatforms( strategySelector ); addTransactionCoordinatorBuilders( strategySelector ); - addMultiTableBulkIdStrategies( strategySelector ); + addSqmMultiTableMutationStrategies( strategySelector ); addImplicitNamingStrategies( strategySelector ); addCacheKeysFactories( strategySelector ); @@ -403,23 +408,27 @@ public class StrategySelectorBuilder { ); } - private void addMultiTableBulkIdStrategies(StrategySelectorImpl strategySelector) { -// strategySelector.registerStrategyImplementor( -// MultiTableBulkIdStrategy.class, -// PersistentTableBulkIdStrategy.SHORT_NAME, -// PersistentTableBulkIdStrategy.class -// ); -// strategySelector.registerStrategyImplementor( -// MultiTableBulkIdStrategy.class, -// GlobalTemporaryTableBulkIdStrategy.SHORT_NAME, -// GlobalTemporaryTableBulkIdStrategy.class -// ); -// strategySelector.registerStrategyImplementor( -// MultiTableBulkIdStrategy.class, -// LocalTemporaryTableBulkIdStrategy.SHORT_NAME, -// LocalTemporaryTableBulkIdStrategy.class -// ); - throw new NotYetImplementedFor6Exception( getClass() ); + private void addSqmMultiTableMutationStrategies(StrategySelectorImpl strategySelector) { + strategySelector.registerStrategyImplementor( + SqmMultiTableMutationStrategy.class, + CteBasedMutationStrategy.SHORT_NAME, + CteBasedMutationStrategy.class + ); + strategySelector.registerStrategyImplementor( + SqmMultiTableMutationStrategy.class, + GlobalTemporaryTableStrategy.SHORT_NAME, + GlobalTemporaryTableStrategy.class + ); + strategySelector.registerStrategyImplementor( + SqmMultiTableMutationStrategy.class, + LocalTemporaryTableStrategy.SHORT_NAME, + LocalTemporaryTableStrategy.class + ); + strategySelector.registerStrategyImplementor( + SqmMultiTableMutationStrategy.class, + PersistentTableStrategy.SHORT_NAME, + PersistentTableStrategy.class + ); } private void addImplicitNamingStrategies(StrategySelectorImpl strategySelector) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java index 9c0019de9f..9398e488d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java @@ -30,7 +30,7 @@ import org.jboss.logging.Logger; public class StrategySelectorImpl implements StrategySelector { private static final Logger log = Logger.getLogger( StrategySelectorImpl.class ); - + @SuppressWarnings("WeakerAccess") public static final StrategyCreator STANDARD_STRATEGY_CREATOR = strategyClass -> { try { return strategyClass.newInstance(); @@ -58,11 +58,10 @@ public class StrategySelectorImpl implements StrategySelector { @Override public void registerStrategyImplementor(Class strategy, String name, Class implementation) { - Map namedStrategyImplementorMap = namedStrategyImplementorByStrategyMap.get( strategy ); - if ( namedStrategyImplementorMap == null ) { - namedStrategyImplementorMap = new ConcurrentHashMap<>(); - namedStrategyImplementorByStrategyMap.put( strategy, namedStrategyImplementorMap ); - } + final Map namedStrategyImplementorMap = namedStrategyImplementorByStrategyMap.computeIfAbsent( + strategy, + aClass -> new ConcurrentHashMap<>() + ); final Class old = namedStrategyImplementorMap.put( name, implementation ); if ( old == null ) { @@ -142,7 +141,6 @@ public class StrategySelectorImpl implements StrategySelector { } @Override - @SuppressWarnings("unchecked") public T resolveDefaultableStrategy(Class strategy, Object strategyReference, final T defaultValue) { return resolveDefaultableStrategy( strategy, @@ -205,7 +203,7 @@ public class StrategySelectorImpl implements StrategySelector { } final Class implementationClass; - if ( Class.class.isInstance( strategyReference ) ) { + if ( strategyReference instanceof Class ) { implementationClass = (Class) strategyReference; } else { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java index 139e389e69..ed70a1b5b9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java @@ -31,7 +31,7 @@ import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode; import org.hibernate.query.criteria.LiteralHandlingMode; import org.hibernate.query.hql.SemanticQueryProducer; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.query.sqm.produce.function.SqmFunctionRegistry; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; @@ -120,8 +120,8 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp } @Override - public SqmMutationStrategy getSqmMutationStrategy() { - return delegate.getSqmMutationStrategy(); + public SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy() { + return delegate.getSqmMultiTableMutationStrategy(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java index 794a2f3a0c..77c1de0f22 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java @@ -27,6 +27,7 @@ import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cfg.MetadataSourceType; import org.hibernate.collection.spi.CollectionSemanticsResolver; import org.hibernate.dialect.function.SQLFunction; +import org.hibernate.metamodel.internal.StandardManagedTypeRepresentationResolver; import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver; import org.jboss.jandex.IndexView; @@ -55,7 +56,8 @@ public interface MetadataBuildingOptions { MappingDefaults getMappingDefaults(); default ManagedTypeRepresentationResolver getManagedTypeRepresentationResolver() { - throw new NotYetImplementedFor6Exception( getClass() ); + // for now always return the standard one + return StandardManagedTypeRepresentationResolver.INSTANCE; } default CollectionSemanticsResolver getPersistentCollectionRepresentationResolver() { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java index fd8f8af817..6d69631013 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java @@ -33,7 +33,7 @@ import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode; import org.hibernate.query.criteria.LiteralHandlingMode; import org.hibernate.query.hql.SemanticQueryProducer; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.query.sqm.produce.function.SqmFunctionRegistry; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; @@ -144,7 +144,7 @@ public interface SessionFactoryOptions { SemanticQueryProducer getHqlTranslator(); - SqmMutationStrategy getSqmMutationStrategy(); + SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy(); StatementInspector getStatementInspector(); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index b10e70b496..7ae795aa5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -15,11 +15,11 @@ import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.registry.classloading.internal.TcclLookupPrecedence; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.spi.TimestampsCacheFactory; -import org.hibernate.internal.log.DeprecationLogger; import org.hibernate.jpa.spi.JpaCompliance; import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode; import org.hibernate.query.internal.ParameterMetadataImpl; import org.hibernate.query.spi.QueryInterpretationCache; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.resource.beans.container.spi.ExtendedBeanManager; import org.hibernate.resource.transaction.spi.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; @@ -943,7 +943,7 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings { /** * Defines the "global" strategy to use for handling HQL and Criteria mutation queries. * - * Names the {@link org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy} to use. + * Names the {@link SqmMultiTableMutationStrategy} to use. */ String QUERY_MULTI_TABLE_MUTATION_STRATEGY = "hibernate.query.mutation_strategy"; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ResultsetMappingSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ResultsetMappingSecondPass.java index 68bc5e84f1..e1f19a68d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ResultsetMappingSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ResultsetMappingSecondPass.java @@ -24,8 +24,10 @@ import org.hibernate.LockMode; import org.hibernate.MappingException; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.boot.spi.NamedResultSetMappingDefinition; import org.hibernate.cfg.BinderHelper; import org.hibernate.cfg.QuerySecondPass; +import org.hibernate.query.spi.NamedResultSetMappingMemento; import org.hibernate.query.sql.spi.ResultSetMappingDescriptor; import org.hibernate.engine.query.spi.sql.NativeSQLQueryConstructorReturn; import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn; @@ -57,6 +59,19 @@ public class ResultsetMappingSecondPass implements QuerySecondPass { @Override public void doSecondPass(Map persistentClasses) throws MappingException { + if ( ann == null ) { + return; + } + + final SqlResultSetMappingDefinition mappingDefinition = SqlResultSetMappingDefinition.from( ann, context ); + + if ( isDefault ) { + context.getMetadataCollector().addDefaultResultSetMapping( mappingDefinition ); + } + else { + context.getMetadataCollector().addResultSetMapping( mappingDefinition ); + } + //TODO add parameters checkings // if ( ann == null ) return; // ResultSetMappingDescriptor definition = new ResultSetMappingDescriptor( ann.name() ); @@ -197,7 +212,6 @@ public class ResultsetMappingSecondPass implements QuerySecondPass { // else { // context.getMetadataCollector().addResultSetMapping( definition ); // } - throw new NotYetImplementedFor6Exception( getClass() ); } private String normalizeColumnQuoting(String name) { diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SqlResultSetMappingDefinition.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SqlResultSetMappingDefinition.java new file mode 100644 index 0000000000..6cdb3436d5 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SqlResultSetMappingDefinition.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.cfg.annotations; + +import javax.persistence.SqlResultSetMapping; + +import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.boot.spi.NamedResultSetMappingDefinition; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.query.internal.NamedResultSetMappingMementoImpl; +import org.hibernate.query.spi.NamedResultSetMappingMemento; + +/** + * @author Steve Ebersole + */ +public class SqlResultSetMappingDefinition implements NamedResultSetMappingDefinition { + public static SqlResultSetMappingDefinition from( + SqlResultSetMapping mappingAnnotation, + MetadataBuildingContext context) { + return new SqlResultSetMappingDefinition( mappingAnnotation.name(), context ); + } + + private final String mappingName; + + private SqlResultSetMappingDefinition(String mappingName, MetadataBuildingContext context) { + this.mappingName = mappingName; + } + + @Override + public String getRegistrationName() { + return mappingName; + } + + @Override + public NamedResultSetMappingMemento resolve(SessionFactoryImplementor factory) { + return new NamedResultSetMappingMementoImpl( mappingName, factory ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java index e10efc5357..80609bb641 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java @@ -25,7 +25,7 @@ import org.hibernate.dialect.function.VarArgsSQLFunction; import org.hibernate.dialect.identity.AbstractTransactSQLIdentityColumnSupport; import org.hibernate.dialect.identity.IdentityColumnSupport; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.type.StandardBasicTypes; /** @@ -211,7 +211,7 @@ abstract class AbstractTransactSQLDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new LocalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java index bc859b3d34..a726624850 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java @@ -40,7 +40,7 @@ import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Lockable; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.sql.CacheJoinFragment; import org.hibernate.sql.JoinFragment; import org.hibernate.type.StandardBasicTypes; @@ -444,7 +444,7 @@ public class Cache71Dialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new GlobalTemporaryTableBulkIdStrategy( // new IdTableSupportStandardImpl() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java index 0e83cd1f29..89b599bfbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java @@ -11,7 +11,7 @@ import java.sql.Types; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.dialect.function.DB2SubstringFunction; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.type.descriptor.sql.CharTypeDescriptor; import org.hibernate.type.descriptor.sql.ClobTypeDescriptor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; @@ -36,7 +36,7 @@ public class DB297Dialect extends DB2Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // // Starting in DB2 9.7, "real" global temporary tables that can be shared between sessions diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java index ee955270b7..1e1021256f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java @@ -38,7 +38,7 @@ import org.hibernate.hql.spi.id.local.AfterUseAction; import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorDB2DatabaseImpl; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; @@ -397,7 +397,7 @@ public class DB2Dialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // // Prior to DB2 9.7, "real" global temporary tables that can be shared between sessions diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java index d711275353..ba2a0dd6c1 100755 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -25,7 +25,7 @@ import org.hibernate.engine.spi.RowSelection; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.sql.CaseFragment; import org.hibernate.sql.DerbyCaseFragment; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorDerbyDatabaseImpl; @@ -591,7 +591,7 @@ public class DerbyDialect extends DB2Dialect { * @param runtimeRootEntityDescriptor */ @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new LocalTemporaryTableBulkIdStrategy(new IdTableSupportStandardImpl() { // @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 8aeed5e827..db498ae350 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -99,7 +99,7 @@ import org.hibernate.procedure.internal.StandardCallableStatementSupport; import org.hibernate.procedure.spi.CallableStatementSupport; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.spi.QueryOptions; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.ANSICaseFragment; import org.hibernate.sql.ANSIJoinFragment; @@ -1509,7 +1509,7 @@ public abstract class Dialect implements ConversionContext { return getCreateTableString(); } - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java index ff39e1bbc0..ef192485c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java @@ -33,7 +33,7 @@ import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorH2DatabaseImpl; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; @@ -368,7 +368,7 @@ public class H2Dialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new LocalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java index 2a4025f5bb..eb5ddb0a9d 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java @@ -11,7 +11,7 @@ import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.dialect.function.VarArgsSQLFunction; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.type.StandardBasicTypes; /** @@ -48,7 +48,7 @@ public class HANAColumnStoreDialect extends AbstractHANADialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new GlobalTemporaryTableBulkIdStrategy( new IdTableSupportStandardImpl() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java index c11800faca..c0be3951c7 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java @@ -8,7 +8,7 @@ package org.hibernate.dialect; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; /** * An SQL dialect for the SAP HANA row store. @@ -36,7 +36,7 @@ public class HANARowStoreDialect extends AbstractHANADialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new GlobalTemporaryTableBulkIdStrategy( new IdTableSupportStandardImpl() { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java index dac914833e..e94bdcc407 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java @@ -45,7 +45,7 @@ import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Lockable; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorHSQLDBDatabaseImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; import org.hibernate.type.StandardBasicTypes; @@ -504,7 +504,7 @@ public class HSQLDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // // Hibernate uses this information for temporary tables that it uses for its own operations diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java index 24147d836f..8ed3636771 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java @@ -26,7 +26,7 @@ import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorInformixDatabaseImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; import org.hibernate.type.StandardBasicTypes; @@ -279,7 +279,7 @@ public class InformixDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new LocalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/IngresDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/IngresDialect.java index 9b8354ad4d..a579f476fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/IngresDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/IngresDialect.java @@ -18,7 +18,7 @@ import org.hibernate.dialect.pagination.FirstLimitHandler; import org.hibernate.dialect.pagination.LegacyFirstLimitHandler; import org.hibernate.dialect.pagination.LimitHandler; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.tool.schema.extract.internal.SequenceNameExtractorImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; import org.hibernate.type.StandardBasicTypes; @@ -270,7 +270,7 @@ public class IngresDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new GlobalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java index bb887e66f3..ef79dc6ebe 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -34,7 +34,7 @@ import org.hibernate.exception.spi.SQLExceptionConversionDelegate; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.mapping.Column; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.type.StandardBasicTypes; /** @@ -343,7 +343,7 @@ public class MySQLDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new LocalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java index 0beb616516..a998b96a60 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java @@ -38,7 +38,7 @@ import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.procedure.internal.StandardCallableStatementSupport; import org.hibernate.procedure.spi.CallableStatementSupport; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.sql.CaseFragment; import org.hibernate.sql.DecodeCaseFragment; import org.hibernate.sql.JoinFragment; @@ -615,7 +615,7 @@ public class Oracle8iDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new GlobalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java index cea8c3196b..85e09ad0cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java @@ -18,7 +18,7 @@ import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorOracleDatabaseImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; import org.hibernate.type.StandardBasicTypes; @@ -344,7 +344,7 @@ public class Oracle9Dialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new GlobalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java index b87c8f4ef3..77aa95f79c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java @@ -39,7 +39,7 @@ import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.procedure.internal.PostgresCallableStatementSupport; import org.hibernate.procedure.spi.CallableStatementSupport; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.sql.BlobTypeDescriptor; import org.hibernate.type.descriptor.sql.ClobTypeDescriptor; @@ -366,7 +366,7 @@ public class PostgreSQL81Dialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new LocalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java index b8f22e546f..27281b505b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java @@ -9,7 +9,7 @@ package org.hibernate.dialect; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.boot.model.TypeContributions; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.service.ServiceRegistry; import org.hibernate.type.PostgresUUIDType; @@ -33,7 +33,7 @@ public class PostgreSQL82Dialect extends PostgreSQL81Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new LocalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SAPDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SAPDBDialect.java index 03a9820afc..7e1ff75b14 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SAPDBDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SAPDBDialect.java @@ -16,7 +16,7 @@ import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.dialect.function.VarArgsSQLFunction; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.sql.CaseFragment; import org.hibernate.sql.DecodeCaseFragment; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorSAPDBDatabaseImpl; @@ -219,7 +219,7 @@ public class SAPDBDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new LocalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/TeradataDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/TeradataDialect.java index c92163a2e6..b1ff43a050 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/TeradataDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/TeradataDialect.java @@ -13,7 +13,7 @@ import org.hibernate.cfg.Environment; import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.dialect.function.VarArgsSQLFunction; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.type.StandardBasicTypes; /** @@ -119,7 +119,7 @@ public class TeradataDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new GlobalTemporaryTableBulkIdStrategy( this, AfterUseAction.CLEAN ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/TimesTenDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/TimesTenDialect.java index 20179edcd3..cd50e9b23c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/TimesTenDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/TimesTenDialect.java @@ -26,7 +26,7 @@ import org.hibernate.dialect.pagination.LegacyFirstLimitHandler; import org.hibernate.dialect.pagination.LimitHandler; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Lockable; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.sql.JoinFragment; import org.hibernate.sql.OracleJoinFragment; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorTimesTenDatabaseImpl; @@ -218,7 +218,7 @@ public class TimesTenDialect extends Dialect { } @Override - public SqmMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { + public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) { throw new NotYetImplementedFor6Exception( getClass() ); // return new GlobalTemporaryTableBulkIdStrategy( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunction.java index 0ee973b23f..d0b8fc9e92 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunction.java @@ -23,6 +23,8 @@ import org.hibernate.type.Type; * * @author David Channon * @author Steve Ebersole + * + * @deprecated Replaced by {@link org.hibernate.query.sqm.function.SqmFunction} */ public interface SQLFunction { /** diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunctionRegistry.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunctionRegistry.java index 48d413fa6b..18b5da527f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunctionRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunctionRegistry.java @@ -15,7 +15,10 @@ import org.hibernate.dialect.Dialect; * Defines a registry for SQLFunction instances * * @author Steve Ebersole + * + * @deprecated Replaced by {@link org.hibernate.query.sqm.function.SqmFunction} */ +@Deprecated public class SQLFunctionRegistry { private final Map functionMap = new TreeMap(String.CASE_INSENSITIVE_ORDER); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java index a78e397a1f..633c50a8da 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java @@ -478,6 +478,11 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { return delegate.getNamedNativeQuery( name ); } + @Override + public NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping) { + return delegate.getNamedNativeQuery( name, resultSetMapping ); + } + @Override public QueryImplementor createQuery(String queryString) { return delegate.createQuery( queryString ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java index 596aaef214..fa507a6c93 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java @@ -108,6 +108,9 @@ public interface SessionImplementor extends Session, SharedSessionContractImplem @Override NativeQueryImplementor getNamedNativeQuery(String name); + @Override + NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping); + @Override QueryImplementor getNamedQuery(String queryName); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 2c66e9d97e..327a2c3e55 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -768,7 +768,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont protected void applyQuerySettingsAndHints(Query query) { } - @Override public NativeQueryImplementor getNamedNativeQuery(String queryName) { final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine() @@ -782,6 +781,19 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + queryName + "]" ) ); } + @Override + public NativeQueryImplementor getNamedNativeQuery(String queryName, String resultSetMapping) { + final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine() + .getNamedQueryRepository() + .getNativeQueryMemento( queryName ); + + if ( namedNativeDescriptor != null ) { + return namedNativeDescriptor.toQuery( this, resultSetMapping ); + } + + throw exceptionConverter.convert( new IllegalArgumentException( "No query defined for that name [" + queryName + "]" ) ); + } + @Override @SuppressWarnings("UnnecessaryLocalVariable") diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 8f230a0ca4..d1999774cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -15,10 +15,12 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TimeZone; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; import java.util.regex.Pattern; import javax.naming.Reference; @@ -53,7 +55,10 @@ import org.hibernate.boot.cfgxml.spi.LoadedConfig; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.cfg.internal.DomainDataRegionConfigImpl; +import org.hibernate.cache.cfg.spi.DomainDataRegionConfig; import org.hibernate.cache.spi.CacheImplementor; +import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Environment; import org.hibernate.cfg.Settings; @@ -93,11 +98,15 @@ import org.hibernate.jpa.internal.AfterCompletionActionLegacyJpaImpl; import org.hibernate.jpa.internal.ExceptionMapperLegacyJpaImpl; import org.hibernate.jpa.internal.ManagedFlushCheckerLegacyJpaImpl; import org.hibernate.jpa.internal.PersistenceUnitUtilImpl; +import org.hibernate.mapping.Collection; +import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.CollectionMetadata; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.JpaMetamodel; +import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; +import org.hibernate.metamodel.spi.DomainMetamodel; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Loadable; @@ -133,8 +142,6 @@ import org.hibernate.type.spi.TypeConfiguration; import org.jboss.logging.Logger; -import static org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting.determineJpaMetaModelPopulationSetting; - /** * Concrete implementation of the SessionFactory interface. Has the following @@ -178,8 +185,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { // todo : org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor too? - private final transient MetamodelImplementor metamodel; - private final transient NodeBuilder criteriaBuilder; + private final transient DomainMetamodel metamodel; private final PersistenceUnitUtil jpaPersistenceUnitUtil; private final transient CacheImplementor cacheAccess; private final transient QueryEngine queryEngine; @@ -200,21 +206,19 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { private final transient SessionBuilder temporarySessionOpenOptions; public SessionFactoryImpl( - final MetadataImplementor metadata, + final MetadataImplementor bootMetamodel, SessionFactoryOptions options) { LOG.debug( "Building session factory" ); this.sessionFactoryOptions = options; - this.settings = new Settings( options, metadata ); + this.settings = new Settings( options, bootMetamodel ); this.serviceRegistry = options .getServiceRegistry() .getService( SessionFactoryServiceRegistryFactory.class ) .buildServiceRegistry( this, options ); - prepareEventListeners( metadata ); - - this.queryEngine = QueryEngine.from( this, metadata ); + prepareEventListeners( bootMetamodel ); final CfgXmlAccessService cfgXmlAccessService = serviceRegistry.getService( CfgXmlAccessService.class ); @@ -247,17 +251,16 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { this.sqlFunctionRegistry = new SQLFunctionRegistry( jdbcServices.getJdbcEnvironment().getDialect(), options.getCustomSqlFunctionMap() ); this.cacheAccess = this.serviceRegistry.getService( CacheImplementor.class ); - this.criteriaBuilder = SqmCriteriaNodeBuilder.create( this ); this.jpaPersistenceUnitUtil = new PersistenceUnitUtilImpl( this ); for ( SessionFactoryObserver sessionFactoryObserver : options.getSessionFactoryObservers() ) { this.observer.addObserver( sessionFactoryObserver ); } - this.typeHelper = new TypeLocatorImpl( metadata.getTypeConfiguration().getTypeResolver() ); + this.typeHelper = new TypeLocatorImpl( bootMetamodel.getTypeConfiguration().getTypeResolver() ); this.filters = new HashMap<>(); - this.filters.putAll( metadata.getFilterDefinitions() ); + this.filters.putAll( bootMetamodel.getFilterDefinitions() ); LOG.debugf( "Session factory constructed with filter configurations : %s", filters ); LOG.debugf( "Instantiating session factory with properties: %s", properties ); @@ -281,14 +284,14 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { this.observer.addObserver( integratorObserver ); try { for ( Integrator integrator : serviceRegistry.getService( IntegratorService.class ).getIntegrators() ) { - integrator.integrate( metadata, this, this.serviceRegistry ); + integrator.integrate( bootMetamodel, this, this.serviceRegistry ); integratorObserver.integrators.add( integrator ); } //Generators: this.identifierGenerators = new HashMap<>(); - metadata.getEntityBindings().stream().filter( model -> !model.isInherited() ).forEach( model -> { + bootMetamodel.getEntityBindings().stream().filter( model -> !model.isInherited() ).forEach( model -> { IdentifierGenerator generator = model.getIdentifier().createIdentifierGenerator( - metadata.getIdentifierGeneratorFactory(), + bootMetamodel.getIdentifierGeneratorFactory(), jdbcServices.getJdbcEnvironment().getDialect(), settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), @@ -299,7 +302,19 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { LOG.debug( "Instantiated session factory" ); - this.metamodel = (MetamodelImplementor) metadata.getTypeConfiguration().scope( this ).create( metadata ); + primeSecondLevelCacheRegions( bootMetamodel ); + + this.metamodel = bootMetamodel.getTypeConfiguration().scope( this ); + ( (DomainMetamodelImpl) metamodel ).finishInitialization( + bootMetamodel, + bootMetamodel.getTypeConfiguration().getMetadataBuildingContext().getBootstrapContext(), + this + ); + + this.queryEngine = QueryEngine.from( this, bootMetamodel ); + if ( options.isNamedQueryStartupCheckingEnabled() ) { + queryEngine.getNamedQueryRepository().checkNamedQueries( queryEngine ); + } // todo (6.0) : manage old getMultiTableBulkIdStrategy @@ -311,7 +326,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { // ); SchemaManagementToolCoordinator.process( - metadata, + bootMetamodel, serviceRegistry, properties, action -> SessionFactoryImpl.this.delayedDropAction = action @@ -321,14 +336,14 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { // this needs to happen after persisters are all ready to go... this.fetchProfiles = new HashMap<>(); - for ( org.hibernate.mapping.FetchProfile mappingProfile : metadata.getFetchProfiles() ) { + for ( org.hibernate.mapping.FetchProfile mappingProfile : bootMetamodel.getFetchProfiles() ) { final FetchProfile fetchProfile = new FetchProfile( mappingProfile.getName() ); for ( org.hibernate.mapping.FetchProfile.Fetch mappingFetch : mappingProfile.getFetches() ) { // resolve the persister owning the fetch - final String entityName = metamodel.getImportedClassName( mappingFetch.getEntity() ); + final String entityName = metamodel.getImportedName( mappingFetch.getEntity() ); final EntityPersister owner = entityName == null ? null - : metamodel.entityPersister( entityName ); + : metamodel.getEntityDescriptor( entityName ); if ( owner == null ) { throw new HibernateException( "Unable to resolve entity reference [" + mappingFetch.getEntity() @@ -379,6 +394,60 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { } } + private void primeSecondLevelCacheRegions(MetadataImplementor mappingMetadata) { + final Map regionConfigBuilders = new ConcurrentHashMap<>(); + + // todo : ultimately this code can be made more efficient when we have a better intrinsic understanding of the hierarchy as a whole + + for ( PersistentClass bootEntityDescriptor : mappingMetadata.getEntityBindings() ) { + final AccessType accessType = AccessType.fromExternalName( bootEntityDescriptor.getCacheConcurrencyStrategy() ); + + if ( accessType != null ) { + if ( bootEntityDescriptor.isCached() ) { + regionConfigBuilders.computeIfAbsent( + bootEntityDescriptor.getRootClass().getCacheRegionName(), + DomainDataRegionConfigImpl.Builder::new + ) + .addEntityConfig( bootEntityDescriptor, accessType ); + } + + if ( bootEntityDescriptor instanceof RootClass + && bootEntityDescriptor.hasNaturalId() + && bootEntityDescriptor.getNaturalIdCacheRegionName() != null ) { + regionConfigBuilders.computeIfAbsent( + bootEntityDescriptor.getNaturalIdCacheRegionName(), + DomainDataRegionConfigImpl.Builder::new + ) + .addNaturalIdConfig( (RootClass) bootEntityDescriptor, accessType ); + } + } + } + + for ( Collection collection : mappingMetadata.getCollectionBindings() ) { + final AccessType accessType = AccessType.fromExternalName( collection.getCacheConcurrencyStrategy() ); + if ( accessType != null ) { + regionConfigBuilders.computeIfAbsent( + collection.getCacheRegionName(), + DomainDataRegionConfigImpl.Builder::new + ) + .addCollectionConfig( collection, accessType ); + } + } + + final Set regionConfigs; + if ( regionConfigBuilders.isEmpty() ) { + regionConfigs = Collections.emptySet(); + } + else { + regionConfigs = new HashSet<>(); + for ( DomainDataRegionConfigImpl.Builder builder : regionConfigBuilders.values() ) { + regionConfigs.add( builder.build() ); + } + } + + getCache().prime( regionConfigs ); + } + private void prepareEventListeners(MetadataImplementor metadata) { final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class ); @@ -521,7 +590,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { @Override public QueryEngine getQueryEngine() { - return null; + return queryEngine; } @Override @@ -639,13 +708,13 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { @Override public NodeBuilder getCriteriaBuilder() { validateNotClosed(); - return criteriaBuilder; + return queryEngine.getCriteriaBuilder(); } @Override public MetamodelImplementor getMetamodel() { validateNotClosed(); - return metamodel; + return (MetamodelImplementor) metamodel; } @Override @@ -757,10 +826,12 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { } if ( metamodel != null ) { - metamodel.close(); + ( (DomainMetamodelImpl) metamodel ).close(); } - queryEngine.close(); + if ( queryEngine != null ) { + queryEngine.close(); + } if ( delayedDropAction != null ) { delayedDropAction.perform( serviceRegistry ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractEmbeddableRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractEmbeddableRepresentationStrategy.java new file mode 100644 index 0000000000..6210554cf4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractEmbeddableRepresentationStrategy.java @@ -0,0 +1,82 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import java.util.Iterator; +import java.util.Map; + +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.Property; +import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.property.access.spi.PropertyAccess; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; + +/** + * @author Steve Ebersole + */ +public abstract class AbstractEmbeddableRepresentationStrategy implements EmbeddableRepresentationStrategy { + private final JavaTypeDescriptor embeddableJavaTypeDescriptor; + + private final int propertySpan; + private final PropertyAccess[] propertyAccesses; + private final boolean hasCustomAccessors; + + private final Map attributeNameToPositionMap; + + public AbstractEmbeddableRepresentationStrategy( + Component bootDescriptor, + JavaTypeDescriptor embeddableJavaTypeDescriptor, + RuntimeModelCreationContext creationContext) { + this.propertySpan = bootDescriptor.getPropertySpan(); + this.embeddableJavaTypeDescriptor = embeddableJavaTypeDescriptor; + + this.propertyAccesses = new PropertyAccess[ propertySpan ]; + this.attributeNameToPositionMap = CollectionHelper.concurrentMap( propertySpan ); + + boolean foundCustomAccessor = false; + Iterator itr = bootDescriptor.getPropertyIterator(); + int i = 0; + while ( itr.hasNext() ) { + final Property prop = ( Property ) itr.next(); + propertyAccesses[i] = buildPropertyAccess( prop ); + attributeNameToPositionMap.put( prop.getName(), i ); + + if ( !prop.isBasicPropertyAccessor() ) { + foundCustomAccessor = true; + } + + i++; + } + + hasCustomAccessors = foundCustomAccessor; + } + + protected abstract PropertyAccess buildPropertyAccess(Property bootAttributeDescriptor); + + public JavaTypeDescriptor getEmbeddableJavaTypeDescriptor() { + return embeddableJavaTypeDescriptor; + } + + public int getPropertySpan() { + return propertySpan; + } + + public PropertyAccess[] getPropertyAccesses() { + return propertyAccesses; + } + + public boolean hasCustomAccessors() { + return hasCustomAccessors; + } + + @Override + public PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor) { + return propertyAccesses[ attributeNameToPositionMap.get( bootAttributeDescriptor.getName() ) ]; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractPojoInstantiator.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractPojoInstantiator.java new file mode 100644 index 0000000000..d2319c8f80 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractPojoInstantiator.java @@ -0,0 +1,37 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.metamodel.spi.Instantiator; + +/** + * @author Steve Ebersole + */ +public abstract class AbstractPojoInstantiator implements Instantiator { + private final Class mappedPojoClass; + private final boolean isAbstract; + + public AbstractPojoInstantiator(Class mappedPojoClass) { + this.mappedPojoClass = mappedPojoClass; + this.isAbstract = ReflectHelper.isAbstractClass( mappedPojoClass ); + } + + public Class getMappedPojoClass() { + return mappedPojoClass; + } + + public boolean isAbstract() { + return isAbstract; + } + + @Override + public boolean isInstance(Object object, SessionFactoryImplementor sessionFactory) { + return mappedPojoClass.isInstance( object ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java index 93b27090ea..59ee9b801a 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java @@ -110,8 +110,7 @@ public class AttributeFactory { attributeMetadata.getMember(), false, false, - property.isOptional(), - context.getCriteriaBuilder() + property.isOptional() ); } @@ -153,8 +152,7 @@ public class AttributeFactory { property.getName(), determineSimpleType( attributeMetadata.getValueContext() ), attributeMetadata.getMember(), - attributeMetadata.getAttributeClassification(), - context.getCriteriaBuilder() + attributeMetadata.getAttributeClassification() ); } @@ -184,8 +182,7 @@ public class AttributeFactory { property.getName(), attributeMetadata.getAttributeClassification(), determineSimpleType( attributeMetadata.getValueContext() ), - attributeMetadata.getMember(), - context.getCriteriaBuilder() + attributeMetadata.getMember() ); } @@ -200,8 +197,7 @@ public class AttributeFactory { attributeMetadata.getOwnerType(), determineSimpleType( attributeMetadata.getElementValueContext() ), javaTypeDescriptor, - determineListIndexOrMapKeyType( attributeMetadata ), - context.getCriteriaBuilder() + determineListIndexOrMapKeyType( attributeMetadata ) ); return info @@ -271,7 +267,7 @@ public class AttributeFactory { embeddableType = new EmbeddableTypeImpl( javaTypeDescriptor, representationStrategy, - context.getCriteriaBuilder().getDomainModel() + context.getJpaMetamodel() ); context.registerEmbeddableType( embeddableType ); @@ -281,7 +277,7 @@ public class AttributeFactory { else { embeddableType = new EmbeddableTypeImpl( component.getRoleName(), - context.getCriteriaBuilder().getDomainModel() + context.getJpaMetamodel() ); } @@ -1000,7 +996,7 @@ public class AttributeFactory { } else { return ownerType.getRepresentationStrategy() - .generatePropertyAccess( attributeContext.getPropertyMapping() ) + .resolvePropertyAccess( attributeContext.getPropertyMapping() ) .getGetter() .getMember(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/DynamicMapInstantiator.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/DynamicMapInstantiator.java new file mode 100644 index 0000000000..ad5426a5ee --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/DynamicMapInstantiator.java @@ -0,0 +1,75 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.Instantiator; + +/** + * @author Steve Ebersole + */ +public class DynamicMapInstantiator implements Instantiator { + public static final String KEY = "$type$"; + + private final String roleName; + private final Set isInstanceEntityNames = new HashSet<>(); + + public DynamicMapInstantiator(Component bootMapping) { + this.roleName = bootMapping.getRoleName(); + } + + public DynamicMapInstantiator(PersistentClass bootMapping) { + this.roleName = bootMapping.getEntityName(); + + isInstanceEntityNames.add( roleName ); + if ( bootMapping.hasSubclasses() ) { + Iterator itr = bootMapping.getSubclassClosureIterator(); + while ( itr.hasNext() ) { + final PersistentClass subclassInfo = ( PersistentClass ) itr.next(); + isInstanceEntityNames.add( subclassInfo.getEntityName() ); + } + } + } + + @Override + public Map instantiate(SharedSessionContractImplementor session) { + Map map = generateMap(); + if ( roleName != null ) { + //noinspection unchecked + map.put( KEY, roleName ); + } + return map; + } + + @SuppressWarnings("WeakerAccess") + protected Map generateMap() { + return new HashMap(); + } + + @Override + public boolean isInstance(Object object, SessionFactoryImplementor sessionFactory) { + if ( object instanceof Map ) { + if ( roleName == null ) { + return true; + } + final String type = (String) ( (Map) object ).get( KEY ); + return type == null || isInstanceEntityNames.contains( type ); + } + else { + return false; + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java index dca1d6fb62..c44e0e1d83 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java @@ -31,7 +31,6 @@ import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.persister.spi.PersisterFactory; -import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.type.EntityType; import org.hibernate.type.Type; import org.hibernate.type.spi.TypeConfiguration; @@ -85,8 +84,6 @@ public class InflightRuntimeMetamodel { modelCreationContext ); - finishDomainMetamodelInitialization(); - } public TypeConfiguration getTypeConfiguration() { @@ -233,39 +230,6 @@ public class InflightRuntimeMetamodel { } } - private void finishDomainMetamodelInitialization() { - // after *all* persisters and named queries are registered - entityPersisterMap.values().forEach( EntityPersister::generateEntityDefinition ); - - for ( EntityPersister persister : entityPersisterMap.values() ) { - persister.postInstantiate(); - registerEntityNameResolvers( persister, entityNameResolvers ); - } - collectionPersisterMap.values().forEach( CollectionPersister::postInstantiate ); - } - - private static void registerEntityNameResolvers( - EntityPersister persister, - Set entityNameResolvers) { - if ( persister.getEntityMetamodel() == null || persister.getEntityMetamodel().getTuplizer() == null ) { - return; - } - registerEntityNameResolvers( persister.getEntityMetamodel().getTuplizer(), entityNameResolvers ); - } - - private static void registerEntityNameResolvers( - EntityTuplizer tuplizer, - Set entityNameResolvers) { - EntityNameResolver[] resolvers = tuplizer.getEntityNameResolvers(); - if ( resolvers == null ) { - return; - } - - for ( EntityNameResolver resolver : resolvers ) { - entityNameResolvers.add( resolver ); - } - } - public Map getImports() { return imports; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index a4869a55c9..86de425f37 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -36,6 +36,7 @@ import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.IdentifiableDomainType; +import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType; import org.hibernate.metamodel.model.domain.PersistentAttribute; @@ -45,8 +46,8 @@ import org.hibernate.metamodel.model.domain.internal.BasicTypeImpl; import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; import org.hibernate.metamodel.model.domain.internal.EntityTypeImpl; import org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl; +import org.hibernate.metamodel.spi.DomainMetamodel; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; -import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder; import org.hibernate.type.descriptor.java.spi.JavaTypeDescriptorRegistry; import org.hibernate.type.spi.TypeConfiguration; @@ -67,9 +68,9 @@ import org.hibernate.type.spi.TypeConfiguration; public class MetadataContext { private static final EntityManagerMessageLogger LOG = HEMLogging.messageLogger( MetadataContext.class ); + private final JpaMetamodel jpaMetamodel; private final RuntimeModelCreationContext runtimeModelCreationContext; - private final SqmCriteriaNodeBuilder criteriaBuilder; private Set knownMappedSuperclasses; private TypeConfiguration typeConfiguration; private final JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting; @@ -91,17 +92,16 @@ public class MetadataContext { * Stack of PersistentClass being process. Last in the list is the highest in the stack. */ private List stackOfPersistentClassesBeingProcessed = new ArrayList<>(); - private InflightRuntimeMetamodel metamodel; + private DomainMetamodel metamodel; public MetadataContext( + JpaMetamodel jpaMetamodel, RuntimeModelCreationContext runtimeModelCreationContext, - InflightRuntimeMetamodel metamodel, - SqmCriteriaNodeBuilder criteriaBuilder, Set mappedSuperclasses, JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) { + this.jpaMetamodel = jpaMetamodel; this.runtimeModelCreationContext = runtimeModelCreationContext; - this.metamodel = metamodel; - this.criteriaBuilder = criteriaBuilder; + this.metamodel = runtimeModelCreationContext.getSessionFactory().getMetamodel(); this.knownMappedSuperclasses = mappedSuperclasses; this.typeConfiguration = runtimeModelCreationContext.getTypeConfiguration(); this.jpaStaticMetaModelPopulationSetting = jpaStaticMetaModelPopulationSetting; @@ -111,8 +111,8 @@ public class MetadataContext { return runtimeModelCreationContext; } - public SqmCriteriaNodeBuilder getCriteriaBuilder() { - return criteriaBuilder; + public JpaMetamodel getJpaMetamodel() { + return jpaMetamodel; } public TypeConfiguration getTypeConfiguration() { @@ -123,7 +123,7 @@ public class MetadataContext { return typeConfiguration.getJavaTypeDescriptorRegistry(); } - InflightRuntimeMetamodel getMetamodel() { + DomainMetamodel getMetamodel() { return metamodel; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/OptimizedPojoInstantiatorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/OptimizedPojoInstantiatorImpl.java new file mode 100644 index 0000000000..47e01d3a47 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/OptimizedPojoInstantiatorImpl.java @@ -0,0 +1,28 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import org.hibernate.bytecode.spi.ReflectionOptimizer; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; + +/** + * @author Steve Ebersole + */ +public class OptimizedPojoInstantiatorImpl extends AbstractPojoInstantiator { + private final ReflectionOptimizer.InstantiationOptimizer instantiationOptimizer; + + public OptimizedPojoInstantiatorImpl(JavaTypeDescriptor javaTypeDescriptor, ReflectionOptimizer reflectionOptimizer) { + super( javaTypeDescriptor.getJavaType() ); + this.instantiationOptimizer = reflectionOptimizer.getInstantiationOptimizer(); + } + + @Override + public Object instantiate(SharedSessionContractImplementor session) { + return instantiationOptimizer.newInstance(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PojoInstantiatorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PojoInstantiatorImpl.java new file mode 100644 index 0000000000..d19c6b7493 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PojoInstantiatorImpl.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import java.lang.reflect.Constructor; + +import org.hibernate.InstantiationException; +import org.hibernate.PropertyNotFoundException; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; + +/** + * @author Steve Ebersole + */ +public class PojoInstantiatorImpl extends AbstractPojoInstantiator { + private static final CoreMessageLogger LOG = CoreLogging.messageLogger( PojoInstantiatorImpl.class ); + + private final Constructor constructor; + + @SuppressWarnings("WeakerAccess") + public PojoInstantiatorImpl(JavaTypeDescriptor javaTypeDescriptor) { + super( javaTypeDescriptor.getJavaType() ); + + this.constructor = isAbstract() + ? null + : resolveConstructor( getMappedPojoClass() ); + } + + private static Constructor resolveConstructor(Class mappedPojoClass) { + try { + //noinspection unchecked + return ReflectHelper.getDefaultConstructor( mappedPojoClass); + } + catch ( PropertyNotFoundException e ) { + LOG.noDefaultConstructor( mappedPojoClass.getName() ); + } + + return null; + } + + + @Override + @SuppressWarnings("unchecked") + public J instantiate(SharedSessionContractImplementor session) { + if ( isAbstract() ) { + throw new InstantiationException( "Cannot instantiate abstract class or interface: ", getMappedPojoClass() ); + } + else if ( constructor == null ) { + throw new InstantiationException( "No default constructor for entity: ", getMappedPojoClass() ); + } + else { + try { + return (J) constructor.newInstance( (Object[]) null ); + } + catch ( Exception e ) { + throw new InstantiationException( "Could not instantiate entity: ", getMappedPojoClass(), e ); + } + } + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java deleted file mode 100644 index 990520e247..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.metamodel.internal; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import org.hibernate.boot.spi.BootstrapContext; -import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.cache.cfg.internal.DomainDataRegionConfigImpl; -import org.hibernate.cache.cfg.spi.DomainDataRegionConfig; -import org.hibernate.cache.spi.access.AccessType; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.mapping.Collection; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.RootClass; -import org.hibernate.metamodel.model.domain.JpaMetamodel; -import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; -import org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl; -import org.hibernate.metamodel.spi.DomainMetamodel; -import org.hibernate.metamodel.spi.RuntimeModelCreationContext; -import org.hibernate.persister.spi.PersisterFactory; -import org.hibernate.type.spi.TypeConfiguration; - -import static org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting.determineJpaMetaModelPopulationSetting; - -/** - * Responsible for interpreting the Hibernate boot metamodel into - * its runtime metamodel - * - * @author Steve Ebersole - * @see org.hibernate.boot.model - * @see org.hibernate.metamodel - */ -public class RuntimeModelCreationProcess { - - // todo (6.0) : look at removing reliance on SessionFactory here as well. Just pass in what we need. - // See RuntimeModelCreationContext. Ultimately we will need SessionFactory to create the persisters - // - // todo (6.0) : ^^ A running list of what we use from SessionFactory: - // - ServiceRegistry - // - Properties - // - Cache (to prime, so we could use a functional interface) - // - Database dropping support for auto-schema-tooling (again, could be functional interface - in fact if ultimately is in terms of how we do that) - // - Creation of named entity-graphs - // - Access to IdentifierGenerators, though we could manage this as part of the DomainMetamodel (and logically maybe that is where it belongs) - // - SessionFactoryOptions - // - BytecodeProvider - // - JpaCompliance - // - // Ultimately the idea here is to build the `InflightRuntimeMetamodel` and pass that along to - // the JpaMetamodel and DomainMetamodel. At a high-level; the details may be to instead - // build the `InflightRuntimeMetamodel` and use the collected information individually to - // each - e.g.: - // ```` - // new JpaMetamodel( - // inflightRuntimeMetamodel.getJpaEntityTypes(), - // inflightRuntimeMetamodel.getJpaEmbeddableTypes, - // ... - // ); - // ```` - // - // ^^ Possibly account for either, e.g.: - // ```` - // class JpaMetamodelImpl implements JpaMetamodel { - // static JpaMetamodelImpl create( - // InflightRuntimeMetamodel inflightRuntimeMetamodel, - // ... ) { - // return new JpaMetamodel( - // inflightRuntimeMetamodel.getJpaEntityTypes(), - // inflightRuntimeMetamodel.getJpaEmbeddableTypes, - // ... - // ); - // } - // } - // ```` - - - private final BootstrapContext bootstrapContext; - private final SessionFactoryImplementor sessionFactory; - private TypeConfiguration typeConfiguration; - - public RuntimeModelCreationProcess( - BootstrapContext bootstrapContext, - SessionFactoryImplementor sessionFactory, - TypeConfiguration typeConfiguration) { - this.bootstrapContext = bootstrapContext; - this.sessionFactory = sessionFactory; - this.typeConfiguration = typeConfiguration; - } - - /** - * Perform the runtime metamodel creation based on the information obtained during - * the first phase of booting, returning the - */ - public DomainMetamodel create(MetadataImplementor bootMetamodel) { - final RuntimeModelCreationContext runtimeModelCreationContext = new RuntimeModelCreationContext() { - @Override - public BootstrapContext getBootstrapContext() { - return bootstrapContext; - } - - @Override - public SessionFactoryImplementor getSessionFactory() { - return sessionFactory; - } - - @Override - public MetadataImplementor getMetadata() { - return bootMetamodel; - } - }; - - final InflightRuntimeMetamodel inflightRuntimeMetamodel = new InflightRuntimeMetamodel( typeConfiguration ); - - final PersisterFactory persisterFactory = sessionFactory.getServiceRegistry().getService( PersisterFactory.class ); - - primeSecondLevelCacheRegions( bootMetamodel ); - - final JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting = determineJpaMetaModelPopulationSetting( sessionFactory.getProperties() ); - - inflightRuntimeMetamodel.processBootMetaModel( - bootMetamodel, - sessionFactory.getCache(), - persisterFactory, - runtimeModelCreationContext - ); - - final JpaMetamodel jpaMetamodel = JpaMetamodelImpl.buildMetamodel( - runtimeModelCreationContext, - bootMetamodel, - inflightRuntimeMetamodel, - sessionFactory.getQueryEngine().getCriteriaBuilder(), - jpaStaticMetaModelPopulationSetting, - bootMetamodel.getNamedEntityGraphs().values() - ); - - return new DomainMetamodelImpl( - sessionFactory, - inflightRuntimeMetamodel, - jpaMetamodel - ); - } - - private void primeSecondLevelCacheRegions(MetadataImplementor mappingMetadata) { - final Map regionConfigBuilders = new ConcurrentHashMap<>(); - - // todo : ultimately this code can be made more efficient when we have a better intrinsic understanding of the hierarchy as a whole - - for ( PersistentClass bootEntityDescriptor : mappingMetadata.getEntityBindings() ) { - final AccessType accessType = AccessType.fromExternalName( bootEntityDescriptor.getCacheConcurrencyStrategy() ); - - if ( accessType != null ) { - if ( bootEntityDescriptor.isCached() ) { - regionConfigBuilders.computeIfAbsent( - bootEntityDescriptor.getRootClass().getCacheRegionName(), - DomainDataRegionConfigImpl.Builder::new - ) - .addEntityConfig( bootEntityDescriptor, accessType ); - } - - if ( bootEntityDescriptor instanceof RootClass - && bootEntityDescriptor.hasNaturalId() - && bootEntityDescriptor.getNaturalIdCacheRegionName() != null ) { - regionConfigBuilders.computeIfAbsent( - bootEntityDescriptor.getNaturalIdCacheRegionName(), - DomainDataRegionConfigImpl.Builder::new - ) - .addNaturalIdConfig( (RootClass) bootEntityDescriptor, accessType ); - } - } - } - - for ( Collection collection : mappingMetadata.getCollectionBindings() ) { - final AccessType accessType = AccessType.fromExternalName( collection.getCacheConcurrencyStrategy() ); - if ( accessType != null ) { - regionConfigBuilders.computeIfAbsent( - collection.getCacheRegionName(), - DomainDataRegionConfigImpl.Builder::new - ) - .addCollectionConfig( collection, accessType ); - } - } - - final Set regionConfigs; - if ( regionConfigBuilders.isEmpty() ) { - regionConfigs = Collections.emptySet(); - } - else { - regionConfigs = new HashSet<>(); - for ( DomainDataRegionConfigImpl.Builder builder : regionConfigBuilders.values() ) { - regionConfigs.add( builder.build() ); - } - } - - sessionFactory.getCache().prime( regionConfigs ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardManagedTypeRepresentationResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardManagedTypeRepresentationResolver.java new file mode 100644 index 0000000000..252a8462a6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardManagedTypeRepresentationResolver.java @@ -0,0 +1,86 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + + +import org.hibernate.mapping.Component; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.RepresentationMode; +import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy; +import org.hibernate.metamodel.spi.EntityRepresentationStrategy; +import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.persister.entity.EntityPersister; + +/** + * @author Steve Ebersole + */ +public class StandardManagedTypeRepresentationResolver implements ManagedTypeRepresentationResolver { + /** + * Singleton access + */ + public static final StandardManagedTypeRepresentationResolver INSTANCE = new StandardManagedTypeRepresentationResolver(); + + @Override + public EntityRepresentationStrategy resolveStrategy( + PersistentClass bootDescriptor, + EntityPersister runtimeDescriptor, + RuntimeModelCreationContext creationContext) { +// RepresentationMode representation = bootDescriptor.getExplicitRepresentationMode(); + RepresentationMode representation = null; + if ( representation == null ) { + if ( runtimeDescriptor.getMappedClass() == null ) { + representation = RepresentationMode.MAP; + } + else { + representation = RepresentationMode.POJO; + } + } + + if ( representation == RepresentationMode.MAP ) { + return new StandardMapEntityRepresentationStrategy( bootDescriptor, runtimeDescriptor, creationContext ); + } + else { + // todo (6.0) : fix this + // currently we end up resolving the ReflectionOptimizer from the BytecodeProvider + // multiple times per class + // + // instead, resolve ReflectionOptimizer once - here - and pass along to + // StandardPojoRepresentationStrategy + return new StandardPojoEntityRepresentationStrategy( bootDescriptor, runtimeDescriptor, creationContext ); + } + } + + @Override + public EmbeddableRepresentationStrategy resolveStrategy( + Component bootDescriptor, + RuntimeModelCreationContext creationContext) { +// RepresentationMode representation = bootDescriptor.getExplicitRepresentationMode(); + RepresentationMode representation = null; + if ( representation == null ) { + if ( bootDescriptor.getComponentClass() == null ) { + representation = RepresentationMode.MAP; + } + else { + representation = RepresentationMode.POJO; + } + } + + if ( representation == RepresentationMode.MAP ) { + return new StandardMapEmbeddableRepresentationStrategy( bootDescriptor, creationContext ); + } + else { + // todo (6.0) : fix this + // currently we end up resolving the ReflectionOptimizer from the BytecodeProvider + // multiple times per class + // + // instead, resolve ReflectionOptimizer once - here - and pass along to + // StandardPojoRepresentationStrategy + return new StandardPojoEmbeddableRepresentationStrategy( bootDescriptor, creationContext ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardMapEmbeddableRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardMapEmbeddableRepresentationStrategy.java new file mode 100644 index 0000000000..fdaa6b3043 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardMapEmbeddableRepresentationStrategy.java @@ -0,0 +1,48 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import org.hibernate.mapping.Component; +import org.hibernate.mapping.Property; +import org.hibernate.metamodel.RepresentationMode; +import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy; +import org.hibernate.metamodel.spi.Instantiator; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl; +import org.hibernate.property.access.spi.PropertyAccess; + +/** + * @author Steve Ebersole + */ +public class StandardMapEmbeddableRepresentationStrategy implements EmbeddableRepresentationStrategy { + private final DynamicMapInstantiator instantiator; + + public StandardMapEmbeddableRepresentationStrategy( + Component bootDescriptor, + RuntimeModelCreationContext creationContext) { + this.instantiator = new DynamicMapInstantiator( bootDescriptor ); + } + + @Override + public RepresentationMode getMode() { + return RepresentationMode.MAP; + } + + @Override + public PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor) { + return PropertyAccessStrategyMapImpl.INSTANCE.buildPropertyAccess( + null, + bootAttributeDescriptor.getName() + ); + } + + @Override + public Instantiator getInstantiator() { + //noinspection unchecked + return (Instantiator) instantiator; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardMapEntityRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardMapEntityRepresentationStrategy.java new file mode 100644 index 0000000000..76fb00afd2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardMapEntityRepresentationStrategy.java @@ -0,0 +1,59 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import org.hibernate.mapping.Component; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; +import org.hibernate.metamodel.RepresentationMode; +import org.hibernate.metamodel.spi.EntityRepresentationStrategy; +import org.hibernate.metamodel.spi.Instantiator; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl; +import org.hibernate.property.access.spi.PropertyAccess; +import org.hibernate.proxy.ProxyFactory; + +/** + * @author Steve Ebersole + */ +public class StandardMapEntityRepresentationStrategy implements EntityRepresentationStrategy { + private final ProxyFactory proxyFactory; + private final DynamicMapInstantiator instantiator; + + public StandardMapEntityRepresentationStrategy( + PersistentClass bootDescriptor, + EntityPersister runtimeDescriptor, + RuntimeModelCreationContext creationContext) { + this.proxyFactory = null; + this.instantiator = new DynamicMapInstantiator( bootDescriptor ); + } + + @Override + public RepresentationMode getMode() { + return RepresentationMode.MAP; + } + + @Override + public PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor) { + return PropertyAccessStrategyMapImpl.INSTANCE.buildPropertyAccess( + null, + bootAttributeDescriptor.getName() + ); + } + + @Override + public Instantiator getInstantiator() { + //noinspection unchecked + return (Instantiator) instantiator; + } + + @Override + public ProxyFactory getProxyFactory() { + return proxyFactory; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEmbeddableRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEmbeddableRepresentationStrategy.java new file mode 100644 index 0000000000..5d46925c66 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEmbeddableRepresentationStrategy.java @@ -0,0 +1,166 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import java.util.Locale; + +import org.hibernate.HibernateException; +import org.hibernate.boot.registry.selector.spi.StrategySelector; +import org.hibernate.bytecode.spi.ReflectionOptimizer; +import org.hibernate.cfg.Environment; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.mapping.Backref; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.IndexBackref; +import org.hibernate.mapping.Property; +import org.hibernate.metamodel.RepresentationMode; +import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy; +import org.hibernate.metamodel.spi.Instantiator; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl; +import org.hibernate.property.access.internal.PropertyAccessStrategyIndexBackRefImpl; +import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies; +import org.hibernate.property.access.spi.PropertyAccess; +import org.hibernate.property.access.spi.PropertyAccessStrategy; + +/** + * @author Steve Ebersole + */ +public class StandardPojoEmbeddableRepresentationStrategy + extends AbstractEmbeddableRepresentationStrategy + implements EmbeddableRepresentationStrategy { + private final StrategySelector strategySelector; + + private final Instantiator instantiator; + + public StandardPojoEmbeddableRepresentationStrategy( + Component bootDescriptor, + RuntimeModelCreationContext creationContext) { + super( + bootDescriptor, + creationContext.getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .resolveDescriptor( bootDescriptor.getComponentClass() ), + creationContext + ); + + assert bootDescriptor.getComponentClass() != null; + + this.strategySelector = creationContext.getSessionFactory() + .getServiceRegistry() + .getService( StrategySelector.class ); + + final ReflectionOptimizer reflectionOptimizer = buildReflectionOptimizer( bootDescriptor, creationContext ); + + if ( reflectionOptimizer != null && reflectionOptimizer.getInstantiationOptimizer() != null ) { + this.instantiator = new OptimizedPojoInstantiatorImpl<>( getEmbeddableJavaTypeDescriptor(), reflectionOptimizer ); + } + else { + this.instantiator = new PojoInstantiatorImpl<>( getEmbeddableJavaTypeDescriptor() ); + } + } + + @Override + protected PropertyAccess buildPropertyAccess(Property bootAttributeDescriptor) { + PropertyAccessStrategy strategy = null; + final String propertyAccessorName = bootAttributeDescriptor.getPropertyAccessorName(); + final BuiltInPropertyAccessStrategies namedStrategy = BuiltInPropertyAccessStrategies.interpret( + propertyAccessorName ); + if ( namedStrategy != null ) { + strategy = namedStrategy.getStrategy(); + } + + if ( strategy == null ) { + + if ( StringHelper.isNotEmpty( propertyAccessorName ) ) { + + // handle explicitly specified attribute accessor + strategy = strategySelector.resolveStrategy( + PropertyAccessStrategy.class, + propertyAccessorName + ); + } + else { + if ( bootAttributeDescriptor instanceof Backref ) { + final Backref backref = (Backref) bootAttributeDescriptor; + strategy = new PropertyAccessStrategyBackRefImpl( backref.getCollectionRole(), backref + .getEntityName() ); + } + else if ( bootAttributeDescriptor instanceof IndexBackref ) { + final IndexBackref indexBackref = (IndexBackref) bootAttributeDescriptor; + strategy = new PropertyAccessStrategyIndexBackRefImpl( + indexBackref.getCollectionRole(), + indexBackref.getEntityName() + ); + } + else { + // for now... + strategy = BuiltInPropertyAccessStrategies.MIXED.getStrategy(); + } + } + } + + if ( strategy == null ) { + throw new HibernateException( + String.format( + Locale.ROOT, + "Could not resolve PropertyAccess for attribute `%s#%s`", + getEmbeddableJavaTypeDescriptor().getJavaType().getName(), + bootAttributeDescriptor.getName() + ) + ); + } + + return strategy.buildPropertyAccess( + getEmbeddableJavaTypeDescriptor().getJavaType(), + bootAttributeDescriptor.getName() + ); + } + + private ReflectionOptimizer buildReflectionOptimizer( + Component bootDescriptor, + RuntimeModelCreationContext creationContext) { + + if ( !Environment.useReflectionOptimizer() ) { + return null; + } + + if ( hasCustomAccessors() ) { + return null; + } + + final String[] getterNames = new String[getPropertySpan()]; + final String[] setterNames = new String[getPropertySpan()]; + final Class[] propTypes = new Class[getPropertySpan()]; + + for ( int i = 0; i < getPropertyAccesses().length; i++ ) { + final PropertyAccess propertyAccess = getPropertyAccesses()[i]; + + getterNames[i] = propertyAccess.getGetter().getMethodName(); + setterNames[i] = propertyAccess.getSetter().getMethodName(); + propTypes[i] = propertyAccess.getGetter().getReturnType(); + } + + return Environment.getBytecodeProvider().getReflectionOptimizer( + bootDescriptor.getComponentClass(), + getterNames, + setterNames, + propTypes + ); + } + + @Override + public RepresentationMode getMode() { + return RepresentationMode.POJO; + } + + @Override + public Instantiator getInstantiator() { + //noinspection unchecked + return instantiator; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEntityRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEntityRepresentationStrategy.java new file mode 100644 index 0000000000..56bde789e9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEntityRepresentationStrategy.java @@ -0,0 +1,119 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.internal; + +import java.util.Locale; + +import org.hibernate.HibernateException; +import org.hibernate.boot.registry.selector.spi.StrategySelector; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.mapping.Backref; +import org.hibernate.mapping.IndexBackref; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; +import org.hibernate.metamodel.RepresentationMode; +import org.hibernate.metamodel.spi.EntityRepresentationStrategy; +import org.hibernate.metamodel.spi.Instantiator; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl; +import org.hibernate.property.access.internal.PropertyAccessStrategyIndexBackRefImpl; +import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies; +import org.hibernate.property.access.spi.PropertyAccess; +import org.hibernate.property.access.spi.PropertyAccessStrategy; +import org.hibernate.proxy.ProxyFactory; + +/** + * @author Steve Ebersole + */ +public class StandardPojoEntityRepresentationStrategy implements EntityRepresentationStrategy { + private final EntityPersister runtimeDescriptor; + private final StrategySelector strategySelector; + + private final ProxyFactory proxyFactory; + private final Instantiator instantiator; + + public StandardPojoEntityRepresentationStrategy( + PersistentClass bootDescriptor, + EntityPersister runtimeDescriptor, + RuntimeModelCreationContext creationContext) { + this.runtimeDescriptor = runtimeDescriptor; + + this.strategySelector = creationContext.getSessionFactory() + .getServiceRegistry() + .getService( StrategySelector.class ); + + this.proxyFactory = null; + this.instantiator = null; + } + + @Override + public RepresentationMode getMode() { + return RepresentationMode.POJO; + } + + @Override + public Instantiator getInstantiator() { + //noinspection unchecked + return instantiator; + } + + @Override + public ProxyFactory getProxyFactory() { + return proxyFactory; + } + + @Override + public PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor) { + PropertyAccessStrategy strategy = null; + + final String propertyAccessorName = bootAttributeDescriptor.getPropertyAccessorName(); + final BuiltInPropertyAccessStrategies namedStrategy = BuiltInPropertyAccessStrategies.interpret( propertyAccessorName ); + + if ( namedStrategy != null ) { + strategy = namedStrategy.getStrategy(); + } + + if ( strategy == null ) { + if ( StringHelper.isNotEmpty( propertyAccessorName ) ) { + // handle explicitly specified attribute accessor + strategy = strategySelector.resolveStrategy( PropertyAccessStrategy.class, propertyAccessorName ); + } + else { + if ( bootAttributeDescriptor instanceof Backref ) { + final Backref backref = (Backref) bootAttributeDescriptor; + strategy = new PropertyAccessStrategyBackRefImpl( backref.getCollectionRole(), backref + .getEntityName() ); + } + else if ( bootAttributeDescriptor instanceof IndexBackref ) { + final IndexBackref indexBackref = (IndexBackref) bootAttributeDescriptor; + strategy = new PropertyAccessStrategyIndexBackRefImpl( + indexBackref.getCollectionRole(), + indexBackref.getEntityName() + ); + } + else { + // for now... + strategy = BuiltInPropertyAccessStrategies.MIXED.getStrategy(); + } + } + } + + if ( strategy == null ) { + throw new HibernateException( + String.format( + Locale.ROOT, + "Could not resolve PropertyAccess for attribute `%s#%s`", + runtimeDescriptor.getMappedClass().getName(), + bootAttributeDescriptor.getName() + ) + ); + } + + return strategy.buildPropertyAccess( runtimeDescriptor.getMappedClass(), bootAttributeDescriptor.getName() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractManagedType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractManagedType.java index de096d6eb7..00445c5801 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractManagedType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractManagedType.java @@ -603,15 +603,16 @@ public abstract class AbstractManagedType @SuppressWarnings("unchecked") public void addAttribute(PersistentAttribute attribute) { if ( attribute instanceof SingularPersistentAttribute ) { - declaredSingularAttributes.put( attribute.getName(), (SingularPersistentAttribute) attribute ); + declaredSingularAttributes.put( attribute.getName(), (SingularPersistentAttribute) attribute ); } else if ( attribute instanceof PluralPersistentAttribute ) { - declaredPluralAttributes.put(attribute.getName(), (PluralPersistentAttribute) attribute ); + declaredPluralAttributes.put(attribute.getName(), (PluralPersistentAttribute) attribute ); + } + else { + throw new IllegalArgumentException( + "Unable to classify attribute as singular or plural [" + attribute + "] for `" + this + '`' + ); } - - throw new IllegalArgumentException( - "Unable to classify attribute as singular or plural [" + attribute + "] for `" + this + '`' - ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java index 6555aaa2dc..fe4ac12535 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java @@ -19,7 +19,6 @@ import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.query.NavigablePath; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.produce.spi.SqmCreationState; import org.hibernate.query.sqm.tree.domain.SqmPath; @@ -42,9 +41,8 @@ public abstract class AbstractPluralAttribute AbstractManagedType ownerType, SimpleDomainType attrType, JavaTypeDescriptor collectionClass, - SimpleDomainType listIndexOrMapKeyType, - NodeBuilder nodeBuilder) { - return new PluralAttributeBuilder<>( ownerType, attrType, collectionClass, listIndexOrMapKeyType, nodeBuilder ); + SimpleDomainType listIndexOrMapKeyType) { + return new PluralAttributeBuilder<>( ownerType, attrType, collectionClass, listIndexOrMapKeyType ); } private final CollectionClassification classification; @@ -67,8 +65,7 @@ public abstract class AbstractPluralAttribute interpretValueClassification( builder.getValueType() ), getName(), builder.getValueType(), - BindableType.PLURAL_ATTRIBUTE, - builder.getNodeBuilder() + BindableType.PLURAL_ATTRIBUTE ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java index 5c36df24ef..cc48e0d43d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java @@ -7,7 +7,6 @@ package org.hibernate.metamodel.model.domain.internal; import org.hibernate.metamodel.model.domain.DomainType; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -18,21 +17,14 @@ public abstract class AbstractSqmPathSource implements SqmPathSource { private final String localPathName; private final DomainType domainType; private final BindableType jpaBindableType; - private final NodeBuilder nodeBuilder; public AbstractSqmPathSource( String localPathName, DomainType domainType, - BindableType jpaBindableType, - NodeBuilder nodeBuilder) { + BindableType jpaBindableType) { this.localPathName = localPathName; this.domainType = domainType; this.jpaBindableType = jpaBindableType; - this.nodeBuilder = nodeBuilder; - } - - protected NodeBuilder getNodeBuilder() { - return nodeBuilder; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java index 2038c6a1cb..cc51717814 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java @@ -21,9 +21,8 @@ public class AnyMappingSqmPathSource extends AbstractSqmPathSource { public AnyMappingSqmPathSource( String localPathName, AnyMappingDomainType domainType, - BindableType jpaBindableType, - NodeBuilder nodeBuilder) { - super( localPathName, domainType, jpaBindableType, nodeBuilder ); + BindableType jpaBindableType) { + super( localPathName, domainType, jpaBindableType ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java index e435fbe5b9..caaeb4a376 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java @@ -9,7 +9,6 @@ package org.hibernate.metamodel.model.domain.internal; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.IllegalPathUsageException; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.produce.spi.SqmCreationState; import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath; @@ -23,9 +22,8 @@ public class BasicSqmPathSource extends AbstractSqmPathSource { public BasicSqmPathSource( String localPathName, BasicDomainType domainType, - BindableType jpaBindableType, - NodeBuilder nodeBuilder) { - super( localPathName, domainType, jpaBindableType, nodeBuilder ); + BindableType jpaBindableType) { + super( localPathName, domainType, jpaBindableType ); } @Override @@ -46,7 +44,7 @@ public class BasicSqmPathSource extends AbstractSqmPathSource { navigablePath, this, lhs, - getNodeBuilder() + creationState.getCreationContext().getNodeBuilder() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java index 3449567887..d58e464ca3 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java @@ -9,7 +9,9 @@ package org.hibernate.metamodel.model.domain.internal; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -20,18 +22,27 @@ import javax.persistence.metamodel.EntityType; import javax.persistence.metamodel.ManagedType; import org.hibernate.EntityNameResolver; +import org.hibernate.HibernateException; import org.hibernate.MappingException; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.UnknownEntityTypeException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; +import org.hibernate.boot.spi.BootstrapContext; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cache.spi.CacheImplementor; +import org.hibernate.cache.spi.access.CollectionDataAccess; +import org.hibernate.cache.spi.access.EntityDataAccess; +import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.graph.RootGraph; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.internal.EntityManagerMessageLogger; import org.hibernate.internal.HEMLogging; import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.metamodel.internal.InflightRuntimeMetamodel; +import org.hibernate.mapping.Collection; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; @@ -39,11 +50,17 @@ import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.metamodel.spi.DomainMetamodel; import org.hibernate.metamodel.spi.MetamodelImplementor; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Queryable; +import org.hibernate.persister.spi.PersisterFactory; +import org.hibernate.tuple.entity.EntityTuplizer; +import org.hibernate.type.Type; import org.hibernate.type.spi.TypeConfiguration; +import static org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting.determineJpaMetaModelPopulationSetting; + /** * Hibernate implementation of the JPA {@link javax.persistence.metamodel.Metamodel} contract. * @@ -65,23 +82,21 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento private final JpaMetamodel jpaMetamodel; - private final Map entityProxyInterfaceMap; + private final Map entityProxyInterfaceMap = new ConcurrentHashMap<>(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // RuntimeModel - private final Map entityPersisterMap; - private final Map collectionPersisterMap; - private final Map> collectionRolesByEntityParticipant; + private final Map entityPersisterMap = new ConcurrentHashMap<>(); + private final Map collectionPersisterMap = new ConcurrentHashMap<>(); + private final Map> collectionRolesByEntityParticipant = new ConcurrentHashMap<>(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // DomainMetamodel - private final Set entityNameResolvers; - - private final Map imports; + private final Set entityNameResolvers = new HashSet<>(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -120,19 +135,186 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento private final Map implementorsCache = new ConcurrentHashMap<>(); - public DomainMetamodelImpl( - SessionFactoryImplementor sessionFactory, - InflightRuntimeMetamodel runtimeMetamodel, - JpaMetamodel jpaMetamodel) { + public DomainMetamodelImpl(SessionFactoryImplementor sessionFactory, TypeConfiguration typeConfiguration) { this.sessionFactory = sessionFactory; - this.jpaMetamodel = jpaMetamodel; - this.typeConfiguration = runtimeMetamodel.getTypeConfiguration(); - this.entityPersisterMap = runtimeMetamodel.getEntityPersisterMap(); - this.collectionPersisterMap = runtimeMetamodel.getCollectionPersisterMap(); - this.collectionRolesByEntityParticipant = runtimeMetamodel.getCollectionRolesByEntityParticipant(); - this.entityNameResolvers = runtimeMetamodel.getEntityNameResolvers(); - this.entityProxyInterfaceMap = runtimeMetamodel.getEntityProxyInterfaceMap(); - this.imports = runtimeMetamodel.getImports(); + this.typeConfiguration = typeConfiguration; + this.jpaMetamodel = new JpaMetamodelImpl( typeConfiguration ); + } + + public void finishInitialization( + MetadataImplementor bootModel, + BootstrapContext bootstrapContext, + SessionFactoryImplementor sessionFactory) { + + final RuntimeModelCreationContext runtimeModelCreationContext = new RuntimeModelCreationContext() { + @Override + public BootstrapContext getBootstrapContext() { + return bootstrapContext; + } + + @Override + public SessionFactoryImplementor getSessionFactory() { + return sessionFactory; + } + + @Override + public MetadataImplementor getMetadata() { + return bootModel; + } + }; + + final PersisterFactory persisterFactory = sessionFactory.getServiceRegistry().getService( PersisterFactory.class ); + + final JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting = determineJpaMetaModelPopulationSetting( sessionFactory.getProperties() ); + + processBootEntities( + bootModel.getEntityBindings(), + sessionFactory.getCache(), + persisterFactory, + runtimeModelCreationContext + ); + + processBootCollections( + bootModel.getCollectionBindings(), + sessionFactory.getCache(), + persisterFactory, + runtimeModelCreationContext + ); + + // after *all* persisters and named queries are registered + entityPersisterMap.values().forEach( EntityPersister::generateEntityDefinition ); + + for ( EntityPersister persister : entityPersisterMap.values() ) { + persister.postInstantiate(); + registerEntityNameResolvers( persister, entityNameResolvers ); + } + + collectionPersisterMap.values().forEach( CollectionPersister::postInstantiate ); + + + ( (JpaMetamodelImpl) this.jpaMetamodel ).processJpa( + bootModel, + entityProxyInterfaceMap, + jpaStaticMetaModelPopulationSetting, + bootModel.getNamedEntityGraphs().values(), + runtimeModelCreationContext + ); + } + + private void processBootEntities( + java.util.Collection entityBindings, + CacheImplementor cacheImplementor, + PersisterFactory persisterFactory, + RuntimeModelCreationContext modelCreationContext) { + for ( final PersistentClass model : entityBindings ) { + final NavigableRole rootEntityRole = new NavigableRole( model.getRootClass().getEntityName() ); + final EntityDataAccess accessStrategy = cacheImplementor.getEntityRegionAccess( rootEntityRole ); + final NaturalIdDataAccess naturalIdAccessStrategy = cacheImplementor + .getNaturalIdCacheRegionAccessStrategy( rootEntityRole ); + + final EntityPersister cp = persisterFactory.createEntityPersister( + model, + accessStrategy, + naturalIdAccessStrategy, + modelCreationContext + ); + entityPersisterMap.put( model.getEntityName(), cp ); + + if ( cp.getConcreteProxyClass() != null + && cp.getConcreteProxyClass().isInterface() + && !Map.class.isAssignableFrom( cp.getConcreteProxyClass() ) + && cp.getMappedClass() != cp.getConcreteProxyClass() ) { + // IMPL NOTE : we exclude Map based proxy interfaces here because that should + // indicate MAP entity mode.0 + + if ( cp.getMappedClass().equals( cp.getConcreteProxyClass() ) ) { + // this part handles an odd case in the Hibernate test suite where we map an interface + // as the class and the proxy. I cannot think of a real life use case for that + // specific test, but.. + log.debugf( + "Entity [%s] mapped same interface [%s] as class and proxy", + cp.getEntityName(), + cp.getMappedClass() + ); + } + else { + final String old = entityProxyInterfaceMap.put( cp.getConcreteProxyClass(), cp.getEntityName() ); + if ( old != null ) { + throw new HibernateException( + String.format( + Locale.ENGLISH, + "Multiple entities [%s, %s] named the same interface [%s] as their proxy which is not supported", + old, + cp.getEntityName(), + cp.getConcreteProxyClass().getName() + ) + ); + } + } + } + } + } + + private void processBootCollections( + java.util.Collection collectionBindings, + CacheImplementor cacheImplementor, + PersisterFactory persisterFactory, + RuntimeModelCreationContext modelCreationContext) { + for ( final Collection model : collectionBindings ) { + final NavigableRole navigableRole = new NavigableRole( model.getRole() ); + + final CollectionDataAccess accessStrategy = cacheImplementor.getCollectionRegionAccess( + navigableRole ); + + final CollectionPersister persister = persisterFactory.createCollectionPersister( + model, + accessStrategy, + modelCreationContext + ); + collectionPersisterMap.put( model.getRole(), persister ); + Type indexType = persister.getIndexType(); + if ( indexType != null && indexType.isEntityType() && !indexType.isAnyType() ) { + String entityName = ( (org.hibernate.type.EntityType) indexType ).getAssociatedEntityName(); + Set roles = collectionRolesByEntityParticipant.get( entityName ); + if ( roles == null ) { + roles = new HashSet<>(); + collectionRolesByEntityParticipant.put( entityName, roles ); + } + roles.add( persister.getRole() ); + } + Type elementType = persister.getElementType(); + if ( elementType.isEntityType() && !elementType.isAnyType() ) { + String entityName = ( (org.hibernate.type.EntityType) elementType ).getAssociatedEntityName(); + Set roles = collectionRolesByEntityParticipant.get( entityName ); + if ( roles == null ) { + roles = new HashSet<>(); + collectionRolesByEntityParticipant.put( entityName, roles ); + } + roles.add( persister.getRole() ); + } + } + } + + private static void registerEntityNameResolvers( + EntityPersister persister, + Set entityNameResolvers) { + if ( persister.getEntityMetamodel() == null || persister.getEntityMetamodel().getTuplizer() == null ) { + return; + } + registerEntityNameResolvers( persister.getEntityMetamodel().getTuplizer(), entityNameResolvers ); + } + + private static void registerEntityNameResolvers( + EntityTuplizer tuplizer, + Set entityNameResolvers) { + EntityNameResolver[] resolvers = tuplizer.getEntityNameResolvers(); + if ( resolvers == null ) { + return; + } + + for ( EntityNameResolver resolver : resolvers ) { + entityNameResolvers.add( resolver ); + } } @Override @@ -270,24 +452,7 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento @Override public String getImportedClassName(String className) { - String result = imports.get( className ); - if ( result == null ) { - try { - sessionFactory.getServiceRegistry().getService( ClassLoaderService.class ).classForName( className ); - imports.put( className, className ); - return className; - } - catch ( ClassLoadingException cnfe ) { - imports.put( className, INVALID_IMPORT ); - return null; - } - } - else if ( result == INVALID_IMPORT ) { - return null; - } - else { - return result; - } + throw new UnsupportedOperationException( ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java index 8025c438ea..85778599d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java @@ -19,7 +19,6 @@ import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmPathSource; /** @@ -84,39 +83,34 @@ public class DomainModelHelper { ValueClassification classification, String name, DomainType valueDomainType, - Bindable.BindableType jpaBindableType, - NodeBuilder nodeBuilder) { + Bindable.BindableType jpaBindableType) { switch ( classification ) { case BASIC: { return new BasicSqmPathSource<>( name, (BasicDomainType) valueDomainType, - jpaBindableType, - nodeBuilder + jpaBindableType ); } case ANY: { return new AnyMappingSqmPathSource<>( name, (AnyMappingDomainType) valueDomainType, - jpaBindableType, - nodeBuilder + jpaBindableType ); } case EMBEDDED: { return new EmbeddedSqmPathSource<>( name, (EmbeddableDomainType) valueDomainType, - jpaBindableType, - nodeBuilder + jpaBindableType ); } case ENTITY: { return new EntitySqmPathSource<>( name, (EntityDomainType) valueDomainType, - jpaBindableType, - nodeBuilder + jpaBindableType ); } default: { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java index ee0703720d..938c2ad8d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java @@ -6,17 +6,11 @@ */ package org.hibernate.metamodel.model.domain.internal; -import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; -import org.hibernate.query.NavigablePath; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.produce.spi.SqmCreationState; -import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.domain.SqmAnyValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmPath; -import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; -import org.hibernate.query.sqm.tree.from.SqmFrom; /** * @author Steve Ebersole @@ -25,9 +19,8 @@ public class EmbeddedSqmPathSource extends AbstractSqmPathSource { public EmbeddedSqmPathSource( String localPathName, EmbeddableDomainType domainType, - BindableType jpaBindableType, - NodeBuilder nodeBuilder) { - super( localPathName, domainType, jpaBindableType, nodeBuilder ); + BindableType jpaBindableType) { + super( localPathName, domainType, jpaBindableType ); } @Override @@ -47,7 +40,7 @@ public class EmbeddedSqmPathSource extends AbstractSqmPathSource { lhs.getNavigablePath().append( getPathName() ), this, lhs, - getNodeBuilder() + creationState.getCreationContext().getNodeBuilder() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java index 9a6862134c..672ca3b774 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java @@ -20,9 +20,8 @@ public class EntitySqmPathSource extends AbstractSqmPathSource { public EntitySqmPathSource( String localPathName, EntityDomainType domainType, - BindableType jpaBindableType, - NodeBuilder nodeBuilder) { - super( localPathName, domainType, jpaBindableType, nodeBuilder ); + BindableType jpaBindableType) { + super( localPathName, domainType, jpaBindableType ); } @Override @@ -42,7 +41,7 @@ public class EntitySqmPathSource extends AbstractSqmPathSource { lhs.getNavigablePath().append( getPathName() ), this, lhs, - getNodeBuilder() + creationState.getCreationContext().getNodeBuilder() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java index 5ccf58c8f0..00b1ab618f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java @@ -7,6 +7,7 @@ package org.hibernate.metamodel.model.domain.internal; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -47,7 +48,6 @@ import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; -import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder; import org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; @@ -69,16 +69,13 @@ public class JpaMetamodelImpl implements JpaMetamodel { private final Map> polymorphicEntityReferenceMap = new ConcurrentHashMap<>(); - private final Map entityProxyInterfaceMap; + private final Map entityProxyInterfaceMap = new ConcurrentHashMap<>(); - private final Map nameToImportNameMap; + private final Map nameToImportNameMap = new ConcurrentHashMap<>(); - public JpaMetamodelImpl(InflightRuntimeMetamodel runtimeMetamodel) { - this.typeConfiguration = runtimeMetamodel.getTypeConfiguration(); - - nameToImportNameMap = runtimeMetamodel.getNameToImportNameMap(); - entityProxyInterfaceMap = runtimeMetamodel.getEntityProxyInterfaceMap(); + public JpaMetamodelImpl(TypeConfiguration typeConfiguration) { + this.typeConfiguration = typeConfiguration; } @Override @@ -94,6 +91,7 @@ public class JpaMetamodelImpl implements JpaMetamodel { @Override public EntityDomainType resolveHqlEntityReference(String entityName) { + // todo (6.0) : currently we lookup the Class reference here twice potentially - fix that final String rename = resolveImportedName( entityName ); if ( rename != null ) { entityName = rename; @@ -442,35 +440,36 @@ public class JpaMetamodelImpl implements JpaMetamodel { RuntimeModelCreationContext runtimeModelCreationContext, MetadataImplementor bootMetamodel, InflightRuntimeMetamodel inflightRuntimeMetamodel, - SqmCriteriaNodeBuilder criteriaBuilder, JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting, java.util.Collection namedEntityGraphDefinitions) { - final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl( inflightRuntimeMetamodel ); + final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl( inflightRuntimeMetamodel.getTypeConfiguration() ); jpaMetamodel.processJpa( - runtimeModelCreationContext, bootMetamodel, - inflightRuntimeMetamodel, - criteriaBuilder, + inflightRuntimeMetamodel.getEntityProxyInterfaceMap(), jpaStaticMetaModelPopulationSetting, - namedEntityGraphDefinitions + namedEntityGraphDefinitions, + runtimeModelCreationContext ); return jpaMetamodel; } - private void processJpa( - RuntimeModelCreationContext runtimeModelCreationContext, + public void processJpa( MetadataImplementor bootMetamodel, - InflightRuntimeMetamodel inflightRuntimeMetamodel, - SqmCriteriaNodeBuilder criteriaBuilder, + Map entityProxyInterfaceMap, JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting, - java.util.Collection namedEntityGraphDefinitions) { + Collection namedEntityGraphDefinitions, + RuntimeModelCreationContext runtimeModelCreationContext) { + this.nameToImportNameMap.putAll( bootMetamodel.getImports() ); + this.entityProxyInterfaceMap.putAll( entityProxyInterfaceMap); + + // todo (6.0) : I believe there should be a distinction here between building the JPA metamodel and pushing that metamodel to the `X_` model + // - JpaStaticMetaModelPopulationSetting is meant to control the latter part - populating the `X_` model if ( jpaStaticMetaModelPopulationSetting != JpaStaticMetaModelPopulationSetting.DISABLED ) { MetadataContext context = new MetadataContext( + this, runtimeModelCreationContext, - inflightRuntimeMetamodel, - criteriaBuilder, bootMetamodel.getMappedSuperclassMappingsCopy(), jpaStaticMetaModelPopulationSetting ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java index 7fd5fa8438..5461cfb2a7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java @@ -31,8 +31,7 @@ class ListAttributeImpl extends AbstractPluralAttribute, E> imp ValueClassification.BASIC, getName(), builder.getListIndexOrMapKeyType(), - BindableType.PLURAL_ATTRIBUTE, - builder.getNodeBuilder() + BindableType.PLURAL_ATTRIBUTE ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java index 4c0169c82c..693f04b0d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java @@ -28,13 +28,11 @@ class MapAttributeImpl extends AbstractPluralAttribute, V> MapAttributeImpl(PluralAttributeBuilder, V, K> xceBuilder) { super( xceBuilder ); - //noinspection unchecked - this.keyPathSource = (SqmPathSource) DomainModelHelper.resolveSqmPathSource( + this.keyPathSource = DomainModelHelper.resolveSqmPathSource( ValueClassification.BASIC, getName(), xceBuilder.getListIndexOrMapKeyType(), - BindableType.PLURAL_ATTRIBUTE, - xceBuilder.getNodeBuilder() + BindableType.PLURAL_ATTRIBUTE ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java index 9142788ff3..b0f1cd3154 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java @@ -17,7 +17,6 @@ import org.hibernate.metamodel.AttributeClassification; import org.hibernate.metamodel.CollectionClassification; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.SimpleDomainType; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** @@ -27,8 +26,6 @@ public class PluralAttributeBuilder { private final ManagedDomainType declaringType; private final SimpleDomainType valueType; - private final NodeBuilder nodeBuilder; - private SimpleDomainType listIndexOrMapKeyType; private AttributeClassification attributeClassification; @@ -42,17 +39,11 @@ public class PluralAttributeBuilder { ManagedDomainType ownerType, SimpleDomainType elementType, JavaTypeDescriptor collectionJavaTypeDescriptor, - SimpleDomainType listIndexOrMapKeyType, - NodeBuilder nodeBuilder) { + SimpleDomainType listIndexOrMapKeyType) { this.declaringType = ownerType; this.valueType = elementType; this.collectionJavaTypeDescriptor = collectionJavaTypeDescriptor; this.listIndexOrMapKeyType = listIndexOrMapKeyType; - this.nodeBuilder = nodeBuilder; - } - - public NodeBuilder getNodeBuilder() { - return nodeBuilder; } public ManagedDomainType getDeclaringType() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java index 06823f6a32..d475827cb0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java @@ -16,7 +16,6 @@ import org.hibernate.metamodel.ValueClassification; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.produce.spi.SqmCreationState; import org.hibernate.query.sqm.tree.SqmJoinType; @@ -50,8 +49,7 @@ public class SingularAttributeImpl Member member, boolean isIdentifier, boolean isVersion, - boolean isOptional, - NodeBuilder nodeBuilder) { + boolean isOptional) { super( declaringType, name, attributeType.getExpressableJavaTypeDescriptor(), attributeClassification, attributeType, member ); this.isIdentifier = isIdentifier; this.isVersion = isVersion; @@ -62,8 +60,7 @@ public class SingularAttributeImpl determineValueClassification( attributeClassification ), name, attributeType, - BindableType.SINGULAR_ATTRIBUTE, - nodeBuilder + BindableType.SINGULAR_ATTRIBUTE ); } @@ -158,8 +155,7 @@ public class SingularAttributeImpl String name, SimpleDomainType attributeType, Member member, - AttributeClassification attributeClassification, - NodeBuilder nodeBuilder) { + AttributeClassification attributeClassification) { super( declaringType, name, @@ -168,8 +164,7 @@ public class SingularAttributeImpl member, true, false, - false, - nodeBuilder + false ); } } @@ -184,8 +179,7 @@ public class SingularAttributeImpl String name, AttributeClassification attributeClassification, SimpleDomainType attributeType, - Member member, - NodeBuilder nodeBuilder) { + Member member) { super( declaringType, name, @@ -194,8 +188,7 @@ public class SingularAttributeImpl member, false, true, - false, - nodeBuilder + false ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EmbeddableRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EmbeddableRepresentationStrategy.java new file mode 100644 index 0000000000..27aed39c18 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EmbeddableRepresentationStrategy.java @@ -0,0 +1,17 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.spi; + +/** + * @author Steve Ebersole + */ +public interface EmbeddableRepresentationStrategy extends ManagedTypeRepresentationStrategy { + /** + * Create a delegate capable of instantiating instances of the represented type. + */ + Instantiator getInstantiator(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EntityRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EntityRepresentationStrategy.java index 6f1a282960..e93b7f3289 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EntityRepresentationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EntityRepresentationStrategy.java @@ -9,14 +9,19 @@ package org.hibernate.metamodel.spi; import org.hibernate.proxy.ProxyFactory; /** - * Specialization of ManagedTypeRepresentationStrategy for entity types - * adding the ability to generate a proxy factory + * Specialization of ManagedTypeRepresentationStrategy for an entity type + * adding the ability to generate an instantiator and a proxy factory * * @author Steve Ebersole */ public interface EntityRepresentationStrategy extends ManagedTypeRepresentationStrategy { + /** + * Create a delegate capable of instantiating instances of the represented type. + */ + Instantiator getInstantiator(); + /** * Create the delegate capable of producing proxies for the given entity */ - ProxyFactory generateProxyFactory(); + ProxyFactory getProxyFactory(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ManagedTypeRepresentationResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ManagedTypeRepresentationResolver.java index f95169d5a3..8fc6ddb176 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ManagedTypeRepresentationResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ManagedTypeRepresentationResolver.java @@ -25,7 +25,7 @@ public interface ManagedTypeRepresentationResolver { /** * Resolve the strategy to use for the given entity */ - ManagedTypeRepresentationStrategy resolveStrategy( + EntityRepresentationStrategy resolveStrategy( PersistentClass bootDescriptor, EntityPersister runtimeDescriptor, RuntimeModelCreationContext creationContext); @@ -33,7 +33,7 @@ public interface ManagedTypeRepresentationResolver { /** * Resolve the strategy to use for the given embeddable */ - ManagedTypeRepresentationStrategy resolveStrategy( + EmbeddableRepresentationStrategy resolveStrategy( Component bootDescriptor, RuntimeModelCreationContext creationContext); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ManagedTypeRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ManagedTypeRepresentationStrategy.java index 8ea4f31eee..73a1395326 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ManagedTypeRepresentationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ManagedTypeRepresentationStrategy.java @@ -28,13 +28,8 @@ import org.hibernate.property.access.spi.PropertyAccess; public interface ManagedTypeRepresentationStrategy { RepresentationMode getMode(); - /** - * Create a delegate capable of instantiating instances of the represented type. - */ - Instantiator generateInstantiator(); - /** * Create the property accessor object for the specified attribute */ - PropertyAccess generatePropertyAccess(Property bootAttributeDescriptor); + PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 506f7d0550..5351bacff8 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -801,7 +801,11 @@ public abstract class AbstractCollectionPersister // return hasOrdering() // ? orderByTranslation.injectAliases( new StandardOrderByAliasResolver( alias ) ) // : ""; - throw new NotYetImplementedFor6Exception( getClass() ); + if ( hasOrdering() ) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + return ""; } @Override @@ -809,7 +813,11 @@ public abstract class AbstractCollectionPersister // return hasManyToManyOrdering() // ? manyToManyOrderByTranslation.injectAliases( new StandardOrderByAliasResolver( alias ) ) // : ""; - throw new NotYetImplementedFor6Exception( getClass() ); + if ( hasManyToManyOrdering() ) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + return ""; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java index ca92419c54..f8892455a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java @@ -33,7 +33,7 @@ import org.hibernate.loader.spi.Loadable; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.persister.walking.spi.EntityDefinition; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.type.Type; @@ -134,7 +134,7 @@ public interface EntityPersister extends EntityDefinition, Loadable { * has multiple tables. Returns {@code null} to indicate that the entity * does not define multiple tables */ - default SqmMutationStrategy getSqmMultiTableMutationStrategy(){ + default SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy(){ throw new NotYetImplementedFor6Exception( getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java index 1fbdcc9823..3a9b67dae5 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java @@ -22,6 +22,7 @@ import org.hibernate.procedure.spi.ParameterStrategy; import org.hibernate.procedure.spi.ProcedureParameterImplementor; import org.hibernate.query.spi.AbstractNamedQueryMemento; import org.hibernate.query.spi.NamedQueryMemento; +import org.hibernate.query.spi.QueryEngine; /** * Implementation of NamedCallableQueryMemento @@ -137,6 +138,11 @@ public class NamedCallableQueryMementoImpl extends AbstractNamedQueryMemento imp ); } + @Override + public void validate(QueryEngine queryEngine) { + // anything to do? + } + /** * A "disconnected" copy of the metadata for a parameter, that can be used in ProcedureCallMementoImpl. */ diff --git a/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java b/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java index b849a60610..78ab4b5744 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java @@ -6,6 +6,10 @@ */ package org.hibernate.query; +import javax.persistence.criteria.CriteriaDelete; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.CriteriaUpdate; + /** * Contract for things that can produce Query instances. Expected implementors include * Session and StatelessSession. @@ -132,6 +136,15 @@ public interface QueryProducer { */ NativeQuery getNamedNativeQuery(String name); + /** + * Get a NativeQuery instance for a named native SQL query + * + * @param name The name of the pre-defined query + * + * @return The NativeQuery instance for manipulation and execution + */ + NativeQuery getNamedNativeQuery(String name, String resultSetMapping); + Query createQuery(CriteriaQuery criteriaQuery); Query createQuery(CriteriaUpdate updateQuery); diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/NamedHqlQueryMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/NamedHqlQueryMementoImpl.java index 8540c6837d..3aadd937d2 100755 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/NamedHqlQueryMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/NamedHqlQueryMementoImpl.java @@ -11,12 +11,19 @@ import java.util.Map; import org.hibernate.CacheMode; import org.hibernate.FlushMode; +import org.hibernate.HibernateException; import org.hibernate.LockOptions; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.query.hql.SemanticQueryProducer; import org.hibernate.query.hql.spi.HqlQueryImplementor; import org.hibernate.query.hql.spi.NamedHqlQueryMemento; import org.hibernate.query.spi.AbstractNamedQueryMemento; +import org.hibernate.query.spi.QueryEngine; +import org.hibernate.query.spi.QueryInterpretationCache; import org.hibernate.query.sqm.internal.QuerySqmImpl; +import org.hibernate.query.sqm.tree.SqmStatement; + +import org.jboss.logging.Logger; /** * Definition of a named query, defined in the mapping metadata. @@ -28,6 +35,8 @@ import org.hibernate.query.sqm.internal.QuerySqmImpl; * @author Steve Ebersole */ public class NamedHqlQueryMementoImpl extends AbstractNamedQueryMemento implements NamedHqlQueryMemento, Serializable { + private static final Logger log = Logger.getLogger( NamedHqlQueryMementoImpl.class ); + private final String hqlString; private final Integer firstResult; @@ -117,6 +126,11 @@ public class NamedHqlQueryMementoImpl extends AbstractNamedQueryMemento implemen ); } + @Override + public void validate(QueryEngine queryEngine) { + queryEngine.getSemanticQueryProducer().interpret( getHqlString() ); + } + @Override public HqlQueryImplementor toQuery(SharedSessionContractImplementor session) { return toQuery( session, null ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java index 05ef91ea3e..ddb799ab68 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java @@ -17,8 +17,6 @@ import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.consume.spi.BaseSemanticQueryWalker; import org.hibernate.query.sqm.produce.spi.SqmCreationProcessingState; import org.hibernate.query.hql.spi.SqmPathRegistry; -import org.hibernate.query.sqm.produce.spi.SqmQuerySpecCreationProcessingState; -import org.hibernate.query.sqm.produce.spi.ImplicitAliasGenerator; import org.hibernate.query.sqm.produce.spi.SqmCreationContext; import org.hibernate.query.sqm.produce.spi.SqmCreationOptions; import org.hibernate.query.sqm.produce.spi.SqmCreationState; @@ -36,7 +34,7 @@ import org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType; import org.hibernate.query.sqm.tree.expression.SqmNamedParameter; import org.hibernate.query.sqm.tree.expression.SqmPositionalParameter; import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; -import org.hibernate.query.sqm.tree.expression.function.SqmFunction; +import org.hibernate.query.sqm.function.SqmFunction; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin; import org.hibernate.query.sqm.tree.from.SqmEntityJoin; diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 287986c8f8..374ce6edbd 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -86,11 +86,11 @@ import org.hibernate.query.sqm.tree.expression.SqmNamedParameter; import org.hibernate.query.sqm.tree.expression.SqmParameter; import org.hibernate.query.sqm.tree.expression.SqmPositionalParameter; import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; -import org.hibernate.query.sqm.tree.expression.function.SqmCastTarget; -import org.hibernate.query.sqm.tree.expression.function.SqmDistinct; -import org.hibernate.query.sqm.tree.expression.function.SqmExtractUnit; -import org.hibernate.query.sqm.tree.expression.function.SqmStar; -import org.hibernate.query.sqm.tree.expression.function.SqmTrimSpecification; +import org.hibernate.query.sqm.function.SqmCastTarget; +import org.hibernate.query.sqm.function.SqmDistinct; +import org.hibernate.query.sqm.function.SqmExtractUnit; +import org.hibernate.query.sqm.function.SqmStar; +import org.hibernate.query.sqm.function.SqmTrimSpecification; import org.hibernate.query.sqm.tree.from.DowncastLocation; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin; diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/NamedQueryRepositoryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/NamedQueryRepositoryImpl.java index cd96ca610f..23443b8e53 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/NamedQueryRepositoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/NamedQueryRepositoryImpl.java @@ -138,15 +138,12 @@ public class NamedQueryRepositoryImpl implements NamedQueryRepository { // Check named HQL queries log.debugf( "Checking %s named HQL queries", hqlMementoMap.size() ); for ( NamedHqlQueryMemento hqlMemento : hqlMementoMap.values() ) { - // this will throw an error if there's something wrong. try { - log.debugf( "Checking named query: %s", hqlMemento.getRegistrationName() ); - final SqmStatement sqmStatement = sqmProducer.interpret( hqlMemento.getHqlString() ); + log.debugf( "Checking named HQL query: %s", hqlMemento.getRegistrationName() ); + hqlMemento.validate( queryEngine ); - if ( cachingEnabled ) { - // todo (6.0) : need to cache these; however atm that requires producing a SqmQueryImpl - // queryEngine.getQueryInterpretationCache().getHQLQueryPlan( hqlMemento.getQueryString(), false, Collections.EMPTY_MAP ); - } + // todo (6.0) : need to cache these; however atm that requires producing a SqmQueryImpl + // queryEngine.getQueryInterpretationCache().getHQLQueryPlan( hqlMemento.getQueryString(), false, Collections.EMPTY_MAP ); } catch ( HibernateException e ) { errors.put( hqlMemento.getRegistrationName(), e ); @@ -156,6 +153,7 @@ public class NamedQueryRepositoryImpl implements NamedQueryRepository { // Check native-sql queries log.debugf( "Checking %s named SQL queries", sqlMementoMap.size() ); for ( NamedNativeQueryMemento memento : sqlMementoMap.values() ) { + memento.validate( queryEngine ); // // this will throw an error if there's something wrong. // try { // log.debugf( "Checking named SQL query: %s", memento.getRegistrationName() ); @@ -185,7 +183,6 @@ public class NamedQueryRepositoryImpl implements NamedQueryRepository { // catch ( HibernateException e ) { // errors.put( namedSQLQueryDefinition.getName(), e ); // } - throw new NotYetImplementedFor6Exception( getClass() ); } return errors; diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/NamedResultSetMappingMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/NamedResultSetMappingMementoImpl.java index aa875b9d0f..6d88313766 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/NamedResultSetMappingMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/NamedResultSetMappingMementoImpl.java @@ -7,6 +7,7 @@ package org.hibernate.query.internal; import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.spi.NamedResultSetMappingMemento; import org.hibernate.query.spi.ResultSetMapping; @@ -14,9 +15,15 @@ import org.hibernate.query.spi.ResultSetMapping; * @author Steve Ebersole */ public class NamedResultSetMappingMementoImpl implements NamedResultSetMappingMemento { + private final String name; + + public NamedResultSetMappingMementoImpl(String name, SessionFactoryImplementor factory) { + this.name = name; + } + @Override public String getName() { - throw new NotYetImplementedFor6Exception( getClass() ); + return name; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryMemento.java b/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryMemento.java index c261e2d6e9..73e82d48b9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryMemento.java @@ -48,6 +48,8 @@ public interface NamedQueryMemento { Map getHints(); + void validate(QueryEngine queryEngine); + interface ParameterMemento { QueryParameterImplementor resolve(SharedSessionContractImplementor session); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/NamedResultSetMappingMemento.java b/hibernate-core/src/main/java/org/hibernate/query/spi/NamedResultSetMappingMemento.java index bc5fb65faf..42ab41482e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/NamedResultSetMappingMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/NamedResultSetMappingMemento.java @@ -6,6 +6,8 @@ */ package org.hibernate.query.spi; +import org.hibernate.Incubating; + /** * Used to keep information about named result mappings defined by the * application which can then be applied to native-sql and stored-procedure @@ -20,6 +22,7 @@ package org.hibernate.query.spi; * @author Emmanuel Bernard * @author Steve Ebersole */ +@Incubating public interface NamedResultSetMappingMemento { String getName(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java index 13cead45b6..c5f3742fa8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java @@ -81,9 +81,9 @@ public class QueryEngine { .getJdbcEnvironment() .getDialect() .initializeFunctionRegistry( this ); - runtimeOptions.getSqmFunctionRegistry().overlay( sqmFunctionRegistry ); - - getNamedQueryRepository().checkNamedQueries( this ); + if ( runtimeOptions.getSqmFunctionRegistry() != null ) { + runtimeOptions.getSqmFunctionRegistry().overlay( sqmFunctionRegistry ); + } } private static QueryInterpretationCache buildQueryPlanCache(Map properties) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryProducerImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryProducerImplementor.java index 6350b5f891..763393ae3f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryProducerImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryProducerImplementor.java @@ -56,4 +56,6 @@ public interface QueryProducerImplementor extends QueryProducer { @Override NativeQueryImplementor getNamedNativeQuery(String name); + + NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/ResultSetMapping.java b/hibernate-core/src/main/java/org/hibernate/query/spi/ResultSetMapping.java index f127bbce7d..920846c73a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/ResultSetMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/ResultSetMapping.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.spi; +import org.hibernate.Incubating; import org.hibernate.sql.results.spi.DomainResultProducer; /** @@ -24,5 +25,6 @@ import org.hibernate.sql.results.spi.DomainResultProducer; * * @author Steve Ebersole */ +@Incubating public interface ResultSetMapping extends DomainResultProducer { } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java index 5f3611f60f..db623fc4eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java @@ -11,8 +11,10 @@ import java.util.Set; import org.hibernate.CacheMode; import org.hibernate.FlushMode; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.query.spi.AbstractNamedQueryMemento; +import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sql.spi.NamedNativeQueryMemento; import org.hibernate.query.sql.spi.NativeQueryImplementor; @@ -100,6 +102,17 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple ); } + @Override + public void validate(QueryEngine queryEngine) { + // todo (6.0) : add any validation we want here + } + + @Override + public NativeQueryImplementor toQuery(SharedSessionContractImplementor session) { + //noinspection unchecked + return toQuery( session, (Class) null ); + } + @Override @SuppressWarnings("unchecked") public NativeQueryImplementor toQuery(SharedSessionContractImplementor session, Class resultType) { @@ -107,8 +120,8 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple } @Override - public NativeQueryImplementor toQuery(SharedSessionContractImplementor session) { - //noinspection unchecked - return toQuery( session, null ); + @SuppressWarnings("unchecked") + public NativeQueryImplementor toQuery(SharedSessionContractImplementor session, String resultSetMappingName) { + return new NativeQueryImpl( this, resultSetMappingName, session ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index 966ebdd77c..74bc2a7ebc 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -119,7 +119,6 @@ public class NativeQueryImpl */ public NativeQueryImpl( NamedNativeQueryMemento memento, - Class resultJavaType, SharedSessionContractImplementor session) { super( session ); @@ -132,10 +131,30 @@ public class NativeQueryImpl this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, session.getFactory() ); applyOptions( memento ); + } + + /** + * Constructs a NativeQueryImpl given a sql query defined in the mappings. + */ + public NativeQueryImpl( + NamedNativeQueryMemento memento, + Class resultJavaType, + SharedSessionContractImplementor session) { + this( memento, session ); // todo (6.0) : validate `resultJavaType` against specified result-set mapping } + /** + * Constructs a NativeQueryImpl given a sql query defined in the mappings. + */ + public NativeQueryImpl( + NamedNativeQueryMemento memento, + String resultSetMappingName, + SharedSessionContractImplementor session) { + this( memento, session ); + } + private ParameterInterpretation resolveParameterInterpretation(SharedSessionContractImplementor session) { final SessionFactoryImplementor sessionFactory = session.getFactory(); final QueryEngine queryEngine = sessionFactory.getQueryEngine(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java index 58aba1932a..d761caa465 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java @@ -32,15 +32,20 @@ public interface NamedNativeQueryMemento extends NamedQueryMemento { */ Set getQuerySpaces(); + /** + * Convert the memento into an untyped executable query + */ + NativeQueryImplementor toQuery(SharedSessionContractImplementor session); + /** * Convert the memento into a typed executable query */ NativeQueryImplementor toQuery(SharedSessionContractImplementor session, Class resultType); /** - * Convert the memento into an untyped executable query + * Convert the memento into a typed executable query */ - NativeQueryImplementor toQuery(SharedSessionContractImplementor session); + NativeQueryImplementor toQuery(SharedSessionContractImplementor session, String resultSetMapping); @Override NamedNativeQueryMemento makeCopy(String name); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java index b105593a64..167c7cea18 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java @@ -33,7 +33,6 @@ import org.hibernate.NullPrecedence; import org.hibernate.SortOrder; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; -import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.query.criteria.HibernateCriteriaBuilder; import org.hibernate.query.criteria.JpaCoalesce; import org.hibernate.query.criteria.JpaCompoundSelection; @@ -62,7 +61,7 @@ import org.hibernate.query.sqm.tree.select.SqmSortSpecification; import org.hibernate.query.sqm.tree.select.SqmSubQuery; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; import org.hibernate.service.ServiceRegistry; -import org.hibernate.query.sqm.tree.expression.function.SqmFunction; +import org.hibernate.query.sqm.function.SqmFunction; import org.hibernate.type.spi.TypeConfiguration; /** diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/consume/spi/BaseSemanticQueryWalker.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/consume/spi/BaseSemanticQueryWalker.java index 9797a2a3d2..7d260fd207 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/consume/spi/BaseSemanticQueryWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/consume/spi/BaseSemanticQueryWalker.java @@ -37,12 +37,12 @@ import org.hibernate.query.sqm.tree.expression.SqmPositionalParameter; import org.hibernate.query.sqm.tree.expression.SqmRestrictedSubQueryExpression; import org.hibernate.query.sqm.tree.expression.SqmTuple; import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; -import org.hibernate.query.sqm.tree.expression.function.SqmCastTarget; -import org.hibernate.query.sqm.tree.expression.function.SqmDistinct; -import org.hibernate.query.sqm.tree.expression.function.SqmExtractUnit; -import org.hibernate.query.sqm.tree.expression.function.SqmFunction; -import org.hibernate.query.sqm.tree.expression.function.SqmStar; -import org.hibernate.query.sqm.tree.expression.function.SqmTrimSpecification; +import org.hibernate.query.sqm.function.SqmCastTarget; +import org.hibernate.query.sqm.function.SqmDistinct; +import org.hibernate.query.sqm.function.SqmExtractUnit; +import org.hibernate.query.sqm.function.SqmFunction; +import org.hibernate.query.sqm.function.SqmStar; +import org.hibernate.query.sqm.function.SqmTrimSpecification; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin; import org.hibernate.query.sqm.tree.from.SqmEntityJoin; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/consume/spi/SemanticQueryWalker.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/consume/spi/SemanticQueryWalker.java index 4880efa00d..81da3f3a79 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/consume/spi/SemanticQueryWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/consume/spi/SemanticQueryWalker.java @@ -36,12 +36,12 @@ import org.hibernate.query.sqm.tree.expression.SqmPositionalParameter; import org.hibernate.query.sqm.tree.expression.SqmRestrictedSubQueryExpression; import org.hibernate.query.sqm.tree.expression.SqmTuple; import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; -import org.hibernate.query.sqm.tree.expression.function.SqmCastTarget; -import org.hibernate.query.sqm.tree.expression.function.SqmDistinct; -import org.hibernate.query.sqm.tree.expression.function.SqmExtractUnit; -import org.hibernate.query.sqm.tree.expression.function.SqmFunction; -import org.hibernate.query.sqm.tree.expression.function.SqmStar; -import org.hibernate.query.sqm.tree.expression.function.SqmTrimSpecification; +import org.hibernate.query.sqm.function.SqmCastTarget; +import org.hibernate.query.sqm.function.SqmDistinct; +import org.hibernate.query.sqm.function.SqmExtractUnit; +import org.hibernate.query.sqm.function.SqmFunction; +import org.hibernate.query.sqm.function.SqmStar; +import org.hibernate.query.sqm.function.SqmTrimSpecification; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin; import org.hibernate.query.sqm.tree.from.SqmEntityJoin; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmCastTarget.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCastTarget.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmCastTarget.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCastTarget.java index fe4acf7e96..656c190125 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmCastTarget.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCastTarget.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; import org.hibernate.query.sqm.NodeBuilder; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmCoalesce.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCoalesce.java similarity index 97% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmCoalesce.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCoalesce.java index 2918fef174..539c5000d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmCoalesce.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCoalesce.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; import java.util.ArrayList; import java.util.List; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmDistinct.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmDistinct.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmDistinct.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmDistinct.java index d2344cf387..24925ceea0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmDistinct.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmDistinct.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmExtractUnit.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmExtractUnit.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmExtractUnit.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmExtractUnit.java index 9cf20f3ee2..d226bcd35f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmExtractUnit.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmExtractUnit.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; import org.hibernate.query.sqm.NodeBuilder; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmFunction.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunction.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmFunction.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunction.java index 7b5fc8f334..6f1f9cddaf 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunction.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; import org.hibernate.query.criteria.JpaFunction; import org.hibernate.query.sqm.consume.spi.SemanticQueryWalker; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmJdbcFunctionEscapeWrapper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmJdbcFunctionEscapeWrapper.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmJdbcFunctionEscapeWrapper.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmJdbcFunctionEscapeWrapper.java index 94f6c865c3..42551d93ad 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmJdbcFunctionEscapeWrapper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmJdbcFunctionEscapeWrapper.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.produce.function.internal.SelfRenderingSqmFunction; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmStar.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmStar.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmStar.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmStar.java index 6dd0f27d0f..adf83da795 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmStar.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmStar.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.consume.spi.SemanticQueryWalker; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmTrimSpecification.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmTrimSpecification.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmTrimSpecification.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmTrimSpecification.java index ec82dfd4fb..28d78fba40 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/SqmTrimSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmTrimSpecification.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; import org.hibernate.query.TrimSpec; import org.hibernate.query.sqm.NodeBuilder; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/package-info.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/package-info.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/package-info.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/function/package-info.java index 7350d07558..87057e3b05 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/function/package-info.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/package-info.java @@ -48,6 +48,5 @@ * * non-standard functions * * using JPA's function('function_name', [args]*) syntax. * * directly leveraging Hibernate's {@link org.hibernate.query.sqm.produce.function.SqmFunctionRegistry} - * */ -package org.hibernate.query.sqm.tree.expression.function; +package org.hibernate.query.sqm.function; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index 5c41350888..18e11df0cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -54,9 +54,9 @@ import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.SemanticException; import org.hibernate.query.sqm.produce.function.SqmFunctionTemplate; -import org.hibernate.query.sqm.tree.expression.function.SqmCastTarget; -import org.hibernate.query.sqm.tree.expression.function.SqmDistinct; -import org.hibernate.query.sqm.tree.expression.function.SqmTrimSpecification; +import org.hibernate.query.sqm.function.SqmCastTarget; +import org.hibernate.query.sqm.function.SqmDistinct; +import org.hibernate.query.sqm.function.SqmTrimSpecification; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; import org.hibernate.query.sqm.tree.domain.SqmBagJoin; @@ -76,7 +76,7 @@ import org.hibernate.query.sqm.tree.expression.SqmLiteralNull; import org.hibernate.query.sqm.tree.expression.SqmRestrictedSubQueryExpression; import org.hibernate.query.sqm.tree.expression.SqmTuple; import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; -import org.hibernate.query.sqm.tree.expression.function.SqmCoalesce; +import org.hibernate.query.sqm.function.SqmCoalesce; import org.hibernate.query.sqm.tree.from.SqmRoot; import org.hibernate.query.sqm.tree.insert.SqmInsertSelectStatement; import org.hibernate.query.sqm.tree.predicate.SqmAndPredicate; @@ -99,7 +99,7 @@ import org.hibernate.query.sqm.tree.select.SqmSortSpecification; import org.hibernate.query.sqm.tree.select.SqmSubQuery; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; import org.hibernate.service.ServiceRegistry; -import org.hibernate.query.sqm.tree.expression.function.SqmFunction; +import org.hibernate.query.sqm.function.SqmFunction; import org.hibernate.type.StandardBasicTypes; import static java.util.Arrays.asList; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java index 9e1f3d3221..a1e17f8c6e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java @@ -13,11 +13,10 @@ import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.mapping.RootClass; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.internal.QueryHelper; import org.hibernate.query.sqm.internal.DomainParameterXref; import org.hibernate.query.sqm.mutation.spi.DeleteHandler; import org.hibernate.query.sqm.mutation.spi.HandlerCreationContext; -import org.hibernate.query.sqm.mutation.spi.SqmMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.query.sqm.mutation.spi.UpdateHandler; import org.hibernate.query.sqm.tree.SqmDeleteOrUpdateStatement; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; @@ -29,12 +28,9 @@ import org.hibernate.query.sqm.tree.predicate.SqmInListPredicate; import org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate; import org.hibernate.query.sqm.tree.predicate.SqmJunctivePredicate; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; -import org.hibernate.query.sqm.tree.select.SqmQuerySpec; -import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.exec.spi.ExecutionContext; -import org.hibernate.sql.exec.spi.JdbcSelect; /** * @author Steve Ebersole @@ -52,15 +48,15 @@ public class SqmMutationStrategyHelper { * Standard resolution of SqmMutationStrategy to use for a given * entity hierarchy. */ - public static SqmMutationStrategy resolveStrategy( + public static SqmMultiTableMutationStrategy resolveStrategy( RootClass bootRootEntityDescriptor, EntityPersister runtimeRootEntityDescriptor, SessionFactoryOptions options, ServiceRegistry serviceRegistry) { // todo (6.0) : Planned support for per-entity config - if ( options.getSqmMutationStrategy() != null ) { - return options.getSqmMutationStrategy(); + if ( options.getSqmMultiTableMutationStrategy() != null ) { + return options.getSqmMultiTableMutationStrategy(); } return serviceRegistry.getService( JdbcServices.class ) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteBasedMutationStrategy.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteBasedMutationStrategy.java new file mode 100644 index 0000000000..123b5f8088 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteBasedMutationStrategy.java @@ -0,0 +1,102 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.query.sqm.mutation.internal.cte; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.boot.spi.BootstrapContext; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.query.sqm.internal.DomainParameterXref; +import org.hibernate.query.sqm.mutation.spi.DeleteHandler; +import org.hibernate.query.sqm.mutation.spi.HandlerCreationContext; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.UpdateHandler; +import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; +import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; + +/** + * @asciidoc + * + * {@link SqmMultiTableMutationStrategy} implementation using SQL's CTE (Common Table Expression) + * approach to perform the update/delete. E.g. (using delete): + * + * ```` + * with cte_id (id) as ( + * select + * id + * from ( + * values + * (?), + * (?), + * (?) + * (?) + * ) + * ) + * delete + * from + * Person + * where + * ( id ) in ( + * select id + * from cte_id + * ) + * ```` + * + * todo (6.0) : why not: + * + * ```` + * with cte_id (id) as ( + * select id + * from Person p + * where ... + * ) + * delete from Contact + * where (id) in ( + * select id + * from cte_id + * ) + * + * with cte_id (id) as ( + * select id + * from Person p + * where ... + * ) + * delete from Person + * where (id) in ( + * select id + * from cte_id + * ) + * ```` + * + * @author Evandro Pires da Silva + * @author Vlad Mihalcea + * @author Steve Ebersole + */ +public class CteBasedMutationStrategy implements SqmMultiTableMutationStrategy { + public static final String SHORT_NAME = "cte"; + public static final String TABLE_NAME = "id_cte"; + + public CteBasedMutationStrategy( + EntityPersister rootDescriptor, + BootstrapContext bootstrapContext) { + } + + @Override + public UpdateHandler buildUpdateHandler( + SqmUpdateStatement sqmUpdateStatement, + DomainParameterXref domainParameterXref, + HandlerCreationContext creationContext) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public DeleteHandler buildDeleteHandler( + SqmDeleteStatement sqmDeleteStatement, + DomainParameterXref domainParameterXref, + HandlerCreationContext creationContext) { + throw new NotYetImplementedFor6Exception( getClass() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/GlobalTemporaryTableStrategy.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/GlobalTemporaryTableStrategy.java new file mode 100644 index 0000000000..f8c5cf8998 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/GlobalTemporaryTableStrategy.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.query.sqm.mutation.internal.idtable; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.query.sqm.internal.DomainParameterXref; +import org.hibernate.query.sqm.mutation.spi.DeleteHandler; +import org.hibernate.query.sqm.mutation.spi.HandlerCreationContext; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.UpdateHandler; +import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; +import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; + +/** + * Strategy based on ANSI SQL's definition of a "global temporary table". + * + * @author Steve Ebersole + */ +public class GlobalTemporaryTableStrategy implements SqmMultiTableMutationStrategy { + public static final String SHORT_NAME = "global_temporary"; + public static final String DROP_ID_TABLES = "hibernate.hql.bulk_id_strategy.global_temporary.drop_tables"; + + @Override + public UpdateHandler buildUpdateHandler( + SqmUpdateStatement sqmUpdateStatement, + DomainParameterXref domainParameterXref, + HandlerCreationContext creationContext) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public DeleteHandler buildDeleteHandler( + SqmDeleteStatement sqmDeleteStatement, + DomainParameterXref domainParameterXref, + HandlerCreationContext creationContext) { + throw new NotYetImplementedFor6Exception( getClass() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/LocalTemporaryTableStrategy.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/LocalTemporaryTableStrategy.java new file mode 100644 index 0000000000..d9b2658086 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/LocalTemporaryTableStrategy.java @@ -0,0 +1,41 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.query.sqm.mutation.internal.idtable; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.query.sqm.internal.DomainParameterXref; +import org.hibernate.query.sqm.mutation.spi.DeleteHandler; +import org.hibernate.query.sqm.mutation.spi.HandlerCreationContext; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.UpdateHandler; +import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; +import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; + +/** + * Strategy based on ANSI SQL's definition of a "local temporary table" (local to each db session). + * + * @author Steve Ebersole + */ +public class LocalTemporaryTableStrategy implements SqmMultiTableMutationStrategy { + public static final String SHORT_NAME = "local_temporary"; + + @Override + public UpdateHandler buildUpdateHandler( + SqmUpdateStatement sqmUpdateStatement, + DomainParameterXref domainParameterXref, + HandlerCreationContext creationContext) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public DeleteHandler buildDeleteHandler( + SqmDeleteStatement sqmDeleteStatement, + DomainParameterXref domainParameterXref, + HandlerCreationContext creationContext) { + throw new NotYetImplementedFor6Exception( getClass() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/PersistentTableStrategy.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/PersistentTableStrategy.java new file mode 100644 index 0000000000..e2a1d4992d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/PersistentTableStrategy.java @@ -0,0 +1,48 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.query.sqm.mutation.internal.idtable; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.query.sqm.internal.DomainParameterXref; +import org.hibernate.query.sqm.mutation.spi.DeleteHandler; +import org.hibernate.query.sqm.mutation.spi.HandlerCreationContext; +import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; +import org.hibernate.query.sqm.mutation.spi.UpdateHandler; +import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; +import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; + +/** + * This is a strategy that mimics temporary tables for databases which do not support + * temporary tables. It follows a pattern similar to the ANSI SQL definition of global + * temporary table using a "session id" column to segment rows from the various sessions. + * + * @author Steve Ebersole + */ +public class PersistentTableStrategy implements SqmMultiTableMutationStrategy { + public static final String SHORT_NAME = "persistent"; + + public static final String DROP_ID_TABLES = "hibernate.hql.bulk_id_strategy.persistent.drop_tables"; + + public static final String SCHEMA = "hibernate.hql.bulk_id_strategy.persistent.schema"; + public static final String CATALOG = "hibernate.hql.bulk_id_strategy.persistent.catalog"; + + @Override + public UpdateHandler buildUpdateHandler( + SqmUpdateStatement sqmUpdateStatement, + DomainParameterXref domainParameterXref, + HandlerCreationContext creationContext) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public DeleteHandler buildDeleteHandler( + SqmDeleteStatement sqmDeleteStatement, + DomainParameterXref domainParameterXref, + HandlerCreationContext creationContext) { + throw new NotYetImplementedFor6Exception( getClass() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/HandlerCreationContext.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/HandlerCreationContext.java index 8f34c12b50..48b1a30518 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/HandlerCreationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/HandlerCreationContext.java @@ -10,8 +10,8 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; /** * Parameter object (pattern) for contextual information for - * {@link SqmMutationStrategy#buildUpdateHandler} and - * {@link SqmMutationStrategy#buildDeleteHandler} + * {@link SqmMultiTableMutationStrategy#buildUpdateHandler} and + * {@link SqmMultiTableMutationStrategy#buildDeleteHandler} */ public interface HandlerCreationContext { /** diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/SqmMutationStrategy.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/SqmMultiTableMutationStrategy.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/SqmMutationStrategy.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/SqmMultiTableMutationStrategy.java index 444c588b94..e00b71c68a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/SqmMutationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/spi/SqmMultiTableMutationStrategy.java @@ -10,12 +10,14 @@ import org.hibernate.Metamodel; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.query.sqm.internal.DomainParameterXref; +import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; /** * Pluggable strategy for defining how mutation (`UPDATE` or `DELETE`) - * queries should be handled. + * queries should be handled when the target entity is mapped to multiple + * tables (generally via secondary tables or joined-inheritance). * * {@link #prepare} and {@link #release} allow the strategy to perform * any one time preparation and cleanup. @@ -31,14 +33,11 @@ import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; * * @author Steve Ebersole */ -public interface SqmMutationStrategy { +public interface SqmMultiTableMutationStrategy { /** * Prepare the strategy for use. Called one time as the SessionFactory * is being built. - * - * @param runtimeMetadata Access to the runtime mappings - * @param connectionAccess Access to a JDBC Connection if needed */ default void prepare( Metamodel runtimeMetadata, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/JdbcFunctionEscapeWrapperTemplate.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/JdbcFunctionEscapeWrapperTemplate.java index 6a4ff7e12b..aa9350bd4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/JdbcFunctionEscapeWrapperTemplate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/JdbcFunctionEscapeWrapperTemplate.java @@ -13,7 +13,7 @@ import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.produce.function.internal.SelfRenderingSqmFunction; import org.hibernate.query.sqm.produce.function.spi.AbstractSqmFunctionTemplate; import org.hibernate.query.sqm.tree.SqmTypedNode; -import org.hibernate.query.sqm.tree.expression.function.SqmJdbcFunctionEscapeWrapper; +import org.hibernate.query.sqm.function.SqmJdbcFunctionEscapeWrapper; /** * Acts as a wrapper to another SqmFunctionTemplate - upon rendering uses the diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/internal/SelfRenderingSqmFunction.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/internal/SelfRenderingSqmFunction.java index a6af6802a6..36afdd0439 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/internal/SelfRenderingSqmFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/internal/SelfRenderingSqmFunction.java @@ -13,7 +13,7 @@ import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.produce.function.spi.SelfRenderingFunctionSupport; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.expression.AbstractSqmExpression; -import org.hibernate.query.sqm.tree.expression.function.SqmFunction; +import org.hibernate.query.sqm.function.SqmFunction; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/internal/SqmTreePrinter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/internal/SqmTreePrinter.java index 5cccd700da..bb4ad9f800 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/internal/SqmTreePrinter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/internal/SqmTreePrinter.java @@ -41,12 +41,12 @@ import org.hibernate.query.sqm.tree.expression.SqmPositionalParameter; import org.hibernate.query.sqm.tree.expression.SqmRestrictedSubQueryExpression; import org.hibernate.query.sqm.tree.expression.SqmTuple; import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; -import org.hibernate.query.sqm.tree.expression.function.SqmCastTarget; -import org.hibernate.query.sqm.tree.expression.function.SqmDistinct; -import org.hibernate.query.sqm.tree.expression.function.SqmExtractUnit; -import org.hibernate.query.sqm.tree.expression.function.SqmFunction; -import org.hibernate.query.sqm.tree.expression.function.SqmStar; -import org.hibernate.query.sqm.tree.expression.function.SqmTrimSpecification; +import org.hibernate.query.sqm.function.SqmCastTarget; +import org.hibernate.query.sqm.function.SqmDistinct; +import org.hibernate.query.sqm.function.SqmExtractUnit; +import org.hibernate.query.sqm.function.SqmFunction; +import org.hibernate.query.sqm.function.SqmStar; +import org.hibernate.query.sqm.function.SqmTrimSpecification; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin; import org.hibernate.query.sqm.tree.from.SqmEntityJoin; diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java b/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java index 0f601bf475..4866d092d1 100755 --- a/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/DynamicMapInstantiator.java @@ -5,6 +5,7 @@ * See the lgpl.txt file in the root directory or . */ package org.hibernate.tuple; + import java.io.Serializable; import java.util.HashMap; import java.util.HashSet; @@ -17,16 +18,16 @@ import org.hibernate.mapping.PersistentClass; public class DynamicMapInstantiator implements Instantiator { public static final String KEY = "$type$"; - private String entityName; - private Set isInstanceEntityNames = new HashSet(); + private final String roleName; + private Set isInstanceEntityNames = new HashSet<>(); public DynamicMapInstantiator() { - this.entityName = null; + this.roleName = null; } public DynamicMapInstantiator(PersistentClass mappingInfo) { - this.entityName = mappingInfo.getEntityName(); - isInstanceEntityNames.add( entityName ); + this.roleName = mappingInfo.getEntityName(); + isInstanceEntityNames.add( roleName ); if ( mappingInfo.hasSubclasses() ) { Iterator itr = mappingInfo.getSubclassClosureIterator(); while ( itr.hasNext() ) { @@ -42,18 +43,18 @@ public class DynamicMapInstantiator implements Instantiator { public final Object instantiate() { Map map = generateMap(); - if ( entityName!=null ) { - map.put( KEY, entityName ); + if ( roleName != null ) { + map.put( KEY, roleName ); } return map; } public final boolean isInstance(Object object) { if ( object instanceof Map ) { - if ( entityName == null ) { + if ( roleName == null ) { return true; } - String type = ( String ) ( ( Map ) object ).get( KEY ); + final String type = (String) ( (Map) object ).get( KEY ); return type == null || isInstanceEntityNames.contains( type ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index 298cd24482..104c35362b 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -23,9 +23,12 @@ import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementHelper; import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.engine.OptimisticLockStyle; +import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadeStyles; +import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.ArrayHelper; @@ -44,6 +47,8 @@ import org.hibernate.tuple.ValueGenerator; import org.hibernate.type.AssociationType; import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; +import org.hibernate.type.ForeignKeyDirection; +import org.hibernate.type.ManyToOneType; import org.hibernate.type.Type; import static org.hibernate.internal.CoreLogging.messageLogger; @@ -833,7 +838,7 @@ public class EntityMetamodel implements Serializable { public EntityType getEntityType() { if ( entityType == null ) { - entityType = sessionFactory.getTypeResolver().getTypeFactory().manyToOne( name ); + entityType = new ManyToOneType( name, getSessionFactory().getTypeConfiguration() ); } return entityType; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java index a461bfe5c3..d3859e085d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java @@ -19,6 +19,7 @@ import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.spi.*; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Loadable; +import org.hibernate.type.spi.TypeConfiguration; /** * A many-to-one association to an entity. @@ -108,6 +109,10 @@ public class ManyToOneType extends EntityType { this.isLogicalOneToOne = original.isLogicalOneToOne; } + public ManyToOneType(String name, TypeConfiguration typeConfiguration) { + this( () -> typeConfiguration, name ); + } + @Override public boolean isNullable() { return ignoreNotFound; diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptorRegistry.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptorRegistry.java index bc421c9c19..cfd3d73405 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptorRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptorRegistry.java @@ -13,6 +13,7 @@ import javax.persistence.AttributeConverter; import org.hibernate.HibernateException; import org.hibernate.annotations.Immutable; +import org.hibernate.annotations.Remove; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; @@ -28,6 +29,7 @@ import org.hibernate.type.spi.TypeConfiguration; * @deprecated Use (5.3) Use {@link org.hibernate.type.descriptor.java.spi.JavaTypeDescriptorRegistry} instead */ @Deprecated +@Remove public class JavaTypeDescriptorRegistry implements Serializable { private static final CoreMessageLogger log = CoreLogging.messageLogger( JavaTypeDescriptorRegistry.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/spi/TypeConfiguration.java b/hibernate-core/src/main/java/org/hibernate/type/spi/TypeConfiguration.java index bb38e99a38..85b88cbede 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/spi/TypeConfiguration.java +++ b/hibernate-core/src/main/java/org/hibernate/type/spi/TypeConfiguration.java @@ -11,7 +11,6 @@ import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Types; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -26,15 +25,13 @@ import org.hibernate.SessionFactory; import org.hibernate.SessionFactoryObserver; import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService; import org.hibernate.boot.spi.BasicTypeRegistration; -import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.id.uuid.LocalObjectUuidHelper; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.SessionFactoryRegistry; -import org.hibernate.metamodel.internal.RuntimeModelCreationProcess; import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; -import org.hibernate.metamodel.spi.MetamodelImplementor; +import org.hibernate.metamodel.spi.DomainMetamodel; import org.hibernate.query.BinaryArithmeticOperator; import org.hibernate.query.internal.QueryHelper; import org.hibernate.query.sqm.SqmExpressable; @@ -86,8 +83,6 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable { private final transient SqlTypeDescriptorRegistry sqlTypeDescriptorRegistry; private final transient BasicTypeRegistry basicTypeRegistry; - private final transient Map importMap = new ConcurrentHashMap<>(); - private final transient Map> jdbcToHibernateTypeContributionMap = new HashMap<>(); // temporarily needed to support deprecations @@ -139,10 +134,6 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable { return sqlTypeDescriptorRegistry; } - public Map getImportMap() { - return Collections.unmodifiableMap( importMap ); - } - public SqlTypeDescriptorIndicators getCurrentBaseSqlTypeIndicators() { return scope.getCurrentBaseSqlTypeIndicators(); } @@ -173,25 +164,16 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable { scope.setMetadataBuildingContext( metadataBuildingContext ); } - public RuntimeModelCreationProcess scope(SessionFactoryImplementor sessionFactory) { - log.debugf( "Scoping TypeConfiguration [%s] to SessionFactoryImpl [%s]", this, sessionFactory ); + public DomainMetamodel scope(SessionFactoryImplementor sessionFactory) { + log.debugf( "Scoping TypeConfiguration [%s] to SessionFactoryImplementor [%s]", this, sessionFactory ); if ( scope.getMetadataBuildingContext() == null ) { throw new IllegalStateException( "MetadataBuildingContext not known" ); } - final BootstrapContext bootstrapContext = scope.getMetadataBuildingContext().getBootstrapContext(); - - for ( Map.Entry importEntry : scope.metadataBuildingContext.getMetadataCollector().getImports().entrySet() ) { - if ( importMap.containsKey( importEntry.getKey() ) ) { - continue; - } - - importMap.put( importEntry.getKey(), importEntry.getValue() ); - } scope.setSessionFactory( sessionFactory ); sessionFactory.addObserver( this ); - return new RuntimeModelCreationProcess( bootstrapContext, sessionFactory, this ); + return new DomainMetamodelImpl( sessionFactory, this ); } /** diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java index 97e0bfc916..28b25faca8 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java @@ -25,12 +25,9 @@ import javax.persistence.metamodel.Type; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.metamodel.internal.RuntimeModelCreationProcess; -import org.hibernate.testing.boot.BootstrapContextImpl; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -94,12 +91,6 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { .addAnnotatedClass( WithGenericCollection.class ) .buildMetadata(); SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory(); - - new RuntimeModelCreationProcess( - BootstrapContextImpl.INSTANCE, - sfi, - ( (MetadataImplementor) metadata ).getTypeConfiguration() - ).create( (MetadataImplementor) metadata ); sfi.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java index 6e5da6ad8f..13834d072a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java @@ -86,7 +86,7 @@ public class QueryAndSQLTest extends BaseCoreFunctionalTestCase { Session s = openSession(); s.beginTransaction(); s.createNativeQuery( sql ).addEntity( "t", AllTables.class ).list(); - s.createNativeQuery( sql2 ).setResultSetMapping( "all" ).list(); + s.createNativeQuery( sql2, "all" ).list(); NativeQuery q = s.createNativeQuery( sql2 ); q.addRoot( "t", AllTables.class ).addProperty( "tableName", "t_name" ).addProperty( "daysOld", "t_time" ); q.list(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java index 113941d9ee..c9ef323c90 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java @@ -6,7 +6,6 @@ */ package org.hibernate.test.annotations.quote.resultsetmappings; -import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; @@ -58,9 +57,7 @@ public class ExplicitSqlResultSetMappingTest extends BaseCoreFunctionalTestCase prepareTestData(); inTransaction( - s -> s.createNativeQuery( queryString ) - .setResultSetMapping( "explicitScalarResultSetMapping" ) - .list() + s -> s.createNativeQuery( queryString, "explicitScalarResultSetMapping" ).list() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionManagementTestCase.java b/hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionManagementTestCase.java index 50b9a8c295..6b65afb752 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionManagementTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionManagementTestCase.java @@ -239,13 +239,6 @@ public abstract class ConnectionManagementTestCase extends BaseNonConfigCoreFunc sessionUnderTest.save( silly ); sessionUnderTest.flush(); - sessionUnderTest.createQuery( "from Silly" ).iterate(); - - disconnect( sessionUnderTest ); - SerializationHelper.serialize( sessionUnderTest ); - checkSerializedState( sessionUnderTest ); - - reconnect( sessionUnderTest ); sessionUnderTest.createQuery( "from Silly" ).scroll(); disconnect( sessionUnderTest ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/converter/custom/CustomTypeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/test/converter/custom/CustomTypeConverterTest.java index 5182e1ab9c..fa3d6f9d06 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/converter/custom/CustomTypeConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/converter/custom/CustomTypeConverterTest.java @@ -26,27 +26,6 @@ import static org.hamcrest.MatcherAssert.assertThat; * @author Steve Ebersole */ public class CustomTypeConverterTest extends BaseUnitTestCase { - @Test - public void testConverterAppliedStaticRegistration() { - // this is how we told users to do it previously using the static reference - - // make sure it still works for now - org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry.INSTANCE.addDescriptor( MyCustomJavaTypeDescriptor.INSTANCE ); - org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( MyCustomSqlTypeDescriptor.INSTANCE ); - - try ( final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() - .applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ) - .build() ) { - final MetadataSources metadataSources = new MetadataSources( ssr ) - .addAnnotatedClass( MyCustomConverter.class ) - .addAnnotatedClass( MyEntity.class ); - final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder(); - - final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration(); - performAssertions( metadataBuilder, bootTypeConfiguration ); - - } - } - @Test public void testConverterAppliedScopedRegistration() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/query/QueryReturnTest.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/query/QueryReturnTest.java index d15d9b801d..83a971f9b0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hbm/query/QueryReturnTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/query/QueryReturnTest.java @@ -2,11 +2,13 @@ package org.hibernate.test.hbm.query; import java.io.StringReader; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; +import org.hibernate.boot.spi.NamedNativeQueryDefinition; import org.hibernate.engine.jdbc.ReaderInputStream; import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn; @@ -50,15 +52,19 @@ public class QueryReturnTest extends BaseUnitTestCase { try { metadataSources.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML))); Metadata metadata = metadataSources.buildMetadata(); - NamedSQLQueryDefinition myQuery = metadata.getNamedNativeQueryMapping( "myQuery"); + NamedNativeQueryDefinition myQuery = metadata.getNamedNativeQueryMapping( "myQuery"); Assert.assertNotNull(myQuery); - NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns(); - Assert.assertNotNull(myQueryReturns); - Assert.assertEquals(1, myQueryReturns.length); - Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0])); - NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn)myQueryReturns[0]; - Assert.assertEquals("e", myQueryRootReturn.getAlias()); - Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName()); + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // NYI +// NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns(); +// Assert.assertNotNull(myQueryReturns); +// Assert.assertEquals(1, myQueryReturns.length); +// Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0])); +// NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn)myQueryReturns[0]; +// Assert.assertEquals("e", myQueryRootReturn.getAlias()); +// Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName()); + throw new NotYetImplementedFor6Exception( getClass() ); } finally { if ( standardServiceRegistry instanceof StandardServiceRegistryImpl ) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/procedure/HANAStoredProcedureTest.java b/hibernate-core/src/test/java/org/hibernate/test/procedure/HANAStoredProcedureTest.java index 324ac824f5..1adee132c7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/procedure/HANAStoredProcedureTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/procedure/HANAStoredProcedureTest.java @@ -33,6 +33,7 @@ import org.hibernate.Session; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.procedure.ProcedureCall; +import org.hibernate.query.procedure.ProcedureParameter; import org.hibernate.result.Output; import org.hibernate.result.ResultSetOutput; import org.hibernate.testing.RequiresDialect; @@ -377,7 +378,13 @@ public class HANAStoredProcedureTest extends BaseEntityManagerFunctionalTestCase Session session = entityManager.unwrap( Session.class ); ProcedureCall call = session.createStoredProcedureCall( "sp_person_phones" ); - call.registerParameter( 1, Long.class, ParameterMode.IN ).bindValue( 1L ); + final ProcedureParameter inParam = call.registerParameter( + 1, + Long.class, + ParameterMode.IN + ); + call.setParameter( inParam, 1L ); + call.registerParameter( 2, Class.class, ParameterMode.REF_CURSOR ); Output output = call.getOutputs().getCurrent(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/procedure/MySQLStoredProcedureTest.java b/hibernate-core/src/test/java/org/hibernate/test/procedure/MySQLStoredProcedureTest.java index 69e0d005b6..1ae81b54fe 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/procedure/MySQLStoredProcedureTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/procedure/MySQLStoredProcedureTest.java @@ -7,7 +7,6 @@ package org.hibernate.test.procedure; import java.sql.CallableStatement; -import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; @@ -23,9 +22,9 @@ import javax.persistence.StoredProcedureQuery; import org.hibernate.Session; import org.hibernate.dialect.MySQL5Dialect; -import org.hibernate.jdbc.Work; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.procedure.ProcedureCall; +import org.hibernate.query.procedure.ProcedureParameter; import org.hibernate.result.Output; import org.hibernate.result.ResultSetOutput; import org.hibernate.type.StringType; @@ -263,9 +262,15 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas Session session = entityManager.unwrap( Session.class ); ProcedureCall call = session.createStoredProcedureCall( "sp_count_phones" ); - call.registerParameter( "personId", Long.class, ParameterMode.IN ).bindValue( 1L ); + final ProcedureParameter inParam = call.registerParameter( + "personId", + Long.class, + ParameterMode.IN + ); call.registerParameter( "phoneCount", Long.class, ParameterMode.OUT ); + call.setParameter( inParam, 1L ); + Long phoneCount = (Long) call.getOutputs().getOutputParameterValue( "phoneCount" ); assertEquals( Long.valueOf( 2 ), phoneCount ); } @@ -330,7 +335,13 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas Session session = entityManager.unwrap( Session.class ); ProcedureCall call = session.createStoredProcedureCall( "sp_phones" ); - call.registerParameter( 1, Long.class, ParameterMode.IN ).bindValue( 1L ); + final ProcedureParameter parameter = call.registerParameter( + 1, + Long.class, + ParameterMode.IN + ); + + call.setParameter( parameter, 1L ); Output output = call.getOutputs().getCurrent(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/procedure/OracleStoredProcedureTest.java b/hibernate-core/src/test/java/org/hibernate/test/procedure/OracleStoredProcedureTest.java index 1d4434ef40..071d57e411 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/procedure/OracleStoredProcedureTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/procedure/OracleStoredProcedureTest.java @@ -31,6 +31,7 @@ import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.jdbc.Work; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.procedure.ProcedureCall; +import org.hibernate.query.procedure.ProcedureParameter; import org.hibernate.result.Output; import org.hibernate.result.ResultSetOutput; import org.hibernate.type.NumericBooleanType; @@ -358,7 +359,12 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa Session session = entityManager.unwrap(Session.class); ProcedureCall call = session.createStoredProcedureCall( "sp_person_phones"); - call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L); + final ProcedureParameter inParam = call.registerParameter( + 1, + Long.class, + ParameterMode.IN + ); + call.setParameter( inParam, 1L ); call.registerParameter(2, Class.class, ParameterMode.REF_CURSOR); Output output = call.getOutputs().getCurrent(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java index 478cd721e5..07e3d10e2f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java @@ -6,7 +6,6 @@ */ package org.hibernate.test.sql.hand.query; -import javax.persistence.PersistenceException; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; @@ -16,10 +15,9 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import javax.persistence.PersistenceException; import org.hibernate.Hibernate; -import org.hibernate.query.NativeQuery; -import org.hibernate.query.Query; import org.hibernate.QueryException; import org.hibernate.Session; import org.hibernate.Transaction; @@ -28,7 +26,8 @@ import org.hibernate.cfg.Environment; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.MySQL5Dialect; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; +import org.hibernate.query.NativeQuery; +import org.hibernate.query.Query; import org.hibernate.transform.BasicTransformerAdapter; import org.hibernate.transform.DistinctRootEntityResultTransformer; import org.hibernate.transform.Transformers; @@ -247,14 +246,10 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase { s.persist(gavin); s.persist(emp); - List l = s.createNativeQuery( getOrgEmpRegionSQL() ) - .setResultSetMapping( "org-emp-regionCode" ) - .list(); + List l = s.createNativeQuery( getOrgEmpRegionSQL(), "org-emp-regionCode" ).list(); assertEquals( l.size(), 2 ); - l = s.createNativeQuery( getOrgEmpPersonSQL() ) - .setResultSetMapping( "org-emp-person" ) - .list(); + l = s.createNativeQuery( getOrgEmpPersonSQL(), "org-emp-person" ).list(); assertEquals( l.size(), 1 ); s.delete(emp); @@ -667,8 +662,7 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase { " LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER"; // as a control, lets apply an existing rs mapping - NativeQuery sqlQuery = s.createNativeQuery( sql ); - sqlQuery.setResultSetMapping( "org-description" ); + NativeQuery sqlQuery = s.createNativeQuery( sql, "org-description" ); sqlQuery.list(); // next try a partial mapping def @@ -728,9 +722,7 @@ public class NativeSQLQueriesTest extends BaseCoreFunctionalTestCase { s.flush(); s.clear(); - List l = s.createNativeQuery( "select name, id, flength, name as scalarName from Speech" ) - .setResultSetMapping( "speech" ) - .list(); + List l = s.createNativeQuery( "select name, id, flength, name as scalarName from Speech", "speech" ).list(); assertEquals( l.size(), 1 ); t.rollback(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/quotedidentifiers/NativeSqlAndQuotedIdentifiersTest.java b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/quotedidentifiers/NativeSqlAndQuotedIdentifiersTest.java index db6d162af1..7fae74ab33 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/quotedidentifiers/NativeSqlAndQuotedIdentifiersTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/quotedidentifiers/NativeSqlAndQuotedIdentifiersTest.java @@ -6,8 +6,6 @@ */ package org.hibernate.test.sql.hand.quotedidentifiers; -import org.junit.Test; - import org.hibernate.Session; import org.hibernate.dialect.Dialect; import org.hibernate.query.NativeQuery; @@ -15,6 +13,7 @@ import org.hibernate.query.NativeQuery; import org.hibernate.testing.DialectCheck; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; /** * Test of various situations with native-sql queries and quoted identifiers @@ -67,8 +66,7 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas public void testPartialScalarDiscovery() { Session session = openSession(); session.beginTransaction(); - NativeQuery query = (NativeQuery) session.getNamedQuery( "query-person" ); - query.setResultSetMapping( "person-scalar" ); + NativeQuery query = session.getNamedNativeQuery( "query-person", "person-scalar" ); query.list(); session.getTransaction().commit(); session.close(); @@ -78,8 +76,7 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas public void testBasicEntityMapping() { Session session = openSession(); session.beginTransaction(); - NativeQuery query = (NativeQuery) session.getNamedQuery( "query-person" ); - query.setResultSetMapping( "person-entity-basic" ); + NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-basic" ); query.list(); session.getTransaction().commit(); session.close(); @@ -89,8 +86,7 @@ public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCas public void testExpandedEntityMapping() { Session session = openSession(); session.beginTransaction(); - NativeQuery query = (NativeQuery) session.getNamedQuery( "query-person" ); - query.setResultSetMapping( "person-entity-expanded" ); + NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-expanded" ); query.list(); session.getTransaction().commit(); session.close();