Skip to content

Commit fde047d

Browse files
committed
start grouping function registration into overridable methods
1 parent 85741cb commit fde047d

File tree

7 files changed

+283
-228
lines changed

7 files changed

+283
-228
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -461,43 +461,9 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
461461
functionFactory.listagg_stringAgg( "string" );
462462
functionFactory.inverseDistributionOrderedSetAggregates();
463463
functionFactory.hypotheticalOrderedSetAggregates_windowEmulation();
464-
functionFactory.array_postgresql();
465-
functionFactory.arrayAggregate();
466-
functionFactory.arrayPosition_postgresql();
467-
functionFactory.arrayPositions_postgresql();
468-
functionFactory.arrayLength_cardinality();
469-
functionFactory.arrayConcat_postgresql();
470-
functionFactory.arrayPrepend_postgresql();
471-
functionFactory.arrayAppend_postgresql();
472-
functionFactory.arrayContains_postgresql();
473-
functionFactory.arrayIntersects_postgresql();
474-
functionFactory.arrayGet_bracket();
475-
functionFactory.arraySet_unnest();
476-
functionFactory.arrayRemove();
477-
functionFactory.arrayRemoveIndex_unnest( true );
478-
functionFactory.arraySlice_operator();
479-
functionFactory.arrayReplace();
480-
functionFactory.arrayTrim_unnest();
481-
functionFactory.arrayReverse_unnest();
482-
functionFactory.arraySort_unnest();
483-
functionFactory.arrayFill_cockroachdb();
484-
functionFactory.arrayToString_postgresql();
485464

486-
functionFactory.jsonValue_cockroachdb();
487-
functionFactory.jsonQuery_cockroachdb();
488-
functionFactory.jsonExists_cockroachdb();
489-
functionFactory.jsonObject_postgresql();
490-
functionFactory.jsonArray_postgresql();
491-
functionFactory.jsonArrayAgg_postgresql( false );
492-
functionFactory.jsonObjectAgg_postgresql( false );
493-
functionFactory.jsonSet_postgresql();
494-
functionFactory.jsonRemove_cockroachdb();
495-
functionFactory.jsonReplace_postgresql();
496-
functionFactory.jsonInsert_postgresql();
497-
// No support for WITH clause in subquery: https://github.com/cockroachdb/cockroach/issues/131011
498-
// functionFactory.jsonMergepatch_postgresql();
499-
functionFactory.jsonArrayAppend_postgresql( false );
500-
functionFactory.jsonArrayInsert_postgresql();
465+
registerArrayFunctions( functionFactory );
466+
registerJsonFunctions( functionFactory );
501467

502468
functionFactory.unnest_postgresql( false );
503469
functionFactory.generateSeries( null, "ordinality", true );
@@ -521,6 +487,48 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
521487
functionFactory.regexpLike_postgresql( false );
522488
}
523489

490+
protected static void registerJsonFunctions(CommonFunctionFactory functionFactory) {
491+
functionFactory.jsonValue_cockroachdb();
492+
functionFactory.jsonQuery_cockroachdb();
493+
functionFactory.jsonExists_cockroachdb();
494+
functionFactory.jsonObject_postgresql();
495+
functionFactory.jsonArray_postgresql();
496+
functionFactory.jsonArrayAgg_postgresql( false );
497+
functionFactory.jsonObjectAgg_postgresql( false );
498+
functionFactory.jsonSet_postgresql();
499+
functionFactory.jsonRemove_cockroachdb();
500+
functionFactory.jsonReplace_postgresql();
501+
functionFactory.jsonInsert_postgresql();
502+
// No support for WITH clause in subquery: https://github.com/cockroachdb/cockroach/issues/131011
503+
// functionFactory.jsonMergepatch_postgresql();
504+
functionFactory.jsonArrayAppend_postgresql( false );
505+
functionFactory.jsonArrayInsert_postgresql();
506+
}
507+
508+
protected static void registerArrayFunctions(CommonFunctionFactory functionFactory) {
509+
functionFactory.array_postgresql();
510+
functionFactory.arrayAggregate();
511+
functionFactory.arrayPosition_postgresql();
512+
functionFactory.arrayPositions_postgresql();
513+
functionFactory.arrayLength_cardinality();
514+
functionFactory.arrayConcat_postgresql();
515+
functionFactory.arrayPrepend_postgresql();
516+
functionFactory.arrayAppend_postgresql();
517+
functionFactory.arrayContains_postgresql();
518+
functionFactory.arrayIntersects_postgresql();
519+
functionFactory.arrayGet_bracket();
520+
functionFactory.arraySet_unnest();
521+
functionFactory.arrayRemove();
522+
functionFactory.arrayRemoveIndex_unnest( true );
523+
functionFactory.arraySlice_operator();
524+
functionFactory.arrayReplace();
525+
functionFactory.arrayTrim_unnest();
526+
functionFactory.arrayReverse_unnest();
527+
functionFactory.arraySort_unnest();
528+
functionFactory.arrayFill_cockroachdb();
529+
functionFactory.arrayToString_postgresql();
530+
}
531+
524532
@Override
525533
public @Nullable String getDefaultOrdinalityColumnName() {
526534
return "ordinality";

hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,20 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
452452
functionFactory.windowFunctions();
453453
functionFactory.listagg( null );
454454

455-
functionFactory.jsonValue_db2();
456-
functionFactory.jsonQuery_no_passing();
457-
functionFactory.jsonExists_no_passing();
458-
functionFactory.jsonObject_db2();
459-
functionFactory.jsonArray_db2();
460-
functionFactory.jsonArrayAgg_db2();
461-
functionFactory.jsonObjectAgg_db2();
462-
functionFactory.jsonTable_db2( getMaximumSeriesSize() );
455+
registerJsonFunctions( functionFactory );
456+
registerXmlFunctions( functionFactory );
457+
458+
functionFactory.unnest_db2( getMaximumSeriesSize() );
459+
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), false, true );
460+
461+
functionFactory.hex( "hex(?1)" );
462+
functionFactory.sha( "hash(?1, 2)" );
463+
functionFactory.md5( "hash(?1, 0)" );
464+
465+
functionFactory.regexpLike();
466+
}
463467

468+
protected static void registerXmlFunctions(CommonFunctionFactory functionFactory) {
464469
functionFactory.xmlelement();
465470
functionFactory.xmlcomment();
466471
functionFactory.xmlforest();
@@ -470,15 +475,17 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
470475
functionFactory.xmlexists();
471476
functionFactory.xmlagg();
472477
functionFactory.xmltable_db2();
478+
}
473479

474-
functionFactory.unnest_db2( getMaximumSeriesSize() );
475-
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), false, true );
476-
477-
functionFactory.hex( "hex(?1)" );
478-
functionFactory.sha( "hash(?1, 2)" );
479-
functionFactory.md5( "hash(?1, 0)" );
480-
481-
functionFactory.regexpLike();
480+
protected void registerJsonFunctions(CommonFunctionFactory functionFactory) {
481+
functionFactory.jsonValue_db2();
482+
functionFactory.jsonQuery_no_passing();
483+
functionFactory.jsonExists_no_passing();
484+
functionFactory.jsonObject_db2();
485+
functionFactory.jsonArray_db2();
486+
functionFactory.jsonArrayAgg_db2();
487+
functionFactory.jsonObjectAgg_db2();
488+
functionFactory.jsonTable_db2( getMaximumSeriesSize() );
482489
}
483490

484491
/**

hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,31 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
198198
// from v. 2.2.0 ROWNUM() is supported in all modes as the equivalent of Oracle ROWNUM
199199
functionFactory.rownum();
200200
functionFactory.listagg_groupConcat();
201+
202+
registerArrayFunctions( functionFactory );
203+
204+
if ( getVersion().isSameOrAfter( 2, 7 ) ) {
205+
functionFactory.jsonObject_hsqldb();
206+
functionFactory.jsonArray_hsqldb();
207+
functionFactory.jsonArrayAgg_hsqldb();
208+
functionFactory.jsonObjectAgg_h2();
209+
}
210+
211+
functionFactory.unnest( "c1", "c2" );
212+
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), true, false );
213+
214+
//trim() requires parameters to be cast when used as trim character
215+
functionContributions.getFunctionRegistry().register( "trim", new TrimFunction(
216+
this,
217+
functionContributions.getTypeConfiguration(),
218+
SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER
219+
) );
220+
221+
functionFactory.hex( "hex(?1)" );
222+
functionFactory.regexpLike_hsql();
223+
}
224+
225+
protected static void registerArrayFunctions(CommonFunctionFactory functionFactory) {
201226
functionFactory.array_hsql();
202227
functionFactory.arrayAggregate();
203228
functionFactory.arrayPosition_hsql();
@@ -219,26 +244,6 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
219244
functionFactory.arraySort_hsql();
220245
functionFactory.arrayFill_hsql();
221246
functionFactory.arrayToString_hsql();
222-
223-
if ( getVersion().isSameOrAfter( 2, 7 ) ) {
224-
functionFactory.jsonObject_hsqldb();
225-
functionFactory.jsonArray_hsqldb();
226-
functionFactory.jsonArrayAgg_hsqldb();
227-
functionFactory.jsonObjectAgg_h2();
228-
}
229-
230-
functionFactory.unnest( "c1", "c2" );
231-
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), true, false );
232-
233-
//trim() requires parameters to be cast when used as trim character
234-
functionContributions.getFunctionRegistry().register( "trim", new TrimFunction(
235-
this,
236-
functionContributions.getTypeConfiguration(),
237-
SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER
238-
) );
239-
240-
functionFactory.hex( "hex(?1)" );
241-
functionFactory.regexpLike_hsql();
242247
}
243248

244249
/**

hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,24 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
667667

668668
functionFactory.listagg_groupConcat();
669669

670+
registerJsonFunctions( functionFactory );
671+
672+
functionFactory.unnest_emulated();
673+
674+
// TODO: which one is correct??
675+
functionFactory.regexpLike_regexp();
676+
functionFactory.regexpLike();
677+
678+
if ( supportsRecursiveCTE() ) {
679+
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), false, false );
680+
}
681+
682+
functionFactory.hex( "hex(?1)" );
683+
functionFactory.sha( "unhex(sha2(?1, 256))" );
684+
functionFactory.md5( "unhex(md5(?1))" );
685+
}
686+
687+
protected static void registerJsonFunctions(CommonFunctionFactory functionFactory) {
670688
functionFactory.jsonValue_mysql();
671689
functionFactory.jsonQuery_mysql();
672690
functionFactory.jsonExists_mysql();
@@ -681,19 +699,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
681699
functionFactory.jsonMergepatch_mysql();
682700
functionFactory.jsonArrayAppend_mysql();
683701
functionFactory.jsonArrayInsert_mysql();
684-
functionFactory.regexpLike_regexp();
685-
686-
functionFactory.unnest_emulated();
687702
functionFactory.jsonTable_mysql();
688-
functionFactory.regexpLike();
689-
690-
if ( supportsRecursiveCTE() ) {
691-
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), false, false );
692-
}
693-
694-
functionFactory.hex( "hex(?1)" );
695-
functionFactory.sha( "unhex(sha2(?1, 256))" );
696-
functionFactory.md5( "unhex(md5(?1))" );
697703
}
698704

699705
/**

hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,55 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
380380
);
381381
functionRegistry.registerAlternateKey( "truncate", "trunc" );
382382

383+
registerArrayFunctions( functionFactory );
384+
registerJsonFunctions( functionFactory );
385+
registerXmlFunctions( functionFactory );
386+
387+
functionFactory.unnest_oracle();
388+
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), true, false );
389+
390+
functionFactory.hex( "rawtohex(?1)" );
391+
functionFactory.sha( "standard_hash(?1, 'SHA256')" );
392+
functionFactory.md5( "standard_hash(?1, 'MD5')" );
393+
394+
functionRegistry.register(
395+
"extract",
396+
new OracleExtractFunction( this, typeConfiguration )
397+
);
398+
functionFactory.regexpLike_predicateFunction();
399+
}
400+
401+
protected static void registerXmlFunctions(CommonFunctionFactory functionFactory) {
402+
functionFactory.xmlelement();
403+
functionFactory.xmlcomment();
404+
functionFactory.xmlforest();
405+
functionFactory.xmlconcat();
406+
functionFactory.xmlpi();
407+
functionFactory.xmlquery_oracle();
408+
functionFactory.xmlexists();
409+
functionFactory.xmlagg();
410+
functionFactory.xmltable_oracle();
411+
}
412+
413+
protected static void registerJsonFunctions(CommonFunctionFactory functionFactory) {
414+
functionFactory.jsonValue_oracle();
415+
functionFactory.jsonQuery_oracle();
416+
functionFactory.jsonExists_oracle();
417+
functionFactory.jsonObject_oracle( true );
418+
functionFactory.jsonArray_oracle();
419+
functionFactory.jsonArrayAgg_oracle();
420+
functionFactory.jsonObjectAgg_oracle();
421+
functionFactory.jsonSet_oracle();
422+
functionFactory.jsonRemove_oracle();
423+
functionFactory.jsonReplace_oracle();
424+
functionFactory.jsonInsert_oracle();
425+
functionFactory.jsonMergepatch_oracle();
426+
functionFactory.jsonArrayAppend_oracle();
427+
functionFactory.jsonArrayInsert_oracle();
428+
functionFactory.jsonTable_oracle();
429+
}
430+
431+
protected static void registerArrayFunctions(CommonFunctionFactory functionFactory) {
383432
functionFactory.array_oracle();
384433
functionFactory.arrayAggregate_jsonArrayagg();
385434
functionFactory.arrayPosition_oracle();
@@ -401,45 +450,6 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
401450
functionFactory.arraySort_oracle();
402451
functionFactory.arrayFill_oracle();
403452
functionFactory.arrayToString_oracle();
404-
405-
functionFactory.jsonValue_oracle();
406-
functionFactory.jsonQuery_oracle();
407-
functionFactory.jsonExists_oracle();
408-
functionFactory.jsonObject_oracle( true );
409-
functionFactory.jsonArray_oracle();
410-
functionFactory.jsonArrayAgg_oracle();
411-
functionFactory.jsonObjectAgg_oracle();
412-
functionFactory.jsonSet_oracle();
413-
functionFactory.jsonRemove_oracle();
414-
functionFactory.jsonReplace_oracle();
415-
functionFactory.jsonInsert_oracle();
416-
functionFactory.jsonMergepatch_oracle();
417-
functionFactory.jsonArrayAppend_oracle();
418-
functionFactory.jsonArrayInsert_oracle();
419-
420-
functionFactory.xmlelement();
421-
functionFactory.xmlcomment();
422-
functionFactory.xmlforest();
423-
functionFactory.xmlconcat();
424-
functionFactory.xmlpi();
425-
functionFactory.xmlquery_oracle();
426-
functionFactory.xmlexists();
427-
functionFactory.xmlagg();
428-
functionFactory.xmltable_oracle();
429-
430-
functionFactory.unnest_oracle();
431-
functionFactory.generateSeries_recursive( getMaximumSeriesSize(), true, false );
432-
functionFactory.jsonTable_oracle();
433-
434-
functionFactory.hex( "rawtohex(?1)" );
435-
functionFactory.sha( "standard_hash(?1, 'SHA256')" );
436-
functionFactory.md5( "standard_hash(?1, 'MD5')" );
437-
438-
functionRegistry.register(
439-
"extract",
440-
new OracleExtractFunction( this, typeConfiguration )
441-
);
442-
functionFactory.regexpLike_predicateFunction();
443453
}
444454

445455
/**

0 commit comments

Comments
 (0)