Skip to content

Commit 44f5020

Browse files
committed
HHH-17404 Apply code-style to OracleOsonJdbcType and misc cleanups
1 parent 52d2618 commit 44f5020

File tree

3 files changed

+77
-75
lines changed

3 files changed

+77
-75
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
132132

133133
private final String uuid = LocalObjectUuidHelper.generateLocalObjectUuid();
134134
private final StandardServiceRegistry serviceRegistry;
135-
private static boolean osonExtensionEnabled;
136135

137136
// integration
138137
private Object beanManagerReference;
@@ -306,10 +305,9 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo
306305
settings.get( AvailableSettings.JAKARTA_VALIDATION_FACTORY )
307306
);
308307

309-
osonExtensionEnabled = !getBoolean( ORACLE_OSON_DISABLED ,settings);
310-
311308
jsonFormatMapper = determineJsonFormatMapper(
312309
settings.get( AvailableSettings.JSON_FORMAT_MAPPER ),
310+
!getBoolean( ORACLE_OSON_DISABLED ,settings),
313311
strategySelector
314312
);
315313

@@ -793,15 +791,16 @@ private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
793791
.getDefaultConnectionHandlingMode();
794792
}
795793

796-
private static FormatMapper determineJsonFormatMapper(Object setting, StrategySelector strategySelector) {
794+
private static FormatMapper determineJsonFormatMapper(Object setting, boolean osonExtensionEnabled, StrategySelector strategySelector) {
797795
return strategySelector.resolveDefaultableStrategy(
798796
FormatMapper.class,
799797
setting,
800798
(Callable<FormatMapper>) () -> {
801799
// Prefer the OSON Jackson FormatMapper by default if available
802-
final FormatMapper jsonJacksonFormatMapper = (osonExtensionEnabled && JacksonIntegration.isJacksonOsonExtensionAvailable())
803-
? getOsonJacksonFormatMapperOrNull()
804-
: getJsonJacksonFormatMapperOrNull();
800+
final FormatMapper jsonJacksonFormatMapper =
801+
(osonExtensionEnabled && JacksonIntegration.isJacksonOsonExtensionAvailable())
802+
? getOsonJacksonFormatMapperOrNull()
803+
: getJsonJacksonFormatMapperOrNull();
805804
return jsonJacksonFormatMapper != null ? jsonJacksonFormatMapper : getJakartaJsonBFormatMapperOrNull();
806805
}
807806
);

hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private static void addJsonFormatMappers(StrategySelectorImpl strategySelector)
313313
JacksonJsonFormatMapper.SHORT_NAME,
314314
JacksonJsonFormatMapper.class
315315
);
316-
if (JacksonIntegration.isJacksonOsonExtensionAvailable() ) {
316+
if ( JacksonIntegration.isJacksonOsonExtensionAvailable() ) {
317317
strategySelector.registerStrategyImplementor(
318318
FormatMapper.class,
319319
JacksonOsonFormatMapper.SHORT_NAME,

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

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.sql.SQLFeatureNotSupportedException;
3535

3636
/**
37-
*
3837
* Type mapping JSON SQL data type for Oracle database.
3938
* This implementation is used when the JDBC OSON extension is available.
4039
*
@@ -67,15 +66,15 @@ public AggregateJdbcType resolveAggregateJdbcType(
6766
@Override
6867
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
6968

70-
if(javaType.getJavaType() == String.class || javaType.getJavaType() == Object.class) {
69+
if ( javaType.getJavaType() == String.class || javaType.getJavaType() == Object.class ) {
7170
return super.getBinder( javaType );
7271
}
7372

7473
return new BasicBinder<>( javaType, this ) {
7574

7675
private <T> byte[] toOson(T value, JavaType<T> javaType, WrapperOptions options) throws Exception {
7776
final ByteArrayOutputStream out = new ByteArrayOutputStream();
78-
if (getEmbeddableMappingType() != null) {
77+
if ( getEmbeddableMappingType() != null ) {
7978
// OracleJsonFactory is used and not OracleOsonFactory as Jackson is not involved here
8079
try (OracleJsonGenerator generator = OSON_JSON_FACTORY.createJsonBinaryGenerator( out )) {
8180
JsonHelper.serialize(
@@ -146,7 +145,7 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions
146145
@Override
147146
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
148147

149-
if(javaType.getJavaType() == String.class || javaType.getJavaType() == Object.class) {
148+
if ( javaType.getJavaType() == String.class || javaType.getJavaType() == Object.class ) {
150149
return super.getExtractor( javaType );
151150
}
152151

@@ -170,16 +169,16 @@ private X fromOson(InputStream osonBytes, WrapperOptions options) throws Excepti
170169

171170
private boolean useUtf8(WrapperOptions options) {
172171
return getEmbeddableMappingType() == null
173-
&& !options.getJsonFormatMapper().supportsSourceType(OracleOsonJacksonHelper.READER_CLASS );
172+
&& !options.getJsonFormatMapper().supportsSourceType( OracleOsonJacksonHelper.READER_CLASS );
174173
}
175174

176-
private X doExtraction(OracleJsonDatum datum, WrapperOptions options) throws SQLException {
175+
private X doExtraction(OracleJsonDatum datum, WrapperOptions options) throws SQLException {
177176
if ( datum == null ) {
178177
return null;
179178
}
180179
InputStream osonBytes = datum.getStream();
181180
try {
182-
return fromOson( osonBytes ,options);
181+
return fromOson( osonBytes, options );
183182
}
184183
catch (Exception e) {
185184
throw new SQLException( e );
@@ -201,107 +200,111 @@ private byte[] getBytesFromResultSetByIndex(ResultSet rs, int index) throws SQLE
201200
// This can be a BLOB or a CLOB. getBytes is not supported on CLOB
202201
// and getString is not supported on BLOB. W have to try both
203202
try {
204-
return rs.getBytes( index);
205-
} catch (SQLFeatureNotSupportedException nse) {
206-
return rs.getString( index).getBytes();
203+
return rs.getBytes( index );
204+
}
205+
catch (SQLFeatureNotSupportedException nse) {
206+
return rs.getString( index ).getBytes();
207207
}
208208
}
209209

210210
private byte[] getBytesFromStatementByIndex(CallableStatement st, int index) throws SQLException {
211211
// This can be a BLOB or a CLOB. getBytes is not supported on CLOB
212212
// and getString is not supported on BLOB. W have to try both
213213
try {
214-
return st.getBytes( index);
215-
} catch (SQLFeatureNotSupportedException nse) {
214+
return st.getBytes( index );
215+
}
216+
catch (SQLFeatureNotSupportedException nse) {
216217

217-
return st.getString( index).getBytes();
218+
return st.getString( index ).getBytes();
218219
}
219220
}
221+
220222
private byte[] getBytesFromStatementByName(CallableStatement st, String columnName) throws SQLException {
221223
// This can be a BLOB or a CLOB. getBytes is not supported on CLOB
222224
// and getString is not supported on BLOB. W have to try both
223225
try {
224-
return st.getBytes( columnName);
225-
} catch (SQLFeatureNotSupportedException nse) {
226-
return st.getString( columnName).getBytes();
226+
return st.getBytes( columnName );
227+
}
228+
catch (SQLFeatureNotSupportedException nse) {
229+
return st.getString( columnName ).getBytes();
227230
}
228231
}
229232

230233
@Override
231234
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
232-
if ( useUtf8( options ) ) {
233-
return fromString(getBytesFromResultSetByIndex(rs, paramIndex), options );
234-
}
235-
else {
236-
try {
235+
if ( useUtf8( options ) ) {
236+
return fromString( getBytesFromResultSetByIndex( rs, paramIndex ), options );
237+
}
238+
else {
239+
try {
237240
OracleJsonDatum ojd = rs.getObject( paramIndex, OracleJsonDatum.class );
238241
return doExtraction( ojd, options );
239-
} catch (SQLException exc) {
240-
if ( exc.getErrorCode() == DatabaseError.JDBC_ERROR_BASE + DatabaseError.EOJ_INVALID_COLUMN_TYPE) {
241-
// This may happen if we are fetching data from an existing schema
242-
// that uses BLOB for JSON column In that case we assume bytes are
243-
// UTF-8 bytes (i.e not OSON) and we fall back to previous String-based implementation
244-
LOG.invalidJSONColumnType( OracleType.BLOB.getName(), OracleType.JSON.getName() );
245-
return fromString(getBytesFromResultSetByIndex(rs, paramIndex), options );
246-
} else {
247-
throw exc;
248-
}
242+
}
243+
catch (SQLException exc) {
244+
if ( exc.getErrorCode() == DatabaseError.JDBC_ERROR_BASE + DatabaseError.EOJ_INVALID_COLUMN_TYPE ) {
245+
// This may happen if we are fetching data from an existing schema
246+
// that uses BLOB for JSON column. In that case we assume bytes are
247+
// UTF-8 bytes (i.e not OSON) and we fall back to previous String-based implementation
248+
LOG.invalidJSONColumnType( OracleType.BLOB.getName(), OracleType.JSON.getName() );
249+
return fromString( getBytesFromResultSetByIndex( rs, paramIndex ), options );
250+
}
251+
else {
252+
throw exc;
249253
}
250254
}
255+
}
251256
}
252257

253258
@Override
254259
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
255-
if ( useUtf8( options ) ) {
256-
return fromString(getBytesFromStatementByIndex(statement, index), options);
257-
}
258-
else {
259-
try {
260+
if ( useUtf8( options ) ) {
261+
return fromString( getBytesFromStatementByIndex( statement, index ), options );
262+
}
263+
else {
264+
try {
260265
OracleJsonDatum ojd = statement.getObject( index, OracleJsonDatum.class );
261266
return doExtraction( ojd, options );
262-
} catch (SQLException exc) {
263-
if ( exc.getErrorCode() == DatabaseError.JDBC_ERROR_BASE + DatabaseError.EOJ_INVALID_COLUMN_TYPE) {
264-
// This may happen if we are fetching data from an existing schema
265-
// that uses BLOB for JSON column In that case we assume bytes are
266-
// UTF-8 bytes (i.e not OSON) and we fall back to previous String-based implementation
267-
LOG.invalidJSONColumnType( OracleType.CLOB.getName(), OracleType.JSON.getName() );
268-
return fromString(getBytesFromStatementByIndex(statement, index), options);
269-
} else {
270-
throw exc;
271-
}
267+
}
268+
catch (SQLException exc) {
269+
if ( exc.getErrorCode() == DatabaseError.JDBC_ERROR_BASE + DatabaseError.EOJ_INVALID_COLUMN_TYPE ) {
270+
// This may happen if we are fetching data from an existing schema
271+
// that uses BLOB for JSON column In that case we assume bytes are
272+
// UTF-8 bytes (i.e not OSON) and we fall back to previous String-based implementation
273+
LOG.invalidJSONColumnType( OracleType.CLOB.getName(), OracleType.JSON.getName() );
274+
return fromString( getBytesFromStatementByIndex( statement, index ), options );
275+
}
276+
else {
277+
throw exc;
272278
}
273279
}
280+
}
274281
}
275282

276283
@Override
277284
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
278285
throws SQLException {
279-
280-
if ( useUtf8( options ) ) {
281-
return fromString(getBytesFromStatementByName(statement, name), options);
282-
}
283-
else {
284-
try {
286+
if ( useUtf8( options ) ) {
287+
return fromString( getBytesFromStatementByName( statement, name ), options );
288+
}
289+
else {
290+
try {
285291
OracleJsonDatum ojd = statement.getObject( name, OracleJsonDatum.class );
286292
return doExtraction( ojd, options );
287-
} catch (SQLException exc) {
288-
if ( exc.getErrorCode() == DatabaseError.JDBC_ERROR_BASE + DatabaseError.EOJ_INVALID_COLUMN_TYPE) {
289-
// This may happen if we are fetching data from an existing schema
290-
// that uses BLOB for JSON column In that case we assume bytes are
291-
// UTF-8 bytes (i.e not OSON) and we fall back to previous String-based implementation
292-
LOG.invalidJSONColumnType( OracleType.CLOB.getName(), OracleType.JSON.getName() );
293-
return fromString(getBytesFromStatementByName(statement, name), options);
294-
} else {
295-
throw exc;
296-
}
293+
}
294+
catch (SQLException exc) {
295+
if ( exc.getErrorCode() == DatabaseError.JDBC_ERROR_BASE + DatabaseError.EOJ_INVALID_COLUMN_TYPE ) {
296+
// This may happen if we are fetching data from an existing schema
297+
// that uses BLOB for JSON column In that case we assume bytes are
298+
// UTF-8 bytes (i.e not OSON) and we fall back to previous String-based implementation
299+
LOG.invalidJSONColumnType( OracleType.CLOB.getName(), OracleType.JSON.getName() );
300+
return fromString( getBytesFromStatementByName( statement, name ), options );
301+
}
302+
else {
303+
throw exc;
297304
}
298305
}
299-
300-
306+
}
301307
}
302-
303308
};
304309
}
305-
306-
307310
}

0 commit comments

Comments
 (0)