set.java

来自「hibernate-3.0.5 中文文档」· Java 代码 · 共 78 行

JAVA
78
字号
//$Id: Set.java,v 1.9 2005/05/21 16:22:37 oneovthafew Exp $package org.hibernate.mapping;import java.util.Iterator;import org.hibernate.MappingException;import org.hibernate.engine.Mapping;import org.hibernate.type.CollectionType;import org.hibernate.type.TypeFactory;/** * A set with no nullable element columns. It will have a primary key * consisting of all table columns (ie. key columns + element columns). * @author Gavin King */public class Set extends Collection {	public void validate(Mapping mapping) throws MappingException {		super.validate( mapping );		//for backward compatibility, disable this:		/*Iterator iter = getElement().getColumnIterator();		while ( iter.hasNext() ) {			Column col = (Column) iter.next();			if ( !col.isNullable() ) {				return;			}		}		throw new MappingException("set element mappings must have at least one non-nullable column: " + getRole() );*/	}	/**	 * Constructor for Set.	 * @param owner	 */	public Set(PersistentClass owner) {		super(owner);	}	public boolean isSet() {		return true;	}	public CollectionType getDefaultCollectionType() {		return isSorted() ?			TypeFactory.sortedSet( getRole(), getReferencedPropertyName(), isEmbedded(), getComparator() ) :			TypeFactory.set( getRole(), getReferencedPropertyName(), isEmbedded() );	}	void createPrimaryKey() {		if ( !isOneToMany() ) {			PrimaryKey pk = new PrimaryKey();			pk.addColumns( getKey().getColumnIterator() );			Iterator iter = getElement().getColumnIterator();			while ( iter.hasNext() ) {				Column col = (Column) iter.next();				if ( !col.isNullable() ) {					pk.addColumn(col);				}			}			if ( pk.getColumnSpan()==getKey().getColumnSpan() ) { 				//for backward compatibility, allow a set with no not-null 				//element columns, using all columns in the row locater SQL				//TODO: create an implicit not null constraint on all cols?			}			else {				getCollectionTable().setPrimaryKey(pk);			}		}		else {			//create an index on the key columns??		}	}	public Object accept(ValueVisitor visitor) {		return visitor.accept(this);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?