Package org.apache.empire.db
Class DBTable
java.lang.Object
org.apache.empire.db.DBObject
org.apache.empire.db.DBExpr
org.apache.empire.db.DBRowSet
org.apache.empire.db.DBTable
- Direct Known Subclasses:
DBMSHandlerBase.DBSeqTable,OracleSYSDatabase.DBColComments,OracleSYSDatabase.DBColInfo,OracleSYSDatabase.DBConstraints,OracleSYSDatabase.DBTabComments,OracleSYSDatabase.DBUserConCol,TTable
This class represent one table of the database.
It contains methods to get, add, update and delete records from the database.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.empire.db.DBRowSet
DBRowSet.FieldInitMode, DBRowSet.PartialMode -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intFields inherited from class org.apache.empire.db.DBRowSet
attributes, beanType, columnReferences, columns, comment, db, entityName, log, timestampColumnFields inherited from class org.apache.empire.db.DBExpr
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESIS, CTX_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionDBTable(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. -
Method Summary
Modifier and TypeMethodDescriptionfinal DBTableColumnCreates a new table column and adds it to the table's column listfinal DBTableColumnaddColumn(String columnName, DataType type, double size, boolean required, Class<? extends Enum<?>> 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.final DBTableColumnCreates 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.final DBTableColumnCreates a new DBTableColumn object and adds it to the column collection.final DBTableColumnCreates 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.final DBTableColumnaddColumn(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.protected voidaddColumn(DBTableColumn column) Adds a column to this table's column list.final DBTableColumnaddForeignKey(String name, DBTable target, boolean required) Adds a new ForgeinKey table column the column list The foreign table must have a single column foreign keyfinal DBTableColumnaddForeignKey(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 keyaddForeignKey(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 keyfinal DBTableColumnaddIdentity(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) valueaddIdentity(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) valuefinal DBIndexAdds an index.final DBIndexaddIndex(String name, DBIndex.DBIndexType type, DBColumn... columns) Adds an index.Adds an index.voidaddSQL(DBSQLBuilder sql, long context) Adds the table's name to the supplied sql command buffer.addTimestamp(String name) Adds a Timestamp column to the current table which will be used for optimistic locking.checkUniqueConstraints(DBRecordBase record) Checks weather a unique constraint is violated when inserting or updating a record.clone()Clones this table and assigns a new table alias.<T extends DBTable>
Tprotected DBColumncloneColumn(DBRowSet clone, DBColumn sourceColumn) Clones a RowSet columnprotected DBIndexclonePrimaryKey(DBRowSet clone) protected DBTableColumncreateAndAppendColumn(String columnName, DataType type, double size, boolean required, Object defValue) Creates a new Column object and appends it to the column listvoidcreateRecord(DBRecordBase record, Object[] initalKey, boolean deferredInit) Gets all table fields and the fields properties.voiddeleteRecord(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.protected StringgenerateAlias(String prefix) Automatically generates a new alias for this ObjectgetAlias()Returns the table alias name of this object.returns the default cascade action for deletes on this table.getExistingReferenceTables(Object[] key, DBContext context) Returns a list of all tables that contain records which reference this recordReturns a list of all foreign key relations for this tableReturns the list of indexes (except the primary key).DBColumn[]Returns an array of all primary key columns.getName()Returns the table name of this object.Returns the primary key.booleanhasExistingReferences(Object[] key, DBContext context) Determines whether a record is references by other records through a foreign-key relation or notprotected voidinitRecordDefaultValues(DBRecordBase record, DBRowSet.FieldInitMode fieldInitMode) initializes the Record Default ValuesbooleanReturns whether or not the table supports record updates.voidremoveIndex(DBIndex index) removes an index.voidsetDefaultCascadeDeleteAction(DBRelation.DBCascadeAction cascadeDeleteAction) sets the default cascade action for deletes on foreign key relations.voidsetPrimaryKey(DBColumn... columns) Sets the primary key.protected ObjectvalidateValue(DBTableColumn column, Object value) validates a column valueMethods inherited from class org.apache.empire.db.DBRowSet
addColumnReference, addReferencedColumns, checkParamRecord, completeInitRecord, count, createRecordCommand, deleteAllReferences, deleteRecord, deleteReferenceRecords, equals, getAllColumns, getAttribute, getAttributes, getBeanType, getColumn, getColumn, getColumnCount, getColumnExprAt, getColumnIndex, getColumnIndex, getColumnReferences, getColumns, getComment, getDatabase, getEntityName, getFullName, getIdentifier, getKeyConstraints, getRenameTablePhrase, getRowsetData, getTimestampColumn, hashCode, initClonedFields, initRecord, initRecord, initRecord, isColumnReadOnly, isKeyColumn, isSame, key, on, on, prepareInitRecord, readRecord, readRecord, readRecord, recordExists, recordExists, setAttribute, setBeanType, setBeanType, setComment, setEntityName, setRowsetData, setTimestampColumn, updateRecordMethods inherited from class org.apache.empire.db.DBObject
checkParamNull
-
Field Details
-
INT_SIZE_DEFAULT
public static final int INT_SIZE_DEFAULT- See Also:
-
INT_SIZE_SMALL
public static final int INT_SIZE_SMALL- See Also:
-
INT_SIZE_MEDIUM
public static final int INT_SIZE_MEDIUM- See Also:
-
INT_SIZE_BIG
public static final int INT_SIZE_BIG- See Also:
-
-
Constructor Details
-
DBTable
Construct a new DBTable object set the specified parameters to this object and add this object to the current database.- Parameters:
name- the table namedb- the valid database objectalias- the table alias
-
DBTable
Construct a new DBTable object set the specified parameters to this object and add this object to the current database.- Parameters:
name- the table namedb- the valid database object
-
-
Method Details
-
generateAlias
Automatically generates a new alias for this Object- Parameters:
prefix- the alias prefix- Returns:
- an alias consisting of the prefix and a unique number
-
getName
Returns the table name of this object. -
getAlias
Returns the table alias name of this object. -
isUpdateable
public boolean isUpdateable()Returns whether or not the table supports record updates. Default is true.- Specified by:
isUpdateablein classDBRowSet- Returns:
- true if the table allows record updates
-
getKeyColumns
Returns an array of all primary key columns.- Specified by:
getKeyColumnsin interfaceEntity- Specified by:
getKeyColumnsin classDBRowSet- Returns:
- an array of all primary key columns
-
clone
Clones this table and assigns a new table alias. This second instance of the same table can be used for self-joins.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 ...- Overrides:
clonein classObject- Returns:
- a table clone with new table alias
- Throws:
CloneNotSupportedException
-
clone
-
cloneColumn
Description copied from class:DBRowSetClones a RowSet column- Specified by:
cloneColumnin classDBRowSet- Parameters:
clone- the cloned rowsetsourceColumn- the source column- Returns:
- the cloned column
-
clonePrimaryKey
-
addColumn
Adds a column to this table's column list.- Parameters:
column- a column object
-
createAndAppendColumn
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- Parameters:
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- Returns:
- the new column object
-
addColumn
public final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Object defValue) Creates a new DBTableColumn object and adds it to the column collection. Instead of the data mode enum, a boolean flag is used to indicate whether the column is required or optional.- Parameters:
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- Returns:
- the new column object
-
addColumn
public final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required) Creates a new table column and adds it to the table's column list- Parameters:
columnName- the column nametype- the type of the column e.g. integer, text, datesize- the column widthrequired- true if not null column- Returns:
- the new column object
-
addColumn
public final 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.- Parameters:
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 options- Returns:
- the new column object
-
addColumn
public final 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.- Parameters:
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 value- Returns:
- the new column object
-
addColumn
public final DBTableColumn addColumn(String columnName, DataType type, double size, boolean required, Class<? extends Enum<?>> 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.- Parameters:
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 type- Returns:
- the new column object
-
addColumn
public final 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.- Parameters:
columnName- the column nametype- the type of the column e.g. integer, text, datesize- the column widthrequired- true if not null columnenumValue- the default value- Returns:
- the new column object
-
addIdentity
Adds an Identity column to the table which also serves as the PrimaryKey An Identity Column is always an auto-generated Integer(Long) value- Parameters:
name- the name of the identity columnseqName- (optional) name of the sequence if supported by DBMS- Returns:
- the Identity column
-
addIdentity
Adds an Identity column to the table which also serves as the PrimaryKey An Identity Column is always an auto-generated Integer(Long) value- Parameters:
name- the name of the identity column- Returns:
- the Identity column
-
addForeignKey
public 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- Parameters:
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 columncascadeAction- the cascade action- Returns:
- the new column
-
addForeignKey
public final 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- Parameters:
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 relation- Returns:
- the new column
-
addForeignKey
Adds a new ForgeinKey table column the column list The foreign table must have a single column foreign key- Parameters:
name- the name of the new columntarget- the table on which to referencerequired- true if the value is required- Returns:
- the new column
-
addTimestamp
Adds a Timestamp column to the current table which will be used for optimistic locking. There can only be one timestamp column per table- Parameters:
name- the name of the new column- Returns:
- the new column
-
getPrimaryKey
Returns the primary key.- Returns:
- the the DBIndex object -> primary key
-
getIndexes
Returns the list of indexes (except the primary key).- Returns:
- a list of DBIndex objects
-
setPrimaryKey
Sets the primary key.- Parameters:
columns- a array with one or more DBColumn objects
-
addIndex
Adds an index.- Parameters:
index- the index to add- Returns:
- the Index object
-
addIndex
Adds an index.- Parameters:
name- the index nametype- the index typecolumns- the columns indexed by this index- Returns:
- the Index object
-
addIndex
Adds an index. Overload for convenience- Parameters:
name- the index nameunique- flag whether the index is uniquecolumns- the index column- Returns:
- the index object
-
removeIndex
removes an index.- Parameters:
index- the index to remove
-
addSQL
Adds the table's name to the supplied sql command buffer. -
createRecord
Gets all table fields and the fields properties. Set this to the specified DBRecord object.- Specified by:
createRecordin classDBRowSet- Parameters:
record- the DBRecord object. contains all fields and the field propertiesinitalKey- the initial key valuesdeferredInit- flag whether to defer initialization
-
checkUniqueConstraints
Checks weather a unique constraint is violated when inserting or updating a record.- Parameters:
record- the record to check- Returns:
- the violated index
-
getDefaultCascadeDeleteAction
returns the default cascade action for deletes on this table. This is used as the default for newly created relations on this table and does not affect existing relations.- Returns:
- the delete cascade action for new relations (DBRelation.DBCascadeAction.CASCADE_RECORDS) are enabled
-
setDefaultCascadeDeleteAction
sets the default cascade action for deletes on foreign key relations.- Parameters:
cascadeDeleteAction- cascade action for deletes (DBRelation.DBCascadeAction.CASCADE_RECORDS)
-
deleteRecord
Creates a delete SQL-Command by using the DBCommand getDelete method execute the the SQL-Command with the DBDatabase executeSQL method.- Specified by:
deleteRecordin classDBRowSet- Parameters:
key- an array of the primary key columnscontext- the database context
-
getForeignKeyRelations
Returns a list of all foreign key relations for this table- Returns:
- the list of foreign key relations
-
hasExistingReferences
Determines whether a record is references by other records through a foreign-key relation or not- Parameters:
key- the key the record to be deletedcontext- the db context- Returns:
- true if the record is references or false otherwise
-
getExistingReferenceTables
Returns a list of all tables that contain records which reference this record- Parameters:
key- the key the record to be deletedcontext- the db context- Returns:
- this list of all tables that contain a refernce to this record
-
validateValue
validates a column value- Parameters:
column- the columnvalue- the value to validate- Returns:
- the validated (possibly converted) value
-
initRecordDefaultValues
initializes the Record Default Values- Overrides:
initRecordDefaultValuesin classDBRowSet- Parameters:
record- the recordfieldInitMode- the field initialization mode
-