FileDocCategorySizeDatePackage
Column.javaAPI DocHibernate 3.2.57140Wed Mar 28 20:42:36 BST 2007org.hibernate.mapping

Column

public class Column extends Object implements Serializable, Selectable, Cloneable
A column of a relational database table
author
Gavin King

Fields Summary
public static final int
DEFAULT_LENGTH
public static final int
DEFAULT_PRECISION
public static final int
DEFAULT_SCALE
private int
length
private int
precision
private int
scale
private Value
value
private int
typeIndex
private String
name
private boolean
nullable
private boolean
unique
private String
sqlType
private Integer
sqlTypeCode
private boolean
quoted
int
uniqueInteger
private String
checkConstraint
private String
comment
private String
defaultValue
Constructors Summary
public Column()


	   
public Column(String columnName)

		setName(columnName);
	
Methods Summary
protected java.lang.Objectclone()
Shallow copy, the value is not copied

		Column copy = new Column();
		copy.setLength( length );
		copy.setScale( scale );
		copy.setValue( value );
		copy.setTypeIndex( typeIndex );
		copy.setName( getQuotedName() );
		copy.setNullable( nullable );
		copy.setPrecision( precision );
		copy.setUnique( unique );
		copy.setSqlType( sqlType );
		copy.setSqlTypeCode( sqlTypeCode );
		copy.uniqueInteger = uniqueInteger; //usually useless
		copy.setCheckConstraint( checkConstraint );
		copy.setComment( comment );
		copy.setDefaultValue( defaultValue );
		return copy;
	
public booleanequals(java.lang.Object object)

		return object instanceof Column && equals( (Column) object );
	
public booleanequals(org.hibernate.mapping.Column column)

		if (null == column) return false;
		if (this == column) return true;

		return isQuoted() ? 
			name.equals(column.name) :
			name.equalsIgnoreCase(column.name);
	
public java.lang.StringgetAlias(org.hibernate.dialect.Dialect dialect)
For any column name, generate an alias that is unique to that column name, and also 10 characters or less in length.

		String alias = name;
		String unique = Integer.toString(uniqueInteger) + '_";
		int lastLetter = StringHelper.lastIndexOfLetter(name);
		if ( lastLetter == -1 ) {
			alias = "column";
		}
		else if ( lastLetter < name.length()-1 ) {
			alias = name.substring(0, lastLetter+1);
		}
		if ( alias.length() > dialect.getMaxAliasLength() ) {
			alias = alias.substring( 0, dialect.getMaxAliasLength() - unique.length() );
		}
		boolean useRawName = name.equals(alias) && 
			!quoted && 
			!name.toLowerCase().equals("rowid");
		if ( useRawName ) {
			return alias;
		}
		else {
			return alias + unique;
		}
	
public java.lang.StringgetAlias(org.hibernate.dialect.Dialect dialect, Table table)
Generate a column alias that is unique across multiple tables

		return getAlias(dialect) + table.getUniqueInteger() + '_";
	
public java.lang.StringgetCanonicalName()

		return quoted ? name : name.toLowerCase();
	
public java.lang.StringgetCheckConstraint()

		return checkConstraint;
	
public java.lang.StringgetComment()

		return comment;
	
public java.lang.StringgetDefaultValue()

		return defaultValue;
	
public intgetLength()

		return length;
	
public java.lang.StringgetName()

		return name;
	
public intgetPrecision()

		return precision;
	
public java.lang.StringgetQuotedName(org.hibernate.dialect.Dialect d)

		return quoted ?
			d.openQuote() + name + d.closeQuote() :
			name;
	
public java.lang.StringgetQuotedName()
returns quoted name as it would be in the mapping file.

		return quoted ?
				"`" + name + "`" :
				name;
	
public intgetScale()

		return scale;
	
public java.lang.StringgetSqlType(org.hibernate.dialect.Dialect dialect, org.hibernate.engine.Mapping mapping)

		return sqlType==null ?
			dialect.getTypeName( getSqlTypeCode(mapping), getLength(), getPrecision(), getScale() ) :
			sqlType;
	
public java.lang.StringgetSqlType()

		return sqlType;
	
public intgetSqlTypeCode(org.hibernate.engine.Mapping mapping)

		org.hibernate.type.Type type = getValue().getType();
		try {
			int sqlTypeCode = type.sqlTypes(mapping)[ getTypeIndex() ];
			if(getSqlTypeCode()!=null && getSqlTypeCode().intValue()!=sqlTypeCode) {
				throw new MappingException("SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
			}
			return sqlTypeCode;
		}
		catch (Exception e) {
			throw new MappingException(
					"Could not determine type for column " +
					name +
					" of type " +
					type.getClass().getName() +
					": " +
					e.getClass().getName(),
					e
				);
		}
	
public java.lang.IntegergetSqlTypeCode()
Returns the underlying columns sqltypecode. If null, it is because the sqltype code is unknown. Use #getSqlTypeCode(Mapping) to retreive the sqltypecode used for the columns associated Value/Type.

return
sqltypecode if it is set, otherwise null.

		return sqlTypeCode;
	
public java.lang.StringgetTemplate(org.hibernate.dialect.Dialect dialect, org.hibernate.dialect.function.SQLFunctionRegistry functionRegistry)

		return getQuotedName(dialect);
	
public java.lang.StringgetText(org.hibernate.dialect.Dialect d)

		return getQuotedName(d);
	
public java.lang.StringgetText()

		return getName();
	
public intgetTypeIndex()

		return typeIndex;
	
public ValuegetValue()

		return value;
	
public booleanhasCheckConstraint()

		return checkConstraint!=null;
	
public inthashCode()

		return isQuoted() ? 
			name.hashCode() : 
			name.toLowerCase().hashCode();
	
public booleanisFormula()

		return false;
	
public booleanisNullable()

		return nullable;
	
public booleanisQuoted()

		return quoted;
	
public booleanisUnique()

		return unique;
	
public voidsetCheckConstraint(java.lang.String checkConstraint)

		this.checkConstraint = checkConstraint;
	
public voidsetComment(java.lang.String comment)

		this.comment = comment;
	
public voidsetDefaultValue(java.lang.String defaultValue)

		this.defaultValue = defaultValue;
	
public voidsetLength(int length)

		this.length = length;
	
public voidsetName(java.lang.String name)

		if (
			name.charAt(0)=='`" ||
			Dialect.QUOTE.indexOf( name.charAt(0) ) > -1 //TODO: deprecated, remove eventually
		) {
			quoted=true;
			this.name=name.substring( 1, name.length()-1 );
		}
		else {
			this.name = name;
		}
	
public voidsetNullable(boolean nullable)

		this.nullable=nullable;
	
public voidsetPrecision(int scale)

		this.precision = scale;
	
public voidsetScale(int scale)

		this.scale = scale;
	
public voidsetSqlType(java.lang.String sqlType)

		this.sqlType = sqlType;
	
public voidsetSqlTypeCode(java.lang.Integer typecode)

		sqlTypeCode=typecode;
	
public voidsetTypeIndex(int typeIndex)

		this.typeIndex = typeIndex;
	
public voidsetUnique(boolean unique)

		this.unique = unique;
	
public voidsetValue(Value value)

		this.value= value;
	
public java.lang.StringtoString()

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