public class DBTable extends DBRowSet implements Cloneable
DBRowSet.PartialMode
Modifier and Type | Field and Description |
---|---|
static int |
BIGINT |
static int |
DEFAULT |
static int |
MEDIUMINT |
static int |
SMALLINT |
columnReferences, columns, comment, db, log, primaryKey, timestampColumn
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESES, 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 |
addColumn(String columnName,
DataType type,
double size,
DataMode dataMode)
Deprecated.
|
DBTableColumn |
addColumn(String columnName,
DataType type,
double size,
DataMode dataMode,
Object defValue)
Deprecated.
|
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(StringBuilder buf,
long context)
Adds the table's name to the supplied sql command buffer.
|
DBTableColumn |
addTimestampColumn(String columnName)
Adds a timestamp column to the table used for optimistic locking.
|
DBIndex |
checkUniqueConstraints(DBRecord rec,
Connection conn)
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 |
crateAndAppendColumn(String columnName,
DataType type,
double size,
boolean required,
Object defValue)
Creates a new Column object and appends it to the column list
|
void |
createRecord(DBRecord rec,
Connection conn)
Gets all table fields and the fields properties.
|
void |
deleteRecord(Object[] key,
Connection conn)
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).
|
String |
getName()
Returns the table name of this object.
|
DBIndex |
getPrimaryKey()
Returns the primary key.
|
protected <T extends DBTable> |
initClonedFields(T clone) |
boolean |
isUpdateable()
Returns whether or not the table supports record updates.
|
Object[] |
key(Object... keyValues)
Creates a record key from a list of key values.
|
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 keys.
|
addColumnReference, addReferencedColumns, completeInitRecord, count, deleteAllReferences, deleteRecord, deleteReferenceRecords, equals, findById, getColumn, getColumn, getColumnExprAt, getColumnIndex, getColumnIndex, getColumnReferences, getColumns, getComment, getDatabase, getFullName, getId, getKeyColumns, getRecordKey, getRenameTablePhrase, getTimestampColumn, hashCode, initRecord, initRecord, isColumnReadOnly, isKeyColumn, prepareInitRecord, readRecord, readRecord, readRecord, recordExists, recordExists, setComment, setKeyConstraints, setTimestampColumn, updateRecord
getObjectValue, getValueClass
public static final int DEFAULT
public static final int SMALLINT
public static final int MEDIUMINT
public static final int BIGINT
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 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 crateAndAppendColumn(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 object@Deprecated public final DBTableColumn addColumn(String columnName, DataType type, double size, DataMode dataMode, Object defValue)
addColumn(String columnName, DataType type, double size, boolean required, Object defValue)
instead.@Deprecated public final DBTableColumn addColumn(String columnName, DataType type, double size, DataMode dataMode)
addColumn(String columnName, DataType type, double size, boolean required)
instead.public 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 columnenumType
- defValue the default valuepublic 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 nameunique
- is this a unique indexcolumns
- 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 DBTableColumn addTimestampColumn(String columnName)
columnName
- the column namepublic void addSQL(StringBuilder buf, long context)
public void createRecord(DBRecord rec, Connection conn)
createRecord
in class DBRowSet
rec
- the DBRecord object. contains all fields and the field propertiesconn
- a valid connection to the database.public DBIndex checkUniqueConstraints(DBRecord rec, Connection conn)
id
- the record's primary keyconn
- a valid JDBC connectionpublic DBRelation.DBCascadeAction getDefaultCascadeDeleteAction()
public void setDefaultCascadeDeleteAction(DBRelation.DBCascadeAction cascadeDeleteAction)
cascadeDeleteAction
- cascade action for deletes (DBRelation.DBCascadeAction.CASCADE_RECORDS)public Object[] key(Object... keyValues)
keyValues
- public void deleteRecord(Object[] key, Connection conn)
deleteRecord
in class DBRowSet
key
- an array of the primary key columnsconn
- a valid connection to the database.public List<DBRelation> getForeignKeyRelations()
Copyright © 2008–2022 Apache Software Foundation. All rights reserved.