HHH-6972 Support PostgreSQL and Oracle LOBs

This commit is contained in:
brmeyer 2012-09-19 04:22:50 -04:00
parent 518fa90dd7
commit 45f2d91a2a
3 changed files with 12 additions and 35 deletions

View File

@ -155,29 +155,6 @@ public class PostgreSQL81Dialect extends Dialect {
getDefaultProperties().setProperty( Environment.NON_CONTEXTUAL_LOB_CREATION, "true" ); getDefaultProperties().setProperty( Environment.NON_CONTEXTUAL_LOB_CREATION, "true" );
} }
/**
* {@inheritDoc}
*/
@Override
public SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
SqlTypeDescriptor descriptor;
switch ( sqlCode ) {
case Types.BLOB: {
descriptor = BlobTypeDescriptor.BLOB_BINDING;
break;
}
case Types.CLOB: {
descriptor = ClobTypeDescriptor.CLOB_BINDING;
break;
}
default: {
descriptor = super.getSqlTypeDescriptorOverride( sqlCode );
break;
}
}
return descriptor;
}
public String getAddColumnString() { public String getAddColumnString() {
return "add column"; return "add column";
} }

View File

@ -38,6 +38,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
* TODO : javadoc * TODO : javadoc
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Brett meyer
*/ */
public class SerializableTypeDescriptor<T extends Serializable> extends AbstractTypeDescriptor<T> { public class SerializableTypeDescriptor<T extends Serializable> extends AbstractTypeDescriptor<T> {
@ -99,30 +100,27 @@ public class SerializableTypeDescriptor<T extends Serializable> extends Abstract
public <X> X unwrap(T value, Class<X> type, WrapperOptions options) { public <X> X unwrap(T value, Class<X> type, WrapperOptions options) {
if ( value == null ) { if ( value == null ) {
return null; return null;
} } else if ( byte[].class.isAssignableFrom( type ) ) {
if ( byte[].class.isAssignableFrom( type ) ) {
return (X) toBytes( value ); return (X) toBytes( value );
} } else if ( InputStream.class.isAssignableFrom( type ) ) {
if ( InputStream.class.isAssignableFrom( type ) ) {
return (X) new ByteArrayInputStream( toBytes( value ) ); return (X) new ByteArrayInputStream( toBytes( value ) );
} } else if ( BinaryStream.class.isAssignableFrom( type ) ) {
if ( BinaryStream.class.isAssignableFrom( type ) ) {
return (X) new BinaryStreamImpl( toBytes( value ) ); return (X) new BinaryStreamImpl( toBytes( value ) );
} else if ( Blob.class.isAssignableFrom( type )) {
return (X) options.getLobCreator().createBlob( toBytes(value) );
} }
throw unknownUnwrap( type ); throw unknownUnwrap( type );
} }
public <X> T wrap(X value, WrapperOptions options) { public <X> T wrap(X value, WrapperOptions options) {
if ( value == null ) { if ( value == null ) {
return null; return null;
} } else if ( byte[].class.isInstance( value ) ) {
if ( byte[].class.isInstance( value ) ) {
return fromBytes( (byte[]) value ); return fromBytes( (byte[]) value );
} } else if ( InputStream.class.isInstance( value ) ) {
if ( InputStream.class.isInstance( value ) ) {
return fromBytes( DataHelper.extractBytes( (InputStream) value ) ); return fromBytes( DataHelper.extractBytes( (InputStream) value ) );
} } else if ( Blob.class.isInstance( value )) {
if ( Blob.class.isInstance( value )) {
try { try {
return fromBytes( DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() ) ); return fromBytes( DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() ) );
} catch ( SQLException e ) { } catch ( SQLException e ) {

View File

@ -37,6 +37,8 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
* Descriptor for {@link Types#BLOB BLOB} handling. * Descriptor for {@link Types#BLOB BLOB} handling.
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Gail Badner
* @author Brett Meyer
*/ */
public abstract class BlobTypeDescriptor implements SqlTypeDescriptor { public abstract class BlobTypeDescriptor implements SqlTypeDescriptor {