Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"json_array(" (expressionOrPredicate ("," expressionOrPredicate)* jsonNullClause?)? ")"

jsonNullClause
: ("absent"|"null") "on null"
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"json_arrayagg(" expressionOrPredicate jsonNullClause? orderByClause? ")" filterClause?

jsonNullClause
: ("absent"|"null") "on null"
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"json_exists(" expression "," expression passingClause? onErrorClause? ")"

passingClause
: "passing" expression "as" identifier ("," expression "as" identifier)*

onErrorClause
: ( "error" | "true" | "false" ) "on error";
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"json_object(" (jsonObjectFunctionEntries jsonNullClause?)? ")"

jsonObjectFunctionEntries
: expressionOrPredicate "," expressionOrPredicate ("," expressionOrPredicate "," expressionOrPredicate)*
| jsonObjectFunctionEntry ("," jsonObjectFunctionEntry)*
;

jsonObjectFunctionEntry
: "key"? expressionOrPredicate "value" expressionOrPredicate
| expressionOrPredicate ":" expressionOrPredicate
;

jsonNullClause
: ("absent"|"null") "on null"
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"json_objectagg(" expressionOrPredicate ("value"|":") expressionOrPredicate jsonNullClause? uniqueKeysClause? ")" filterClause?

jsonNullClause
: ("absent"|"null") "on null"
;

uniqueKeysClause
: ("with"|"without") "unique keys"
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"json_query(" expression "," expression passingClause? wrapperClause? onErrorClause? onEmptyClause? ")"

wrapperClause
: "with" ("conditional"|"unconditional")? "array"? "wrapper"
| "without" "array"? "wrapper"

passingClause
: "passing" expression "as" identifier ("," expression "as" identifier)*

onErrorClause
: ( "error" | "null" | ( "empty" ( "array" | "object" )? ) ) "on error";

onEmptyClause
: ( "error" | "null" | ( "empty" ( "array" | "object" )? ) ) "on empty";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"json_value(" expression "," expression passingClause? ("returning" castTarget)? onErrorClause? onEmptyClause? ")"

passingClause
: "passing" expression "as" identifier ("," expression "as" identifier)*

onErrorClause
: ( "error" | "null" | ( "default" expression ) ) "on error";

onEmptyClause
: ( "error" | "null" | ( "default" expression ) ) "on empty";
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import static org.hibernate.type.SqlTypes.INET;
import static org.hibernate.type.SqlTypes.INTEGER;
import static org.hibernate.type.SqlTypes.JSON;
import static org.hibernate.type.SqlTypes.JSON_ARRAY;
import static org.hibernate.type.SqlTypes.LONG32NVARCHAR;
import static org.hibernate.type.SqlTypes.LONG32VARBINARY;
import static org.hibernate.type.SqlTypes.LONG32VARCHAR;
Expand Down Expand Up @@ -257,9 +258,11 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
if ( getVersion().isSameOrAfter( 20 ) ) {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( INET, "inet", this ) );
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "jsonb", this ) );
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON_ARRAY, "jsonb", this ) );
}
else {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "json", this ) );
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON_ARRAY, "json", this ) );
}
ddlTypeRegistry.addDescriptor( new NamedNativeEnumDdlTypeImpl( this ) );
ddlTypeRegistry.addDescriptor( new NamedNativeOrdinalEnumDdlTypeImpl( this ) );
Expand Down Expand Up @@ -364,19 +367,23 @@ protected void contributeCockroachTypes(TypeContributions typeContributions, Ser
if ( getVersion().isSameOrAfter( 20, 0 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( PgJdbcHelper.getInetJdbcType( serviceRegistry ) );
jdbcTypeRegistry.addDescriptorIfAbsent( PgJdbcHelper.getJsonbJdbcType( serviceRegistry ) );
jdbcTypeRegistry.addDescriptorIfAbsent( PgJdbcHelper.getJsonbArrayJdbcType( serviceRegistry ) );
}
else {
jdbcTypeRegistry.addDescriptorIfAbsent( PgJdbcHelper.getJsonJdbcType( serviceRegistry ) );
jdbcTypeRegistry.addDescriptorIfAbsent( PgJdbcHelper.getJsonArrayJdbcType( serviceRegistry ) );
}
}
else {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingIntervalSecondJdbcType.INSTANCE );
if ( getVersion().isSameOrAfter( 20, 0 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingInetJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingJsonJdbcType.JSONB_INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingJsonArrayJdbcType.JSONB_INSTANCE );
}
else {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingJsonJdbcType.JSON_INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingJsonArrayJdbcType.JSON_INSTANCE );
}
}
}
Expand All @@ -386,9 +393,11 @@ protected void contributeCockroachTypes(TypeContributions typeContributions, Ser
if ( getVersion().isSameOrAfter( 20, 0 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingInetJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingJsonJdbcType.JSONB_INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingJsonArrayJdbcType.JSONB_INSTANCE );
}
else {
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingJsonJdbcType.JSON_INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( PostgreSQLCastingJsonArrayJdbcType.JSON_INSTANCE );
}
}

Expand Down Expand Up @@ -488,6 +497,14 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionFactory.arrayFill_cockroachdb();
functionFactory.arrayToString_postgresql();

functionFactory.jsonValue_cockroachdb();
functionFactory.jsonQuery_cockroachdb();
functionFactory.jsonExists_cockroachdb();
functionFactory.jsonObject_postgresql();
functionFactory.jsonArray_postgresql();
functionFactory.jsonArrayAgg_postgresql( false );
functionFactory.jsonObjectAgg_postgresql( false );

// Postgres uses # instead of ^ for XOR
functionContributions.getFunctionRegistry().patternDescriptorBuilder( "bitxor", "(?1#?2)" )
.setExactArgumentCount( 2 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionFactory.windowFunctions();
if ( getDB2Version().isSameOrAfter( 9, 5 ) ) {
functionFactory.listagg( null );

if ( getDB2Version().isSameOrAfter( 11 ) ) {
functionFactory.jsonValue_no_passing();
functionFactory.jsonQuery_no_passing();
functionFactory.jsonExists_no_passing();
functionFactory.jsonObject_db2();
functionFactory.jsonArray_db2();
functionFactory.jsonArrayAgg_db2();
functionFactory.jsonObjectAgg_db2();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import static org.hibernate.type.SqlTypes.GEOMETRY;
import static org.hibernate.type.SqlTypes.INTERVAL_SECOND;
import static org.hibernate.type.SqlTypes.JSON;
import static org.hibernate.type.SqlTypes.JSON_ARRAY;
import static org.hibernate.type.SqlTypes.LONG32NVARCHAR;
import static org.hibernate.type.SqlTypes.LONG32VARBINARY;
import static org.hibernate.type.SqlTypes.LONG32VARCHAR;
Expand Down Expand Up @@ -265,6 +266,7 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
}
if ( getVersion().isSameOrAfter( 1, 4, 200 ) ) {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "json", this ) );
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON_ARRAY, "json", this ) );
}
}
ddlTypeRegistry.addDescriptor( new NativeEnumDdlTypeImpl( this ) );
Expand Down Expand Up @@ -295,6 +297,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
}
if ( getVersion().isSameOrAfter( 1, 4, 200 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( H2JsonJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( H2JsonArrayJdbcType.INSTANCE );
}
jdbcTypeRegistry.addDescriptor( EnumJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( OrdinalEnumJdbcType.INSTANCE );
Expand Down Expand Up @@ -399,8 +402,19 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionFactory.arrayTrim_trim_array();
functionFactory.arrayFill_h2();
functionFactory.arrayToString_h2( getMaximumArraySize() );

if ( getVersion().isSameOrAfter( 2, 2, 220 ) ) {
functionFactory.jsonValue_h2();
functionFactory.jsonQuery_h2();
functionFactory.jsonExists_h2();
functionFactory.jsonArrayAgg_h2();
functionFactory.jsonObjectAgg_h2();
}
}
else {
functionFactory.jsonObject();
functionFactory.jsonArray();

// Use group_concat until 2.x as listagg was buggy
functionFactory.listagg_groupConcat();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionFactory.arrayFill_hsql();
functionFactory.arrayToString_hsql();

if ( getVersion().isSameOrAfter( 2, 7 ) ) {
functionFactory.jsonObject_hsqldb();
functionFactory.jsonArray_hsqldb();
functionFactory.jsonArrayAgg_hsqldb();
functionFactory.jsonObjectAgg_h2();
}

//trim() requires parameters to be cast when used as trim character
functionContributions.getFunctionRegistry().register( "trim", new TrimFunction(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hibernate.type.SqlTypes;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JsonArrayJdbcType;
import org.hibernate.type.descriptor.jdbc.JsonJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl;
Expand Down Expand Up @@ -91,6 +92,11 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
.getBasicTypeRegistry()
.resolve( StandardBasicTypes.BOOLEAN )
);
commonFunctionFactory.jsonValue_mariadb();
commonFunctionFactory.jsonArray_mariadb();
commonFunctionFactory.jsonQuery_mariadb();
commonFunctionFactory.jsonArrayAgg_mariadb();
commonFunctionFactory.jsonObjectAgg_mariadb();
if ( getVersion().isSameOrAfter( 10, 3, 3 ) ) {
commonFunctionFactory.inverseDistributionOrderedSetAggregates_windowEmulation();
functionContributions.getFunctionRegistry().patternDescriptorBuilder( "median", "median(?1) over ()" )
Expand Down Expand Up @@ -140,6 +146,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration().getJdbcTypeRegistry();
// Make sure we register the JSON type descriptor before calling super, because MariaDB does not need casting
jdbcTypeRegistry.addDescriptorIfAbsent( SqlTypes.JSON, JsonJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( SqlTypes.JSON_ARRAY, JsonArrayJdbcType.INSTANCE );

super.contributeTypes( typeContributions, serviceRegistry );
if ( getVersion().isSameOrAfter( 10, 7 ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,16 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionRegistry.registerAlternateKey( "char", "chr" );

functionFactory.listagg_groupConcat();

if ( getMySQLVersion().isSameOrAfter( 5, 7 ) ) {
functionFactory.jsonValue_mysql();
functionFactory.jsonQuery_mysql();
functionFactory.jsonExists_mysql();
functionFactory.jsonObject_mysql();
functionFactory.jsonArray_mysql();
functionFactory.jsonArrayAgg_mysql();
functionFactory.jsonObjectAgg_mysql();
}
}

@Override
Expand All @@ -663,6 +673,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry

if ( getMySQLVersion().isSameOrAfter( 5, 7 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( SqlTypes.JSON, MySQLCastingJsonJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptorIfAbsent( SqlTypes.JSON_ARRAY, MySQLCastingJsonArrayJdbcType.INSTANCE );
}

// MySQL requires a custom binder for binding untyped nulls with the NULL type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,7 @@
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.BooleanDecoder;
import org.hibernate.dialect.DmlTargetColumnQualifierSupport;
import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.OracleBooleanJdbcType;
import org.hibernate.dialect.OracleJdbcHelper;
import org.hibernate.dialect.OracleJsonJdbcType;
import org.hibernate.dialect.OracleReflectionStructJdbcType;
import org.hibernate.dialect.OracleTypes;
import org.hibernate.dialect.OracleUserDefinedTypeExporter;
import org.hibernate.dialect.OracleXmlJdbcType;
import org.hibernate.dialect.Replacer;
import org.hibernate.dialect.RowLockStrategy;
import org.hibernate.dialect.TimeZoneSupport;
import org.hibernate.dialect.*;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.OracleAggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
Expand Down Expand Up @@ -104,9 +91,10 @@
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType;
import org.hibernate.type.descriptor.jdbc.BlobJdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.OracleJsonBlobJdbcType;
import org.hibernate.type.descriptor.jdbc.NullJdbcType;
import org.hibernate.type.descriptor.jdbc.ObjectNullAsNullTypeJdbcType;
import org.hibernate.type.descriptor.jdbc.OracleJsonArrayBlobJdbcType;
import org.hibernate.type.descriptor.jdbc.OracleJsonBlobJdbcType;
import org.hibernate.type.descriptor.jdbc.SqlTypedJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.descriptor.sql.internal.ArrayDdlTypeImpl;
Expand All @@ -127,6 +115,7 @@
import static org.hibernate.type.SqlTypes.ARRAY;
import static org.hibernate.type.SqlTypes.BIGINT;
import static org.hibernate.type.SqlTypes.BINARY;
import static org.hibernate.type.SqlTypes.BIT;
import static org.hibernate.type.SqlTypes.BOOLEAN;
import static org.hibernate.type.SqlTypes.DATE;
import static org.hibernate.type.SqlTypes.DECIMAL;
Expand All @@ -135,6 +124,7 @@
import static org.hibernate.type.SqlTypes.GEOMETRY;
import static org.hibernate.type.SqlTypes.INTEGER;
import static org.hibernate.type.SqlTypes.JSON;
import static org.hibernate.type.SqlTypes.JSON_ARRAY;
import static org.hibernate.type.SqlTypes.NUMERIC;
import static org.hibernate.type.SqlTypes.NVARCHAR;
import static org.hibernate.type.SqlTypes.REAL;
Expand Down Expand Up @@ -320,6 +310,15 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
functionFactory.arrayTrim_oracle();
functionFactory.arrayFill_oracle();
functionFactory.arrayToString_oracle();

if ( getVersion().isSameOrAfter( 12 ) ) {
functionFactory.jsonValue_oracle();
functionFactory.jsonQuery_oracle();
functionFactory.jsonExists_oracle();
functionFactory.jsonObject_oracle();
functionFactory.jsonArray_oracle();
functionFactory.jsonArrayAgg_oracle();
}
}

@Override
Expand Down Expand Up @@ -658,6 +657,7 @@ private void extractField(StringBuilder pattern, TemporalUnit unit, TemporalUnit
protected String columnType(int sqlTypeCode) {
switch ( sqlTypeCode ) {
case BOOLEAN:
case BIT:
// still, after all these years...
return "number(1,0)";

Expand Down Expand Up @@ -716,9 +716,11 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( GEOMETRY, "MDSYS.SDO_GEOMETRY", this ) );
if ( getVersion().isSameOrAfter( 21 ) ) {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "json", this ) );
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON_ARRAY, "json", this ) );
}
else if ( getVersion().isSameOrAfter( 12 ) ) {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "blob", this ) );
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON_ARRAY, "blob", this ) );
}
}

Expand Down Expand Up @@ -888,9 +890,11 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry

if ( getVersion().isSameOrAfter( 21 ) ) {
typeContributions.contributeJdbcType( OracleJsonJdbcType.INSTANCE );
typeContributions.contributeJdbcType( OracleJsonArrayJdbcType.INSTANCE );
}
else {
typeContributions.contributeJdbcType( OracleJsonBlobJdbcType.INSTANCE );
typeContributions.contributeJdbcType( OracleJsonArrayBlobJdbcType.INSTANCE );
}
}

Expand Down
Loading