6 - SQM based on JPA type system

- compilation errors down to zero and some test failure causes addressed
This commit is contained in:
Steve Ebersole 2019-07-24 13:40:56 -05:00 committed by Andrea Boriero
parent 268f479b16
commit 00da979e70
124 changed files with 1832 additions and 721 deletions

View File

@ -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;

View File

@ -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<SqmMutationStrategy>() {
new Callable<SqmMultiTableMutationStrategy>() {
@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;
}

View File

@ -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) {

View File

@ -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 <T> void registerStrategyImplementor(Class<T> strategy, String name, Class<? extends T> implementation) {
Map<String,Class> namedStrategyImplementorMap = namedStrategyImplementorByStrategyMap.get( strategy );
if ( namedStrategyImplementorMap == null ) {
namedStrategyImplementorMap = new ConcurrentHashMap<>();
namedStrategyImplementorByStrategyMap.put( strategy, namedStrategyImplementorMap );
}
final Map<String,Class> 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> T resolveDefaultableStrategy(Class<T> strategy, Object strategyReference, final T defaultValue) {
return resolveDefaultableStrategy(
strategy,
@ -205,7 +203,7 @@ public class StrategySelectorImpl implements StrategySelector {
}
final Class<? extends T> implementationClass;
if ( Class.class.isInstance( strategyReference ) ) {
if ( strategyReference instanceof Class ) {
implementationClass = (Class<T>) strategyReference;
}
else {

View File

@ -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

View File

@ -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() {

View File

@ -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();

View File

@ -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";

View File

@ -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) {

View File

@ -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 );
}
}

View File

@ -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(

View File

@ -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() {

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

@ -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(

View File

@ -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() {

View File

@ -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() {

View File

@ -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

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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 );
}

View File

@ -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(

View File

@ -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 {
/**

View File

@ -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<String,SQLFunction> functionMap = new TreeMap<String, SQLFunction>(String.CASE_INSENSITIVE_ORDER);

View File

@ -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 );

View File

@ -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);

View File

@ -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")

View File

@ -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 <tt>SessionFactory</tt> 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<String, DomainDataRegionConfigImpl.Builder> 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<DomainDataRegionConfig> 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 );

View File

@ -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<String,Integer> 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() ) ];
}
}

View File

@ -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 );
}
}

View File

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

View File

@ -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<Map> {
public static final String KEY = "$type$";
private final String roleName;
private final Set<String> 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;
}
}
}

View File

@ -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<EntityNameResolver> entityNameResolvers) {
if ( persister.getEntityMetamodel() == null || persister.getEntityMetamodel().getTuplizer() == null ) {
return;
}
registerEntityNameResolvers( persister.getEntityMetamodel().getTuplizer(), entityNameResolvers );
}
private static void registerEntityNameResolvers(
EntityTuplizer tuplizer,
Set<EntityNameResolver> entityNameResolvers) {
EntityNameResolver[] resolvers = tuplizer.getEntityNameResolvers();
if ( resolvers == null ) {
return;
}
for ( EntityNameResolver resolver : resolvers ) {
entityNameResolvers.add( resolver );
}
}
public Map<String, String> getImports() {
return imports;
}

View File

@ -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<MappedSuperclass> 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<PersistentClass> stackOfPersistentClassesBeingProcessed = new ArrayList<>();
private InflightRuntimeMetamodel metamodel;
private DomainMetamodel metamodel;
public MetadataContext(
JpaMetamodel jpaMetamodel,
RuntimeModelCreationContext runtimeModelCreationContext,
InflightRuntimeMetamodel metamodel,
SqmCriteriaNodeBuilder criteriaBuilder,
Set<MappedSuperclass> 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;
}

View File

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

View File

@ -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<J> 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 );
}
}
}
}

View File

@ -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<String, DomainDataRegionConfigImpl.Builder> 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<DomainDataRegionConfig> 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 );
}
}

View File

@ -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 );
}
}
}

View File

@ -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 <J> Instantiator<J> getInstantiator() {
//noinspection unchecked
return (Instantiator) instantiator;
}
}

View File

@ -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 <J> Instantiator<J> getInstantiator() {
//noinspection unchecked
return (Instantiator) instantiator;
}
@Override
public ProxyFactory getProxyFactory() {
return proxyFactory;
}
}

View File

@ -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 <J> Instantiator<J> getInstantiator() {
//noinspection unchecked
return instantiator;
}
}

View File

@ -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 <J> Instantiator<J> 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() );
}
}

View File

@ -603,15 +603,16 @@ public abstract class AbstractManagedType<J>
@SuppressWarnings("unchecked")
public void addAttribute(PersistentAttribute<J,?> attribute) {
if ( attribute instanceof SingularPersistentAttribute ) {
declaredSingularAttributes.put( attribute.getName(), (SingularPersistentAttribute<J,?>) attribute );
declaredSingularAttributes.put( attribute.getName(), (SingularPersistentAttribute) attribute );
}
else if ( attribute instanceof PluralPersistentAttribute ) {
declaredPluralAttributes.put(attribute.getName(), (PluralPersistentAttribute<J,?,?>) 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

View File

@ -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<D,C,E>
AbstractManagedType<X> ownerType,
SimpleDomainType<E> attrType,
JavaTypeDescriptor<C> collectionClass,
SimpleDomainType<K> listIndexOrMapKeyType,
NodeBuilder nodeBuilder) {
return new PluralAttributeBuilder<>( ownerType, attrType, collectionClass, listIndexOrMapKeyType, nodeBuilder );
SimpleDomainType<K> listIndexOrMapKeyType) {
return new PluralAttributeBuilder<>( ownerType, attrType, collectionClass, listIndexOrMapKeyType );
}
private final CollectionClassification classification;
@ -67,8 +65,7 @@ public abstract class AbstractPluralAttribute<D,C,E>
interpretValueClassification( builder.getValueType() ),
getName(),
builder.getValueType(),
BindableType.PLURAL_ATTRIBUTE,
builder.getNodeBuilder()
BindableType.PLURAL_ATTRIBUTE
);
}

View File

@ -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<J> implements SqmPathSource<J> {
private final String localPathName;
private final DomainType<J> domainType;
private final BindableType jpaBindableType;
private final NodeBuilder nodeBuilder;
public AbstractSqmPathSource(
String localPathName,
DomainType<J> 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

View File

@ -21,9 +21,8 @@ public class AnyMappingSqmPathSource<J> extends AbstractSqmPathSource<J> {
public AnyMappingSqmPathSource(
String localPathName,
AnyMappingDomainType<J> domainType,
BindableType jpaBindableType,
NodeBuilder nodeBuilder) {
super( localPathName, domainType, jpaBindableType, nodeBuilder );
BindableType jpaBindableType) {
super( localPathName, domainType, jpaBindableType );
}
@Override

View File

@ -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<J> extends AbstractSqmPathSource<J> {
public BasicSqmPathSource(
String localPathName,
BasicDomainType<J> domainType,
BindableType jpaBindableType,
NodeBuilder nodeBuilder) {
super( localPathName, domainType, jpaBindableType, nodeBuilder );
BindableType jpaBindableType) {
super( localPathName, domainType, jpaBindableType );
}
@Override
@ -46,7 +44,7 @@ public class BasicSqmPathSource<J> extends AbstractSqmPathSource<J> {
navigablePath,
this,
lhs,
getNodeBuilder()
creationState.getCreationContext().getNodeBuilder()
);
}
}

View File

@ -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<Class, String> entityProxyInterfaceMap;
private final Map<Class, String> entityProxyInterfaceMap = new ConcurrentHashMap<>();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// RuntimeModel
private final Map<String, EntityPersister> entityPersisterMap;
private final Map<String, CollectionPersister> collectionPersisterMap;
private final Map<String, Set<String>> collectionRolesByEntityParticipant;
private final Map<String, EntityPersister> entityPersisterMap = new ConcurrentHashMap<>();
private final Map<String, CollectionPersister> collectionPersisterMap = new ConcurrentHashMap<>();
private final Map<String, Set<String>> collectionRolesByEntityParticipant = new ConcurrentHashMap<>();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// DomainMetamodel
private final Set<EntityNameResolver> entityNameResolvers;
private final Map<String,String> imports;
private final Set<EntityNameResolver> entityNameResolvers = new HashSet<>();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -120,19 +135,186 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento
private final Map<String, String[]> 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<PersistentClass> 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<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<String> 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<String> 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<EntityNameResolver> entityNameResolvers) {
if ( persister.getEntityMetamodel() == null || persister.getEntityMetamodel().getTuplizer() == null ) {
return;
}
registerEntityNameResolvers( persister.getEntityMetamodel().getTuplizer(), entityNameResolvers );
}
private static void registerEntityNameResolvers(
EntityTuplizer tuplizer,
Set<EntityNameResolver> 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( );
}

View File

@ -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<J> valueDomainType,
Bindable.BindableType jpaBindableType,
NodeBuilder nodeBuilder) {
Bindable.BindableType jpaBindableType) {
switch ( classification ) {
case BASIC: {
return new BasicSqmPathSource<>(
name,
(BasicDomainType<J>) valueDomainType,
jpaBindableType,
nodeBuilder
jpaBindableType
);
}
case ANY: {
return new AnyMappingSqmPathSource<>(
name,
(AnyMappingDomainType<J>) valueDomainType,
jpaBindableType,
nodeBuilder
jpaBindableType
);
}
case EMBEDDED: {
return new EmbeddedSqmPathSource<>(
name,
(EmbeddableDomainType<J>) valueDomainType,
jpaBindableType,
nodeBuilder
jpaBindableType
);
}
case ENTITY: {
return new EntitySqmPathSource<>(
name,
(EntityDomainType<J>) valueDomainType,
jpaBindableType,
nodeBuilder
jpaBindableType
);
}
default: {

View File

@ -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<J> extends AbstractSqmPathSource<J> {
public EmbeddedSqmPathSource(
String localPathName,
EmbeddableDomainType<J> domainType,
BindableType jpaBindableType,
NodeBuilder nodeBuilder) {
super( localPathName, domainType, jpaBindableType, nodeBuilder );
BindableType jpaBindableType) {
super( localPathName, domainType, jpaBindableType );
}
@Override
@ -47,7 +40,7 @@ public class EmbeddedSqmPathSource<J> extends AbstractSqmPathSource<J> {
lhs.getNavigablePath().append( getPathName() ),
this,
lhs,
getNodeBuilder()
creationState.getCreationContext().getNodeBuilder()
);
}
}

View File

@ -20,9 +20,8 @@ public class EntitySqmPathSource<J> extends AbstractSqmPathSource<J> {
public EntitySqmPathSource(
String localPathName,
EntityDomainType<J> domainType,
BindableType jpaBindableType,
NodeBuilder nodeBuilder) {
super( localPathName, domainType, jpaBindableType, nodeBuilder );
BindableType jpaBindableType) {
super( localPathName, domainType, jpaBindableType );
}
@Override
@ -42,7 +41,7 @@ public class EntitySqmPathSource<J> extends AbstractSqmPathSource<J> {
lhs.getNavigablePath().append( getPathName() ),
this,
lhs,
getNodeBuilder()
creationState.getCreationContext().getNodeBuilder()
);
}
}

View File

@ -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<Class, SqmPolymorphicRootDescriptor<?>> polymorphicEntityReferenceMap = new ConcurrentHashMap<>();
private final Map<Class, String> entityProxyInterfaceMap;
private final Map<Class, String> entityProxyInterfaceMap = new ConcurrentHashMap<>();
private final Map<String, String> nameToImportNameMap;
private final Map<String, String> 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 <X> EntityDomainType<X> 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<NamedEntityGraphDefinition> 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<Class, String> entityProxyInterfaceMap,
JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting,
java.util.Collection<NamedEntityGraphDefinition> namedEntityGraphDefinitions) {
Collection<NamedEntityGraphDefinition> 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
);

View File

@ -31,8 +31,7 @@ class ListAttributeImpl<X, E> extends AbstractPluralAttribute<X, List<E>, E> imp
ValueClassification.BASIC,
getName(),
builder.getListIndexOrMapKeyType(),
BindableType.PLURAL_ATTRIBUTE,
builder.getNodeBuilder()
BindableType.PLURAL_ATTRIBUTE
);
}

View File

@ -28,13 +28,11 @@ class MapAttributeImpl<X, K, V> extends AbstractPluralAttribute<X, Map<K, V>, V>
MapAttributeImpl(PluralAttributeBuilder<X, Map<K, V>, 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
);
}

View File

@ -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<D, C, E, K> {
private final ManagedDomainType<D> declaringType;
private final SimpleDomainType<E> valueType;
private final NodeBuilder nodeBuilder;
private SimpleDomainType<K> listIndexOrMapKeyType;
private AttributeClassification attributeClassification;
@ -42,17 +39,11 @@ public class PluralAttributeBuilder<D, C, E, K> {
ManagedDomainType<D> ownerType,
SimpleDomainType<E> elementType,
JavaTypeDescriptor<C> collectionJavaTypeDescriptor,
SimpleDomainType<K> listIndexOrMapKeyType,
NodeBuilder nodeBuilder) {
SimpleDomainType<K> listIndexOrMapKeyType) {
this.declaringType = ownerType;
this.valueType = elementType;
this.collectionJavaTypeDescriptor = collectionJavaTypeDescriptor;
this.listIndexOrMapKeyType = listIndexOrMapKeyType;
this.nodeBuilder = nodeBuilder;
}
public NodeBuilder getNodeBuilder() {
return nodeBuilder;
}
public ManagedDomainType<D> getDeclaringType() {

View File

@ -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<D,J>
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<D,J>
determineValueClassification( attributeClassification ),
name,
attributeType,
BindableType.SINGULAR_ATTRIBUTE,
nodeBuilder
BindableType.SINGULAR_ATTRIBUTE
);
}
@ -158,8 +155,7 @@ public class SingularAttributeImpl<D,J>
String name,
SimpleDomainType<J> attributeType,
Member member,
AttributeClassification attributeClassification,
NodeBuilder nodeBuilder) {
AttributeClassification attributeClassification) {
super(
declaringType,
name,
@ -168,8 +164,7 @@ public class SingularAttributeImpl<D,J>
member,
true,
false,
false,
nodeBuilder
false
);
}
}
@ -184,8 +179,7 @@ public class SingularAttributeImpl<D,J>
String name,
AttributeClassification attributeClassification,
SimpleDomainType<Y> attributeType,
Member member,
NodeBuilder nodeBuilder) {
Member member) {
super(
declaringType,
name,
@ -194,8 +188,7 @@ public class SingularAttributeImpl<D,J>
member,
false,
true,
false,
nodeBuilder
false
);
}
}

View File

@ -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.
*/
<J> Instantiator<J> getInstantiator();
}

View File

@ -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.
*/
<J> Instantiator<J> getInstantiator();
/**
* Create the delegate capable of producing proxies for the given entity
*/
ProxyFactory generateProxyFactory();
ProxyFactory getProxyFactory();
}

View File

@ -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);
}

View File

@ -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.
*/
<J> Instantiator<J> generateInstantiator();
/**
* Create the property accessor object for the specified attribute
*/
PropertyAccess generatePropertyAccess(Property bootAttributeDescriptor);
PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor);
}

View File

@ -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

View File

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

View File

@ -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.
*/

View File

@ -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);
<T> Query<T> createQuery(CriteriaQuery<T> criteriaQuery);
Query createQuery(CriteriaUpdate updateQuery);

View File

@ -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 );

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -48,6 +48,8 @@ public interface NamedQueryMemento {
Map<String, Object> getHints();
void validate(QueryEngine queryEngine);
interface ParameterMemento {
QueryParameterImplementor resolve(SharedSessionContractImplementor session);
}

View File

@ -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();

View File

@ -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) {

View File

@ -56,4 +56,6 @@ public interface QueryProducerImplementor extends QueryProducer {
@Override
NativeQueryImplementor getNamedNativeQuery(String name);
NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping);
}

View File

@ -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 {
}

View File

@ -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 <T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session) {
//noinspection unchecked
return toQuery( session, (Class) null );
}
@Override
@SuppressWarnings("unchecked")
public <T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session, Class<T> resultType) {
@ -107,8 +120,8 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple
}
@Override
public <T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session) {
//noinspection unchecked
return toQuery( session, null );
@SuppressWarnings("unchecked")
public <T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session, String resultSetMappingName) {
return new NativeQueryImpl( this, resultSetMappingName, session );
}
}

View File

@ -119,7 +119,6 @@ public class NativeQueryImpl<R>
*/
public NativeQueryImpl(
NamedNativeQueryMemento memento,
Class<R> resultJavaType,
SharedSessionContractImplementor session) {
super( session );
@ -132,10 +131,30 @@ public class NativeQueryImpl<R>
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<R> 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();

View File

@ -32,15 +32,20 @@ public interface NamedNativeQueryMemento extends NamedQueryMemento {
*/
Set<String> getQuerySpaces();
/**
* Convert the memento into an untyped executable query
*/
<T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session);
/**
* Convert the memento into a typed executable query
*/
<T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session, Class<T> resultType);
/**
* Convert the memento into an untyped executable query
* Convert the memento into a typed executable query
*/
<T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session);
<T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session, String resultSetMapping);
@Override
NamedNativeQueryMemento makeCopy(String name);

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 )

View File

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

Some files were not shown because too many files have changed in this diff Show More