Skip to content

Commit 17f3286

Browse files
committed
HHH-18604 Add json_set function
1 parent 7e11d7a commit 17f3286

File tree

23 files changed

+465
-0
lines changed

23 files changed

+465
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,7 @@ it is necessary to enable the `hibernate.query.hql.json_functions_enabled` confi
16391639
| `json_query()` | Queries non-scalar values by JSON path in a JSON document
16401640
| `json_arrayagg()` | Creates a JSON array by aggregating values
16411641
| `json_objectagg()` | Creates a JSON object by aggregating values
1642+
| `json_set()` | Inserts/Replaces a value by JSON path within a JSON document
16421643
|===
16431644
16441645
@@ -2013,6 +2014,22 @@ include::{json-example-dir-hql}/JsonObjectAggregateTest.java[tags=hql-json-objec
20132014
20142015
WARNING: Some databases like e.g. MySQL, SAP HANA, DB2 and SQL Server do not support raising an error on duplicate keys.
20152016
2017+
[[hql-json-set-function]]
2018+
===== `json_set()`
2019+
2020+
Inserts/Replaces a value by JSON path within a JSON document.
2021+
The function takes 3 arguments, the json document, the json path and the new value to set/insert.
2022+
2023+
[[hql-json-set-example]]
2024+
====
2025+
[source, java, indent=0]
2026+
----
2027+
include::{json-example-dir-hql}/JsonSetTest.java[tags=hql-json-set-example]
2028+
----
2029+
====
2030+
2031+
WARNING: SAP HANA, DB2, H2 and HSQLDB do not support this function.
2032+
20162033
[[hql-user-defined-functions]]
20172034
==== Native and user-defined functions
20182035

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
508508
functionFactory.jsonArray_postgresql();
509509
functionFactory.jsonArrayAgg_postgresql( false );
510510
functionFactory.jsonObjectAgg_postgresql( false );
511+
functionFactory.jsonSet_postgresql();
511512

512513
// Postgres uses # instead of ^ for XOR
513514
functionContributions.getFunctionRegistry().patternDescriptorBuilder( "bitxor", "(?1#?2)" )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
660660
functionFactory.jsonArray_mysql();
661661
functionFactory.jsonArrayAgg_mysql();
662662
functionFactory.jsonObjectAgg_mysql();
663+
functionFactory.jsonSet_mysql();
663664
}
664665
}
665666

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
@@ -316,6 +316,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
316316
functionFactory.jsonObject_oracle();
317317
functionFactory.jsonArray_oracle();
318318
functionFactory.jsonArrayAgg_oracle();
319+
functionFactory.jsonSet_oracle();
319320
}
320321
}
321322

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
@@ -658,6 +658,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
658658
functionFactory.jsonObjectAgg_postgresql( false );
659659
}
660660
}
661+
functionFactory.jsonSet_postgresql();
661662

662663
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
663664
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
@@ -406,6 +406,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
406406
functionFactory.jsonExists_sqlserver();
407407
functionFactory.jsonObject_sqlserver();
408408
functionFactory.jsonArray_sqlserver();
409+
functionFactory.jsonSet_sqlserver();
409410
}
410411
if ( getVersion().isSameOrAfter( 14 ) ) {
411412
functionFactory.listagg_stringAggWithinGroup( "varchar(max)" );

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
475475
functionFactory.jsonArray_postgresql();
476476
functionFactory.jsonArrayAgg_postgresql( false );
477477
functionFactory.jsonObjectAgg_postgresql( false );
478+
functionFactory.jsonSet_postgresql();
478479

479480
// Postgres uses # instead of ^ for XOR
480481
functionContributions.getFunctionRegistry().patternDescriptorBuilder( "bitxor", "(?1#?2)" )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
645645
functionFactory.jsonArray_mysql();
646646
functionFactory.jsonArrayAgg_mysql();
647647
functionFactory.jsonObjectAgg_mysql();
648+
functionFactory.jsonSet_mysql();
648649
}
649650

650651
@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
@@ -407,6 +407,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
407407
functionFactory.jsonObject_oracle();
408408
functionFactory.jsonArray_oracle();
409409
functionFactory.jsonArrayAgg_oracle();
410+
functionFactory.jsonSet_oracle();
410411
}
411412

412413
@Override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
619619
functionFactory.jsonObjectAgg_postgresql( false );
620620
}
621621
}
622+
functionFactory.jsonSet_postgresql();
622623

623624
functionFactory.makeDateTimeTimestamp();
624625
// Note that PostgreSQL doesn't support the OVER clause for ordered set-aggregate functions

0 commit comments

Comments
 (0)