Skip to content

Commit af09813

Browse files
committed
HHH-18497 Add xmlexists function
1 parent 449d002 commit af09813

File tree

22 files changed

+274
-0
lines changed

22 files changed

+274
-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
@@ -2177,6 +2177,7 @@ it is necessary to enable the `hibernate.query.hql.xml_functions_enabled` config
21772177
| `xmlconcat()` | Concatenates multiple XML fragments to each other
21782178
| `xmlpi()` | Constructs an XML processing instruction
21792179
| `xmlquery()` | Extracts content from XML document using XQuery or XPath
2180+
| `xmlexists()` | Checks if an XQuery or XPath expression exists in an XML document
21802181
|===
21812182
21822183
@@ -2325,6 +2326,30 @@ include::{xml-example-dir-hql}/XmlQueryTest.java[tags=hql-xmlquery-example]
23252326
23262327
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
23272328
2329+
[[hql-xmlexists-function]]
2330+
===== `xmlexists()`
2331+
2332+
Checks if an XQuery or XPath expression exists in an XML document.
2333+
2334+
[[hql-xmlexists-bnf]]
2335+
[source, antlrv4, indent=0]
2336+
----
2337+
include::{extrasdir}/xmlexists_bnf.txt[]
2338+
----
2339+
2340+
The first argument represents the XQuery or XPath expression.
2341+
The second argument after the `passing` keyword represents the XML document.
2342+
2343+
[[hql-xmlexists-example]]
2344+
====
2345+
[source, java, indent=0]
2346+
----
2347+
include::{xml-example-dir-hql}/XmlExistsTest.java[tags=hql-xmlexists-example]
2348+
----
2349+
====
2350+
2351+
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
2352+
23282353
[[hql-user-defined-functions]]
23292354
==== Native and user-defined functions
23302355
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"xmlexists(" 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
@@ -447,6 +447,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
447447
functionFactory.xmlconcat();
448448
functionFactory.xmlpi();
449449
functionFactory.xmlquery_db2();
450+
functionFactory.xmlexists();
450451
}
451452

452453
@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
@@ -332,6 +332,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
332332
functionFactory.xmlconcat();
333333
functionFactory.xmlpi();
334334
functionFactory.xmlquery_oracle();
335+
functionFactory.xmlexists();
335336
}
336337

337338
@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
@@ -675,6 +675,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
675675
functionFactory.xmlconcat();
676676
functionFactory.xmlpi();
677677
functionFactory.xmlquery_postgresql();
678+
functionFactory.xmlexists();
678679

679680
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
680681
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
@@ -419,6 +419,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
419419
functionFactory.xmlconcat_sqlserver();
420420
functionFactory.xmlpi_sqlserver();
421421
functionFactory.xmlquery_sqlserver();
422+
functionFactory.xmlexists_sqlserver();
422423
if ( getVersion().isSameOrAfter( 14 ) ) {
423424
functionFactory.listagg_stringAggWithinGroup( "varchar(max)" );
424425
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+
XMLEXISTS : [xX] [mM] [lL] [eE] [xX] [iI] [sS] [tT] [sS];
335336
XMLFOREST : [xX] [mM] [lL] [fF] [oO] [rR] [eE] [sS] [tT];
336337
XMLPI : [xX] [mM] [lL] [pP] [iI];
337338
XMLQUERY : [xX] [mM] [lL] [qQ] [uU] [eE] [rR] [yY];

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
@@ -1722,6 +1722,7 @@ xmlFunction
17221722
| xmlforestFunction
17231723
| xmlpiFunction
17241724
| xmlqueryFunction
1725+
| xmlexistsFunction
17251726
;
17261727

17271728
/**
@@ -1759,6 +1760,13 @@ xmlqueryFunction
17591760
: XMLQUERY LEFT_PAREN expression PASSING expression RIGHT_PAREN
17601761
;
17611762

1763+
/**
1764+
* The 'xmlexists()' function
1765+
*/
1766+
xmlexistsFunction
1767+
: XMLEXISTS LEFT_PAREN expression PASSING expression RIGHT_PAREN
1768+
;
1769+
17621770
/**
17631771
* Support for "soft" keywords which may be used as identifiers
17641772
*
@@ -1967,6 +1975,7 @@ xmlqueryFunction
19671975
| WRAPPER
19681976
| XMLATTRIBUTES
19691977
| XMLELEMENT
1978+
| XMLEXISTS
19701979
| XMLFOREST
19711980
| XMLPI
19721981
| XMLQUERY

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
432432
functionFactory.xmlconcat();
433433
functionFactory.xmlpi();
434434
functionFactory.xmlquery_db2();
435+
functionFactory.xmlexists();
435436
}
436437

437438
@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
@@ -422,6 +422,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
422422
functionFactory.xmlconcat();
423423
functionFactory.xmlpi();
424424
functionFactory.xmlquery_oracle();
425+
functionFactory.xmlexists();
425426
}
426427

427428
@Override

0 commit comments

Comments
 (0)