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

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


net.sf.hibernate.type
Interface Type

All Superinterfaces:
Serializable
All Known Subinterfaces:
AbstractComponentType, AssociationType, DiscriminatorType, IdentifierType, VersionType
All Known Implementing Classes:
AbstractType, BooleanType, ByteType, CalendarType, CharacterType, ComponentType, CompositeCustomType, DateType, DynamicComponentType, EntityType, IntegerType, LongType, ObjectType, PersistentCollectionType, ShortType, StringType, TimestampType

public interface Type
extends Serializable

Defines a mapping from a Java type to an JDBC datatype. This interface is intended to be implemented by applications that need custom types.

Implementors should usually be immutable and must certainly be threadsafe. Implementors must override equals().

Author:
Gavin King

Method Summary
 Object assemble(Serializable cached, SessionImplementor session, Object owner)
          Reconstruct the object from its cached "disassembled" state.
 Object copy(Object original, Object target, SessionImplementor session, Object owner, Map copiedAlready)
           
 Object deepCopy(Object value)
          Return a deep copy of the persistent state, stopping at entities and at collections.
 Serializable disassemble(Object value, SessionImplementor session)
          Return a cacheable "disassembled" representation of the object.
 boolean equals(Object x, Object y)
          Compare two instances of the class mapped by this type for persistence "equality", ie.
 Object fromString(String xml)
          Parse the XML representation of an instance.
 int getColumnSpan(Mapping mapping)
          How many columns are used to persist this type.
 String getName()
          Returns the abbreviated name of the type.
 Class getReturnedClass()
          The class returned by nullSafeGet() methods.
 boolean hasNiceEquals()
          Deprecated. we are not using this anymore
 Object hydrate(ResultSet rs, String[] names, SessionImplementor session, Object owner)
          Retrieve an instance of the mapped class, or the identifier of an entity or collection, from a JDBC resultset.
 boolean isAssociationType()
          Return true if the implementation is castable to AssociationType.
 boolean isComponentType()
          Is this type a component type.
 boolean isDirty(Object old, Object current, SessionImplementor session)
          Should the parent be considered dirty, given both the old and current field or element value?
 boolean isEntityType()
          Is this type an entity type?
 boolean isModified(Object oldHydratedState, Object currentState, SessionImplementor session)
          Has the parent object been modified, compared to the current database state?
 boolean isMutable()
          Are objects of this type mutable.
 boolean isObjectType()
          Is this an "object" type.
 boolean isPersistentCollectionType()
          Is this type a collection type.
 Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
          Retrieve an instance of the mapped class from a JDBC resultset.
 Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
          Retrieve an instance of the mapped class from a JDBC resultset.
 void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
          Write an instance of the mapped class to a prepared statement.
 Object resolveIdentifier(Object value, SessionImplementor session, Object owner)
          Map identifiers to entities or collections.
 int[] sqlTypes(Mapping mapping)
          Return the SQL type codes for the columns mapped by this type.
 String toString(Object value, SessionFactoryImplementor factory)
          A representation of the value to be embedded in an XML element.
 

Method Detail

isAssociationType

public boolean isAssociationType()
Return true if the implementation is castable to AssociationType. This does not necessarily imply that the type actually represents an association.

Returns:
boolean
See Also:
AssociationType

isPersistentCollectionType

public boolean isPersistentCollectionType()
Is this type a collection type.


isComponentType

public boolean isComponentType()
Is this type a component type. If so, the implementation must be castable to AbstractComponentType. A component type may own collections or associations and hence must provide certain extra functionality.

Returns:
boolean
See Also:
AbstractComponentType

isEntityType

public boolean isEntityType()
Is this type an entity type?

Returns:
boolean

isObjectType

public boolean isObjectType()
Is this an "object" type. I.e. a reference to a persistent entity that is not modelled as a (foreign key) association.


sqlTypes

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

Returns:
the typecodes
Throws:
MappingException
See Also:
Types

getColumnSpan

public int getColumnSpan(Mapping mapping)
                  throws MappingException
How many columns are used to persist this type.

Throws:
MappingException

getReturnedClass

public Class getReturnedClass()
The class returned by nullSafeGet() methods. This is used to establish the class of an array of this type.

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", ie. Equality of persistent state.

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

isDirty

public boolean isDirty(Object old,
                       Object current,
                       SessionImplementor session)
                throws HibernateException
Should the parent be considered dirty, given both the old and current field or element value?

Parameters:
old - the old value
current - the current value
session -
Returns:
true if the field is dirty
Throws:
HibernateException

isModified

public boolean isModified(Object oldHydratedState,
                          Object currentState,
                          SessionImplementor session)
                   throws HibernateException
Has the parent object been modified, compared to the current database state?

Parameters:
oldHydratedState - the database state, in a "hydrated" form, with identifiers unresolved
currentState - the current state of the object
session -
Returns:
true if the field has been modified
Throws:
HibernateException

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String[] names,
                          SessionImplementor session,
                          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 -
names - the column names
session -
owner - the parent entity
Returns:
Object
Throws:
HibernateException
SQLException
See Also:
alternative, 2-phase property initialization

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String name,
                          SessionImplementor session,
                          Object owner)
                   throws HibernateException,
                          SQLException
Retrieve an instance of the mapped class from a JDBC resultset. Implementations should handle possibility of null values. This method might be called if the type is known to be a single-column type.

Parameters:
rs -
name - the column name
session -
owner - the parent entity
Returns:
Object
Throws:
HibernateException
SQLException

nullSafeSet

public void nullSafeSet(PreparedStatement st,
                        Object value,
                        int index,
                        SessionImplementor session)
                 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 -
value - the object to write
index - statement parameter index
session -
Throws:
HibernateException
SQLException

toString

public String toString(Object value,
                       SessionFactoryImplementor factory)
                throws HibernateException
A representation of the value to be embedded in an XML element.

Parameters:
value -
factory -
Returns:
String
Throws:
HibernateException

fromString

public Object fromString(String xml)
                  throws HibernateException
Parse the XML representation of an instance.

Parameters:
xml -
Returns:
an instance of the type
Throws:
HibernateException

getName

public String getName()
Returns the abbreviated name of the type.

Returns:
String the Hibernate type name

deepCopy

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

Parameters:
value - generally a collection element or entity field
Returns:
Object a copy
Throws:
HibernateException

isMutable

public boolean isMutable()
Are objects of this type mutable. (With respect to the referencing object ... entities and collections are considered immutable because they manage their own internal state.)

Returns:
boolean

disassemble

public Serializable disassemble(Object value,
                                SessionImplementor session)
                         throws HibernateException
Return a cacheable "disassembled" representation of the object.

Parameters:
value - the value to cache
session - the session
Returns:
the disassembled, deep cloned state
Throws:
HibernateException

assemble

public Object assemble(Serializable cached,
                       SessionImplementor session,
                       Object owner)
                throws HibernateException
Reconstruct the object from its cached "disassembled" state.

Parameters:
cached - the disassembled state from the cache
session - the session
owner - the parent entity object
Returns:
the the object
Throws:
HibernateException

hasNiceEquals

public boolean hasNiceEquals()
Deprecated. we are not using this anymore

Does this type implement a well-behaved equals() method. (ie. one that is consistent with Type.equals().) Strictly, if this method returns true then x.equals(y) implies Type.equals(x, y) and also Type.equals(x, y) implies that probably x.equals(y)

See Also:
Object.equals(java.lang.Object), equals(java.lang.Object, java.lang.Object)

hydrate

public Object hydrate(ResultSet rs,
                      String[] names,
                      SessionImplementor session,
                      Object owner)
               throws HibernateException,
                      SQLException
Retrieve an instance of the mapped class, or the identifier of an entity or collection, from a JDBC resultset. This is useful for 2-phase property initialization - the second phase is a call to resolveIdentifier().

Parameters:
rs -
names - the column names
session - the session
owner - the parent entity
Returns:
Object an identifier or actual value
Throws:
HibernateException
SQLException
See Also:
resolveIdentifier(Object, SessionImplementor, Object)

resolveIdentifier

public Object resolveIdentifier(Object value,
                                SessionImplementor session,
                                Object owner)
                         throws HibernateException
Map identifiers to entities or collections. This is the second phase of 2-phase property initialization.

Parameters:
value - an identifier or value returned by hydrate()
owner - the parent entity
session - the session
Returns:
the given value, or the value associated with the identifier
Throws:
HibernateException
See Also:
hydrate(ResultSet, String[], SessionImplementor, Object)

copy

public Object copy(Object original,
                   Object target,
                   SessionImplementor session,
                   Object owner,
                   Map copiedAlready)
            throws HibernateException
Throws:
HibernateException