Skip to content

Commit a3f5068

Browse files
committed
HHH-18497 Add xmlpi function
1 parent 2f5bc10 commit a3f5068

File tree

28 files changed

+359
-3
lines changed

28 files changed

+359
-3
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,7 @@ it is necessary to enable the `hibernate.query.hql.xml_functions_enabled` config
21752175
| `xmlcomment()` | Constructs an XML comment from the single argument
21762176
| `xmlforest()` | Constructs an XML forest from the arguments
21772177
| `xmlconcat()` | Concatenates multiple XML fragments to each other
2178+
| `xmlpi()` | Constructs an XML processing instruction
21782179
|===
21792180
21802181
@@ -2266,6 +2267,39 @@ include::{xml-example-dir-hql}/XmlConcatTest.java[tags=hql-xmlconcat-example]
22662267
22672268
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
22682269
2270+
[[hql-xmlpi-function]]
2271+
===== `xmlpi()`
2272+
2273+
Constructs an XML processing instruction from the arguments.
2274+
2275+
[[hql-xmlpi-bnf]]
2276+
[source, antlrv4, indent=0]
2277+
----
2278+
include::{extrasdir}/xmlpi_bnf.txt[]
2279+
----
2280+
2281+
The identifier represents the XML processing instruction name and can be quoted by using backticks.
2282+
2283+
[[hql-xmlpi-example]]
2284+
====
2285+
[source, java, indent=0]
2286+
----
2287+
include::{xml-example-dir-hql}/XmlPiTest.java[tags=hql-xmlpi-example]
2288+
----
2289+
====
2290+
2291+
The optional second argument represents the processing instruction content.
2292+
2293+
[[hql-xmlpi-content-example]]
2294+
====
2295+
[source, java, indent=0]
2296+
----
2297+
include::{xml-example-dir-hql}/XmlPiTest.java[tags=hql-xmlpi-content-example]
2298+
----
2299+
====
2300+
2301+
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
2302+
22692303
[[hql-user-defined-functions]]
22702304
==== Native and user-defined functions
22712305
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"xmlpi(name " identifier ("," expressionOrPredicate)? ")"

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
@@ -445,6 +445,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
445445
functionFactory.xmlcomment();
446446
functionFactory.xmlforest();
447447
functionFactory.xmlconcat();
448+
functionFactory.xmlpi();
448449
}
449450

450451
@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
@@ -422,6 +422,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
422422
functionFactory.xmlcomment();
423423
functionFactory.xmlforest_h2();
424424
functionFactory.xmlconcat_h2();
425+
functionFactory.xmlpi_h2();
425426
}
426427
else {
427428
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
@@ -330,6 +330,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
330330
functionFactory.xmlcomment();
331331
functionFactory.xmlforest();
332332
functionFactory.xmlconcat();
333+
functionFactory.xmlpi();
333334
}
334335

335336
@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
@@ -673,6 +673,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
673673
functionFactory.xmlcomment();
674674
functionFactory.xmlforest();
675675
functionFactory.xmlconcat();
676+
functionFactory.xmlpi();
676677

677678
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
678679
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
@@ -417,6 +417,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
417417
functionFactory.xmlcomment_sqlserver();
418418
functionFactory.xmlforest_sqlserver();
419419
functionFactory.xmlconcat_sqlserver();
420+
functionFactory.xmlpi_sqlserver();
420421
if ( getVersion().isSameOrAfter( 14 ) ) {
421422
functionFactory.listagg_stringAggWithinGroup( "varchar(max)" );
422423
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
@@ -333,6 +333,7 @@ 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];
335335
XMLFOREST : [xX] [mM] [lL] [fF] [oO] [rR] [eE] [sS] [tT];
336+
XMLPI : [xX] [mM] [lL] [pP] [iI];
336337
YEAR : [yY] [eE] [aA] [rR];
337338
ZONED : [zZ] [oO] [nN] [eE] [dD];
338339

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
@@ -1720,6 +1720,7 @@ jsonUniqueKeysClause
17201720
xmlFunction
17211721
: xmlelementFunction
17221722
| xmlforestFunction
1723+
| xmlpiFunction
17231724
;
17241725

17251726
/**
@@ -1743,6 +1744,13 @@ xmlforestFunction
17431744
: XMLFOREST LEFT_PAREN expressionOrPredicate (AS identifier)? (COMMA expressionOrPredicate (AS identifier)?)* RIGHT_PAREN
17441745
;
17451746

1747+
/**
1748+
* The 'xmlpi()' function
1749+
*/
1750+
xmlpiFunction
1751+
: XMLPI LEFT_PAREN NAME identifier (COMMA expression)? RIGHT_PAREN
1752+
;
1753+
17461754
/**
17471755
* Support for "soft" keywords which may be used as identifiers
17481756
*
@@ -1952,6 +1960,7 @@ xmlforestFunction
19521960
| XMLATTRIBUTES
19531961
| XMLELEMENT
19541962
| XMLFOREST
1963+
| XMLPI
19551964
| YEAR
19561965
| ZONED) {
19571966
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
@@ -430,6 +430,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
430430
functionFactory.xmlcomment();
431431
functionFactory.xmlforest();
432432
functionFactory.xmlconcat();
433+
functionFactory.xmlpi();
433434
}
434435

435436
@Override

0 commit comments

Comments
 (0)