15
15
import org .hibernate .community .dialect .sequence .SequenceInformationExtractorTimesTenDatabaseImpl ;
16
16
import org .hibernate .community .dialect .sequence .TimesTenSequenceSupport ;
17
17
import org .hibernate .dialect .Dialect ;
18
+ import org .hibernate .dialect .BooleanDecoder ;
18
19
import org .hibernate .dialect .RowLockStrategy ;
19
20
import org .hibernate .dialect .function .CommonFunctionFactory ;
21
+ import org .hibernate .query .sqm .produce .function .StandardFunctionReturnTypeResolvers ;
20
22
import org .hibernate .dialect .lock .LockingStrategy ;
21
23
import org .hibernate .dialect .lock .OptimisticForceIncrementLockingStrategy ;
22
24
import org .hibernate .dialect .lock .OptimisticLockingStrategy ;
34
36
import org .hibernate .metamodel .mapping .EntityMappingType ;
35
37
import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
36
38
import org .hibernate .persister .entity .Lockable ;
39
+ import org .hibernate .query .sqm .CastType ;
37
40
import org .hibernate .query .sqm .IntervalType ;
38
41
import org .hibernate .query .sqm .TemporalUnit ;
39
42
import org .hibernate .query .sqm .mutation .internal .temptable .GlobalTemporaryTableInsertStrategy ;
42
45
import org .hibernate .query .sqm .mutation .spi .SqmMultiTableMutationStrategy ;
43
46
import org .hibernate .sql .ast .SqlAstTranslator ;
44
47
import org .hibernate .sql .ast .SqlAstTranslatorFactory ;
48
+ import org .hibernate .sql .ast .SqlAstNodeRenderingMode ;
45
49
import org .hibernate .sql .ast .spi .StandardSqlAstTranslatorFactory ;
46
50
import org .hibernate .sql .ast .tree .Statement ;
47
51
import org .hibernate .sql .exec .spi .JdbcOperation ;
@@ -188,61 +192,27 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
188
192
final BasicType <Integer >intType = basicTypeRegistry .resolve ( StandardBasicTypes .INTEGER );
189
193
190
194
// 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 );
200
197
functionFactory .concat_pipeOperator ();
201
- functionContributions .getFunctionRegistry ().register (
202
- "to_char" , new StandardSQLFunction ("to_char" , StandardBasicTypes .STRING )
203
- );
198
+ functionFactory .toCharNumberDateTimestamp ();
204
199
functionFactory .char_chr ();
205
200
functionFactory .instr ();
206
201
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 ();
213
203
functionFactory .soundex ();
214
204
215
205
// Date/Time Functions
216
- functionContributions .getFunctionRegistry ().register (
217
- "to_date" , new StandardSQLFunction ("to_date" , StandardBasicTypes .TIMESTAMP )
218
- );
219
206
functionContributions .getFunctionRegistry ().register (
220
207
"sysdate" , new CurrentFunction ("sysdate" , "sysdate" , timestampType )
221
208
);
222
209
functionContributions .getFunctionRegistry ().register (
223
210
"getdate" , new StandardSQLFunction ("getdate" , StandardBasicTypes .TIMESTAMP )
224
211
);
225
212
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
-
239
213
// 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 ();
246
216
247
217
// Math functions
248
218
functionFactory .ceiling_ceil ();
@@ -253,15 +223,12 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
253
223
functionContributions .getFunctionRegistry ().register (
254
224
"trunc" , new StandardSQLFunction ("trunc" )
255
225
);
226
+ functionContributions .getFunctionRegistry ().registerAlternateKey ( "truncate" , "trunc" );
256
227
functionContributions .getFunctionRegistry ().register (
257
228
"round" , new StandardSQLFunction ("round" )
258
229
);
259
230
260
231
// Bitwise functions
261
- functionContributions .getFunctionRegistry ().register (
262
- "bitnot" , new StandardSQLFunction ("bitnot" , StandardBasicTypes .INTEGER )
263
- );
264
-
265
232
functionContributions .getFunctionRegistry ()
266
233
.patternDescriptorBuilder ( "bitor" , "(?1+?2-bitand(?1,?2))" )
267
234
.setExactArgumentCount ( 2 )
@@ -277,9 +244,12 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
277
244
.register ();
278
245
279
246
// 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
+
283
253
functionContributions .getFunctionRegistry ().register (
284
254
"user" , new CurrentFunction ("user" , "user" , stringType )
285
255
);
@@ -574,6 +544,11 @@ public String currentTime() {
574
544
return "sysdate" ;
575
545
}
576
546
547
+ @ Override
548
+ public String currentTimestamp () {
549
+ return "sysdate" ;
550
+ }
551
+
577
552
@ Override
578
553
public int getMaxVarcharLength () {
579
554
// 1 to 4,194,304 bytes according to TimesTen Doc
@@ -606,4 +581,52 @@ public String getFromDualForSelectOnly() {
606
581
return " from dual" ;
607
582
}
608
583
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
+
609
632
}
0 commit comments