FileDocCategorySizeDatePackage
SimpleValue.javaAPI DocHibernate 3.2.58645Tue Aug 30 15:11:44 BST 2005org.hibernate.mapping

SimpleValue

public class SimpleValue extends Object implements KeyValue
Any value that maps to columns.
author
Gavin King

Fields Summary
private final List
columns
private String
typeName
private Properties
identifierGeneratorProperties
private String
identifierGeneratorStrategy
private String
nullValue
private Table
table
private String
foreignKeyName
private boolean
alternateUniqueKey
private Properties
typeParameters
private boolean
cascadeDeleteEnabled
Constructors Summary
public SimpleValue(Table table)

		this.table = table;
	
public SimpleValue()

Methods Summary
public java.lang.Objectaccept(ValueVisitor visitor)

		return visitor.accept(this);
	
public voidaddColumn(Column column)

		if ( !columns.contains(column) ) columns.add(column);
		column.setValue(this);
		column.setTypeIndex( columns.size()-1 );
	
public voidaddFormula(Formula formula)

		columns.add(formula);
	
public voidcreateForeignKey()

public voidcreateForeignKeyOfEntity(java.lang.String entityName)

		if ( !hasFormula() && !"none".equals(getForeignKeyName())) {
			ForeignKey fk = table.createForeignKey( getForeignKeyName(), getConstraintColumns(), entityName );
			fk.setCascadeDeleteEnabled(cascadeDeleteEnabled);
		}
	
public org.hibernate.id.IdentifierGeneratorcreateIdentifierGenerator(org.hibernate.dialect.Dialect dialect, java.lang.String defaultCatalog, java.lang.String defaultSchema, RootClass rootClass)

		
		Properties params = new Properties();
		
		//if the hibernate-mapping did not specify a schema/catalog, use the defaults
		//specified by properties - but note that if the schema/catalog were specified
		//in hibernate-mapping, or as params, they will already be initialized and
		//will override the values set here (they are in identifierGeneratorProperties)
		if ( defaultSchema!=null ) {
			params.setProperty(PersistentIdentifierGenerator.SCHEMA, defaultSchema);
		}
		if ( defaultCatalog!=null ) {
			params.setProperty(PersistentIdentifierGenerator.CATALOG, defaultCatalog);
		}
		
		//pass the entity-name, if not a collection-id
		if (rootClass!=null) {
			params.setProperty( IdentifierGenerator.ENTITY_NAME, rootClass.getEntityName() );
		}
		
		//init the table here instead of earlier, so that we can get a quoted table name
		//TODO: would it be better to simply pass the qualified table name, instead of
		//      splitting it up into schema/catalog/table names
		String tableName = getTable().getQuotedName(dialect);
		params.setProperty( PersistentIdentifierGenerator.TABLE, tableName );
		
		//pass the column name (a generated id almost always has a single column)
		String columnName = ( (Column) getColumnIterator().next() ).getQuotedName(dialect);
		params.setProperty( PersistentIdentifierGenerator.PK, columnName );
		
		if (rootClass!=null) {
			StringBuffer tables = new StringBuffer();
			Iterator iter = rootClass.getIdentityTables().iterator();
			while ( iter.hasNext() ) {
				Table table= (Table) iter.next();
				tables.append( table.getQuotedName(dialect) );
				if ( iter.hasNext() ) tables.append(", ");
			}
			params.setProperty( PersistentIdentifierGenerator.TABLES, tables.toString() );
		}
		else {
			params.setProperty( PersistentIdentifierGenerator.TABLES, tableName );
		}

		if (identifierGeneratorProperties!=null) {
			params.putAll(identifierGeneratorProperties);
		}
		
		return IdentifierGeneratorFactory.create(
				identifierGeneratorStrategy,
				getType(),
				params,
				dialect
			);
		
	
public boolean[]getColumnInsertability()

		boolean[] result = new boolean[ getColumnSpan() ];
		int i = 0;
		Iterator iter = getColumnIterator();
		while ( iter.hasNext() ) {
			Selectable s = (Selectable) iter.next();
			result[i++] = !s.isFormula();
		}
		return result;
	
public java.util.IteratorgetColumnIterator()

		return columns.iterator();
	
public intgetColumnSpan()

		return columns.size();
	
public boolean[]getColumnUpdateability()

		return getColumnInsertability();
	
public java.util.ListgetConstraintColumns()

		return columns;
	
public org.hibernate.FetchModegetFetchMode()

		return FetchMode.SELECT;
	
public java.lang.StringgetForeignKeyName()

		return foreignKeyName;
	
public java.util.PropertiesgetIdentifierGeneratorProperties()

		return identifierGeneratorProperties;
	
public java.lang.StringgetIdentifierGeneratorStrategy()
Returns the identifierGeneratorStrategy.

return
String

		return identifierGeneratorStrategy;
	
public java.lang.StringgetNullValue()

		return nullValue;
	
public TablegetTable()

		return table;
	
public org.hibernate.type.TypegetType()

		if (typeName==null) {
			throw new MappingException("No type name");
		}
		Type result = TypeFactory.heuristicType(typeName, typeParameters);
		if (result==null) {
			String msg = "Could not determine type for: " + typeName;
			if(columns!=null && columns.size()>0) {
				msg += ", for columns: " + columns;
			}
			throw new MappingException(msg);
		}
		return result;
	
public java.lang.StringgetTypeName()

		return typeName;
	
public java.util.PropertiesgetTypeParameters()

		return typeParameters;
	
public booleanhasFormula()

		Iterator iter = getColumnIterator();
		while ( iter.hasNext() ) {
			Object o = iter.next();
			if (o instanceof Formula) return true;
		}
		return false;
	
public booleanisAlternateUniqueKey()

		return alternateUniqueKey;
	
public booleanisCascadeDeleteEnabled()


	   
		return cascadeDeleteEnabled;
	
public booleanisIdentityColumn(org.hibernate.dialect.Dialect dialect)

		return IdentifierGeneratorFactory.getIdentifierGeneratorClass(identifierGeneratorStrategy, dialect)
				.equals(IdentityGenerator.class);
	
public booleanisNullable()

		if ( hasFormula() ) return true;
		boolean nullable = true;
		Iterator iter = getColumnIterator();
		while ( iter.hasNext() ) {
			if ( !( (Column) iter.next() ).isNullable() ) {
				nullable = false;
				return nullable; //shortcut
			}
		}
		return nullable;
	
public booleanisSimpleValue()

		return true;
	
public booleanisTypeSpecified()

		return typeName!=null;
	
public booleanisUpdateable()

		//needed to satisfy KeyValue
		return true;
	
public booleanisValid(org.hibernate.engine.Mapping mapping)

		return getColumnSpan()==getType().getColumnSpan(mapping);
	
public voidsetAlternateUniqueKey(boolean unique)

		this.alternateUniqueKey = unique;
	
public voidsetCascadeDeleteEnabled(boolean cascadeDeleteEnabled)

		this.cascadeDeleteEnabled = cascadeDeleteEnabled;
	
public voidsetForeignKeyName(java.lang.String foreignKeyName)

		this.foreignKeyName = foreignKeyName;
	
public voidsetIdentifierGeneratorProperties(java.util.Properties identifierGeneratorProperties)
Sets the identifierGeneratorProperties.

param
identifierGeneratorProperties The identifierGeneratorProperties to set

		this.identifierGeneratorProperties = identifierGeneratorProperties;
	
public voidsetIdentifierGeneratorStrategy(java.lang.String identifierGeneratorStrategy)
Sets the identifierGeneratorStrategy.

param
identifierGeneratorStrategy The identifierGeneratorStrategy to set

		this.identifierGeneratorStrategy = identifierGeneratorStrategy;
	
public voidsetNullValue(java.lang.String nullValue)
Sets the nullValue.

param
nullValue The nullValue to set

		this.nullValue = nullValue;
	
public voidsetTable(Table table)

		this.table = table;
	
public voidsetTypeName(java.lang.String type)

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

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

		if (typeName==null) {
			if (className==null) {
				throw new MappingException("you must specify types for a dynamic entity: " + propertyName);
			}
			typeName = ReflectHelper.reflectedPropertyClass(className, propertyName).getName();
		}
	
public java.lang.StringtoString()

		return getClass().getName() + '(" + columns.toString() + ')";