Module org.eclipse.persistence.core
Class DatabaseField
- java.lang.Object
-
- org.eclipse.persistence.internal.helper.DatabaseField
-
- All Implemented Interfaces:
Serializable,Cloneable,CoreField
- Direct Known Subclasses:
FunctionField,ObjectRelationalDatabaseField,XMLField
public class DatabaseField extends Object implements Cloneable, Serializable, CoreField
INTERNAL:Purpose: Define a fully qualified field name.
Responsibilities:
- Know its name and its table.
- See Also:
DatabaseTable, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected StringcolumnDefinitionintindexStore normal index of field in result set to optimize performance.protected booleanisCreatableprotected booleanisInsertableprotected booleanisNullableprotected booleanisPrimaryKeyprotected booleanisTranslatedReturns true if this field was translated.protected booleanisUniqueprotected booleanisUpdatablebooleankeepInRowIndicates whether the field should be kept in the record after the object is created.protected intlengthprotected StringnameColumn name of the field.protected StringnameForComparisonsIf this is set, it will be used in determining equality (unless delimiters are used) and the hashcode.static intNULL_SQL_TYPEused to represent the value when it has not being definedprotected intprecisionprotected StringqualifiedNamePERF: Cache fully qualified table.field-name.protected intscaleVariables used for generating DDLintsqlTypeRespective JDBC type of the field's value.protected DatabaseTabletableFields table (encapsulates name + creator).Class<?>typeRespective Java type desired for the field's value, used to optimize performance and for binding.StringtypeNameprotected booleanuseDelimitersprotected booleanuseUpperCaseForComparisonssetting to true will cause getNameForComparisons to lazy initialize nameForComparisons using the value from getName().toUpperCase().
-
Constructor Summary
Constructors Constructor Description DatabaseField()DatabaseField(String qualifiedName)DatabaseField(String fieldName, String tableName)DatabaseField(String qualifiedName, String startDelimiter, String endDelimiter)DatabaseField(String fieldName, DatabaseTable databaseTable)DatabaseField(String fieldName, DatabaseTable databaseTable, String startDelimiter, String endDelimiter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DatabaseFieldclone()The table is not cloned because it is treated as an automatic value.voidconvertClassNamesToClasses(ClassLoader classLoader)booleanequals(Object object)Determine whether the receiver is equal to a DatabaseField.booleanequals(DatabaseField field)Determine whether the receiver is equal to a DatabaseField.StringgetColumnDefinition()Get the SQL fragment that is used when generating the DDL for the column.intgetIndex()Return the expected index that this field will occur in the result set row.intgetLength()Used to specify the column length when generating DDL.StringgetName()Return the unqualified name of the field.StringgetNameDelimited(DatasourcePlatform platform)Returns this fields name with database delimiters if useDelimiters is true.StringgetNameForComparisons()INTERNAL: gets the string used for comparisons and in determining the hashcode.intgetPrecision()Returns the precision for a decimal column when generating DDL.StringgetQualifiedName()StringgetQualifiedNameDelimited(DatasourcePlatform platform)Return the qualified name of the field.intgetScale()Returns the scale for a decimal column when generating DDL.intgetSqlType()Return the JDBC type that corresponds to the field.DatabaseTablegetTable()StringgetTableName()Class<?>getType()StringgetTypeName()booleangetUseUpperCaseForComparisons()inthashCode()Return the hashcode of the name, because it is fairly unique.booleanhasTableName()voidinitDDLFields()Inits the DDL generation fields with our defaults.booleanisCreatable()booleanisInsertable()Used to specify whether the column should be included in SQL UPDATE statements.booleanisNullable()Used for generating DDL.booleanisObjectRelationalDatabaseField()PUBLIC: Return if this is an ObjectRelationalDatabaseField.booleanisPrimaryKey()Used to specify whether the column should be included in the primary on the database table.booleanisReadOnly()Returns true is this database field should be read only.booleanisTranslated()Return true if this database field is a translation.booleanisUnique()Used for generating DDL.booleanisUpdatable()Returns whether the column should be included in SQL INSERT statements.booleankeepInRow()voidresetQualifiedName(String qualifiedName)Reset the field's name and table from the qualified name.voidsetColumnDefinition(String columnDefinition)Set the SQL fragment that is used when generating the DDL for the column.voidsetCreatable(boolean isCreatable)voidsetIndex(int index)Set the expected index that this field will occur in the result set row.voidsetInsertable(boolean isInsertable)Used to specify whether the column should be included in SQL UPDATE statements.voidsetIsTranslated(boolean isTranslated)Set the isTranslated flag.voidsetKeepInRow(boolean keepInRow)voidsetLength(int length)Used to specify the column length when generating DDL.voidsetName(String name)Set the unqualified name of the field.voidsetName(String name, String startDelimiter, String endDelimiter)Set the unqualified name of the field.voidsetName(String name, DatasourcePlatform platform)Set the unqualified name of the field.voidsetNameForComparisons(String name)INTERNAL: sets the string to be used for equality checking and determining the hashcode of this field.voidsetNullable(boolean isNullable)Used for generating DDL.voidsetPrecision(int precision)Used to specify the precision for a decimal column when generating DDL.voidsetPrimaryKey(boolean isPrimaryKey)Used to specify whether the column should be included in primary key on the database table.voidsetScale(int scale)Used to specify the scale for a decimal column when generating DDL.voidsetSqlType(int sqlType)Set the JDBC type that corresponds to the field.voidsetTable(DatabaseTable table)Set the table for the field.voidsetTableName(String tableName)voidsetType(Class<?> type)Set the Java class type that corresponds to the field.voidsetTypeName(String typeName)voidsetUnique(boolean isUnique)Used for generating DDL.voidsetUpdatable(boolean isUpdatable)Used to specify whether the column should be included in SQL INSERT statements.voidsetUseDelimiters(boolean useDelimiters)booleanshouldUseDelimiters()StringtoString()voiduseUpperCaseForComparisons(boolean useUpperCaseForComparisons)INTERNAL: Sets the useUpperCaseForComparisons flag which is used to force using the uppercase version of the field's name to determine field equality and its hashcode, but will still use the original name when writing/printing operations.
-
-
-
Field Detail
-
scale
protected int scale
Variables used for generating DDL
-
length
protected int length
-
precision
protected int precision
-
isUnique
protected boolean isUnique
-
isNullable
protected boolean isNullable
-
isUpdatable
protected boolean isUpdatable
-
isInsertable
protected boolean isInsertable
-
isCreatable
protected boolean isCreatable
-
isPrimaryKey
protected boolean isPrimaryKey
-
columnDefinition
protected String columnDefinition
-
name
protected String name
Column name of the field.
-
qualifiedName
protected String qualifiedName
PERF: Cache fully qualified table.field-name.
-
table
protected DatabaseTable table
Fields table (encapsulates name + creator).
-
type
public transient Class<?> type
Respective Java type desired for the field's value, used to optimize performance and for binding. PERF: Allow direct variable access from getObject.
-
typeName
public String typeName
-
sqlType
public int sqlType
Respective JDBC type of the field's value. This overrides the class type, which the JDBC type is normally computed from. PERF: Allow direct variable access from getObject.
-
index
public int index
Store normal index of field in result set to optimize performance. PERF: Allow direct variable access from getIndicatingNoEntry.
-
useDelimiters
protected boolean useDelimiters
-
nameForComparisons
protected String nameForComparisons
If this is set, it will be used in determining equality (unless delimiters are used) and the hashcode.- See Also:
getNameForComparisons()
-
useUpperCaseForComparisons
protected boolean useUpperCaseForComparisons
setting to true will cause getNameForComparisons to lazy initialize nameForComparisons using the value from getName().toUpperCase().
-
NULL_SQL_TYPE
public static final int NULL_SQL_TYPE
used to represent the value when it has not being defined- See Also:
- Constant Field Values
-
isTranslated
protected boolean isTranslated
Returns true if this field was translated.
-
keepInRow
public boolean keepInRow
Indicates whether the field should be kept in the record after the object is created. Used by ObjectLevelReadQuery ResultSetAccessOptimization.
-
-
Constructor Detail
-
DatabaseField
public DatabaseField()
-
DatabaseField
public DatabaseField(String qualifiedName)
-
DatabaseField
public DatabaseField(String qualifiedName, String startDelimiter, String endDelimiter)
-
DatabaseField
public DatabaseField(String fieldName, DatabaseTable databaseTable)
-
DatabaseField
public DatabaseField(String fieldName, DatabaseTable databaseTable, String startDelimiter, String endDelimiter)
-
-
Method Detail
-
initDDLFields
public void initDDLFields()
Inits the DDL generation fields with our defaults. Note: we used to initialize the length to the JPA default of 255 but since this default value should only apply for string fields we set it to 0 to indicate that it was not specified and rely on the default (255) to come from individual platforms.
-
clone
public DatabaseField clone()
The table is not cloned because it is treated as an automatic value.
-
convertClassNamesToClasses
public void convertClassNamesToClasses(ClassLoader classLoader)
-
equals
public boolean equals(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 unspecified, ie. have no name.
-
equals
public boolean equals(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 unspecified, ie. have no name.
-
getColumnDefinition
public String getColumnDefinition()
Get the SQL fragment that is used when generating the DDL for the column.
-
getIndex
public int getIndex()
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.
-
getLength
public int getLength()
Used to specify the column length when generating DDL.
-
getName
public String getName()
Return the unqualified name of the field.
-
getNameDelimited
public String getNameDelimited(DatasourcePlatform platform)
Returns this fields name with database delimiters if useDelimiters is true. This method should be called any time the field name is requested for writing SQL.
-
getPrecision
public int getPrecision()
Returns the precision for a decimal column when generating DDL.
-
getQualifiedName
public String getQualifiedName()
-
getQualifiedNameDelimited
public String getQualifiedNameDelimited(DatasourcePlatform platform)
Return the qualified name of the field. PERF: Cache the qualified name.
-
getScale
public int getScale()
Returns the scale for a decimal column when generating DDL.
-
getTable
public DatabaseTable getTable()
-
getTableName
public String getTableName()
-
setTableName
public void setTableName(String tableName)
-
getTypeName
public String getTypeName()
-
setTypeName
public void setTypeName(String typeName)
-
getSqlType
public int getSqlType()
Return the JDBC type that corresponds to the field. The JDBC type is normally determined from the class type, but this allows it to be overridden 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.
-
hashCode
public int hashCode()
Return the hashcode of the name, because it is fairly unique.
-
hasTableName
public boolean hasTableName()
-
isObjectRelationalDatabaseField
public boolean isObjectRelationalDatabaseField()
PUBLIC: Return if this is an ObjectRelationalDatabaseField.
-
isInsertable
public boolean isInsertable()
Used to specify whether the column should be included in SQL UPDATE statements.
-
isNullable
public boolean isNullable()
Used for generating DDL. Returns true if the database column is nullable.
-
isPrimaryKey
public boolean isPrimaryKey()
Used to specify whether the column should be included in the primary on the database table.
-
isTranslated
public boolean isTranslated()
Return true if this database field is a translation.
-
isUnique
public boolean isUnique()
Used for generating DDL. Returns true if the field is a unique key.
-
isReadOnly
public boolean isReadOnly()
Returns true is this database field should be read only.
-
keepInRow
public boolean keepInRow()
-
isUpdatable
public boolean isUpdatable()
Returns whether the column should be included in SQL INSERT statements.
-
resetQualifiedName
public void resetQualifiedName(String qualifiedName)
Reset the field's name and table from the qualified name.
-
setColumnDefinition
public void setColumnDefinition(String columnDefinition)
Set the SQL fragment that is used when generating the DDL for the column.
-
setIndex
public void setIndex(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.
-
setInsertable
public void setInsertable(boolean isInsertable)
Used to specify whether the column should be included in SQL UPDATE statements.
-
setKeepInRow
public void setKeepInRow(boolean keepInRow)
-
setIsTranslated
public void setIsTranslated(boolean isTranslated)
Set the isTranslated flag.
-
setLength
public void setLength(int length)
Used to specify the column length when generating DDL.
-
setName
public void setName(String name)
Set the unqualified name of the field.
-
setName
public void setName(String name, DatasourcePlatform platform)
Set the unqualified name of the field. If the name contains database delimiters, they will be stripped and a flag will be set to have them added when the DatabaseField is written to SQL
-
setName
public void setName(String name, String startDelimiter, String endDelimiter)
Set the unqualified name of the field. If the name contains database delimiters, they will be stripped and a flag will be set to have them added when the DatabaseField is written to SQL
-
setNullable
public void setNullable(boolean isNullable)
Used for generating DDL. Set to true if the database column is nullable.
-
setPrecision
public void setPrecision(int precision)
Used to specify the precision for a decimal column when generating DDL.
-
setPrimaryKey
public void setPrimaryKey(boolean isPrimaryKey)
Used to specify whether the column should be included in primary key on the database table.
-
setScale
public void setScale(int scale)
Used to specify the scale for a decimal column when generating DDL.
-
setSqlType
public void setSqlType(int sqlType)
Set the JDBC type that corresponds to the field. The JDBC type is normally determined from the class type, but this allows it to be overridden 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.
-
setTable
public void setTable(DatabaseTable table)
Set the table for the field.
-
setType
public void setType(Class<?> type)
Set the Java class type that corresponds to the field. The JDBC type is determined from the class type, this is used to optimize performance, and for binding.
-
setUnique
public void setUnique(boolean isUnique)
Used for generating DDL. Set to true if the field is a unique key.
-
setUpdatable
public void setUpdatable(boolean isUpdatable)
Used to specify whether the column should be included in SQL INSERT statements.
-
setUseDelimiters
public void setUseDelimiters(boolean useDelimiters)
-
shouldUseDelimiters
public boolean shouldUseDelimiters()
-
useUpperCaseForComparisons
public void useUpperCaseForComparisons(boolean useUpperCaseForComparisons)
INTERNAL: Sets the useUpperCaseForComparisons flag which is used to force using the uppercase version of the field's name to determine field equality and its hashcode, but will still use the original name when writing/printing operations. If this isn't a change, it is ignored, otherwise it sets the nameForComparisons to null.
-
getUseUpperCaseForComparisons
public boolean getUseUpperCaseForComparisons()
-
setNameForComparisons
public void setNameForComparisons(String name)
INTERNAL: sets the string to be used for equality checking and determining the hashcode of this field. This will overwrite the useUpperCaseForEquality setting with the passed in string.
-
isCreatable
public boolean isCreatable()
-
setCreatable
public void setCreatable(boolean isCreatable)
-
getNameForComparisons
public String getNameForComparisons()
INTERNAL: gets the string used for comparisons and in determining the hashcode.
-
-