1 package org.hibernate.mapping; 3 4 import java.util.Iterator ; 5 6 import org.hibernate.MappingException; 7 import org.hibernate.engine.Mapping; 8 9 14 public abstract class IndexedCollection extends Collection { 15 16 public static final String DEFAULT_INDEX_COLUMN_NAME = "idx"; 17 18 private Value index; 19 private String indexNodeName; 20 21 public IndexedCollection(PersistentClass owner) { 22 super(owner); 23 } 24 25 public Value getIndex() { 26 return index; 27 } 28 public void setIndex(Value index) { 29 this.index = index; 30 } 31 public final boolean isIndexed() { 32 return true; 33 } 34 35 void createPrimaryKey() { 36 if ( !isOneToMany() ) { 37 PrimaryKey pk = new PrimaryKey(); 38 pk.addColumns( getKey().getColumnIterator() ); 39 40 boolean isFormula = false; 42 Iterator iter = getIndex().getColumnIterator(); 43 while ( iter.hasNext() ) { 44 if ( ( (Selectable) iter.next() ).isFormula() ) isFormula=true; 45 } 46 if (isFormula) { 47 pk.addColumns( getElement().getColumnIterator() ); 49 } 50 else { 51 pk.addColumns( getIndex().getColumnIterator() ); 52 } 53 getCollectionTable().setPrimaryKey(pk); 54 } 55 else { 56 63 } 64 } 65 66 public void validate(Mapping mapping) throws MappingException { 67 super.validate(mapping); 68 if ( !getIndex().isValid(mapping) ) { 69 throw new MappingException( 70 "collection index mapping has wrong number of columns: " + 71 getRole() + 72 " type: " + 73 getIndex().getType().getName() 74 ); 75 } 76 if ( indexNodeName!=null && !indexNodeName.startsWith("@") ) { 77 throw new MappingException("index node must be an attribute: " + indexNodeName ); 78 } 79 } 80 81 public boolean isList() { 82 return false; 83 } 84 85 public String getIndexNodeName() { 86 return indexNodeName; 87 } 88 89 public void setIndexNodeName(String indexNodeName) { 90 this.indexNodeName = indexNodeName; 91 } 92 93 94 } 95 | Popular Tags |