FileDocCategorySizeDatePackage
Collection.javaAPI DocHibernate 3.2.514712Tue May 08 22:52:56 BST 2007org.hibernate.mapping

Collection

public abstract class Collection extends Object implements Fetchable, Filterable, Value
Mapping for a collection. Subclasses specialize to particular collection styles.
author
Gavin King

Fields Summary
public static final String
DEFAULT_ELEMENT_COLUMN_NAME
public static final String
DEFAULT_KEY_COLUMN_NAME
private KeyValue
key
private Value
element
private Table
collectionTable
private String
role
private boolean
lazy
private boolean
extraLazy
private boolean
inverse
private boolean
mutable
private boolean
subselectLoadable
private String
cacheConcurrencyStrategy
private String
cacheRegionName
private String
orderBy
private String
where
private String
manyToManyWhere
private String
manyToManyOrderBy
private PersistentClass
owner
private String
referencedPropertyName
private String
nodeName
private String
elementNodeName
private boolean
sorted
private Comparator
comparator
private String
comparatorClassName
private boolean
orphanDelete
private int
batchSize
private org.hibernate.FetchMode
fetchMode
private boolean
embedded
private boolean
optimisticLocked
private Class
collectionPersisterClass
private String
typeName
private Properties
typeParameters
private final Map
filters
private final Map
manyToManyFilters
private final Set
synchronizedTables
private String
customSQLInsert
private boolean
customInsertCallable
private org.hibernate.engine.ExecuteUpdateResultCheckStyle
insertCheckStyle
private String
customSQLUpdate
private boolean
customUpdateCallable
private org.hibernate.engine.ExecuteUpdateResultCheckStyle
updateCheckStyle
private String
customSQLDelete
private boolean
customDeleteCallable
private org.hibernate.engine.ExecuteUpdateResultCheckStyle
deleteCheckStyle
private String
customSQLDeleteAll
private boolean
customDeleteAllCallable
private org.hibernate.engine.ExecuteUpdateResultCheckStyle
deleteAllCheckStyle
private String
loaderName
Constructors Summary
protected Collection(PersistentClass owner)


	   
		this.owner = owner;
	
Methods Summary
public voidaddFilter(java.lang.String name, java.lang.String condition)

		filters.put( name, condition );
	
public voidaddManyToManyFilter(java.lang.String name, java.lang.String condition)

		manyToManyFilters.put( name, condition );
	
private voidcheckColumnDuplication(java.util.Set distinctColumns, java.util.Iterator columns)

		while ( columns.hasNext() ) {
			Selectable s = (Selectable) columns.next();
			if ( !s.isFormula() ) {
				Column col = (Column) s;
				if ( !distinctColumns.add( col.getName() ) ) {
					throw new MappingException( "Repeated column in mapping for collection: "
						+ getRole()
						+ " column: "
						+ col.getName() );
				}
			}
		}
	
private voidcheckColumnDuplication()

		HashSet cols = new HashSet();
		checkColumnDuplication( cols, getKey().getColumnIterator() );
		if ( isIndexed() ) {
			checkColumnDuplication( cols, ( (IndexedCollection) this )
				.getIndex()
				.getColumnIterator() );
		}
		if ( isIdentified() ) {
			checkColumnDuplication( cols, ( (IdentifierCollection) this )
				.getIdentifier()
				.getColumnIterator() );
		}
		if ( !isOneToMany() ) {
			checkColumnDuplication( cols, getElement().getColumnIterator() );
		}
	
public voidcreateAllKeys()

		createForeignKeys();
		if ( !isInverse() ) createPrimaryKey();
	
public voidcreateForeignKey()

	
private voidcreateForeignKeys()

		// if ( !isInverse() ) { // for inverse collections, let the "other end" handle it
		if ( referencedPropertyName == null ) {
			getElement().createForeignKey();
			key.createForeignKeyOfEntity( getOwner().getEntityName() );
		}
		// }
	
abstract voidcreatePrimaryKey()

public intgetBatchSize()

		return batchSize;
	
public java.lang.StringgetCacheConcurrencyStrategy()

		return cacheConcurrencyStrategy;
	
public java.lang.StringgetCacheRegionName()

		return cacheRegionName == null ? role : cacheRegionName;
	
public java.lang.ClassgetCollectionPersisterClass()

		return collectionPersisterClass;
	
public TablegetCollectionTable()

		return collectionTable;
	
public org.hibernate.type.CollectionTypegetCollectionType()

		if ( typeName == null ) {
			return getDefaultCollectionType();
		}
		else {
			return TypeFactory.customCollection( typeName, typeParameters, role, referencedPropertyName, isEmbedded() );
		}
	
public boolean[]getColumnInsertability()

		return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
	
public java.util.IteratorgetColumnIterator()

		return EmptyIterator.INSTANCE;
	
public intgetColumnSpan()

		return 0;
	
public boolean[]getColumnUpdateability()

		return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
	
public java.util.ComparatorgetComparator()

		if ( comparator == null && comparatorClassName != null ) {
			try {
				setComparator( (Comparator) ReflectHelper.classForName( comparatorClassName ).newInstance() );
			}
			catch ( Exception e ) {
				throw new MappingException(
						"Could not instantiate comparator class [" + comparatorClassName
						+ "] for collection " + getRole()  
				);
			}
		}
		return comparator;
	
public java.lang.StringgetComparatorClassName()

		return comparatorClassName;
	
public java.lang.StringgetCustomSQLDelete()

		return customSQLDelete;
	
public java.lang.StringgetCustomSQLDeleteAll()

		return customSQLDeleteAll;
	
public org.hibernate.engine.ExecuteUpdateResultCheckStylegetCustomSQLDeleteAllCheckStyle()

		return deleteAllCheckStyle;
	
public org.hibernate.engine.ExecuteUpdateResultCheckStylegetCustomSQLDeleteCheckStyle()

		return deleteCheckStyle;
	
public java.lang.StringgetCustomSQLInsert()

		return customSQLInsert;
	
public org.hibernate.engine.ExecuteUpdateResultCheckStylegetCustomSQLInsertCheckStyle()

		return insertCheckStyle;
	
public java.lang.StringgetCustomSQLUpdate()

		return customSQLUpdate;
	
public org.hibernate.engine.ExecuteUpdateResultCheckStylegetCustomSQLUpdateCheckStyle()

		return updateCheckStyle;
	
public abstract org.hibernate.type.CollectionTypegetDefaultCollectionType()

public ValuegetElement()

		return element;
	
public java.lang.StringgetElementNodeName()

		return elementNodeName;
	
public org.hibernate.FetchModegetFetchMode()

		return fetchMode;
	
public java.util.MapgetFilterMap()

		return filters;
	
public KeyValuegetKey()

		return key;
	
public java.lang.StringgetLoaderName()

		return loaderName;
	
public java.util.MapgetManyToManyFilterMap()

		return manyToManyFilters;
	
public java.lang.StringgetManyToManyOrdering()

		return manyToManyOrderBy;
	
public java.lang.StringgetManyToManyWhere()

		return manyToManyWhere;
	
public java.lang.StringgetNodeName()

		return nodeName;
	
public java.lang.StringgetOrderBy()

		return orderBy;
	
public PersistentClassgetOwner()

		return owner;
	
public java.lang.StringgetOwnerEntityName()

		return owner.getEntityName();
	
public java.lang.StringgetReferencedPropertyName()

		return referencedPropertyName;
	
public java.lang.StringgetRole()

		return role;
	
public java.util.SetgetSynchronizedTables()

		return synchronizedTables;
	
public TablegetTable()

		return owner.getTable();
	
public org.hibernate.type.TypegetType()

		return getCollectionType();
	
public java.lang.StringgetTypeName()

		return typeName;
	
public java.util.PropertiesgetTypeParameters()

		return typeParameters;
	
public java.lang.StringgetWhere()

		return where;
	
public booleanhasFormula()

		return false;
	
public booleanhasOrder()

		return orderBy!=null || manyToManyOrderBy!=null;
	
public booleanhasOrphanDelete()

		return orphanDelete;
	
public booleanisAlternateUniqueKey()

		return false;
	
public booleanisArray()

		return false;
	
public booleanisCustomDeleteAllCallable()

		return customDeleteAllCallable;
	
public booleanisCustomDeleteCallable()

		return customDeleteCallable;
	
public booleanisCustomInsertCallable()

		return customInsertCallable;
	
public booleanisCustomUpdateCallable()

		return customUpdateCallable;
	
public booleanisEmbedded()

		return embedded;
	
public booleanisExtraLazy()

		return extraLazy;
	
public booleanisIdentified()

		return false;
	
public booleanisIndexed()

		return false;
	
public booleanisInverse()

		return inverse;
	
public booleanisLazy()

		return lazy;
	
public booleanisMap()

		return false;
	
public booleanisMutable()

		return mutable;
	
public booleanisNullable()

		return true;
	
public booleanisOneToMany()

		return element instanceof OneToMany;
	
public booleanisOptimisticLocked()

		return optimisticLocked;
	
public booleanisPrimitiveArray()

		return false;
	
public booleanisSet()

		return false;
	
public booleanisSimpleValue()

		return false;
	
public booleanisSorted()

		return sorted;
	
public booleanisSubselectLoadable()

		return subselectLoadable;
	
public booleanisValid(org.hibernate.engine.Mapping mapping)

		return true;
	
public voidsetBatchSize(int i)

		batchSize = i;
	
public voidsetCacheConcurrencyStrategy(java.lang.String cacheConcurrencyStrategy)

		this.cacheConcurrencyStrategy = cacheConcurrencyStrategy;
	
public voidsetCacheRegionName(java.lang.String cacheRegionName)

		this.cacheRegionName = cacheRegionName;
	
public voidsetCollectionPersisterClass(java.lang.Class persister)

		this.collectionPersisterClass = persister;
	
public voidsetCollectionTable(Table table)

		this.collectionTable = table;
	
public voidsetComparator(java.util.Comparator comparator)

		this.comparator = comparator;
	
public voidsetComparatorClassName(java.lang.String comparatorClassName)

		this.comparatorClassName = comparatorClassName;		
	
public voidsetCustomSQLDelete(java.lang.String customSQLDelete, boolean callable, org.hibernate.engine.ExecuteUpdateResultCheckStyle checkStyle)

		this.customSQLDelete = customSQLDelete;
		this.customDeleteCallable = callable;
		this.deleteCheckStyle = checkStyle;
	
public voidsetCustomSQLDeleteAll(java.lang.String customSQLDeleteAll, boolean callable, org.hibernate.engine.ExecuteUpdateResultCheckStyle checkStyle)

		this.customSQLDeleteAll = customSQLDeleteAll;
		this.customDeleteAllCallable = callable;
		this.deleteAllCheckStyle = checkStyle;
	
public voidsetCustomSQLInsert(java.lang.String customSQLInsert, boolean callable, org.hibernate.engine.ExecuteUpdateResultCheckStyle checkStyle)

		this.customSQLInsert = customSQLInsert;
		this.customInsertCallable = callable;
		this.insertCheckStyle = checkStyle;
	
public voidsetCustomSQLUpdate(java.lang.String customSQLUpdate, boolean callable, org.hibernate.engine.ExecuteUpdateResultCheckStyle checkStyle)

		this.customSQLUpdate = customSQLUpdate;
		this.customUpdateCallable = callable;
		this.updateCheckStyle = checkStyle;
	
public voidsetElement(Value element)

		this.element = element;
	
public voidsetElementNodeName(java.lang.String elementNodeName)

		this.elementNodeName = elementNodeName;
	
public voidsetEmbedded(boolean embedded)

		this.embedded = embedded;
	
public voidsetExtraLazy(boolean extraLazy)

		this.extraLazy = extraLazy;
	
public voidsetFetchMode(org.hibernate.FetchMode fetchMode)

		this.fetchMode = fetchMode;
	
public voidsetInverse(boolean inverse)

		this.inverse = inverse;
	
public voidsetKey(KeyValue key)

		this.key = key;
	
public voidsetLazy(boolean lazy)

		this.lazy = lazy;
	
public voidsetLoaderName(java.lang.String name)

		this.loaderName = name==null ? null : name.intern();
	
public voidsetManyToManyOrdering(java.lang.String orderFragment)

		this.manyToManyOrderBy = orderFragment;
	
public voidsetManyToManyWhere(java.lang.String manyToManyWhere)

		this.manyToManyWhere = manyToManyWhere;
	
public voidsetMutable(boolean mutable)

		this.mutable = mutable;
	
public voidsetNodeName(java.lang.String nodeName)

		this.nodeName = nodeName;
	
public voidsetOptimisticLocked(boolean optimisticLocked)

		this.optimisticLocked = optimisticLocked;
	
public voidsetOrderBy(java.lang.String orderBy)

		this.orderBy = orderBy;
	
public voidsetOrphanDelete(boolean orphanDelete)

		this.orphanDelete = orphanDelete;
	
public voidsetOwner(PersistentClass owner)

		this.owner = owner;
	
public voidsetReferencedPropertyName(java.lang.String propertyRef)

		this.referencedPropertyName = propertyRef==null ? null : propertyRef.intern();
	
public voidsetRole(java.lang.String role)

		this.role = role==null ? null : role.intern();
	
public voidsetSorted(boolean sorted)

		this.sorted = sorted;
	
public voidsetSubselectLoadable(boolean subqueryLoadable)

		this.subselectLoadable = subqueryLoadable;
	
public voidsetTypeName(java.lang.String typeName)

		this.typeName = typeName;
	
public voidsetTypeParameters(java.util.Properties parameterMap)

		this.typeParameters = parameterMap;
	
public voidsetTypeUsingReflection(java.lang.String className, java.lang.String propertyName)

	
public voidsetWhere(java.lang.String where)

		this.where = where;
	
public java.lang.StringtoString()

		return getClass().getName() + '(" + getRole() + ')";
	
public voidvalidate(org.hibernate.engine.Mapping mapping)

		if ( getKey().isCascadeDeleteEnabled() && ( !isInverse() || !isOneToMany() ) ) {
			throw new MappingException(
				"only inverse one-to-many associations may use on-delete=\"cascade\": " 
				+ getRole() );
		}
		if ( !getKey().isValid( mapping ) ) {
			throw new MappingException(
				"collection foreign key mapping has wrong number of columns: "
				+ getRole()
				+ " type: "
				+ getKey().getType().getName() );
		}
		if ( !getElement().isValid( mapping ) ) {
			throw new MappingException( 
				"collection element mapping has wrong number of columns: "
				+ getRole()
				+ " type: "
				+ getElement().getType().getName() );
		}

		checkColumnDuplication();
		
		if ( elementNodeName!=null && elementNodeName.startsWith("@") ) {
			throw new MappingException("element node must not be an attribute: " + elementNodeName );
		}
		if ( elementNodeName!=null && elementNodeName.equals(".") ) {
			throw new MappingException("element node must not be the parent: " + elementNodeName );
		}
		if ( nodeName!=null && nodeName.indexOf('@")>-1 ) {
			throw new MappingException("collection node must not be an attribute: " + elementNodeName );
		}