org.hibernate.type

Class CustomCollectionType

Implemented Interfaces:
AssociationType, Serializable, Type

public class CustomCollectionType
extends CollectionType

A custom type for mapping user-written classes that implement PersistentCollection
Author:
Gavin King
See Also:
PersistentCollection, UserCollectionType

Field Summary

Fields inherited from class org.hibernate.type.CollectionType

UNFETCHED_COLLECTION

Constructor Summary

CustomCollectionType(Class userTypeClass, String role, String foreignKeyPropertyName, boolean isEmbeddedInXML)

Method Summary

boolean
contains(Object collection, Object entity, SessionImplementor session)
Iterator
getElementsIterator(Object collection)
Get an iterator over the element set of the collection in POJO mode
Class
getReturnedClass()
The class returned by nullSafeGet() methods.
UserCollectionType
getUserType()
Object
indexOf(Object collection, Object entity)
Object
instantiate(int anticipatedType)
Instantiate an empty instance of the "underlying" collection (not a wrapper), but with the given anticipated size (i.e.
PersistentCollection
instantiate(SessionImplementor session, CollectionPersister persister, Serializable key)
Instantiate an uninitialized collection wrapper or holder.
protected String
renderLoggableString(Object value, SessionFactoryImplementor factory)
Object
replaceElements(Object original, Object target, Object owner, Map copyCache, SessionImplementor session)
Replace the elements of a collection with the elements of another collection.
PersistentCollection
wrap(SessionImplementor session, Object collection)
Wrap the naked collection instance in a wrapper, or instantiate a holder.

Methods inherited from class org.hibernate.type.CollectionType

assemble, compare, contains, deepCopy, disassemble, fromXMLNode, getAssociatedEntityName, getAssociatedJoinable, getCollection, getColumnSpan, getElementType, getElementsIterator, getElementsIterator, getForeignKeyDirection, getHashCode, getIdOfOwnerOrNull, getKeyOfOwner, getLHSPropertyName, getName, getOnCondition, getRHSUniqueKeyPropertyName, getRole, hasHolder, hydrate, indexOf, initializeImmediately, instantiate, instantiate, instantiateResult, isAlwaysDirtyChecked, isArrayType, isAssociationType, isCollectionType, isDirty, isDirty, isEmbeddedInXML, isEqual, isModified, isMutable, isXMLElement, nullSafeGet, nullSafeGet, nullSafeSet, nullSafeSet, renderLoggableString, replace, replaceElements, resolve, semiResolve, setToXMLNode, sqlTypes, toColumnNullness, toLoggableString, toString, useLHSPrimaryKey, wrap

Methods inherited from class org.hibernate.type.AbstractType

assemble, beforeAssemble, compare, disassemble, getHashCode, getHashCode, getSemiResolvedType, hydrate, isAnyType, isAssociationType, isCollectionType, isComponentType, isDirty, isEntityType, isEqual, isEqual, isModified, isSame, isXMLElement, replace, replaceNode, resolve, semiResolve

Constructor Details

CustomCollectionType

public CustomCollectionType(Class userTypeClass,
                            String role,
                            String foreignKeyPropertyName,
                            boolean isEmbeddedInXML)

Method Details

contains

public boolean contains(Object collection,
                        Object entity,
                        SessionImplementor session)
Overrides:
contains in interface CollectionType

getElementsIterator

public Iterator getElementsIterator(Object collection)
Get an iterator over the element set of the collection in POJO mode
Overrides:
getElementsIterator in interface CollectionType
Parameters:
collection - The collection to be iterated
Returns:
The iterator.

getReturnedClass

public Class getReturnedClass()
The class returned by nullSafeGet() methods. This is used to establish the class of an array of this type.
Specified by:
getReturnedClass in interface Type
Returns:
Class

getUserType

public UserCollectionType getUserType()

indexOf

public Object indexOf(Object collection,
                      Object entity)
Overrides:
indexOf in interface CollectionType

instantiate

public Object instantiate(int anticipatedType)
Instantiate an empty instance of the "underlying" collection (not a wrapper), but with the given anticipated size (i.e. accounting for initial capacity and perhaps load factor).
Overrides:
instantiate in interface CollectionType
Parameters:
Returns:
A newly instantiated collection to be wrapped.

instantiate

public PersistentCollection instantiate(SessionImplementor session,
                                        CollectionPersister persister,
                                        Serializable key)
            throws HibernateException
Instantiate an uninitialized collection wrapper or holder. Callers MUST add the holder to the persistence context!
Overrides:
instantiate in interface CollectionType
Parameters:
session - The session from which the request is originating.
persister - The underlying collection persister (metadata)
key - The owner key.
Returns:
The instantiated collection.

renderLoggableString

protected String renderLoggableString(Object value,
                                      SessionFactoryImplementor factory)
            throws HibernateException
Overrides:
renderLoggableString in interface CollectionType

replaceElements

public Object replaceElements(Object original,
                              Object target,
                              Object owner,
                              Map copyCache,
                              SessionImplementor session)
            throws HibernateException
Replace the elements of a collection with the elements of another collection.
Overrides:
replaceElements in interface CollectionType
Parameters:
original - The 'source' of the replacement elements (where we copy from)
target - The target of the replacement elements (where we copy to)
owner - The owner of the collection being merged
copyCache - The map of elements already replaced.
session - The session from which the merge event originated.
Returns:
The merged collection.

wrap

public PersistentCollection wrap(SessionImplementor session,
                                 Object collection)
Wrap the naked collection instance in a wrapper, or instantiate a holder. Callers MUST add the holder to the persistence context!
Overrides:
wrap in interface CollectionType
Parameters:
session - The session from which the request is originating.
collection - The bare collection to be wrapped.
Returns:
The wrapped collection.