Skip to content

Commit 0189d45

Browse files
committed
HHH-18497 Add xmlforest function
1 parent f9a725e commit 0189d45

File tree

34 files changed

+552
-6
lines changed

34 files changed

+552
-6
lines changed

documentation/src/main/asciidoc/userguide/chapters/query/hql/QueryLanguage.adoc

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,7 @@ it is necessary to enable the `hibernate.query.hql.xml_functions_enabled` config
21732173
21742174
| `xmlelement()` | Constructs an XML element from arguments
21752175
| `xmlcomment()` | Constructs an XML comment from the single argument
2176+
| `xmlforest()` | Constructs an XML forest from thearguments
21762177
|===
21772178
21782179
@@ -2208,7 +2209,7 @@ include::{xml-example-dir-hql}/XmlElementTest.java[tags=hql-xmlelement-attribute
22082209
----
22092210
====
22102211
2211-
WARNING: SAP HANA, MySQL, MariaDB, H2 and HSQLDB do not support this function.
2212+
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
22122213
22132214
[[hql-xmlcomment-function]]
22142215
===== `xmlcomment()`
@@ -2223,7 +2224,31 @@ include::{xml-example-dir-hql}/XmlCommentTest.java[tags=hql-xmlcomment-example]
22232224
----
22242225
====
22252226
2226-
WARNING: SAP HANA, MySQL, MariaDB, H2 and HSQLDB do not support this function.
2227+
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
2228+
2229+
[[hql-xmlforest-function]]
2230+
===== `xmlforest()`
2231+
2232+
Constructs an XML forest from the arguments. A forest is a sequence of XML elements.
2233+
2234+
[[hql-xmlforest-bnf]]
2235+
[source, antlrv4, indent=0]
2236+
----
2237+
include::{extrasdir}/xmlforest_bnf.txt[]
2238+
----
2239+
2240+
The optional name specifies the XML element name to use for the content as produced by the expression.
2241+
The name can be omitted if a path expression is passed, in which case the last attribute name is used as element name.
2242+
2243+
[[hql-xmlforest-example]]
2244+
====
2245+
[source, java, indent=0]
2246+
----
2247+
include::{xml-example-dir-hql}/XmlForestTest.java[tags=hql-xmlforest-example]
2248+
----
2249+
====
2250+
2251+
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
22272252
22282253
[[hql-user-defined-functions]]
22292254
==== Native and user-defined functions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"xmlforest(expressionOrPredicate ("as" identifier)? ("," expressionOrPredicate ("as" identifier)?)* ")"

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
443443

444444
functionFactory.xmlelement();
445445
functionFactory.xmlcomment();
446+
functionFactory.xmlforest();
446447
}
447448

448449
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/H2LegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
420420

421421
functionFactory.xmlelement_h2();
422422
functionFactory.xmlcomment();
423+
functionFactory.xmlforest_h2();
423424
}
424425
else {
425426
functionFactory.listagg_groupConcat();

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
328328

329329
functionFactory.xmlelement();
330330
functionFactory.xmlcomment();
331+
functionFactory.xmlforest();
331332
}
332333

333334
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
671671

672672
functionFactory.xmlelement();
673673
functionFactory.xmlcomment();
674+
functionFactory.xmlforest();
674675

675676
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
676677
functionFactory.makeDateTimeTimestamp();

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
415415
}
416416
functionFactory.xmlelement_sqlserver();
417417
functionFactory.xmlcomment_sqlserver();
418+
functionFactory.xmlforest_sqlserver();
418419
if ( getVersion().isSameOrAfter( 14 ) ) {
419420
functionFactory.listagg_stringAggWithinGroup( "varchar(max)" );
420421
functionFactory.jsonArrayAgg_sqlserver( getVersion().isSameOrAfter( 16 ) );

hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlLexer.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ WITHOUT : [wW] [iI] [tT] [hH] [oO] [uU] [tT];
332332
WRAPPER : [wW] [rR] [aA] [pP] [pP] [eE] [rR];
333333
XMLATTRIBUTES : [xX] [mM] [lL] [aA] [tT] [tT] [rR] [iI] [bB] [uU] [tT] [eE] [sS];
334334
XMLELEMENT : [xX] [mM] [lL] [eE] [lL] [eE] [mM] [eE] [nN] [tT];
335+
XMLFOREST : [xX] [mM] [lL] [fF] [oO] [rR] [eE] [sS] [tT];
335336
YEAR : [yY] [eE] [aA] [rR];
336337
ZONED : [zZ] [oO] [nN] [eE] [dD];
337338

hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlParser.g4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ jsonUniqueKeysClause
17191719

17201720
xmlFunction
17211721
: xmlelementFunction
1722+
| xmlforestFunction
17221723
;
17231724

17241725
/**
@@ -1735,6 +1736,13 @@ xmlattributesFunction
17351736
: XMLATTRIBUTES LEFT_PAREN expressionOrPredicate AS identifier (COMMA expressionOrPredicate AS identifier)* RIGHT_PAREN
17361737
;
17371738

1739+
/**
1740+
* The 'xmlforest()' function
1741+
*/
1742+
xmlforestFunction
1743+
: XMLFOREST LEFT_PAREN expressionOrPredicate (AS identifier)? (COMMA expressionOrPredicate (AS identifier)?)* RIGHT_PAREN
1744+
;
1745+
17381746
/**
17391747
* Support for "soft" keywords which may be used as identifiers
17401748
*
@@ -1943,6 +1951,7 @@ xmlattributesFunction
19431951
| WRAPPER
19441952
| XMLATTRIBUTES
19451953
| XMLELEMENT
1954+
| XMLFOREST
19461955
| YEAR
19471956
| ZONED) {
19481957
logUseOfReservedWordAsIdentifier( getCurrentToken() );

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
428428

429429
functionFactory.xmlelement();
430430
functionFactory.xmlcomment();
431+
functionFactory.xmlforest();
431432
}
432433

433434
@Override

0 commit comments

Comments
 (0)