From ba5ef1b14904a31f9e07b7b3ebc574d315b1f2fd Mon Sep 17 00:00:00 2001
From: Steve Ebersole
Date: Mon, 11 Nov 2019 16:09:11 -0600
Subject: [PATCH] HHH-13715 - working support for "multi-table" HQL/Criteria
UPDATE and DELETE queries;
local-temp-table support works tested on H2. I believe cte support works as well - need to set up and environment with a database supporting it.
There is a problem saving entities with secondary tables atm so for now i cannot create the data to assert that the correct rows were deleted. But looking at the executed SQL it works
---
.../boot/model/relational/Exportable.java | 2 +-
.../dialect/AbstractTransactSQLDialect.java | 26 +-
.../org/hibernate/dialect/Cache71Dialect.java | 4 +-
.../org/hibernate/dialect/DB297Dialect.java | 4 +-
.../org/hibernate/dialect/DB2Dialect.java | 4 +-
.../org/hibernate/dialect/DerbyDialect.java | 48 +--
.../java/org/hibernate/dialect/Dialect.java | 10 +-
.../java/org/hibernate/dialect/H2Dialect.java | 34 +-
.../dialect/HANAColumnStoreDialect.java | 4 +-
.../dialect/HANARowStoreDialect.java | 4 +-
.../org/hibernate/dialect/HSQLDialect.java | 3 +-
.../hibernate/dialect/InformixDialect.java | 40 +-
.../org/hibernate/dialect/IngresDialect.java | 3 +-
.../org/hibernate/dialect/MySQLDialect.java | 41 ++-
.../hibernate/dialect/Oracle8iDialect.java | 3 +-
.../org/hibernate/dialect/Oracle9Dialect.java | 3 +-
.../dialect/PostgreSQL81Dialect.java | 4 +-
.../dialect/PostgreSQL82Dialect.java | 4 +-
.../org/hibernate/dialect/SAPDBDialect.java | 4 +-
.../hibernate/dialect/TeradataDialect.java | 5 +-
.../hibernate/dialect/TimesTenDialect.java | 3 +-
.../engine/jdbc/spi/JdbcServices.java | 4 +
.../hibernate/internal/util/StringHelper.java | 7 +
.../internal/DatabaseSnapshotExecutor.java | 8 +-
.../MetamodelSelectBuilderProcess.java | 3 -
.../SingleIdEntityLoaderDynamicBatch.java | 2 +-
.../loader/internal/SingleIdLoadPlan.java | 2 +-
.../metamodel/mapping/ColumnConsumer.java | 19 +
.../metamodel/mapping/EntityMappingType.java | 8 +
.../mapping/ForeignKeyDescriptor.java | 32 +-
.../metamodel/mapping/ModelPart.java | 19 +-
.../mapping/PluralAttributeMapping.java | 2 +
.../metamodel/mapping/Queryable.java | 1 +
.../BasicValuedSingularAttributeMapping.java | 6 +
.../internal/EmbeddedAttributeMapping.java | 9 +-
.../internal/MappingModelCreationHelper.java | 20 +-
.../internal/PluralAttributeMappingImpl.java | 16 +
.../internal/SimpleForeignKeyDescriptor.java | 59 +++
.../domain/AbstractIdentifiableType.java | 59 ++-
.../model/domain/IdentifiableDomainType.java | 4 +
.../model/domain/internal/EntityTypeImpl.java | 2 +-
.../internal/MappedSuperclassTypeImpl.java | 9 +
.../entity/AbstractEntityPersister.java | 33 +-
.../entity/JoinedSubclassEntityPersister.java | 20 +
.../entity/SingleTableEntityPersister.java | 20 +
.../entity/UnionSubclassEntityPersister.java | 21 ++
.../org/hibernate/query/spi/QueryEngine.java | 34 +-
.../internal/ConcreteSqmSelectQueryPlan.java | 12 +-
.../sqm/internal/SimpleDeleteQueryPlan.java | 10 +-
.../internal/SqmIdSelectGenerator.java | 140 +++++++
.../internal/SqmMutationStrategyHelper.java | 108 ++++--
.../cte/AbstractCteMutationHandler.java | 51 +++
.../cte/CteBasedMutationStrategy.java | 68 +++-
.../internal/cte/CteDeleteHandler.java | 260 +++++++++++++
.../internal/cte/CteUpdateHandler.java | 40 ++
.../idtable/AbstractTableBasedHandler.java | 342 ++++++++++++++++++
.../internal/idtable/AfterUseAction.java | 18 +
.../internal/idtable/BeforeUseAction.java | 17 +
.../mutation/internal/idtable/IdTable.java | 83 +++++
.../internal/idtable/IdTableColumn.java | 51 +++
.../internal/idtable/IdTableExporter.java | 25 ++
.../internal/idtable/IdTableHelper.java | 235 ++++++++++++
.../idtable/IdTableSessionUidColumn.java | 22 ++
.../idtable/LocalTemporaryTableStrategy.java | 57 ++-
.../idtable/PhysicalIdTableExporter.java | 90 +++++
.../idtable/TableBasedDeleteHandler.java | 169 +++++++++
.../internal/idtable/TempIdTableExporter.java | 95 +++++
.../UnrestrictedTableBasedDeleteHandler.java | 96 +++++
.../internal/idtable/package-info.java | 21 ++
.../mutation/spi/AbstractMutationHandler.java | 3 +-
...n.java => SimpleSqmDeleteTranslation.java} | 4 +-
...er.java => SimpleSqmDeleteTranslator.java} | 4 +-
.../sqm/sql/SqmInsertSelectTranslation.java | 37 ++
.../sqm/sql/SqmInsertSelectTranslator.java | 17 +
.../sqm/sql/SqmQuerySpecTranslation.java | 37 ++
...etation.java => SqmSelectTranslation.java} | 8 +-
...onverter.java => SqmSelectTranslator.java} | 6 +-
...nterpretation.java => SqmTranslation.java} | 2 +-
.../query/sqm/sql/SqmTranslatorFactory.java | 11 +-
....java => StandardSqmDeleteTranslator.java} | 22 +-
.../StandardSqmInsertSelectTranslator.java | 92 +++++
....java => StandardSqmSelectTranslator.java} | 28 +-
.../domain/SqmPolymorphicRootDescriptor.java | 5 +
.../sql/ast/SqlAstDeleteTranslator.java | 3 +
.../sql/ast/SqlAstInsertSelectTranslator.java | 18 +
.../sql/ast/SqlAstSelectTranslator.java | 4 +-
.../sql/ast/SqlAstTranslatorFactory.java | 20 +-
...bstractSqlAstToJdbcOperationConverter.java | 10 +-
.../spi/SqlAstToJdbcOperationConverter.java | 5 +-
.../spi/StandardSqlAstDeleteTranslator.java | 53 ++-
.../StandardSqlAstInsertSelectTranslator.java | 64 ++++
.../spi/StandardSqlAstSelectTranslator.java | 17 +-
.../spi/StandardSqlAstTranslatorFactory.java | 11 +-
.../hibernate/sql/ast/tree/cte/CteColumn.java | 37 ++
.../sql/ast/tree/cte/CteStatement.java | 45 +++
.../hibernate/sql/ast/tree/cte/CteTable.java | 193 ++++++++++
.../sql/ast/tree/cte/CteTableGroup.java | 113 ++++++
.../hibernate/sql/exec/spi/JdbcInsert.java | 13 +
.../mapping/SecondaryTableTests.java | 94 +++++
.../orm/test/sql/ast/SmokeTests.java | 16 +-
.../sql/exec/HqlDeleteExecutionTests.java | 76 +++-
101 files changed, 3455 insertions(+), 295 deletions(-)
create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ColumnConsumer.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmIdSelectGenerator.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteDeleteHandler.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteUpdateHandler.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/AbstractTableBasedHandler.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/AfterUseAction.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/BeforeUseAction.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/IdTable.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/IdTableColumn.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/IdTableExporter.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/IdTableHelper.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/IdTableSessionUidColumn.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/PhysicalIdTableExporter.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/TableBasedDeleteHandler.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/TempIdTableExporter.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/UnrestrictedTableBasedDeleteHandler.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/package-info.java
rename hibernate-core/src/main/java/org/hibernate/query/sqm/sql/{SimpleSqmDeleteInterpretation.java => SimpleSqmDeleteTranslation.java} (89%)
rename hibernate-core/src/main/java/org/hibernate/query/sqm/sql/{SimpleSqmDeleteToSqlAstConverter.java => SimpleSqmDeleteTranslator.java} (70%)
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/sql/SqmInsertSelectTranslation.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/sql/SqmInsertSelectTranslator.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/sql/SqmQuerySpecTranslation.java
rename hibernate-core/src/main/java/org/hibernate/query/sqm/sql/{SqmSelectInterpretation.java => SqmSelectTranslation.java} (78%)
rename hibernate-core/src/main/java/org/hibernate/query/sqm/sql/{SqmSelectToSqlAstConverter.java => SqmSelectTranslator.java} (60%)
rename hibernate-core/src/main/java/org/hibernate/query/sqm/sql/{SqmInterpretation.java => SqmTranslation.java} (94%)
rename hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/{StandardSqmDeleteToSqlAstConverter.java => StandardSqmDeleteTranslator.java} (84%)
create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmInsertSelectTranslator.java
rename hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/{StandardSqmSelectToSqlAstConverter.java => StandardSqmSelectTranslator.java} (95%)
create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/ast/SqlAstInsertSelectTranslator.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/ast/spi/StandardSqlAstInsertSelectTranslator.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteColumn.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteStatement.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTable.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTableGroup.java
create mode 100644 hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcInsert.java
create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/SecondaryTableTests.java
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/Exportable.java b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/Exportable.java
index 5a04c4b5a4..82b3817c79 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/Exportable.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/Exportable.java
@@ -19,5 +19,5 @@ public interface Exportable {
*
* @return The exporting identifier.
*/
- public String getExportIdentifier();
+ String getExportIdentifier();
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java
index 80609bb641..94808ed5e0 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java
@@ -15,7 +15,7 @@ import java.util.Map;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
-import org.hibernate.NotYetImplementedFor6Exception;
+import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.CharIndexFunction;
import org.hibernate.dialect.function.NoArgSQLFunction;
@@ -24,7 +24,10 @@ import org.hibernate.dialect.function.StandardSQLFunction;
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.metamodel.mapping.EntityMappingType;
+import org.hibernate.query.sqm.mutation.internal.idtable.AfterUseAction;
+import org.hibernate.query.sqm.mutation.internal.idtable.IdTable;
+import org.hibernate.query.sqm.mutation.internal.idtable.LocalTemporaryTableStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.type.StandardBasicTypes;
@@ -211,20 +214,13 @@ abstract class AbstractTransactSQLDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
- throw new NotYetImplementedFor6Exception( getClass() );
-
-// return new LocalTemporaryTableBulkIdStrategy(
-// new IdTableSupportStandardImpl() {
-// @Override
-// public String generateIdTableName(String baseName) {
-// return "#" + baseName;
-// }
-// },
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType entityDescriptor) {
+ return new LocalTemporaryTableStrategy(
+ new IdTable( entityDescriptor, basename -> "#" + basename ),
// // sql-server, at least needed this dropped after use; strange!
-// AfterUseAction.DROP,
-// TempTableDdlTransactionHandling.NONE
-// );
+ AfterUseAction.DROP,
+ TempTableDdlTransactionHandling.NONE
+ );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java
index a726624850..41830f595a 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java
@@ -38,7 +38,7 @@ import org.hibernate.exception.internal.CacheSQLExceptionConversionDelegate;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
-import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.sql.CacheJoinFragment;
@@ -444,7 +444,7 @@ public class Cache71Dialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new GlobalTemporaryTableBulkIdStrategy(
// new IdTableSupportStandardImpl() {
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java
index 89b599bfbc..69e8ebc7b4 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB297Dialect.java
@@ -10,7 +10,7 @@ import java.sql.Types;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.dialect.function.DB2SubstringFunction;
-import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
import org.hibernate.type.descriptor.sql.ClobTypeDescriptor;
@@ -36,7 +36,7 @@ public class DB297Dialect extends DB2Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// // Starting in DB2 9.7, "real" global temporary tables that can be shared between sessions
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
index bc6059b54f..a8465e953d 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
@@ -33,7 +33,7 @@ import org.hibernate.engine.spi.RowSelection;
import org.hibernate.exception.LockTimeoutException;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
import org.hibernate.internal.util.JdbcExceptionHelper;
-import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorDB2DatabaseImpl;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
@@ -393,7 +393,7 @@ public class DB2Dialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// // Prior to DB2 9.7, "real" global temporary tables that can be shared between sessions
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java
index b699ba9f76..0024ee0182 100755
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java
@@ -13,7 +13,7 @@ import java.sql.Types;
import java.util.Locale;
import org.hibernate.MappingException;
-import org.hibernate.NotYetImplementedFor6Exception;
+import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.dialect.function.AnsiTrimFunction;
import org.hibernate.dialect.function.DerbyConcatFunction;
import org.hibernate.dialect.pagination.AbstractLimitHandler;
@@ -24,7 +24,11 @@ import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
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.metamodel.mapping.EntityMappingType;
+import org.hibernate.query.sqm.mutation.internal.idtable.AfterUseAction;
+import org.hibernate.query.sqm.mutation.internal.idtable.IdTable;
+import org.hibernate.query.sqm.mutation.internal.idtable.LocalTemporaryTableStrategy;
+import org.hibernate.query.sqm.mutation.internal.idtable.TempIdTableExporter;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.DerbyCaseFragment;
@@ -590,31 +594,27 @@ public class DerbyDialect extends DB2Dialect {
* The DECLARE GLOBAL TEMPORARY TABLE statement defines a temporary table for the current connection.
*
*
- * {@link DB2Dialect} returns a {@link org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy} that
+ * {@link DB2Dialect} returns a {@link org.hibernate.query.sqm.mutation.internal.idtable.GlobalTemporaryTableStrategy} that
* will make temporary tables created at startup and hence unavailable for subsequent connections.
* see HHH-10238.
- *
- * @return
- * @param runtimeRootEntityDescriptor
*/
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
- throw new NotYetImplementedFor6Exception( getClass() );
-// return new LocalTemporaryTableBulkIdStrategy(new IdTableSupportStandardImpl() {
-// @Override
-// public String generateIdTableName(String baseName) {
-// return "session." + super.generateIdTableName( baseName );
-// }
-//
-// @Override
-// public String getCreateIdTableCommand() {
-// return "declare global temporary table";
-// }
-//
-// @Override
-// public String getCreateIdTableStatementOptions() {
-// return "not logged";
-// }
-// }, AfterUseAction.CLEAN, null);
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
+ return new LocalTemporaryTableStrategy(
+ new IdTable( rootEntityDescriptor, basename -> "HT_" + basename ),
+ () -> new TempIdTableExporter() {
+ @Override
+ protected String getCreateCommand() {
+ return "declare global temporary table";
+ }
+
+ @Override
+ protected String getCreateOptions() {
+ return "not logged";
+ }
+ },
+ AfterUseAction.CLEAN,
+ TempTableDdlTransactionHandling.NONE
+ );
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
index 52b63c2626..6aac973dc1 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
@@ -92,7 +92,7 @@ import org.hibernate.mapping.Constraint;
import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.Index;
import org.hibernate.mapping.Table;
-import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.procedure.internal.StandardCallableStatementSupport;
import org.hibernate.procedure.spi.CallableStatementSupport;
@@ -101,6 +101,7 @@ import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
+import org.hibernate.query.sqm.sql.internal.StandardSqmSelectTranslator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ANSICaseFragment;
import org.hibernate.sql.ANSIJoinFragment;
@@ -110,10 +111,7 @@ import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.spi.ANSICaseExpressionWalker;
import org.hibernate.sql.ast.spi.CaseExpressionWalker;
-import org.hibernate.sql.ast.spi.SqlAstWalker;
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
-import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression;
-import org.hibernate.sql.ast.tree.expression.Expression;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
@@ -1517,7 +1515,7 @@ public abstract class Dialect implements ConversionContext {
return getCreateTableString();
}
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType entityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
}
@@ -3114,7 +3112,7 @@ public abstract class Dialect implements ConversionContext {
* Note that {@link SessionFactoryOptions#getSqmTranslatorFactory()} has higher
* precedence as it comes directly from the user config
*
- * @see org.hibernate.query.sqm.sql.internal.StandardSqmSelectToSqlAstConverter
+ * @see StandardSqmSelectTranslator
* @see QueryEngine#getSqmTranslatorFactory()
*/
public SqmTranslatorFactory getSqmTranslatorFactory() {
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java
index 83a79d6e3e..8051252090 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java
@@ -10,8 +10,8 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.JDBCException;
-import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.PessimisticLockException;
+import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.function.AvgWithArgumentCastFunction;
import org.hibernate.dialect.function.NoArgSQLFunction;
@@ -32,7 +32,11 @@ import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
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.metamodel.mapping.EntityMappingType;
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.query.sqm.mutation.internal.idtable.AfterUseAction;
+import org.hibernate.query.sqm.mutation.internal.idtable.IdTable;
+import org.hibernate.query.sqm.mutation.internal.idtable.LocalTemporaryTableStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorH2DatabaseImpl;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
@@ -368,26 +372,12 @@ public class H2Dialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
- throw new NotYetImplementedFor6Exception( getClass() );
-
-// return new LocalTemporaryTableBulkIdStrategy(
-// new IdTableSupportStandardImpl() {
-// @Override
-// public String getCreateIdTableCommand() {
-// return "create cached local temporary table if not exists";
-// }
-//
-// @Override
-// public String getCreateIdTableStatementOptions() {
-// // actually 2 different options are specified here:
-// // 1) [on commit drop] - says to drop the table on transaction commit
-// // 2) [transactional] - says to not perform an implicit commit of any current transaction
-// return "on commit drop transactional"; }
-// },
-// AfterUseAction.CLEAN,
-// TempTableDdlTransactionHandling.NONE
-// );
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType entityDescriptor) {
+ return new LocalTemporaryTableStrategy(
+ new IdTable( entityDescriptor, basename -> "HT_" + basename ),
+ AfterUseAction.NONE,
+ TempTableDdlTransactionHandling.NONE
+ );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java
index eb5ddb0a9d..73eb048f3d 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java
@@ -10,7 +10,7 @@ import org.hibernate.NotYetImplementedFor6Exception;
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.metamodel.mapping.EntityMappingType;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.type.StandardBasicTypes;
@@ -48,7 +48,7 @@ public class HANAColumnStoreDialect extends AbstractHANADialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new GlobalTemporaryTableBulkIdStrategy( new IdTableSupportStandardImpl() {
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java
index c0be3951c7..e7540cdf3a 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANARowStoreDialect.java
@@ -7,7 +7,7 @@
package org.hibernate.dialect;
import org.hibernate.NotYetImplementedFor6Exception;
-import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
/**
@@ -36,7 +36,7 @@ public class HANARowStoreDialect extends AbstractHANADialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new GlobalTemporaryTableBulkIdStrategy( new IdTableSupportStandardImpl() {
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java
index 97386e4050..87d8ec9053 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java
@@ -42,6 +42,7 @@ import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.internal.util.ReflectHelper;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
@@ -503,7 +504,7 @@ public class HSQLDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// // Hibernate uses this information for temporary tables that it uses for its own operations
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java
index 8ed3636771..e91008712e 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java
@@ -11,6 +11,7 @@ import java.sql.Types;
import java.util.Locale;
import org.hibernate.NotYetImplementedFor6Exception;
+import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.dialect.function.NvlFunction;
import org.hibernate.dialect.function.SQLFunctionTemplate;
@@ -25,7 +26,11 @@ import org.hibernate.dialect.unique.UniqueDelegate;
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.metamodel.mapping.EntityMappingType;
+import org.hibernate.query.sqm.mutation.internal.idtable.AfterUseAction;
+import org.hibernate.query.sqm.mutation.internal.idtable.IdTable;
+import org.hibernate.query.sqm.mutation.internal.idtable.LocalTemporaryTableStrategy;
+import org.hibernate.query.sqm.mutation.internal.idtable.TempIdTableExporter;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorInformixDatabaseImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
@@ -279,24 +284,23 @@ public class InformixDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
- throw new NotYetImplementedFor6Exception( getClass() );
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
+ return new LocalTemporaryTableStrategy(
+ new IdTable( rootEntityDescriptor, basename -> "HT_" + basename ),
+ () -> new TempIdTableExporter() {
+ @Override
+ protected String getCreateCommand() {
+ return "create temp table";
+ }
-// return new LocalTemporaryTableBulkIdStrategy(
-// new IdTableSupportStandardImpl() {
-// @Override
-// public String getCreateIdTableCommand() {
-// return "create temp table";
-// }
-//
-// @Override
-// public String getCreateIdTableStatementOptions() {
-// return "with no log";
-// }
-// },
-// AfterUseAction.CLEAN,
-// null
-// );
+ @Override
+ protected String getCreateOptions() {
+ return "with no log";
+ }
+ },
+ AfterUseAction.NONE,
+ TempTableDdlTransactionHandling.NONE
+ );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/IngresDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/IngresDialect.java
index a579f476fe..06a2a03bcc 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/IngresDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/IngresDialect.java
@@ -17,6 +17,7 @@ import org.hibernate.dialect.function.VarArgsSQLFunction;
import org.hibernate.dialect.pagination.FirstLimitHandler;
import org.hibernate.dialect.pagination.LegacyFirstLimitHandler;
import org.hibernate.dialect.pagination.LimitHandler;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.tool.schema.extract.internal.SequenceNameExtractorImpl;
@@ -270,7 +271,7 @@ public class IngresDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new GlobalTemporaryTableBulkIdStrategy(
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java
index 7d896e3ba9..f8f8221711 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java
@@ -17,6 +17,7 @@ import org.hibernate.JDBCException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.NullPrecedence;
import org.hibernate.PessimisticLockException;
+import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.dialect.function.StandardSQLFunction;
@@ -33,7 +34,11 @@ import org.hibernate.exception.LockTimeoutException;
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.metamodel.mapping.EntityMappingType;
+import org.hibernate.query.sqm.mutation.internal.idtable.AfterUseAction;
+import org.hibernate.query.sqm.mutation.internal.idtable.IdTable;
+import org.hibernate.query.sqm.mutation.internal.idtable.LocalTemporaryTableStrategy;
+import org.hibernate.query.sqm.mutation.internal.idtable.TempIdTableExporter;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.type.StandardBasicTypes;
@@ -343,24 +348,24 @@ public class MySQLDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
- throw new NotYetImplementedFor6Exception( getClass() );
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
-// return new LocalTemporaryTableBulkIdStrategy(
-// new IdTableSupportStandardImpl() {
-// @Override
-// public String getCreateIdTableCommand() {
-// return "create temporary table if not exists";
-// }
-//
-// @Override
-// public String getDropIdTableCommand() {
-// return "drop temporary table";
-// }
-// },
-// AfterUseAction.DROP,
-// TempTableDdlTransactionHandling.NONE
-// );
+ return new LocalTemporaryTableStrategy(
+ new IdTable( rootEntityDescriptor, basename -> "HT_" + basename ),
+ () -> new TempIdTableExporter() {
+ @Override
+ protected String getCreateCommand() {
+ return "create temporary table if not exists";
+ }
+
+ @Override
+ protected String getDropCommand() {
+ return "drop temporary table";
+ }
+ },
+ AfterUseAction.NONE,
+ TempTableDdlTransactionHandling.NONE
+ );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java
index ea6fa7b403..b50a0f2853 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java
@@ -35,6 +35,7 @@ import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
import org.hibernate.internal.util.JdbcExceptionHelper;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.procedure.internal.StandardCallableStatementSupport;
import org.hibernate.procedure.spi.CallableStatementSupport;
@@ -622,7 +623,7 @@ public class Oracle8iDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new GlobalTemporaryTableBulkIdStrategy(
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java
index 85e09ad0cf..f25fac12cb 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java
@@ -17,6 +17,7 @@ import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.JdbcExceptionHelper;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorOracleDatabaseImpl;
@@ -344,7 +345,7 @@ public class Oracle9Dialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new GlobalTemporaryTableBulkIdStrategy(
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java
index 77aa95f79c..a2e9af88c7 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java
@@ -36,7 +36,7 @@ import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
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.metamodel.mapping.EntityMappingType;
import org.hibernate.procedure.internal.PostgresCallableStatementSupport;
import org.hibernate.procedure.spi.CallableStatementSupport;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
@@ -366,7 +366,7 @@ public class PostgreSQL81Dialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new LocalTemporaryTableBulkIdStrategy(
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java
index 27281b505b..fcf8ccd7bb 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL82Dialect.java
@@ -8,7 +8,7 @@ package org.hibernate.dialect;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.boot.model.TypeContributions;
-import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.metamodel.mapping.EntityMappingType;
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 SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new LocalTemporaryTableBulkIdStrategy(
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SAPDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SAPDBDialect.java
index b28122a793..46816a0b3e 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/SAPDBDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/SAPDBDialect.java
@@ -15,7 +15,7 @@ import org.hibernate.dialect.function.NoArgSQLFunction;
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.metamodel.mapping.EntityMappingType;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.DecodeCaseFragment;
@@ -226,7 +226,7 @@ public class SAPDBDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new LocalTemporaryTableBulkIdStrategy(
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/TeradataDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/TeradataDialect.java
index b1ff43a050..c50a90df27 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/TeradataDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/TeradataDialect.java
@@ -5,6 +5,7 @@
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.dialect;
+
import java.sql.Types;
import org.hibernate.HibernateException;
@@ -12,7 +13,7 @@ import org.hibernate.NotYetImplementedFor6Exception;
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.metamodel.mapping.EntityMappingType;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.type.StandardBasicTypes;
@@ -119,7 +120,7 @@ public class TeradataDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new GlobalTemporaryTableBulkIdStrategy( this, AfterUseAction.CLEAN );
}
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/TimesTenDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/TimesTenDialect.java
index cd50e9b23c..13087d93bb 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/TimesTenDialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/TimesTenDialect.java
@@ -24,6 +24,7 @@ import org.hibernate.dialect.lock.UpdateLockingStrategy;
import org.hibernate.dialect.pagination.FirstLimitHandler;
import org.hibernate.dialect.pagination.LegacyFirstLimitHandler;
import org.hibernate.dialect.pagination.LimitHandler;
+import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
@@ -218,7 +219,7 @@ public class TimesTenDialect extends Dialect {
}
@Override
- public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityPersister runtimeRootEntityDescriptor) {
+ public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType rootEntityDescriptor) {
throw new NotYetImplementedFor6Exception( getClass() );
// return new GlobalTemporaryTableBulkIdStrategy(
diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/JdbcServices.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/JdbcServices.java
index e03d7d725b..2c27c3f527 100644
--- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/JdbcServices.java
+++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/JdbcServices.java
@@ -94,4 +94,8 @@ public interface JdbcServices extends Service {
default JdbcMutationExecutor getJdbcUpdateExecutor() {
return StandardJdbcMutationExecutor.INSTANCE;
}
+
+ default JdbcMutationExecutor getJdbcInsertExecutor() {
+ return StandardJdbcMutationExecutor.INSTANCE;
+ }
}
diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java
index ef0a99b091..b53aa747ff 100644
--- a/hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java
+++ b/hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java
@@ -119,6 +119,13 @@ public final class StringHelper {
return new String( buffer );
}
+ public static void repeat(String string, int times, String separator, StringBuilder buffer) {
+ buffer.append( string );
+ for ( int i = 1; i < times; i++ ) {
+ buffer.append( separator ).append( string );
+ }
+ }
+
public static String replace(String template, String placeholder, String replacement) {
return replace( template, placeholder, replacement, false );
}
diff --git a/hibernate-core/src/main/java/org/hibernate/loader/internal/DatabaseSnapshotExecutor.java b/hibernate-core/src/main/java/org/hibernate/loader/internal/DatabaseSnapshotExecutor.java
index 191d1d88c4..6441822296 100644
--- a/hibernate-core/src/main/java/org/hibernate/loader/internal/DatabaseSnapshotExecutor.java
+++ b/hibernate-core/src/main/java/org/hibernate/loader/internal/DatabaseSnapshotExecutor.java
@@ -100,9 +100,6 @@ class DatabaseSnapshotExecutor {
final NavigablePath idPath = rootPath.append( EntityIdentifierMapping.ROLE_LOCAL_NAME );
entityDescriptor.getIdentifierMapping().visitColumns(
- idPath,
- rootTableGroup,
- state,
(col, tab, jdbcMapping) -> {
final TableReference tableReference = rootTableGroup.resolveTableReference( tab );
@@ -151,9 +148,6 @@ class DatabaseSnapshotExecutor {
contributorMapping -> {
final NavigablePath attrPath = rootPath.append( contributorMapping.getAttributeName() );
contributorMapping.visitColumns(
- attrPath,
- rootTableGroup,
- state,
(columnExpression, containingTableExpression, jdbcMapping) -> {
final TableReference tableReference = rootTableGroup.resolveTableReference(
containingTableExpression );
@@ -203,7 +197,7 @@ class DatabaseSnapshotExecutor {
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
- jdbcSelect = sqlAstTranslatorFactory.buildSelectConverter( sessionFactory ).interpret( selectStatement );
+ jdbcSelect = sqlAstTranslatorFactory.buildSelectTranslator( sessionFactory ).translate( selectStatement );
}
Object[] loadDatabaseSnapshot(Object id, SharedSessionContractImplementor session) {
diff --git a/hibernate-core/src/main/java/org/hibernate/loader/internal/MetamodelSelectBuilderProcess.java b/hibernate-core/src/main/java/org/hibernate/loader/internal/MetamodelSelectBuilderProcess.java
index aef5ba6a44..da66478518 100644
--- a/hibernate-core/src/main/java/org/hibernate/loader/internal/MetamodelSelectBuilderProcess.java
+++ b/hibernate-core/src/main/java/org/hibernate/loader/internal/MetamodelSelectBuilderProcess.java
@@ -252,9 +252,6 @@ public class MetamodelSelectBuilderProcess {
final List columnReferences = new ArrayList<>( numberOfKeyColumns );
keyPart.visitColumns(
- keyPath,
- rootTableGroup,
- sqlAstCreationState,
(columnExpression, containingTableExpression, jdbcMapping) -> {
final TableReference tableReference = rootTableGroup.resolveTableReference( containingTableExpression );
columnReferences.add(
diff --git a/hibernate-core/src/main/java/org/hibernate/loader/internal/SingleIdEntityLoaderDynamicBatch.java b/hibernate-core/src/main/java/org/hibernate/loader/internal/SingleIdEntityLoaderDynamicBatch.java
index c0c438cfe7..6443f34382 100644
--- a/hibernate-core/src/main/java/org/hibernate/loader/internal/SingleIdEntityLoaderDynamicBatch.java
+++ b/hibernate-core/src/main/java/org/hibernate/loader/internal/SingleIdEntityLoaderDynamicBatch.java
@@ -99,7 +99,7 @@ public class SingleIdEntityLoaderDynamicBatch extends SingleIdEntityLoaderSup
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
- final JdbcSelect jdbcSelect = sqlAstTranslatorFactory.buildSelectConverter( sessionFactory ).interpret( sqlAstDescriptor.getSqlAst() );
+ final JdbcSelect jdbcSelect = sqlAstTranslatorFactory.buildSelectTranslator( sessionFactory ).translate( sqlAstDescriptor.getSqlAst() );
final JdbcParameterBindings jdbcParameterBindings = new JdbcParameterBindingsImpl(
getLoadable().getIdentifierMapping().getJdbcTypeCount( sessionFactory.getTypeConfiguration() )
diff --git a/hibernate-core/src/main/java/org/hibernate/loader/internal/SingleIdLoadPlan.java b/hibernate-core/src/main/java/org/hibernate/loader/internal/SingleIdLoadPlan.java
index cb0c0f2b6c..d87eb0b2fd 100644
--- a/hibernate-core/src/main/java/org/hibernate/loader/internal/SingleIdLoadPlan.java
+++ b/hibernate-core/src/main/java/org/hibernate/loader/internal/SingleIdLoadPlan.java
@@ -50,7 +50,7 @@ class SingleIdLoadPlan {
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
- final JdbcSelect jdbcSelect = sqlAstTranslatorFactory.buildSelectConverter( sessionFactory ).interpret( sqlAstDescriptor.getSqlAst() );
+ final JdbcSelect jdbcSelect = sqlAstTranslatorFactory.buildSelectTranslator( sessionFactory ).translate( sqlAstDescriptor.getSqlAst() );
final JdbcParameterBindings jdbcParameterBindings = new JdbcParameterBindingsImpl(
restrictivePart.getJdbcTypeCount( sessionFactory.getTypeConfiguration() )
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ColumnConsumer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ColumnConsumer.java
new file mode 100644
index 0000000000..a4cd790db2
--- /dev/null
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ColumnConsumer.java
@@ -0,0 +1,19 @@
+/*
+ * 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.mapping;
+
+/**
+ * @author Steve Ebersole
+ */
+@FunctionalInterface
+public interface ColumnConsumer {
+ // todo (6.0) : pass values `updateable`, `checkable`, etc
+ void accept(
+ String columnExpression,
+ String containingTableExpression,
+ JdbcMapping jdbcMapping);
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java
index 9643eb54e2..26ae68f998 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java
@@ -152,6 +152,14 @@ public interface EntityMappingType extends ManagedMappingType, Loadable {
// by default do nothing
}
+ default void visitConstraintOrderedTables(ConstraintOrderedTableConsumer consumer) {
+ throw new NotYetImplementedFor6Exception( getClass() );
+ }
+
+ interface ConstraintOrderedTableConsumer {
+ void consume(String tableExpression, Supplier> tableKeyColumnVisitationSupplier);
+ }
+
@Override
default void visitAttributeMappings(Consumer action) {
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ForeignKeyDescriptor.java
index effe568748..3e3e7cefde 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ForeignKeyDescriptor.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ForeignKeyDescriptor.java
@@ -18,7 +18,9 @@ import org.hibernate.sql.results.spi.DomainResultCreationState;
/**
* @author Steve Ebersole
*/
-public interface ForeignKeyDescriptor {
+public interface ForeignKeyDescriptor extends VirtualModelPart {
+ String PART_NAME = "{fk}";
+
DomainResult createDomainResult(NavigablePath collectionPath, TableGroup tableGroup, DomainResultCreationState creationState);
Predicate generateJoinPredicate(
@@ -27,4 +29,32 @@ public interface ForeignKeyDescriptor {
JoinType joinType,
SqlExpressionResolver sqlExpressionResolver,
SqlAstCreationContext creationContext);
+
+ @Override
+ default String getPartName() {
+ return PART_NAME;
+ }
+
+ /**
+ * Visits the FK "referring" columns
+ */
+ @Override
+ default void visitColumns(ColumnConsumer consumer) {
+ visitReferringColumns( consumer );
+ }
+
+ void visitReferringColumns(ColumnConsumer consumer);
+
+ void visitTargetColumns(ColumnConsumer consumer);
+
+ void visitColumnMappings(FkColumnMappingConsumer consumer);
+
+ interface FkColumnMappingConsumer {
+ void consume(
+ String referringTable,
+ String referringColumn,
+ String targetTable,
+ String targetColumn,
+ JdbcMapping jdbcMapping);
+ }
}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java
index 0bee03eb54..d4d8478afc 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java
@@ -7,16 +7,11 @@
package org.hibernate.metamodel.mapping;
import java.util.function.BiConsumer;
-import java.util.function.Consumer;
import org.hibernate.NotYetImplementedFor6Exception;
-import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.NavigablePath;
-import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.from.TableGroup;
-import org.hibernate.sql.ast.tree.predicate.ComparisonPredicate;
-import org.hibernate.sql.ast.tree.predicate.Predicate;
import org.hibernate.sql.results.spi.DomainResult;
import org.hibernate.sql.results.spi.DomainResultCreationState;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
@@ -70,20 +65,8 @@ public interface ModelPart extends MappingModelExpressable {
throw new NotYetImplementedFor6Exception( getClass() );
}
- default void visitColumns(
- NavigablePath navigablePath,
- TableGroup tableGroup,
- DomainResultCreationState creationState,
- ColumnConsumer consumer) {
+ default void visitColumns(ColumnConsumer consumer) {
}
- @FunctionalInterface
- interface ColumnConsumer {
- // todo (6.0) : pass values `updateable`, `checkable`, etc
- void accept(
- String columnExpression,
- String containingTableExpression,
- JdbcMapping jdbcMapping);
- }
}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/PluralAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/PluralAttributeMapping.java
index 36325884a9..b30a84418e 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/PluralAttributeMapping.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/PluralAttributeMapping.java
@@ -41,4 +41,6 @@ public interface PluralAttributeMapping
default void visitFetchables(Consumer fetchableConsumer, EntityMappingType treatTargetType) {
fetchableConsumer.accept( getElementDescriptor() );
}
+
+ String getSeparateCollectionTable();
}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/Queryable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/Queryable.java
index a0555c6f78..3bfe992406 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/Queryable.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/Queryable.java
@@ -7,6 +7,7 @@
package org.hibernate.metamodel.mapping;
import java.util.function.Consumer;
+import java.util.function.Supplier;
import org.hibernate.boot.spi.SessionFactoryOptions;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java
index d4f509facd..c35ef34fe0 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java
@@ -13,6 +13,7 @@ import org.hibernate.engine.FetchStrategy;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
+import org.hibernate.metamodel.mapping.ColumnConsumer;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
@@ -215,4 +216,9 @@ public class BasicValuedSingularAttributeMapping extends AbstractSingularAttribu
TypeConfiguration typeConfiguration) {
action.accept( getJdbcMapping() );
}
+
+ @Override
+ public void visitColumns(ColumnConsumer consumer) {
+ consumer.accept( mappedColumnExpression, tableExpression, jdbcMapping );
+ }
}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java
index 570530fd4f..5c1de3b8a6 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java
@@ -16,6 +16,7 @@ import org.hibernate.engine.FetchStrategy;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.collections.CollectionHelper;
+import org.hibernate.metamodel.mapping.ColumnConsumer;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityMappingType;
@@ -129,12 +130,8 @@ public class EmbeddedAttributeMapping
}
@Override
- public void visitColumns(
- NavigablePath navigablePath,
- TableGroup tableGroup,
- DomainResultCreationState creationState,
- ColumnConsumer consumer) {
- getEmbeddableTypeDescriptor().visitColumns( navigablePath, tableGroup, creationState, consumer );
+ public void visitColumns(ColumnConsumer consumer) {
+ getEmbeddableTypeDescriptor().visitColumns( consumer );
}
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java
index b246125be9..cf35df2831 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java
@@ -25,6 +25,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.FetchStrategy;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
+import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@@ -46,6 +47,7 @@ import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.mapping.CollectionIdentifierDescriptor;
import org.hibernate.metamodel.mapping.CollectionMappingType;
import org.hibernate.metamodel.mapping.CollectionPart;
+import org.hibernate.metamodel.mapping.ColumnConsumer;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
@@ -136,6 +138,11 @@ public class MappingModelCreationHelper {
return 1;
}
+ @Override
+ public void visitColumns(ColumnConsumer consumer) {
+ consumer.accept( getMappedColumnExpression(), getContainingTableExpression(), getJdbcMapping() );
+ }
+
@Override
public void visitJdbcTypes(
Consumer action,
@@ -635,7 +642,7 @@ public class MappingModelCreationHelper {
final CollectionPersister collectionDescriptor = domainModel.findCollectionDescriptor( bootValueMapping.getRole() );
assert collectionDescriptor != null;
- String tableExpression = ( (Joinable) collectionDescriptor ).getTableName();
+ final String tableExpression = ( (Joinable) collectionDescriptor ).getTableName();
final String sqlAliasStem = SqlAliasStemHelper.INSTANCE.generateStemFromAttributeName( bootProperty.getName() );
@@ -823,6 +830,7 @@ public class MappingModelCreationHelper {
return new PluralAttributeMappingImpl(
attrName,
+ bootValueMapping,
propertyAccess,
entityMappingType -> contributorMetadata,
collectionMappingType,
@@ -869,6 +877,7 @@ public class MappingModelCreationHelper {
final BasicValuedModelPart simpleFkTarget = (BasicValuedModelPart) fkTarget;
return new SimpleForeignKeyDescriptor(
+ bootValueMapping.getKey().getTable().getName(),
bootValueMapping.getKey().getColumnIterator().next().getText( dialect ),
simpleFkTarget.getContainingTableExpression(),
simpleFkTarget.getMappedColumnExpression(),
@@ -896,10 +905,19 @@ public class MappingModelCreationHelper {
fkTarget = referencedEntityDescriptor.findSubPart( bootValueMapping.getReferencedPropertyName() );
}
+ final JdbcServices jdbcServices = creationProcess.getCreationContext().getSessionFactory().getJdbcServices();
+
if ( fkTarget instanceof BasicValuedModelPart ) {
final BasicValuedModelPart simpleFkTarget = (BasicValuedModelPart) fkTarget;
return new SimpleForeignKeyDescriptor(
+ creationProcess.getCreationContext()
+ .getBootstrapContext()
+ .getMetadataBuildingOptions()
+ .getPhysicalNamingStrategy().toPhysicalTableName(
+ bootValueMapping.getTable().getNameIdentifier(),
+ jdbcServices.getJdbcEnvironment()
+ ).getText(),
bootValueMapping.getColumnIterator().next().getText( dialect ),
simpleFkTarget.getContainingTableExpression(),
simpleFkTarget.getMappedColumnExpression(),
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java
index bb0727c674..54aa094e4a 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java
@@ -12,6 +12,7 @@ import org.hibernate.LockMode;
import org.hibernate.engine.FetchStrategy;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.CascadeStyle;
+import org.hibernate.mapping.Collection;
import org.hibernate.metamodel.mapping.CollectionIdentifierDescriptor;
import org.hibernate.metamodel.mapping.CollectionMappingType;
import org.hibernate.metamodel.mapping.CollectionPart;
@@ -22,6 +23,7 @@ import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.persister.collection.CollectionPersister;
+import org.hibernate.persister.entity.Joinable;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.query.NavigablePath;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
@@ -59,12 +61,14 @@ public class PluralAttributeMappingImpl extends AbstractAttributeMapping impleme
private final CascadeStyle cascadeStyle;
private final CollectionPersister collectionDescriptor;
+ private final String separateCollectionTable;
private final String sqlAliasStem;
@SuppressWarnings("WeakerAccess")
public PluralAttributeMappingImpl(
String attributeName,
+ Collection bootDescriptor,
PropertyAccess propertyAccess,
StateArrayContributorMetadataAccess stateArrayContributorMetadataAccess,
CollectionMappingType collectionMappingType,
@@ -90,6 +94,13 @@ public class PluralAttributeMappingImpl extends AbstractAttributeMapping impleme
this.collectionDescriptor = collectionDescriptor;
this.sqlAliasStem = SqlAliasStemHelper.INSTANCE.generateStemFromAttributeName( attributeName );
+
+ if ( bootDescriptor.isOneToMany() ) {
+ separateCollectionTable = null;
+ }
+ else {
+ separateCollectionTable = ( (Joinable) collectionDescriptor ).getTableName();
+ }
}
@Override
@@ -122,6 +133,11 @@ public class PluralAttributeMappingImpl extends AbstractAttributeMapping impleme
return identifierDescriptor;
}
+ @Override
+ public String getSeparateCollectionTable() {
+ return separateCollectionTable;
+ }
+
@Override
public int getStateArrayPosition() {
return stateArrayPosition;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java
index 3bfc90389d..b12f0c2c84 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java
@@ -6,10 +6,17 @@
*/
package org.hibernate.metamodel.mapping.internal;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Consumer;
+
+import org.hibernate.engine.spi.SharedSessionContractImplementor;
+import org.hibernate.metamodel.mapping.ColumnConsumer;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.query.ComparisonOperator;
import org.hibernate.query.NavigablePath;
+import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.JoinType;
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
@@ -23,21 +30,26 @@ import org.hibernate.sql.ast.tree.predicate.Predicate;
import org.hibernate.sql.results.internal.domain.basic.BasicResult;
import org.hibernate.sql.results.spi.DomainResult;
import org.hibernate.sql.results.spi.DomainResultCreationState;
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.spi.TypeConfiguration;
/**
* @author Steve Ebersole
*/
public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor {
+ private final String keyColumnContainingTable;
private final String keyColumnExpression;
private final String targetColumnContainingTable;
private final String targetColumnExpression;
private final JdbcMapping jdbcMapping;
public SimpleForeignKeyDescriptor(
+ String keyColumnContainingTable,
String keyColumnExpression,
String targetColumnContainingTable,
String targetColumnExpression,
JdbcMapping jdbcMapping) {
+ this.keyColumnContainingTable = keyColumnContainingTable;
this.keyColumnExpression = keyColumnExpression;
this.targetColumnContainingTable = targetColumnContainingTable;
this.targetColumnExpression = targetColumnExpression;
@@ -114,4 +126,51 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor {
keyReference
);
}
+
+ @Override
+ public JavaTypeDescriptor getJavaTypeDescriptor() {
+ return jdbcMapping.getJavaTypeDescriptor();
+ }
+
+ @Override
+ public void visitReferringColumns(ColumnConsumer consumer) {
+ consumer.accept( keyColumnContainingTable, keyColumnExpression, jdbcMapping );
+ }
+
+ @Override
+ public void visitTargetColumns(ColumnConsumer consumer) {
+ consumer.accept( targetColumnContainingTable, targetColumnExpression, jdbcMapping );
+ }
+
+ @Override
+ public void visitColumnMappings(FkColumnMappingConsumer consumer) {
+ consumer.consume( keyColumnContainingTable, keyColumnExpression, targetColumnContainingTable, targetColumnExpression, jdbcMapping );
+ }
+
+ @Override
+ public int getJdbcTypeCount(TypeConfiguration typeConfiguration) {
+ return 1;
+ }
+
+ @Override
+ public List getJdbcMappings(TypeConfiguration typeConfiguration) {
+ return Collections.singletonList( jdbcMapping );
+ }
+
+ @Override
+ public void visitJdbcTypes(
+ Consumer action,
+ Clause clause,
+ TypeConfiguration typeConfiguration) {
+ action.accept( jdbcMapping );
+ }
+
+ @Override
+ public void visitJdbcValues(
+ Object value,
+ Clause clause,
+ JdbcValuesConsumer valuesConsumer,
+ SharedSessionContractImplementor session) {
+ valuesConsumer.consume( value, jdbcMapping );
+ }
}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java
index ce86916368..89c8f09fb6 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java
@@ -10,12 +10,20 @@ import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
+import javax.persistence.metamodel.Bindable;
import javax.persistence.metamodel.IdentifiableType;
import javax.persistence.metamodel.SingularAttribute;
+import org.hibernate.NotYetImplementedFor6Exception;
+import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.model.domain.internal.AttributeContainer;
+import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource;
+import org.hibernate.metamodel.model.domain.internal.EmbeddedSqmPathSource;
+import org.hibernate.query.sqm.SqmPathSource;
+import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
-import org.hibernate.type.spi.TypeConfiguration;
+
+import org.jboss.logging.Logger;
/**
* Defines commonality for the JPA {@link IdentifiableType} types. JPA defines
@@ -36,6 +44,8 @@ public abstract class AbstractIdentifiableType
private final boolean hasIdClass;
private SingularPersistentAttribute id;
private Set> idClassAttributes;
+ private SqmPathSource identifierDescriptor;
+
private final boolean isVersioned;
private SingularPersistentAttribute versionAttribute;
@@ -66,6 +76,11 @@ public abstract class AbstractIdentifiableType
return (InFlightAccessImpl) super.getInFlightAccess();
}
+ @Override
+ public SqmPathSource getIdentifierDescriptor() {
+ return identifierDescriptor;
+ }
+
public boolean hasIdClass() {
return hasIdClass;
}
@@ -173,7 +188,6 @@ public abstract class AbstractIdentifiableType
*
* @return IdClass attributes or {@code null}
*/
- @SuppressWarnings("unchecked")
public Set> getIdClassAttributesSafely() {
if ( !hasIdClass() ) {
return null;
@@ -335,6 +349,47 @@ public abstract class AbstractIdentifiableType
@Override
public void finishUp() {
managedTypeAccess.finishUp();
+
+ identifierDescriptor = interpretIdDescriptor();
+ }
+ }
+
+ private static final Logger log = Logger.getLogger( AbstractIdentifiableType.class );
+
+ private SqmPathSource interpretIdDescriptor() {
+ log.tracef( "Interpreting domain-model identifier descriptor" );
+
+ if ( getSuperType() != null ) {
+ return getSuperType().getIdentifierDescriptor();
+ }
+ else if ( id != null ) {
+ // simple id or aggregate composite id
+ final SimpleDomainType> type = id.getType();
+ if ( type instanceof BasicDomainType ) {
+ //noinspection unchecked
+ return new BasicSqmPathSource(
+ EntityIdentifierMapping.ROLE_LOCAL_NAME,
+ (BasicDomainType) type,
+ Bindable.BindableType.SINGULAR_ATTRIBUTE
+ );
+ }
+ else {
+ assert type instanceof EmbeddableDomainType;
+ final EmbeddableDomainType compositeType = (EmbeddableDomainType) type;
+ //noinspection unchecked
+ return new EmbeddedSqmPathSource(
+ EntityIdentifierMapping.ROLE_LOCAL_NAME,
+ compositeType,
+ Bindable.BindableType.SINGULAR_ATTRIBUTE
+ );
+ }
+ }
+ else if ( idClassAttributes != null && ! idClassAttributes.isEmpty() ) {
+ // non-aggregate composite id
+ throw new NotYetImplementedFor6Exception( getClass() );
+ }
+ else {
+ throw new UnsupportedOperationException( "Could not build SqmPathSource for entity identifier : " + getTypeName() );
}
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/IdentifiableDomainType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/IdentifiableDomainType.java
index f2d00d8c98..5d2a0c3f34 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/IdentifiableDomainType.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/IdentifiableDomainType.java
@@ -11,12 +11,16 @@ import java.util.function.Consumer;
import javax.persistence.metamodel.IdentifiableType;
import javax.persistence.metamodel.SingularAttribute;
+import org.hibernate.query.sqm.SqmPathSource;
+
/**
* Extension to the JPA {@link IdentifiableType} contract
*
* @author Steve Ebersole
*/
public interface IdentifiableDomainType extends ManagedDomainType, IdentifiableType {
+ SqmPathSource getIdentifierDescriptor();
+
@Override
SingularPersistentAttribute super J, Y> getId(Class type);
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java
index 84ec2b3781..9a92caa6d1 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java
@@ -18,8 +18,8 @@ import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
-import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.hql.spi.SqmCreationState;
+import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java
index 9df376c85f..7e30bbca77 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java
@@ -6,13 +6,22 @@
*/
package org.hibernate.metamodel.model.domain.internal;
+import javax.persistence.metamodel.Bindable;
+
+import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.graph.spi.SubGraphImplementor;
+import org.hibernate.mapping.Component;
import org.hibernate.mapping.MappedSuperclass;
+import org.hibernate.mapping.Property;
+import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
+import org.hibernate.query.sqm.SqmPathSource;
+import org.hibernate.type.BasicType;
+import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
index 3ea3b79fd5..99d715bdb8 100644
--- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
+++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
@@ -130,6 +130,7 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.Formula;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
@@ -166,6 +167,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.Setter;
import org.hibernate.query.ComparisonOperator;
import org.hibernate.query.NavigablePath;
+import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
+import org.hibernate.query.sqm.mutation.internal.cte.CteBasedMutationStrategy;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
import org.hibernate.sql.Alias;
@@ -6189,14 +6192,40 @@ public abstract class AbstractEntityPersister
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory();
if ( isMultiTable() ) {
- sqmMultiTableMutationStrategy = null;
- //sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect().getFallbackSqmMutationStrategy( this )
+ sqmMultiTableMutationStrategy = interpretSqmMultiTableStrategy(
+ this,
+ creationProcess
+ );
}
else {
sqmMultiTableMutationStrategy = null;
}
}
+ protected static SqmMultiTableMutationStrategy interpretSqmMultiTableStrategy(
+ AbstractEntityPersister entityMappingDescriptor,
+ MappingModelCreationProcess creationProcess) {
+ assert entityMappingDescriptor.isMultiTable();
+
+ if ( entityMappingDescriptor.getSuperMappingType() != null ) {
+ return entityMappingDescriptor.getSuperMappingType().getSqmMultiTableMutationStrategy();
+ }
+
+ // we need the boot model so we can have access to the Table
+ final RootClass entityBootDescriptor = (RootClass) creationProcess.getCreationContext()
+ .getBootModel()
+ .getEntityBinding( entityMappingDescriptor.getRootEntityName() );
+ final Table rootTable = entityBootDescriptor.getRootTable();
+
+ return SqmMutationStrategyHelper.resolveStrategy(
+ entityBootDescriptor,
+ entityMappingDescriptor,
+ creationProcess.getCreationContext().getSessionFactory().getSessionFactoryOptions() ,
+ creationProcess.getCreationContext().getSessionFactory().getServiceRegistry()
+ );
+
+ }
+
@Override
public SqmMultiTableMutationStrategy getSqmMultiTableMutationStrategy() {
return sqmMultiTableMutationStrategy;
diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
index cabd9ec268..4dea660c11 100644
--- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
+++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java
@@ -15,6 +15,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -1251,6 +1252,25 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
}
}
+ @Override
+ public void visitConstraintOrderedTables(ConstraintOrderedTableConsumer consumer) {
+ final AtomicInteger tablePositionWrapper = new AtomicInteger( );
+
+ for ( String tableName : constraintOrderedTableNames ) {
+ final int tablePosition = tablePositionWrapper.getAndIncrement();
+
+ consumer.consume(
+ tableName,
+ () -> columnConsumer -> {
+ final String[] keyColumnNames = constraintOrderedKeyColumnNames[tablePosition];
+ for ( String column : keyColumnNames ) {
+ columnConsumer.accept( column, tableName, null );
+ }
+ }
+ );
+ }
+ }
+
private class CaseSearchedExpressionInfo{
CaseSearchedExpression caseSearchedExpression;
List columnReferences = new ArrayList<>( );
diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java
index 3631a9e79c..a8385e35a5 100644
--- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java
+++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java
@@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -919,4 +920,23 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
)
);
}
+
+ @Override
+ public void visitConstraintOrderedTables(ConstraintOrderedTableConsumer consumer) {
+ final AtomicInteger tablePositionWrapper = new AtomicInteger( );
+
+ for ( String tableName : constraintOrderedTableNames ) {
+ final int tablePosition = tablePositionWrapper.getAndIncrement();
+
+ consumer.consume(
+ tableName,
+ () -> columnConsumer -> {
+ final String[] keyColumnNames = constraintOrderedKeyColumnNames[tablePosition];
+ for ( String column : keyColumnNames ) {
+ columnConsumer.accept( column, tableName, null );
+ }
+ }
+ );
+ }
+ }
}
diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java
index f3acc29dd5..ce3d573251 100644
--- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java
+++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java
@@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -417,6 +418,26 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
return isAbstract() || hasSubclasses();
}
+
+ @Override
+ public void visitConstraintOrderedTables(ConstraintOrderedTableConsumer consumer) {
+ final AtomicInteger tablePositionWrapper = new AtomicInteger( );
+
+ for ( String tableName : constraintOrderedTableNames ) {
+ final int tablePosition = tablePositionWrapper.getAndIncrement();
+
+ consumer.consume(
+ tableName,
+ () -> columnConsumer -> {
+ final String[] keyColumnNames = constraintOrderedKeyColumnNames[tablePosition];
+ for ( String column : keyColumnNames ) {
+ columnConsumer.accept( column, tableName, null );
+ }
+ }
+ );
+ }
+ }
+
@Override
protected void buildDiscriminatorMapping() {
if ( hasSubclasses() ) {
diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java
index 0167da915a..73db7f4b65 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java
@@ -33,11 +33,13 @@ import org.hibernate.query.sqm.internal.SqmCreationOptionsStandard;
import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder;
import org.hibernate.query.sqm.produce.function.SqmFunctionRegistry;
import org.hibernate.query.sqm.spi.SqmCreationContext;
-import org.hibernate.query.sqm.sql.SimpleSqmDeleteToSqlAstConverter;
-import org.hibernate.query.sqm.sql.SqmSelectToSqlAstConverter;
+import org.hibernate.query.sqm.sql.SimpleSqmDeleteTranslator;
+import org.hibernate.query.sqm.sql.SqmInsertSelectTranslator;
+import org.hibernate.query.sqm.sql.SqmSelectTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
-import org.hibernate.query.sqm.sql.internal.StandardSqmDeleteToSqlAstConverter;
-import org.hibernate.query.sqm.sql.internal.StandardSqmSelectToSqlAstConverter;
+import org.hibernate.query.sqm.sql.internal.StandardSqmDeleteTranslator;
+import org.hibernate.query.sqm.sql.internal.StandardSqmInsertSelectTranslator;
+import org.hibernate.query.sqm.sql.internal.StandardSqmSelectTranslator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
@@ -145,16 +147,15 @@ public class QueryEngine {
return dialect.getSqmTranslatorFactory();
}
- //noinspection Convert2Lambda
return new SqmTranslatorFactory() {
@Override
- public SqmSelectToSqlAstConverter createSelectConverter(
+ public SqmSelectTranslator createSelectTranslator(
QueryOptions queryOptions,
DomainParameterXref domainParameterXref,
QueryParameterBindings domainParameterBindings,
LoadQueryInfluencers influencers,
SqlAstCreationContext creationContext) {
- return new StandardSqmSelectToSqlAstConverter(
+ return new StandardSqmSelectTranslator(
queryOptions,
domainParameterXref,
domainParameterBindings,
@@ -164,13 +165,28 @@ public class QueryEngine {
}
@Override
- public SimpleSqmDeleteToSqlAstConverter createSimpleDeleteConverter(
+ public SimpleSqmDeleteTranslator createSimpleDeleteTranslator(
QueryOptions queryOptions,
DomainParameterXref domainParameterXref,
QueryParameterBindings domainParameterBindings,
LoadQueryInfluencers influencers,
SqlAstCreationContext creationContext) {
- return new StandardSqmDeleteToSqlAstConverter(
+ return new StandardSqmDeleteTranslator(
+ creationContext,
+ queryOptions,
+ domainParameterXref,
+ domainParameterBindings
+ );
+ }
+
+ @Override
+ public SqmInsertSelectTranslator createInsertSelectTranslator(
+ QueryOptions queryOptions,
+ DomainParameterXref domainParameterXref,
+ QueryParameterBindings domainParameterBindings,
+ LoadQueryInfluencers influencers,
+ SqlAstCreationContext creationContext) {
+ return new StandardSqmInsertSelectTranslator(
creationContext,
queryOptions,
domainParameterXref,
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java
index ce4f499483..e87fab86d0 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java
@@ -25,9 +25,9 @@ import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterImplementor;
import org.hibernate.query.spi.ScrollableResultsImplementor;
import org.hibernate.query.spi.SelectQueryPlan;
-import org.hibernate.query.sqm.sql.SqmSelectToSqlAstConverter;
+import org.hibernate.query.sqm.sql.SqmSelectTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
-import org.hibernate.query.sqm.sql.SqmSelectInterpretation;
+import org.hibernate.query.sqm.sql.SqmSelectTranslation;
import org.hibernate.query.sqm.tree.SqmStatement;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
@@ -164,7 +164,7 @@ public class ConcreteSqmSelectQueryPlan implements SelectQueryPlan {
final SqmTranslatorFactory sqmTranslatorFactory = queryEngine.getSqmTranslatorFactory();
- final SqmSelectToSqlAstConverter sqmConverter = sqmTranslatorFactory.createSelectConverter(
+ final SqmSelectTranslator sqmConverter = sqmTranslatorFactory.createSelectTranslator(
executionContext.getQueryOptions(),
domainParameterXref,
executionContext.getQueryParameterBindings(),
@@ -172,14 +172,14 @@ public class ConcreteSqmSelectQueryPlan implements SelectQueryPlan {
sessionFactory
);
- final SqmSelectInterpretation interpretation = sqmConverter.interpret( sqm );
+ final SqmSelectTranslation interpretation = sqmConverter.translate( sqm );
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
- jdbcSelect = sqlAstTranslatorFactory.buildSelectConverter( sessionFactory )
- .interpret( interpretation.getSqlAst() );
+ jdbcSelect = sqlAstTranslatorFactory.buildSelectTranslator( sessionFactory )
+ .translate( interpretation.getSqlAst() );
this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(
domainParameterXref,
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java
index b79c690ca5..b96034394d 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java
@@ -16,8 +16,8 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.spi.NonSelectQueryPlan;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.spi.QueryParameterImplementor;
-import org.hibernate.query.sqm.sql.SimpleSqmDeleteInterpretation;
-import org.hibernate.query.sqm.sql.SimpleSqmDeleteToSqlAstConverter;
+import org.hibernate.query.sqm.sql.SimpleSqmDeleteTranslation;
+import org.hibernate.query.sqm.sql.SimpleSqmDeleteTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
@@ -55,7 +55,7 @@ public class SimpleDeleteQueryPlan implements NonSelectQueryPlan {
final QueryEngine queryEngine = factory.getQueryEngine();
final SqmTranslatorFactory converterFactory = queryEngine.getSqmTranslatorFactory();
- final SimpleSqmDeleteToSqlAstConverter converter = converterFactory.createSimpleDeleteConverter(
+ final SimpleSqmDeleteTranslator converter = converterFactory.createSimpleDeleteTranslator(
executionContext.getQueryOptions(),
domainParameterXref,
executionContext.getQueryParameterBindings(),
@@ -63,12 +63,12 @@ public class SimpleDeleteQueryPlan implements NonSelectQueryPlan {
factory
);
- final SimpleSqmDeleteInterpretation sqmInterpretation = converter.interpret( sqmDelete );
+ final SimpleSqmDeleteTranslation sqmInterpretation = converter.translate( sqmDelete );
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
- final SqlAstDeleteTranslator sqlAstTranslator = sqlAstTranslatorFactory.buildDeleteConverter( factory );
+ final SqlAstDeleteTranslator sqlAstTranslator = sqlAstTranslatorFactory.buildDeleteTranslator( factory );
jdbcDelete = sqlAstTranslator.translate( sqmInterpretation.getSqlAst() );
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmIdSelectGenerator.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmIdSelectGenerator.java
new file mode 100644
index 0000000000..bf678bb903
--- /dev/null
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmIdSelectGenerator.java
@@ -0,0 +1,140 @@
+/*
+ * 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;
+
+import org.hibernate.engine.spi.SessionFactoryImplementor;
+import org.hibernate.internal.util.collections.Stack;
+import org.hibernate.internal.util.collections.StandardStack;
+import org.hibernate.metamodel.model.domain.EntityDomainType;
+import org.hibernate.query.hql.spi.SqmCreationOptions;
+import org.hibernate.query.hql.spi.SqmCreationProcessingState;
+import org.hibernate.query.hql.spi.SqmCreationState;
+import org.hibernate.query.sqm.SqmQuerySource;
+import org.hibernate.query.sqm.internal.SqmQuerySpecCreationProcessingStateStandardImpl;
+import org.hibernate.query.sqm.mutation.internal.idtable.IdTableSessionUidColumn;
+import org.hibernate.query.sqm.spi.SqmCreationContext;
+import org.hibernate.query.sqm.tree.SqmDeleteOrUpdateStatement;
+import org.hibernate.query.sqm.tree.domain.SqmPath;
+import org.hibernate.query.sqm.tree.expression.SqmLiteral;
+import org.hibernate.query.sqm.tree.from.SqmFromClause;
+import org.hibernate.query.sqm.tree.from.SqmRoot;
+import org.hibernate.query.sqm.tree.select.SqmQuerySpec;
+import org.hibernate.query.sqm.tree.select.SqmSelectClause;
+import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
+import org.hibernate.query.sqm.tree.select.SqmSelection;
+import org.hibernate.sql.exec.spi.ExecutionContext;
+import org.hibernate.type.StringType;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Helper used to generate the SELECT for selection of an entity's
+ * identifier, here specifically intended to be used as the SELECT
+ * portion of a multi-table SQM mutation
+ *
+ * @author Steve Ebersole
+ */
+public class SqmIdSelectGenerator {
+ private static final Logger log = Logger.getLogger( SqmIdSelectGenerator.class );
+
+ public static SqmQuerySpec generateSqmEntityIdSelect(
+ SqmDeleteOrUpdateStatement sqmStatement,
+ ExecutionContext executionContext,
+ SessionFactoryImplementor sessionFactory) {
+ final SqmIdSelectGenerator generator = new SqmIdSelectGenerator( sqmStatement, executionContext, sessionFactory );
+ return generator.process();
+ }
+
+ private final SqmDeleteOrUpdateStatement sourceSqmStatement;
+ private final ExecutionContext executionContext;
+ private final SqmCreationContext creationContext;
+ private final EntityDomainType entityType;
+
+ public SqmIdSelectGenerator(
+ SqmDeleteOrUpdateStatement sourceSqmStatement,
+ ExecutionContext executionContext,
+ SqmCreationContext creationContext) {
+ this.sourceSqmStatement = sourceSqmStatement;
+ this.executionContext = executionContext;
+ this.creationContext = creationContext;
+
+ final String targetEntityName = sourceSqmStatement.getTarget().getEntityName();
+ this.entityType = creationContext.getJpaMetamodel().entity( targetEntityName );
+ }
+
+ private SqmQuerySpec process() {
+ final SqmQuerySpec sqmQuerySpec = new SqmQuerySpec( creationContext.getNodeBuilder() );
+
+
+ final Stack processingStateStack = new StandardStack<>();
+
+ final SqmCreationState creationState = new SqmCreationState() {
+ @Override
+ public SqmCreationContext getCreationContext() {
+ return creationContext;
+ }
+
+ @Override
+ public SqmCreationOptions getCreationOptions() {
+ return () -> false;
+ }
+
+ @Override
+ public Stack getProcessingStateStack() {
+ return processingStateStack;
+ }
+ };
+
+ // temporary - used just for creating processingState
+ final SqmSelectStatement sqmSelectStatement = new SqmSelectStatement( creationContext.getNodeBuilder() );
+ //noinspection unchecked
+ sqmSelectStatement.setQuerySpec( sqmQuerySpec );
+
+ final SqmCreationProcessingState processingState = new SqmQuerySpecCreationProcessingStateStandardImpl(
+ null,
+ sqmSelectStatement,
+ creationState
+ );
+
+ processingStateStack.push( processingState );
+
+ final SqmFromClause sqmFromClause = new SqmFromClause();
+ sqmQuerySpec.setFromClause( sqmFromClause );
+
+ //noinspection unchecked
+ final SqmRoot> sqmRoot = new SqmRoot( entityType, null, sourceSqmStatement.nodeBuilder() );
+ sqmFromClause.addRoot( sqmRoot );
+
+ final SqmSelectClause sqmSelectClause = new SqmSelectClause( true, creationContext.getNodeBuilder() );
+ sqmQuerySpec.setSelectClause( sqmSelectClause );
+ applySelections( sqmQuerySpec, sqmRoot, processingState );
+
+ if ( sourceSqmStatement.getWhereClause() != null ) {
+ sqmQuerySpec.applyPredicate( sourceSqmStatement.getWhereClause().getPredicate() );
+ }
+
+ return sqmQuerySpec;
+ }
+
+ private void applySelections(
+ SqmQuerySpec sqmQuerySpec,
+ SqmRoot> sqmRoot,
+ SqmCreationProcessingState processingState) {
+ //noinspection unchecked
+ final SqmPath idPath = entityType.getIdentifierDescriptor().createSqmPath( sqmRoot, processingState.getCreationState() );
+
+ //noinspection unchecked
+ sqmQuerySpec.getSelectClause().add(
+ new SqmSelection(
+ idPath,
+ null,
+ processingState.getCreationState().getCreationContext().getNodeBuilder()
+ )
+ );
+ }
+
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java
index d6abf8e453..93fe9bf55c 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java
@@ -7,30 +7,46 @@
package org.hibernate.query.sqm.mutation.internal;
import java.util.List;
+import java.util.Map;
-import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.boot.spi.SessionFactoryOptions;
+import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.RootClass;
import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.query.spi.QueryEngine;
+import org.hibernate.query.spi.QueryParameterImplementor;
import org.hibernate.query.sqm.internal.DomainParameterXref;
+import org.hibernate.query.sqm.internal.SqmUtil;
+import org.hibernate.query.sqm.mutation.internal.idtable.IdTable;
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.sql.SqmSelectTranslation;
+import org.hibernate.query.sqm.sql.SqmSelectTranslator;
+import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
import org.hibernate.query.sqm.tree.SqmDeleteOrUpdateStatement;
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
import org.hibernate.query.sqm.tree.domain.SqmSimplePath;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
+import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.query.sqm.tree.predicate.SqmBetweenPredicate;
+import org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmGroupedPredicate;
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.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.exec.spi.ExecutionContext;
+import org.hibernate.sql.exec.spi.JdbcParameter;
+import org.hibernate.sql.exec.spi.JdbcParameterBindings;
+import org.hibernate.sql.exec.spi.JdbcSelect;
/**
* @author Steve Ebersole
@@ -49,7 +65,7 @@ public class SqmMutationStrategyHelper {
* entity hierarchy.
*/
public static SqmMultiTableMutationStrategy resolveStrategy(
- RootClass bootRootEntityDescriptor,
+ RootClass bootEntityDescriptor,
EntityPersister runtimeRootEntityDescriptor,
SessionFactoryOptions options,
ServiceRegistry serviceRegistry) {
@@ -213,43 +229,59 @@ public class SqmMutationStrategyHelper {
* or UPDATE SQM query
*/
public static List