From d0255d2c2bca958d9c7305c846e74e34fd70a275 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 1 Feb 2022 16:13:48 +0100 Subject: [PATCH] make CommonFunctionFactory a real object --- .../community/dialect/CUBRIDDialect.java | 99 +- .../community/dialect/CacheDialect.java | 59 +- .../community/dialect/FirebirdDialect.java | 57 +- .../community/dialect/InformixDialect.java | 53 +- .../community/dialect/IngresDialect.java | 59 +- .../community/dialect/MaxDBDialect.java | 57 +- .../community/dialect/MimerSQLDialect.java | 21 +- .../community/dialect/RDMSOS2200Dialect.java | 65 +- .../community/dialect/SQLiteDialect.java | 29 +- .../dialect/SybaseAnywhereDialect.java | 2 +- .../community/dialect/TeradataDialect.java | 47 +- .../community/dialect/TimesTenDialect.java | 29 +- .../dialect/AbstractHANADialect.java | 57 +- .../dialect/AbstractTransactSQLDialect.java | 49 +- .../hibernate/dialect/CockroachDialect.java | 47 +- .../org/hibernate/dialect/DB2Dialect.java | 93 +- .../org/hibernate/dialect/DB2iDialect.java | 7 +- .../org/hibernate/dialect/DB2zDialect.java | 7 +- .../org/hibernate/dialect/DerbyDialect.java | 49 +- .../java/org/hibernate/dialect/Dialect.java | 36 +- .../java/org/hibernate/dialect/H2Dialect.java | 102 +- .../org/hibernate/dialect/HSQLDialect.java | 98 +- .../org/hibernate/dialect/MySQLDialect.java | 106 +- .../org/hibernate/dialect/OracleDialect.java | 81 +- .../hibernate/dialect/PostgreSQLDialect.java | 88 +- .../dialect/PostgresPlusDialect.java | 9 +- .../hibernate/dialect/SQLServerDialect.java | 28 +- .../org/hibernate/dialect/SpannerDialect.java | 42 +- .../org/hibernate/dialect/SybaseDialect.java | 14 +- .../function/CommonFunctionFactory.java | 1450 ++++++++--------- .../function/SQLServerFormatEmulation.java | 2 - 31 files changed, 1459 insertions(+), 1483 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java index b8086dfe64..0ee6f3dd79 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java @@ -184,58 +184,59 @@ public class CUBRIDDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.reverse( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.crc32( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.log2( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.trim2(); + functionFactory.space(); + functionFactory.reverse(); + functionFactory.repeat(); + functionFactory.crc32(); + functionFactory.cot(); + functionFactory.log2(); + functionFactory.log10(); + functionFactory.pi(); //rand() returns an integer between 0 and 231 on CUBRID -// CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.systimestamp( queryEngine ); +// functionFactory.rand(); + functionFactory.radians(); + functionFactory.degrees(); + functionFactory.systimestamp(); //TODO: CUBRID also has systime()/sysdate() returning TIME/DATE - CommonFunctionFactory.localtimeLocaltimestamp( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.bitLength( queryEngine ); - CommonFunctionFactory.md5( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.toCharNumberDateTimestamp( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); + functionFactory.localtimeLocaltimestamp(); + functionFactory.hourMinuteSecond(); + functionFactory.yearMonthDay(); + functionFactory.dayofweekmonthyear(); + functionFactory.lastDay(); + functionFactory.weekQuarter(); + functionFactory.octetLength(); + functionFactory.bitLength(); + functionFactory.md5(); + functionFactory.trunc(); + functionFactory.truncate(); + functionFactory.toCharNumberDateTimestamp(); + functionFactory.substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.translate( queryEngine ); - CommonFunctionFactory.ceiling_ceil( queryEngine ); - CommonFunctionFactory.sha1( queryEngine ); - CommonFunctionFactory.sha2( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.char_chr( queryEngine ); - CommonFunctionFactory.position( queryEngine ); -// CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.insert( queryEngine ); - CommonFunctionFactory.nowCurdateCurtime( queryEngine ); - CommonFunctionFactory.makedateMaketime( queryEngine ); - CommonFunctionFactory.bitandorxornot_bitAndOrXorNot( queryEngine ); - CommonFunctionFactory.median( queryEngine ); - CommonFunctionFactory.stddev( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.variance( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); - CommonFunctionFactory.datediff( queryEngine ); - CommonFunctionFactory.adddateSubdateAddtimeSubtime( queryEngine ); - CommonFunctionFactory.addMonths( queryEngine ); - CommonFunctionFactory.monthsBetween( queryEngine ); - CommonFunctionFactory.rownumInstOrderbyGroupbyNum( queryEngine ); + functionFactory.instr(); + functionFactory.translate(); + functionFactory.ceiling_ceil(); + functionFactory.sha1(); + functionFactory.sha2(); + functionFactory.ascii(); + functionFactory.char_chr(); + functionFactory.position(); +// functionFactory.concat_pipeOperator(); + functionFactory.insert(); + functionFactory.nowCurdateCurtime(); + functionFactory.makedateMaketime(); + functionFactory.bitandorxornot_bitAndOrXorNot(); + functionFactory.median(); + functionFactory.stddev(); + functionFactory.stddevPopSamp(); + functionFactory.variance(); + functionFactory.varPopSamp(); + functionFactory.datediff(); + functionFactory.adddateSubdateAddtimeSubtime(); + functionFactory.addMonths(); + functionFactory.monthsBetween(); + functionFactory.rownumInstOrderbyGroupbyNum(); } @Override 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 6790653274..810739df8e 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 @@ -138,34 +138,35 @@ public class CacheDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.repeat(); + functionFactory.trim2(); + functionFactory.substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.daynameMonthname( queryEngine ); - CommonFunctionFactory.toCharNumberDateTimestamp( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.repeat_replicate( queryEngine ); - CommonFunctionFactory.datepartDatename( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.chr_char( queryEngine ); - CommonFunctionFactory.nowCurdateCurtime( queryEngine ); - CommonFunctionFactory.sysdate( queryEngine ); - CommonFunctionFactory.stddev( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.variance( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); + functionFactory.concat_pipeOperator(); + functionFactory.cot(); + functionFactory.log10(); + functionFactory.log(); + functionFactory.pi(); + functionFactory.space(); + functionFactory.hourMinuteSecond(); + functionFactory.yearMonthDay(); + functionFactory.weekQuarter(); + functionFactory.daynameMonthname(); + functionFactory.toCharNumberDateTimestamp(); + functionFactory.truncate(); + functionFactory.dayofweekmonthyear(); + functionFactory.repeat_replicate(); + functionFactory.datepartDatename(); + functionFactory.ascii(); + functionFactory.chr_char(); + functionFactory.nowCurdateCurtime(); + functionFactory.sysdate(); + functionFactory.stddev(); + functionFactory.stddevPopSamp(); + functionFactory.variance(); + functionFactory.varPopSamp(); + functionFactory.lastDay(); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", @@ -174,7 +175,7 @@ public class CacheDialect extends Dialect { "$find(?2,?1,?3)", STRING, STRING, INTEGER ).setArgumentListSignature("(pattern, string[, start])"); - CommonFunctionFactory.bitLength_pattern( queryEngine, "($length(?1)*8)" ); + functionFactory.bitLength_pattern( "($length(?1)*8)" ); useJdbcEscape(queryEngine, "sin"); useJdbcEscape(queryEngine, "cos"); @@ -345,7 +346,7 @@ public class CacheDialect extends Dialect { // callable statement support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Override - public int registerResultSetOutParameter(CallableStatement statement, int col) throws SQLException { + public int registerResultSetOutParameter(CallableStatement statement, int col) { return col; } 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 75945266b1..8df4b098a1 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 @@ -247,35 +247,36 @@ public class FirebirdDialect extends Dialect { final BasicType doubleType = basicTypeRegistry.resolve( StandardBasicTypes.DOUBLE ); final BasicType characterType = basicTypeRegistry.resolve( StandardBasicTypes.CHARACTER ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.concat_pipeOperator(); + functionFactory.cot(); + functionFactory.cosh(); + functionFactory.sinh(); + functionFactory.tanh(); if ( getVersion().isSameOrAfter( 3, 0 ) ) { - CommonFunctionFactory.moreHyperbolic( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); - CommonFunctionFactory.covarPopSamp( queryEngine ); - CommonFunctionFactory.corr( queryEngine ); - CommonFunctionFactory.regrLinearRegressionAggregates( queryEngine ); + functionFactory.moreHyperbolic(); + functionFactory.stddevPopSamp(); + functionFactory.varPopSamp(); + functionFactory.covarPopSamp(); + functionFactory.corr(); + functionFactory.regrLinearRegressionAggregates(); } - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.bitLength( queryEngine ); - CommonFunctionFactory.substringFromFor( queryEngine ); - CommonFunctionFactory.overlay( queryEngine ); - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.reverse( queryEngine ); - CommonFunctionFactory.bitandorxornot_binAndOrXorNot( queryEngine ); - CommonFunctionFactory.leastGreatest_minMaxValue( queryEngine ); + functionFactory.log(); + functionFactory.log10(); + functionFactory.pi(); + functionFactory.rand(); + functionFactory.sinh(); + functionFactory.tanh(); + functionFactory.cosh(); + functionFactory.trunc(); + functionFactory.octetLength(); + functionFactory.bitLength(); + functionFactory.substringFromFor(); + functionFactory.overlay(); + functionFactory.position(); + functionFactory.reverse(); + functionFactory.bitandorxornot_binAndOrXorNot(); + functionFactory.leastGreatest_minMaxValue(); SqmFunctionRegistry functionRegistry = queryEngine.getSqmFunctionRegistry(); functionRegistry.registerBinaryTernaryPattern( @@ -322,7 +323,7 @@ public class FirebirdDialect extends Dialect { ); } - CommonFunctionFactory.listagg_list( "varchar", queryEngine ); + functionFactory.listagg_list( "varchar" ); } @Override 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 368ba500d0..95fcc841ad 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 @@ -152,33 +152,34 @@ public class InformixDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.instr(); + functionFactory.substr(); + functionFactory.substring_substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.reverse( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.moreHyperbolic( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.initcap( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.ceiling_ceil( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.char_chr( queryEngine ); - CommonFunctionFactory.addMonths( queryEngine ); - CommonFunctionFactory.monthsBetween( queryEngine ); - CommonFunctionFactory.stddev( queryEngine ); - CommonFunctionFactory.variance( queryEngine ); - CommonFunctionFactory.locate_positionSubstring( queryEngine ); + functionFactory.trunc(); + functionFactory.trim2(); + functionFactory.space(); + functionFactory.reverse(); + functionFactory.octetLength(); + functionFactory.degrees(); + functionFactory.radians(); + functionFactory.sinh(); + functionFactory.tanh(); + functionFactory.cosh(); + functionFactory.moreHyperbolic(); + functionFactory.log10(); + functionFactory.initcap(); + functionFactory.yearMonthDay(); + functionFactory.ceiling_ceil(); + functionFactory.concat_pipeOperator(); + functionFactory.ascii(); + functionFactory.char_chr(); + functionFactory.addMonths(); + functionFactory.monthsBetween(); + functionFactory.stddev(); + functionFactory.variance(); + functionFactory.locate_positionSubstring(); //coalesce() and nullif() both supported since Informix 12 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 679d93b4cf..94114721da 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 @@ -253,32 +253,33 @@ public class IngresDialect extends Dialect { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Common functions - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.initcap( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.monthsBetween( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.log(); + functionFactory.rand(); + functionFactory.soundex(); + functionFactory.octetLength(); + functionFactory.repeat(); + functionFactory.trim2(); + functionFactory.trunc(); + functionFactory.truncate(); + functionFactory.initcap(); + functionFactory.yearMonthDay(); + functionFactory.hourMinuteSecond(); + functionFactory.dayofweekmonthyear(); + functionFactory.weekQuarter(); + functionFactory.lastDay(); + functionFactory.concat_pipeOperator(); + functionFactory.substr(); + functionFactory.monthsBetween(); + functionFactory.substring_substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.char_chr( queryEngine ); - CommonFunctionFactory.sysdate( queryEngine ); - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.format_dateFormat( queryEngine ); - CommonFunctionFactory.dateTrunc( queryEngine ); - CommonFunctionFactory.bitLength_pattern( queryEngine, "octet_length(hex(?1))*4" ); + functionFactory.ascii(); + functionFactory.char_chr(); + functionFactory.sysdate(); + functionFactory.position(); + functionFactory.format_dateFormat(); + functionFactory.dateTrunc(); + functionFactory.bitLength_pattern( "octet_length(hex(?1))*4" ); final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() .resolve( StandardBasicTypes.INTEGER ); @@ -292,7 +293,7 @@ public class IngresDialect extends Dialect { queryEngine.getSqmFunctionRegistry().registerPattern( "extract", "date_part('?1',?2)", integerType ); - CommonFunctionFactory.bitandorxornot_bitAndOrXorNot(queryEngine); + functionFactory.bitandorxornot_bitAndOrXorNot(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "squeeze" ) .setExactArgumentCount( 1 ) @@ -300,9 +301,9 @@ public class IngresDialect extends Dialect { .register(); // No idea since when this is supported - CommonFunctionFactory.listagg( null, queryEngine ); - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.listagg( null ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } 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 7d62f51a7a..33aefb08fb 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 @@ -120,36 +120,37 @@ public class MaxDBDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); - CommonFunctionFactory.translate( queryEngine ); - CommonFunctionFactory.initcap( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.daynameMonthname( queryEngine ); - CommonFunctionFactory.dateTimeTimestamp( queryEngine ); - CommonFunctionFactory.ceiling_ceil( queryEngine ); - CommonFunctionFactory.week_weekofyear( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.coalesce_value( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.log(); + functionFactory.pi(); + functionFactory.cot(); + functionFactory.cosh(); + functionFactory.sinh(); + functionFactory.tanh(); + functionFactory.radians(); + functionFactory.degrees(); + functionFactory.trunc(); + functionFactory.trim2(); + functionFactory.substr(); + functionFactory.substring_substr(); + functionFactory.translate(); + functionFactory.initcap(); + functionFactory.soundex(); + functionFactory.yearMonthDay(); + functionFactory.hourMinuteSecond(); + functionFactory.dayofweekmonthyear(); + functionFactory.daynameMonthname(); + functionFactory.dateTimeTimestamp(); + functionFactory.ceiling_ceil(); + functionFactory.week_weekofyear(); + functionFactory.concat_pipeOperator(); + functionFactory.coalesce_value(); //since lpad/rpad are not actually useful padding //functions, map them to lfill/rfill - CommonFunctionFactory.pad_fill( queryEngine ); - CommonFunctionFactory.datediff( queryEngine ); - CommonFunctionFactory.adddateSubdateAddtimeSubtime( queryEngine ); - CommonFunctionFactory.addMonths( queryEngine ); + functionFactory.pad_fill(); + functionFactory.datediff(); + functionFactory.adddateSubdateAddtimeSubtime(); + functionFactory.addMonths(); final BasicType integerType = queryEngine.getTypeConfiguration().getBasicTypeRegistry() .resolve( StandardBasicTypes.INTEGER ); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java index 207c1b7184..3e97dd5427 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java @@ -111,16 +111,17 @@ public class MimerSQLDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.bitLength( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.pad_repeat( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.localtimeLocaltimestamp( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.soundex(); + functionFactory.octetLength(); + functionFactory.bitLength(); + functionFactory.truncate(); + functionFactory.repeat(); + functionFactory.pad_repeat(); + functionFactory.dayofweekmonthyear(); + functionFactory.concat_pipeOperator(); + functionFactory.position(); + functionFactory.localtimeLocaltimestamp(); } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java index ab94ed3dbd..653eed7530 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/RDMSOS2200Dialect.java @@ -169,38 +169,39 @@ public class RDMSOS2200Dialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); -// CommonFunctionFactory.replicate( queryEngine ); //synonym for more common repeat() - CommonFunctionFactory.initcap( queryEngine ); - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.translate( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.daynameMonthname( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.ceiling_ceil( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.chr_char( queryEngine ); - CommonFunctionFactory.insert( queryEngine ); - CommonFunctionFactory.addMonths( queryEngine ); - CommonFunctionFactory.monthsBetween( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.cosh(); + functionFactory.sinh(); + functionFactory.tanh(); + functionFactory.cot(); + functionFactory.log(); + functionFactory.log10(); + functionFactory.pi(); + functionFactory.rand(); + functionFactory.trunc(); + functionFactory.truncate(); + functionFactory.soundex(); + functionFactory.trim2(); + functionFactory.space(); + functionFactory.repeat(); +// functionFactory.replicate(); //synonym for more common repeat() + functionFactory.initcap(); + functionFactory.instr(); + functionFactory.substr(); + functionFactory.translate(); + functionFactory.yearMonthDay(); + functionFactory.hourMinuteSecond(); + functionFactory.dayofweekmonthyear(); + functionFactory.weekQuarter(); + functionFactory.daynameMonthname(); + functionFactory.lastDay(); + functionFactory.ceiling_ceil(); + functionFactory.concat_pipeOperator(); + functionFactory.ascii(); + functionFactory.chr_char(); + functionFactory.insert(); + functionFactory.addMonths(); + functionFactory.monthsBetween(); } @Override 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 91126e7d9a..b849b44754 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 @@ -256,20 +256,21 @@ public class SQLiteDialect extends Dialect { 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 ); - CommonFunctionFactory.characterLength_length( queryEngine, SqlAstNodeRenderingMode.DEFAULT ); - CommonFunctionFactory.leastGreatest_minMax( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.mod_operator(); + functionFactory.leftRight_substr(); + functionFactory.concat_pipeOperator(); + functionFactory.characterLength_length( SqlAstNodeRenderingMode.DEFAULT ); + functionFactory.leastGreatest_minMax(); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); - CommonFunctionFactory.chr_char( queryEngine ); + functionFactory.radians(); + functionFactory.degrees(); + functionFactory.trunc(); + functionFactory.log(); + functionFactory.trim2(); + functionFactory.substr(); + functionFactory.substring_substr(); + functionFactory.chr_char(); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", @@ -316,7 +317,7 @@ public class SQLiteDialect extends Dialect { .setParameterTypes(NUMERIC) .register(); } - CommonFunctionFactory.listagg_groupConcat( queryEngine ); + functionFactory.listagg_groupConcat(); } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java index c2e8945507..1c6de87002 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java @@ -80,7 +80,7 @@ public class SybaseAnywhereDialect extends SybaseDialect { @Override public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.listagg_list( "varchar", queryEngine ); + new CommonFunctionFactory( queryEngine ).listagg_list( "varchar" ); } @Override 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 abeae191ef..87c338e657 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 @@ -252,15 +252,16 @@ public class TeradataDialect extends Dialect { final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.moreHyperbolic( queryEngine ); - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.concat_pipeOperator(); + functionFactory.octetLength(); + functionFactory.moreHyperbolic(); + functionFactory.instr(); + functionFactory.substr(); + functionFactory.substring_substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.bitLength_pattern( queryEngine, "octet_length(cast(?1 as char))*4" ); + functionFactory.position(); + functionFactory.bitLength_pattern( "octet_length(cast(?1 as char))*4" ); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "mod", "(?1 mod ?2)" ) .setInvariantType( stringType ) @@ -270,23 +271,23 @@ public class TeradataDialect extends Dialect { if ( getVersion().isSameOrAfter( 14 ) ) { //list actually taken from Teradata 15 docs - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.initcap( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.char_chr( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.moreHyperbolic( queryEngine ); - CommonFunctionFactory.monthsBetween( queryEngine ); - CommonFunctionFactory.addMonths( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); + functionFactory.lastDay(); + functionFactory.initcap(); + functionFactory.trim2(); + functionFactory.soundex(); + functionFactory.ascii(); + functionFactory.char_chr(); + functionFactory.trunc(); + functionFactory.moreHyperbolic(); + functionFactory.monthsBetween(); + functionFactory.addMonths(); + functionFactory.stddevPopSamp(); + functionFactory.varPopSamp(); } // No idea since when this is supported - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } /** @@ -489,7 +490,7 @@ public class TeradataDialect extends Dialect { return getVersion().isBefore( 14 ) ? super.getViolatedConstraintNameExtractor() : EXTRACTOR; } - private static ViolatedConstraintNameExtractor EXTRACTOR = + private static final ViolatedConstraintNameExtractor EXTRACTOR = new TemplatedViolatedConstraintNameExtractor( sqle -> { String constraintName; switch ( sqle.getErrorCode() ) { 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 c879ecb43f..c6b2db08a6 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 @@ -147,20 +147,21 @@ public class TimesTenDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.toCharNumberDateTimestamp( queryEngine ); - CommonFunctionFactory.ceiling_ceil( queryEngine ); - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); - CommonFunctionFactory.leftRight_substr( queryEngine ); - CommonFunctionFactory.char_chr( queryEngine ); - CommonFunctionFactory.rownumRowid( queryEngine ); - CommonFunctionFactory.sysdate( queryEngine ); - CommonFunctionFactory.addMonths( queryEngine ); - CommonFunctionFactory.monthsBetween( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.trim2(); + functionFactory.soundex(); + functionFactory.trunc(); + functionFactory.toCharNumberDateTimestamp(); + functionFactory.ceiling_ceil(); + functionFactory.instr(); + functionFactory.substr(); + functionFactory.substring_substr(); + functionFactory.leftRight_substr(); + functionFactory.char_chr(); + functionFactory.rownumRowid(); + functionFactory.sysdate(); + functionFactory.addMonths(); + functionFactory.monthsBetween(); queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( "locate", 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 20bb15923f..9580a089bf 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java @@ -282,35 +282,36 @@ public abstract class AbstractHANADialect extends Dialect { FunctionParameterType.STRING, FunctionParameterType.STRING, FunctionParameterType.INTEGER ).setArgumentListSignature("(pattern, string[, start])"); - CommonFunctionFactory.ceiling_ceil( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); - CommonFunctionFactory.log10_log( queryEngine ); - CommonFunctionFactory.bitand( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.daynameMonthname( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.characterLength_length( queryEngine, SqlAstNodeRenderingMode.DEFAULT ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.chr_char( queryEngine ); - CommonFunctionFactory.addYearsMonthsDaysHoursMinutesSeconds( queryEngine ); - CommonFunctionFactory.daysBetween( queryEngine ); - CommonFunctionFactory.secondsBetween( queryEngine ); - CommonFunctionFactory.format_toVarchar( queryEngine ); - CommonFunctionFactory.currentUtcdatetimetimestamp( queryEngine ); - CommonFunctionFactory.everyAny_sumCaseCase( queryEngine ); - CommonFunctionFactory.bitLength_pattern( queryEngine, "length(to_binary(?1))*8" ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.ceiling_ceil(); + functionFactory.concat_pipeOperator(); + functionFactory.trim2(); + functionFactory.cot(); + functionFactory.cosh(); + functionFactory.sinh(); + functionFactory.tanh(); + functionFactory.log10_log(); + functionFactory.bitand(); + functionFactory.hourMinuteSecond(); + functionFactory.yearMonthDay(); + functionFactory.dayofweekmonthyear(); + functionFactory.weekQuarter(); + functionFactory.daynameMonthname(); + functionFactory.lastDay(); + functionFactory.characterLength_length( SqlAstNodeRenderingMode.DEFAULT ); + functionFactory.ascii(); + functionFactory.chr_char(); + functionFactory.addYearsMonthsDaysHoursMinutesSeconds(); + functionFactory.daysBetween(); + functionFactory.secondsBetween(); + functionFactory.format_toVarchar(); + functionFactory.currentUtcdatetimetimestamp(); + functionFactory.everyAny_sumCaseCase(); + functionFactory.bitLength_pattern( "length(to_binary(?1))*8" ); - CommonFunctionFactory.listagg_stringAgg( "varchar", queryEngine ); - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.listagg_stringAgg( "varchar" ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } @Override 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 3185bdc1a2..05703ea7c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java @@ -124,30 +124,31 @@ public abstract class AbstractTransactSQLDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.ln_log( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.atan2_atn2( queryEngine ); - CommonFunctionFactory.mod_operator( queryEngine ); - CommonFunctionFactory.square( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.reverse( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.pad_replicate( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.ascii(queryEngine); - CommonFunctionFactory.chr_char( queryEngine ); - CommonFunctionFactory.concat_plusOperator( queryEngine ); - CommonFunctionFactory.trim1( queryEngine ); - CommonFunctionFactory.repeat_replicate( queryEngine ); - CommonFunctionFactory.characterLength_len( queryEngine ); - CommonFunctionFactory.substring_substringLen( queryEngine ); - CommonFunctionFactory.datepartDatename( queryEngine ); - CommonFunctionFactory.lastDay_eomonth( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.cot(); + functionFactory.log(); + functionFactory.ln_log(); + functionFactory.log10(); + functionFactory.atan2_atn2(); + functionFactory.mod_operator(); + functionFactory.square(); + functionFactory.rand(); + functionFactory.radians(); + functionFactory.degrees(); + functionFactory.pi(); + functionFactory.reverse(); + functionFactory.space(); + functionFactory.pad_replicate(); + functionFactory.yearMonthDay(); + functionFactory.ascii(); + functionFactory.chr_char(); + functionFactory.concat_plusOperator(); + functionFactory.trim1(); + functionFactory.repeat_replicate(); + functionFactory.characterLength_len(); + functionFactory.substring_substringLen(); + functionFactory.datepartDatename(); + functionFactory.lastDay_eomonth(); queryEngine.getSqmFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) ); queryEngine.getSqmFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) ); 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 4a541d6ac3..9098337d24 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java @@ -208,35 +208,36 @@ public class CockroachDialect extends Dialect { final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.char_chr( queryEngine ); - CommonFunctionFactory.overlay( queryEngine ); - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.substringFromFor( queryEngine ); - CommonFunctionFactory.locate_positionSubstring( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.reverse( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.md5( queryEngine ); - CommonFunctionFactory.sha1( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.bitLength( queryEngine ); - CommonFunctionFactory.cbrt( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); //TODO: emulate second arg + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.ascii(); + functionFactory.char_chr(); + functionFactory.overlay(); + functionFactory.position(); + functionFactory.substringFromFor(); + functionFactory.locate_positionSubstring(); + functionFactory.trim2(); + functionFactory.substr(); + functionFactory.reverse(); + functionFactory.repeat(); + functionFactory.md5(); + functionFactory.sha1(); + functionFactory.octetLength(); + functionFactory.bitLength(); + functionFactory.cbrt(); + functionFactory.cot(); + functionFactory.degrees(); + functionFactory.radians(); + functionFactory.pi(); + functionFactory.trunc(); //TODO: emulate second arg queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder("format", "experimental_strftime") .setInvariantType( stringType ) .setArgumentsValidator( CommonFunctionFactory.formatValidator() ) .setArgumentListSignature("(TEMPORAL datetime as STRING pattern)") .register(); - CommonFunctionFactory.listagg_stringAgg( "string", queryEngine ); - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.listagg_stringAgg( "string" ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } @Override 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 1a7de86837..ab1b9205d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java @@ -188,19 +188,20 @@ public class DB2Dialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function - CommonFunctionFactory.avg_castingNonDoubleArguments( this, queryEngine, SqlAstNodeRenderingMode.DEFAULT ); + functionFactory.avg_castingNonDoubleArguments( this, SqlAstNodeRenderingMode.DEFAULT ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); + functionFactory.cot(); + functionFactory.degrees(); + functionFactory.log(); + functionFactory.log10(); + functionFactory.radians(); + functionFactory.rand(); + functionFactory.soundex(); + functionFactory.trim2(); + functionFactory.space(); + functionFactory.repeat(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "substr" ) .setInvariantType( queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ) @@ -217,38 +218,38 @@ public class DB2Dialect extends Dialect { .setParameterTypes(FunctionParameterType.STRING, FunctionParameterType.INTEGER, FunctionParameterType.INTEGER, FunctionParameterType.ANY) .setArgumentListSignature( "(STRING string{ INTEGER from|,} start[{ INTEGER for|,} length[, units]])" ) .register(); - CommonFunctionFactory.translate( queryEngine ); - CommonFunctionFactory.bitand( queryEngine ); - CommonFunctionFactory.bitor( queryEngine ); - CommonFunctionFactory.bitxor( queryEngine ); - CommonFunctionFactory.bitnot( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.daynameMonthname( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.toCharNumberDateTimestamp( queryEngine ); - CommonFunctionFactory.dateTimeTimestamp( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.char_chr( queryEngine ); - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.insert( queryEngine ); - CommonFunctionFactory.overlayCharacterLength_overlay( queryEngine ); - CommonFunctionFactory.median( queryEngine ); - CommonFunctionFactory.stddev( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.regrLinearRegressionAggregates( queryEngine ); - CommonFunctionFactory.variance( queryEngine ); - CommonFunctionFactory.stdevVarianceSamp( queryEngine ); - CommonFunctionFactory.addYearsMonthsDaysHoursMinutesSeconds( queryEngine ); - CommonFunctionFactory.yearsMonthsDaysHoursMinutesSecondsBetween( queryEngine ); - CommonFunctionFactory.dateTrunc( queryEngine ); - CommonFunctionFactory.bitLength_pattern( queryEngine, "length(?1)*8" ); + functionFactory.translate(); + functionFactory.bitand(); + functionFactory.bitor(); + functionFactory.bitxor(); + functionFactory.bitnot(); + functionFactory.yearMonthDay(); + functionFactory.hourMinuteSecond(); + functionFactory.dayofweekmonthyear(); + functionFactory.weekQuarter(); + functionFactory.daynameMonthname(); + functionFactory.lastDay(); + functionFactory.toCharNumberDateTimestamp(); + functionFactory.dateTimeTimestamp(); + functionFactory.concat_pipeOperator(); + functionFactory.octetLength(); + functionFactory.ascii(); + functionFactory.char_chr(); + functionFactory.position(); + functionFactory.trunc(); + functionFactory.truncate(); + functionFactory.insert(); + functionFactory.overlayCharacterLength_overlay(); + functionFactory.median(); + functionFactory.stddev(); + functionFactory.stddevPopSamp(); + functionFactory.regrLinearRegressionAggregates(); + functionFactory.variance(); + functionFactory.stdevVarianceSamp(); + functionFactory.addYearsMonthsDaysHoursMinutesSeconds(); + functionFactory.yearsMonthsDaysHoursMinutesSecondsBetween(); + functionFactory.dateTrunc(); + functionFactory.bitLength_pattern( "length(?1)*8" ); queryEngine.getSqmFunctionRegistry().register( "format", new DB2FormatEmulation( queryEngine.getTypeConfiguration() ) ); @@ -263,10 +264,10 @@ public class DB2Dialect extends Dialect { .register(); if ( getDB2Version().isSameOrAfter( 9, 5 ) ) { - CommonFunctionFactory.listagg( null, queryEngine ); + functionFactory.listagg( null ); if ( getDB2Version().isSameOrAfter( 11, 1 ) ) { - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java index 57da4447d6..d3ce94f055 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java @@ -46,9 +46,10 @@ public class DB2iDialect extends DB2Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); if ( getVersion().isSameOrAfter( 7, 2 ) ) { - CommonFunctionFactory.listagg( null, queryEngine ); - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.listagg( null ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java index 150c9fc539..fcfcf84097 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java @@ -57,9 +57,10 @@ public class DB2zDialect extends DB2Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); if ( getVersion().isSameOrAfter( 12 ) ) { - CommonFunctionFactory.listagg( null, queryEngine ); - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.listagg( null ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } } 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 2d72ce1941..97450dfec0 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -217,38 +217,39 @@ public class DerbyDialect extends Dialect { final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); final BasicType stringType = basicTypeRegistry.resolve( StandardBasicTypes.STRING ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + // Derby needs an actual argument type for aggregates like SUM, AVG, MIN, MAX to determine the result type - CommonFunctionFactory.aggregates( + functionFactory.aggregates( this, - queryEngine, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER, "||", getCastTypeName( stringType, null, null, null ) ); // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function - CommonFunctionFactory.avg_castingNonDoubleArguments( this, queryEngine, SqlAstNodeRenderingMode.DEFAULT ); + functionFactory.avg_castingNonDoubleArguments( this, SqlAstNodeRenderingMode.DEFAULT ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.chr_char( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.trim1( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); - CommonFunctionFactory.leftRight_substrLength( queryEngine ); - CommonFunctionFactory.characterLength_length( queryEngine, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER ); - CommonFunctionFactory.power_expLn( queryEngine ); - CommonFunctionFactory.bitLength_pattern( queryEngine, "length(?1)*8" ); + functionFactory.concat_pipeOperator(); + functionFactory.cot(); + functionFactory.chr_char(); + functionFactory.degrees(); + functionFactory.radians(); + functionFactory.log10(); + functionFactory.sinh(); + functionFactory.cosh(); + functionFactory.tanh(); + functionFactory.pi(); + functionFactory.rand(); + functionFactory.trim1(); + functionFactory.hourMinuteSecond(); + functionFactory.yearMonthDay(); + functionFactory.varPopSamp(); + functionFactory.stddevPopSamp(); + functionFactory.substring_substr(); + functionFactory.leftRight_substrLength(); + functionFactory.characterLength_length( SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER ); + functionFactory.power_expLn(); + functionFactory.bitLength_pattern( "length(?1)*8" ); queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "round", "floor(?1*1e?2+0.5)/1e?2") .setReturnTypeResolver( useArgType(1) ) 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 ee426323ca..ae4f81e749 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -779,15 +779,17 @@ public abstract class Dialect implements ConversionContext { final BasicType localTimeType = basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_TIME ); final BasicType localDateType = basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_DATE ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + //aggregate functions, supported on every database - CommonFunctionFactory.aggregates( this, queryEngine, SqlAstNodeRenderingMode.DEFAULT, "||", null ); + functionFactory.aggregates( this, SqlAstNodeRenderingMode.DEFAULT, "||", null ); //the ANSI SQL-defined aggregate functions any() and every() are only //supported on one database, but can be emulated using sum() and case, //though there is a more natural mapping on some databases - CommonFunctionFactory.everyAny_sumCase( queryEngine ); + functionFactory.everyAny_sumCase(); //math functions supported on almost every database @@ -799,42 +801,42 @@ public abstract class Dialect implements ConversionContext { //decimal" version of these functions, and if any database attempted //to implement such a silly thing, it would be dog slow. - CommonFunctionFactory.math( queryEngine ); + functionFactory.math(); //trig functions supported on almost every database - CommonFunctionFactory.trigonometry( queryEngine ); + functionFactory.trigonometry(); //coalesce() function, supported by most databases, must be emulated //in terms of nvl() for platforms which don't support it natively - CommonFunctionFactory.coalesce( queryEngine ); + functionFactory.coalesce(); //nullif() function, supported on almost every database - CommonFunctionFactory.nullif( queryEngine ); + functionFactory.nullif(); //string functions, must be emulated where not supported - CommonFunctionFactory.leftRight( queryEngine ); - CommonFunctionFactory.replace( queryEngine ); - CommonFunctionFactory.concat( queryEngine ); - CommonFunctionFactory.lowerUpper( queryEngine ); + functionFactory.leftRight(); + functionFactory.replace(); + functionFactory.concat(); + functionFactory.lowerUpper(); //there are two forms of substring(), the JPA standard syntax, which //separates arguments using commas, and the ANSI SQL standard syntax //with named arguments (we support both) - CommonFunctionFactory.substring( queryEngine ); + functionFactory.substring(); //the JPA locate() function is especially tricky to emulate, calling //for lots of Dialect-specific customization - CommonFunctionFactory.locate( queryEngine ); + functionFactory.locate(); //JPA string length() function, a synonym for ANSI SQL character_length() - CommonFunctionFactory.length_characterLength( queryEngine ); + functionFactory.length_characterLength(); //only some databases support the ANSI SQL-style position() function, so //define it here as an alias for locate() @@ -870,7 +872,7 @@ public abstract class Dialect implements ConversionContext { //There is a 'collate' operator in a number of major databases - CommonFunctionFactory.collate( queryEngine ); + functionFactory.collate(); //ANSI SQL extract() function is supported on the databases we care most //about (though it is called datepart() in some of them) but HQL defines @@ -881,7 +883,7 @@ public abstract class Dialect implements ConversionContext { //comparison functions supported on every known database - CommonFunctionFactory.leastGreatest( queryEngine ); + functionFactory.leastGreatest(); //two-argument synonym for coalesce() supported on most but not every //database, so define it here as an alias for coalesce(arg1,arg2) @@ -892,7 +894,7 @@ public abstract class Dialect implements ConversionContext { //where not supported, but they're not considered "standard" ... instead //they're used to implement pad() - CommonFunctionFactory.pad( queryEngine ); + functionFactory.pad(); //pad() is a function we've designed to look like ANSI trim() @@ -907,7 +909,7 @@ public abstract class Dialect implements ConversionContext { //Oracle-style to_char() function, and on others using their native //formatting functions - CommonFunctionFactory.format_toChar( queryEngine ); + functionFactory.format_toChar(); //timestampadd()/timestampdiff() delegated back to the Dialect itself //since there is a great variety of different ways to emulate them diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java index 8dd11b497c..ffe510f118 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java @@ -223,70 +223,72 @@ public class H2Dialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - // H2 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, "||", null ); - // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function - CommonFunctionFactory.avg_castingNonDoubleArguments( this, queryEngine, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.translate( queryEngine ); - CommonFunctionFactory.bitand( queryEngine ); - CommonFunctionFactory.bitor( queryEngine ); - CommonFunctionFactory.bitxor( queryEngine ); - CommonFunctionFactory.bitAndOr( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.dayOfWeekMonthYear( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.daynameMonthname( queryEngine ); + // H2 needs an actual argument type for aggregates like SUM, AVG, MIN, MAX to determine the result type + functionFactory.aggregates( this, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER, "||", null ); + // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function + functionFactory.avg_castingNonDoubleArguments( this, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER ); + + functionFactory.pi(); + functionFactory.cot(); + functionFactory.radians(); + functionFactory.degrees(); + functionFactory.log10(); + functionFactory.rand(); + functionFactory.truncate(); + functionFactory.soundex(); + functionFactory.translate(); + functionFactory.bitand(); + functionFactory.bitor(); + functionFactory.bitxor(); + functionFactory.bitAndOr(); + functionFactory.yearMonthDay(); + functionFactory.hourMinuteSecond(); + functionFactory.dayOfWeekMonthYear(); + functionFactory.weekQuarter(); + functionFactory.daynameMonthname(); if ( useLocalTime ) { - CommonFunctionFactory.localtimeLocaltimestamp( queryEngine ); + functionFactory.localtimeLocaltimestamp(); } - CommonFunctionFactory.bitLength( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.chr_char( queryEngine ); - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); + functionFactory.bitLength(); + functionFactory.octetLength(); + functionFactory.ascii(); + functionFactory.octetLength(); + functionFactory.space(); + functionFactory.repeat(); + functionFactory.chr_char(); + functionFactory.instr(); + functionFactory.substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.trim1( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.nowCurdateCurtime( queryEngine ); - CommonFunctionFactory.sysdate( queryEngine ); - CommonFunctionFactory.insert( queryEngine ); -// CommonFunctionFactory.everyAny( queryEngine ); //this would work too - CommonFunctionFactory.everyAny_boolAndOr( queryEngine ); - CommonFunctionFactory.median( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); + functionFactory.position(); + functionFactory.trim1(); + functionFactory.concat_pipeOperator(); + functionFactory.nowCurdateCurtime(); + functionFactory.sysdate(); + functionFactory.insert(); +// functionFactory.everyAny(); //this would work too + functionFactory.everyAny_boolAndOr(); + functionFactory.median(); + functionFactory.stddevPopSamp(); + functionFactory.varPopSamp(); if ( getVersion().isSame( 1, 4, 200 ) ) { // See https://github.com/h2database/h2database/issues/2518 - CommonFunctionFactory.format_toChar( queryEngine ); + functionFactory.format_toChar(); } else { - CommonFunctionFactory.format_formatdatetime( queryEngine ); + functionFactory.format_formatdatetime(); } - CommonFunctionFactory.rownum( queryEngine ); + functionFactory.rownum(); if ( getVersion().isSameOrAfter( 1, 4, 200 ) ) { - CommonFunctionFactory.listagg( null, queryEngine ); + functionFactory.listagg( null ); if ( getVersion().isSameOrAfter( 2 ) ) { - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } } else { - CommonFunctionFactory.listagg_groupConcat( queryEngine ); + functionFactory.listagg_groupConcat(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java index f82d839d1d..3e0b3ba211 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java @@ -167,64 +167,66 @@ public class HSQLDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function - CommonFunctionFactory.avg_castingNonDoubleArguments( this, queryEngine, SqlAstNodeRenderingMode.DEFAULT ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.reverse( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.translate( queryEngine ); - CommonFunctionFactory.bitand( queryEngine ); - CommonFunctionFactory.bitor( queryEngine ); - CommonFunctionFactory.bitxor( queryEngine ); - CommonFunctionFactory.bitnot( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.daynameMonthname( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.trim1( queryEngine ); - CommonFunctionFactory.toCharNumberDateTimestamp( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.localtimeLocaltimestamp( queryEngine ); - CommonFunctionFactory.bitLength( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.chr_char( queryEngine ); - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); + // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function + functionFactory.avg_castingNonDoubleArguments( this, SqlAstNodeRenderingMode.DEFAULT ); + + functionFactory.cot(); + functionFactory.radians(); + functionFactory.degrees(); + functionFactory.log10(); + functionFactory.rand(); + functionFactory.trunc(); + functionFactory.truncate(); + functionFactory.pi(); + functionFactory.soundex(); + functionFactory.reverse(); + functionFactory.space(); + functionFactory.repeat(); + functionFactory.translate(); + functionFactory.bitand(); + functionFactory.bitor(); + functionFactory.bitxor(); + functionFactory.bitnot(); + functionFactory.yearMonthDay(); + functionFactory.hourMinuteSecond(); + functionFactory.dayofweekmonthyear(); + functionFactory.weekQuarter(); + functionFactory.daynameMonthname(); + functionFactory.lastDay(); + functionFactory.trim1(); + functionFactory.toCharNumberDateTimestamp(); + functionFactory.concat_pipeOperator(); + functionFactory.localtimeLocaltimestamp(); + functionFactory.bitLength(); + functionFactory.octetLength(); + functionFactory.ascii(); + functionFactory.chr_char(); + functionFactory.instr(); + functionFactory.substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.nowCurdateCurtime( queryEngine ); - CommonFunctionFactory.insert( queryEngine ); - CommonFunctionFactory.overlay( queryEngine ); - CommonFunctionFactory.median( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); - CommonFunctionFactory.addMonths( queryEngine ); - CommonFunctionFactory.monthsBetween( queryEngine ); - CommonFunctionFactory.collate_quoted( queryEngine ); + functionFactory.position(); + functionFactory.nowCurdateCurtime(); + functionFactory.insert(); + functionFactory.overlay(); + functionFactory.median(); + functionFactory.stddevPopSamp(); + functionFactory.varPopSamp(); + functionFactory.addMonths(); + functionFactory.monthsBetween(); + functionFactory.collate_quoted(); if ( getVersion().isSameOrAfter( 2 ) ) { //SYSDATE is similar to LOCALTIMESTAMP but it returns the timestamp when it is called - CommonFunctionFactory.sysdate( queryEngine ); + functionFactory.sysdate(); } // from v. 2.2.0 ROWNUM() is supported in all modes as the equivalent of Oracle ROWNUM if ( getVersion().isSameOrAfter( 2, 2 ) ) { - CommonFunctionFactory.rownum( queryEngine ); + functionFactory.rownum(); } - CommonFunctionFactory.listagg_groupConcat( queryEngine ); + functionFactory.listagg_groupConcat(); } @Override 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 da95a2390b..cf1adb96e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -383,70 +383,72 @@ public class MySQLDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.log2( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.pi( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.reverse( queryEngine ); - CommonFunctionFactory.space( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.pad_space( queryEngine ); - CommonFunctionFactory.md5( queryEngine ); - CommonFunctionFactory.yearMonthDay( queryEngine ); - CommonFunctionFactory.hourMinuteSecond( queryEngine ); - CommonFunctionFactory.dayofweekmonthyear( queryEngine ); - CommonFunctionFactory.weekQuarter( queryEngine ); - CommonFunctionFactory.daynameMonthname( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.date( queryEngine ); - CommonFunctionFactory.timestamp( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + + functionFactory.soundex(); + functionFactory.radians(); + functionFactory.degrees(); + functionFactory.cot(); + functionFactory.log(); + functionFactory.log2(); + functionFactory.log10(); + functionFactory.pi(); + functionFactory.trim2(); + functionFactory.octetLength(); + functionFactory.reverse(); + functionFactory.space(); + functionFactory.repeat(); + functionFactory.pad_space(); + functionFactory.md5(); + functionFactory.yearMonthDay(); + functionFactory.hourMinuteSecond(); + functionFactory.dayofweekmonthyear(); + functionFactory.weekQuarter(); + functionFactory.daynameMonthname(); + functionFactory.lastDay(); + functionFactory.date(); + functionFactory.timestamp(); time( queryEngine ); - CommonFunctionFactory.utcDateTimeTimestamp( queryEngine ); - CommonFunctionFactory.rand( queryEngine ); - CommonFunctionFactory.crc32( queryEngine ); - CommonFunctionFactory.sha1( queryEngine ); - CommonFunctionFactory.sha2( queryEngine ); - CommonFunctionFactory.sha( queryEngine ); - CommonFunctionFactory.bitLength( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.chr_char( queryEngine ); - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); + functionFactory.utcDateTimeTimestamp(); + functionFactory.rand(); + functionFactory.crc32(); + functionFactory.sha1(); + functionFactory.sha2(); + functionFactory.sha(); + functionFactory.bitLength(); + functionFactory.octetLength(); + functionFactory.ascii(); + functionFactory.chr_char(); + functionFactory.instr(); + functionFactory.substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.nowCurdateCurtime( queryEngine ); - CommonFunctionFactory.truncate( queryEngine ); - CommonFunctionFactory.insert( queryEngine ); - CommonFunctionFactory.bitandorxornot_operator( queryEngine ); - CommonFunctionFactory.bitAndOr( queryEngine ); - CommonFunctionFactory.stddev( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.variance( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); - CommonFunctionFactory.datediff( queryEngine ); - CommonFunctionFactory.adddateSubdateAddtimeSubtime( queryEngine ); - CommonFunctionFactory.format_dateFormat( queryEngine ); - CommonFunctionFactory.makedateMaketime( queryEngine ); + functionFactory.position(); + functionFactory.nowCurdateCurtime(); + functionFactory.truncate(); + functionFactory.insert(); + functionFactory.bitandorxornot_operator(); + functionFactory.bitAndOr(); + functionFactory.stddev(); + functionFactory.stddevPopSamp(); + functionFactory.variance(); + functionFactory.varPopSamp(); + functionFactory.datediff(); + functionFactory.adddateSubdateAddtimeSubtime(); + functionFactory.format_dateFormat(); + functionFactory.makedateMaketime(); if ( getMySQLVersion().isBefore( 5, 7 ) ) { - CommonFunctionFactory.sysdateParens( queryEngine ); + functionFactory.sysdateParens(); } else { // MySQL timestamp type defaults to precision 0 (seconds) but // we want the standard default precision of 6 (microseconds) - CommonFunctionFactory.sysdateExplicitMicros( queryEngine ); + functionFactory.sysdateExplicitMicros(); } queryEngine.getSqmFunctionRegistry().register( "field", new FieldFunction( queryEngine.getTypeConfiguration() ) ); - CommonFunctionFactory.listagg_groupConcat( queryEngine ); + functionFactory.listagg_groupConcat(); } @Override 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 2d71b44023..25b3c96253 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java @@ -137,49 +137,50 @@ public class OracleDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.log10_log( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.initcap( queryEngine ); - CommonFunctionFactory.instr( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); - CommonFunctionFactory.leftRight_substr( queryEngine ); - CommonFunctionFactory.translate( queryEngine ); - CommonFunctionFactory.bitand( queryEngine ); - CommonFunctionFactory.lastDay( queryEngine ); - CommonFunctionFactory.toCharNumberDateTimestamp( queryEngine ); - CommonFunctionFactory.ceiling_ceil( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.rownumRowid( queryEngine ); - CommonFunctionFactory.sysdate( queryEngine ); - CommonFunctionFactory.systimestamp( queryEngine ); - CommonFunctionFactory.characterLength_length( queryEngine, SqlAstNodeRenderingMode.DEFAULT ); - CommonFunctionFactory.addMonths( queryEngine ); - CommonFunctionFactory.monthsBetween( queryEngine ); - CommonFunctionFactory.everyAny_sumCaseCase( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.cosh(); + functionFactory.sinh(); + functionFactory.tanh(); + functionFactory.trunc(); + functionFactory.log(); + functionFactory.log10_log(); + functionFactory.soundex(); + functionFactory.trim2(); + functionFactory.initcap(); + functionFactory.instr(); + functionFactory.substr(); + functionFactory.substring_substr(); + functionFactory.leftRight_substr(); + functionFactory.translate(); + functionFactory.bitand(); + functionFactory.lastDay(); + functionFactory.toCharNumberDateTimestamp(); + functionFactory.ceiling_ceil(); + functionFactory.concat_pipeOperator(); + functionFactory.rownumRowid(); + functionFactory.sysdate(); + functionFactory.systimestamp(); + functionFactory.characterLength_length( SqlAstNodeRenderingMode.DEFAULT ); + functionFactory.addMonths(); + functionFactory.monthsBetween(); + functionFactory.everyAny_sumCaseCase(); - CommonFunctionFactory.median( queryEngine ); - CommonFunctionFactory.stddev( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.variance( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); - CommonFunctionFactory.covarPopSamp( queryEngine ); - CommonFunctionFactory.corr( queryEngine ); - CommonFunctionFactory.regrLinearRegressionAggregates( queryEngine ); - CommonFunctionFactory.bitLength_pattern( queryEngine, "vsize(?1)*8" ); + functionFactory.median(); + functionFactory.stddev(); + functionFactory.stddevPopSamp(); + functionFactory.variance(); + functionFactory.varPopSamp(); + functionFactory.covarPopSamp(); + functionFactory.corr(); + functionFactory.regrLinearRegressionAggregates(); + functionFactory.bitLength_pattern( "vsize(?1)*8" ); if ( getVersion().isBefore( 9 ) ) { queryEngine.getSqmFunctionRegistry().register( "coalesce", new NvlCoalesceEmulation() ); } else { //Oracle has had coalesce() since 9.0.1 - CommonFunctionFactory.coalesce( queryEngine ); + functionFactory.coalesce(); } queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( @@ -191,13 +192,13 @@ public class OracleDialect extends Dialect { ).setArgumentListSignature("(pattern, string[, start])"); // The within group clause became optional in 18 if ( getVersion().isSameOrAfter( 18 ) ) { - CommonFunctionFactory.listagg( null, queryEngine ); + functionFactory.listagg( null ); } else { - CommonFunctionFactory.listagg( "within group (order by rownum)", queryEngine ); + functionFactory.listagg( "within group (order by rownum)" ); } - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); + functionFactory.hypotheticalOrderedSetAggregates(); + functionFactory.inverseDistributionOrderedSetAggregates(); // Oracle has a regular aggregate function named stats_mode queryEngine.getSqmFunctionRegistry().register( "mode", 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 bd86a5732b..6738c563c3 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -402,59 +402,61 @@ public class PostgreSQLDialect extends Dialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.cot( queryEngine ); - CommonFunctionFactory.radians( queryEngine ); - CommonFunctionFactory.degrees( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.log( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + + functionFactory.cot(); + functionFactory.radians(); + functionFactory.degrees(); + functionFactory.trunc(); + functionFactory.log(); if ( getVersion().isSameOrAfter(12) ) { - CommonFunctionFactory.log10( queryEngine ); + functionFactory.log10(); } else { queryEngine.getSqmFunctionRegistry().registerAlternateKey( "log10", "log" ); } - CommonFunctionFactory.cbrt( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.md5( queryEngine ); - CommonFunctionFactory.initcap( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); + functionFactory.cbrt(); + functionFactory.trim2(); + functionFactory.octetLength(); + functionFactory.repeat(); + functionFactory.md5(); + functionFactory.initcap(); + functionFactory.substr(); + functionFactory.substring_substr(); //also natively supports ANSI-style substring() - CommonFunctionFactory.translate( queryEngine ); - CommonFunctionFactory.toCharNumberDateTimestamp( queryEngine ); - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.localtimeLocaltimestamp( queryEngine ); - CommonFunctionFactory.dateTrunc( queryEngine ); - CommonFunctionFactory.bitLength( queryEngine ); - CommonFunctionFactory.octetLength( queryEngine ); - CommonFunctionFactory.ascii( queryEngine ); - CommonFunctionFactory.char_chr( queryEngine ); - CommonFunctionFactory.position( queryEngine ); - CommonFunctionFactory.bitandorxornot_operator( queryEngine ); - CommonFunctionFactory.bitAndOr( queryEngine ); - CommonFunctionFactory.everyAny_boolAndOr( queryEngine ); - CommonFunctionFactory.median_percentileCont( queryEngine, false ); - CommonFunctionFactory.stddev( queryEngine ); - CommonFunctionFactory.stddevPopSamp( queryEngine ); - CommonFunctionFactory.variance( queryEngine ); - CommonFunctionFactory.varPopSamp( queryEngine ); - CommonFunctionFactory.covarPopSamp( queryEngine ); - CommonFunctionFactory.corr( queryEngine ); - CommonFunctionFactory.regrLinearRegressionAggregates( queryEngine ); - CommonFunctionFactory.insert_overlay( queryEngine ); - CommonFunctionFactory.overlay( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); //was introduced in Postgres 9 apparently + functionFactory.translate(); + functionFactory.toCharNumberDateTimestamp(); + functionFactory.concat_pipeOperator(); + functionFactory.localtimeLocaltimestamp(); + functionFactory.dateTrunc(); + functionFactory.bitLength(); + functionFactory.octetLength(); + functionFactory.ascii(); + functionFactory.char_chr(); + functionFactory.position(); + functionFactory.bitandorxornot_operator(); + functionFactory.bitAndOr(); + functionFactory.everyAny_boolAndOr(); + functionFactory.median_percentileCont( false ); + functionFactory.stddev(); + functionFactory.stddevPopSamp(); + functionFactory.variance(); + functionFactory.varPopSamp(); + functionFactory.covarPopSamp(); + functionFactory.corr(); + functionFactory.regrLinearRegressionAggregates(); + functionFactory.insert_overlay(); + functionFactory.overlay(); + functionFactory.soundex(); //was introduced in Postgres 9 apparently - CommonFunctionFactory.locate_positionSubstring( queryEngine ); - CommonFunctionFactory.listagg_stringAgg( "varchar", queryEngine ); + functionFactory.locate_positionSubstring(); + functionFactory.listagg_stringAgg( "varchar" ); if ( getVersion().isSameOrAfter( 9, 4 ) ) { - CommonFunctionFactory.makeDateTimeTimestamp( queryEngine ); + functionFactory.makeDateTimeTimestamp(); // Note that PostgreSQL doesn't support the OVER clause for ordered set-aggregate functions - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgresPlusDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgresPlusDialect.java index 8c9bbf0750..6c44a2f6f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgresPlusDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgresPlusDialect.java @@ -46,10 +46,11 @@ public class PostgresPlusDialect extends PostgreSQLDialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry( queryEngine ); - CommonFunctionFactory.soundex( queryEngine ); - CommonFunctionFactory.rownumRowid( queryEngine ); - CommonFunctionFactory.sysdate( queryEngine ); - CommonFunctionFactory.systimestamp( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.soundex(); + functionFactory.rownumRowid(); + functionFactory.sysdate(); + functionFactory.systimestamp(); // queryEngine.getSqmFunctionRegistry().register( "coalesce", new NvlCoalesceEmulation() ); 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 c0167a6780..4f2df9bea5 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java @@ -209,20 +209,22 @@ public class SQLServerDialect extends AbstractTransactSQLDialect { BasicType timeType = basicTypeRegistry.resolve( StandardBasicTypes.TIME ); BasicType timestampType = basicTypeRegistry.resolve( StandardBasicTypes.TIMESTAMP ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + // 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)" ); + functionFactory.aggregates( this, SqlAstNodeRenderingMode.DEFAULT, "+", "varchar(max)" ); // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function - CommonFunctionFactory.avg_castingNonDoubleArguments( this, queryEngine, SqlAstNodeRenderingMode.DEFAULT ); + functionFactory.avg_castingNonDoubleArguments( this, SqlAstNodeRenderingMode.DEFAULT ); - CommonFunctionFactory.truncate_round( queryEngine ); - CommonFunctionFactory.everyAny_sumIif( queryEngine ); - CommonFunctionFactory.bitLength_pattern( queryEngine, "datalength(?1) * 8" ); + functionFactory.truncate_round(); + functionFactory.everyAny_sumIif(); + functionFactory.bitLength_pattern( "datalength(?1) * 8" ); if ( getVersion().isSameOrAfter( 10 ) ) { - CommonFunctionFactory.locate_charindex( queryEngine ); - CommonFunctionFactory.stddevPopSamp_stdevp( queryEngine ); - CommonFunctionFactory.varPopSamp_varp( queryEngine ); + functionFactory.locate_charindex(); + functionFactory.stddevPopSamp_stdevp(); + functionFactory.varPopSamp_varp(); } if ( getVersion().isSameOrAfter( 11 ) ) { @@ -230,9 +232,9 @@ public class SQLServerDialect extends AbstractTransactSQLDialect { //actually translate() was added in 2017 but //it's not worth adding a new dialect for that! - CommonFunctionFactory.translate( queryEngine ); + functionFactory.translate(); - CommonFunctionFactory.median_percentileCont( queryEngine, true ); + functionFactory.median_percentileCont( true ); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datefromparts" ) .setInvariantType( dateType ) @@ -265,10 +267,10 @@ public class SQLServerDialect extends AbstractTransactSQLDialect { .setParameterTypes(INTEGER) .register(); } - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); if ( getVersion().isSameOrAfter( 14 ) ) { - CommonFunctionFactory.listagg_stringAggWithinGroup( "varchar(max)", queryEngine ); + functionFactory.listagg_stringAggWithinGroup( "varchar(max)" ); } } 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 64e6d059c3..8dc73f48de 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SpannerDialect.java @@ -179,17 +179,19 @@ public class SpannerDialect extends Dialect { .setArgumentCountBetween( 1, 2 ) .register(); - // Mathematical Functions - CommonFunctionFactory.log( queryEngine ); - CommonFunctionFactory.log10( queryEngine ); - CommonFunctionFactory.trunc( queryEngine ); - CommonFunctionFactory.ceiling_ceil( queryEngine ); - CommonFunctionFactory.cosh( queryEngine ); - CommonFunctionFactory.sinh( queryEngine ); - CommonFunctionFactory.tanh( queryEngine ); - CommonFunctionFactory.moreHyperbolic( queryEngine ); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); - CommonFunctionFactory.bitandorxornot_bitAndOrXorNot( queryEngine ); + // Mathematical Functions + functionFactory.log(); + functionFactory.log10(); + functionFactory.trunc(); + functionFactory.ceiling_ceil(); + functionFactory.cosh(); + functionFactory.sinh(); + functionFactory.tanh(); + functionFactory.moreHyperbolic(); + + functionFactory.bitandorxornot_bitAndOrXorNot(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "is_inf" ) .setInvariantType( booleanType ) @@ -208,7 +210,7 @@ public class SpannerDialect extends Dialect { .setExactArgumentCount( 2 ) .register(); - CommonFunctionFactory.sha1( queryEngine ); + functionFactory.sha1(); // Hash Functions queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "farm_fingerprint" ) @@ -225,12 +227,12 @@ public class SpannerDialect extends Dialect { .register(); // String Functions - CommonFunctionFactory.concat_pipeOperator( queryEngine ); - CommonFunctionFactory.trim2( queryEngine ); - CommonFunctionFactory.reverse( queryEngine ); - CommonFunctionFactory.repeat( queryEngine ); - CommonFunctionFactory.substr( queryEngine ); - CommonFunctionFactory.substring_substr( queryEngine ); + functionFactory.concat_pipeOperator(); + functionFactory.trim2(); + functionFactory.reverse(); + functionFactory.repeat(); + functionFactory.substr(); + functionFactory.substring_substr(); queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "byte_length" ) .setInvariantType( longType ) .setExactArgumentCount( 1 ) @@ -427,9 +429,9 @@ public class SpannerDialect extends Dialect { .setArgumentsValidator( CommonFunctionFactory.formatValidator() ) .setArgumentListSignature("(TIMESTAMP datetime as STRING pattern)") .register(); - CommonFunctionFactory.listagg_stringAgg( "string", queryEngine ); - CommonFunctionFactory.inverseDistributionOrderedSetAggregates( queryEngine ); - CommonFunctionFactory.hypotheticalOrderedSetAggregates( queryEngine ); + functionFactory.listagg_stringAgg( "string" ); + functionFactory.inverseDistributionOrderedSetAggregates(); + functionFactory.hypotheticalOrderedSetAggregates(); } @Override 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 c596d41839..5b96d4b21b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java @@ -205,20 +205,22 @@ public class SybaseDialect extends AbstractTransactSQLDialect { public void initializeFunctionRegistry(QueryEngine queryEngine) { super.initializeFunctionRegistry(queryEngine); + CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + // 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)" ); + functionFactory.aggregates( this, SqlAstNodeRenderingMode.DEFAULT, "+", "varchar(16384)" ); // AVG by default uses the input type, so we possibly need to cast the argument type, hence a special function - CommonFunctionFactory.avg_castingNonDoubleArguments( this, queryEngine, SqlAstNodeRenderingMode.DEFAULT ); + functionFactory.avg_castingNonDoubleArguments( this, SqlAstNodeRenderingMode.DEFAULT ); //this doesn't work 100% on earlier versions of Sybase //which were missing the third parameter in charindex() //TODO: we could emulate it with substring() like in Postgres - CommonFunctionFactory.locate_charindex( queryEngine ); + functionFactory.locate_charindex(); - CommonFunctionFactory.replace_strReplace( queryEngine ); - CommonFunctionFactory.everyAny_sumCaseCase( queryEngine ); - CommonFunctionFactory.bitLength_pattern( queryEngine, "datalength(?1) * 8" ); + functionFactory.replace_strReplace(); + functionFactory.everyAny_sumCaseCase(); + functionFactory.bitLength_pattern( "datalength(?1) * 8" ); } @Override 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 ba780e5428..6d4a32066b 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 @@ -12,6 +12,7 @@ import java.util.Arrays; import org.hibernate.dialect.Dialect; import org.hibernate.query.spi.QueryEngine; +import org.hibernate.query.sqm.function.SqmFunctionRegistry; import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator; import org.hibernate.query.sqm.produce.function.ArgumentsValidator; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; @@ -20,128 +21,156 @@ import org.hibernate.type.BasicType; import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.SqlTypes; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; import static org.hibernate.query.sqm.produce.function.FunctionParameterType.*; import static org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers.useArgType; /** - * A group common function template definitions. Centralized for easier use from - * Dialects + * Enumeratoes common function template definitions. + * Centralized for easier use from dialects. * * @author Steve Ebersole * @author Gavin King */ public class CommonFunctionFactory { + + private final BasicType booleanType; + private final BasicType characterType; + private final BasicType stringType; + private final BasicType integerType; + private final BasicType longType; + private final BasicType doubleType; + private final BasicType dateType; + private final BasicType timeType; + private final BasicType timestampType; + + private final SqmFunctionRegistry functionRegistry; + private final TypeConfiguration typeConfiguration; + + public CommonFunctionFactory(QueryEngine queryEngine) { + functionRegistry = queryEngine.getSqmFunctionRegistry(); + typeConfiguration = queryEngine.getTypeConfiguration(); + + BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); + dateType = basicTypeRegistry.resolve(StandardBasicTypes.DATE); + timeType = basicTypeRegistry.resolve(StandardBasicTypes.TIME); + timestampType = basicTypeRegistry.resolve(StandardBasicTypes.TIMESTAMP); + longType = basicTypeRegistry.resolve(StandardBasicTypes.LONG); + characterType = basicTypeRegistry.resolve(StandardBasicTypes.CHARACTER); + booleanType = basicTypeRegistry.resolve(StandardBasicTypes.BOOLEAN); + stringType = basicTypeRegistry.resolve(StandardBasicTypes.STRING); + integerType = basicTypeRegistry.resolve(StandardBasicTypes.INTEGER); + doubleType = basicTypeRegistry.resolve(StandardBasicTypes.DOUBLE); + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // trigonometric/geometric functions - public static void cosh(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "cosh" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void cosh() { + functionRegistry.namedDescriptorBuilder( "cosh" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void cot(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "cot" ) + public void cot() { + functionRegistry.namedDescriptorBuilder( "cot" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .register(); } - public static void degrees(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "degrees" ) + public void degrees() { + functionRegistry.namedDescriptorBuilder( "degrees" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .register(); } - public static void log(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "log" ) + public void log() { + functionRegistry.namedDescriptorBuilder( "log" ) .setArgumentCountBetween( 1, 2 ) .setParameterTypes(NUMERIC, NUMERIC) - .setInvariantType( - queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) - ) + .setInvariantType(doubleType) .register(); } - public static void ln_log(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ln", "log" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void ln_log() { + functionRegistry.namedDescriptorBuilder( "ln", "log" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void log10(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "log10" ) + public void log10() { + functionRegistry.namedDescriptorBuilder( "log10" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .register(); } /** * For Oracle and HANA */ - public static void log10_log(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "log10", "log(10,?1)" ) + public void log10_log() { + functionRegistry.patternDescriptorBuilder( "log10", "log(10,?1)" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .register(); } - public static void log2(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "log2" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void log2() { + functionRegistry.namedDescriptorBuilder( "log2" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void radians(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "radians" ) + public void radians() { + functionRegistry.namedDescriptorBuilder( "radians" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .register(); } - public static void sinh(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sinh" ) + public void sinh() { + functionRegistry.namedDescriptorBuilder( "sinh" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .register(); } - public static void tanh(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "tanh" ) + public void tanh() { + functionRegistry.namedDescriptorBuilder( "tanh" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .register(); } - public static void moreHyperbolic(QueryEngine queryEngine) { - final BasicType doubleType = getDoubleType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "acosh" ) - .setInvariantType( doubleType ) + public void moreHyperbolic() { + functionRegistry.namedDescriptorBuilder( "acosh" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "asinh" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "asinh" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "atanh" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "atanh" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); @@ -150,20 +179,20 @@ public class CommonFunctionFactory { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // basic math functions - public static void trunc(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "trunc" ) + public void trunc() { + functionRegistry.namedDescriptorBuilder( "trunc" ) .setArgumentCountBetween( 1, 2 ) .setParameterTypes(NUMERIC, INTEGER) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .setArgumentListSignature( "(NUMERIC number[, INTEGER places])" ) .register(); } - public static void truncate(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "truncate" ) + public void truncate() { + functionRegistry.namedDescriptorBuilder( "truncate" ) .setExactArgumentCount( 2 ) //some databases allow 1 arg but in these it's a synonym for trunc() .setParameterTypes(NUMERIC, INTEGER) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .setArgumentListSignature( "(NUMERIC number, INTEGER places)" ) .register(); } @@ -171,11 +200,11 @@ public class CommonFunctionFactory { /** * SQL Server */ - public static void truncate_round(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "truncate", "round(?1,?2,1)" ) + public void truncate_round() { + functionRegistry.patternDescriptorBuilder( "truncate", "round(?1,?2,1)" ) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, INTEGER) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .setArgumentListSignature( "(NUMERIC number, INTEGER places)" ) .register(); } @@ -183,31 +212,31 @@ public class CommonFunctionFactory { /** * Returns double between 0.0 and 1.0. First call may specify a seed value. */ - public static void rand(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "rand" ) + public void rand() { + functionRegistry.namedDescriptorBuilder( "rand" ) .setArgumentCountBetween( 0, 1 ) .setParameterTypes(INTEGER) .setUseParenthesesWhenNoArgs( true ) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .setArgumentListSignature( "([INTEGER seed])" ) .register(); } - public static void median(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "median" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void median() { + functionRegistry.namedAggregateDescriptorBuilder( "median" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void median_percentileCont(QueryEngine queryEngine, boolean over) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( + public void median_percentileCont(boolean over) { + functionRegistry.patternDescriptorBuilder( "median", "percentile_cont(0.5) within group (order by ?1)" + ( over ? " over()" : "" ) ) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); @@ -219,9 +248,9 @@ public class CommonFunctionFactory { * - On Postgres it means stdev_samp() * - On Oracle, DB2, MySQL it means stdev_pop() */ - public static void stddev(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stddev" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void stddev() { + functionRegistry.namedAggregateDescriptorBuilder( "stddev" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); @@ -233,76 +262,70 @@ public class CommonFunctionFactory { * - On Postgres it means var_samp() * - On Oracle, DB2, MySQL it means var_pop() */ - public static void variance(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "variance" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void variance() { + functionRegistry.namedAggregateDescriptorBuilder( "variance" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void stddevPopSamp(QueryEngine queryEngine) { - final BasicType doubleType = getDoubleType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stddev_pop" ) - .setInvariantType( doubleType ) + public void stddevPopSamp() { + functionRegistry.namedAggregateDescriptorBuilder( "stddev_pop" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stddev_samp" ) - .setInvariantType( doubleType ) + functionRegistry.namedAggregateDescriptorBuilder( "stddev_samp" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void varPopSamp(QueryEngine queryEngine) { - final BasicType doubleType = getDoubleType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "var_pop" ) - .setInvariantType( doubleType ) + public void varPopSamp() { + functionRegistry.namedAggregateDescriptorBuilder( "var_pop" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "var_samp" ) - .setInvariantType( doubleType ) + functionRegistry.namedAggregateDescriptorBuilder( "var_samp" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void covarPopSamp(QueryEngine queryEngine) { - final BasicType doubleType = getDoubleType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "covar_pop" ) - .setInvariantType( doubleType ) + public void covarPopSamp() { + functionRegistry.namedAggregateDescriptorBuilder( "covar_pop" ) + .setInvariantType(doubleType) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "covar_samp" ) - .setInvariantType( doubleType ) + functionRegistry.namedAggregateDescriptorBuilder( "covar_samp" ) + .setInvariantType(doubleType) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, NUMERIC) .register(); } - public static void corr(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "corr" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void corr() { + functionRegistry.namedAggregateDescriptorBuilder( "corr" ) + .setInvariantType(doubleType) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, NUMERIC) .register(); } - public static void regrLinearRegressionAggregates(QueryEngine queryEngine) { - final BasicType doubleType = queryEngine.getTypeConfiguration() - .getBasicTypeRegistry() - .resolve( StandardBasicTypes.DOUBLE ); + public void regrLinearRegressionAggregates() { 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( doubleType ) + fnName -> functionRegistry.namedAggregateDescriptorBuilder( fnName ) + .setInvariantType(doubleType) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, NUMERIC) .register() @@ -312,16 +335,14 @@ public class CommonFunctionFactory { /** * DB2 */ - public static void stdevVarianceSamp(QueryEngine queryEngine) { - final BasicType doubleType = getDoubleType( queryEngine ); - - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stddev_samp" ) - .setInvariantType( doubleType ) + public void stdevVarianceSamp() { + functionRegistry.namedAggregateDescriptorBuilder( "stddev_samp" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "variance_samp" ) - .setInvariantType( doubleType ) + functionRegistry.namedAggregateDescriptorBuilder( "variance_samp" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); @@ -330,45 +351,42 @@ public class CommonFunctionFactory { /** * SQL Server-style */ - public static void stddevPopSamp_stdevp(QueryEngine queryEngine) { - final BasicType doubleType = getDoubleType( queryEngine ); - - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stdev" ) - .setInvariantType( doubleType ) + public void stddevPopSamp_stdevp() { + functionRegistry.namedAggregateDescriptorBuilder( "stdev" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "stdevp" ) - .setInvariantType( doubleType ) + functionRegistry.namedAggregateDescriptorBuilder( "stdevp" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "stddev_samp", "stdev" ); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "stddev_pop", "stdevp" ); + functionRegistry.registerAlternateKey( "stddev_samp", "stdev" ); + functionRegistry.registerAlternateKey( "stddev_pop", "stdevp" ); } /** * SQL Server-style */ - public static void varPopSamp_varp(QueryEngine queryEngine) { - BasicType doubleType = getDoubleType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "var" ) - .setInvariantType( doubleType ) + public void varPopSamp_varp() { + functionRegistry.namedAggregateDescriptorBuilder( "var" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "varp" ) - .setInvariantType( doubleType ) + functionRegistry.namedAggregateDescriptorBuilder( "varp" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "var_samp", "var" ); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "var_pop", "varp" ); + functionRegistry.registerAlternateKey( "var_samp", "var" ); + functionRegistry.registerAlternateKey( "var_pop", "varp" ); } - public static void pi(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "pi" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void pi() { + functionRegistry.noArgsBuilder( "pi" ) + .setInvariantType(doubleType) .setUseParenthesesWhenNoArgs( true ) .register(); } @@ -376,55 +394,52 @@ public class CommonFunctionFactory { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // character functions - public static void soundex(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "soundex" ) + public void soundex() { + functionRegistry.namedDescriptorBuilder( "soundex" ) .setExactArgumentCount( 1 ) - .setInvariantType( getStringType( queryEngine ) ) + .setInvariantType(stringType) .register(); } - public static void trim2(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ltrim" ) - .setInvariantType( stringType ) + public void trim2() { + functionRegistry.namedDescriptorBuilder( "ltrim" ) + .setInvariantType(stringType) .setArgumentCountBetween( 1, 2 ) .setParameterTypes(STRING, STRING) .setArgumentListSignature( "(STRING string[, STRING characters])" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "rtrim" ) - .setInvariantType( stringType ) + functionRegistry.namedDescriptorBuilder( "rtrim" ) + .setInvariantType(stringType) .setArgumentCountBetween( 1, 2 ) .setParameterTypes(STRING, STRING) .setArgumentListSignature( "(STRING string[, STRING characters])" ) .register(); } - public static void trim1(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ltrim" ) - .setInvariantType( stringType ) + public void trim1() { + functionRegistry.namedDescriptorBuilder( "ltrim" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .setArgumentListSignature( "(STRING string)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "rtrim" ) - .setInvariantType( stringType ) + functionRegistry.namedDescriptorBuilder( "rtrim" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .setArgumentListSignature( "(STRING string)" ) .register(); } - public static void pad(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "lpad" ) - .setInvariantType( stringType ) + public void pad() { + functionRegistry.namedDescriptorBuilder( "lpad" ) + .setInvariantType(stringType) .setArgumentCountBetween( 2, 3 ) .setParameterTypes(STRING, INTEGER, STRING) .setArgumentListSignature( "(STRING string, INTEGER length[, STRING padding])" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "rpad" ) - .setInvariantType( stringType ) + functionRegistry.namedDescriptorBuilder( "rpad" ) + .setInvariantType(stringType) .setArgumentCountBetween( 2, 3 ) .setParameterTypes(STRING, INTEGER, STRING) .setArgumentListSignature( "(STRING string, INTEGER length[, STRING padding])" ) @@ -434,16 +449,15 @@ public class CommonFunctionFactory { /** * In MySQL the third argument is required */ - public static void pad_space(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + public void pad_space() { + functionRegistry.registerBinaryTernaryPattern( "lpad", stringType, "lpad(?1,?2,' ')", "lpad(?1,?2,?3)", STRING, INTEGER, STRING ).setArgumentListSignature( "(string, length[, padding])" ); - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + functionRegistry.registerBinaryTernaryPattern( "rpad", stringType, "rpad(?1,?2,' ')", @@ -455,16 +469,15 @@ public class CommonFunctionFactory { /** * Transact-SQL */ - public static void pad_replicate(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + public void pad_replicate() { + functionRegistry.registerBinaryTernaryPattern( "lpad", stringType, "(space(?2-len(?1))+?1)", "(replicate(?3,?2-len(?1))+?1)", STRING, INTEGER, STRING ).setArgumentListSignature( "(string, length[, padding])" ); - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + functionRegistry.registerBinaryTernaryPattern( "rpad", stringType, "(?1+space(?2-len(?1)))", @@ -473,16 +486,15 @@ public class CommonFunctionFactory { ).setArgumentListSignature( "(string, length[, padding])" ); } - public static void pad_repeat(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + public void pad_repeat() { + functionRegistry.registerBinaryTernaryPattern( "lpad", stringType, "(repeat(' ',?2-character_length(?1))||?1)", "(repeat(?3,?2-character_length(?1))||?1)", STRING, INTEGER, STRING ).setArgumentListSignature( "(string, length[, padding])" ); - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + functionRegistry.registerBinaryTernaryPattern( "rpad", stringType, "(?1||repeat(' ',?2-character_length(?1)))", @@ -494,16 +506,15 @@ public class CommonFunctionFactory { /** * SAP DB */ - public static void pad_fill(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + public void pad_fill() { + functionRegistry.registerBinaryTernaryPattern( "lpad", stringType, "lfill(?1,' ',?2)", "lfill(?1,?3,?2)", STRING, INTEGER, STRING ).setArgumentListSignature( "(string, length[, padding])" ); - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + functionRegistry.registerBinaryTernaryPattern( "rpad", stringType, "rfill(?1,' ',?2)", @@ -512,150 +523,145 @@ public class CommonFunctionFactory { ).setArgumentListSignature( "(string, length[, padding])" ); } - public static void reverse(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "reverse" ) - .setInvariantType( getStringType( queryEngine ) ) + public void reverse() { + functionRegistry.namedDescriptorBuilder( "reverse" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .register(); } - public static void space(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "space" ) - .setInvariantType( getStringType( queryEngine ) ) + public void space() { + functionRegistry.namedDescriptorBuilder( "space" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .setParameterTypes(INTEGER) .register(); } - public static void repeat(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "repeat" ) - .setInvariantType( getStringType( queryEngine ) ) + public void repeat() { + functionRegistry.namedDescriptorBuilder( "repeat" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER times)" ) .register(); } - public static void leftRight(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "left" ) - .setInvariantType( stringType ) + public void leftRight() { + functionRegistry.namedDescriptorBuilder( "left" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER length)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "right" ) - .setInvariantType( stringType ) + functionRegistry.namedDescriptorBuilder( "right" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER length)" ) .register(); } - public static void leftRight_substr(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "left", "substr(?1,1,?2)" ) - .setInvariantType( stringType ) + public void leftRight_substr() { + functionRegistry.patternDescriptorBuilder( "left", "substr(?1,1,?2)" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER length)" ) .register(); - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "right", "substr(?1,-?2)" ) - .setInvariantType( stringType ) + functionRegistry.patternDescriptorBuilder( "right", "substr(?1,-?2)" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER length)" ) .register(); } - public static void leftRight_substrLength(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "left", "substr(?1,1,?2)" ) - .setInvariantType( stringType ) + public void leftRight_substrLength() { + functionRegistry.patternDescriptorBuilder( "left", "substr(?1,1,?2)" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER length)" ) .register(); - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "right", "substr(?1,length(?1)-?2+1)" ) - .setInvariantType( stringType ) + functionRegistry.patternDescriptorBuilder( "right", "substr(?1,length(?1)-?2+1)" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER length)" ) .register(); } - public static void repeat_replicate(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "replicate" ) - .setInvariantType( getStringType( queryEngine ) ) + public void repeat_replicate() { + functionRegistry.namedDescriptorBuilder( "replicate" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER times)" ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "repeat", "replicate" ); + functionRegistry.registerAlternateKey( "repeat", "replicate" ); } - public static void md5(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "md5" ) - .setInvariantType( - getStringType( queryEngine ) - ) + public void md5() { + functionRegistry.namedDescriptorBuilder( "md5" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .register(); } - public static void initcap(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "initcap" ) - .setInvariantType( getStringType( queryEngine ) ) + public void initcap() { + functionRegistry.namedDescriptorBuilder( "initcap" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .register(); } - public static void instr(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "instr" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void instr() { + functionRegistry.namedDescriptorBuilder( "instr" ) + .setInvariantType(integerType) .setArgumentCountBetween( 2, 4 ) .setParameterTypes(STRING, STRING, INTEGER, INTEGER) .setArgumentListSignature( "(STRING string, STRING pattern[, INTEGER start[, INTEGER occurrence]])" ) .register(); } - public static void substr(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "substr" ) - .setInvariantType( getStringType( queryEngine ) ) + public void substr() { + functionRegistry.namedDescriptorBuilder( "substr" ) + .setInvariantType(stringType) .setArgumentCountBetween( 2, 3 ) .setParameterTypes(STRING, INTEGER, INTEGER) .setArgumentListSignature( "(STRING string, INTEGER start[, INTEGER length])" ) .register(); } - public static void translate(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "translate" ) - .setInvariantType( getStringType( queryEngine ) ) + public void translate() { + functionRegistry.namedDescriptorBuilder( "translate" ) + .setInvariantType(stringType) .setExactArgumentCount( 3 ) .register(); } - public static void bitand(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bitand" ) + public void bitand() { + functionRegistry.namedDescriptorBuilder( "bitand" ) .setExactArgumentCount( 2 ) .register(); } - public static void bitor(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bitor" ) + public void bitor() { + functionRegistry.namedDescriptorBuilder( "bitor" ) .setExactArgumentCount( 2 ) .register(); } - public static void bitxor(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bitxor" ) + public void bitxor() { + functionRegistry.namedDescriptorBuilder( "bitxor" ) .setExactArgumentCount( 2 ) .register(); } - public static void bitnot(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bitnot" ) + public void bitnot() { + functionRegistry.namedDescriptorBuilder( "bitnot" ) .setExactArgumentCount( 1 ) .register(); } @@ -663,70 +669,70 @@ public class CommonFunctionFactory { /** * Binary bitwise operators, not aggregate functions! */ - public static void bitandorxornot_bitAndOrXorNot(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bit_and" ) + public void bitandorxornot_bitAndOrXorNot() { + functionRegistry.namedDescriptorBuilder( "bit_and" ) .setExactArgumentCount( 2 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "bitand", "bit_and" ); + functionRegistry.registerAlternateKey( "bitand", "bit_and" ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bit_or" ) + functionRegistry.namedDescriptorBuilder( "bit_or" ) .setExactArgumentCount( 2 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "bitor", "bit_or" ); + functionRegistry.registerAlternateKey( "bitor", "bit_or" ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bit_xor" ) + functionRegistry.namedDescriptorBuilder( "bit_xor" ) .setExactArgumentCount( 2 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "bitxor", "bit_xor" ); + functionRegistry.registerAlternateKey( "bitxor", "bit_xor" ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bit_not" ) + functionRegistry.namedDescriptorBuilder( "bit_not" ) .setExactArgumentCount( 1 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "bitnot", "bit_not" ); + functionRegistry.registerAlternateKey( "bitnot", "bit_not" ); } /** * Bitwise operators, not aggregate functions! */ - public static void bitandorxornot_binAndOrXorNot(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bin_and" ) + public void bitandorxornot_binAndOrXorNot() { + functionRegistry.namedDescriptorBuilder( "bin_and" ) .setMinArgumentCount( 1 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "bitand", "bin_and" ); + functionRegistry.registerAlternateKey( "bitand", "bin_and" ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bin_or" ) + functionRegistry.namedDescriptorBuilder( "bin_or" ) .setMinArgumentCount( 1 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "bitor", "bin_or" ); + functionRegistry.registerAlternateKey( "bitor", "bin_or" ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bin_xor" ) + functionRegistry.namedDescriptorBuilder( "bin_xor" ) .setMinArgumentCount( 1 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "bitxor", "bin_xor" ); + functionRegistry.registerAlternateKey( "bitxor", "bin_xor" ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bin_not" ) + functionRegistry.namedDescriptorBuilder( "bin_not" ) .setExactArgumentCount( 1 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "bitnot", "bin_not" ); + functionRegistry.registerAlternateKey( "bitnot", "bin_not" ); } /** * Binary bitwise operators, not aggregate functions! */ - public static void bitandorxornot_operator(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "bitand", "(?1&?2)" ) + public void bitandorxornot_operator() { + functionRegistry.patternDescriptorBuilder( "bitand", "(?1&?2)" ) .setExactArgumentCount( 2 ) .register(); - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "bitor", "(?1|?2)" ) + functionRegistry.patternDescriptorBuilder( "bitor", "(?1|?2)" ) .setExactArgumentCount( 2 ) .register(); - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "bitxor", "(?1^?2)" ) + functionRegistry.patternDescriptorBuilder( "bitxor", "(?1^?2)" ) .setExactArgumentCount( 2 ) .register(); - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "bitnot", "~?1" ) + functionRegistry.patternDescriptorBuilder( "bitnot", "~?1" ) .setExactArgumentCount( 1 ) .register(); } @@ -734,17 +740,17 @@ public class CommonFunctionFactory { /** * These are aggregate functions taking one argument! */ - public static void bitAndOr(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "bit_and" ) + public void bitAndOr() { + functionRegistry.namedAggregateDescriptorBuilder( "bit_and" ) .setExactArgumentCount( 1 ) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "bit_or" ) + functionRegistry.namedAggregateDescriptorBuilder( "bit_or" ) .setExactArgumentCount( 1 ) .register(); //MySQL has it but how is that even useful? -// queryEngine.getSqmFunctionRegistry().namedTemplateBuilder( "bit_xor" ) +// functionRegistry.namedTemplateBuilder( "bit_xor" ) // .setExactArgumentCount( 1 ) // .register(); } @@ -752,19 +758,17 @@ public class CommonFunctionFactory { /** * These are aggregate functions taking one argument! */ - public static void everyAny(QueryEngine queryEngine) { - final BasicType booleanType = getBooleanType( queryEngine ); - - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "every" ) + public void everyAny() { + functionRegistry.namedAggregateDescriptorBuilder( "every" ) .setExactArgumentCount( 1 ) - .setInvariantType( booleanType ) + .setInvariantType(booleanType) .setParameterTypes(BOOLEAN) .setArgumentListSignature( "(BOOLEAN predicate)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "any" ) + functionRegistry.namedAggregateDescriptorBuilder( "any" ) .setExactArgumentCount( 1 ) - .setInvariantType( booleanType ) + .setInvariantType(booleanType) .setParameterTypes(BOOLEAN) .setArgumentListSignature( "(BOOLEAN predicate)" ) .register(); @@ -775,24 +779,22 @@ public class CommonFunctionFactory { * databases that can directly aggregate both boolean columns * and predicates! */ - public static void everyAny_boolAndOr(QueryEngine queryEngine) { - final BasicType booleanType = getBooleanType(queryEngine); - - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "bool_and" ) + public void everyAny_boolAndOr() { + functionRegistry.namedAggregateDescriptorBuilder( "bool_and" ) .setExactArgumentCount( 1 ) .setParameterTypes(BOOLEAN) - .setInvariantType( booleanType ) + .setInvariantType(booleanType) .setArgumentListSignature( "(BOOLEAN predicate)" ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "every", "bool_and" ); + functionRegistry.registerAlternateKey( "every", "bool_and" ); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "bool_or" ) + functionRegistry.namedAggregateDescriptorBuilder( "bool_or" ) .setExactArgumentCount( 1 ) .setParameterTypes(BOOLEAN) - .setInvariantType( booleanType ) + .setInvariantType(booleanType) .setArgumentListSignature( "(BOOLEAN predicate)" ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "any", "bool_or" ); + functionRegistry.registerAlternateKey( "any", "bool_or" ); } /** @@ -800,22 +802,22 @@ public class CommonFunctionFactory { * for databases that have to emulate the boolean * aggregation functions using sum() and case. */ - public static void everyAny_sumCase(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( "every", - new EveryAnyEmulation( queryEngine.getTypeConfiguration(), true ) ); - queryEngine.getSqmFunctionRegistry().register( "any", - new EveryAnyEmulation( queryEngine.getTypeConfiguration(), false ) ); + public void everyAny_sumCase() { + functionRegistry.register( "every", + new EveryAnyEmulation( typeConfiguration, true ) ); + functionRegistry.register( "any", + new EveryAnyEmulation( typeConfiguration, false ) ); } /** * These are aggregate functions taking one argument, * for SQL Server. */ - public static void everyAny_sumIif(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( "every", - new SQLServerEveryAnyEmulation( queryEngine.getTypeConfiguration(), true ) ); - queryEngine.getSqmFunctionRegistry().register( "any", - new SQLServerEveryAnyEmulation( queryEngine.getTypeConfiguration(), false ) ); + public void everyAny_sumIif() { + functionRegistry.register( "every", + new SQLServerEveryAnyEmulation( typeConfiguration, true ) ); + functionRegistry.register( "any", + new SQLServerEveryAnyEmulation( typeConfiguration, false ) ); } @@ -823,11 +825,11 @@ public class CommonFunctionFactory { * These are aggregate functions taking one argument, * for Oracle and Sybase. */ - public static void everyAny_sumCaseCase(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( "every", - new CaseWhenEveryAnyEmulation( queryEngine.getTypeConfiguration(), true ) ); - queryEngine.getSqmFunctionRegistry().register( "any", - new CaseWhenEveryAnyEmulation( queryEngine.getTypeConfiguration(), false ) ); + public void everyAny_sumCaseCase() { + functionRegistry.register( "every", + new CaseWhenEveryAnyEmulation( typeConfiguration, true ) ); + functionRegistry.register( "any", + new CaseWhenEveryAnyEmulation( typeConfiguration, false ) ); } /** @@ -835,20 +837,19 @@ public class CommonFunctionFactory { * since their names collide with the HQL abbreviations * for extract(), they can't actually be called from HQL. */ - public static void yearMonthDay(QueryEngine queryEngine) { - final BasicType integerType = getIntegerType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "day" ) - .setInvariantType( integerType ) + public void yearMonthDay() { + functionRegistry.namedDescriptorBuilder( "day" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "month" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "month" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "year" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "year" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); @@ -859,226 +860,219 @@ public class CommonFunctionFactory { * since their names collide with the HQL abbreviations * for extract(), they can't actually be called from HQL. */ - public static void hourMinuteSecond(QueryEngine queryEngine) { - final BasicType integerType = getIntegerType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "hour" ) - .setInvariantType( integerType ) + public void hourMinuteSecond() { + functionRegistry.namedDescriptorBuilder( "hour" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(TIME) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "minute" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "minute" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(TIME) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "second" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "second" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(TIME) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "microsecond" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "microsecond" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(TIME) .register(); } - public static void dayofweekmonthyear(QueryEngine queryEngine) { - final BasicType integerType = getIntegerType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "dayofweek" ) - .setInvariantType( integerType ) + public void dayofweekmonthyear() { + functionRegistry.namedDescriptorBuilder( "dayofweek" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "dayofmonth" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "dayofmonth" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "day", "dayofmonth" ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "dayofyear" ) - .setInvariantType( integerType ) + functionRegistry.registerAlternateKey( "day", "dayofmonth" ); + functionRegistry.namedDescriptorBuilder( "dayofyear" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); } - public static void dayOfWeekMonthYear(QueryEngine queryEngine) { - final BasicType integerType = getIntegerType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "day_of_week" ) - .setInvariantType( integerType ) + public void dayOfWeekMonthYear() { + functionRegistry.namedDescriptorBuilder( "day_of_week" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "day_of_month" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "day_of_month" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "day", "day_of_month" ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "day_of_year" ) - .setInvariantType( integerType ) + functionRegistry.registerAlternateKey( "day", "day_of_month" ); + functionRegistry.namedDescriptorBuilder( "day_of_year" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); } - public static void daynameMonthname(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "monthname" ) - .setInvariantType( stringType ) + public void daynameMonthname() { + functionRegistry.namedDescriptorBuilder( "monthname" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "dayname" ) - .setInvariantType( stringType ) + functionRegistry.namedDescriptorBuilder( "dayname" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); } - public static void weekQuarter(QueryEngine queryEngine) { - final BasicType integerType = getIntegerType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "week" ) - .setInvariantType( integerType ) + public void weekQuarter() { + functionRegistry.namedDescriptorBuilder( "week" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "quarter" ) + functionRegistry.namedDescriptorBuilder( "quarter" ) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) - .setInvariantType( integerType ) + .setInvariantType(integerType) .register(); } - public static void lastDay(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "last_day" ) - .setInvariantType( getDateType( queryEngine ) ) + public void lastDay() { + functionRegistry.namedDescriptorBuilder( "last_day" ) + .setInvariantType(dateType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); } - public static void lastDay_eomonth(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "eomonth" ) - .setInvariantType( getDateType( queryEngine ) ) + public void lastDay_eomonth() { + functionRegistry.namedDescriptorBuilder( "eomonth" ) + .setInvariantType(dateType) .setArgumentCountBetween( 1, 2 ) .setParameterTypes(DATE, INTEGER) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "last_date", "eomonth" ); + functionRegistry.registerAlternateKey( "last_date", "eomonth" ); } - public static void ceiling_ceil(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ceil" ) + public void ceiling_ceil() { + functionRegistry.namedDescriptorBuilder( "ceil" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) // To avoid truncating to a specific data type, we default to using the argument type .setReturnTypeResolver( useArgType( 1 ) ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "ceiling", "ceil" ); + functionRegistry.registerAlternateKey( "ceiling", "ceil" ); } - public static void toCharNumberDateTimestamp(QueryEngine queryEngine) { + public void toCharNumberDateTimestamp() { //argument counts are right for Oracle, TimesTen, and CUBRID - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_number" ) + functionRegistry.namedDescriptorBuilder( "to_number" ) //always 1 arg on HSQL and Cache, always 2 on Postgres .setArgumentCountBetween( 1, 3 ) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_char" ) + functionRegistry.namedDescriptorBuilder( "to_char" ) .setArgumentCountBetween( 1, 3 ) //always 2 args on HSQL and Postgres - .setInvariantType( getStringType( queryEngine ) ) + .setInvariantType(stringType) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_date" ) + functionRegistry.namedDescriptorBuilder( "to_date" ) //always 2 args on HSQL and Postgres .setArgumentCountBetween( 1, 3 ) - .setInvariantType( getDateType( queryEngine ) ) + .setInvariantType(dateType) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "to_timestamp" ) + functionRegistry.namedDescriptorBuilder( "to_timestamp" ) //always 2 args on HSQL and Postgres .setArgumentCountBetween( 1, 3 ) - .setInvariantType( getTimestampType( queryEngine ) ) + .setInvariantType(timestampType) .register(); } - public static void dateTimeTimestamp(QueryEngine queryEngine) { - date( queryEngine ); - time( queryEngine ); - timestamp( queryEngine ); + public void dateTimeTimestamp() { + date(); + time(); + timestamp(); } - public static void timestamp(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "timestamp" ) + public void timestamp() { + functionRegistry.namedDescriptorBuilder( "timestamp" ) .setArgumentCountBetween( 1, 2 ) //accepts (DATE,TIME) (DATE,INTEGER) or DATE or STRING - .setInvariantType( getTimestampType( queryEngine ) ) + .setInvariantType(timestampType) .register(); } - public static void time(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "time" ) + public void time() { + functionRegistry.namedDescriptorBuilder( "time" ) .setExactArgumentCount( 1 ) //accepts TIME or STRING - .setInvariantType( - queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.TIME ) - ) + .setInvariantType(timeType) .register(); } - public static void date(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "date" ) + public void date() { + functionRegistry.namedDescriptorBuilder( "date" ) .setExactArgumentCount( 1 ) //accepts DATE or STRING - .setInvariantType( getDateType( queryEngine ) ) + .setInvariantType(dateType) .register(); } - public static void utcDateTimeTimestamp(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "utc_date" ) + public void utcDateTimeTimestamp() { + functionRegistry.noArgsBuilder( "utc_date" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( getDateType( queryEngine ) ) + .setInvariantType(dateType) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "utc_time" ) + functionRegistry.noArgsBuilder( "utc_time" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( getTimeType( queryEngine ) ) + .setInvariantType(timeType) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "utc_timestamp" ) + functionRegistry.noArgsBuilder( "utc_timestamp" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( getTimestampType( queryEngine ) ) + .setInvariantType(timestampType) .register(); } - public static void currentUtcdatetimetimestamp(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "current_utcdate" ) + public void currentUtcdatetimetimestamp() { + functionRegistry.noArgsBuilder( "current_utcdate" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( getDateType( queryEngine ) ) + .setInvariantType(dateType) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "current_utctime" ) + functionRegistry.noArgsBuilder( "current_utctime" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( getTimeType( queryEngine ) ) + .setInvariantType(timeType) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "current_utctimestamp" ) + functionRegistry.noArgsBuilder( "current_utctimestamp" ) .setUseParenthesesWhenNoArgs( false ) - .setInvariantType( getTimestampType( queryEngine ) ) + .setInvariantType(timestampType) .register(); } - public static void week_weekofyear(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "weekofyear" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void week_weekofyear() { + functionRegistry.namedDescriptorBuilder( "weekofyear" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(DATE) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "week", "weekofyear" ); + functionRegistry.registerAlternateKey( "week", "weekofyear" ); } /** * Almost every database */ - public static void concat_pipeOperator(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "concat", "(?1||?2...)" ) - .setInvariantType( getStringType( queryEngine ) ) + public void concat_pipeOperator() { + functionRegistry.patternDescriptorBuilder( "concat", "(?1||?2...)" ) + .setInvariantType(stringType) .setMinArgumentCount( 1 ) .setParameterTypes(STRING) .setArgumentListSignature( "(STRING string0[, STRING string1[, ...]])" ) @@ -1088,9 +1082,9 @@ public class CommonFunctionFactory { /** * Transact SQL-style */ - public static void concat_plusOperator(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "concat", "(?1+?2...)" ) - .setInvariantType( getStringType( queryEngine ) ) + public void concat_plusOperator() { + functionRegistry.patternDescriptorBuilder( "concat", "(?1+?2...)" ) + .setInvariantType(stringType) .setMinArgumentCount( 1 ) .setParameterTypes(STRING) .setArgumentListSignature( "(STRING string0[, STRING string1[, ...]])" ) @@ -1100,14 +1094,13 @@ public class CommonFunctionFactory { /** * Oracle-style */ - public static void rownumRowid(QueryEngine queryEngine) { - final BasicType longType = getLongType( queryEngine ); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "rowid" ) - .setInvariantType( longType ) + public void rownumRowid() { + functionRegistry.noArgsBuilder( "rowid" ) + .setInvariantType(longType) .setUseParenthesesWhenNoArgs( false ) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "rownum" ) - .setInvariantType( longType ) + functionRegistry.noArgsBuilder( "rownum" ) + .setInvariantType(longType) .setUseParenthesesWhenNoArgs( false ) .register(); } @@ -1115,9 +1108,9 @@ public class CommonFunctionFactory { /** * H2/HSQL-style */ - public static void rownum(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "rownum" ) - .setInvariantType( getLongType( queryEngine ) ) + public void rownum() { + functionRegistry.noArgsBuilder( "rownum" ) + .setInvariantType(longType) .setUseParenthesesWhenNoArgs( true ) //H2 and HSQL require the parens .register(); } @@ -1125,24 +1118,22 @@ public class CommonFunctionFactory { /** * CUBRID */ - public static void rownumInstOrderbyGroupbyNum(QueryEngine queryEngine) { - final BasicType integerType = getIntegerType( queryEngine ); - - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "rownum" ) - .setInvariantType( integerType ) + public void rownumInstOrderbyGroupbyNum() { + functionRegistry.noArgsBuilder( "rownum" ) + .setInvariantType(integerType) .setUseParenthesesWhenNoArgs( false ) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "inst_num" ) - .setInvariantType( integerType ) + functionRegistry.noArgsBuilder( "inst_num" ) + .setInvariantType(integerType) .setUseParenthesesWhenNoArgs( true ) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "orderby_num" ) - .setInvariantType( integerType ) + functionRegistry.noArgsBuilder( "orderby_num" ) + .setInvariantType(integerType) .setUseParenthesesWhenNoArgs( true ) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "groupby_num" ) - .setInvariantType( integerType ) + functionRegistry.noArgsBuilder( "groupby_num" ) + .setInvariantType(integerType) .setUseParenthesesWhenNoArgs( true ) .register(); } @@ -1150,15 +1141,15 @@ public class CommonFunctionFactory { /** * MySQL/CUBRID */ - public static void makedateMaketime(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "makedate" ) - .setInvariantType( getDateType( queryEngine ) ) + public void makedateMaketime() { + functionRegistry.namedDescriptorBuilder( "makedate" ) + .setInvariantType(dateType) .setExactArgumentCount( 2 ) .setParameterTypes(INTEGER, INTEGER) .setArgumentListSignature( "(INTEGER year, INTEGER dayofyear)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "maketime" ) - .setInvariantType( getTimeType( queryEngine ) ) + functionRegistry.namedDescriptorBuilder( "maketime" ) + .setInvariantType(timeType) .setExactArgumentCount( 3 ) .setParameterTypes(INTEGER, INTEGER, INTEGER) .setArgumentListSignature( "(INTEGER hour, INTEGER min, INTEGER sec)" ) @@ -1168,34 +1159,33 @@ public class CommonFunctionFactory { /** * Postgres */ - public static void makeDateTimeTimestamp(QueryEngine queryEngine) { - BasicType timestampType = getTimestampType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "make_date" ) - .setInvariantType( getDateType( queryEngine ) ) + public void makeDateTimeTimestamp() { + functionRegistry.namedDescriptorBuilder( "make_date" ) + .setInvariantType(dateType) .setExactArgumentCount( 3 ) .setParameterTypes(INTEGER, INTEGER, INTEGER) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "make_time" ) - .setInvariantType( getTimeType( queryEngine ) ) + functionRegistry.namedDescriptorBuilder( "make_time" ) + .setInvariantType(timeType) .setExactArgumentCount( 3 ) .setParameterTypes(INTEGER, INTEGER, INTEGER) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "make_timestamp" ) + functionRegistry.namedDescriptorBuilder( "make_timestamp" ) .setInvariantType( timestampType ) .setExactArgumentCount( 6 ) .setParameterTypes(INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "make_timestamptz" ) + functionRegistry.namedDescriptorBuilder( "make_timestamptz" ) .setInvariantType( timestampType ) .setArgumentCountBetween( 6, 7 ) .setParameterTypes(INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER) .register(); } - public static void sysdate(QueryEngine queryEngine) { + public void sysdate() { // returns a local timestamp - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "sysdate" ) - .setInvariantType( getTimestampType( queryEngine ) ) + functionRegistry.noArgsBuilder( "sysdate" ) + .setInvariantType(timestampType) .setUseParenthesesWhenNoArgs( false ) .register(); } @@ -1203,9 +1193,9 @@ public class CommonFunctionFactory { /** * MySQL requires the parens in sysdate() */ - public static void sysdateParens(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "sysdate" ) - .setInvariantType( getTimestampType( queryEngine ) ) + public void sysdateParens() { + functionRegistry.noArgsBuilder( "sysdate" ) + .setInvariantType(timestampType) .setUseParenthesesWhenNoArgs( true ) .register(); } @@ -1213,84 +1203,82 @@ public class CommonFunctionFactory { /** * MySQL 5.7 precision defaults to seconds, but microseconds is better */ - public static void sysdateExplicitMicros(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "sysdate", "sysdate(6)" ) - .setInvariantType( getTimestampType( queryEngine ) ) + public void sysdateExplicitMicros() { + functionRegistry.patternDescriptorBuilder( "sysdate", "sysdate(6)" ) + .setInvariantType(timestampType) .setExactArgumentCount( 0 ) .register(); } - public static void systimestamp(QueryEngine queryEngine) { + public void systimestamp() { // returns a timestamp with timezone - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "systimestamp" ) - .setInvariantType( getTimestampType( queryEngine ) ) + functionRegistry.noArgsBuilder( "systimestamp" ) + .setInvariantType(timestampType) .setUseParenthesesWhenNoArgs( false ) .register(); } - public static void localtimeLocaltimestamp(QueryEngine queryEngine) { + public void localtimeLocaltimestamp() { //these functions return times without timezones - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "localtime" ) - .setInvariantType( getTimeType( queryEngine ) ) + functionRegistry.noArgsBuilder( "localtime" ) + .setInvariantType(timeType) .setUseParenthesesWhenNoArgs( false ) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "localtimestamp" ) - .setInvariantType( getTimestampType( queryEngine ) ) + functionRegistry.noArgsBuilder( "localtimestamp" ) + .setInvariantType(timestampType) .setUseParenthesesWhenNoArgs( false ) .register(); - final BasicTypeRegistry basicTypeRegistry = queryEngine.getTypeConfiguration().getBasicTypeRegistry(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "local_time", "localtime" ) + final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); + functionRegistry.noArgsBuilder( "local_time", "localtime" ) .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_TIME ) ) .setUseParenthesesWhenNoArgs( false ) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "local_datetime", "localtimestamp" ) + functionRegistry.noArgsBuilder( "local_datetime", "localtimestamp" ) .setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.LOCAL_DATE_TIME ) ) .setUseParenthesesWhenNoArgs( false ) .register(); } - public static void trigonometry(QueryEngine queryEngine) { - final BasicType doubleType = getDoubleType( queryEngine ); - - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sin" ) - .setInvariantType( doubleType ) + public void trigonometry() { + functionRegistry.namedDescriptorBuilder( "sin" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "cos" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "cos" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "tan" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "tan" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "asin" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "asin" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "acos" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "acos" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "atan" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "atan" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "atan2" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "atan2" ) + .setInvariantType(doubleType) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, NUMERIC) .register(); @@ -1299,16 +1287,16 @@ public class CommonFunctionFactory { /** * Transact-SQL atan2 is misspelled */ - public static void atan2_atn2(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "atan2", "atn2" ) - .setInvariantType( getDoubleType(queryEngine) ) + public void atan2_atn2() { + functionRegistry.namedDescriptorBuilder( "atan2", "atn2" ) + .setInvariantType(doubleType) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, NUMERIC) .register(); } - public static void coalesce(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "coalesce" ) + public void coalesce() { + functionRegistry.namedDescriptorBuilder( "coalesce" ) .setMinArgumentCount( 1 ) .register(); } @@ -1316,15 +1304,15 @@ public class CommonFunctionFactory { /** * SAP DB */ - public static void coalesce_value(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "value" ) + public void coalesce_value() { + functionRegistry.namedDescriptorBuilder( "value" ) .setMinArgumentCount( 1 ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "coalesce", "value" ); + functionRegistry.registerAlternateKey( "coalesce", "value" ); } - public static void nullif(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "nullif" ) + public void nullif() { + functionRegistry.namedDescriptorBuilder( "nullif" ) .setExactArgumentCount( 2 ) .register(); } @@ -1332,60 +1320,60 @@ public class CommonFunctionFactory { /** * ANSI SQL-style */ - public static void length_characterLength(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "character_length" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void length_characterLength() { + functionRegistry.namedDescriptorBuilder( "character_length" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "length", "character_length" ); + functionRegistry.registerAlternateKey( "length", "character_length" ); } /** * Transact SQL-style */ - public static void characterLength_len(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "len" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void characterLength_len() { + functionRegistry.namedDescriptorBuilder( "len" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "character_length", "len" ); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "length", "len" ); + functionRegistry.registerAlternateKey( "character_length", "len" ); + functionRegistry.registerAlternateKey( "length", "len" ); } /** * Oracle-style */ - public static void characterLength_length(QueryEngine queryEngine, SqlAstNodeRenderingMode argumentRenderingMode) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "length" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void characterLength_length(SqlAstNodeRenderingMode argumentRenderingMode) { + functionRegistry.namedDescriptorBuilder( "length" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .setArgumentRenderingMode( argumentRenderingMode ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "character_length", "length" ); + functionRegistry.registerAlternateKey( "character_length", "length" ); } - public static void octetLength(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "octet_length" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void octetLength() { + functionRegistry.namedDescriptorBuilder( "octet_length" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .register(); } - public static void bitLength(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "bit_length" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void bitLength() { + functionRegistry.namedDescriptorBuilder( "bit_length" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .register(); } - public static void bitLength_pattern(QueryEngine queryEngine, String pattern) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "bit_length", pattern ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void bitLength_pattern(String pattern) { + functionRegistry.patternDescriptorBuilder( "bit_length", pattern ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .register(); @@ -1394,18 +1382,18 @@ public class CommonFunctionFactory { /** * ANSI-style */ - public static void position(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "position", "position(?1 in ?2)" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void position() { + functionRegistry.patternDescriptorBuilder( "position", "position(?1 in ?2)" ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, STRING) .setArgumentListSignature( "(STRING pattern in STRING string)" ) .register(); } - public static void locate(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "locate" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void locate() { + functionRegistry.namedDescriptorBuilder( "locate" ) + .setInvariantType(integerType) .setArgumentCountBetween( 2, 3 ) .setParameterTypes(STRING, STRING, INTEGER) .setArgumentListSignature( "(STRING pattern, STRING string[, INTEGER start])" ) @@ -1415,23 +1403,23 @@ public class CommonFunctionFactory { /** * Transact SQL-style */ - public static void locate_charindex(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "charindex" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void locate_charindex() { + functionRegistry.namedDescriptorBuilder( "charindex" ) + .setInvariantType(integerType) .setArgumentCountBetween( 2, 3 ) .setParameterTypes(STRING, STRING, INTEGER) .setArgumentListSignature( "(STRING pattern, STRING string[, INTEGER start])" ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "locate", "charindex" ); + functionRegistry.registerAlternateKey( "locate", "charindex" ); } /** * locate() in terms of ANSI position() and substring() */ - public static void locate_positionSubstring(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + public void locate_positionSubstring() { + functionRegistry.registerBinaryTernaryPattern( "locate", - getIntegerType( queryEngine ), + integerType, "position(?1 in ?2)", "(position(?1 in substring(?2 from ?3))+(?3)-1)", STRING, STRING, INTEGER ) @@ -1440,10 +1428,10 @@ public class CommonFunctionFactory { /** * ANSI-style substring */ - public static void substringFromFor(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().registerBinaryTernaryPattern( + public void substringFromFor() { + functionRegistry.registerBinaryTernaryPattern( "substring", - getStringType( queryEngine ), + stringType, "substring(?1 from ?2)", "substring(?1 from ?2 for ?3)", STRING, INTEGER, INTEGER ) @@ -1453,9 +1441,9 @@ public class CommonFunctionFactory { /** * Not the same as ANSI-style substring! */ - public static void substring(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "substring" ) - .setInvariantType( getStringType( queryEngine ) ) + public void substring() { + functionRegistry.namedDescriptorBuilder( "substring" ) + .setInvariantType(stringType) .setArgumentCountBetween( 2, 3 ) .setParameterTypes(STRING, INTEGER, INTEGER) .setArgumentListSignature( "(STRING string{ from|,} INTEGER start[{ for|,} INTEGER length])" ) @@ -1465,11 +1453,11 @@ public class CommonFunctionFactory { /** * Transact SQL-style (3 required args) */ - public static void substring_substringLen(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry() + public void substring_substringLen() { + functionRegistry .registerBinaryTernaryPattern( "substring", - getStringType( queryEngine ), + stringType, "substring(?1,?2,len(?1)-?2+1)", "substring(?1,?2,?3)", STRING, INTEGER, INTEGER @@ -1480,18 +1468,18 @@ public class CommonFunctionFactory { /** * Oracle, and many others */ - public static void substring_substr(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "substring", "substr" ) + public void substring_substr() { + functionRegistry.namedDescriptorBuilder( "substring", "substr" ) .setArgumentListSignature( "(STRING string{ from|,} INTEGER start[{ for|,} INTEGER length])" ) - .setInvariantType( getStringType( queryEngine ) ) + .setInvariantType(stringType) .setArgumentCountBetween( 2, 3 ) .setParameterTypes(STRING, INTEGER, INTEGER) .register(); } - public static void insert(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "insert" ) - .setInvariantType( getStringType( queryEngine ) ) + public void insert() { + functionRegistry.namedDescriptorBuilder( "insert" ) + .setInvariantType(stringType) .setParameterTypes(STRING, INTEGER, INTEGER, STRING) .setArgumentListSignature( "(STRING string, INTEGER start, INTEGER length, STRING replacement)" ) .register(); @@ -1500,12 +1488,12 @@ public class CommonFunctionFactory { /** * Postgres */ - public static void insert_overlay(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( + public void insert_overlay() { + functionRegistry.patternDescriptorBuilder( "insert", "overlay(?1 placing ?4 from ?2 for ?3)" ) - .setInvariantType( getStringType( queryEngine ) ) + .setInvariantType(stringType) .setExactArgumentCount( 4 ) .setParameterTypes(STRING, INTEGER, INTEGER, STRING) .setArgumentListSignature( "(STRING string, INTEGER start, INTEGER length, STRING replacement)" ) @@ -1515,10 +1503,10 @@ public class CommonFunctionFactory { /** * ANSI SQL form, supported by Postgres, HSQL */ - public static void overlay(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().registerTernaryQuaternaryPattern( + public void overlay() { + functionRegistry.registerTernaryQuaternaryPattern( "overlay", - getStringType( queryEngine ), + stringType, "overlay(?1 placing ?2 from ?3)", "overlay(?1 placing ?2 from ?3 for ?4)", STRING, STRING, INTEGER, INTEGER @@ -1529,10 +1517,10 @@ public class CommonFunctionFactory { /** * For DB2 which has a broken implementation of overlay() */ - public static void overlayCharacterLength_overlay(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().registerTernaryQuaternaryPattern( + public void overlayCharacterLength_overlay() { + functionRegistry.registerTernaryQuaternaryPattern( "overlay", - getStringType( queryEngine ), + stringType, //use character_length() here instead of length() //because DB2 doesn't like "length(?)" "overlay(?1 placing ?2 from ?3 for character_length(?2))", @@ -1542,9 +1530,9 @@ public class CommonFunctionFactory { .setArgumentListSignature( "(string placing replacement from start[ for length])" ); } - public static void replace(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "replace" ) - .setInvariantType( getStringType( queryEngine ) ) + public void replace() { + functionRegistry.namedDescriptorBuilder( "replace" ) + .setInvariantType(stringType) .setExactArgumentCount( 3 ) .setParameterTypes(STRING, STRING, STRING) .setArgumentListSignature( "(STRING string, STRING pattern, STRING replacement)" ) @@ -1554,81 +1542,79 @@ public class CommonFunctionFactory { /** * Sybase */ - public static void replace_strReplace(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "str_replace" ) - .setInvariantType( getStringType( queryEngine ) ) + public void replace_strReplace() { + functionRegistry.namedDescriptorBuilder( "str_replace" ) + .setInvariantType(stringType) .setExactArgumentCount( 3 ) .setParameterTypes(STRING, STRING, STRING) .setArgumentListSignature( "(STRING string, STRING pattern, STRING replacement)" ) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "replace", "str_replace" ); + functionRegistry.registerAlternateKey( "replace", "str_replace" ); } - public static void concat(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "concat" ) - .setInvariantType( getStringType( queryEngine ) ) + public void concat() { + functionRegistry.namedDescriptorBuilder( "concat" ) + .setInvariantType(stringType) .setMinArgumentCount( 1 ) .setParameterTypes(STRING) .setArgumentListSignature( "(STRING string0[, STRING string1[, ...]])" ) .register(); } - public static void lowerUpper(QueryEngine queryEngine) { - final BasicType stringType = getStringType( queryEngine ); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "lower" ) - .setInvariantType( stringType ) + public void lowerUpper() { + functionRegistry.namedDescriptorBuilder( "lower" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .setArgumentListSignature( "(STRING string)" ) .register(); - - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "upper" ) - .setInvariantType( stringType ) + functionRegistry.namedDescriptorBuilder( "upper" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) .setArgumentListSignature( "(STRING string)" ) .register(); } - public static void ascii(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ascii" ) + public void ascii() { + functionRegistry.namedDescriptorBuilder( "ascii" ) .setExactArgumentCount( 1 ) .setParameterTypes(STRING) - .setInvariantType( getIntegerType( queryEngine ) )//should it be BYTE?? + .setInvariantType(integerType)//should it be BYTE?? .register(); } - public static void char_chr(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "chr" ) + public void char_chr() { + functionRegistry.namedDescriptorBuilder( "chr" ) .setExactArgumentCount( 1 ) .setParameterTypes(INTEGER) - .setInvariantType( getCharacterType(queryEngine) ) + .setInvariantType(characterType) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "char", "chr" ); + functionRegistry.registerAlternateKey( "char", "chr" ); } - public static void chr_char(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "char" ) + public void chr_char() { + functionRegistry.namedDescriptorBuilder( "char" ) .setExactArgumentCount( 1 ) .setParameterTypes(INTEGER) - .setInvariantType( getCharacterType(queryEngine) ) + .setInvariantType(characterType) .register(); - queryEngine.getSqmFunctionRegistry().registerAlternateKey( "chr", "char" ); + functionRegistry.registerAlternateKey( "chr", "char" ); } /** * Transact SQL-style */ - public static void datepartDatename(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datepart" ) + public void datepartDatename() { + functionRegistry.namedDescriptorBuilder( "datepart" ) // .setInvariantType( StandardBasicTypes.INTEGER ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(TEMPORAL_UNIT, TEMPORAL) .setArgumentListSignature( "(TEMPORAL_UNIT field, TEMPORAL arg)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datename" ) - .setInvariantType( getStringType( queryEngine ) ) + functionRegistry.namedDescriptorBuilder( "datename" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(TEMPORAL_UNIT, TEMPORAL) .setArgumentListSignature( "(TEMPORAL_UNIT field, TEMPORAL arg)" ) @@ -1640,90 +1626,89 @@ public class CommonFunctionFactory { // MySQL, Cache: now()/curtime()/curdate() mean current_timestamp/current_time/current_date // CUBRID: now()/curtime()/curdate() mean current_datetime/current_time/current_date // Postgres: now() means current_timestamp - public static void nowCurdateCurtime(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "curtime" ) - .setInvariantType( getTimeType( queryEngine ) ) + public void nowCurdateCurtime() { + functionRegistry.noArgsBuilder( "curtime" ) + .setInvariantType(timeType) .setUseParenthesesWhenNoArgs( true ) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "curdate" ) - .setInvariantType( getDateType( queryEngine ) ) + functionRegistry.noArgsBuilder( "curdate" ) + .setInvariantType(dateType) .setUseParenthesesWhenNoArgs( true ) .register(); - queryEngine.getSqmFunctionRegistry().noArgsBuilder( "now" ) - .setInvariantType( getTimestampType( queryEngine ) ) + functionRegistry.noArgsBuilder( "now" ) + .setInvariantType(timestampType) .setUseParenthesesWhenNoArgs( true ) .register(); } - public static void leastGreatest(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "least" ) + public void leastGreatest() { + functionRegistry.namedDescriptorBuilder( "least" ) .setMinArgumentCount( 2 ) .setParameterTypes(COMPARABLE, COMPARABLE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "greatest" ) + functionRegistry.namedDescriptorBuilder( "greatest" ) .setMinArgumentCount( 2 ) .setParameterTypes(COMPARABLE, COMPARABLE) .register(); } - public static void leastGreatest_minMax(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "least", "min" ) + public void leastGreatest_minMax() { + functionRegistry.namedDescriptorBuilder( "least", "min" ) .setMinArgumentCount( 2 ) .setParameterTypes(COMPARABLE, COMPARABLE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "greatest", "max" ) + functionRegistry.namedDescriptorBuilder( "greatest", "max" ) .setMinArgumentCount( 2 ) .setParameterTypes(COMPARABLE, COMPARABLE) .register(); } - public static void leastGreatest_minMaxValue(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "least", "minvalue" ) + public void leastGreatest_minMaxValue() { + functionRegistry.namedDescriptorBuilder( "least", "minvalue" ) .setMinArgumentCount( 2 ) .setParameterTypes(COMPARABLE, COMPARABLE) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "greatest", "maxvalue" ) + functionRegistry.namedDescriptorBuilder( "greatest", "maxvalue" ) .setMinArgumentCount( 2 ) .setParameterTypes(COMPARABLE, COMPARABLE) .register(); } - public static void aggregates( + public void aggregates( Dialect dialect, - QueryEngine queryEngine, SqlAstNodeRenderingMode inferenceArgumentRenderingMode, String concatOperator, String concatArgumentCastType) { - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "max" ) + functionRegistry.namedAggregateDescriptorBuilder( "max" ) .setArgumentRenderingMode( inferenceArgumentRenderingMode ) .setExactArgumentCount( 1 ) .setParameterTypes(COMPARABLE) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "min" ) + functionRegistry.namedAggregateDescriptorBuilder( "min" ) .setArgumentRenderingMode( inferenceArgumentRenderingMode ) .setExactArgumentCount( 1 ) .setParameterTypes(COMPARABLE) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "sum" ) + functionRegistry.namedAggregateDescriptorBuilder( "sum" ) .setArgumentRenderingMode( inferenceArgumentRenderingMode ) - .setReturnTypeResolver( new SumReturnTypeResolver( queryEngine.getTypeConfiguration() ) ) + .setReturnTypeResolver( new SumReturnTypeResolver( typeConfiguration ) ) .setExactArgumentCount( 1 ) .register(); - queryEngine.getSqmFunctionRegistry().namedAggregateDescriptorBuilder( "avg" ) + functionRegistry.namedAggregateDescriptorBuilder( "avg" ) .setArgumentRenderingMode( inferenceArgumentRenderingMode ) - .setInvariantType( getDoubleType( queryEngine ) ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().register( + functionRegistry.register( CountFunction.FUNCTION_NAME, new CountFunction( dialect, - queryEngine.getTypeConfiguration(), + typeConfiguration, inferenceArgumentRenderingMode, concatOperator, concatArgumentCastType @@ -1731,217 +1716,212 @@ public class CommonFunctionFactory { ); } - public static void avg_castingNonDoubleArguments( + public void avg_castingNonDoubleArguments( Dialect dialect, - QueryEngine queryEngine, SqlAstNodeRenderingMode inferenceArgumentRenderingMode) { - queryEngine.getSqmFunctionRegistry().register( + functionRegistry.register( AvgFunction.FUNCTION_NAME, new AvgFunction( dialect, - queryEngine.getTypeConfiguration(), + typeConfiguration, inferenceArgumentRenderingMode, dialect.getTypeName( SqlTypes.DOUBLE ) ) ); } - public static void listagg(String emptyWithinReplacement, QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( + public void listagg(String emptyWithinReplacement) { + functionRegistry.register( ListaggFunction.FUNCTION_NAME, - new ListaggFunction( emptyWithinReplacement, queryEngine.getTypeConfiguration() ) + new ListaggFunction( emptyWithinReplacement, typeConfiguration ) ); } - public static void listagg_groupConcat(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( + public void listagg_groupConcat() { + functionRegistry.register( ListaggGroupConcatEmulation.FUNCTION_NAME, - new ListaggGroupConcatEmulation( queryEngine.getTypeConfiguration() ) + new ListaggGroupConcatEmulation( typeConfiguration ) ); } - public static void listagg_list(String stringType, QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( + public void listagg_list(String stringType) { + functionRegistry.register( ListaggStringAggEmulation.FUNCTION_NAME, - new ListaggStringAggEmulation( "list", stringType, false, queryEngine.getTypeConfiguration() ) + new ListaggStringAggEmulation( "list", stringType, false, typeConfiguration ) ); } - public static void listagg_stringAgg(String stringType, QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( + public void listagg_stringAgg(String stringType) { + functionRegistry.register( ListaggStringAggEmulation.FUNCTION_NAME, - new ListaggStringAggEmulation( "string_agg", stringType, false, queryEngine.getTypeConfiguration() ) + new ListaggStringAggEmulation( "string_agg", stringType, false, typeConfiguration ) ); } - public static void listagg_stringAggWithinGroup(String stringType, QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( + public void listagg_stringAggWithinGroup(String stringType) { + functionRegistry.register( ListaggStringAggEmulation.FUNCTION_NAME, - new ListaggStringAggEmulation( "string_agg", stringType, true, queryEngine.getTypeConfiguration() ) + new ListaggStringAggEmulation( "string_agg", stringType, true, typeConfiguration ) ); } - public static void inverseDistributionOrderedSetAggregates(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( + public void inverseDistributionOrderedSetAggregates() { + functionRegistry.register( "mode", - new InverseDistributionFunction( "mode", null, queryEngine.getTypeConfiguration() ) + new InverseDistributionFunction( "mode", null, typeConfiguration ) ); - queryEngine.getSqmFunctionRegistry().register( + functionRegistry.register( "percentile_cont", - new InverseDistributionFunction( "percentile_cont", NUMERIC, queryEngine.getTypeConfiguration() ) + new InverseDistributionFunction( "percentile_cont", NUMERIC, typeConfiguration ) ); - queryEngine.getSqmFunctionRegistry().register( + functionRegistry.register( "percentile_disc", - new InverseDistributionFunction( "percentile_disc", NUMERIC, queryEngine.getTypeConfiguration() ) + new InverseDistributionFunction( "percentile_disc", NUMERIC, typeConfiguration ) ); } - public static void hypotheticalOrderedSetAggregates(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().register( + public void hypotheticalOrderedSetAggregates() { + functionRegistry.register( "rank", - new HypotheticalSetFunction( "rank", StandardBasicTypes.LONG, queryEngine.getTypeConfiguration() ) + new HypotheticalSetFunction( "rank", StandardBasicTypes.LONG, typeConfiguration ) ); - queryEngine.getSqmFunctionRegistry().register( + functionRegistry.register( "dense_rank", - new HypotheticalSetFunction( "dense_rank", StandardBasicTypes.LONG, queryEngine.getTypeConfiguration() ) + new HypotheticalSetFunction( "dense_rank", StandardBasicTypes.LONG, typeConfiguration ) ); - queryEngine.getSqmFunctionRegistry().register( + functionRegistry.register( "percent_rank", - new HypotheticalSetFunction( "percent_rank", StandardBasicTypes.DOUBLE, queryEngine.getTypeConfiguration() ) + new HypotheticalSetFunction( "percent_rank", StandardBasicTypes.DOUBLE, typeConfiguration ) ); - queryEngine.getSqmFunctionRegistry().register( + functionRegistry.register( "cume_dist", - new HypotheticalSetFunction( "cume_dist", StandardBasicTypes.DOUBLE, queryEngine.getTypeConfiguration() ) + new HypotheticalSetFunction( "cume_dist", StandardBasicTypes.DOUBLE, typeConfiguration ) ); } - public static void math(QueryEngine queryEngine) { - - final BasicType integerType = getIntegerType( queryEngine ); - final BasicType doubleType = getDoubleType( queryEngine ); - - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "round" ) + public void math() { + functionRegistry.namedDescriptorBuilder( "round" ) // To avoid truncating to a specific data type, we default to using the argument type .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, INTEGER) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "floor" ) + functionRegistry.namedDescriptorBuilder( "floor" ) // To avoid truncating to a specific data type, we default to using the argument type .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ceiling" ) + functionRegistry.namedDescriptorBuilder( "ceiling" ) // To avoid truncating to a specific data type, we default to using the argument type .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "mod" ) + functionRegistry.namedDescriptorBuilder( "mod" ) // According to JPA spec 4.6.17.2.2. - .setInvariantType( integerType ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setParameterTypes(INTEGER, INTEGER) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "abs" ) + functionRegistry.namedDescriptorBuilder( "abs" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sign" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "sign" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); //transcendental functions are by nature of floating point type - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sqrt" ) + functionRegistry.namedDescriptorBuilder( "sqrt" ) // According to JPA spec 4.6.17.2.2. - .setInvariantType( doubleType ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "ln" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "ln" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "exp" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "exp" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "power" ) - .setInvariantType( doubleType ) + functionRegistry.namedDescriptorBuilder( "power" ) + .setInvariantType(doubleType) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, NUMERIC) .register(); } - public static void mod_operator(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "mod", "(?1%?2)" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void mod_operator() { + functionRegistry.patternDescriptorBuilder( "mod", "(?1%?2)" ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setParameterTypes(INTEGER, INTEGER) .register(); } - public static void power_expLn(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "power", "exp(ln(?1)*?2)" ) - .setInvariantType( getDoubleType(queryEngine) ) + public void power_expLn() { + functionRegistry.patternDescriptorBuilder( "power", "exp(ln(?1)*?2)" ) + .setInvariantType(doubleType) .setExactArgumentCount( 2 ) .setParameterTypes(NUMERIC, NUMERIC) .register(); } - public static void square(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "square" ) + public void square() { + functionRegistry.namedDescriptorBuilder( "square" ) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void cbrt(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "cbrt" ) - .setInvariantType( getDoubleType( queryEngine ) ) + public void cbrt() { + functionRegistry.namedDescriptorBuilder( "cbrt" ) + .setInvariantType(doubleType) .setExactArgumentCount( 1 ) .setParameterTypes(NUMERIC) .register(); } - public static void crc32(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "crc32" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void crc32() { + functionRegistry.namedDescriptorBuilder( "crc32" ) + .setInvariantType(integerType) .setExactArgumentCount( 1 ) .register(); } - public static void sha1(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sha1" ) - .setInvariantType( getStringType( queryEngine ) ) + public void sha1() { + functionRegistry.namedDescriptorBuilder( "sha1" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .register(); } - public static void sha2(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sha2" ) - .setInvariantType( getStringType( queryEngine ) ) + public void sha2() { + functionRegistry.namedDescriptorBuilder( "sha2" ) + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .register(); } - public static void sha(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "sha" ) - .setInvariantType( getStringType( queryEngine ) ) + public void sha() { + functionRegistry.namedDescriptorBuilder( "sha" ) + .setInvariantType(stringType) .setExactArgumentCount( 1 ) .register(); } @@ -1949,9 +1929,9 @@ public class CommonFunctionFactory { /** * MySQL style, returns the number of days between two dates */ - public static void datediff(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "datediff" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void datediff() { + functionRegistry.namedDescriptorBuilder( "datediff" ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, DATE) .setArgumentListSignature( "(DATE end, DATE start)" ) @@ -1961,26 +1941,26 @@ public class CommonFunctionFactory { /** * MySQL style */ - public static void adddateSubdateAddtimeSubtime(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "adddate" ) + public void adddateSubdateAddtimeSubtime() { + functionRegistry.namedDescriptorBuilder( "adddate" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, INTEGER) .setArgumentListSignature( "(DATE datetime, INTEGER days)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "subdate" ) + functionRegistry.namedDescriptorBuilder( "subdate" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, INTEGER) .setArgumentListSignature( "(DATE datetime, INTEGER days)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "addtime" ) + functionRegistry.namedDescriptorBuilder( "addtime" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, TIME) .setArgumentListSignature( "(TIME datetime, TIME time)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "subtime" ) + functionRegistry.namedDescriptorBuilder( "subtime" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, TIME) @@ -1988,8 +1968,8 @@ public class CommonFunctionFactory { .register(); } - public static void addMonths(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "add_months" ) + public void addMonths() { + functionRegistry.namedDescriptorBuilder( "add_months" ) .setReturnTypeResolver( useArgType( 1 ) ) .setArgumentListSignature( "(DATE datetime, INTEGER months)" ) .setExactArgumentCount( 2 ) @@ -1997,107 +1977,104 @@ public class CommonFunctionFactory { .register(); } - public static void monthsBetween(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "months_between" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void monthsBetween() { + functionRegistry.namedDescriptorBuilder( "months_between" ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setArgumentListSignature( "(DATE end, DATE start)" ) .setParameterTypes(DATE, DATE) .register(); } - public static void daysBetween(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "days_between" ) - .setInvariantType( getIntegerType( queryEngine ) ) + public void daysBetween() { + functionRegistry.namedDescriptorBuilder( "days_between" ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, DATE) .setArgumentListSignature( "(DATE end, DATE start)" ) .register(); } - public static void secondsBetween(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "seconds_between" ) - .setInvariantType( getLongType( queryEngine ) ) + public void secondsBetween() { + functionRegistry.namedDescriptorBuilder( "seconds_between" ) + .setInvariantType(longType) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, TIME) .setArgumentListSignature( "(TIME end, TIME start)" ) .register(); } - public static void yearsMonthsDaysHoursMinutesSecondsBetween(QueryEngine queryEngine) { - final BasicType longType = getLongType( queryEngine ); - final BasicType integerType = getIntegerType( queryEngine ); - - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "years_between" ) - .setInvariantType( integerType ) + public void yearsMonthsDaysHoursMinutesSecondsBetween() { + functionRegistry.namedDescriptorBuilder( "years_between" ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, DATE) .setArgumentListSignature( "(DATE end, DATE start)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "months_between" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "months_between" ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, DATE) .setArgumentListSignature( "(DATE end, DATE start)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "days_between" ) - .setInvariantType( integerType ) + functionRegistry.namedDescriptorBuilder( "days_between" ) + .setInvariantType(integerType) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, DATE) .setArgumentListSignature( "(DATE end, DATE start)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "hours_between" ) - .setInvariantType( longType ) + functionRegistry.namedDescriptorBuilder( "hours_between" ) + .setInvariantType(longType) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, TIME) .setArgumentListSignature( "(TIME end, TIME start)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "minutes_between" ) - .setInvariantType( longType ) + functionRegistry.namedDescriptorBuilder( "minutes_between" ) + .setInvariantType(longType) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, TIME) .setArgumentListSignature( "(TIME end, TIME start)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "seconds_between" ) - .setInvariantType( longType ) + functionRegistry.namedDescriptorBuilder( "seconds_between" ) + .setInvariantType(longType) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, TIME) .setArgumentListSignature( "(TIME end, TIME start)" ) .register(); } - public static void addYearsMonthsDaysHoursMinutesSeconds(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "add_years" ) + public void addYearsMonthsDaysHoursMinutesSeconds() { + functionRegistry.namedDescriptorBuilder( "add_years" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, INTEGER) .setArgumentListSignature( "(DATE datetime, INTEGER years)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "add_months" ) + functionRegistry.namedDescriptorBuilder( "add_months" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, INTEGER) .setArgumentListSignature( "(DATE datetime, INTEGER months)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "add_days" ) + functionRegistry.namedDescriptorBuilder( "add_days" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(DATE, INTEGER) .setArgumentListSignature( "(DATE datetime, INTEGER days)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "add_hours" ) + functionRegistry.namedDescriptorBuilder( "add_hours" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, INTEGER) .setArgumentListSignature( "(TIME datetime, INTEGER hours)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "add_minutes" ) + functionRegistry.namedDescriptorBuilder( "add_minutes" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, INTEGER) .setArgumentListSignature( "(TIME datetime, INTEGER minutes)" ) .register(); - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "add_seconds" ) + functionRegistry.namedDescriptorBuilder( "add_seconds" ) .setReturnTypeResolver( useArgType( 1 ) ) .setExactArgumentCount( 2 ) .setParameterTypes(TIME, INTEGER) @@ -2108,9 +2085,9 @@ public class CommonFunctionFactory { /** * H2-style (uses Java's SimpleDateFormat directly so no need to translate format) */ - public static void format_formatdatetime(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format", "formatdatetime" ) - .setInvariantType( getStringType( queryEngine ) ) + public void format_formatdatetime() { + functionRegistry.namedDescriptorBuilder( "format", "formatdatetime" ) + .setInvariantType(stringType) .setArgumentsValidator( formatValidator() ) .setArgumentListSignature( "(TEMPORAL datetime as STRING pattern)" ) .register(); @@ -2121,9 +2098,9 @@ public class CommonFunctionFactory { * * @see org.hibernate.dialect.OracleDialect#datetimeFormat */ - public static void format_toChar(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format", "to_char" ) - .setInvariantType( getStringType( queryEngine ) ) + public void format_toChar() { + functionRegistry.namedDescriptorBuilder( "format", "to_char" ) + .setInvariantType(stringType) .setArgumentsValidator( formatValidator() ) .setArgumentListSignature( "(TEMPORAL datetime as STRING pattern)" ) .register(); @@ -2134,9 +2111,9 @@ public class CommonFunctionFactory { * * @see org.hibernate.dialect.MySQLDialect#datetimeFormat */ - public static void format_dateFormat(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format", "date_format" ) - .setInvariantType( getStringType( queryEngine ) ) + public void format_dateFormat() { + functionRegistry.namedDescriptorBuilder( "format", "date_format" ) + .setInvariantType(stringType) .setArgumentsValidator( formatValidator() ) .setArgumentListSignature( "(TEMPORAL datetime as STRING pattern)" ) .register(); @@ -2147,9 +2124,9 @@ public class CommonFunctionFactory { * * @see org.hibernate.dialect.OracleDialect#datetimeFormat */ - public static void format_toVarchar(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().namedDescriptorBuilder( "format", "to_varchar" ) - .setInvariantType( getStringType( queryEngine ) ) + public void format_toVarchar() { + functionRegistry.namedDescriptorBuilder( "format", "to_varchar" ) + .setInvariantType(stringType) .setArgumentsValidator( formatValidator() ) .setArgumentListSignature( "(TEMPORAL datetime as STRING pattern)" ) .register(); @@ -2162,9 +2139,9 @@ public class CommonFunctionFactory { /** * Use the 'collate' operator which exists on at least Postgres, MySQL, Oracle, and SQL Server */ - public static void collate(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder("collate", "(?1 collate ?2)") - .setInvariantType( getStringType(queryEngine) ) + public void collate() { + functionRegistry.patternDescriptorBuilder("collate", "(?1 collate ?2)") + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, COLLATION) .setArgumentListSignature("(STRING string as COLLATION collation)") @@ -2174,57 +2151,22 @@ public class CommonFunctionFactory { /** * HSQL requires quotes around certain collations */ - public static void collate_quoted(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder("collate", "(?1 collate '?2')") - .setInvariantType( getStringType( queryEngine ) ) + public void collate_quoted() { + functionRegistry.patternDescriptorBuilder("collate", "(?1 collate '?2')") + .setInvariantType(stringType) .setExactArgumentCount( 2 ) .setParameterTypes(STRING, ANY) .setArgumentListSignature("(STRING string as COLLATION collation)") .register(); } - public static void dateTrunc(QueryEngine queryEngine) { - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "date_trunc", "date_trunc('?1',?2)" ) - .setInvariantType( getTimestampType( queryEngine ) ) + public void dateTrunc() { + functionRegistry.patternDescriptorBuilder( "date_trunc", "date_trunc('?1',?2)" ) + .setInvariantType(timestampType) .setExactArgumentCount( 2 ) .setParameterTypes(TEMPORAL_UNIT, TEMPORAL) .setArgumentListSignature( "(TEMPORAL_UNIT field, TEMPORAL datetime)" ) .register(); } - private static BasicType getBooleanType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.BOOLEAN); - } - - private static BasicType getStringType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.STRING); - } - - private static BasicType getIntegerType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.INTEGER); - } - - private static BasicType getDoubleType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.DOUBLE); - } - - private static BasicType getDateType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.DATE); - } - - private static BasicType getTimeType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.TIME); - } - - private static BasicType getTimestampType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.TIMESTAMP); - } - - private static BasicType getLongType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.LONG); - } - - private static BasicType getCharacterType(QueryEngine queryEngine) { - return queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.CHARACTER); - } } 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 8278344719..b867ff8999 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 @@ -11,8 +11,6 @@ import jakarta.persistence.TemporalType; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; -import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator; -import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.SqlAppender;