diff --git a/documentation/src/test/java/org/hibernate/userguide/hql/HQLTest.java b/documentation/src/test/java/org/hibernate/userguide/hql/HQLTest.java index 01f45412fe..775b040039 100644 --- a/documentation/src/test/java/org/hibernate/userguide/hql/HQLTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/hql/HQLTest.java @@ -32,6 +32,7 @@ import org.hibernate.dialect.OracleDialect; import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; +import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StringType; import org.hibernate.userguide.model.AddressType; import org.hibernate.userguide.model.Call; @@ -771,7 +772,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase { "select p " + "from Person p " + "where p.name like :name" ) - .setParameter( "name", "J%", StringType.INSTANCE ); + .setParameter( "name", "J%", StandardBasicTypes.STRING ); //end::hql-api-parameter-example[] }); } diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetUserType.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetUserType.java index ca0fc7187e..5ebbae2528 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetUserType.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetUserType.java @@ -27,7 +27,7 @@ public class BitSetUserType implements UserType { @Override public int[] sqlTypes() { - return new int[] {StringType.INSTANCE.getJdbcTypeDescriptor().getDefaultSqlTypeCode()}; + return new int[] { Types.VARCHAR }; } @Override diff --git a/documentation/src/test/java/org/hibernate/userguide/sql/SQLTest.java b/documentation/src/test/java/org/hibernate/userguide/sql/SQLTest.java index 4bf4d1aaa9..cb1ac11e4e 100644 --- a/documentation/src/test/java/org/hibernate/userguide/sql/SQLTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/sql/SQLTest.java @@ -21,6 +21,7 @@ import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.hibernate.loader.NonUniqueDiscoveredSqlAliasException; import org.hibernate.transform.Transformers; import org.hibernate.type.LongType; +import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StringType; import org.hibernate.userguide.model.AddressType; import org.hibernate.userguide.model.Call; @@ -215,8 +216,8 @@ public class SQLTest extends BaseEntityManagerFunctionalTestCase { //tag::sql-hibernate-scalar-query-explicit-result-set-example[] List persons = session.createNativeQuery( "SELECT * FROM Person" ) - .addScalar( "id", LongType.INSTANCE ) - .addScalar( "name", StringType.INSTANCE ) + .addScalar( "id", StandardBasicTypes.LONG ) + .addScalar( "name", StandardBasicTypes.STRING ) .list(); for(Object[] person : persons) { @@ -236,7 +237,7 @@ public class SQLTest extends BaseEntityManagerFunctionalTestCase { //tag::sql-hibernate-scalar-query-partial-explicit-result-set-example[] List persons = session.createNativeQuery( "SELECT * FROM Person" ) - .addScalar( "id", LongType.INSTANCE ) + .addScalar( "id", StandardBasicTypes.LONG ) .addScalar( "name" ) .list(); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java index 842fb57028..89f960ee65 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java @@ -152,7 +152,7 @@ public class CacheDialect extends Dialect { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ), "$find(?2,?1)", "$find(?2,?1,?3)" ).setArgumentListSignature("(pattern, string[, start])"); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java index 786cb1911b..9f717403e0 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java @@ -52,12 +52,16 @@ import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.community.dialect.sequence.SequenceInformationExtractorFirebirdDatabaseImpl; import org.hibernate.tool.schema.extract.internal.SequenceNameExtractorImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry; +import org.hibernate.type.spi.TypeConfiguration; import java.sql.DatabaseMetaData; import java.sql.SQLException; +import java.sql.Timestamp; import java.sql.Types; import java.time.temporal.TemporalAccessor; import java.util.Arrays; @@ -227,6 +231,13 @@ public class FirebirdDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType byteArrayType = basicTypeRegistry.resolve( StandardBasicTypes.BINARY ); + final BasicType integerType = basicTypeRegistry.resolve( StandardBasicTypes.INTEGER ); + final BasicType shortType = basicTypeRegistry.resolve( StandardBasicTypes.SHORT ); + final BasicType doubleType = basicTypeRegistry.resolve( StandardBasicTypes.DOUBLE ); + final BasicType characterType = basicTypeRegistry.resolve( StandardBasicTypes.CHARACTER ); + CommonFunctionFactory.concat_pipeOperator( queryEngine ); CommonFunctionFactory.cot( queryEngine ); CommonFunctionFactory.cosh( queryEngine ); @@ -260,30 +271,30 @@ public class FirebirdDialect extends Dialect { SqmFunctionRegistry functionRegistry = queryEngine.getSqmFunctionRegistry(); functionRegistry.registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + integerType, "position(?1 in ?2)", "position(?1,?2,?3)" ).setArgumentListSignature( "(pattern, string[, start])" ); functionRegistry.namedDescriptorBuilder( "ascii_val" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.SHORT ) + .setInvariantType( shortType ) .register(); functionRegistry.registerAlternateKey( "ascii", "ascii_val" ); functionRegistry.namedDescriptorBuilder( "ascii_char" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.CHARACTER ) + .setInvariantType( characterType ) .register(); functionRegistry.registerAlternateKey( "chr", "ascii_char" ); functionRegistry.registerAlternateKey( "char", "ascii_char" ); functionRegistry.registerPattern( "radians", "((?1)*pi()/180e0)", - StandardBasicTypes.DOUBLE + doubleType ); functionRegistry.registerPattern( "degrees", "((?1)*180e0/pi())", - StandardBasicTypes.DOUBLE + doubleType ); if ( getVersion() >= 400 ) { @@ -291,13 +302,13 @@ public class FirebirdDialect extends Dialect { .forEach( hash -> functionRegistry.registerPattern( hash, "crypt_hash(?1 using " + hash + ")", - StandardBasicTypes.BINARY + byteArrayType ) ); functionRegistry.registerAlternateKey( "sha", "sha1" ); functionRegistry.registerPattern( "crc32", "hash(?1 using crc32)", - StandardBasicTypes.INTEGER + integerType ); } } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java index 01f1816d57..7874c4c7be 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java @@ -167,7 +167,7 @@ public class InformixDialect extends Dialect { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ), "instr(?2,?1)", "instr(?2,?1,?3)" ).setArgumentListSignature("(pattern, string[, start])"); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java index 8b8f20a815..5b1fae7e4d 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java @@ -48,6 +48,8 @@ import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.tool.schema.extract.internal.SequenceNameExtractorImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry; @@ -217,6 +219,9 @@ public class IngresDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Common functions @@ -247,20 +252,22 @@ public class IngresDialect extends Dialect { CommonFunctionFactory.dateTrunc( queryEngine ); CommonFunctionFactory.bitLength_pattern( queryEngine, "octet_length(hex(?1))*4" ); + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + integerType, "position(?1 in ?2)", "(position(?1 in substring(?2 from ?3))+(?3)-1)" ).setArgumentListSignature("(pattern, string[, start])"); - queryEngine.getSqmFunctionRegistry().registerPattern( "extract", "date_part('?1',?2)", StandardBasicTypes.INTEGER ); + queryEngine.getSqmFunctionRegistry().registerPattern( "extract", "date_part('?1',?2)", integerType ); CommonFunctionFactory.bitandorxornot_bitAndOrXorNot(queryEngine); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "squeeze" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .register(); } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java index 5ff8116898..335430e07b 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MaxDBDialect.java @@ -28,6 +28,7 @@ import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.community.dialect.sequence.SequenceInformationExtractorSAPDBDatabaseImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; +import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry; @@ -131,20 +132,22 @@ public class MaxDBDialect extends Dialect { CommonFunctionFactory.adddateSubdateAddtimeSubtime( queryEngine ); CommonFunctionFactory.addMonths( queryEngine ); - queryEngine.getSqmFunctionRegistry().registerPattern( "extract", "?1(?2)", StandardBasicTypes.INTEGER ); + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); + queryEngine.getSqmFunctionRegistry().registerPattern( "extract", "?1(?2)", integerType ); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "nullif", "case ?1 when ?2 then null else ?1 end" ) .setExactArgumentCount(2) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "index" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setArgumentCountBetween( 2, 4 ) .register(); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, "index(?2,?1)", "index(?2,?1,?3)" + integerType, "index(?2,?1)", "index(?2,?1,?3)" ).setArgumentListSignature("(pattern, string[, start])"); } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java index d6de9a3259..e654725fd3 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java @@ -48,6 +48,8 @@ import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory; import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.exec.spi.JdbcOperation; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.jdbc.BlobJdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.ClobJdbcTypeDescriptor; @@ -235,6 +237,10 @@ public class SQLiteDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); + final BasicType integerType = basicTypeRegistry.resolve( StandardBasicTypes.INTEGER ); + CommonFunctionFactory.mod_operator( queryEngine ); CommonFunctionFactory.leftRight_substr( queryEngine ); CommonFunctionFactory.concat_pipeOperator( queryEngine ); @@ -252,25 +258,25 @@ public class SQLiteDialect extends Dialect { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + integerType, "instr(?2,?1)", "instr(?2,?1,?3)" ).setArgumentListSignature("(pattern, string[, start])"); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "lpad", - StandardBasicTypes.STRING, + stringType, "(substr(replace(hex(zeroblob(?2)),'00',' '),1,?2-length(?1))||?1)", "(substr(replace(hex(zeroblob(?2)),'00',?3),1,?2-length(?1))||?1)" ).setArgumentListSignature("(string, length[, padding])"); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "rpad", - StandardBasicTypes.STRING, + stringType, "(?1||substr(replace(hex(zeroblob(?2)),'00',' '),1,?2-length(?1)))", "(?1||substr(replace(hex(zeroblob(?2)),'00',?3),1,?2-length(?1)))" ).setArgumentListSignature("(string, length[, padding])"); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("format", "strftime") - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature("(datetime as pattern)") .register(); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java index 6ba1805f53..3f7c8621cb 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java @@ -43,6 +43,8 @@ import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.tool.schema.internal.StandardIndexExporter; import org.hibernate.tool.schema.spi.Exporter; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry; @@ -234,6 +236,8 @@ public class TeradataDialect extends Dialect { @Override public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); CommonFunctionFactory.concat_pipeOperator( queryEngine ); CommonFunctionFactory.octetLength( queryEngine ); @@ -246,7 +250,7 @@ public class TeradataDialect extends Dialect { CommonFunctionFactory.bitLength_pattern( queryEngine, "octet_length(cast(?1 as char))*4" ); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "mod", "(?1 mod ?2)" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .register(); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java index 1da67a54ae..36db3f3f29 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TimesTenDialect.java @@ -151,7 +151,7 @@ public class TimesTenDialect extends Dialect { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ), "instr(?2,?1)", "instr(?2,?1,?3)" ).setArgumentListSignature("(pattern, string[, start])"); diff --git a/hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixDialectTestCase.java b/hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixDialectTestCase.java index fb40e6b988..46d05b8a05 100644 --- a/hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixDialectTestCase.java +++ b/hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixDialectTestCase.java @@ -18,7 +18,13 @@ import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.ast.spi.SqlAppender; +import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.descriptor.java.DateJavaTypeDescriptor; +import org.hibernate.type.descriptor.java.JdbcDateJavaTypeDescriptor; +import org.hibernate.type.descriptor.java.JdbcTimestampJavaTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.DateJdbcTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.TimestampJdbcTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.testing.TestForIssue; @@ -28,6 +34,7 @@ import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Testing of patched support for Informix boolean type; see HHH-9894, HHH-10800 @@ -85,9 +92,11 @@ public class InformixDialectTestCase extends BaseUnitTestCase { SelfRenderingSqmFunction sqmExpression = functionDescriptor.generateSqmExpression( null, queryEngine, - null + new TypeConfiguration() ); - assertEquals( StandardBasicTypes.TIMESTAMP, sqmExpression.getNodeType() ); + BasicType basicType = (BasicType) sqmExpression.getNodeType(); + assertEquals( DateJavaTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); + assertEquals( TimestampJdbcTypeDescriptor.INSTANCE, basicType.getJdbcTypeDescriptor() ); SqlAppender appender = new StringBuilderSqlAppender(); sqmExpression.getRenderingSupport().render( appender, Collections.emptyList(), null ); @@ -102,9 +111,11 @@ public class InformixDialectTestCase extends BaseUnitTestCase { SelfRenderingSqmFunction sqmExpression = functionDescriptor.generateSqmExpression( null, queryEngine, - null + new TypeConfiguration() ); - assertEquals( StandardBasicTypes.DATE, sqmExpression.getNodeType() ); + BasicType basicType = (BasicType) sqmExpression.getNodeType(); + assertEquals( DateJavaTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); + assertEquals( DateJdbcTypeDescriptor.INSTANCE, basicType.getJdbcTypeDescriptor() ); SqlAppender appender = new StringBuilderSqlAppender(); sqmExpression.getRenderingSupport().render( appender, Collections.emptyList(), null ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java index bbc244cd93..93b9ae6972 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java @@ -749,6 +749,11 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont return basicTypeRegistrations; } + @Override + public TypeConfiguration getTypeConfiguration() { + return bootstrapContext.getTypeConfiguration(); + } + @Override public ReflectionManager getReflectionManager() { return bootstrapContext.getReflectionManager(); @@ -887,7 +892,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont } } - public void setBootstrapContext(BootstrapContextImpl bootstrapContext) { + public void setBootstrapContext(BootstrapContext bootstrapContext) { this.bootstrapContext = bootstrapContext; } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/FunctionContributions.java b/hibernate-core/src/main/java/org/hibernate/boot/model/FunctionContributions.java new file mode 100644 index 0000000000..3446a4e1e0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/FunctionContributions.java @@ -0,0 +1,24 @@ +/* + * 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 . + */ +package org.hibernate.boot.model; + +import org.hibernate.query.sqm.function.SqmFunctionRegistry; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.type.spi.TypeConfiguration; + +/** + * Defines the target contributing functions, whether via dialects or {@link FunctionContributor} + * + * @author Christian Beikov + */ +public interface FunctionContributions { + TypeConfiguration getTypeConfiguration(); + + SqmFunctionRegistry getFunctionRegistry(); + + ServiceRegistry getServiceRegistry(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/FunctionContributor.java b/hibernate-core/src/main/java/org/hibernate/boot/model/FunctionContributor.java index 29fbfeeeac..1e1a3d1d2e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/FunctionContributor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/FunctionContributor.java @@ -27,10 +27,9 @@ public interface FunctionContributor { /** * Contribute functions * - * @param functionRegistry The target for the contributions - * @param serviceRegistry The service registry + * @param functionContributions The target for the contributions */ - void contributeFunctions(SqmFunctionRegistry functionRegistry, ServiceRegistry serviceRegistry); + void contributeFunctions(FunctionContributions functionContributions); /** * Determines order in which the contributions will be applied (lowest ordinal first). diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/VersionResolution.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/VersionResolution.java index c3986f1cfa..9bcd979b19 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/VersionResolution.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/VersionResolution.java @@ -14,12 +14,10 @@ import org.hibernate.mapping.BasicValue; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; import org.hibernate.type.BasicType; -import org.hibernate.type.RowVersionType; import org.hibernate.type.descriptor.java.BasicJavaTypeDescriptor; import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.MutabilityPlan; -import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; import org.hibernate.type.spi.TypeConfiguration; @@ -45,16 +43,6 @@ public class VersionResolution implements BasicValue.Resolution { final java.lang.reflect.Type implicitJavaType = implicitJavaTypeAccess.apply( typeConfiguration ); final JavaTypeDescriptor registered = typeConfiguration.getJavaTypeDescriptorRegistry().resolveDescriptor( implicitJavaType ); - - if ( registered instanceof PrimitiveByteArrayJavaTypeDescriptor ) { - return new VersionResolution<>( - RowVersionType.INSTANCE.getJavaTypeDescriptor(), - RowVersionType.INSTANCE.getJdbcTypeDescriptor(), - RowVersionType.INSTANCE, - RowVersionType.INSTANCE - ); - } - final BasicJavaTypeDescriptor jtd = (BasicJavaTypeDescriptor) registered; final JdbcTypeDescriptor recommendedJdbcType = jtd.getRecommendedJdbcType( diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/Database.java b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/Database.java index 3fa01784d5..f3779539f7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/relational/Database.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/relational/Database.java @@ -22,6 +22,7 @@ import org.hibernate.dialect.H2Dialect; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.service.ServiceRegistry; +import org.hibernate.type.spi.TypeConfiguration; /** * @author Steve Ebersole @@ -29,6 +30,7 @@ import org.hibernate.service.ServiceRegistry; public class Database { private final Dialect dialect; + private final TypeConfiguration typeConfiguration; private final JdbcEnvironment jdbcEnvironment; private final Map namespaceMap = new TreeMap<>(); private final Map auxiliaryDatabaseObjects = new HashMap<>(); @@ -44,6 +46,7 @@ public class Database { public Database(MetadataBuildingOptions buildingOptions, JdbcEnvironment jdbcEnvironment) { this.serviceRegistry = buildingOptions.getServiceRegistry(); + this.typeConfiguration = buildingOptions.getTypeConfiguration(); this.jdbcEnvironment = jdbcEnvironment; this.physicalNamingStrategy = buildingOptions.getPhysicalNamingStrategy(); this.dialect = determineDialect( buildingOptions ); @@ -169,4 +172,8 @@ public class Database { public ServiceRegistry getServiceRegistry() { return serviceRegistry; } + + public TypeConfiguration getTypeConfiguration() { + return typeConfiguration; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index 72e8086fed..fb69404084 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -6,6 +6,7 @@ */ package org.hibernate.boot.model.source.internal.hbm; +import java.sql.Types; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -2019,14 +2020,22 @@ public class ModelBinder { private static boolean isLob(Integer sqlType, String sqlTypeName) { if ( sqlType != null ) { - return ClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType || - BlobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType || - NClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType; + switch ( sqlType ) { + case Types.BLOB: + case Types.CLOB: + case Types.NCLOB: + return true; + } + return false; } else if ( sqlTypeName != null ) { - return ClobType.INSTANCE.getName().equalsIgnoreCase( sqlTypeName ) || - BlobType.INSTANCE.getName().equalsIgnoreCase( sqlTypeName ) || - NClobType.INSTANCE.getName().equalsIgnoreCase( sqlTypeName ); + switch ( sqlTypeName.toLowerCase( Locale.ROOT ) ) { + case "blob": + case "clob": + case "nclob": + return true; + } + return false; } return false; } @@ -2405,8 +2414,9 @@ public class ModelBinder { ); } else { - discriminatorTypeName = StandardBasicTypes.STRING.getTypeName(); - discriminatorType = StandardBasicTypes.STRING; + discriminatorTypeName = StandardBasicTypes.STRING.getName(); + discriminatorType = metadataBuildingContext.getBootstrapContext().getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.STRING ); } anyBinding.setMetaType( discriminatorTypeName ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingMetadataBuildingOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingMetadataBuildingOptions.java index 2c52169dc2..3e215929e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingMetadataBuildingOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingMetadataBuildingOptions.java @@ -22,6 +22,7 @@ import org.hibernate.boot.model.naming.PhysicalNamingStrategy; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cfg.MetadataSourceType; +import org.hibernate.type.spi.TypeConfiguration; import org.jboss.jandex.IndexView; @@ -59,6 +60,11 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad return delegate.getBasicTypeRegistrations(); } + @Override + public TypeConfiguration getTypeConfiguration() { + return delegate.getTypeConfiguration(); + } + @Override public IndexView getJandexView() { return delegate.getJandexView(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java index 16625a758a..a5f96b5c67 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java @@ -25,6 +25,7 @@ import org.hibernate.collection.internal.StandardCollectionSemanticsResolver; import org.hibernate.collection.spi.CollectionSemanticsResolver; import org.hibernate.metamodel.internal.ManagedTypeRepresentationResolverStandard; import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver; +import org.hibernate.type.spi.TypeConfiguration; import org.jboss.jandex.IndexView; @@ -182,6 +183,8 @@ public interface MetadataBuildingOptions { IdGeneratorStrategyInterpreter getIdGenerationTypeInterpreter(); + TypeConfiguration getTypeConfiguration(); + /** * Access to all explicit cache region mappings. * diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java index b6eae1ef9e..6fb07aa5cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java @@ -15,6 +15,7 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.UUID; import org.hibernate.AssertionFailure; import org.hibernate.FlushMode; @@ -39,14 +40,9 @@ import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; import org.hibernate.resource.transaction.spi.TransactionStatus; +import org.hibernate.type.BasicType; import org.hibernate.type.CompositeType; -import org.hibernate.type.IntegerType; -import org.hibernate.type.LongType; -import org.hibernate.type.PostgresUUIDType; -import org.hibernate.type.StringType; import org.hibernate.type.Type; -import org.hibernate.type.UUIDBinaryType; -import org.hibernate.type.UUIDCharType; /** * Base class implementing {@link PersistentCollection} @@ -1261,12 +1257,14 @@ public abstract class AbstractPersistentCollection implements Serializable, P } private static boolean mayUseIdDirect(Type idType) { - return idType == StringType.INSTANCE - || idType == IntegerType.INSTANCE - || idType == LongType.INSTANCE - || idType == UUIDBinaryType.INSTANCE - || idType == UUIDCharType.INSTANCE - || idType == PostgresUUIDType.INSTANCE; + if ( idType instanceof BasicType ) { + final Class javaType = ( (BasicType) idType ).getJavaType(); + return javaType == String.class + || javaType == Integer.class + || javaType == Long.class + || javaType == UUID.class; + } + return false; } /** diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java index 8c7a06d991..1ea0d73ed4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java @@ -60,7 +60,7 @@ import org.hibernate.type.descriptor.java.DataHelper; import org.hibernate.type.descriptor.java.DoubleJavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.jdbc.*; -import org.hibernate.type.internal.StandardBasicTypeImpl; +import org.hibernate.type.internal.BasicTypeImpl; import java.io.*; import java.nio.charset.StandardCharsets; @@ -823,7 +823,7 @@ public abstract class AbstractHANADialect extends Dialect { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ), "locate(?2,?1)", "locate(?2,?1,?3)" ).setArgumentListSignature("(pattern, string[, start])"); @@ -1477,7 +1477,7 @@ public abstract class AbstractHANADialect extends Dialect { registerHibernateType( Types.DOUBLE, StandardBasicTypes.BIG_DECIMAL.getName() ); typeContributions.getTypeConfiguration().getBasicTypeRegistry() .register( - new StandardBasicTypeImpl<>( + new BasicTypeImpl<>( DoubleJavaTypeDescriptor.INSTANCE, NumericJdbcTypeDescriptor.INSTANCE ), 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 8d635d9b4d..cb50485ac3 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java @@ -125,7 +125,7 @@ public abstract class AbstractTransactSQLDialect extends Dialect { queryEngine.getSqmFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) ); queryEngine.getSqmFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) ); - queryEngine.getSqmFunctionRegistry().register( "str", new TransactSQLStrFunction() ); + queryEngine.getSqmFunctionRegistry().register( "str", new TransactSQLStrFunction( queryEngine.getTypeConfiguration() ) ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java index e167498f9d..3bbccfb1e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java @@ -28,6 +28,8 @@ import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory; import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.exec.spi.JdbcOperation; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; import java.sql.DatabaseMetaData; @@ -107,6 +109,9 @@ public class CockroachDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry(queryEngine); + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); + CommonFunctionFactory.ascii( queryEngine ); CommonFunctionFactory.char_chr( queryEngine ); CommonFunctionFactory.overlay( queryEngine ); @@ -129,7 +134,7 @@ public class CockroachDialect extends Dialect { CommonFunctionFactory.trunc( queryEngine ); //TODO: emulate second arg queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("format", "experimental_strftime") - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature("(datetime as pattern)") .register(); 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 fe037ad884..6075da8ab9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java @@ -197,10 +197,12 @@ public class DB2Dialect extends Dialect { CommonFunctionFactory.dateTrunc( queryEngine ); CommonFunctionFactory.bitLength_pattern( queryEngine, "length(?1)*8" ); - queryEngine.getSqmFunctionRegistry().register( "format", new DB2FormatEmulation() ); + queryEngine.getSqmFunctionRegistry().register( "format", new DB2FormatEmulation( queryEngine.getTypeConfiguration() ) ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "posstr" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature("(string, pattern)") .register(); 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 a18fa6ac0c..77521d99e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -53,6 +53,8 @@ import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorDerbyDatabaseImpl; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.JavaObjectType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.jdbc.DecimalJdbcTypeDescriptor; @@ -188,13 +190,16 @@ public class DerbyDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); + // Derby needs an actual argument type for aggregates like SUM, AVG, MIN, MAX to determine the result type CommonFunctionFactory.aggregates( this, queryEngine, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER, "||", - getCastTypeName( StandardBasicTypes.STRING, null, null, null ) + getCastTypeName( stringType, null, null, null ) ); CommonFunctionFactory.concat_pipeOperator( queryEngine ); @@ -223,14 +228,14 @@ public class DerbyDialect extends Dialect { .setExactArgumentCount( 2 ) .register(); - queryEngine.getSqmFunctionRegistry().register( "concat", new DerbyConcatFunction( this ) ); + queryEngine.getSqmFunctionRegistry().register( "concat", new DerbyConcatFunction( this, queryEngine.getTypeConfiguration() ) ); //no way I can see to pad with anything other than spaces - queryEngine.getSqmFunctionRegistry().register( "lpad", new DerbyLpadEmulation() ); - queryEngine.getSqmFunctionRegistry().register( "rpad", new DerbyRpadEmulation() ); + queryEngine.getSqmFunctionRegistry().register( "lpad", new DerbyLpadEmulation( queryEngine.getTypeConfiguration() ) ); + queryEngine.getSqmFunctionRegistry().register( "rpad", new DerbyRpadEmulation( queryEngine.getTypeConfiguration() ) ); queryEngine.getSqmFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) ); queryEngine.getSqmFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) ); - queryEngine.getSqmFunctionRegistry().register( "overlay", new InsertSubstringOverlayEmulation( true ) ); + queryEngine.getSqmFunctionRegistry().register( "overlay", new InsertSubstringOverlayEmulation( queryEngine.getTypeConfiguration(), true ) ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 06267f5693..cfac83ae80 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -73,6 +73,8 @@ import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNo import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; import org.hibernate.tool.schema.internal.*; import org.hibernate.tool.schema.spi.Exporter; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -89,6 +91,11 @@ import jakarta.persistence.TemporalType; import java.io.InputStream; import java.io.OutputStream; import java.sql.*; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; import java.time.temporal.TemporalAccessor; import java.util.Date; import java.util.*; @@ -188,43 +195,43 @@ public abstract class Dialect implements ConversionContext { registerColumnType( Types.NCLOB, "nclob" ); // register hibernate types for default use in scalar sqlquery type auto detection - registerHibernateType( Types.BOOLEAN, StandardBasicTypes.BOOLEAN.getTypeName() ); + registerHibernateType( Types.BOOLEAN, StandardBasicTypes.BOOLEAN.getName() ); - registerHibernateType( Types.BIT, 64, StandardBasicTypes.LONG.getTypeName() ); - registerHibernateType( Types.BIT, 32, StandardBasicTypes.INTEGER.getTypeName() ); - registerHibernateType( Types.BIT, 16, StandardBasicTypes.SHORT.getTypeName() ); - registerHibernateType( Types.BIT, 8, StandardBasicTypes.BYTE.getTypeName() ); - registerHibernateType( Types.BIT, 1, StandardBasicTypes.BOOLEAN.getTypeName() ); + registerHibernateType( Types.BIT, 64, StandardBasicTypes.LONG.getName() ); + registerHibernateType( Types.BIT, 32, StandardBasicTypes.INTEGER.getName() ); + registerHibernateType( Types.BIT, 16, StandardBasicTypes.SHORT.getName() ); + registerHibernateType( Types.BIT, 8, StandardBasicTypes.BYTE.getName() ); + registerHibernateType( Types.BIT, 1, StandardBasicTypes.BOOLEAN.getName() ); - registerHibernateType( Types.REAL, StandardBasicTypes.FLOAT.getTypeName() ); - registerHibernateType( Types.DOUBLE, StandardBasicTypes.DOUBLE.getTypeName() ); - registerHibernateType( Types.FLOAT, StandardBasicTypes.DOUBLE.getTypeName() ); - registerHibernateType( Types.NUMERIC, StandardBasicTypes.BIG_DECIMAL.getTypeName() ); - registerHibernateType( Types.DECIMAL, StandardBasicTypes.BIG_DECIMAL.getTypeName() ); + registerHibernateType( Types.REAL, StandardBasicTypes.FLOAT.getName() ); + registerHibernateType( Types.DOUBLE, StandardBasicTypes.DOUBLE.getName() ); + registerHibernateType( Types.FLOAT, StandardBasicTypes.DOUBLE.getName() ); + registerHibernateType( Types.NUMERIC, StandardBasicTypes.BIG_DECIMAL.getName() ); + registerHibernateType( Types.DECIMAL, StandardBasicTypes.BIG_DECIMAL.getName() ); - registerHibernateType( Types.BIGINT, StandardBasicTypes.LONG.getTypeName() ); - registerHibernateType( Types.INTEGER, StandardBasicTypes.INTEGER.getTypeName() ); - registerHibernateType( Types.SMALLINT, StandardBasicTypes.SHORT.getTypeName() ); - registerHibernateType( Types.TINYINT, StandardBasicTypes.BYTE.getTypeName() ); + registerHibernateType( Types.BIGINT, StandardBasicTypes.LONG.getName() ); + registerHibernateType( Types.INTEGER, StandardBasicTypes.INTEGER.getName() ); + registerHibernateType( Types.SMALLINT, StandardBasicTypes.SHORT.getName() ); + registerHibernateType( Types.TINYINT, StandardBasicTypes.BYTE.getName() ); - registerHibernateType( Types.CHAR, 1, StandardBasicTypes.CHARACTER.getTypeName() ); - registerHibernateType( Types.CHAR, StandardBasicTypes.STRING.getTypeName() ); - registerHibernateType( Types.VARCHAR, 1, StandardBasicTypes.CHARACTER.getTypeName() ); - registerHibernateType( Types.VARCHAR, StandardBasicTypes.STRING.getTypeName() ); - registerHibernateType( Types.NVARCHAR, StandardBasicTypes.NSTRING.getTypeName() ); - registerHibernateType( Types.LONGVARCHAR, StandardBasicTypes.TEXT.getTypeName() ); - registerHibernateType( Types.LONGNVARCHAR, StandardBasicTypes.NTEXT.getTypeName() ); + registerHibernateType( Types.CHAR, 1, StandardBasicTypes.CHARACTER.getName() ); + registerHibernateType( Types.CHAR, StandardBasicTypes.STRING.getName() ); + registerHibernateType( Types.VARCHAR, 1, StandardBasicTypes.CHARACTER.getName() ); + registerHibernateType( Types.VARCHAR, StandardBasicTypes.STRING.getName() ); + registerHibernateType( Types.NVARCHAR, StandardBasicTypes.NSTRING.getName() ); + registerHibernateType( Types.LONGVARCHAR, StandardBasicTypes.TEXT.getName() ); + registerHibernateType( Types.LONGNVARCHAR, StandardBasicTypes.NTEXT.getName() ); - registerHibernateType( Types.BINARY, StandardBasicTypes.BINARY.getTypeName() ); - registerHibernateType( Types.VARBINARY, StandardBasicTypes.BINARY.getTypeName() ); - registerHibernateType( Types.LONGVARBINARY, StandardBasicTypes.IMAGE.getTypeName() ); + registerHibernateType( Types.BINARY, StandardBasicTypes.BINARY.getName() ); + registerHibernateType( Types.VARBINARY, StandardBasicTypes.BINARY.getName() ); + registerHibernateType( Types.LONGVARBINARY, StandardBasicTypes.IMAGE.getName() ); - registerHibernateType( Types.BLOB, StandardBasicTypes.BLOB.getTypeName() ); - registerHibernateType( Types.CLOB, StandardBasicTypes.CLOB.getTypeName() ); + registerHibernateType( Types.BLOB, StandardBasicTypes.BLOB.getName() ); + registerHibernateType( Types.CLOB, StandardBasicTypes.CLOB.getName() ); - registerHibernateType( Types.DATE, StandardBasicTypes.DATE.getTypeName() ); - registerHibernateType( Types.TIME, StandardBasicTypes.TIME.getTypeName() ); - registerHibernateType( Types.TIMESTAMP, StandardBasicTypes.TIMESTAMP.getTypeName() ); + registerHibernateType( Types.DATE, StandardBasicTypes.DATE.getName() ); + registerHibernateType( Types.TIME, StandardBasicTypes.TIME.getName() ); + registerHibernateType( Types.TIMESTAMP, StandardBasicTypes.TIMESTAMP.getName() ); if(supportsPartitionBy()) { registerKeyword( "PARTITION" ); @@ -478,6 +485,15 @@ public abstract class Dialect implements ConversionContext { * */ public void initializeFunctionRegistry(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType timestampType = basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ); + final BasicType dateType = basicTypeRegistry.resolve( StandardBasicTypes.DATE ); + final BasicType timeType = basicTypeRegistry.resolve( StandardBasicTypes.TIME ); + final BasicType instantType = basicTypeRegistry.resolve( StandardBasicTypes.INSTANT ); + final BasicType offsetDateTimeType = basicTypeRegistry.resolve( StandardBasicTypes.OFFSET_DATE_TIME ); + final BasicType localDateTimeType = basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_DATE_TIME ); + final BasicType localTimeType = basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_TIME ); + final BasicType localDateType = basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_DATE ); //aggregate functions, supported on every database @@ -531,18 +547,18 @@ public abstract class Dialect implements ConversionContext { //only some databases support the ANSI SQL-style position() function, so //define it here as an alias for locate() - queryEngine.getSqmFunctionRegistry().register( "position", new LocatePositionEmulation() ); + queryEngine.getSqmFunctionRegistry().register( "position", new LocatePositionEmulation( queryEngine.getTypeConfiguration() ) ); //very few databases support ANSI-style overlay() function, so emulate //it here in terms of either insert() or concat()/substring() - queryEngine.getSqmFunctionRegistry().register( "overlay", new InsertSubstringOverlayEmulation( false ) ); + queryEngine.getSqmFunctionRegistry().register( "overlay", new InsertSubstringOverlayEmulation( queryEngine.getTypeConfiguration(), false ) ); //ANSI SQL trim() function is supported on almost all of the databases //we care about, but on some it must be emulated using ltrim(), rtrim(), //and replace() - queryEngine.getSqmFunctionRegistry().register( "trim", new TrimFunction( this ) ); + queryEngine.getSqmFunctionRegistry().register( "trim", new TrimFunction( this, queryEngine.getTypeConfiguration() ) ); //ANSI SQL cast() function is supported on the databases we care most //about but in certain cases it doesn't allow some useful typecasts, @@ -580,12 +596,12 @@ public abstract class Dialect implements ConversionContext { //pad() is a function we've designed to look like ANSI trim() - queryEngine.getSqmFunctionRegistry().register( "pad", new LpadRpadPadEmulation() ); + queryEngine.getSqmFunctionRegistry().register( "pad", new LpadRpadPadEmulation( queryEngine.getTypeConfiguration() ) ); //legacy Hibernate convenience function for casting to string, defined //here as an alias for cast(arg as String) - queryEngine.getSqmFunctionRegistry().register( "str", new CastStrEmulation() ); + queryEngine.getSqmFunctionRegistry().register( "str", new CastStrEmulation( queryEngine.getTypeConfiguration() ) ); //format() function for datetimes, emulated on many databases using the //Oracle-style to_char() function, and on others using their native @@ -596,8 +612,8 @@ public abstract class Dialect implements ConversionContext { //timestampadd()/timestampdiff() delegated back to the Dialect itself //since there is a great variety of different ways to emulate them - queryEngine.getSqmFunctionRegistry().register( "timestampadd", new TimestampaddFunction( this ) ); - queryEngine.getSqmFunctionRegistry().register( "timestampdiff", new TimestampdiffFunction( this ) ); + queryEngine.getSqmFunctionRegistry().register( "timestampadd", new TimestampaddFunction( this, queryEngine.getTypeConfiguration() ) ); + queryEngine.getSqmFunctionRegistry().register( "timestampdiff", new TimestampdiffFunction( this, queryEngine.getTypeConfiguration() ) ); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "dateadd", "timestampadd" ); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "datediff", "timestampdiff" ); @@ -609,7 +625,7 @@ public abstract class Dialect implements ConversionContext { new CurrentFunction( "current_date", currentDate(), - StandardBasicTypes.DATE + dateType ) ); queryEngine.getSqmFunctionRegistry().register( @@ -617,7 +633,7 @@ public abstract class Dialect implements ConversionContext { new CurrentFunction( "current_time", currentTime(), - StandardBasicTypes.TIME + timeType ) ); queryEngine.getSqmFunctionRegistry().register( @@ -625,7 +641,7 @@ public abstract class Dialect implements ConversionContext { new CurrentFunction( "current_timestamp", currentTimestamp(), - StandardBasicTypes.TIMESTAMP + timestampType ) ); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "current date", "current_date" ); @@ -638,7 +654,7 @@ public abstract class Dialect implements ConversionContext { new CurrentFunction( "local_date", currentDate(), - StandardBasicTypes.LOCAL_DATE + localDateType ) ); queryEngine.getSqmFunctionRegistry().register( @@ -646,7 +662,7 @@ public abstract class Dialect implements ConversionContext { new CurrentFunction( "local_time", currentLocalTime(), - StandardBasicTypes.LOCAL_TIME + localTimeType ) ); queryEngine.getSqmFunctionRegistry().register( @@ -654,7 +670,7 @@ public abstract class Dialect implements ConversionContext { new CurrentFunction( "local_datetime", currentLocalTimestamp(), - StandardBasicTypes.LOCAL_DATE_TIME + localDateTimeType ) ); queryEngine.getSqmFunctionRegistry().register( @@ -662,7 +678,7 @@ public abstract class Dialect implements ConversionContext { new CurrentFunction( "offset_datetime", currentTimestampWithTimeZone(), - StandardBasicTypes.OFFSET_DATE_TIME + offsetDateTimeType ) ); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "local date", "local_date" ); @@ -675,7 +691,7 @@ public abstract class Dialect implements ConversionContext { new CurrentFunction( "instant", currentTimestamp(), - StandardBasicTypes.INSTANT + instantType ) ); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "current_instant", "instant" ); //deprecated legacy! @@ -3458,7 +3474,8 @@ public abstract class Dialect implements ConversionContext { JdbcTypeDescriptor jdbcType, JavaTypeDescriptor javaType, Integer precision, - Integer scale, Long length); + Integer scale, + Long length); } public class SizeStrategyImpl implements SizeStrategy { @@ -3478,25 +3495,27 @@ public abstract class Dialect implements ConversionContext { if ( javaType.getJavaTypeClass() == Boolean.class && length != null && length == 255 ) { length = null; } - size.setLength( javaType.getDefaultSqlLength( Dialect.this ) ); + size.setLength( javaType.getDefaultSqlLength( Dialect.this, jdbcType ) ); break; case Types.CHAR: - // Use the default length for char if we encounter the JPA default 255 instead - if ( javaType.getJavaTypeClass() == Character.class && length != null && length == 255 ) { - length = null; - } - size.setLength( javaType.getDefaultSqlLength( Dialect.this ) ); - break; case Types.NCHAR: - case Types.BINARY: + // Use the default length for char and UUID if we encounter the JPA default 255 instead + if ( length != null && length == 255 ) { + if ( javaType.getJavaTypeClass() == Character.class || javaType.getJavaTypeClass() == UUID.class ) { + length = null; + } + } + size.setLength( javaType.getDefaultSqlLength( Dialect.this, jdbcType ) ); + break; case Types.VARCHAR: case Types.NVARCHAR: + case Types.BINARY: case Types.VARBINARY: // Use the default length for UUID if we encounter the JPA default 255 instead if ( javaType.getJavaTypeClass() == UUID.class && length != null && length == 255 ) { length = null; } - size.setLength( javaType.getDefaultSqlLength( Dialect.this ) ); + size.setLength( javaType.getDefaultSqlLength( Dialect.this, jdbcType ) ); break; case Types.LONGVARCHAR: case Types.LONGNVARCHAR: @@ -3528,7 +3547,7 @@ public abstract class Dialect implements ConversionContext { break; case Types.CLOB: case Types.BLOB: - size.setLength( javaType.getDefaultSqlLength(Dialect.this) ); + size.setLength( javaType.getDefaultSqlLength( Dialect.this, jdbcType ) ); break; } 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 24b564c6cb..5153ebfdb1 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANAColumnStoreDialect.java @@ -103,12 +103,15 @@ public class HANAColumnStoreDialect extends AbstractHANADialect { super.initializeFunctionRegistry( queryEngine ); // full-text search functions - queryEngine.getSqmFunctionRegistry().registerNamed( "score", StandardBasicTypes.DOUBLE ); + queryEngine.getSqmFunctionRegistry().registerNamed( + "score", + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ); queryEngine.getSqmFunctionRegistry().registerNamed( "snippets" ); queryEngine.getSqmFunctionRegistry().registerNamed( "highlighted" ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "contains", - StandardBasicTypes.BOOLEAN, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.BOOLEAN ), "contains(?1,?2)", "contains(?1,?2,?3)" ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java index d4820e9668..448f8aa1c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java @@ -77,7 +77,12 @@ public class MariaDBDialect extends MySQLDialect { super.initializeFunctionRegistry(queryEngine); if ( getVersion() >= 1020 ) { - queryEngine.getSqmFunctionRegistry().registerNamed("json_valid", StandardBasicTypes.NUMERIC_BOOLEAN); + queryEngine.getSqmFunctionRegistry().registerNamed( + "json_valid", + queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.BOOLEAN ) + ); } } 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 3847e6e556..74d341f96c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -59,7 +59,6 @@ import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.NullJdbcTypeDescriptor; -import org.hibernate.type.descriptor.jdbc.ObjectNullAsNullTypeJdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry; import java.sql.CallableStatement; @@ -394,7 +393,7 @@ public class MySQLDialect extends Dialect { CommonFunctionFactory.sysdateExplicitMicros( queryEngine ); } - queryEngine.getSqmFunctionRegistry().register( "field", new FieldFunction() ); + queryEngine.getSqmFunctionRegistry().register( "field", new FieldFunction( queryEngine.getTypeConfiguration() ) ); } @Override @@ -448,7 +447,9 @@ public class MySQLDialect extends Dialect { private void time(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "time" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .register(); } @@ -731,7 +732,10 @@ public class MySQLDialect extends Dialect { //inconsistent with other Dialects which need a length return String.format( "binary(%d)", - length == null ? type.getJdbcMapping().getJavaTypeDescriptor().getDefaultSqlLength(this) : length + length != null ? length : type.getJdbcMapping().getJavaTypeDescriptor().getDefaultSqlLength( + this, + type.getJdbcMapping().getJdbcTypeDescriptor() + ) ); case Types.VARCHAR: case Types.LONGVARCHAR: @@ -740,7 +744,10 @@ public class MySQLDialect extends Dialect { //inconsistent with other Dialects which need a length return String.format( "char(%d)", - length == null ? type.getJdbcMapping().getJavaTypeDescriptor().getDefaultSqlLength(this) : length + length != null ? length : type.getJdbcMapping().getJavaTypeDescriptor().getDefaultSqlLength( + this, + type.getJdbcMapping().getJdbcTypeDescriptor() + ) ); default: return super.getCastTypeName( type, length, precision, scale ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java index afeb546751..81ad42e971 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java @@ -189,7 +189,7 @@ public class OracleDialect extends Dialect { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ), "instr(?2,?1)", "instr(?2,?1,?3)" ).setArgumentListSignature("(pattern, string[, start])"); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java index f7955b319a..f5b934d2d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -335,7 +335,7 @@ public class PostgreSQLDialect extends Dialect { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ), "position(?1 in ?2)", "(position(?1 in substring(?2 from ?3))+(?3)-1)" ).setArgumentListSignature("(pattern, string[, start])"); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java index 47daf7643b..966aca4be7 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java @@ -44,6 +44,8 @@ import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.tool.schema.internal.StandardSequenceExporter; import org.hibernate.tool.schema.spi.Exporter; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; @@ -51,6 +53,7 @@ import org.hibernate.type.descriptor.jdbc.SmallIntJdbcTypeDescriptor; import java.sql.DatabaseMetaData; import java.sql.SQLException; +import java.sql.Timestamp; import java.sql.Types; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; @@ -167,6 +170,11 @@ public class SQLServerDialect extends AbstractTransactSQLDialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry(queryEngine); + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + BasicType dateType = basicTypeRegistry.resolve( StandardBasicTypes.DATE ); + BasicType timeType = basicTypeRegistry.resolve( StandardBasicTypes.TIME ); + BasicType timestampType = basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ); + // For SQL-Server we need to cast certain arguments to varchar(max) to be able to concat them CommonFunctionFactory.aggregates( this, queryEngine, SqlAstNodeRenderingMode.DEFAULT, "+", "varchar(max)" ); @@ -181,7 +189,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect { } if ( getVersion() >= 11 ) { - queryEngine.getSqmFunctionRegistry().register( "format", new SQLServerFormatEmulation( this ) ); + queryEngine.getSqmFunctionRegistry().register( "format", new SQLServerFormatEmulation( this, queryEngine.getTypeConfiguration() ) ); //actually translate() was added in 2017 but //it's not worth adding a new dialect for that! @@ -190,27 +198,27 @@ public class SQLServerDialect extends AbstractTransactSQLDialect { CommonFunctionFactory.median_percentileCont( queryEngine, true ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datefromparts" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( dateType ) .setExactArgumentCount( 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timefromparts" ) - .setInvariantType( StandardBasicTypes.TIME ) + .setInvariantType( timeType ) .setExactArgumentCount( 5 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "smalldatetimefromparts" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 5 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datetimefromparts" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 7 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datetime2fromparts" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 8 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datetimeoffsetfromparts" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 10 ) .register(); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java index 6e04ff76eb..d82b395dd4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java @@ -39,9 +39,12 @@ import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory; import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.tool.schema.spi.Exporter; +import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.StandardBasicTypes; import java.sql.Types; +import java.util.Date; import java.util.Map; import jakarta.persistence.TemporalType; @@ -108,6 +111,13 @@ public class SpannerDialect extends Dialect { @Override public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType byteArrayType = basicTypeRegistry.resolve( StandardBasicTypes.BINARY ); + final BasicType longType = basicTypeRegistry.resolve( StandardBasicTypes.LONG ); + final BasicType booleanType = basicTypeRegistry.resolve( StandardBasicTypes.BOOLEAN ); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); + final BasicType dateType = basicTypeRegistry.resolve( StandardBasicTypes.DATE ); + final BasicType timestampType = basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ); // Aggregate Functions queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "any_value" ) @@ -117,19 +127,19 @@ public class SpannerDialect extends Dialect { .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "countif" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "logical_and" ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "logical_or" ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "string_agg" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setArgumentCountBetween( 1, 2 ) .register(); @@ -146,19 +156,19 @@ public class SpannerDialect extends Dialect { CommonFunctionFactory.bitandorxornot_bitAndOrXorNot( queryEngine ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "is_inf" ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "is_nan" ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ieee_divide" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( booleanType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "div" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 2 ) .register(); @@ -166,15 +176,15 @@ public class SpannerDialect extends Dialect { // Hash Functions queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "farm_fingerprint" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sha256" ) - .setInvariantType( StandardBasicTypes.BINARY ) + .setInvariantType( byteArrayType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sha512" ) - .setInvariantType( StandardBasicTypes.BINARY ) + .setInvariantType( byteArrayType ) .setExactArgumentCount( 1 ) .register(); @@ -186,34 +196,34 @@ public class SpannerDialect extends Dialect { CommonFunctionFactory.substr( queryEngine ); CommonFunctionFactory.substring_substr( queryEngine ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "byte_length" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "code_points_to_bytes" ) - .setInvariantType( StandardBasicTypes.BINARY ) + .setInvariantType( byteArrayType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "code_points_to_string" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ends_with" ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setExactArgumentCount( 2 ) .register(); // queryEngine.getSqmFunctionRegistry().namedTemplateBuilder( "format" ) // .setInvariantType( StandardBasicTypes.STRING ) // .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "from_base64" ) - .setInvariantType( StandardBasicTypes.BINARY ) + .setInvariantType( byteArrayType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "from_hex" ) - .setInvariantType( StandardBasicTypes.BINARY ) + .setInvariantType( byteArrayType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "regexp_contains" ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "regexp_extract" ) @@ -226,39 +236,39 @@ public class SpannerDialect extends Dialect { .setExactArgumentCount( 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "safe_convert_bytes_to_string" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "split" ) .setArgumentCountBetween( 1, 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "starts_with" ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "strpos" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_base64" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_code_points" ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_hex" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .register(); // JSON Functions queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "json_query" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "json_value" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .register(); @@ -269,11 +279,11 @@ public class SpannerDialect extends Dialect { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "array_concat" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "array_length" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "array_to_string" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setArgumentCountBetween( 2, 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "array_reverse" ) @@ -282,102 +292,102 @@ public class SpannerDialect extends Dialect { // Date functions queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "date" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( dateType ) .setArgumentCountBetween( 1, 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "date_add" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( dateType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "date_sub" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( dateType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "date_diff" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "date_trunc" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( dateType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "date_from_unix_date" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( dateType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format_date" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "parse_date" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( dateType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "unix_date" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 1 ) .register(); // Timestamp functions queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "string" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setArgumentCountBetween( 1, 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setArgumentCountBetween( 1, 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp_add" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp_sub" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp_diff" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp_trunc" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setArgumentCountBetween( 2, 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format_timestamp" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setArgumentCountBetween( 2, 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "parse_timestamp" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setArgumentCountBetween( 2, 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp_seconds" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp_millis" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp_micros" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "unix_seconds" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "unix_millis" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "unix_micros" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder("format", "format_timestamp(?2,?1)") - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature("(datetime as pattern)") .register(); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java index 84bdb14173..0d49d0c6f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java @@ -237,7 +237,7 @@ public class SybaseDialect extends AbstractTransactSQLDialect { // For SQL-Server we need to cast certain arguments to varchar(16384) to be able to concat them CommonFunctionFactory.aggregates( this, queryEngine, SqlAstNodeRenderingMode.DEFAULT, "+", "varchar(16384)" ); - queryEngine.getSqmFunctionRegistry().register( "concat", new SybaseConcatFunction( this ) ); + queryEngine.getSqmFunctionRegistry().register( "concat", new SybaseConcatFunction( this, queryEngine.getTypeConfiguration() ) ); //this doesn't work 100% on earlier versions of Sybase //which were missing the third parameter in charindex() diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CaseWhenEveryAnyEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CaseWhenEveryAnyEmulation.java index 078d9506a6..80f1232e1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CaseWhenEveryAnyEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CaseWhenEveryAnyEmulation.java @@ -17,6 +17,7 @@ import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; /** * @author Jan Schatteman @@ -25,12 +26,14 @@ public class CaseWhenEveryAnyEmulation extends AbstractSqmSelfRenderingFunctionD private final boolean every; - public CaseWhenEveryAnyEmulation(boolean every) { + public CaseWhenEveryAnyEmulation(TypeConfiguration typeConfiguration, boolean every) { super( every ? "every" : "any", FunctionKind.AGGREGATE, StandardArgumentsValidators.exactly( 1 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.BOOLEAN ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.BOOLEAN ) + ) ); this.every = every; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java index b4eae3b4ee..e0ec1ee10a 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java @@ -29,11 +29,13 @@ import static java.util.Arrays.asList; public class CastStrEmulation extends AbstractSqmFunctionDescriptor { - public CastStrEmulation() { + public CastStrEmulation(TypeConfiguration typeConfiguration) { super( "str", StandardArgumentsValidators.exactly( 1 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); } @@ -56,7 +58,7 @@ public class CastStrEmulation asList( argument, new SqmCastTarget<>( - StandardBasicTypes.STRING, + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ), argument.nodeBuilder() ) ), diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java index 85e2a1af7d..c8d079c310 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java @@ -9,6 +9,7 @@ package org.hibernate.dialect.function; import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Types; +import java.util.Date; import java.util.List; import java.util.Arrays; import java.util.function.Supplier; @@ -25,6 +26,8 @@ import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.sql.ast.SqlAstNodeRenderingMode; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeRegistry; +import org.hibernate.type.DoubleType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.spi.TypeConfiguration; @@ -43,7 +46,9 @@ public class CommonFunctionFactory { public static void cosh(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "cosh" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); } @@ -51,27 +56,35 @@ public class CommonFunctionFactory { public static void cot(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "cot" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .register(); } public static void degrees(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "degrees" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .register(); } public static void log(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "log" ) .setArgumentCountBetween( 1, 2 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .register(); } public static void ln_log(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ln", "log" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); } @@ -79,13 +92,17 @@ public class CommonFunctionFactory { public static void log10(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "log10" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .register(); } public static void log2(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "log2" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); } @@ -93,35 +110,43 @@ public class CommonFunctionFactory { public static void radians(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "radians" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .register(); } public static void sinh(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sinh" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .register(); } public static void tanh(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "tanh" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .register(); } public static void moreHyperbolic(QueryEngine queryEngine) { + final BasicType doubleType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "acosh" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "asinh" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "atanh" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); } @@ -132,7 +157,9 @@ public class CommonFunctionFactory { public static void trunc(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "trunc" ) .setArgumentCountBetween( 1, 2 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setArgumentListSignature( "(number[, places])" ) .register(); } @@ -140,7 +167,9 @@ public class CommonFunctionFactory { public static void truncate(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "truncate" ) .setExactArgumentCount( 2 ) //some databases allow 1 arg but in these it's a synonym for trunc() - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setArgumentListSignature( "(number, places)" ) .register(); } @@ -151,7 +180,9 @@ public class CommonFunctionFactory { public static void truncate_round(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "truncate", "round(?1,?2,1)" ) .setExactArgumentCount( 2 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setArgumentListSignature( "(number, places)" ) .register(); } @@ -163,14 +194,18 @@ public class CommonFunctionFactory { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "rand" ) .setArgumentCountBetween( 0, 1 ) .setUseParenthesesWhenNoArgs( true ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setArgumentListSignature( "([seed])" ) .register(); } public static void median(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "median" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); } @@ -181,7 +216,9 @@ public class CommonFunctionFactory { "percentile_cont(0.5) within group (order by ?1)" + ( over ? " over()" : "" ) ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); } @@ -194,7 +231,9 @@ public class CommonFunctionFactory { */ public static void stddev(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stddev" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); } @@ -207,59 +246,73 @@ public class CommonFunctionFactory { */ public static void variance(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "variance" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); } public static void stddevPopSamp(QueryEngine queryEngine) { + final BasicType doubleType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stddev_pop" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stddev_samp" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); } public static void varPopSamp(QueryEngine queryEngine) { + final BasicType doubleType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "var_pop" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "var_samp" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); } public static void covarPopSamp(QueryEngine queryEngine) { + final BasicType doubleType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "covar_pop" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 2 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "covar_samp" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 2 ) .register(); } public static void corr(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "corr" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 2 ) .register(); } public static void regrLinearRegressionAggregates(QueryEngine queryEngine) { + final BasicType doubleType = queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); + Arrays.asList( "regr_avgx", "regr_avgy", "regr_count", "regr_intercept", "regr_r2", "regr_slope", "regr_sxx", "regr_sxy", "regr_syy" ) .forEach( fnName -> queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( fnName ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 2 ) .register() ); @@ -269,12 +322,14 @@ public class CommonFunctionFactory { * DB2 */ public static void stdevVarianceSamp(QueryEngine queryEngine) { + final BasicType doubleType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stddev_samp" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "variance_samp" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); } @@ -283,12 +338,16 @@ public class CommonFunctionFactory { * SQL Server-style */ public static void stddevPopSamp_stdevp(QueryEngine queryEngine) { + final BasicType doubleType = queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); + queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stdev" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stdevp" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "stddev_samp", "stdev" ); @@ -299,12 +358,15 @@ public class CommonFunctionFactory { * SQL Server-style */ public static void varPopSamp_varp(QueryEngine queryEngine) { + BasicType doubleType = queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "var" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "varp" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "var_samp", "var" ); @@ -313,7 +375,9 @@ public class CommonFunctionFactory { public static void pi(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().noArgsBuilder( "pi" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setUseParenthesesWhenNoArgs( true ) .register(); } @@ -324,44 +388,52 @@ public class CommonFunctionFactory { public static void soundex(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "soundex" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .register(); } public static void trim2(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ltrim" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setArgumentCountBetween( 1, 2 ) .setArgumentListSignature( "(string[, characters])" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "rtrim" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setArgumentCountBetween( 1, 2 ) .setArgumentListSignature( "(string[, characters])" ) .register(); } public static void trim1(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ltrim" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .setArgumentListSignature( "(string)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "rtrim" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .setArgumentListSignature( "(string)" ) .register(); } public static void pad(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "lpad" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setArgumentCountBetween( 2, 3 ) .setArgumentListSignature( "(string, length[, padding])" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "rpad" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setArgumentCountBetween( 2, 3 ) .setArgumentListSignature( "(string, length[, padding])" ) .register(); @@ -371,15 +443,17 @@ public class CommonFunctionFactory { * In MySQL the third argument is required */ public static void pad_space(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "lpad", - StandardBasicTypes.STRING, + stringType, "lpad(?1,?2,' ')", "lpad(?1,?2,?3)" ).setArgumentListSignature( "(string, length[, padding])" ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "rpad", - StandardBasicTypes.STRING, + stringType, "rpad(?1,?2,' ')", "rpad(?1,?2,?3)" ).setArgumentListSignature( "(string, length[, padding])" ); @@ -389,30 +463,34 @@ public class CommonFunctionFactory { * Transact-SQL */ public static void pad_replicate(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "lpad", - StandardBasicTypes.STRING, + stringType, "(space(?2-len(?1))+?1)", "(replicate(?3,?2-len(?1))+?1)" ).setArgumentListSignature( "(string, length[, padding])" ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "rpad", - StandardBasicTypes.STRING, + stringType, "(?1+space(?2-len(?1)))", "(?1+replicate(?3,?2-len(?1)))" ).setArgumentListSignature( "(string, length[, padding])" ); } public static void pad_repeat(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "lpad", - StandardBasicTypes.STRING, + stringType, "(repeat(' ',?2-character_length(?1))||?1)", "(repeat(?3,?2-character_length(?1))||?1)" ).setArgumentListSignature( "(string, length[, padding])" ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "rpad", - StandardBasicTypes.STRING, + stringType, "(?1||repeat(' ',?2-character_length(?1)))", "(?1||repeat(?3,?2-character_length(?1)))" ).setArgumentListSignature( "(string, length[, padding])" ); @@ -422,15 +500,17 @@ public class CommonFunctionFactory { * SAP DB */ public static void pad_fill(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "lpad", - StandardBasicTypes.STRING, + stringType, "lfill(?1,' ',?2)", "lfill(?1,?3,?2)" ).setArgumentListSignature( "(string, length[, padding])" ); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "rpad", - StandardBasicTypes.STRING, + stringType, "rfill(?1,' ',?2)", "rfill(?1,?3,?2)" ).setArgumentListSignature( "(string, length[, padding])" ); @@ -438,60 +518,72 @@ public class CommonFunctionFactory { public static void reverse(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "reverse" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 1 ) .register(); } public static void space(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "space" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 1 ) .register(); } public static void repeat(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "repeat" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(string, times)" ) .register(); } public static void leftRight(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "left" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(string, length)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "right" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(string, length)" ) .register(); } public static void leftRight_substr(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "left", "substr(?1,1,?2)" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(string, length)" ) .register(); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "right", "substr(?1,-?2)" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(string, length)" ) .register(); } public static void leftRight_substrLength(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "left", "substr(?1,1,?2)" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(string, length)" ) .register(); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "right", "substr(?1,length(?1)-?2+1)" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(string, length)" ) .register(); @@ -499,7 +591,9 @@ public class CommonFunctionFactory { public static void repeat_replicate(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "replicate" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(string, times)" ) .register(); @@ -508,21 +602,27 @@ public class CommonFunctionFactory { public static void md5(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "md5" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 1 ) .register(); } public static void initcap(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "initcap" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 1 ) .register(); } public static void instr(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "instr" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setArgumentCountBetween( 2, 4 ) .setArgumentListSignature( "(string, pattern[, start[, occurrence]])" ) .register(); @@ -530,7 +630,9 @@ public class CommonFunctionFactory { public static void substr(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "substr" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setArgumentCountBetween( 2, 3 ) .setArgumentListSignature( "(string, start[, length])" ) .register(); @@ -538,7 +640,9 @@ public class CommonFunctionFactory { public static void translate(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "translate" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 3 ) .register(); } @@ -660,15 +764,19 @@ public class CommonFunctionFactory { * These are aggregate functions taking one argument! */ public static void everyAny(QueryEngine queryEngine) { + final BasicType booleanType = queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.BOOLEAN ); + queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "every" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setArgumentListSignature( "(predicate)" ) .register(); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "any" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setArgumentListSignature( "(predicate)" ) .register(); } @@ -679,16 +787,20 @@ public class CommonFunctionFactory { * and predicates! */ public static void everyAny_boolAndOr(QueryEngine queryEngine) { + final BasicType booleanType = queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.BOOLEAN ); + queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "bool_and" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setArgumentListSignature( "(predicate)" ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "every", "bool_and" ); queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "bool_or" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.BOOLEAN ) + .setInvariantType( booleanType ) .setArgumentListSignature( "(predicate)" ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "any", "bool_or" ); @@ -700,8 +812,8 @@ public class CommonFunctionFactory { * aggregation functions using sum() and case. */ public static void everyAny_sumCase(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( "every", new EveryAnyEmulation( true ) ); - queryEngine.getSqmFunctionRegistry().register( "any", new EveryAnyEmulation( false ) ); + queryEngine.getSqmFunctionRegistry().register( "every", new EveryAnyEmulation( queryEngine.getTypeConfiguration(), true ) ); + queryEngine.getSqmFunctionRegistry().register( "any", new EveryAnyEmulation( queryEngine.getTypeConfiguration(), false ) ); } /** @@ -709,8 +821,8 @@ public class CommonFunctionFactory { * for SQL Server. */ public static void everyAny_sumIif(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( "every", new SQLServerEveryAnyEmulation( true ) ); - queryEngine.getSqmFunctionRegistry().register( "any", new SQLServerEveryAnyEmulation( false ) ); + queryEngine.getSqmFunctionRegistry().register( "every", new SQLServerEveryAnyEmulation( queryEngine.getTypeConfiguration(), true ) ); + queryEngine.getSqmFunctionRegistry().register( "any", new SQLServerEveryAnyEmulation( queryEngine.getTypeConfiguration(), false ) ); } @@ -719,108 +831,124 @@ public class CommonFunctionFactory { * for Oracle. */ public static void everyAny_sumCaseCase(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( "every", new CaseWhenEveryAnyEmulation( true ) ); - queryEngine.getSqmFunctionRegistry().register( "any", new CaseWhenEveryAnyEmulation( false ) ); + queryEngine.getSqmFunctionRegistry().register( "every", new CaseWhenEveryAnyEmulation( queryEngine.getTypeConfiguration(), true ) ); + queryEngine.getSqmFunctionRegistry().register( "any", new CaseWhenEveryAnyEmulation( queryEngine.getTypeConfiguration(), false ) ); } public static void yearMonthDay(QueryEngine queryEngine) { + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "day" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "month" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "year" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); } public static void hourMinuteSecond(QueryEngine queryEngine) { + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "hour" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "minute" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "second" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "microsecond" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); } public static void dayofweekmonthyear(QueryEngine queryEngine) { + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "dayofweek" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "dayofmonth" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "day", "dayofmonth" ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "dayofyear" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); } public static void dayOfWeekMonthYear(QueryEngine queryEngine) { + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "day_of_week" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "day_of_month" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "day", "day_of_month" ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "day_of_year" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); } public static void daynameMonthname(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "monthname" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "dayname" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .register(); } public static void weekQuarter(QueryEngine queryEngine) { + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "week" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "quarter" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .register(); } public static void lastDay(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "last_day" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DATE ) + ) .setExactArgumentCount( 1 ) .register(); } public static void lastDay_eomonth(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "eomonth" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DATE ) + ) .setArgumentCountBetween( 1, 2 ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "last_date", "eomonth" ); @@ -836,26 +964,27 @@ public class CommonFunctionFactory { } public static void toCharNumberDateTimestamp(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); //argument counts are right for Oracle, TimesTen, and CUBRID queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_number" ) //always 1 arg on HSQL and Cache, always 2 on Postgres .setArgumentCountBetween( 1, 3 ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DOUBLE ) ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_char" ) .setArgumentCountBetween( 1, 3 ) //always 2 args on HSQL and Postgres - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.STRING ) ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_date" ) //always 2 args on HSQL and Postgres .setArgumentCountBetween( 1, 3 ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DATE ) ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_timestamp" ) //always 2 args on HSQL and Postgres .setArgumentCountBetween( 1, 3 ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ) ) .register(); } @@ -868,57 +997,69 @@ public class CommonFunctionFactory { public static void timestamp(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp" ) .setArgumentCountBetween( 1, 2 ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( + queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.TIMESTAMP ) + ) .register(); } public static void time(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "time" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.TIME ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.TIME ) + ) .register(); } public static void date(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "date" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DATE ) + ) .register(); } public static void utcDateTimeTimestamp(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "utc_date" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DATE ) ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "utc_time" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( StandardBasicTypes.TIME ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIME ) ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "utc_timestamp" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ) ) .register(); } public static void currentUtcdatetimetimestamp(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "current_utcdate" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DATE ) ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "current_utctime" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( StandardBasicTypes.TIME ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIME ) ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "current_utctimestamp" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ) ) .register(); } public static void week_weekofyear(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "weekofyear" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "week", "weekofyear" ); @@ -929,7 +1070,9 @@ public class CommonFunctionFactory { */ public static void concat_pipeOperator(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "concat", "(?1||?2...)" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) // .setMinArgumentCount( 1 ) .setArgumentListSignature( "(string0[, string1[, ...]])" ) .register(); @@ -940,7 +1083,9 @@ public class CommonFunctionFactory { */ public static void concat_plusOperator(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "concat", "(?1+?2...)" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) // .setMinArgumentCount( 1 ) .setArgumentListSignature( "(string0[, string1[, ...]])" ) .register(); @@ -950,12 +1095,15 @@ public class CommonFunctionFactory { * Oracle-style */ public static void rownumRowid(QueryEngine queryEngine) { + final BasicType longType = queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.LONG ); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "rowid" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setUseParenthesesWhenNoArgs( false ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "rownum" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setUseParenthesesWhenNoArgs( false ) .register(); } @@ -965,7 +1113,9 @@ public class CommonFunctionFactory { */ public static void rownum(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().noArgsBuilder( "rownum" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.LONG ) + ) .setUseParenthesesWhenNoArgs( true ) //H2 and HSQL require the parens .register(); } @@ -974,21 +1124,23 @@ public class CommonFunctionFactory { * CUBRID */ public static void rownumInstOrderbyGroupbyNum(QueryEngine queryEngine) { + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "rownum" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setUseParenthesesWhenNoArgs( false ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "inst_num" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setUseParenthesesWhenNoArgs( true ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "orderby_num" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setUseParenthesesWhenNoArgs( true ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "groupby_num" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setUseParenthesesWhenNoArgs( true ) .register(); } @@ -997,13 +1149,14 @@ public class CommonFunctionFactory { * MySQL/CUBRID */ public static void makedateMaketime(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "makedate" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DATE ) ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(year, dayofyear)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "maketime" ) - .setInvariantType( StandardBasicTypes.TIME ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIME )) .setExactArgumentCount( 3 ) .setArgumentListSignature( "(hour, min, sec)" ) .register(); @@ -1013,20 +1166,22 @@ public class CommonFunctionFactory { * Postgres */ public static void makeDateTimeTimestamp(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + BasicType timestampType = basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "make_date" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DATE ) ) .setExactArgumentCount( 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "make_time" ) - .setInvariantType( StandardBasicTypes.TIME ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIME ) ) .setExactArgumentCount( 3 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "make_timestamp" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setExactArgumentCount( 6 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "make_timestamptz" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( timestampType ) .setArgumentCountBetween( 6, 7 ) .register(); } @@ -1034,7 +1189,11 @@ public class CommonFunctionFactory { public static void sysdate(QueryEngine queryEngine) { // returns a local timestamp queryEngine.getSqmFunctionRegistry().noArgsBuilder( "sysdate" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( + queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.TIMESTAMP ) + ) .setUseParenthesesWhenNoArgs( false ) .register(); } @@ -1044,7 +1203,11 @@ public class CommonFunctionFactory { */ public static void sysdateParens(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().noArgsBuilder( "sysdate" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( + queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.TIMESTAMP ) + ) .setUseParenthesesWhenNoArgs( true ) .register(); } @@ -1054,7 +1217,11 @@ public class CommonFunctionFactory { */ public static void sysdateExplicitMicros(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "sysdate", "sysdate(6)" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( + queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.TIMESTAMP ) + ) .setExactArgumentCount( 0 ) .register(); } @@ -1062,65 +1229,73 @@ public class CommonFunctionFactory { public static void systimestamp(QueryEngine queryEngine) { // returns a timestamp with timezone queryEngine.getSqmFunctionRegistry().noArgsBuilder( "systimestamp" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( + queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.TIMESTAMP ) + ) .setUseParenthesesWhenNoArgs( false ) .register(); } public static void localtimeLocaltimestamp(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); //these functions return times without timezones queryEngine.getSqmFunctionRegistry().noArgsBuilder( "localtime" ) - .setInvariantType( StandardBasicTypes.TIME ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIME ) ) .setUseParenthesesWhenNoArgs( false ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "localtimestamp" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ) ) .setUseParenthesesWhenNoArgs( false ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "local_time", "localtime" ) - .setInvariantType( StandardBasicTypes.LOCAL_TIME ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_TIME ) ) .setUseParenthesesWhenNoArgs( false ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "local_datetime", "localtimestamp" ) - .setInvariantType( StandardBasicTypes.LOCAL_DATE_TIME ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_DATE_TIME ) ) .setUseParenthesesWhenNoArgs( false ) .register(); } public static void trigonometry(QueryEngine queryEngine) { + final BasicType doubleType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.DOUBLE ); + queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sin" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "cos" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "tan" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "asin" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "acos" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "atan" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "atan2" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( doubleType ) .setExactArgumentCount( 2 ) .register(); } @@ -1130,7 +1305,9 @@ public class CommonFunctionFactory { */ public static void atan2_atn2(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "atan2", "atn2" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 2 ) .register(); } @@ -1162,7 +1339,9 @@ public class CommonFunctionFactory { */ public static void length_characterLength(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "character_length" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "length", "character_length" ); @@ -1173,7 +1352,9 @@ public class CommonFunctionFactory { */ public static void characterLength_len(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "len" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "character_length", "len" ); @@ -1185,7 +1366,9 @@ public class CommonFunctionFactory { */ public static void characterLength_length(QueryEngine queryEngine, SqlAstNodeRenderingMode argumentRenderingMode) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "length" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 1 ) .setArgumentRenderingMode( argumentRenderingMode ) .register(); @@ -1194,21 +1377,27 @@ public class CommonFunctionFactory { public static void octetLength(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "octet_length" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 1 ) .register(); } public static void bitLength(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bit_length" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 1 ) .register(); } public static void bitLength_pattern(QueryEngine queryEngine, String pattern) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "bit_length", pattern ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 1 ) .register(); } @@ -1218,7 +1407,9 @@ public class CommonFunctionFactory { */ public static void position(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "position", "position(?1 in ?2)" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(pattern in string)" ) .register(); @@ -1226,7 +1417,9 @@ public class CommonFunctionFactory { public static void locate(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "locate" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setArgumentCountBetween( 2, 3 ) .setArgumentListSignature( "(pattern, string[, start])" ) .register(); @@ -1237,7 +1430,9 @@ public class CommonFunctionFactory { */ public static void locate_charindex(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "charindex" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setArgumentCountBetween( 2, 3 ) .setArgumentListSignature( "(pattern, string[, start])" ) .register(); @@ -1250,7 +1445,7 @@ public class CommonFunctionFactory { public static void locate_positionSubstring(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", - StandardBasicTypes.INTEGER, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ), "position(?1 in ?2)", "(position(?1 in substring(?2 from ?3))+?3)" ) .setArgumentListSignature( "(pattern, string[, start])" ); @@ -1261,7 +1456,7 @@ public class CommonFunctionFactory { public static void substringFromFor(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "substring", - StandardBasicTypes.STRING, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ), "substring(?1 from ?2)", "substring(?1 from ?2 for ?3)" ) .setArgumentListSignature( "(string{ from|,} start[{ for|,} length])" ); @@ -1272,7 +1467,9 @@ public class CommonFunctionFactory { */ public static void substring(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "substring" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setArgumentCountBetween( 2, 3 ) .setArgumentListSignature( "(string{ from|,} start[{ for|,} length])" ) .register(); @@ -1285,7 +1482,7 @@ public class CommonFunctionFactory { queryEngine.getSqmFunctionRegistry() .registerBinaryTernaryPattern( "substring", - StandardBasicTypes.STRING, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ), "substring(?1,?2,len(?1)-?2+1)", "substring(?1,?2,?3)" ) @@ -1298,14 +1495,18 @@ public class CommonFunctionFactory { public static void substring_substr(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "substring", "substr" ) .setArgumentListSignature( "(string{ from|,} start[{ for|,} length])" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setArgumentCountBetween( 2, 3 ) .register(); } public static void insert(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "insert" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 4 ) .setArgumentListSignature( "(string, start, length, replacement)" ) .register(); @@ -1319,7 +1520,9 @@ public class CommonFunctionFactory { "insert", "overlay(?1 placing ?4 from ?2 for ?3)" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 4 ) .setArgumentListSignature( "(string, start, length, replacement)" ) .register(); @@ -1331,7 +1534,7 @@ public class CommonFunctionFactory { public static void overlay(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().registerTernaryQuaternaryPattern( "overlay", - StandardBasicTypes.STRING, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ), "overlay(?1 placing ?2 from ?3)", "overlay(?1 placing ?2 from ?3 for ?4)" ) @@ -1344,7 +1547,7 @@ public class CommonFunctionFactory { public static void overlayCharacterLength_overlay(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().registerTernaryQuaternaryPattern( "overlay", - StandardBasicTypes.STRING, + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ), //use character_length() here instead of length() //because DB2 doesn't like "length(?)" "overlay(?1 placing ?2 from ?3 for character_length(?2))", @@ -1355,7 +1558,9 @@ public class CommonFunctionFactory { public static void replace(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "replace" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 3 ) .setArgumentListSignature( "(string, pattern, replacement)" ) .register(); @@ -1366,7 +1571,9 @@ public class CommonFunctionFactory { */ public static void replace_strReplace(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "str_replace" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 3 ) .setArgumentListSignature( "(string, pattern, replacement)" ) .register(); @@ -1375,21 +1582,25 @@ public class CommonFunctionFactory { public static void concat(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "concat" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setMinArgumentCount( 1 ) .setArgumentListSignature( "(string0[, string1[, ...]])" ) .register(); } public static void lowerUpper(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "lower" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .setArgumentListSignature( "(string)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "upper" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( stringType ) .setExactArgumentCount( 1 ) .setArgumentListSignature( "(string)" ) .register(); @@ -1398,14 +1609,18 @@ public class CommonFunctionFactory { public static void ascii(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ascii" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.INTEGER ) //should it be BYTE?? + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + )//should it be BYTE?? .register(); } public static void char_chr(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "chr" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.CHARACTER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.CHARACTER ) + ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "char", "chr" ); } @@ -1413,7 +1628,9 @@ public class CommonFunctionFactory { public static void chr_char(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "char" ) .setExactArgumentCount( 1 ) - .setInvariantType( StandardBasicTypes.CHARACTER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.CHARACTER ) + ) .register(); queryEngine.getSqmFunctionRegistry().registerAlternateKey( "chr", "char" ); } @@ -1429,7 +1646,9 @@ public class CommonFunctionFactory { .setArgumentListSignature( "(field, arg)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datename" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(field, arg)" ) .register(); @@ -1441,16 +1660,17 @@ public class CommonFunctionFactory { // CUBRID: now()/curtime()/curdate() mean current_datetime/current_time/current_date // Postgres: now() means current_timestamp public static void nowCurdateCurtime(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "curtime" ) - .setInvariantType( StandardBasicTypes.TIME ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIME ) ) .setUseParenthesesWhenNoArgs( true ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "curdate" ) - .setInvariantType( StandardBasicTypes.DATE ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DATE ) ) .setUseParenthesesWhenNoArgs( true ) .register(); queryEngine.getSqmFunctionRegistry().noArgsBuilder( "now" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ) ) .setUseParenthesesWhenNoArgs( true ) .register(); } @@ -1610,17 +1830,21 @@ public class CommonFunctionFactory { queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "avg" ) .setArgumentRenderingMode( inferenceArgumentRenderingMode ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().register( CountFunction.FUNCTION_NAME, - new CountFunction( dialect, concatOperator, concatArgumentCastType ) + new CountFunction( dialect, queryEngine.getTypeConfiguration(), concatOperator, concatArgumentCastType ) ); } public static void math(QueryEngine queryEngine) { + final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "round" ) // To avoid truncating to a specific data type, we default to using the argument type .setReturnTypeResolver( useArgType( 1 ) ) @@ -1641,7 +1865,7 @@ public class CommonFunctionFactory { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "mod" ) // According to JPA spec 4.6.17.2.2. - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 2 ) .register(); @@ -1650,13 +1874,15 @@ public class CommonFunctionFactory { .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sign" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 1 ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sqrt" ) // According to JPA spec 4.6.17.2.2. - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); @@ -1670,13 +1896,15 @@ public class CommonFunctionFactory { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "power" ) .setExactArgumentCount( 2 ) - .setReturnTypeResolver( new PowerReturnTypeResolver() ) + .setReturnTypeResolver( new PowerReturnTypeResolver( queryEngine.getTypeConfiguration() ) ) .register(); } public static void mod_operator(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "mod", "(?1%?2)" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 2 ) .register(); } @@ -1684,7 +1912,7 @@ public class CommonFunctionFactory { public static void power_expLn(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "power", "exp(ln(?1)*?2)" ) .setExactArgumentCount( 2 ) - .setReturnTypeResolver( new PowerReturnTypeResolver() ) + .setReturnTypeResolver( new PowerReturnTypeResolver( queryEngine.getTypeConfiguration() ) ) .register(); } @@ -1696,35 +1924,45 @@ public class CommonFunctionFactory { public static void cbrt(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "cbrt" ) - .setInvariantType( StandardBasicTypes.DOUBLE ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) + ) .setExactArgumentCount( 1 ) .register(); } public static void crc32(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "crc32" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 1 ) .register(); } public static void sha1(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sha1" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 1 ) .register(); } public static void sha2(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sha2" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 2 ) .register(); } public static void sha(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sha" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 1 ) .register(); } @@ -1734,7 +1972,9 @@ public class CommonFunctionFactory { */ public static void datediff(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datediff" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); @@ -1776,7 +2016,9 @@ public class CommonFunctionFactory { public static void monthsBetween(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "months_between" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); @@ -1784,7 +2026,9 @@ public class CommonFunctionFactory { public static void daysBetween(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "days_between" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); @@ -1792,40 +2036,45 @@ public class CommonFunctionFactory { public static void secondsBetween(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "seconds_between" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.LONG ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); } public static void yearsMonthsDaysHoursMinutesSecondsBetween(QueryEngine queryEngine) { + final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); + final BasicType longType = basicTypeRegistry.resolve( StandardBasicTypes.LONG ); + final BasicType integerType = basicTypeRegistry.resolve( StandardBasicTypes.INTEGER ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "years_between" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "months_between" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "days_between" ) - .setInvariantType( StandardBasicTypes.INTEGER ) + .setInvariantType( integerType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "hours_between" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "minutes_between" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "seconds_between" ) - .setInvariantType( StandardBasicTypes.LONG ) + .setInvariantType( longType ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(end, start)" ) .register(); @@ -1869,7 +2118,9 @@ public class CommonFunctionFactory { */ public static void format_formatdatetime(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format", "formatdatetime" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(datetime as pattern)" ) .register(); @@ -1882,7 +2133,9 @@ public class CommonFunctionFactory { */ public static void format_toChar(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format", "to_char" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(datetime as pattern)" ) .register(); @@ -1895,7 +2148,9 @@ public class CommonFunctionFactory { */ public static void format_dateFormat(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format", "date_format" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(datetime as pattern)" ) .register(); @@ -1908,7 +2163,9 @@ public class CommonFunctionFactory { */ public static void format_toVarchar(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format", "to_varchar" ) - .setInvariantType( StandardBasicTypes.STRING ) + .setInvariantType( + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(datetime as pattern)" ) .register(); @@ -1916,7 +2173,11 @@ public class CommonFunctionFactory { public static void dateTrunc(QueryEngine queryEngine) { queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "date_trunc", "date_trunc('?1',?2)" ) - .setInvariantType( StandardBasicTypes.TIMESTAMP ) + .setInvariantType( + queryEngine.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.TIMESTAMP ) + ) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(field, datetime)" ) .register(); @@ -1924,6 +2185,12 @@ public class CommonFunctionFactory { private static class PowerReturnTypeResolver implements FunctionReturnTypeResolver { + private final BasicType doubleType; + + private PowerReturnTypeResolver(TypeConfiguration typeConfiguration) { + this.doubleType = typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ); + } + @Override public AllowableFunctionReturnType resolveFunctionReturnType( AllowableFunctionReturnType impliedType, @@ -1960,7 +2227,7 @@ public class CommonFunctionFactory { else if ( powerMapping.getJdbcMapping().getJdbcTypeDescriptor().isDecimal() ) { return powerMapping; } - return StandardBasicTypes.DOUBLE; + return doubleType; } } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CountFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CountFunction.java index 909b966c47..7ff3af3cc4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CountFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CountFunction.java @@ -34,6 +34,7 @@ import org.hibernate.sql.ast.tree.from.TableGroupJoin; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; /** * @author Christian Beikov @@ -45,12 +46,14 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor { private final String concatOperator; private final String concatArgumentCastType; - public CountFunction(Dialect dialect, String concatOperator, String concatArgumentCastType) { + public CountFunction(Dialect dialect, TypeConfiguration typeConfiguration, String concatOperator, String concatArgumentCastType) { super( FUNCTION_NAME, FunctionKind.AGGREGATE, StandardArgumentsValidators.exactly( 1 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.LONG ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.LONG ) + ) ); this.dialect = dialect; this.concatOperator = concatOperator; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/DB2FormatEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/DB2FormatEmulation.java index 5a28f0e61a..ee1b95a7a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/DB2FormatEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/DB2FormatEmulation.java @@ -7,6 +7,7 @@ package org.hibernate.dialect.function; import org.hibernate.dialect.OracleDialect; +import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; @@ -32,11 +33,13 @@ import jakarta.persistence.TemporalType; public class DB2FormatEmulation extends AbstractSqmSelfRenderingFunctionDescriptor { - public DB2FormatEmulation() { + public DB2FormatEmulation(TypeConfiguration typeConfiguration) { super( "format", StandardArgumentsValidators.exactly( 2 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyConcatFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyConcatFunction.java index 914df8beba..b1b53ec0c3 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyConcatFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyConcatFunction.java @@ -12,6 +12,7 @@ import java.util.List; import org.hibernate.dialect.Dialect; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.query.CastType; +import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; @@ -22,16 +23,19 @@ import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; public class DerbyConcatFunction extends AbstractSqmSelfRenderingFunctionDescriptor { private final Dialect dialect; - public DerbyConcatFunction(Dialect dialect) { + public DerbyConcatFunction(Dialect dialect, TypeConfiguration typeConfiguration) { super( "concat", StandardArgumentsValidators.min( 1 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); this.dialect = dialect; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyLpadEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyLpadEmulation.java index 10ac541bca..41143ddfef 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyLpadEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyLpadEmulation.java @@ -8,6 +8,7 @@ package org.hibernate.dialect.function; import java.util.List; +import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; @@ -16,6 +17,7 @@ import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; /** * A derby implementation for lpad. @@ -25,11 +27,13 @@ import org.hibernate.type.StandardBasicTypes; public class DerbyLpadEmulation extends AbstractSqmSelfRenderingFunctionDescriptor { - public DerbyLpadEmulation() { + public DerbyLpadEmulation(TypeConfiguration typeConfiguration) { super( "lpad", StandardArgumentsValidators.exactly( 2 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyRpadEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyRpadEmulation.java index 874a2d724f..b1254e2ebc 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyRpadEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/DerbyRpadEmulation.java @@ -8,6 +8,7 @@ package org.hibernate.dialect.function; import java.util.List; +import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; @@ -16,6 +17,7 @@ import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; /** * A derby implementation for rpad. @@ -25,11 +27,13 @@ import org.hibernate.type.StandardBasicTypes; public class DerbyRpadEmulation extends AbstractSqmSelfRenderingFunctionDescriptor { - public DerbyRpadEmulation() { + public DerbyRpadEmulation(TypeConfiguration typeConfiguration) { super( "rpad", StandardArgumentsValidators.exactly( 2 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/EveryAnyEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/EveryAnyEmulation.java index 6cb8f927e3..68a3f3342f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/EveryAnyEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/EveryAnyEmulation.java @@ -32,12 +32,14 @@ public class EveryAnyEmulation extends AbstractSqmSelfRenderingFunctionDescripto private final boolean every; - public EveryAnyEmulation(boolean every) { + public EveryAnyEmulation(TypeConfiguration typeConfiguration, boolean every) { super( every ? "every" : "any", FunctionKind.AGGREGATE, StandardArgumentsValidators.exactly( 1 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.BOOLEAN ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.BOOLEAN ) + ) ); this.every = every; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/FieldFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/FieldFunction.java index 9abf496a3a..21bc971789 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/FieldFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/FieldFunction.java @@ -18,13 +18,17 @@ import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.SqlTuple; import org.hibernate.sql.ast.tree.expression.SqlTupleContainer; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; public class FieldFunction extends AbstractSqmSelfRenderingFunctionDescriptor { - public FieldFunction() { + + public FieldFunction(TypeConfiguration typeConfiguration) { super( "field", StandardArgumentsValidators.min( 2 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.INTEGER ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java index 9ae7902bdc..5475a5b2a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java @@ -40,11 +40,13 @@ public class InsertSubstringOverlayEmulation private final boolean strictSubstring; - public InsertSubstringOverlayEmulation(boolean strictSubstring) { + public InsertSubstringOverlayEmulation(TypeConfiguration typeConfiguration, boolean strictSubstring) { super( "overlay", StandardArgumentsValidators.between( 3, 4 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); this.strictSubstring = strictSubstring; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java index 5a3ba1b341..4f4190792d 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java @@ -21,14 +21,15 @@ import java.util.List; /** * @author Gavin King */ -public class LocatePositionEmulation - extends AbstractSqmFunctionDescriptor { +public class LocatePositionEmulation extends AbstractSqmFunctionDescriptor { - public LocatePositionEmulation() { + public LocatePositionEmulation(TypeConfiguration typeConfiguration) { super( "position", StandardArgumentsValidators.exactly( 2 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.INTEGER ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ) + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java index 400c2b50e8..68e9d6996f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java @@ -28,11 +28,13 @@ import static java.util.Arrays.asList; public class LpadRpadPadEmulation extends AbstractSqmFunctionDescriptor { - public LpadRpadPadEmulation() { + public LpadRpadPadEmulation(TypeConfiguration typeConfiguration) { super( "pad", StandardArgumentsValidators.between( 3, 4 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerEveryAnyEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerEveryAnyEmulation.java index 80668a60ac..e24b91f6e3 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerEveryAnyEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerEveryAnyEmulation.java @@ -17,6 +17,7 @@ import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; /** * @author Jan Schatteman @@ -25,12 +26,14 @@ public class SQLServerEveryAnyEmulation extends AbstractSqmSelfRenderingFunction private final boolean every; - public SQLServerEveryAnyEmulation(boolean every) { + public SQLServerEveryAnyEmulation(TypeConfiguration typeConfiguration, boolean every) { super( every ? "every" : "any", FunctionKind.AGGREGATE, StandardArgumentsValidators.exactly( 1 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.BOOLEAN ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.BOOLEAN ) + ) ); this.every = every; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerFormatEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerFormatEmulation.java index 3fd3e25817..06e616ad1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerFormatEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerFormatEmulation.java @@ -10,6 +10,7 @@ import java.util.List; import jakarta.persistence.TemporalType; import org.hibernate.dialect.SQLServerDialect; +import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; @@ -30,11 +31,13 @@ public class SQLServerFormatEmulation extends AbstractSqmSelfRenderingFunctionDe private final SQLServerDialect dialect; - public SQLServerFormatEmulation(SQLServerDialect dialect) { + public SQLServerFormatEmulation(SQLServerDialect dialect, TypeConfiguration typeConfiguration) { super( "format", StandardArgumentsValidators.exactly( 2 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); this.dialect = dialect; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java index d8f8ce9130..a8201a06c4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java @@ -6,8 +6,8 @@ */ package org.hibernate.dialect.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; import org.hibernate.query.sqm.function.NamedSqmFunctionDescriptor; +import org.hibernate.type.BasicTypeReference; /** * Simplified API allowing users to contribute @@ -17,22 +17,22 @@ import org.hibernate.query.sqm.function.NamedSqmFunctionDescriptor; * @author David Channon */ public class StandardSQLFunction extends NamedSqmFunctionDescriptor { - private final AllowableFunctionReturnType type; + private final BasicTypeReference type; public StandardSQLFunction(String name) { this( name, null ); } - public StandardSQLFunction(String name, AllowableFunctionReturnType type) { + public StandardSQLFunction(String name, BasicTypeReference type) { this( name, true, type ); } - public StandardSQLFunction(String name, boolean useParentheses, AllowableFunctionReturnType type) { + public StandardSQLFunction(String name, boolean useParentheses, BasicTypeReference type) { super( name, useParentheses, null, null ); this.type = type; } - public AllowableFunctionReturnType getType() { + public BasicTypeReference getType() { return type; } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/SybaseConcatFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/SybaseConcatFunction.java index f678dff0cf..085652bc2f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/SybaseConcatFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/SybaseConcatFunction.java @@ -12,6 +12,7 @@ import java.util.List; import org.hibernate.dialect.Dialect; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.query.CastType; +import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; @@ -22,16 +23,19 @@ import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; public class SybaseConcatFunction extends AbstractSqmSelfRenderingFunctionDescriptor { private final Dialect dialect; - public SybaseConcatFunction(Dialect dialect) { + public SybaseConcatFunction(Dialect dialect, TypeConfiguration typeConfiguration) { super( "concat", StandardArgumentsValidators.min( 1 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); this.dialect = dialect; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampaddFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampaddFunction.java index bd3f72e6ce..3b3f9ae5fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampaddFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampaddFunction.java @@ -25,6 +25,7 @@ import org.hibernate.sql.ast.tree.expression.CastTarget; import org.hibernate.sql.ast.tree.expression.DurationUnit; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.QueryLiteral; +import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.spi.TypeConfiguration; @@ -43,8 +44,9 @@ public class TimestampaddFunction private final Dialect dialect; private final CastFunction castFunction; + private final BasicType integerType; - public TimestampaddFunction(Dialect dialect) { + public TimestampaddFunction(Dialect dialect, TypeConfiguration typeConfiguration) { super( "timestampadd", StandardArgumentsValidators.exactly( 3 ), @@ -52,6 +54,7 @@ public class TimestampaddFunction ); this.dialect = dialect; this.castFunction = new CastFunction( dialect, Types.BOOLEAN ); + this.integerType = typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ); } @Override @@ -123,7 +126,8 @@ public class TimestampaddFunction ) ); } - castArguments.add( new CastTarget( StandardBasicTypes.INTEGER ) ); + + castArguments.add( new CastTarget( integerType ) ); newArguments.set( 0, new DurationUnit( unit, field.getExpressionType() ) ); newArguments.set( 1, @@ -131,8 +135,8 @@ public class TimestampaddFunction "cast", castFunction::render, castArguments, - StandardBasicTypes.INTEGER, - StandardBasicTypes.INTEGER + integerType, + integerType ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampdiffFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampdiffFunction.java index b8e1e158c3..57a0b111af 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampdiffFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampdiffFunction.java @@ -33,11 +33,13 @@ public class TimestampdiffFunction private final Dialect dialect; - public TimestampdiffFunction(Dialect dialect) { + public TimestampdiffFunction(Dialect dialect, TypeConfiguration typeConfiguration) { super( "timestampdiff", StandardArgumentsValidators.exactly( 3 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.LONG ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.LONG ) + ) ); this.dialect = dialect; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java index 08157729d1..08d623d215 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java @@ -29,11 +29,13 @@ import org.hibernate.type.spi.TypeConfiguration; */ public class TransactSQLStrFunction extends CastStrEmulation implements FunctionRenderingSupport { - public TransactSQLStrFunction() { + public TransactSQLStrFunction(TypeConfiguration typeConfiguration) { super( "str", StandardArgumentsValidators.between( 1, 3 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TrimFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TrimFunction.java index fb78f05585..fa454e0ba5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TrimFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TrimFunction.java @@ -8,6 +8,7 @@ package org.hibernate.dialect.function; import org.hibernate.dialect.Dialect; import org.hibernate.query.TrimSpec; +import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; @@ -19,6 +20,7 @@ import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.QueryLiteral; import org.hibernate.sql.ast.tree.expression.TrimSpecification; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; import java.util.Collections; import java.util.List; @@ -28,13 +30,15 @@ import java.util.List; */ public class TrimFunction extends AbstractSqmSelfRenderingFunctionDescriptor { - private Dialect dialect; + private final Dialect dialect; - public TrimFunction(Dialect dialect) { + public TrimFunction(Dialect dialect, TypeConfiguration typeConfiguration) { super( "trim", StandardArgumentsValidators.exactly( 3 ), - StandardFunctionReturnTypeResolvers.invariant( StandardBasicTypes.STRING ) + StandardFunctionReturnTypeResolvers.invariant( + typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) + ) ); this.dialect = dialect; } diff --git a/hibernate-core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java index 99fd082d84..8f359f7166 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java @@ -42,7 +42,9 @@ import org.hibernate.mapping.Column; import org.hibernate.mapping.PrimaryKey; import org.hibernate.mapping.Table; import org.hibernate.service.ServiceRegistry; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.LongType; +import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StringType; import org.hibernate.type.Type; @@ -332,11 +334,12 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera // todo : not sure the best solution here. do we add the columns if missing? other? table.setPrimaryKey( new PrimaryKey( table ) ); + final BasicTypeRegistry basicTypeRegistry = database.getTypeConfiguration().getBasicTypeRegistry(); final Column pkColumn = new ExportableColumn( database, table, segmentColumnName, - StringType.INSTANCE, + basicTypeRegistry.resolve( StandardBasicTypes.STRING ), database.getDialect().getTypeName( Types.VARCHAR, Size.length(keySize) ) ); pkColumn.setNullable( false ); @@ -347,7 +350,7 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera database, table, valueColumnName, - LongType.INSTANCE + basicTypeRegistry.resolve( StandardBasicTypes.LONG ) ); table.addColumn( valueColumn ); } diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java index 0e068d8fa2..bb7d0d1687 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java @@ -50,7 +50,9 @@ import org.hibernate.mapping.Column; import org.hibernate.mapping.PrimaryKey; import org.hibernate.mapping.Table; import org.hibernate.service.ServiceRegistry; +import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.LongType; +import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StringType; import org.hibernate.type.Type; @@ -714,12 +716,13 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab (identifier) -> new Table( contributor, namespace, identifier, false ) ); + final BasicTypeRegistry basicTypeRegistry = database.getTypeConfiguration().getBasicTypeRegistry(); // todo : not sure the best solution here. do we add the columns if missing? other? final Column segmentColumn = new ExportableColumn( database, table, segmentColumnName, - StringType.INSTANCE, + basicTypeRegistry.resolve( StandardBasicTypes.STRING ), dialect.getTypeName( Types.VARCHAR, Size.length(segmentValueLength) ) ); segmentColumn.setNullable( false ); @@ -733,7 +736,7 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab database, table, valueColumnName, - LongType.INSTANCE + basicTypeRegistry.resolve( StandardBasicTypes.LONG ) ); table.addColumn( valueColumn ); } diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java index e47126288a..0da660a89e 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/TableStructure.java @@ -36,6 +36,7 @@ import org.hibernate.internal.CoreMessageLogger; import org.hibernate.jdbc.AbstractReturningWork; import org.hibernate.mapping.Table; import org.hibernate.type.LongType; +import org.hibernate.type.StandardBasicTypes; import org.jboss.logging.Logger; @@ -284,7 +285,7 @@ public class TableStructure implements DatabaseStructure { database, table, valueColumnNameText, - LongType.INSTANCE + database.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.LONG ) ); table.addColumn( valueColumn ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index c2592f6963..51a5e018c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -839,7 +839,7 @@ public interface CoreMessageLogger extends BasicLogger { @LogMessage(level = WARN) @Message(value = "Type [%s] defined no registration keys; ignoring", id = 269) - void typeDefinedNoRegistrationKeys(BasicType type); + void typeDefinedNoRegistrationKeys(Object type); @LogMessage(level = DEBUG) @Message(value = "Type registration key [%s] overrode previous key : %s", id = 270) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java index df2fe4839d..b079320640 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java @@ -48,6 +48,7 @@ import org.hibernate.sql.results.graph.basic.BasicResult; import org.hibernate.sql.results.internal.RowTransformerDatabaseSnapshotImpl; import org.hibernate.sql.results.spi.ListResultsConsumer; import org.hibernate.type.IntegerType; +import org.hibernate.type.StandardBasicTypes; import org.jboss.logging.Logger; @@ -107,7 +108,12 @@ class DatabaseSnapshotExecutor { // We just need a literal to have a result set domainResults.add( - new QueryLiteral<>( null, IntegerType.INSTANCE ).createDomainResult( null, state ) + new QueryLiteral<>( + null, + sessionFactory.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ) + ).createDomainResult( null, state ) ); final NavigablePath idNavigablePath = rootPath.append( entityDescriptor.getIdentifierMapping().getNavigableRole().getNavigableName() ); entityDescriptor.getIdentifierMapping().forEachSelectable( 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 159112e6b0..270a95787f 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 @@ -68,7 +68,9 @@ public class EntityTypeImpl discriminatorType = (DomainType) discriminatorMetadata.getResolutionType(); } else { - discriminatorType = StandardBasicTypes.STRING; + discriminatorType = jpaMetamodel.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.STRING ); } this.discriminatorPathSource = new DiscriminatorSqmPathSource<>( diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPropertyMapping.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPropertyMapping.java deleted file mode 100644 index 5f4b13dbc6..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPropertyMapping.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.persister.collection; - -import org.hibernate.QueryException; -import org.hibernate.persister.entity.PropertyMapping; -import org.hibernate.type.StandardBasicTypes; -import org.hibernate.type.Type; - -/** - * @author Gavin King - */ -public class CollectionPropertyMapping implements PropertyMapping { - private final QueryableCollection memberPersister; - - public CollectionPropertyMapping(QueryableCollection memberPersister) { - this.memberPersister = memberPersister; - } - - public Type toType(String propertyName) throws QueryException { - if ( propertyName.equals(CollectionPropertyNames.COLLECTION_ELEMENTS) ) { - return memberPersister.getElementType(); - } - else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_INDICES) ) { - if ( !memberPersister.hasIndex() ) { - throw new QueryException("unindexed collection before indices()"); - } - return memberPersister.getIndexType(); - } - else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_SIZE) ) { - return StandardBasicTypes.INTEGER; - } - else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_MAX_INDEX) ) { - return memberPersister.getIndexType(); - } - else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_MIN_INDEX) ) { - return memberPersister.getIndexType(); - } - else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_MAX_ELEMENT) ) { - return memberPersister.getElementType(); - } - else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_MIN_ELEMENT) ) { - return memberPersister.getElementType(); - } - else { - //return memberPersister.getPropertyType(propertyName); - throw new QueryException("illegal syntax near collection: " + propertyName); - } - } - - /** - * Given a property path, return the corresponding column name(s). - */ - public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException { - throw new UnsupportedOperationException( "References to collections must be define a SQL alias" ); - } - - public Type getType() { - //return memberPersister.getType(); - return memberPersister.getCollectionType(); - } - -} 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 140e4a32bf..d06b83acc8 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 @@ -212,7 +212,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { else { explicitDiscriminatorColumnName = null; discriminatorAlias = IMPLICIT_DISCRIMINATOR_ALIAS; - discriminatorType = StandardBasicTypes.INTEGER; + discriminatorType = factory.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); try { discriminatorValue = persistentClass.getSubclassId(); discriminatorSQLString = discriminatorValue.toString(); @@ -225,7 +227,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { else { explicitDiscriminatorColumnName = null; discriminatorAlias = IMPLICIT_DISCRIMINATOR_ALIAS; - discriminatorType = StandardBasicTypes.INTEGER; + discriminatorType = factory.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); discriminatorValue = null; discriminatorSQLString = 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 666d296f75..69bf5cfebb 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 @@ -53,6 +53,7 @@ import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.ast.tree.from.UnionTableGroup; import org.hibernate.sql.ast.tree.from.UnionTableReference; import org.hibernate.sql.ast.tree.predicate.Predicate; +import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; @@ -74,6 +75,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { private final String[] subclassTableExpressions; private final Object discriminatorValue; private final String discriminatorSQLValue; + private final BasicType discriminatorType; private final Map subclassByDiscriminatorValue = new HashMap<>(); private final String[] constraintOrderedTableNames; @@ -144,6 +146,9 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { discriminatorValue = persistentClass.getSubclassId(); discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() ); + discriminatorType = factory.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.INTEGER ); // PROPERTIES @@ -286,7 +291,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { @Override public Type getDiscriminatorType() { - return StandardBasicTypes.INTEGER; + return discriminatorType; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java index a1935c37a5..52eb4aa05c 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java @@ -65,6 +65,7 @@ import org.hibernate.result.UpdateCountOutput; import org.hibernate.result.spi.ResultContext; import org.hibernate.sql.exec.spi.JdbcCall; import org.hibernate.sql.results.NoMoreOutputsException; +import org.hibernate.type.BasicTypeReference; import org.jboss.logging.Logger; @@ -898,7 +899,8 @@ public class ProcedureCallImpl QueryParameter

parameter, P value, AllowableParameterType type) { - return (ProcedureCallImplementor) super.setParameter( parameter, value, type ); + super.setParameter( parameter, value, type ); + return this; } // @Override @@ -908,7 +910,8 @@ public class ProcedureCallImpl @Override public ProcedureCallImplementor setParameter(String name, Object value, AllowableParameterType type) { - return (ProcedureCallImplementor) super.setParameter( name, value, type ); + super.setParameter( name, value, type ); + return this; } // @Override @@ -918,10 +921,27 @@ public class ProcedureCallImpl @Override public ProcedureCallImplementor setParameter(int position, Object value, AllowableParameterType type) { - //noinspection unchecked - return (ProcedureCallImplementor) super.setParameter( position, value, type ); + super.setParameter( position, value, type ); + return this; } + @Override + public ProcedureCallImplementor setParameter(String name, Object value, BasicTypeReference type) { + super.setParameter( name, value, type ); + return this; + } + + @Override + public ProcedureCallImplementor setParameter(int position, Object value, BasicTypeReference type) { + super.setParameter( position, value, type ); + return this; + } + + @Override + public

ProcedureCallImplementor setParameter(QueryParameter

parameter, P val, BasicTypeReference type) { + super.setParameter( parameter, val, type ); + return this; + } // @Override // public ProcedureCallImplementor setParameter(int position, Object value, Type type) { // return (ProcedureCallImplementor) super.setParameter( position, value, type ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java b/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java index d16d18d23a..3ff925eae3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java @@ -31,6 +31,7 @@ import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.transform.ResultTransformer; +import org.hibernate.type.BasicTypeReference; /** * Represents a native (SQL) query. @@ -79,6 +80,20 @@ public interface NativeQuery extends Query, SynchronizeableQuery { */ NativeQuery addScalar(String columnAlias); + /** + * Declare a scalar query result. + *

+ * Functions like {@code } in {@code hbm.xml} or + * {@link jakarta.persistence.ColumnResult} in annotations + * + * @param columnAlias The column alias in the result-set to be processed + * as a scalar result + * @param type The Hibernate type as which to treat the value. + * + * @return {@code this}, for method chaining + */ + NativeQuery addScalar(String columnAlias, BasicTypeReference type); + /** * Declare a scalar query result. *

@@ -677,6 +692,15 @@ public interface NativeQuery extends Query, SynchronizeableQuery { @Override

NativeQuery setParameter(QueryParameter

parameter, P val, AllowableParameterType type); + @Override + NativeQuery setParameter(String name, Object val, BasicTypeReference type); + + @Override + NativeQuery setParameter(int position, Object val, BasicTypeReference type); + + @Override +

NativeQuery setParameter(QueryParameter

parameter, P val, BasicTypeReference type); + @Override NativeQuery setParameterList(int position, Collection values); diff --git a/hibernate-core/src/main/java/org/hibernate/query/Query.java b/hibernate-core/src/main/java/org/hibernate/query/Query.java index dd342e033d..0a2f995601 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/Query.java +++ b/hibernate-core/src/main/java/org/hibernate/query/Query.java @@ -38,6 +38,7 @@ import org.hibernate.graph.RootGraph; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.query.spi.QueryOptions; import org.hibernate.transform.ResultTransformer; +import org.hibernate.type.BasicTypeReference; /** * Represents an HQL/JPQL query or a compiled Criteria query. Also acts as the Hibernate @@ -301,6 +302,29 @@ public interface Query extends TypedQuery, CommonQueryContract { */ Query setParameter(int position, Object val, AllowableParameterType type); + /** + * Bind a named query parameter using the supplied Type + * + * @param name the name of the parameter + * @param val the possibly-null parameter value + * @param type the Hibernate allowable parameter type + * + * @return {@code this}, for method chaining + */ + Query setParameter(String name, Object val, BasicTypeReference type); + + /** + * Bind a value to a JDBC-style query parameter. + * + * @param position the position of the parameter in the query + * string, numbered from 0. + * @param val the possibly-null parameter value + * @param type the Hibernate allowable parameter type + * + * @return {@code this}, for method chaining + */ + Query setParameter(int position, Object val, BasicTypeReference type); + /** * Bind a named query parameter as some form of date/time using * the indicated temporal-type. @@ -349,6 +373,17 @@ public interface Query extends TypedQuery, CommonQueryContract { */

Query setParameter(QueryParameter

parameter, P val, AllowableParameterType type); + /** + * Bind a query parameter using the supplied Type + * + * @param parameter The query parameter memento + * @param val the possibly-null parameter value + * @param type the Hibernate allowable parameter type + * + * @return {@code this}, for method chaining + */ +

Query setParameter(QueryParameter

parameter, P val, BasicTypeReference type); + Query setParameter(Parameter param, Instant value, TemporalType temporalType); Query setParameter( diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index f695fab964..9863723920 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -185,6 +185,7 @@ import org.hibernate.sql.ast.SqlAstNodeRenderingMode; import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; +import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaTypeDescriptor; import org.jboss.logging.Logger; @@ -2969,7 +2970,9 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem private SqmLiteral binaryLiteral(String text) { return new SqmLiteral<>( - StandardBasicTypes.BINARY.fromStringValue( CharSequenceHelper.subSequence( text, 2, text.length() - 1 ) ), + PrimitiveByteArrayJavaTypeDescriptor.INSTANCE.fromString( + CharSequenceHelper.subSequence( text, 2, text.length() - 1 ) + ), resolveExpressableTypeBasic( byte[].class ), creationContext.getNodeBuilder() ); @@ -3688,7 +3691,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem if ( collectionReferenceCtx == null ) { final SqmLiteral literal = new SqmLiteral<>( 1, - StandardBasicTypes.INTEGER, + creationContext.getNodeBuilder().getIntegerType(), creationContext.getNodeBuilder() ); subQuery.applyInferableType( literal.getNodeType() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryHelper.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryHelper.java index 58d029e84d..1d62a81247 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryHelper.java @@ -30,7 +30,6 @@ public class QueryHelper { //noinspection unchecked SqmExpressable highest = highestPrecedenceType2( (SqmExpressable) types[0], types[1] ); for ( int i = 2; i < types.length; i++ ) { - //noinspection unchecked highest = highestPrecedenceType2( highest, types[i] ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java index b11b25d1d2..bcd1ad3f44 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java @@ -55,6 +55,7 @@ import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.query.IllegalQueryOperationException; +import org.hibernate.query.Query; import org.hibernate.query.QueryLogging; import org.hibernate.query.QueryParameter; import org.hibernate.query.ResultListTransformer; @@ -63,6 +64,7 @@ import org.hibernate.query.TypedParameterValue; import org.hibernate.query.internal.ScrollableResultsIterator; import org.hibernate.query.named.NamedQueryMemento; import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeReference; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import static org.hibernate.LockMode.UPGRADE; @@ -1031,6 +1033,22 @@ public abstract class AbstractQuery implements QueryImplementor { return this; } + @Override + public QueryImplementor setParameter(String name, Object value, BasicTypeReference type) { + return setParameter( name, value, session.getTypeConfiguration().getBasicTypeRegistry().resolve( type ) ); + } + + @Override + @SuppressWarnings( {"unchecked", "rawtypes"} ) + public QueryImplementor setParameter(int position, Object value, BasicTypeReference type) { + return setParameter( position, value, session.getTypeConfiguration().getBasicTypeRegistry().resolve( type ) ); + } + + @Override + public

Query setParameter(QueryParameter

parameter, P val, BasicTypeReference type) { + return setParameter( parameter, val, session.getTypeConfiguration().getBasicTypeRegistry().resolve( type ) ); + } + @Override public

QueryImplementor setParameter(QueryParameter

parameter, P value, TemporalType temporalType) { locateBinding( parameter ).setBindValue( value, temporalType ); 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 fe17a2f477..609be2e42b 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 @@ -13,6 +13,7 @@ import java.util.Map; import java.util.function.Supplier; import org.hibernate.Incubating; +import org.hibernate.boot.model.FunctionContributions; import org.hibernate.boot.model.FunctionContributor; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.BootstrapContext; @@ -138,8 +139,24 @@ public class QueryEngine { userDefinedRegistry.overlay( sqmFunctionRegistry ); } + final FunctionContributions functionContributions = new FunctionContributions() { + @Override + public TypeConfiguration getTypeConfiguration() { + return typeConfiguration; + } + + @Override + public SqmFunctionRegistry getFunctionRegistry() { + return sqmFunctionRegistry; + } + + @Override + public ServiceRegistry getServiceRegistry() { + return serviceRegistry; + } + }; for ( FunctionContributor contributor : sortedFunctionContributors( serviceRegistry ) ) { - contributor.contributeFunctions( sqmFunctionRegistry, serviceRegistry ); + contributor.contributeFunctions( functionContributions ); } final boolean showSQLFunctions = ConfigurationHelper.getBoolean( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index 97acb64967..a9143767eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -54,6 +54,7 @@ import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.persister.entity.Loadable; import org.hibernate.query.Limit; +import org.hibernate.query.NativeQuery; import org.hibernate.query.ParameterMetadata; import org.hibernate.query.Query; import org.hibernate.query.QueryParameter; @@ -76,6 +77,7 @@ import org.hibernate.query.spi.MutableQueryOptions; import org.hibernate.query.spi.NonSelectQueryPlan; import org.hibernate.query.spi.ParameterMetadataImplementor; import org.hibernate.query.spi.QueryEngine; +import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.spi.QueryInterpretationCache; import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.spi.QueryParameterImplementor; @@ -95,6 +97,7 @@ import org.hibernate.sql.results.jdbc.spi.JdbcValuesMappingProducer; import org.hibernate.sql.results.spi.RowTransformer; import org.hibernate.transform.ResultTransformer; import org.hibernate.type.BasicType; +import org.hibernate.type.BasicTypeReference; import static org.hibernate.jpa.QueryHints.HINT_NATIVE_LOCKMODE; @@ -713,6 +716,16 @@ public class NativeQueryImpl return this; } + @Override + public NativeQuery addScalar(String columnAlias, BasicTypeReference type) { + return registerBuilder( + Builders.scalar( + columnAlias, + getSessionFactory().getTypeConfiguration().getBasicTypeRegistry().resolve( type ) + ) + ); + } + @Override public NativeQueryImplementor addScalar(String columnAlias, BasicDomainType type) { return registerBuilder( Builders.scalar( columnAlias, (BasicType) type ) ); @@ -1337,44 +1350,62 @@ public class NativeQueryImpl @Override public

NativeQueryImplementor setParameter(QueryParameter

parameter, P value, AllowableParameterType type) { - //noinspection unchecked - return (NativeQueryImplementor) super.setParameter( parameter, value, type ); + super.setParameter( parameter, value, type ); + return this; } @Override public NativeQueryImplementor setParameter(String name, Object value, AllowableParameterType type) { - //noinspection unchecked - return (NativeQueryImplementor) super.setParameter( name, value, type ); + super.setParameter( name, value, type ); + return this; } @Override public NativeQueryImplementor setParameter(int position, Object value, AllowableParameterType type) { - //noinspection unchecked - return (NativeQueryImplementor) super.setParameter( position, value, type ); + super.setParameter( position, value, type ); + return this; + } + + @Override + public NativeQueryImplementor setParameter(String name, Object value, BasicTypeReference type) { + super.setParameter( name, value, type ); + return this; + } + + @Override + public NativeQueryImplementor setParameter(int position, Object value, BasicTypeReference type) { + super.setParameter( position, value, type ); + return this; + } + + @Override + public

NativeQueryImplementor setParameter(QueryParameter

parameter, P val, BasicTypeReference type) { + super.setParameter( parameter, val, type ); + return this; } @Override public NativeQueryImplementor setParameterList(int position, Collection values) { - //noinspection unchecked - return (NativeQueryImplementor) super.setParameterList( position, values ); + super.setParameterList( position, values ); + return this; } @Override public NativeQueryImplementor setParameterList(int position, Object[] values) { - //noinspection unchecked - return (NativeQueryImplementor) super.setParameterList( position, values ); + super.setParameterList( position, values ); + return this; } @Override public NativeQueryImplementor setParameterList(String name, Collection values, Class javaType) { - //noinspection unchecked - return (NativeQueryImplementor) super.setParameterList( name, values, javaType ); + super.setParameterList( name, values, javaType ); + return this; } @Override public NativeQueryImplementor setParameterList(int position, Collection values, Class javaType) { - //noinspection unchecked - return (NativeQueryImplementor) super.setParameterList( position, values, javaType ); + super.setParameterList( position, values, javaType ); + return this; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java index 465b354242..f9b1214a29 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java @@ -36,6 +36,7 @@ import org.hibernate.query.TupleTransformer; import org.hibernate.query.named.NameableQuery; import org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard; import org.hibernate.query.spi.QueryImplementor; +import org.hibernate.type.BasicTypeReference; /** * @author Steve Ebersole @@ -225,6 +226,15 @@ public interface NativeQueryImplementor extends QueryImplementor, NativeQu @Override NativeQueryImplementor setParameter(int position, Object val, AllowableParameterType type); + @Override + NativeQueryImplementor setParameter(String name, Object val, BasicTypeReference type); + + @Override + NativeQueryImplementor setParameter(int position, Object val, BasicTypeReference type); + + @Override +

NativeQueryImplementor setParameter(QueryParameter

parameter, P val, BasicTypeReference type); + @Override

NativeQueryImplementor setParameter( QueryParameter

parameter, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java index b09b8d2269..8d055b8279 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java @@ -62,6 +62,7 @@ import org.hibernate.query.sqm.tree.select.SqmSubQuery; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; import org.hibernate.service.ServiceRegistry; import org.hibernate.query.sqm.tree.expression.SqmFunction; +import org.hibernate.type.BasicType; import org.hibernate.type.spi.TypeConfiguration; /** @@ -639,4 +640,8 @@ public interface NodeBuilder extends HibernateCriteriaBuilder { @Override SqmSortSpecification desc(Expression x); + + BasicType getBooleanType(); + + BasicType getIntegerType(); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index 0b94767a84..b529fab556 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -165,6 +165,8 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, private final transient Supplier domainModelAccess; private final transient ServiceRegistry serviceRegistry; private final transient ValueHandlingMode criteriaValueHandlingMode; + private transient BasicType booleanType; + private transient BasicType integerType; public SqmCriteriaNodeBuilder( String uuid, @@ -186,6 +188,25 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return domainModelAccess.get(); } + @Override + public BasicType getBooleanType() { + final BasicType booleanType = this.booleanType; + if ( booleanType == null ) { + return this.booleanType = getTypeConfiguration().getBasicTypeRegistry() + .resolve( StandardBasicTypes.BOOLEAN ); + } + return booleanType; + } + + @Override + public BasicType getIntegerType() { + final BasicType integerType = this.integerType; + if ( integerType == null ) { + return this.integerType = getTypeConfiguration().getBasicTypeForJavaType( Integer.class ); + } + return integerType; + } + @Override public ServiceRegistry getServiceRegistry() { return serviceRegistry; @@ -987,14 +1008,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, public SqmExpression concat(Expression x, Expression y) { final SqmExpression xSqmExpression = (SqmExpression) x; final SqmExpression ySqmExpression = (SqmExpression) y; - //noinspection unchecked return getFunctionDescriptor( "concat" ).generateSqmExpression( asList( xSqmExpression, ySqmExpression ), - (AllowableFunctionReturnType) highestPrecedenceType( - xSqmExpression.getNodeType(), - ySqmExpression.getNodeType(), - StandardBasicTypes.STRING - ), + null, getQueryEngine(), getJpaMetamodel().getTypeConfiguration() ); @@ -1008,11 +1024,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "concat" ).generateSqmExpression( asList( xSqmExpression, ySqmExpression ), - (AllowableFunctionReturnType) highestPrecedenceType( - xSqmExpression.getNodeType(), - ySqmExpression.getNodeType(), - StandardBasicTypes.STRING - ), + null, getQueryEngine(), getJpaMetamodel().getTypeConfiguration() ); @@ -1026,11 +1038,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "concat" ).generateSqmExpression( asList( xSqmExpression, ySqmExpression ), - (AllowableFunctionReturnType) highestPrecedenceType( - xSqmExpression.getNodeType(), - ySqmExpression.getNodeType(), - StandardBasicTypes.STRING - ), + null, getQueryEngine(), getJpaMetamodel().getTypeConfiguration() ); @@ -1044,11 +1052,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "concat" ).generateSqmExpression( asList( xSqmExpression, ySqmExpression ), - (AllowableFunctionReturnType) highestPrecedenceType( - xSqmExpression.getNodeType(), - ySqmExpression.getNodeType(), - StandardBasicTypes.STRING - ), + null, getQueryEngine(), getJpaMetamodel().getTypeConfiguration() ); @@ -1067,15 +1071,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, SqmExpression source, SqmExpression from, SqmExpression len) { - //noinspection unchecked - final AllowableFunctionReturnType resultType = (AllowableFunctionReturnType) QueryHelper.highestPrecedenceType2( - source.getNodeType(), - StandardBasicTypes.STRING - ); - return getFunctionDescriptor( "substring" ).generateSqmExpression( - len==null ? asList( source, from ) : asList( source, from, len ), - resultType, + len == null ? asList( source, from ) : asList( source, from, len ), + null, getQueryEngine(), getJpaMetamodel().getTypeConfiguration() ); @@ -1132,10 +1130,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, arguments.add( trimCharacter ); arguments.add( source ); - //noinspection unchecked return getFunctionDescriptor( "trim" ).generateSqmExpression( arguments, - (AllowableFunctionReturnType) QueryHelper.highestPrecedenceType2( source.getNodeType(), StandardBasicTypes.STRING ), + null, getQueryEngine(), getJpaMetamodel().getTypeConfiguration() ); @@ -1246,7 +1243,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("locate").generateSqmExpression( arguments, - StandardBasicTypes.INTEGER, + null, getQueryEngine(), getJpaMetamodel().getTypeConfiguration() ); @@ -1281,10 +1278,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, @Override public SqmFunction currentDate() { - //noinspection unchecked return getFunctionDescriptor("current_date") .generateSqmExpression( - (AllowableFunctionReturnType) (AllowableFunctionReturnType) StandardBasicTypes.DATE, + null, queryEngine, getJpaMetamodel().getTypeConfiguration() ); @@ -1292,10 +1288,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, @Override public SqmFunction currentTimestamp() { - //noinspection unchecked return getFunctionDescriptor("current_timestamp") .generateSqmExpression( - (AllowableFunctionReturnType) (AllowableFunctionReturnType) StandardBasicTypes.TIMESTAMP, + null, queryEngine, getJpaMetamodel().getTypeConfiguration() ); @@ -1303,10 +1298,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, @Override public SqmFunction