4949
5050public 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