Skip to content

Commit 875e0ca

Browse files
committed
HHH-16933 Stop using syntax sugar JSON item-methods
1 parent 2751cda commit 875e0ca

File tree

1 file changed

+20
-77
lines changed

1 file changed

+20
-77
lines changed

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

Lines changed: 20 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class OracleAggregateSupport extends AggregateSupportImpl {
5353
private static final AggregateSupport V12_INSTANCE = new OracleAggregateSupport( false, JsonSupport.QUERY );
5454
private static final AggregateSupport LEGACY_INSTANCE = new OracleAggregateSupport( false, JsonSupport.NONE );
5555

56+
private static final String JSON_QUERY_START = "json_query(";
57+
private static final String JSON_QUERY_END = "')";
58+
5659
private final boolean checkConstraintSupport;
5760
private final JsonSupport jsonSupport;
5861

@@ -98,82 +101,22 @@ public String aggregateComponentCustomReadExpression(
98101
switch ( jsonSupport ) {
99102
case OSON:
100103
case MERGEPATCH:
101-
switch ( columnType.getTypeCode() ) {
102-
case BOOLEAN:
103-
if ( columnType.getTypeName().toLowerCase( Locale.ROOT ).trim().startsWith( "number" ) ) {
104-
return template.replace(
105-
placeholder,
106-
"decode(" + aggregateParentReadExpression + "." + column + ".boolean(),'true',1,'false',0,null)"
107-
);
108-
}
109-
case TINYINT:
110-
case SMALLINT:
111-
case INTEGER:
112-
case BIGINT:
113-
return template.replace(
114-
placeholder,
115-
"" + aggregateParentReadExpression + "." + column + ".number()"
116-
);
117-
case DATE:
118-
return template.replace(
119-
placeholder,
120-
aggregateParentReadExpression + "." + column + ".date()"
121-
);
122-
case TIME:
123-
case TIME_WITH_TIMEZONE:
124-
case TIME_UTC:
125-
return template.replace(
126-
placeholder,
127-
"to_timestamp(" + aggregateParentReadExpression + "." + column + ".string(),'hh24:mi:ss')"
128-
);
129-
case TIMESTAMP:
130-
return template.replace(
131-
placeholder,
132-
// Don't use .timestamp() directly because that is limited to precision 6
133-
"to_timestamp(" + aggregateParentReadExpression + "." + column + ".string(),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9')"
134-
);
135-
case TIMESTAMP_WITH_TIMEZONE:
136-
case TIMESTAMP_UTC:
137-
return template.replace(
138-
placeholder,
139-
// Don't use .timestamp() directly because that is limited to precision 6
140-
"to_timestamp_tz(" + aggregateParentReadExpression + "." + column + ".string(),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9TZH:TZM')"
141-
);
142-
case BINARY:
143-
case VARBINARY:
144-
case LONG32VARBINARY:
145-
// We encode binary data as hex, so we have to decode here
146-
return template.replace(
147-
placeholder,
148-
"hextoraw(" + aggregateParentReadExpression + "." + column + ".string())"
149-
);
150-
case CLOB:
151-
case NCLOB:
152-
case BLOB:
153-
// We encode binary data as hex, so we have to decode here
154-
return template.replace(
155-
placeholder,
156-
"(select * from json_table(" + aggregateParentReadExpression + ",'$' columns (" + column + " " + columnType.getTypeName() + " path '$." + column + "')))"
157-
);
158-
case JSON:
159-
return template.replace(
160-
placeholder,
161-
aggregateParentReadExpression + "." + column
162-
);
163-
default:
164-
return template.replace(
165-
placeholder,
166-
"cast(" + aggregateParentReadExpression + "." + column + ".string() as " + columnType.getTypeName() + ')'
167-
);
168-
}
169104
case QUERY_AND_PATH:
170105
case QUERY:
106+
final String parentPartExpression;
107+
if ( aggregateParentReadExpression.startsWith( JSON_QUERY_START )
108+
&& aggregateParentReadExpression.endsWith( JSON_QUERY_END ) ) {
109+
parentPartExpression = aggregateParentReadExpression.substring( JSON_QUERY_START.length(), aggregateParentReadExpression.length() - JSON_QUERY_END.length() ) + ".";
110+
}
111+
else {
112+
parentPartExpression = aggregateParentReadExpression + ",'$.";
113+
}
171114
switch ( columnType.getTypeCode() ) {
172115
case BOOLEAN:
173116
if ( columnType.getTypeName().toLowerCase( Locale.ROOT ).trim().startsWith( "number" ) ) {
174117
return template.replace(
175118
placeholder,
176-
"decode(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'true',1,'false',0,null)"
119+
"decode(json_value(" + parentPartExpression + column + "'),'true',1,'false',0,null)"
177120
);
178121
}
179122
case TINYINT:
@@ -182,36 +125,36 @@ public String aggregateComponentCustomReadExpression(
182125
case BIGINT:
183126
return template.replace(
184127
placeholder,
185-
"json_value(" + aggregateParentReadExpression + ",'$." + column + "' returning " + columnType.getTypeName() + ')'
128+
"json_value(" + parentPartExpression + column + "' returning " + columnType.getTypeName() + ')'
186129
);
187130
case DATE:
188131
return template.replace(
189132
placeholder,
190-
"to_date(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'YYYY-MM-DD')"
133+
"to_date(json_value(" + parentPartExpression + column + "'),'YYYY-MM-DD')"
191134
);
192135
case TIME:
193136
return template.replace(
194137
placeholder,
195-
"to_timestamp(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'hh24:mi:ss')"
138+
"to_timestamp(json_value(" + parentPartExpression + column + "'),'hh24:mi:ss')"
196139
);
197140
case TIMESTAMP:
198141
return template.replace(
199142
placeholder,
200-
"to_timestamp(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9')"
143+
"to_timestamp(json_value(" + parentPartExpression + column + "'),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9')"
201144
);
202145
case TIMESTAMP_WITH_TIMEZONE:
203146
case TIMESTAMP_UTC:
204147
return template.replace(
205148
placeholder,
206-
"to_timestamp_tz(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9TZH:TZM')"
149+
"to_timestamp_tz(json_value(" + parentPartExpression + column + "'),'YYYY-MM-DD\"T\"hh24:mi:ss.FF9TZH:TZM')"
207150
);
208151
case BINARY:
209152
case VARBINARY:
210153
case LONG32VARBINARY:
211154
// We encode binary data as hex, so we have to decode here
212155
return template.replace(
213156
placeholder,
214-
"hextoraw(json_value(" + aggregateParentReadExpression + ",'$." + column + "'))"
157+
"hextoraw(json_value(" + parentPartExpression + column + "'))"
215158
);
216159
case CLOB:
217160
case NCLOB:
@@ -224,12 +167,12 @@ public String aggregateComponentCustomReadExpression(
224167
case JSON:
225168
return template.replace(
226169
placeholder,
227-
"json_value(" + aggregateParentReadExpression + ",'$." + column + "')"
170+
"json_query(" + parentPartExpression + column + "')"
228171
);
229172
default:
230173
return template.replace(
231174
placeholder,
232-
"cast(json_value(" + aggregateParentReadExpression + ",'$." + column + "') as " + columnType.getTypeName() + ')'
175+
"cast(json_value(" + parentPartExpression + column + "') as " + columnType.getTypeName() + ')'
233176
);
234177
}
235178
case NONE:

0 commit comments

Comments
 (0)