Skip to content

Commit a87e3ca

Browse files
committed
HHH-17404 Address dialect and aggregate support comments
1 parent a2d6e3a commit a87e3ca

File tree

3 files changed

+39
-61
lines changed

3 files changed

+39
-61
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
991991

992992
@Override
993993
public AggregateSupport getAggregateSupport() {
994-
return OracleAggregateSupport.valueOf( this ,true);
994+
return OracleAggregateSupport.valueOf( this );
995995
}
996996

997997
@Override

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
import static org.hibernate.LockOptions.SKIP_LOCKED;
113113
import static org.hibernate.LockOptions.WAIT_FOREVER;
114114
import static org.hibernate.cfg.DialectSpecificSettings.ORACLE_OSON_DISABLED;
115-
import static org.hibernate.dialect.DialectLogging.DIALECT_MESSAGE_LOGGER;
115+
import static org.hibernate.dialect.DialectLogging.DIALECT_LOGGER;
116116
import static org.hibernate.dialect.OracleJdbcHelper.getArrayJdbcTypeConstructor;
117117
import static org.hibernate.dialect.OracleJdbcHelper.getNestedTableJdbcTypeConstructor;
118118
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
@@ -187,8 +187,6 @@ public class OracleDialect extends Dialect {
187187

188188
private static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 19 );
189189

190-
private boolean osonExtensionEnabled = false;
191-
192190
private final OracleUserDefinedTypeExporter userDefinedTypeExporter = new OracleUserDefinedTypeExporter( this );
193191
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
194192
private final SequenceSupport oracleSequenceSupport = OracleSequenceSupport.getInstance(this);
@@ -1002,16 +1000,12 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
10021000
typeContributions.contributeJdbcType( OracleOsonJacksonJdbcType.INSTANCE );
10031001
typeContributions.contributeJdbcTypeConstructor( OracleOsonArrayJdbcTypeConstructor.INSTANCE );
10041002

1005-
DIALECT_MESSAGE_LOGGER.DIALECT_LOGGER.log( Logger.Level.DEBUG,
1006-
"Oracle OSON Jackson extension used" );
1007-
// as we speak, this is not supported by OSON extension
1008-
osonExtensionEnabled = true;
1003+
DIALECT_LOGGER.log( Logger.Level.DEBUG, "Oracle OSON Jackson extension used" );
10091004
}
10101005
else {
1011-
if (DIALECT_MESSAGE_LOGGER.DIALECT_LOGGER.isDebugEnabled()) {
1012-
DIALECT_MESSAGE_LOGGER.DIALECT_LOGGER.log( Logger.Level.DEBUG,
1013-
"Oracle OSON Jackson extension not used" );
1014-
DIALECT_MESSAGE_LOGGER.DIALECT_LOGGER.log( Logger.Level.DEBUG,
1006+
if (DIALECT_LOGGER.isDebugEnabled()) {
1007+
DIALECT_LOGGER.log( Logger.Level.DEBUG, "Oracle OSON Jackson extension not used" );
1008+
DIALECT_LOGGER.log( Logger.Level.DEBUG,
10151009
"JacksonIntegration.isOracleOsonExtensionAvailable(): " +
10161010
JacksonIntegration.isOracleOsonExtensionAvailable());
10171011
}
@@ -1064,7 +1058,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
10641058

10651059
@Override
10661060
public AggregateSupport getAggregateSupport() {
1067-
return OracleAggregateSupport.valueOf( this ,!osonExtensionEnabled );
1061+
return OracleAggregateSupport.valueOf( this );
10681062
}
10691063

10701064
@Override

hibernate-core/src/main/java/org/hibernate/dialect/aggregate/OracleAggregateSupport.java

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@
4949

5050
public class OracleAggregateSupport extends AggregateSupportImpl {
5151

52-
protected static final AggregateSupport V23_INSTANCE = new OracleAggregateSupport( true, JsonSupport.OSON, true );
52+
protected static final AggregateSupport V23_INSTANCE = new OracleAggregateSupport( true, JsonSupport.OSON );
5353
// Special instance used when an Oracle OSON extension is available and used
54-
protected static final AggregateSupport V23_OSON_EXT_INSTANCE = new OracleAggregateSupport( true, JsonSupport.OSON,false);
55-
protected static final AggregateSupport V21_INSTANCE = new OracleAggregateSupport( false, JsonSupport.OSON, true );
56-
protected static final AggregateSupport V19_INSTANCE = new OracleAggregateSupport( false, JsonSupport.MERGEPATCH , true);
57-
protected static final AggregateSupport V18_INSTANCE = new OracleAggregateSupport( false, JsonSupport.QUERY_AND_PATH, true );
58-
protected static final AggregateSupport V12_INSTANCE = new OracleAggregateSupport( false, JsonSupport.QUERY , true);
59-
protected static final AggregateSupport LEGACY_INSTANCE = new OracleAggregateSupport( false, JsonSupport.NONE , true);
54+
protected static final AggregateSupport V21_INSTANCE = new OracleAggregateSupport( false, JsonSupport.OSON );
55+
protected static final AggregateSupport V19_INSTANCE = new OracleAggregateSupport( false, JsonSupport.MERGEPATCH );
56+
protected static final AggregateSupport V18_INSTANCE = new OracleAggregateSupport( false, JsonSupport.QUERY_AND_PATH );
57+
protected static final AggregateSupport V12_INSTANCE = new OracleAggregateSupport( false, JsonSupport.QUERY );
58+
protected static final AggregateSupport LEGACY_INSTANCE = new OracleAggregateSupport( false, JsonSupport.NONE );
6059

6160
private static final String JSON_QUERY_START = "json_query(";
6261
private static final String JSON_QUERY_JSON_END = "' returning json)";
@@ -70,30 +69,30 @@ public class OracleAggregateSupport extends AggregateSupportImpl {
7069

7170
private final boolean checkConstraintSupport;
7271
private final JsonSupport jsonSupport;
73-
private final boolean dateTypesStoreAsString;
7472

75-
private OracleAggregateSupport(boolean checkConstraintSupport, JsonSupport jsonSupport, boolean dateTypesStoreAsString) {
73+
private OracleAggregateSupport(boolean checkConstraintSupport, JsonSupport jsonSupport) {
7674
this.checkConstraintSupport = checkConstraintSupport;
7775
this.jsonSupport = jsonSupport;
78-
// this flag tell us if data is serialized/de-serialized as String. As opposed to using OSON
79-
// In other words, this flag tells us if the Oracle OSON JDBC extension is used or not.
80-
this.dateTypesStoreAsString = dateTypesStoreAsString;
8176
}
8277

83-
public static AggregateSupport valueOf(Dialect dialect, boolean useDateStoredAsString) {
78+
public static AggregateSupport valueOf(Dialect dialect) {
8479
final DatabaseVersion version = dialect.getVersion();
8580
return switch ( version.getMajor() ) {
8681
case 12, 13, 14, 15, 16, 17 -> V12_INSTANCE;
8782
case 18 -> V18_INSTANCE;
8883
case 19, 20 -> V19_INSTANCE;
8984
case 21, 22 -> V21_INSTANCE;
9085
default -> version.isSameOrAfter( 23 )
91-
? useDateStoredAsString?OracleAggregateSupport.V23_INSTANCE:
92-
OracleAggregateSupport.V23_OSON_EXT_INSTANCE
93-
: OracleAggregateSupport.LEGACY_INSTANCE;
86+
? OracleAggregateSupport.V23_INSTANCE
87+
: OracleAggregateSupport.LEGACY_INSTANCE;
9488
};
9589
}
9690

91+
private boolean supportsOson() {
92+
// OSON is supported when check constraints are supported
93+
return checkConstraintSupport;
94+
}
95+
9796
@Override
9897
public String aggregateComponentCustomReadExpression(
9998
String template,
@@ -147,17 +146,17 @@ public String aggregateComponentCustomReadExpression(
147146
);
148147

149148
case DATE:
150-
if (this.dateTypesStoreAsString) {
149+
if (supportsOson()) {
150+
// Oracle OSON extension is used, value is not stored as string
151151
return template.replace(
152152
placeholder,
153-
"to_date(json_value(" + parentPartExpression + columnExpression + "'),'YYYY-MM-DD')"
153+
"json_value(" + parentPartExpression + columnExpression + "' returning date)"
154154
);
155155
}
156156
else {
157-
// Oracle OSON extension is used, value is not stored as string
158157
return template.replace(
159158
placeholder,
160-
"json_value(" + parentPartExpression + columnExpression + "' returning date)"
159+
"to_date(substr(json_value(" + parentPartExpression + columnExpression + "'),1,10),'YYYY-MM-DD')"
161160
);
162161
}
163162

@@ -167,45 +166,31 @@ public String aggregateComponentCustomReadExpression(
167166
"to_timestamp(json_value(" + parentPartExpression + columnExpression + "'),'hh24:mi:ss')"
168167
);
169168
case TIMESTAMP:
170-
if (this.dateTypesStoreAsString) {
171-
return template.replace(
172-
placeholder,
173-
"to_timestamp(json_value(" + parentPartExpression + columnExpression + "'),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9')"
174-
);
175-
}
176-
else {
177-
178-
return template.replace(
179-
placeholder,
180-
"json_value(" + parentPartExpression + columnExpression + "' returning timestamp)"
181-
);
182-
}
183-
case DURATION:
184-
if (this.dateTypesStoreAsString) {
169+
if (supportsOson()) {
185170
return template.replace(
186171
placeholder,
187-
"cast(json_value(" + parentPartExpression + columnExpression + "') as " + column.getColumnDefinition() + ')'
172+
"json_value(" + parentPartExpression + columnExpression + "' returning timestamp(9))"
188173
);
189174
}
190175
else {
191176
return template.replace(
192177
placeholder,
193-
"json_value(" + parentPartExpression + columnExpression + "' returning interval day to second)"
178+
"to_timestamp(json_value(" + parentPartExpression + columnExpression + "'),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9')"
194179
);
195180
}
196181
case TIMESTAMP_WITH_TIMEZONE:
197182
case TIMESTAMP_UTC:
198-
if (this.dateTypesStoreAsString) {
183+
if (supportsOson()) {
184+
// Oracle OSON extension is used, value is not stored as string
199185
return template.replace(
200186
placeholder,
201-
"to_timestamp_tz(json_value(" + parentPartExpression + columnExpression + "'),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9TZH:TZM')"
187+
"json_value(" + parentPartExpression + columnExpression + "' returning timestamp(9) with time zone)"
202188
);
203189
}
204190
else {
205-
// Oracle OSON extension is used, value is not stored as string
206191
return template.replace(
207192
placeholder,
208-
"json_value(" + parentPartExpression + columnExpression + "')"
193+
"to_timestamp_tz(json_value(" + parentPartExpression + columnExpression + "'),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9TZH:TZM')"
209194
);
210195
}
211196
case UUID:
@@ -236,13 +221,8 @@ public String aggregateComponentCustomReadExpression(
236221
final BasicPluralType<?, ?> pluralType = (BasicPluralType<?, ?>) column.getJdbcMapping();
237222
final OracleArrayJdbcType jdbcType = (OracleArrayJdbcType) pluralType.getJdbcType();
238223
switch ( jdbcType.getElementJdbcType().getDefaultSqlTypeCode() ) {
239-
240-
case DATE:
241-
return template.replace(
242-
placeholder,
243-
"json_value(" + parentPartExpression + columnExpression + "' returning " + column.getColumnDefinition() + ')'
244-
);
245224
case BOOLEAN:
225+
case DATE:
246226
case TIME:
247227
case TIMESTAMP:
248228
case TIMESTAMP_WITH_TIMEZONE:
@@ -251,11 +231,15 @@ public String aggregateComponentCustomReadExpression(
251231
case VARBINARY:
252232
case LONG32VARBINARY:
253233
case UUID:
254-
default:
255234
return template.replace(
256235
placeholder,
257236
jdbcType.getSqlTypeName() + "_from_json(json_query(" + parentPartExpression + columnExpression + "' returning " + jsonTypeName + "))"
258237
);
238+
default:
239+
return template.replace(
240+
placeholder,
241+
"json_value(" + parentPartExpression + columnExpression + "' returning " + column.getColumnDefinition() + ')'
242+
);
259243
}
260244
case JSON:
261245
case JSON_ARRAY:

0 commit comments

Comments
 (0)