org.springframework.orm.hibernate3.support
Class BlobSerializableType

java.lang.Object
  extended by org.springframework.orm.hibernate3.support.AbstractLobType
      extended by org.springframework.orm.hibernate3.support.BlobSerializableType

public class BlobSerializableType
extends AbstractLobType

Hibernate UserType implementation for arbitrary objects that get serialized to BLOBs. Retrieves the LobHandler to use from LocalSessionFactoryBean at config time.

Can also be defined in generic Hibernate mappings, as DefaultLobCreator will work with most JDBC-compliant database drivers. In this case, the field type does not have to be BLOB: For databases like MySQL and MS SQL Server, any large enough binary type will work.

Since:
1.2
Author:
Juergen Hoeller
See Also:
LocalSessionFactoryBean.setLobHandler(org.springframework.jdbc.support.lob.LobHandler)

Field Summary
private static int OUTPUT_BYTE_ARRAY_INITIAL_SIZE
          Initial size for ByteArrayOutputStreams used for serialization output.
 
Fields inherited from class org.springframework.orm.hibernate3.support.AbstractLobType
logger
 
Constructor Summary
  BlobSerializableType()
          Constructor used by Hibernate: fetches config-time LobHandler and config-time JTA TransactionManager from LocalSessionFactoryBean.
protected BlobSerializableType(LobHandler lobHandler, TransactionManager jtaTransactionManager)
          Constructor used for testing: takes an explicit LobHandler and an explicit JTA TransactionManager (can be null).
 
Method Summary
 java.lang.Object deepCopy(java.lang.Object value)
          This implementation returns the passed-in value as-is.
 boolean isMutable()
          This implementation returns false.
protected  java.lang.Object nullSafeGetInternal(java.sql.ResultSet rs, java.lang.String[] names, java.lang.Object owner, LobHandler lobHandler)
          Template method to extract a value from the given result set.
protected  void nullSafeSetInternal(java.sql.PreparedStatement ps, int index, java.lang.Object value, LobCreator lobCreator)
          Template method to set the given parameter value on the given statement.
 java.lang.Class returnedClass()
           
 int[] sqlTypes()
           
 
Methods inherited from class org.springframework.orm.hibernate3.support.AbstractLobType
assemble, disassemble, equals, hashCode, nullSafeGet, nullSafeSet, replace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTPUT_BYTE_ARRAY_INITIAL_SIZE

private static final int OUTPUT_BYTE_ARRAY_INITIAL_SIZE
Initial size for ByteArrayOutputStreams used for serialization output.

If a serialized object is larger than these 1024 bytes, the size of the byte array used by the output stream will be doubled each time the limit is reached.

See Also:
Constant Field Values
Constructor Detail

BlobSerializableType

public BlobSerializableType()
Constructor used by Hibernate: fetches config-time LobHandler and config-time JTA TransactionManager from LocalSessionFactoryBean.

See Also:
LocalSessionFactoryBean.getConfigTimeLobHandler(), LocalSessionFactoryBean.getConfigTimeTransactionManager()

BlobSerializableType

protected BlobSerializableType(LobHandler lobHandler,
                               TransactionManager jtaTransactionManager)
Constructor used for testing: takes an explicit LobHandler and an explicit JTA TransactionManager (can be null).

Method Detail

sqlTypes

public int[] sqlTypes()

returnedClass

public java.lang.Class returnedClass()

isMutable

public boolean isMutable()
Description copied from class: AbstractLobType
This implementation returns false.

Overrides:
isMutable in class AbstractLobType

deepCopy

public java.lang.Object deepCopy(java.lang.Object value)
                          throws HibernateException
Description copied from class: AbstractLobType
This implementation returns the passed-in value as-is.

Overrides:
deepCopy in class AbstractLobType
Throws:
HibernateException

nullSafeGetInternal

protected java.lang.Object nullSafeGetInternal(java.sql.ResultSet rs,
                                               java.lang.String[] names,
                                               java.lang.Object owner,
                                               LobHandler lobHandler)
                                        throws java.sql.SQLException,
                                               java.io.IOException,
                                               HibernateException
Description copied from class: AbstractLobType
Template method to extract a value from the given result set.

Specified by:
nullSafeGetInternal in class AbstractLobType
Parameters:
rs - the ResultSet to extract from
names - the column names
owner - the containing entity
lobHandler - the LobHandler to use
Returns:
the extracted value
Throws:
java.sql.SQLException - if thrown by JDBC methods
java.io.IOException - if thrown by streaming methods
HibernateException - in case of any other exceptions

nullSafeSetInternal

protected void nullSafeSetInternal(java.sql.PreparedStatement ps,
                                   int index,
                                   java.lang.Object value,
                                   LobCreator lobCreator)
                            throws java.sql.SQLException,
                                   java.io.IOException
Description copied from class: AbstractLobType
Template method to set the given parameter value on the given statement.

Specified by:
nullSafeSetInternal in class AbstractLobType
Parameters:
ps - the PreparedStatement to set on
index - the statement parameter index
value - the value to set
lobCreator - the LobCreator to use
Throws:
java.sql.SQLException - if thrown by JDBC methods
java.io.IOException - if thrown by streaming methods