Skip to content

Commit 12558fd

Browse files
committed
HHH-18497 Add xmlquery function
1 parent a3f5068 commit 12558fd

File tree

25 files changed

+358
-0
lines changed

25 files changed

+358
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,7 @@ it is necessary to enable the `hibernate.query.hql.xml_functions_enabled` config
21762176
| `xmlforest()` | Constructs an XML forest from the arguments
21772177
| `xmlconcat()` | Concatenates multiple XML fragments to each other
21782178
| `xmlpi()` | Constructs an XML processing instruction
2179+
| `xmlquery()` | Extracts content from XML document using XQuery or XPath
21792180
|===
21802181
21812182
@@ -2300,6 +2301,30 @@ include::{xml-example-dir-hql}/XmlPiTest.java[tags=hql-xmlpi-content-example]
23002301
23012302
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
23022303
2304+
[[hql-xmlquery-function]]
2305+
===== `xmlquery()`
2306+
2307+
Extracts content from an XML document using XQuery or XPath.
2308+
2309+
[[hql-xmlquery-bnf]]
2310+
[source, antlrv4, indent=0]
2311+
----
2312+
include::{extrasdir}/xmlquery_bnf.txt[]
2313+
----
2314+
2315+
The first argument represents the XQuery or XPath expression.
2316+
The second argument after the `passing` keyword represents the XML document.
2317+
2318+
[[hql-xmlquery-example]]
2319+
====
2320+
[source, java, indent=0]
2321+
----
2322+
include::{xml-example-dir-hql}/XmlQueryTest.java[tags=hql-xmlquery-example]
2323+
----
2324+
====
2325+
2326+
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
2327+
23032328
[[hql-user-defined-functions]]
23042329
==== Native and user-defined functions
23052330
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"xmlquery(" expression "passing" expression ")"

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
@@ -446,6 +446,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
446446
functionFactory.xmlforest();
447447
functionFactory.xmlconcat();
448448
functionFactory.xmlpi();
449+
functionFactory.xmlquery_db2();
449450
}
450451

451452
@Override

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
@@ -331,6 +331,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
331331
functionFactory.xmlforest();
332332
functionFactory.xmlconcat();
333333
functionFactory.xmlpi();
334+
functionFactory.xmlquery_oracle();
334335
}
335336

336337
@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
@@ -674,6 +674,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
674674
functionFactory.xmlforest();
675675
functionFactory.xmlconcat();
676676
functionFactory.xmlpi();
677+
functionFactory.xmlquery_postgresql();
677678

678679
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
679680
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
@@ -418,6 +418,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
418418
functionFactory.xmlforest_sqlserver();
419419
functionFactory.xmlconcat_sqlserver();
420420
functionFactory.xmlpi_sqlserver();
421+
functionFactory.xmlquery_sqlserver();
421422
if ( getVersion().isSameOrAfter( 14 ) ) {
422423
functionFactory.listagg_stringAggWithinGroup( "varchar(max)" );
423424
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
@@ -334,6 +334,7 @@ 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];
335335
XMLFOREST : [xX] [mM] [lL] [fF] [oO] [rR] [eE] [sS] [tT];
336336
XMLPI : [xX] [mM] [lL] [pP] [iI];
337+
XMLQUERY : [xX] [mM] [lL] [qQ] [uU] [eE] [rR] [yY];
337338
YEAR : [yY] [eE] [aA] [rR];
338339
ZONED : [zZ] [oO] [nN] [eE] [dD];
339340

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
@@ -1721,6 +1721,7 @@ xmlFunction
17211721
: xmlelementFunction
17221722
| xmlforestFunction
17231723
| xmlpiFunction
1724+
| xmlqueryFunction
17241725
;
17251726

17261727
/**
@@ -1751,6 +1752,13 @@ xmlpiFunction
17511752
: XMLPI LEFT_PAREN NAME identifier (COMMA expression)? RIGHT_PAREN
17521753
;
17531754

1755+
/**
1756+
* The 'xmlquery()' function
1757+
*/
1758+
xmlqueryFunction
1759+
: XMLQUERY LEFT_PAREN expression PASSING expression RIGHT_PAREN
1760+
;
1761+
17541762
/**
17551763
* Support for "soft" keywords which may be used as identifiers
17561764
*
@@ -1961,6 +1969,7 @@ xmlpiFunction
19611969
| XMLELEMENT
19621970
| XMLFOREST
19631971
| XMLPI
1972+
| XMLQUERY
19641973
| YEAR
19651974
| ZONED) {
19661975
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
@@ -431,6 +431,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
431431
functionFactory.xmlforest();
432432
functionFactory.xmlconcat();
433433
functionFactory.xmlpi();
434+
functionFactory.xmlquery_db2();
434435
}
435436

436437
@Override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
421421
functionFactory.xmlforest();
422422
functionFactory.xmlconcat();
423423
functionFactory.xmlpi();
424+
functionFactory.xmlquery_oracle();
424425
}
425426

426427
@Override

0 commit comments

Comments
 (0)