HHH-7889 Created SQL ClobTypeDescriptor#STREAM_BINDING_EXTRACTING for Sybase remapping. Reverting back to Lob extraction ignoring useStreamForLobBinding

This commit is contained in:
Brett Meyer 2013-02-19 14:35:59 -05:00
parent 7bf544716a
commit 89619201a3
5 changed files with 110 additions and 248 deletions

View File

@ -26,6 +26,7 @@ package org.hibernate.dialect;
import java.sql.Types;
import org.hibernate.type.descriptor.sql.BlobTypeDescriptor;
import org.hibernate.type.descriptor.sql.ClobTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
@ -48,7 +49,15 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
@Override
protected SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
return sqlCode == Types.BLOB ? BlobTypeDescriptor.PRIMITIVE_ARRAY_BINDING : super.getSqlTypeDescriptorOverride( sqlCode );
switch (sqlCode) {
case Types.BLOB:
return BlobTypeDescriptor.PRIMITIVE_ARRAY_BINDING;
case Types.CLOB:
// Some Sybase drivers cannot support getClob. See HHH-7889
return ClobTypeDescriptor.STREAM_BINDING_EXTRACTING;
default:
return super.getSqlTypeDescriptorOverride( sqlCode );
}
}
@Override

View File

@ -107,11 +107,11 @@ public class ClobTypeDescriptor extends AbstractTypeDescriptor<Clob> {
try {
if ( CharacterStream.class.isAssignableFrom( type ) ) {
if ( ClobImplementer.class.isInstance( value ) ) {
// if the incoming Clob is a wrapper, just pass along its BinaryStream
// if the incoming Clob is a wrapper, just pass along its CharacterStream
return (X) ( (ClobImplementer) value ).getUnderlyingStream();
}
else {
// otherwise we need to build a BinaryStream...
// otherwise we need to build a CharacterStream...
return (X) new CharacterStreamImpl( DataHelper.extractString( value.getCharacterStream() ) );
}
}

View File

@ -31,6 +31,7 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.engine.jdbc.BinaryStream;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
@ -56,11 +57,24 @@ public abstract class BlobTypeDescriptor implements SqlTypeDescriptor {
return true;
}
protected abstract <X> BasicExtractor<X> getBlobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor);
@Override
public <X> BasicExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return getBlobExtractor( javaTypeDescriptor );
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getBlob( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getBlob( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getBlob( name ), options );
}
};
}
protected abstract <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor);
@ -92,35 +106,7 @@ public abstract class BlobTypeDescriptor implements SqlTypeDescriptor {
}
};
}
@Override
public <X> BasicExtractor<X> getBlobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return getBinding( options ).getExtractor( javaTypeDescriptor ).doExtract( rs, name, options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
return getBinding( options ).getExtractor( javaTypeDescriptor ).doExtract( statement, index, options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
return getBinding( options ).getExtractor( javaTypeDescriptor ).doExtract( statement, name, options );
}
};
}
};
private static final BlobTypeDescriptor getBinding( WrapperOptions options ) {
// TODO: STREAM_BINDING causes multiple tests to fail on oracle and
// mssql. The extracted blob is not the same size as what was persisted.
// For now, rely only on BLOB_BINDING. SEe HHH-8018.
// return options.useStreamForLobBinding() ? STREAM_BINDING : BLOB_BINDING;
return BLOB_BINDING;
}
public static final BlobTypeDescriptor PRIMITIVE_ARRAY_BINDING =
new BlobTypeDescriptor() {
@ -134,26 +120,6 @@ public abstract class BlobTypeDescriptor implements SqlTypeDescriptor {
}
};
}
@Override
public <X> BasicExtractor<X> getBlobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getBytes( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getBytes( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getBytes( name ), options );
}
};
}
};
public static final BlobTypeDescriptor BLOB_BINDING =
@ -168,26 +134,6 @@ public abstract class BlobTypeDescriptor implements SqlTypeDescriptor {
}
};
}
@Override
public <X> BasicExtractor<X> getBlobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getBlob( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getBlob( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getBlob( name ), options );
}
};
}
};
public static final BlobTypeDescriptor STREAM_BINDING =
@ -203,28 +149,6 @@ public abstract class BlobTypeDescriptor implements SqlTypeDescriptor {
}
};
}
@Override
public <X> BasicExtractor<X> getBlobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getBinaryStream( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
// TODO: CallableStatement does not have getBinaryStream
return javaTypeDescriptor.wrap( statement.getBytes( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
// TODO: CallableStatement does not have getBinaryStream
return javaTypeDescriptor.wrap( statement.getBytes( name ), options );
}
};
}
};
}

View File

@ -52,13 +52,28 @@ public abstract class ClobTypeDescriptor implements SqlTypeDescriptor {
public boolean canBeRemapped() {
return true;
}
protected abstract <X> BasicExtractor<X> getClobExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
@Override
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
return getClobExtractor( javaTypeDescriptor );
}
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getClob( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getClob( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getClob( name ), options );
}
};
}
protected abstract <X> BasicBinder<X> getClobBinder(JavaTypeDescriptor<X> javaTypeDescriptor);
@ -79,37 +94,16 @@ public abstract class ClobTypeDescriptor implements SqlTypeDescriptor {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
getBinding( options ).getClobBinder( javaTypeDescriptor ).doBind( st, value, index, options );
if ( options.useStreamForLobBinding() ) {
STREAM_BINDING.getClobBinder( javaTypeDescriptor ).doBind( st, value, index, options );
}
else {
CLOB_BINDING.getClobBinder( javaTypeDescriptor ).doBind( st, value, index, options );
}
}
};
}
@Override
public <X> BasicExtractor<X> getClobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return getBinding( options ).getClobExtractor( javaTypeDescriptor ).doExtract( rs, name, options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return getBinding( options ).getClobExtractor( javaTypeDescriptor ).doExtract( statement, index, options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return getBinding( options ).getClobExtractor( javaTypeDescriptor ).doExtract( statement, name, options );
}
};
}
};
private static final ClobTypeDescriptor getBinding( WrapperOptions options ) {
return options.useStreamForLobBinding() ? STREAM_BINDING : CLOB_BINDING;
}
public static final ClobTypeDescriptor CLOB_BINDING =
new ClobTypeDescriptor() {
@ -123,30 +117,6 @@ public abstract class ClobTypeDescriptor implements SqlTypeDescriptor {
}
};
}
@Override
public <X> BasicExtractor<X> getClobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>(javaTypeDescriptor, this) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getClob( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getClob( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getClob( name ), options );
}
};
};
};
public static final ClobTypeDescriptor STREAM_BINDING =
@ -162,15 +132,29 @@ public abstract class ClobTypeDescriptor implements SqlTypeDescriptor {
}
};
}
@Override
public <X> BasicExtractor<X> getClobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>(javaTypeDescriptor, this) {
};
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getCharacterStream( name ), options );
}
public static final ClobTypeDescriptor STREAM_BINDING_EXTRACTING =
new ClobTypeDescriptor() {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
}
};
}
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getCharacterStream( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
@ -183,9 +167,8 @@ public abstract class ClobTypeDescriptor implements SqlTypeDescriptor {
throws SQLException {
return javaTypeDescriptor.wrap( statement.getCharacterStream( name ), options );
}
};
};
};
}
};
}

View File

@ -52,13 +52,28 @@ public abstract class NClobTypeDescriptor implements SqlTypeDescriptor {
public boolean canBeRemapped() {
return true;
}
protected abstract <X> BasicExtractor<X> getNClobExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
@Override
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
return getNClobExtractor( javaTypeDescriptor );
}
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getNClob( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getNClob( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getNClob( name ), options );
}
};
}
protected abstract <X> BasicBinder<X> getNClobBinder(JavaTypeDescriptor<X> javaTypeDescriptor);
@ -79,37 +94,16 @@ public abstract class NClobTypeDescriptor implements SqlTypeDescriptor {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
getBinding( options ).getNClobBinder( javaTypeDescriptor ).doBind( st, value, index, options );
if ( options.useStreamForLobBinding() ) {
STREAM_BINDING.getNClobBinder( javaTypeDescriptor ).doBind( st, value, index, options );
}
else {
NCLOB_BINDING.getNClobBinder( javaTypeDescriptor ).doBind( st, value, index, options );
}
}
};
}
@Override
public <X> BasicExtractor<X> getNClobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return getBinding( options ).getNClobExtractor( javaTypeDescriptor ).doExtract( rs, name, options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return getBinding( options ).getNClobExtractor( javaTypeDescriptor ).doExtract( statement, index, options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return getBinding( options ).getNClobExtractor( javaTypeDescriptor ).doExtract( statement, name, options );
}
};
}
};
private static final NClobTypeDescriptor getBinding( WrapperOptions options ) {
return options.useStreamForLobBinding() ? STREAM_BINDING : NCLOB_BINDING;
}
public static final NClobTypeDescriptor NCLOB_BINDING =
new NClobTypeDescriptor() {
@ -123,30 +117,6 @@ public abstract class NClobTypeDescriptor implements SqlTypeDescriptor {
}
};
}
@Override
public <X> BasicExtractor<X> getNClobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>(javaTypeDescriptor, this) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getNClob( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getNClob( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getNClob( name ), options );
}
};
};
};
public static final NClobTypeDescriptor STREAM_BINDING =
@ -162,29 +132,5 @@ public abstract class NClobTypeDescriptor implements SqlTypeDescriptor {
}
};
}
@Override
public <X> BasicExtractor<X> getNClobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>(javaTypeDescriptor, this) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getCharacterStream( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getCharacterStream( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getCharacterStream( name ), options );
}
};
};
};
}