1515import org .hibernate .community .dialect .sequence .SequenceInformationExtractorTimesTenDatabaseImpl ;
1616import org .hibernate .community .dialect .sequence .TimesTenSequenceSupport ;
1717import org .hibernate .dialect .Dialect ;
18+ import org .hibernate .dialect .BooleanDecoder ;
1819import org .hibernate .dialect .RowLockStrategy ;
1920import org .hibernate .dialect .function .CommonFunctionFactory ;
21+ import org .hibernate .query .sqm .produce .function .StandardFunctionReturnTypeResolvers ;
2022import org .hibernate .dialect .lock .LockingStrategy ;
2123import org .hibernate .dialect .lock .OptimisticForceIncrementLockingStrategy ;
2224import org .hibernate .dialect .lock .OptimisticLockingStrategy ;
3436import org .hibernate .metamodel .mapping .EntityMappingType ;
3537import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
3638import org .hibernate .persister .entity .Lockable ;
39+ import org .hibernate .query .sqm .CastType ;
3740import org .hibernate .query .sqm .IntervalType ;
3841import org .hibernate .query .sqm .TemporalUnit ;
3942import org .hibernate .query .sqm .mutation .internal .temptable .GlobalTemporaryTableInsertStrategy ;
4245import org .hibernate .query .sqm .mutation .spi .SqmMultiTableMutationStrategy ;
4346import org .hibernate .sql .ast .SqlAstTranslator ;
4447import org .hibernate .sql .ast .SqlAstTranslatorFactory ;
48+ import org .hibernate .sql .ast .SqlAstNodeRenderingMode ;
4549import org .hibernate .sql .ast .spi .StandardSqlAstTranslatorFactory ;
4650import org .hibernate .sql .ast .tree .Statement ;
4751import org .hibernate .sql .exec .spi .JdbcOperation ;
@@ -188,61 +192,27 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
188192 final BasicType <Integer >intType = basicTypeRegistry .resolve ( StandardBasicTypes .INTEGER );
189193
190194 // String Functions
191- functionContributions .getFunctionRegistry ().register (
192- "rtrim" , new StandardSQLFunction ("rtrim" , StandardBasicTypes .STRING )
193- );
194- functionContributions .getFunctionRegistry ().register (
195- "ltrim" , new StandardSQLFunction ("ltrim" , StandardBasicTypes .STRING )
196- );
197- functionContributions .getFunctionRegistry ().register (
198- "length" , new StandardSQLFunction ("length" , StandardBasicTypes .LONG )
199- );
195+ functionFactory .trim2 ();
196+ functionFactory .characterLength_length ( SqlAstNodeRenderingMode .DEFAULT );
200197 functionFactory .concat_pipeOperator ();
201- functionContributions .getFunctionRegistry ().register (
202- "to_char" , new StandardSQLFunction ("to_char" , StandardBasicTypes .STRING )
203- );
198+ functionFactory .toCharNumberDateTimestamp ();
204199 functionFactory .char_chr ();
205200 functionFactory .instr ();
206201 functionFactory .substr ();
207- functionContributions .getFunctionRegistry ().register (
208- "str" , new StandardSQLFunction ("to_char" , StandardBasicTypes .STRING )
209- );
210- functionContributions .getFunctionRegistry ().register (
211- "substring" , new StandardSQLFunction ( "substr" , StandardBasicTypes .STRING )
212- );
202+ functionFactory .substring_substr ();
213203 functionFactory .soundex ();
214204
215205 // Date/Time Functions
216- functionContributions .getFunctionRegistry ().register (
217- "to_date" , new StandardSQLFunction ("to_date" , StandardBasicTypes .TIMESTAMP )
218- );
219206 functionContributions .getFunctionRegistry ().register (
220207 "sysdate" , new CurrentFunction ("sysdate" , "sysdate" , timestampType )
221208 );
222209 functionContributions .getFunctionRegistry ().register (
223210 "getdate" , new StandardSQLFunction ("getdate" , StandardBasicTypes .TIMESTAMP )
224211 );
225212
226- functionContributions .getFunctionRegistry ().register (
227- "current_date" , new CurrentFunction ("sysdate" , "sysdate" , dateType )
228- );
229- functionContributions .getFunctionRegistry ().register (
230- "current_time" , new CurrentFunction ("sysdate" , "sysdate" , timeType )
231- );
232- functionContributions .getFunctionRegistry ().register (
233- "current_timestamp" , new CurrentFunction ("sysdate" , "sysdate" , timestampType )
234- );
235- functionContributions .getFunctionRegistry ().register (
236- "to_timestamp" , new StandardSQLFunction ("to_timestamp" , StandardBasicTypes .TIMESTAMP )
237- );
238-
239213 // Multi-param date dialect functions
240- functionContributions .getFunctionRegistry ().register (
241- "add_months" , new StandardSQLFunction ("add_months" , StandardBasicTypes .DATE )
242- );
243- functionContributions .getFunctionRegistry ().register (
244- "months_between" , new StandardSQLFunction ("months_between" , StandardBasicTypes .FLOAT )
245- );
214+ functionFactory .addMonths ();
215+ functionFactory .monthsBetween ();
246216
247217 // Math functions
248218 functionFactory .ceiling_ceil ();
@@ -253,15 +223,12 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
253223 functionContributions .getFunctionRegistry ().register (
254224 "trunc" , new StandardSQLFunction ("trunc" )
255225 );
226+ functionContributions .getFunctionRegistry ().registerAlternateKey ( "truncate" , "trunc" );
256227 functionContributions .getFunctionRegistry ().register (
257228 "round" , new StandardSQLFunction ("round" )
258229 );
259230
260231 // Bitwise functions
261- functionContributions .getFunctionRegistry ().register (
262- "bitnot" , new StandardSQLFunction ("bitnot" , StandardBasicTypes .INTEGER )
263- );
264-
265232 functionContributions .getFunctionRegistry ()
266233 .patternDescriptorBuilder ( "bitor" , "(?1+?2-bitand(?1,?2))" )
267234 .setExactArgumentCount ( 2 )
@@ -277,9 +244,12 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
277244 .register ();
278245
279246 // Misc. functions
280- functionContributions .getFunctionRegistry ().register (
281- "nvl" , new StandardSQLFunction ("nvl" )
282- );
247+ functionContributions .getFunctionRegistry ().namedDescriptorBuilder ( "nvl" )
248+ .setMinArgumentCount ( 2 )
249+ .setArgumentTypeResolver ( StandardFunctionArgumentTypeResolvers .ARGUMENT_OR_IMPLIED_RESULT_TYPE )
250+ .setReturnTypeResolver ( StandardFunctionReturnTypeResolvers .useFirstNonNull () )
251+ .register ();
252+
283253 functionContributions .getFunctionRegistry ().register (
284254 "user" , new CurrentFunction ("user" , "user" , stringType )
285255 );
@@ -574,6 +544,11 @@ public String currentTime() {
574544 return "sysdate" ;
575545 }
576546
547+ @ Override
548+ public String currentTimestamp () {
549+ return "sysdate" ;
550+ }
551+
577552 @ Override
578553 public int getMaxVarcharLength () {
579554 // 1 to 4,194,304 bytes according to TimesTen Doc
@@ -606,4 +581,52 @@ public String getFromDualForSelectOnly() {
606581 return " from dual" ;
607582 }
608583
584+ @ Override
585+ public String castPattern (CastType from , CastType to ) {
586+ String result ;
587+ switch ( to ) {
588+ case INTEGER :
589+ case LONG :
590+ result = BooleanDecoder .toInteger ( from );
591+ if ( result != null ) {
592+ return result ;
593+ }
594+ break ;
595+ case STRING :
596+ switch ( from ) {
597+ case BOOLEAN :
598+ case INTEGER_BOOLEAN :
599+ case TF_BOOLEAN :
600+ case YN_BOOLEAN :
601+ return BooleanDecoder .toString ( from );
602+ case DATE :
603+ return "to_char(?1,'YYYY-MM-DD')" ;
604+ case TIME :
605+ return "to_char(?1,'HH24:MI:SS')" ;
606+ case TIMESTAMP :
607+ return "to_char(?1,'YYYY-MM-DD HH24:MI:SS.FF9')" ;
608+ }
609+ break ;
610+ case CLOB :
611+ return "to_clob(?1)" ;
612+ case DATE :
613+ if ( from == CastType .STRING ) {
614+ return "to_date(?1,'YYYY-MM-DD')" ;
615+ }
616+ break ;
617+ case TIME :
618+ if ( from == CastType .STRING ) {
619+ return "to_date(?1,'HH24:MI:SS')" ;
620+ }
621+ break ;
622+ case TIMESTAMP :
623+ if ( from == CastType .STRING ) {
624+ return "to_timestamp(?1,'YYYY-MM-DD HH24:MI:SS.FF9')" ;
625+ }
626+ break ;
627+ }
628+ return super .castPattern (from , to );
629+ }
630+
631+
609632}
0 commit comments