public class DBTable extends DBRowSet implements Cloneable
DBRowSet.FieldInitMode, DBRowSet.PartialMode
Modifier and Type | Field and Description |
---|---|
static int |
INT_SIZE_BIG |
static int |
INT_SIZE_DEFAULT |
static int |
INT_SIZE_MEDIUM |
static int |
INT_SIZE_SMALL |
beanType, columnReferences, columns, comment, db, entityName, log, timestampColumn
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESIS, CTX_VALUE
Constructor and Description |
---|
DBTable(String name,
DBDatabase db)
Construct a new DBTable object set the specified parameters
to this object and add this object to the current database.
|
DBTable(String name,
DBDatabase db,
String alias)
Construct a new DBTable object set the specified parameters
to this object and add this object to the current database.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addColumn(DBTableColumn column)
Adds a column to this table's column list.
|
DBTableColumn |
addColumn(String columnName,
DataType type,
double size,
boolean required)
Creates a new table column and adds it to the table's column list
|
DBTableColumn |
addColumn(String columnName,
DataType type,
double size,
boolean required,
Class<?> enumType)
Creates a new table column with Enum-Options and adds it to the table's column list
This overload should be used for column containing enum values which have no default value.
|
DBTableColumn |
addColumn(String columnName,
DataType type,
double size,
boolean required,
Enum<?> enumValue)
Creates a new table column with Enum-Options and adds it to the table's column list
This overload should be used for column containing enum values which have a default value.
|
DBTableColumn |
addColumn(String columnName,
DataType type,
double size,
boolean required,
Object defValue)
Creates a new DBTableColumn object and adds it to the column collection.
|
DBTableColumn |
addColumn(String columnName,
DataType type,
double size,
boolean required,
Options options)
Creates a new table column with options and adds it to the table's column list
This overload should be used for column containing enum values which have no default value.
|
DBTableColumn |
addColumn(String columnName,
DataType type,
double size,
boolean required,
Options options,
Object defValue)
Creates a new table column with options and adds it to the table's column list
This overload should be used for column containing enum values which have a default value.
|
DBTableColumn |
addForeignKey(String name,
DBTable target,
boolean required)
Adds a new ForgeinKey table column the column list
The foreign table must have a single column foreign key
|
DBTableColumn |
addForeignKey(String name,
DBTable target,
boolean required,
boolean cascade)
Adds a new ForgeinKey table column the column list
The foreign table must have a single column foreign key
|
DBTableColumn |
addForeignKey(String name,
DBTable target,
boolean required,
Options options,
DBRelation.DBCascadeAction cascadeAction)
Adds a new ForgeinKey table column the column list
The foreign table must have a single column foreign key
|
DBTableColumn |
addIdentity(String name)
Adds an Identity column to the table which also serves as the PrimaryKey
An Identity Column is always an auto-generated Integer(Long) value
|
DBTableColumn |
addIdentity(String name,
String seqName)
Adds an Identity column to the table which also serves as the PrimaryKey
An Identity Column is always an auto-generated Integer(Long) value
|
DBIndex |
addIndex(DBIndex index)
Adds an index.
|
DBIndex |
addIndex(String name,
boolean unique,
DBColumn... columns)
Adds an index.
|
DBIndex |
addIndex(String name,
DBIndex.DBIndexType type,
DBColumn... columns)
Adds an index.
|
void |
addSQL(DBSQLBuilder sql,
long context)
Adds the table's name to the supplied sql command buffer.
|
DBTableColumn |
addTimestamp(String name)
Adds a Timestamp column to the current table which will be used for optimistic locking.
|
DBIndex |
checkUniqueConstraints(DBRecordBase record)
Checks weather a unique constraint is violated when inserting or updating a record.
|
Object |
clone()
Clones this table and assigns a new table alias.
|
<T extends DBTable> |
clone(String newAlias) |
protected DBTableColumn |
createAndAppendColumn(String columnName,
DataType type,
double size,
boolean required,
Object defValue)
Creates a new Column object and appends it to the column list
|
void |
createRecord(DBRecordBase record,
Object[] initalKey,
boolean deferredInit)
Gets all table fields and the fields properties.
|
void |
deleteRecord(Object[] key,
DBContext context)
Creates a delete SQL-Command by using the DBCommand getDelete method
execute the the SQL-Command with the DBDatabase
executeSQL method.
|
String |
getAlias()
Returns the table alias name of this object.
|
DBRelation.DBCascadeAction |
getDefaultCascadeDeleteAction()
returns the default cascade action for deletes on this table.
|
List<DBRelation> |
getForeignKeyRelations()
Returns a list of all foreign key relations for this table
|
List<DBIndex> |
getIndexes()
Returns the list of indexes (except the primary key).
|
DBColumn[] |
getKeyColumns()
Returns an array of all primary key columns.
|
String |
getName()
Returns the table name of this object.
|
DBIndex |
getPrimaryKey()
Returns the primary key.
|
protected <T extends DBTable> |
initClonedFields(T clone) |
protected void |
initRecordDefaultValues(DBRecordBase record,
DBRowSet.FieldInitMode fieldInitMode)
initializes the Record Default Values
|
boolean |
isUpdateable()
Returns whether or not the table supports record updates.
|
void |
removeIndex(DBIndex index)
removes an index.
|
void |
setDefaultCascadeDeleteAction(DBRelation.DBCascadeAction cascadeDeleteAction)
sets the default cascade action for deletes on foreign key relations.
|
void |
setPrimaryKey(DBColumn... columns)
Sets the primary key.
|
protected Object |
validateValue(DBTableColumn column,
Object value)
validates a column value
|
addColumnReference, addReferencedColumns, checkParamRecord, completeInitRecord, count, createRecordCommand, deleteAllReferences, deleteRecord, deleteReferenceRecords, equals, getBeanType, getColumn, getColumn, getColumnExprAt, getColumnIndex, getColumnIndex, getColumnReferences, getColumns, getComment, getDatabase, getEntityName, getFullName, getIdentifier, getKeyConstraints, getRenameTablePhrase, getRowsetData, getTimestampColumn, hashCode, initRecord, initRecord, isColumnReadOnly, isKeyColumn, isSame, key, on, on, prepareInitRecord, readRecord, readRecord, readRecord, recordExists, recordExists, setBeanType, setBeanType, setComment, setEntityName, setRowsetData, setTimestampColumn, updateRecord
checkParamNull
public static final int INT_SIZE_DEFAULT
public static final int INT_SIZE_SMALL
public static final int INT_SIZE_MEDIUM
public static final int INT_SIZE_BIG
public DBTable(String name, DBDatabase db, String alias)
name
- the table namedb
- the valid database objectpublic DBTable(String name, DBDatabase db)
name
- the table namedb
- the valid database objectpublic String getName()
public String getAlias()
public boolean isUpdateable()
isUpdateable
in class DBRowSet
public DBColumn[] getKeyColumns()
getKeyColumns
in interface EntityType
getKeyColumns
in class DBRowSet
public Object clone() throws CloneNotSupportedException
This method requires that all declared column fields are NOT declared final. i.e. instead of: public final DBTableColumn MYCOL; columns must be declared: public DBTableColumn MYCOL; A runtime exception for the CloneNotSupported will be thrown if references cannot be adjusted. Alternatively a second table instance may be created manually like this: public final MyTable MYTABLE1 = new MyTable(); public final MyTable MYTABLE2 = new MyTable(); ... cmd.join(MYTABLE1.ID, MYTABLE2.PARENTID); // self-join ...
clone
in class Object
CloneNotSupportedException
protected <T extends DBTable> void initClonedFields(T clone) throws CloneNotSupportedException
CloneNotSupportedException
protected void addColumn(DBTableColumn column)
column
- a column objectprotected DBTableColumn createAndAppendColumn(String columnName, DataType type, double size, boolean required, Object defValue)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthrequired
- true if not null columndefValue
- a Object objectpublic final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Object defValue)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthrequired
- true if not null columndefValue
- a Object objectpublic final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthrequired
- true if not null columnpublic final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Options options)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthrequired
- true if not null columnoptions
- this list of optionspublic final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Options options, Object defValue)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthrequired
- true if not null columnoptions
- this list of optionsdefValue
- the default valuepublic final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Class<?> enumType)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthrequired
- true if not null columnenumType
- the class of the enum typepublic final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Enum<?> enumValue)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthrequired
- true if not null columnenumValue
- the default valuepublic DBTableColumn addIdentity(String name, String seqName)
name
- the name of the identity columnseqName
- (optional) name of the sequence if supported by DBMSpublic final DBTableColumn addIdentity(String name)
name
- the name of the identity columnpublic DBTableColumn addForeignKey(String name, DBTable target, boolean required, Options options, DBRelation.DBCascadeAction cascadeAction)
name
- the name of the new columntarget
- the table on which to referencerequired
- true if the value is requiredoptions
- (optional) a set of allowed values for this columnpublic final DBTableColumn addForeignKey(String name, DBTable target, boolean required, boolean cascade)
name
- the name of the new columntarget
- the table on which to referencerequired
- true if the value is requiredcascade
- whether or not to cascade deletes for this relationpublic final DBTableColumn addForeignKey(String name, DBTable target, boolean required)
name
- the name of the new columntarget
- the table on which to referencerequired
- true if the value is requiredpublic DBTableColumn addTimestamp(String name)
name
- the name of the new columnpublic DBIndex getPrimaryKey()
public List<DBIndex> getIndexes()
public void setPrimaryKey(DBColumn... columns)
columns
- a array with one or more DBColumn objectspublic final DBIndex addIndex(String name, DBIndex.DBIndexType type, DBColumn... columns)
name
- the index nametype
- the index typecolumns
- the columns indexed by this indexpublic final DBIndex addIndex(String name, boolean unique, DBColumn... columns)
public void removeIndex(DBIndex index)
index
- the index to removepublic void addSQL(DBSQLBuilder sql, long context)
public void createRecord(DBRecordBase record, Object[] initalKey, boolean deferredInit)
createRecord
in class DBRowSet
record
- the DBRecord object. contains all fields and the field propertiesinitalKey
- the initial key valuesdeferredInit
- flag whether to defer initializationpublic DBIndex checkUniqueConstraints(DBRecordBase record)
record
- the record to checkpublic DBRelation.DBCascadeAction getDefaultCascadeDeleteAction()
public void setDefaultCascadeDeleteAction(DBRelation.DBCascadeAction cascadeDeleteAction)
cascadeDeleteAction
- cascade action for deletes (DBRelation.DBCascadeAction.CASCADE_RECORDS)public void deleteRecord(Object[] key, DBContext context)
deleteRecord
in class DBRowSet
key
- an array of the primary key columnscontext
- the database contextpublic List<DBRelation> getForeignKeyRelations()
protected Object validateValue(DBTableColumn column, Object value)
protected void initRecordDefaultValues(DBRecordBase record, DBRowSet.FieldInitMode fieldInitMode)
initRecordDefaultValues
in class DBRowSet
record
- the recordfieldInitMode
- the field initialization modeCopyright © 2008–2023 Apache Software Foundation. All rights reserved.