Skip to content

Commit 79dd4aa

Browse files
beikovejannett
authored andcommitted
HHH-17404 Address dialect and aggregate support comments
1 parent 0e0c781 commit 79dd4aa

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
@@ -124,9 +124,9 @@
124124
import static org.hibernate.LockOptions.WAIT_FOREVER;
125125
import static org.hibernate.cfg.DialectSpecificSettings.ORACLE_USE_BINARY_FLOATS;
126126
import static org.hibernate.cfg.DialectSpecificSettings.ORACLE_OSON_DISABLED;
127-
import static org.hibernate.dialect.DialectLogging.DIALECT_MESSAGE_LOGGER;
128127
import static org.hibernate.dialect.type.OracleJdbcHelper.getArrayJdbcTypeConstructor;
129128
import static org.hibernate.dialect.type.OracleJdbcHelper.getNestedTableJdbcTypeConstructor;
129+
import static org.hibernate.dialect.DialectLogging.DIALECT_LOGGER;
130130
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
131131
import static org.hibernate.internal.util.JdbcExceptionHelper.extractErrorCode;
132132
import static org.hibernate.internal.util.StringHelper.isEmpty;
@@ -199,8 +199,6 @@ public class OracleDialect extends Dialect {
199199

200200
private static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 19 );
201201

202-
private boolean osonExtensionEnabled = false;
203-
204202
private final OracleUserDefinedTypeExporter userDefinedTypeExporter = new OracleUserDefinedTypeExporter( this );
205203
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
206204
private final SequenceSupport oracleSequenceSupport = OracleSequenceSupport.getInstance(this);
@@ -1023,16 +1021,12 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
10231021
typeContributions.contributeJdbcType( OracleOsonJacksonJdbcType.INSTANCE );
10241022
typeContributions.contributeJdbcTypeConstructor( OracleOsonArrayJdbcTypeConstructor.INSTANCE );
10251023

1026-
DIALECT_MESSAGE_LOGGER.DIALECT_LOGGER.log( Logger.Level.DEBUG,
1027-
"Oracle OSON Jackson extension used" );
1028-
// as we speak, this is not supported by OSON extension
1029-
osonExtensionEnabled = true;
1024+
DIALECT_LOGGER.log( Logger.Level.DEBUG, "Oracle OSON Jackson extension used" );
10301025
}
10311026
else {
1032-
if (DIALECT_MESSAGE_LOGGER.DIALECT_LOGGER.isDebugEnabled()) {
1033-
DIALECT_MESSAGE_LOGGER.DIALECT_LOGGER.log( Logger.Level.DEBUG,
1034-
"Oracle OSON Jackson extension not used" );
1035-
DIALECT_MESSAGE_LOGGER.DIALECT_LOGGER.log( Logger.Level.DEBUG,
1027+
if (DIALECT_LOGGER.isDebugEnabled()) {
1028+
DIALECT_LOGGER.log( Logger.Level.DEBUG, "Oracle OSON Jackson extension not used" );
1029+
DIALECT_LOGGER.log( Logger.Level.DEBUG,
10361030
"JacksonIntegration.isOracleOsonExtensionAvailable(): " +
10371031
JacksonIntegration.isOracleOsonExtensionAvailable());
10381032
}
@@ -1085,7 +1079,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
10851079

10861080
@Override
10871081
public AggregateSupport getAggregateSupport() {
1088-
return OracleAggregateSupport.valueOf( this ,!osonExtensionEnabled );
1082+
return OracleAggregateSupport.valueOf( this );
10891083
}
10901084

10911085
@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)