Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-18020 Align behavior of ClobJdbcType with BlobJdbcType #8260

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -876,12 +876,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
// Therefore here we overwrite the sql type descriptors to
// use the non-N variants which are supported.
jdbcTypeRegistry.addDescriptor( Types.NCHAR, CharJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor(
Types.NCLOB,
useInputStreamToInsertBlob()
? ClobJdbcType.STREAM_BINDING
: ClobJdbcType.CLOB_BINDING
);
jdbcTypeRegistry.addDescriptor( Types.NCLOB, ClobJdbcType.STREAM_BINDING );
jdbcTypeRegistry.addDescriptor( Types.NVARCHAR, VarcharJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ public void setBootstrapContext(BootstrapContext bootstrapContext) {

private static TimeZoneStorageType resolveTimeZoneStorageStrategy(
ConfigurationService configService) {
return configService.getSetting(
return configService.getSetting(
AvailableSettings.TIMEZONE_DEFAULT_STORAGE,
value -> TimeZoneStorageType.valueOf( value.toString() ),
TimeZoneStorageType.DEFAULT
Expand All @@ -1017,7 +1017,7 @@ private static WrapperArrayHandling resolveWrapperArrayHandling(
WRAPPER_ARRAY_HANDLING,
WrapperArrayHandling::interpretExternalSettingLeniently
),
() -> resolveFallbackWrapperArrayHandling( configService, serviceRegistry )
() -> resolveFallbackWrapperArrayHandling( configService )
);

if ( setting == WrapperArrayHandling.PICK ) {
Expand All @@ -1035,9 +1035,8 @@ private static WrapperArrayHandling resolveWrapperArrayHandling(
};

private static WrapperArrayHandling resolveFallbackWrapperArrayHandling(
ConfigurationService configService,
StandardServiceRegistry serviceRegistry) {
if ( configService.getSetting( JPA_COMPLIANCE, BOOLEAN ) == Boolean.TRUE ) {
ConfigurationService configService) {
if ( configService.getSetting( JPA_COMPLIANCE, BOOLEAN, false ) ) {
// JPA compliance was enabled. Use PICK
return WrapperArrayHandling.PICK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@

import jakarta.persistence.TemporalType;

import static org.hibernate.dialect.HANAServerConfiguration.MAX_LOB_PREFETCH_SIZE_DEFAULT_VALUE;
import static org.hibernate.query.sqm.produce.function.FunctionParameterType.ANY;
import static org.hibernate.type.SqlTypes.BINARY;
import static org.hibernate.type.SqlTypes.BOOLEAN;
Expand Down Expand Up @@ -1763,7 +1764,7 @@ private X extract(NClob nclob, WrapperOptions options) throws SQLException {
if ( nclob == null ) {
return null;
}
if ( nclob.length() < HANANClobJdbcType.this.maxLobPrefetchSize ) {
if ( nclob.length() < maxLobPrefetchSize ) {
X retVal = javaType.wrap(nclob, options);
nclob.free();
return retVal;
Expand All @@ -1790,14 +1791,14 @@ protected X doExtract(CallableStatement statement, String name, WrapperOptions o
}

public int getMaxLobPrefetchSize() {
return this.maxLobPrefetchSize;
return maxLobPrefetchSize;
}
}

public static class HANABlobType implements JdbcType {

private static final long serialVersionUID = 5874441715643764323L;
public static final JdbcType INSTANCE = new HANABlobType( HANAServerConfiguration.MAX_LOB_PREFETCH_SIZE_DEFAULT_VALUE );
public static final JdbcType INSTANCE = new HANABlobType( MAX_LOB_PREFETCH_SIZE_DEFAULT_VALUE );

final int maxLobPrefetchSize;

Expand All @@ -1815,7 +1816,7 @@ public int getJdbcTypeCode() {

@Override
public String getFriendlyName() {
return "BLOB (hana)";
return "BLOB (HANA)";
}

@Override
Expand All @@ -1830,7 +1831,7 @@ private X extract(Blob blob, WrapperOptions options) throws SQLException {
if ( blob == null ) {
return null;
}
if (blob.length() < HANABlobType.this.maxLobPrefetchSize ) {
if ( blob.length() < maxLobPrefetchSize ) {
X retVal = javaType.wrap(blob, options);
blob.free();
return retVal;
Expand Down Expand Up @@ -1868,7 +1869,7 @@ protected void doBind(PreparedStatement st, X value, int index, WrapperOptions o
descriptor = BlobJdbcType.PRIMITIVE_ARRAY_BINDING;
}
else if ( options.useStreamForLobBinding() ) {
descriptor = HANABlobType.this.hanaStreamBlobTypeDescriptor;
descriptor = hanaStreamBlobTypeDescriptor;
}
descriptor.getBinder( javaType ).bind( st, value, index, options );
}
Expand All @@ -1881,15 +1882,15 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions
descriptor = BlobJdbcType.PRIMITIVE_ARRAY_BINDING;
}
else if ( options.useStreamForLobBinding() ) {
descriptor = HANABlobType.this.hanaStreamBlobTypeDescriptor;
descriptor = hanaStreamBlobTypeDescriptor;
}
descriptor.getBinder( javaType ).bind( st, value, name, options );
}
};
}

public int getMaxLobPrefetchSize() {
return this.maxLobPrefetchSize;
return maxLobPrefetchSize;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,12 +958,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
// Therefore here we overwrite the sql type descriptors to
// use the non-N variants which are supported.
jdbcTypeRegistry.addDescriptor( Types.NCHAR, CharJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor(
Types.NCLOB,
useInputStreamToInsertBlob()
? ClobJdbcType.STREAM_BINDING
: ClobJdbcType.CLOB_BINDING
);
jdbcTypeRegistry.addDescriptor( Types.NCLOB, ClobJdbcType.STREAM_BINDING );
jdbcTypeRegistry.addDescriptor( Types.NVARCHAR, VarcharJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcType.INSTANCE );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1688,13 +1688,6 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
jdbcTypeRegistry.addDescriptor( NClobJdbcType.DEFAULT );
}

if ( useInputStreamToInsertBlob() ) {
jdbcTypeRegistry.addDescriptor(
Types.CLOB,
ClobJdbcType.STREAM_BINDING
);
}

if ( getTimeZoneSupport() == TimeZoneSupport.NATIVE ) {
jdbcTypeRegistry.addDescriptor( TimestampUtcAsOffsetDateTimeJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( TimeUtcAsOffsetTimeJdbcType.INSTANCE );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,17 +895,9 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry

// account for Oracle's deprecated support for LONGVARBINARY
// prefer BLOB, unless the user explicitly opts out
boolean preferLong = serviceRegistry.requireService( ConfigurationService.class ).getSetting(
PREFER_LONG_RAW,
StandardConverters.BOOLEAN,
false
);

BlobJdbcType descriptor = preferLong ?
BlobJdbcType.PRIMITIVE_ARRAY_BINDING :
BlobJdbcType.DEFAULT;

typeContributions.contributeJdbcType( descriptor );
final boolean preferLong = serviceRegistry.requireService( ConfigurationService.class )
.getSetting( PREFER_LONG_RAW, StandardConverters.BOOLEAN, false );
typeContributions.contributeJdbcType( preferLong ? BlobJdbcType.PRIMITIVE_ARRAY_BINDING : BlobJdbcType.DEFAULT );

if ( getVersion().isSameOrAfter( 21 ) ) {
typeContributions.contributeJdbcType( OracleJsonJdbcType.INSTANCE );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.TemporalUnit;
import org.hibernate.query.sqm.function.FunctionRenderer;
import org.hibernate.query.sqm.function.FunctionRenderingSupport;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
import org.hibernate.query.sqm.produce.function.ArgumentsValidator;
import org.hibernate.query.sqm.tree.SqmTypedNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor;
import org.hibernate.query.sqm.function.FunctionRenderer;
import org.hibernate.query.sqm.function.FunctionRenderingSupport;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator;
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

/**
* Resolve according to JPA spec 4.8.5
*
* <p>
* {@code SUM} returns:
* <ul>
* <li>{@code Long} when applied to state fields of integral types (other than {@code BigInteger});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.hibernate.query.ReturnableType;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.function.FunctionRenderer;
import org.hibernate.query.sqm.function.FunctionRenderingSupport;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*/
public class TrimFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
private final Dialect dialect;
private SqlAstNodeRenderingMode argumentRenderingMode;
private final SqlAstNodeRenderingMode argumentRenderingMode;

public TrimFunction(Dialect dialect, TypeConfiguration typeConfiguration) {
this( dialect, typeConfiguration, SqlAstNodeRenderingMode.DEFAULT );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,32 @@ public Class<?> getPreferredJavaTypeClass(WrapperOptions options) {
return byte[].class;
}

private BlobJdbcType getDescriptor(Object value, WrapperOptions options) {
if ( value instanceof byte[] ) {
// performance shortcut for binding BLOB data in byte[] format
return PRIMITIVE_ARRAY_BINDING;
}
else if ( options.useStreamForLobBinding() ) {
return STREAM_BINDING;
}
else {
return BLOB_BINDING;
}
}

@Override
public <X> BasicBinder<X> getBlobBinder(final JavaType<X> javaType) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
BlobJdbcType descriptor = BLOB_BINDING;
if ( value instanceof byte[] ) {
// performance shortcut for binding BLOB data in byte[] format
descriptor = PRIMITIVE_ARRAY_BINDING;
}
else if ( options.useStreamForLobBinding() ) {
descriptor = STREAM_BINDING;
}
descriptor.getBlobBinder( javaType ).doBind( st, value, index, options );
getDescriptor( value, options ).getBlobBinder( javaType ).doBind( st, value, index, options );
}

@Override
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
throws SQLException {
BlobJdbcType descriptor = BLOB_BINDING;
if ( value instanceof byte[] ) {
// performance shortcut for binding BLOB data in byte[] format
descriptor = PRIMITIVE_ARRAY_BINDING;
}
else if ( options.useStreamForLobBinding() ) {
descriptor = STREAM_BINDING;
}
descriptor.getBlobBinder( javaType ).doBind( st, value, name, options );
getDescriptor( value, options ).getBlobBinder( javaType ).doBind( st, value, name, options );
}
};
}
Expand Down Expand Up @@ -202,22 +199,14 @@ public <X> BasicBinder<X> getBlobBinder(final JavaType<X> javaType) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
final BinaryStream binaryStream = javaType.unwrap(
value,
BinaryStream.class,
options
);
final BinaryStream binaryStream = javaType.unwrap( value, BinaryStream.class, options );
st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() );
}

@Override
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
throws SQLException {
final BinaryStream binaryStream = javaType.unwrap(
value,
BinaryStream.class,
options
);
final BinaryStream binaryStream = javaType.unwrap( value, BinaryStream.class, options );
st.setBinaryStream( name, binaryStream.getInputStream(), binaryStream.getLength() );
}
};
Expand Down