org.hibernate.test.instrument.domain
Class CustomBlobType

java.lang.Object
  extended by org.hibernate.test.instrument.domain.CustomBlobType
All Implemented Interfaces:
UserType

public class CustomBlobType
extends Object
implements UserType

A simple byte[]-based custom type.


Constructor Summary
CustomBlobType()
           
 
Method Summary
 Object assemble(Serializable arg0, Object arg1)
          Reconstruct an object from the cacheable representation.
 Object deepCopy(Object value)
          Return a deep copy of the persistent state, stopping at entities and at collections.
 Serializable disassemble(Object arg0)
          Transform the object into its cacheable representation.
 boolean equals(Object x, Object y)
          Compare two instances of the class mapped by this type for persistence "equality".
 int hashCode(Object arg0)
          Get a hashcode for the instance, consistent with persistence "equality"
 boolean isMutable()
          Are objects of this type mutable?
 Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
          Retrieve an instance of the mapped class from a JDBC resultset.
 void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session)
          Write an instance of the mapped class to a prepared statement.
 Object replace(Object arg0, Object arg1, Object arg2)
          During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging.
 Class returnedClass()
          The class returned by nullSafeGet().
 int[] sqlTypes()
          Return the SQL type codes for the columns mapped by this type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomBlobType

public CustomBlobType()
Method Detail

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String[] names,
                          SessionImplementor session,
                          Object owner)
                   throws SQLException
Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.

Specified by:
nullSafeGet in interface UserType
Parameters:
rs - a JDBC result set
names - the column names
owner - the containing entity @return Object
Throws:
SQLException

nullSafeSet

public void nullSafeSet(PreparedStatement ps,
                        Object value,
                        int index,
                        SessionImplementor session)
                 throws SQLException,
                        HibernateException
Write an instance of the mapped class to a prepared statement. Implementors should handle possibility of null values. A multi-column type should be written to parameters starting from index.

Specified by:
nullSafeSet in interface UserType
Parameters:
ps - a JDBC prepared statement
value - the object to write
index - statement parameter index
Throws:
SQLException
HibernateException

deepCopy

public Object deepCopy(Object value)
Return a deep copy of the persistent state, stopping at entities and at collections. It is not necessary to copy immutable objects, or null values, in which case it is safe to simply return the argument.

Specified by:
deepCopy in interface UserType
Parameters:
value - the object to be cloned, which may be null
Returns:
Object a copy

isMutable

public boolean isMutable()
Are objects of this type mutable?

Specified by:
isMutable in interface UserType
Returns:
boolean

sqlTypes

public int[] sqlTypes()
Return the SQL type codes for the columns mapped by this type. The codes are defined on java.sql.Types.

Specified by:
sqlTypes in interface UserType
Returns:
int[] the typecodes
See Also:
Types

returnedClass

public Class returnedClass()
The class returned by nullSafeGet().

Specified by:
returnedClass in interface UserType
Returns:
Class

equals

public boolean equals(Object x,
                      Object y)
Compare two instances of the class mapped by this type for persistence "equality". Equality of the persistent state.

Specified by:
equals in interface UserType
Returns:
boolean

assemble

public Object assemble(Serializable arg0,
                       Object arg1)
                throws HibernateException
Reconstruct an object from the cacheable representation. At the very least this method should perform a deep copy if the type is mutable. (optional operation)

Specified by:
assemble in interface UserType
Parameters:
arg0 - the object to be cached
arg1 - the owner of the cached object
Returns:
a reconstructed object from the cachable representation
Throws:
HibernateException

disassemble

public Serializable disassemble(Object arg0)
                         throws HibernateException
Transform the object into its cacheable representation. At the very least this method should perform a deep copy if the type is mutable. That may not be enough for some implementations, however; for example, associations must be cached as identifier values. (optional operation)

Specified by:
disassemble in interface UserType
Parameters:
arg0 - the object to be cached
Returns:
a cachable representation of the object
Throws:
HibernateException

hashCode

public int hashCode(Object arg0)
             throws HibernateException
Get a hashcode for the instance, consistent with persistence "equality"

Specified by:
hashCode in interface UserType
Throws:
HibernateException

replace

public Object replace(Object arg0,
                      Object arg1,
                      Object arg2)
               throws HibernateException
During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging. For immutable objects, or null values, it is safe to simply return the first parameter. For mutable objects, it is safe to return a copy of the first parameter. For objects with component values, it might make sense to recursively replace component values.

Specified by:
replace in interface UserType
Parameters:
arg0 - the value from the detached entity being merged
arg1 - the value in the managed entity
Returns:
the value to be merged
Throws:
HibernateException


Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.