站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate 2.1.8 正式版 API 英文文档

UserType (Hibernate API Documentation) - Hibernate 2.1.8 正式版 API 英文文档


net.sf.hibernate
Interface UserType


public interface UserType

This interface should be implemented by user-defined "types". A "type" class is not the actual property type - it is a class that knows how to serialize instances of another class to and from JDBC.

This interface


Implementors must be immutable and must declare a public default constructor.

The actual class mapped by a UserType may be just about anything. However, if it is to be cacheable by JCS, it must be serializable.

CompositeUserType provides an extended version of this interface that is useful for more complex cases.

Alternatively, custom types could implement Type directly or extend one of the abstract classes in net.sf.hibernate.type. This approach risks future incompatible changes to classes or interfaces in that package.

Author:
Gavin King
See Also:
for more complex cases, Type

Method Summary
 Object deepCopy(Object value)
          Return a deep copy of the persistent state, stopping at entities and at collections.
 boolean equals(Object x, Object y)
          Compare two instances of the class mapped by this type for persistence "equality".
 boolean isMutable()
          Are objects of this type mutable?
 Object nullSafeGet(ResultSet rs, String[] names, Object owner)
          Retrieve an instance of the mapped class from a JDBC resultset.
 void nullSafeSet(PreparedStatement st, Object value, int index)
          Write an instance of the mapped class to a prepared statement.
 Class returnedClass()
          The class returned by nullSafeGet().
 int[] sqlTypes()
          Return the SQL type codes for the columns mapped by this type.
 

Method Detail

sqlTypes

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

Returns:
int[] the typecodes
See Also:
Types

returnedClass

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

Returns:
Class

equals

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

Parameters:
x -
y -
Returns:
boolean
Throws:
HibernateException

nullSafeGet

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

Parameters:
rs - a JDBC result set
names - the column names
owner - the containing entity
Returns:
Object
Throws:
HibernateException
SQLException

nullSafeSet

public void nullSafeSet(PreparedStatement st,
                        Object value,
                        int index)
                 throws HibernateException,
                        SQLException
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.

Parameters:
st - a JDBC prepared statement
value - the object to write
index - statement parameter index
Throws:
HibernateException
SQLException

deepCopy

public Object deepCopy(Object value)
                throws HibernateException
Return a deep copy of the persistent state, stopping at entities and at collections.

Returns:
Object a copy
Throws:
HibernateException

isMutable

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

Returns:
boolean