FileDocCategorySizeDatePackage
PersistentClass.javaAPI DocHibernate 3.2.523238Tue Dec 05 11:48:42 GMT 2006org.hibernate.mapping

PersistentClass

public abstract class PersistentClass extends Object implements Serializable, Filterable, MetaAttributable
Mapping for an entity.
author
Gavin King

Fields Summary
private static final org.hibernate.sql.Alias
PK_ALIAS
public static final String
NULL_DISCRIMINATOR_MAPPING
public static final String
NOT_NULL_DISCRIMINATOR_MAPPING
private String
entityName
private String
className
private String
proxyInterfaceName
private String
nodeName
private String
discriminatorValue
private boolean
lazy
private ArrayList
properties
private final ArrayList
subclasses
private final ArrayList
subclassProperties
private final ArrayList
subclassTables
private boolean
dynamicInsert
private boolean
dynamicUpdate
private int
batchSize
private boolean
selectBeforeUpdate
private Map
metaAttributes
private ArrayList
joins
private final ArrayList
subclassJoins
private final Map
filters
protected final Set
synchronizedTables
private String
loaderName
private Boolean
isAbstract
private boolean
hasSubselectLoadableCollections
private Component
identifierMapper
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
temporaryIdTableName
private String
temporaryIdTableDDL
private Map
tuplizerImpls
protected int
optimisticLockMode
Constructors Summary
Methods Summary
public abstract java.lang.Objectaccept(PersistentClassVisitor mv)

public voidaddFilter(java.lang.String name, java.lang.String condition)

		filters.put(name, condition);
	
public voidaddJoin(Join join)

		joins.add(join);
		join.setPersistentClass(this);
	
public voidaddProperty(Property p)

		properties.add(p);
		p.setPersistentClass(this);
	
public voidaddSubclass(Subclass subclass)

		// inheritance cycle detection (paranoid check)
		PersistentClass superclass = getSuperclass();
		while (superclass!=null) {
			if( subclass.getEntityName().equals( superclass.getEntityName() ) ) {
				throw new MappingException(
					"Circular inheritance mapping detected: " +
					subclass.getEntityName() +
					" will have it self as superclass when extending " +
					getEntityName()
				);
			}
			superclass = superclass.getSuperclass();
		}
		subclasses.add(subclass);
	
protected voidaddSubclassJoin(Join join)

		subclassJoins.add(join);
	
protected voidaddSubclassProperty(Property prop)

		subclassProperties.add(prop);
	
protected voidaddSubclassTable(Table subclassTable)

		subclassTables.add(subclassTable);
	
public voidaddSynchronizedTable(java.lang.String table)

		synchronizedTables.add(table);
	
public voidaddTuplizer(org.hibernate.EntityMode entityMode, java.lang.String implClassName)

		if ( tuplizerImpls == null ) {
			tuplizerImpls = new HashMap();
		}
		tuplizerImpls.put( entityMode, implClassName );
	
protected voidcheckColumnDuplication(java.util.Set distinctColumns, java.util.Iterator columns)

		while ( columns.hasNext() ) {
			Selectable columnOrFormula = (Selectable) columns.next();
			if ( !columnOrFormula.isFormula() ) {
				Column col = (Column) columnOrFormula;
				if ( !distinctColumns.add( col.getName() ) ) {
					throw new MappingException(
							"Repeated column in mapping for entity: " +
							getEntityName() +
							" column: " +
							col.getName() +
							" (should be mapped with insert=\"false\" update=\"false\")"
						);
				}
			}
		}
	
protected voidcheckColumnDuplication()

		HashSet cols = new HashSet();
		if (getIdentifierMapper() == null ) {
			//an identifier mapper => getKey will be included in the getNonDuplicatedPropertyIterator()
			//and checked later, so it needs to be excluded
			checkColumnDuplication( cols, getKey().getColumnIterator() );
		}
		checkColumnDuplication( cols, getDiscriminatorColumnIterator() );
		checkPropertyColumnDuplication( cols, getNonDuplicatedPropertyIterator() );
		Iterator iter = getJoinIterator();
		while ( iter.hasNext() ) {
			cols.clear();
			Join join = (Join) iter.next();
			checkColumnDuplication( cols, join.getKey().getColumnIterator() );
			checkPropertyColumnDuplication( cols, join.getPropertyIterator() );
		}
	
protected voidcheckPropertyColumnDuplication(java.util.Set distinctColumns, java.util.Iterator properties)

		while ( properties.hasNext() ) {
			Property prop = (Property) properties.next();
			if ( prop.getValue() instanceof Component ) { //TODO: remove use of instanceof!
				Component component = (Component) prop.getValue();
				checkPropertyColumnDuplication( distinctColumns, component.getPropertyIterator() );
			}
			else {
				if ( prop.isUpdateable() || prop.isInsertable() ) {
					checkColumnDuplication( distinctColumns, prop.getColumnIterator() );
				}
			}
		}
	
private voidcheckPropertyDuplication()

		HashSet names = new HashSet();
		Iterator iter = getPropertyIterator();
		while ( iter.hasNext() ) {
			Property prop = (Property) iter.next();
			if ( !names.add( prop.getName() ) ) {
				throw new MappingException( "Duplicate property mapping of " + prop.getName() + " found in " + getEntityName());
			}
		}
	
public voidcreatePrimaryKey()

		//Primary key constraint
		PrimaryKey pk = new PrimaryKey();
		Table table = getTable();
		pk.setTable(table);
		pk.setName( PK_ALIAS.toAliasString( table.getName() ) );
		table.setPrimaryKey(pk);

		pk.addColumns( getKey().getColumnIterator() );
	
public intgetBatchSize()

		return batchSize;
	
public abstract java.lang.StringgetCacheConcurrencyStrategy()

public java.lang.StringgetClassName()


	   
		return className;
	
public java.lang.StringgetCustomSQLDelete()

		return customSQLDelete;
	
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 java.util.IteratorgetDirectSubclasses()

		return subclasses.iterator();
	
public abstract ValuegetDiscriminator()

protected java.util.IteratorgetDiscriminatorColumnIterator()

		return EmptyIterator.INSTANCE;
	
public java.lang.StringgetDiscriminatorValue()

		return discriminatorValue;
	
public java.lang.StringgetEntityName()

		return entityName;
	
public abstract java.lang.ClassgetEntityPersisterClass()

public java.util.MapgetFilterMap()

		return filters;
	
public abstract KeyValuegetIdentifier()

public ComponentgetIdentifierMapper()

		return identifierMapper;
	
public abstract PropertygetIdentifierProperty()

public TablegetIdentityTable()

		return getRootTable();
	
public java.util.IteratorgetJoinClosureIterator()

		return joins.iterator();
	
public intgetJoinClosureSpan()

		return joins.size();
	
public java.util.IteratorgetJoinIterator()

		return joins.iterator();
	
public intgetJoinNumber(Property prop)

		int result=1;
		Iterator iter = getSubclassJoinClosureIterator();
		while ( iter.hasNext() ) {
			Join join = (Join) iter.next();
			if ( join.containsProperty(prop) ) return result;
			result++;
		}
		return 0;
	
public abstract KeyValuegetKey()

public abstract java.util.IteratorgetKeyClosureIterator()

public java.lang.StringgetLoaderName()

		return loaderName;
	
public java.lang.ClassgetMappedClass()

		if (className==null) return null;
		try {
			return ReflectHelper.classForName(className);
		}
		catch (ClassNotFoundException cnfe) {
			throw new MappingException("entity class not found: " + className, cnfe);
		}
	
public MetaAttributegetMetaAttribute(java.lang.String name)

		return metaAttributes==null?null:(MetaAttribute) metaAttributes.get(name);
	
public java.util.MapgetMetaAttributes()

		return metaAttributes;
	
public java.lang.StringgetNodeName()

		return nodeName;
	
protected java.util.IteratorgetNonDuplicatedPropertyIterator()

		return getUnjoinedPropertyIterator();
	
public abstract intgetOptimisticLockMode()

private PropertygetProperty(java.lang.String propertyName, java.util.Iterator iterator)

		while ( iterator.hasNext() ) {
			Property prop = (Property) iterator.next();
			if ( prop.getName().equals( StringHelper.root(propertyName) ) ) {
				return prop;
			}
		}
		throw new MappingException( "property [" + propertyName + "] not found on entity [" + getEntityName() + "]" );
	
public PropertygetProperty(java.lang.String propertyName)

		Iterator iter = getPropertyClosureIterator();
		Property identifierProperty = getIdentifierProperty();
		if ( identifierProperty != null
				&& identifierProperty.getName().equals( StringHelper.root(propertyName) )
				) {
			return identifierProperty;
		}
		else {
			return getProperty( propertyName, iter );
		}
	
public abstract java.util.IteratorgetPropertyClosureIterator()

public intgetPropertyClosureSpan()

		int span = properties.size();
		for ( int i=0; i<joins.size(); i++ ) {
			Join join = (Join) joins.get(i);
			span += join.getPropertySpan();
		}
		return span;
	
public java.util.IteratorgetPropertyIterator()
Build an iterator over the properties defined on this class. The returned iterator only accounts for "normal" properties (i.e. non-identifier properties).

Differs from {@link #getUnjoinedPropertyIterator} in that the iterator we return here will include properties defined as part of a join.

return
An iterator over the "normal" properties.

		ArrayList iterators = new ArrayList();
		iterators.add( properties.iterator() );
		for ( int i = 0; i < joins.size(); i++ ) {
			Join join = ( Join ) joins.get( i );
			iterators.add( join.getPropertyIterator() );
		}
		return new JoinedIterator( iterators );
	
public java.lang.ClassgetProxyInterface()

		if (proxyInterfaceName==null) return null;
		try {
			return ReflectHelper.classForName(proxyInterfaceName);
		}
		catch (ClassNotFoundException cnfe) {
			throw new MappingException("proxy class not found: " + proxyInterfaceName, cnfe);
		}
	
public java.lang.StringgetProxyInterfaceName()

		return proxyInterfaceName;
	
public PropertygetRecursiveProperty(java.lang.String propertyPath)

		try {
			return getRecursiveProperty( propertyPath, getPropertyIterator() );
		}
		catch ( MappingException e ) {
			throw new MappingException(
					"property [" + propertyPath + "] not found on entity [" + getEntityName() + "]", e
			);
		}
	
private PropertygetRecursiveProperty(java.lang.String propertyPath, java.util.Iterator iter)

		Property property = null;
		StringTokenizer st = new StringTokenizer( propertyPath, ".", false );
		try {
			while ( st.hasMoreElements() ) {
				final String element = ( String ) st.nextElement();
				if ( property == null ) {
					// we are processing the root of the prpertyPath, so we have the following
					// considerations:
					//		1) specifically account for identifier properties
					//		2) specifically account for embedded composite-identifiers
					// 		3) perform a normal property lookup
					Property identifierProperty = getIdentifierProperty();
					if ( identifierProperty != null && identifierProperty.getName().equals( element ) ) {
						// we have a mapped identifier property and the root of
						// the incoming property path matched that identifier
						// property
						property = identifierProperty;
					}
					else if ( identifierProperty == null && getIdentifier() != null && Component.class.isInstance( getIdentifier() ) ) {
						// we have an embedded composite identifier
						try {
							identifierProperty = getProperty( element, ( ( Component ) getIdentifier() ).getPropertyIterator() );
							if ( identifierProperty != null ) {
								// the root of the incoming property path matched one
								// of the embedded composite identifier properties
								property = identifierProperty;
							}
						}
						catch( MappingException ignore ) {
							// ignore it...
						}
					}

					if ( property == null ) {
						property = getProperty( element, iter );
					}
				}
				else {
					//flat recursive algorithm
					property = ( ( Component ) property.getValue() ).getProperty( element );
				}
			}
		}
		catch ( MappingException e ) {
			throw new MappingException( "property [" + propertyPath + "] not found on entity [" + getEntityName() + "]" );
		}

		return property;
	
public java.util.IteratorgetReferenceablePropertyIterator()
Build an iterator of properties which are "referenceable".

see
#getReferencedProperty for a discussion of "referenceable"
return
The property iterator.

		return getPropertyClosureIterator();
	
public PropertygetReferencedProperty(java.lang.String propertyPath)
Given a property path, locate the appropriate referenceable property reference.

A referenceable property is a property which can be a target of a foreign-key mapping (an identifier or explcitly named in a property-ref).

param
propertyPath The property path to resolve into a property reference.
return
The property reference (never null).
throws
MappingException If the property could not be found.

		try {
			return getRecursiveProperty( propertyPath, getReferenceablePropertyIterator() );
		}
		catch ( MappingException e ) {
			throw new MappingException(
					"property-ref [" + propertyPath + "] not found on entity [" + getEntityName() + "]", e
			);
		}
	
public abstract RootClassgetRootClass()

public abstract TablegetRootTable()

public java.util.IteratorgetSubclassClosureIterator()

		ArrayList iters = new ArrayList();
		iters.add( new SingletonIterator(this) );
		Iterator iter = getSubclassIterator();
		while ( iter.hasNext() ) {
			PersistentClass clazz = (PersistentClass)  iter.next();
			iters.add( clazz.getSubclassClosureIterator() );
		}
		return new JoinedIterator(iters);
	
public abstract intgetSubclassId()

public java.util.IteratorgetSubclassIterator()
Iterate over subclasses in a special 'order', most derived subclasses first.

		Iterator[] iters = new Iterator[ subclasses.size() + 1 ];
		Iterator iter = subclasses.iterator();
		int i=0;
		while ( iter.hasNext() ) {
			iters[i++] = ( (Subclass) iter.next() ).getSubclassIterator();
		}
		iters[i] = subclasses.iterator();
		return new JoinedIterator(iters);
	
public java.util.IteratorgetSubclassJoinClosureIterator()

		return new JoinedIterator( getJoinClosureIterator(), subclassJoins.iterator() );
	
public java.util.IteratorgetSubclassPropertyClosureIterator()

		ArrayList iters = new ArrayList();
		iters.add( getPropertyClosureIterator() );
		iters.add( subclassProperties.iterator() );
		for ( int i=0; i<subclassJoins.size(); i++ ) {
			Join join = (Join) subclassJoins.get(i);
			iters.add( join.getPropertyIterator() );
		}
		return new JoinedIterator(iters);
	
public intgetSubclassSpan()

		int n = subclasses.size();
		Iterator iter = subclasses.iterator();
		while ( iter.hasNext() ) {
			n += ( (Subclass) iter.next() ).getSubclassSpan();
		}
		return n;
	
public java.util.IteratorgetSubclassTableClosureIterator()

		return new JoinedIterator( getTableClosureIterator(), subclassTables.iterator() );
	
public abstract org.hibernate.mapping.PersistentClassgetSuperclass()

public abstract java.util.SetgetSynchronizedTables()

public abstract TablegetTable()

public abstract java.util.IteratorgetTableClosureIterator()

public java.lang.StringgetTemporaryIdTableDDL()

		return temporaryIdTableDDL;
	
public java.lang.StringgetTemporaryIdTableName()

		return temporaryIdTableName;
	
public java.lang.StringgetTuplizerImplClassName(org.hibernate.EntityMode mode)

		if ( tuplizerImpls == null ) return null;
		return ( String ) tuplizerImpls.get( mode );
	
public java.util.MapgetTuplizerMap()

		if ( tuplizerImpls == null ) {
			return null;
		}
		return java.util.Collections.unmodifiableMap( tuplizerImpls );
	
public java.util.IteratorgetUnjoinedPropertyIterator()
Build an iterator over the properties defined on this class which are not defined as part of a join. As with {@link #getPropertyIterator}, the returned iterator only accounts for non-identifier properties.

return
An iterator over the non-joined "normal" properties.

		return properties.iterator();
	
public abstract PropertygetVersion()

public abstract java.lang.StringgetWhere()

public booleanhasDom4jRepresentation()

		return getNodeName()!=null;
	
public abstract booleanhasEmbeddedIdentifier()

public booleanhasIdentifierMapper()

		return identifierMapper != null;
	
public abstract booleanhasIdentifierProperty()

public booleanhasNaturalId()

		Iterator props = getRootClass().getPropertyIterator();
		while ( props.hasNext() ) {
			if ( ( (Property) props.next() ).isNaturalIdentifier() ) {
				return true;
			}
		}
		return false;
	
public booleanhasPojoRepresentation()

		return getClassName()!=null;
	
public booleanhasSelectBeforeUpdate()

		return selectBeforeUpdate;
	
public booleanhasSubclasses()

		return subclasses.size() > 0;
	
public booleanhasSubselectLoadableCollections()

		return hasSubselectLoadableCollections;
	
public java.lang.BooleanisAbstract()

		return isAbstract;
	
public booleanisClassOrSuperclassJoin(Join join)

		return joins.contains(join);
	
public booleanisClassOrSuperclassTable(Table closureTable)

		return getTable()==closureTable;
	
public booleanisCustomDeleteCallable()

		return customDeleteCallable;
	
public booleanisCustomInsertCallable()

		return customInsertCallable;
	
public booleanisCustomUpdateCallable()

		return customUpdateCallable;
	
public abstract booleanisDiscriminatorInsertable()

public booleanisDiscriminatorValueNotNull()

		return NOT_NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() );
	
public booleanisDiscriminatorValueNull()

		return NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() );
	
public abstract booleanisExplicitPolymorphism()

public booleanisForceDiscriminator()

		return false;
	
public abstract booleanisInherited()

public abstract booleanisJoinedSubclass()

public booleanisLazy()

		return lazy;
	
public abstract booleanisLazyPropertiesCacheable()

public abstract booleanisMutable()

public abstract booleanisPolymorphic()

public abstract booleanisVersioned()

abstract intnextSubclassId()

public voidprepareTemporaryTables(org.hibernate.engine.Mapping mapping, org.hibernate.dialect.Dialect dialect)

		if ( dialect.supportsTemporaryTables() ) {
			temporaryIdTableName = dialect.generateTemporaryTableName( getTable().getName() );
			Table table = new Table();
			table.setName( temporaryIdTableName );
			Iterator itr = getTable().getPrimaryKey().getColumnIterator();
			while( itr.hasNext() ) {
				Column column = (Column) itr.next();
				table.addColumn( (Column) column.clone()  );
			}
			temporaryIdTableDDL = table.sqlTemporaryTableCreateString( dialect, mapping );
		}
	
public voidsetAbstract(java.lang.Boolean isAbstract)

		this.isAbstract = isAbstract;
	
public voidsetBatchSize(int batchSize)

		this.batchSize = batchSize;
	
public voidsetClassName(java.lang.String className)

		this.className = className==null ? null : className.intern();
	
public voidsetCustomSQLDelete(java.lang.String customSQLDelete, boolean callable, org.hibernate.engine.ExecuteUpdateResultCheckStyle checkStyle)

		this.customSQLDelete = customSQLDelete;
		this.customDeleteCallable = callable;
		this.deleteCheckStyle = 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 voidsetDiscriminatorValue(java.lang.String discriminatorValue)

		this.discriminatorValue = discriminatorValue;
	
public voidsetDynamicInsert(boolean dynamicInsert)

		this.dynamicInsert = dynamicInsert;
	
public voidsetDynamicUpdate(boolean dynamicUpdate)

		this.dynamicUpdate = dynamicUpdate;
	
public voidsetEntityName(java.lang.String entityName)

		this.entityName = entityName==null ? null : entityName.intern();
	
public abstract voidsetEntityPersisterClass(java.lang.Class classPersisterClass)

public voidsetIdentifierMapper(Component handle)

		this.identifierMapper = handle;
	
public voidsetLazy(boolean lazy)

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

		this.loaderName = loaderName==null ? null : loaderName.intern();
	
public voidsetMetaAttributes(java.util.Map metas)

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

		this.nodeName = nodeName;
	
public voidsetOptimisticLockMode(int optimisticLockMode)

		this.optimisticLockMode = optimisticLockMode;
	
public voidsetProxyInterfaceName(java.lang.String proxyInterfaceName)

		this.proxyInterfaceName = proxyInterfaceName;
	
public voidsetSelectBeforeUpdate(boolean selectBeforeUpdate)

		this.selectBeforeUpdate = selectBeforeUpdate;
	
public voidsetSubselectLoadableCollections(boolean hasSubselectCollections)

		this.hasSubselectLoadableCollections = hasSubselectCollections;
	
public java.lang.StringtoString()

		return getClass().getName() + '(" + getEntityName() + ')";
	
public booleanuseDynamicInsert()

		return dynamicInsert;
	
public booleanuseDynamicUpdate()

		return dynamicUpdate;
	
public voidvalidate(org.hibernate.engine.Mapping mapping)

		Iterator iter = getPropertyIterator();
		while ( iter.hasNext() ) {
			Property prop = (Property) iter.next();
			if ( !prop.isValid(mapping) ) {
				throw new MappingException(
						"property mapping has wrong number of columns: " +
						StringHelper.qualify( getEntityName(), prop.getName() ) +
						" type: " +
						prop.getType().getName()
					);
			}
		}
		checkPropertyDuplication();
		checkColumnDuplication();