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

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


net.sf.hibernate.type
Class PersistentCollectionType

java.lang.Object
  extended bynet.sf.hibernate.type.AbstractType
      extended bynet.sf.hibernate.type.PersistentCollectionType
All Implemented Interfaces:
AssociationType, Serializable, Type
Direct Known Subclasses:
ArrayType, BagType, IdentifierBagType, ListType, MapType, SetType

public abstract class PersistentCollectionType
extends AbstractType
implements AssociationType

A type that handles Hibernate PersistentCollections (including arrays).

Author:
Gavin King
See Also:
Serialized Form

Constructor Summary
PersistentCollectionType(String role)
           
 
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 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.
 Class getAssociatedClass(SessionFactoryImplementor factory)
           
 int getColumnSpan(Mapping session)
          How many columns are used to persist this type.
 Iterator getElementsIterator(Object collection)
           
protected  Type getElementType(SessionFactoryImplementor factory)
           
 ForeignKeyDirection getForeignKeyDirection()
          Get the foreign key directionality of this association
 Joinable getJoinable(SessionFactoryImplementor factory)
          Get the "persister" for this association - a class or collection persister
 String getName()
          Returns the abbreviated name of the type.
 String[] getReferencedColumns(SessionFactoryImplementor factory)
          Get the columns referenced by this association.
 String getRole()
           
 int hashCode()
           
 boolean hasNiceEquals()
          Does this type implement a well-behaved equals() method.
 Object hydrate(ResultSet rs, String[] name, SessionImplementor session, Object owner)
          Retrieve an instance of the mapped class, or the identifier of an entity or collection, from a JDBC resultset.
abstract  PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister)
           
 boolean isArrayType()
           
 boolean isAssociationType()
          Note: return true because this type is castable to AssociationType.
 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 isModified(Object old, Object current, SessionImplementor session)
          Has the parent object been modified, compared to the current database state?
 boolean isMutable()
          Are objects of this type mutable.
 boolean isPersistentCollectionType()
          Is this type a collection type.
 Object nullSafeGet(ResultSet rs, String[] name, 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 session)
          Return the SQL type codes for the columns mapped by this type.
 String toString()
           
 String toString(Object value, SessionFactoryImplementor factory)
          A representation of the value to be embedded in an XML element.
 boolean usePrimaryKeyAsForeignKey()
          Is the foreign key the primary key of the table?
abstract  PersistentCollection wrap(SessionImplementor session, Object collection)
           
 
Methods inherited from class net.sf.hibernate.type.AbstractType
isComponentType, isEntityType, isObjectType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.hibernate.type.Type
getReturnedClass, isComponentType, isEntityType, isObjectType
 

Constructor Detail

PersistentCollectionType

public PersistentCollectionType(String role)
Method Detail

getRole

public String getRole()

isPersistentCollectionType

public boolean isPersistentCollectionType()
Description copied from interface: Type
Is this type a collection type.

Specified by:
isPersistentCollectionType in interface Type
Overrides:
isPersistentCollectionType in class AbstractType

equals

public final boolean equals(Object x,
                            Object y)
Description copied from interface: Type
Compare two instances of the class mapped by this type for persistence "equality", ie. Equality of persistent state.

Specified by:
equals in interface Type
Parameters:
x -
y -
Returns:
boolean

instantiate

public abstract PersistentCollection instantiate(SessionImplementor session,
                                                 CollectionPersister persister)
                                          throws HibernateException
Throws:
HibernateException

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String name,
                          SessionImplementor session,
                          Object owner)
                   throws HibernateException,
                          SQLException
Description copied from interface: Type
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.

Specified by:
nullSafeGet in interface Type
Parameters:
rs -
name - the column name
session -
owner - the parent entity
Returns:
Object
Throws:
SQLException
HibernateException

nullSafeGet

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

Specified by:
nullSafeGet in interface Type
Parameters:
rs -
name - the column names
session -
owner - the parent entity
Returns:
Object
Throws:
HibernateException
SQLException
See Also:
alternative, 2-phase property initialization

nullSafeSet

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

sqlTypes

public int[] sqlTypes(Mapping session)
               throws MappingException
Description copied from interface: Type
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 Type
Returns:
the typecodes
Throws:
MappingException
See Also:
Types

getColumnSpan

public int getColumnSpan(Mapping session)
                  throws MappingException
Description copied from interface: Type
How many columns are used to persist this type.

Specified by:
getColumnSpan in interface Type
Throws:
MappingException

toString

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

Specified by:
toString in interface Type
Parameters:
value -
factory -
Returns:
String
Throws:
HibernateException

fromString

public Object fromString(String xml)
Description copied from interface: Type
Parse the XML representation of an instance.

Specified by:
fromString in interface Type
Parameters:
xml -
Returns:
an instance of the type

deepCopy

public Object deepCopy(Object value)
                throws HibernateException
Description copied from interface: Type
Return a deep copy of the persistent state, stopping at entities and at collections.

Specified by:
deepCopy in interface Type
Parameters:
value - generally a collection element or entity field
Returns:
Object a copy
Throws:
HibernateException

getName

public String getName()
Description copied from interface: Type
Returns the abbreviated name of the type.

Specified by:
getName in interface Type
Returns:
String the Hibernate type name

getElementsIterator

public Iterator getElementsIterator(Object collection)

isMutable

public boolean isMutable()
Description copied from interface: Type
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.)

Specified by:
isMutable in interface Type
Returns:
boolean

disassemble

public Serializable disassemble(Object value,
                                SessionImplementor session)
                         throws HibernateException
Description copied from interface: Type
Return a cacheable "disassembled" representation of the object.

Specified by:
disassemble in interface Type
Overrides:
disassemble in class AbstractType
Throws:
HibernateException

assemble

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

Specified by:
assemble in interface Type
Overrides:
assemble in class AbstractType
Throws:
HibernateException

isDirty

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

Specified by:
isDirty in interface Type
Overrides:
isDirty in class AbstractType
Throws:
HibernateException

hasNiceEquals

public boolean hasNiceEquals()
Description copied from interface: Type
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)

Specified by:
hasNiceEquals in interface Type
See Also:
Object.equals(java.lang.Object), Type.equals(java.lang.Object, java.lang.Object)

wrap

public abstract PersistentCollection wrap(SessionImplementor session,
                                          Object collection)

isAssociationType

public boolean isAssociationType()
Note: return true because this type is castable to AssociationType. Not because all collections are associations.

Specified by:
isAssociationType in interface Type
Overrides:
isAssociationType in class AbstractType

getForeignKeyDirection

public ForeignKeyDirection getForeignKeyDirection()
Description copied from interface: AssociationType
Get the foreign key directionality of this association

Specified by:
getForeignKeyDirection in interface AssociationType

hydrate

public Object hydrate(ResultSet rs,
                      String[] name,
                      SessionImplementor session,
                      Object owner)
               throws HibernateException,
                      SQLException
Description copied from interface: Type
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().

Specified by:
hydrate in interface Type
Overrides:
hydrate in class AbstractType
Throws:
HibernateException
SQLException

resolveIdentifier

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

Specified by:
resolveIdentifier in interface Type
Overrides:
resolveIdentifier in class AbstractType
Throws:
HibernateException

isArrayType

public boolean isArrayType()

usePrimaryKeyAsForeignKey

public boolean usePrimaryKeyAsForeignKey()
Description copied from interface: AssociationType
Is the foreign key the primary key of the table?

Specified by:
usePrimaryKeyAsForeignKey in interface AssociationType

getJoinable

public Joinable getJoinable(SessionFactoryImplementor factory)
                     throws MappingException
Description copied from interface: AssociationType
Get the "persister" for this association - a class or collection persister

Specified by:
getJoinable in interface AssociationType
Throws:
MappingException

getReferencedColumns

public String[] getReferencedColumns(SessionFactoryImplementor factory)
                              throws MappingException
Description copied from interface: AssociationType
Get the columns referenced by this association.

Specified by:
getReferencedColumns in interface AssociationType
Throws:
MappingException

isModified

public boolean isModified(Object old,
                          Object current,
                          SessionImplementor session)
                   throws HibernateException
Description copied from interface: Type
Has the parent object been modified, compared to the current database state?

Specified by:
isModified in interface Type
Overrides:
isModified in class AbstractType
Throws:
HibernateException

getAssociatedClass

public Class getAssociatedClass(SessionFactoryImplementor factory)
                         throws MappingException
Specified by:
getAssociatedClass in interface AssociationType
Throws:
MappingException

equals

public boolean equals(Object object)
Overrides:
equals in class AbstractType

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractType

copy

public Object copy(Object original,
                   Object target,
                   SessionImplementor session,
                   Object owner,
                   Map copiedAlready)
            throws HibernateException
Specified by:
copy in interface Type
Overrides:
copy in class AbstractType
Throws:
HibernateException

getElementType

protected final Type getElementType(SessionFactoryImplementor factory)
                             throws MappingException
Throws:
MappingException

toString

public String toString()