HHH-7889 Created SQL ClobTypeDescriptor#STREAM_BINDING_EXTRACTING for
Sybase remapping. Reverting back to Lob extraction ignoring useStreamForLobBinding
This commit is contained in:
parent
343a599a4b
commit
b51d9649e2
|
@ -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
|
||||
|
|
|
@ -105,11 +105,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() ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,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;
|
||||
|
||||
|
@ -55,11 +56,14 @@ 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 );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor);
|
||||
|
@ -87,25 +91,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 );
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
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() {
|
||||
|
@ -119,16 +105,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 );
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
public static final BlobTypeDescriptor BLOB_BINDING =
|
||||
|
@ -143,16 +119,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 );
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
public static final BlobTypeDescriptor STREAM_BINDING =
|
||||
|
@ -168,16 +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.getBinaryStream( name ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
package org.hibernate.type.descriptor.sql;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Clob;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -53,11 +52,14 @@ public abstract class ClobTypeDescriptor implements SqlTypeDescriptor {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected abstract <X> BasicExtractor<X> getClobExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
|
||||
|
||||
@Override
|
||||
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return getClobExtractor( 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.getClob( name ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract <X> BasicBinder<X> getClobBinder(JavaTypeDescriptor<X> javaTypeDescriptor);
|
||||
|
@ -75,26 +77,17 @@ 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 );
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
private static final ClobTypeDescriptor getBinding( WrapperOptions options ) {
|
||||
return options.useStreamForLobBinding() ? STREAM_BINDING : CLOB_BINDING;
|
||||
}
|
||||
|
||||
public static final ClobTypeDescriptor CLOB_BINDING =
|
||||
new ClobTypeDescriptor() {
|
||||
@Override
|
||||
|
@ -107,23 +100,26 @@ 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 );
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
public static final ClobTypeDescriptor STREAM_BINDING =
|
||||
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() );
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
|
@ -136,16 +132,14 @@ public abstract class ClobTypeDescriptor implements SqlTypeDescriptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicExtractor<X> getClobExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return new BasicExtractor<X>(javaTypeDescriptor, this) {
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
package org.hibernate.type.descriptor.sql;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.NClob;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -53,11 +52,14 @@ public abstract class NClobTypeDescriptor implements SqlTypeDescriptor {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected abstract <X> BasicExtractor<X> getNClobExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
|
||||
|
||||
@Override
|
||||
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return getNClobExtractor( 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.getNClob( name ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract <X> BasicBinder<X> getNClobBinder(JavaTypeDescriptor<X> javaTypeDescriptor);
|
||||
|
@ -75,26 +77,17 @@ 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 );
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
private static final NClobTypeDescriptor getBinding( WrapperOptions options ) {
|
||||
return options.useStreamForLobBinding() ? STREAM_BINDING : NCLOB_BINDING;
|
||||
}
|
||||
|
||||
public static final NClobTypeDescriptor NCLOB_BINDING =
|
||||
new NClobTypeDescriptor() {
|
||||
@Override
|
||||
|
@ -107,18 +100,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 );
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
public static final NClobTypeDescriptor STREAM_BINDING =
|
||||
|
@ -134,17 +115,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 );
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue