FileDocCategorySizeDatePackage
DatabaseField.javaAPI DocGlassfish v2 API13243Tue May 22 16:54:34 BST 2007oracle.toplink.essentials.internal.helper

DatabaseField

public class DatabaseField extends Object implements Serializable, Cloneable
INTERNAL:

Purpose: Define a fully qualified field name.

Responsibilities:

  • Know its name and its table.
see
DatabaseTable

Fields Summary
protected int
scale
Variables used for generating DDL
protected int
length
protected int
precision
protected boolean
isUnique
protected boolean
isNullable
protected boolean
isUpdatable
protected boolean
isInsertable
protected String
columnDefinition
protected String
name
Column name of the field.
protected DatabaseTable
table
Fields table (encapsulates name + creator).
public transient Class
type
Respective Java type desired for the field's value, used to optimize performance and for binding.
public int
sqlType
Respective JDBC type of the field's value. This overrides the class type, which the JDBC type is normally computed from.
protected int
index
Store normal index of field in result set to optimize performance.
Constructors Summary
public DatabaseField()

        this("", new DatabaseTable());
    
public DatabaseField(String qualifiedName)

        this.index = -1;
        this.sqlType = -1;
        int index = qualifiedName.lastIndexOf('.");

        if (index == -1) {
            this.name = qualifiedName;
            this.table = new DatabaseTable();
        } else {
            this.name = qualifiedName.substring(index + 1, qualifiedName.length());
            this.table = new DatabaseTable(qualifiedName.substring(0, index));
        }
        
        initDDLFields();
    
public DatabaseField(String fieldName, String tableName)

        this(fieldName, new DatabaseTable(tableName));
    
public DatabaseField(String fieldName, DatabaseTable databaseTable)

        this.index = -1;
        this.sqlType = -1;
        this.name = fieldName;
        this.table = databaseTable;
        initDDLFields();
    
Methods Summary
public java.lang.Objectclone()
The table is not cloned because it is treated as an automic value.

        try {
            return super.clone();
        } catch (CloneNotSupportedException exception) {
        }

        return null;
    
public booleanequals(oracle.toplink.essentials.internal.helper.DatabaseField field)
Determine whether the receiver is equal to a DatabaseField. Return true if the receiver and field have the same name and table. Also return true if the table of the receiver or field are unspecfied, ie. have no name.

        if (this == field) {
            return true;
        }

        if (field != null) {
            if (DatabasePlatform.shouldIgnoreCaseOnFieldComparisons()) {
                if (getName().equalsIgnoreCase(field.getName())) {
                    if ((getTableName().length() == 0) || (field.getTableName().length() == 0)) {
                        return true;
                    }
                    return (getTable().equals(field.getTable()));
                }
            } else {
                if (getName().equals(field.getName())) {
                    if ((getTableName().length() == 0) || (field.getTableName().length() == 0)) {
                        return true;
                    }
                    return (getTable().equals(field.getTable()));
                }
            }
        }

        return false;
    
public booleanequals(java.lang.Object object)
Determine whether the receiver is equal to a DatabaseField. Return true if the receiver and field have the same name and table. Also return true if the table of the receiver or field are unspecfied, ie. have no name.

        if (!(object instanceof DatabaseField)) {
            return false;
        }

        return equals((DatabaseField)object);
    
public java.lang.StringgetColumnDefinition()
Get the SQL fragment that is used when generating the DDL for the column.

        return this.columnDefinition;
    
public intgetIndex()
Return the expected index that this field will occur in the result set row. This is used to optimize performance of database row field lookups.

        return index;
    
public intgetLength()
Used to specify the column length when generating DDL.

        return this.length;
    
public java.lang.StringgetName()
Return the unqualified name of the field.

        return name;
    
public intgetPrecision()
Returns the precision for a decimal column when generating DDL.

        return this.precision;
    
public java.lang.StringgetQualifiedName()
Return the qualified name of the field.

        if (hasTableName()) {
            return getTable().getQualifiedName() + "." + getName();
        } else {
            return getName();
        }
    
public intgetScale()
Returns the scale for a decimal column when generating DDL.

        return this.scale;
    
public intgetSqlType()
Return the JDBC type that coresponds to the field. The JDBC type is normally determined from the class type, but this allows it to be overriden for types that do not match directly to a Java type, such as MONEY or ARRAY, STRUCT, XMLTYPE, etc. This can be used for binding or stored procedure usage.

        return sqlType;
    
public oracle.toplink.essentials.internal.helper.DatabaseTablegetTable()

        return table;
    
public java.lang.StringgetTableName()

        return getTable().getName();
    
public java.lang.ClassgetType()

        return type;
    
public booleanhasTableName()

        if (getTable() == null) {
            return false;
        }
        if (getTable().getName() == null) {
            return false;
        }
        return !(getTable().getName().equals(""));
    
public inthashCode()
Return the hashcode of the name, because it is fairly unqiue.

        return getName().hashCode();
    
public voidinitDDLFields()
Inits the DDL generation fields. Currently equivalent to the defaults from the EJB 3.0 spec.

        scale = 0;
        length = 255;
        precision = 0;
        isUnique = false;
        isNullable = true;
        isUpdatable = true;
        isInsertable = true;
        columnDefinition = "";
    
public booleanisInsertable()
Used to specify whether the column should be included in SQL UPDATE statements.

        return this.isInsertable;
    
public booleanisNullable()
Used for generatating DDL. Returns true if the database column is nullable.

        return this.isNullable;
    
public booleanisReadOnly()
Returns true is this database field should be read only.

        return (! isUpdatable && ! isInsertable);
    
public booleanisUnique()
Used for generatating DDL. Returns true if the field is a unique key.

        return this.isUnique;
    
public booleanisUpdatable()
Returns whether the column should be included in SQL INSERT statements.

        return this.isUpdatable;
    
public voidresetQualifiedName(java.lang.String qualifiedName)
Reset the field's name and table from the qualified name.

        setIndex(-1);
        int index = qualifiedName.lastIndexOf('.");

        if (index == -1) {
            setName(qualifiedName);
            getTable().setName("");
            getTable().setTableQualifier("");
        } else {
            setName(qualifiedName.substring(index + 1, qualifiedName.length()));
            getTable().setPossiblyQualifiedName(qualifiedName.substring(0, index));
        }
    
public voidsetColumnDefinition(java.lang.String columnDefinition)
Set the SQL fragment that is used when generating the DDL for the column.

        this.columnDefinition = columnDefinition;
    
public voidsetIndex(int index)
Set the expected index that this field will occur in the result set row. This is used to optimize performance of database row field lookups.

        this.index = index;
    
public voidsetInsertable(boolean isInsertable)
Used to specify whether the column should be included in SQL UPDATE statements.

        this.isInsertable = isInsertable;
    
public voidsetLength(int length)
Used to specify the column length when generating DDL.

        this.length = length;
    
public voidsetName(java.lang.String name)
Set the unqualified name of the field.

        this.name = name;
    
public voidsetNullable(boolean isNullable)
Used for generatating DDL. Set to true if the database column is nullable.

        this.isNullable = isNullable;
    
public voidsetPrecision(int precision)
Used to specify the precision for a decimal column when generating DDL.

        this.precision = precision;
    
public voidsetScale(int scale)
Used to specify the scale for a decimal column when generating DDL.

        this.scale = scale;
    
public voidsetSqlType(int sqlType)
Set the JDBC type that coresponds to the field. The JDBC type is normally determined from the class type, but this allows it to be overriden for types that do not match directly to a Java type, such as MONEY or ARRAY, STRUCT, XMLTYPE, etc. This can be used for binding or stored procedure usage.

        this.sqlType = sqlType;
    
public voidsetTable(oracle.toplink.essentials.internal.helper.DatabaseTable table)
Set the table for the field.

        this.table = table;
    
public voidsetTableName(java.lang.String tableName)
Set the table name for this field.

        setTable(new DatabaseTable(tableName));
    
public voidsetType(java.lang.Class type)
Set the Java class type that coresponds to the field. The JDBC type is determined from the class type, this is used to optimize performance, and for binding.

        this.type = type;
    
public voidsetUnique(boolean isUnique)
Used for generatating DDL. Set to true if the field is a unique key.

        this.isUnique = isUnique;
    
public voidsetUpdatable(boolean isUpdatable)
Used to specify whether the column should be included in SQL INSERT statements.

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

        return this.getQualifiedName();