FileDocCategorySizeDatePackage
IndexedCollection.javaAPI DocHibernate 3.2.52341Sun Feb 20 01:37:56 GMT 2005org.hibernate.mapping

IndexedCollection

public abstract class IndexedCollection extends Collection
Indexed collections include Lists, Maps, arrays and primitive arrays.
author
Gavin King

Fields Summary
public static final String
DEFAULT_INDEX_COLUMN_NAME
private Value
index
private String
indexNodeName
Constructors Summary
public IndexedCollection(PersistentClass owner)


	   
		super(owner);
	
Methods Summary
voidcreatePrimaryKey()

		if ( !isOneToMany() ) {
			PrimaryKey pk = new PrimaryKey();
			pk.addColumns( getKey().getColumnIterator() );
			
			// index should be last column listed
			boolean isFormula = false;
			Iterator iter = getIndex().getColumnIterator();
			while ( iter.hasNext() ) {
				if ( ( (Selectable) iter.next() ).isFormula() ) isFormula=true;
			}
			if (isFormula) {
				//if it is a formula index, use the element columns in the PK
				pk.addColumns( getElement().getColumnIterator() );
			}
			else {
				pk.addColumns( getIndex().getColumnIterator() ); 
			}
			getCollectionTable().setPrimaryKey(pk);
		}
		else {
			// don't create a unique key, 'cos some
			// databases don't like a UK on nullable
			// columns
			/*ArrayList list = new ArrayList();
			list.addAll( getKey().getConstraintColumns() );
			list.addAll( getIndex().getConstraintColumns() );
			getCollectionTable().createUniqueKey(list);*/
		}
	
public ValuegetIndex()

		return index;
	
public java.lang.StringgetIndexNodeName()

		return indexNodeName;
	
public final booleanisIndexed()

		return true;
	
public booleanisList()

		return false;
	
public voidsetIndex(Value index)

		this.index = index;
	
public voidsetIndexNodeName(java.lang.String indexNodeName)

		this.indexNodeName = indexNodeName;
	
public voidvalidate(org.hibernate.engine.Mapping mapping)

		super.validate(mapping);
		if ( !getIndex().isValid(mapping) ) {
			throw new MappingException(
				"collection index mapping has wrong number of columns: " +
				getRole() +
				" type: " +
				getIndex().getType().getName()
			);
		}
		if ( indexNodeName!=null && !indexNodeName.startsWith("@") ) {
			throw new MappingException("index node must be an attribute: " + indexNodeName );
		}