|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.empire.commons.ErrorObject
org.apache.empire.db.DBObject
org.apache.empire.db.DBExpr
org.apache.empire.db.DBRowSet
org.apache.empire.db.DBTable
public class DBTable
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.commons.ErrorObject |
---|
ErrorObject.ObjectErrorInfo |
Field Summary |
---|
Fields inherited from class org.apache.empire.db.DBRowSet |
---|
columnReferences, columns, comment, db, log, primaryKey, timestampColumn |
Fields inherited from class org.apache.empire.db.DBExpr |
---|
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESES, CTX_VALUE |
Constructor Summary | |
---|---|
DBTable(java.lang.String name,
DBDatabase db)
Construct a new DBTable object set the specified parameters to this object and add this object to the current database. |
Method Summary | |
---|---|
protected boolean |
addColumn(DBTableColumn column)
Adds a column to this table's column list. |
DBTableColumn |
addColumn(java.lang.String columnName,
DataType type,
double size,
boolean required)
Creates a new DBTableColumn object and adds it to the column collection. |
DBTableColumn |
addColumn(java.lang.String columnName,
DataType type,
double size,
boolean required,
java.lang.Object defValue)
Creates a new DBTableColumn object and adds it to the column collection. |
DBTableColumn |
addColumn(java.lang.String columnName,
DataType type,
double size,
DataMode dataMode)
Creates a new DBTableColumn object and adds it to the column collection. |
DBTableColumn |
addColumn(java.lang.String columnName,
DataType type,
double size,
DataMode dataMode,
java.lang.Object defValue)
Creates a new DBTableColumn object and adds it to the column collection. |
boolean |
addIndex(java.lang.String indexName,
boolean unique,
DBColumn[] indexColumns)
Adds an index. |
void |
addSQL(java.lang.StringBuilder buf,
long context)
Adds the table's name to the supplied sql command buffer. |
DBTableColumn |
addTimestampColumn(java.lang.String columnName)
Adds a timestamp column to the table used for optimistic locking. |
java.lang.Object |
clone()
Clones this table and assigns a new table alias. |
boolean |
createRecord(DBRecord rec,
java.sql.Connection conn)
Gets all table fields and the fields properties. |
boolean |
deleteRecord(java.lang.Object[] key,
java.sql.Connection conn)
Creates a delete SQL-Command by using the DBCommand getDelete method execute the the SQL-Command with the DBDatabase executeSQL method. |
java.lang.String |
getAlias()
Returns the table alias name of this object. |
java.util.List<DBIndex> |
getIndexes()
Returns the list of indexes (except the primary key). |
java.lang.String |
getName()
Returns the table name of this object. |
DBIndex |
getPrimaryKey()
Returns the primary key. |
boolean |
isCascadeDelete()
Returns true if cascaded deletes are enabled or false otherwise. |
void |
setCascadeDelete(boolean cascadeDelete)
Sets true if delete records will. |
void |
setPrimaryKey(DBColumn column)
Sets the primary key to a single column. |
boolean |
setPrimaryKey(DBColumn[] columns)
Sets the primary keys. |
void |
setPrimaryKey(DBColumn col1,
DBColumn col2)
Adds two columns to the primary key list. |
void |
setPrimaryKey(DBColumn col1,
DBColumn col2,
DBColumn col3)
Adds three columns to the primary key list. |
Methods inherited from class org.apache.empire.db.DBRowSet |
---|
addColumnReference, addReferencedColumns, completeInitRecord, count, deleteAllReferences, deleteRecord, deleteReferenceRecords, getColumn, getColumn, getColumnIndex, getColumnIndex, getColumnReferences, getColumns, getComment, getDatabase, getFullName, getKeyColumns, getRecordKey, getRenameTablePhrase, getTimestampColumn, initRecord, initRecord, isColumnReadOnly, isKeyColumn, prepareInitRecord, readRecord, readRecord, recordExists, recordExists, setComment, setKeyConstraints, setTimestampColumn, updateRecord |
Methods inherited from class org.apache.empire.db.DBExpr |
---|
getObjectValue, getValueClass |
Methods inherited from class org.apache.empire.db.DBObject |
---|
error, error |
Methods inherited from class org.apache.empire.commons.ErrorObject |
---|
clearError, clearErrorInfo, error, error, error, error, error, getErrorInfo, getErrorMessage, getErrorParams, getErrorSource, getErrorType, getMessage, hasError, internalSetError, isExceptionsEnabled, setExceptionsEnabled, success |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DBTable(java.lang.String name, DBDatabase db)
name
- the table namedb
- the valid database objectMethod Detail |
---|
public java.lang.String getName()
getName
in class DBRowSet
public java.lang.String getAlias()
getAlias
in class DBRowSet
public java.lang.Object clone()
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 java.lang.Object
protected boolean addColumn(DBTableColumn column)
column
- a column objectpublic final DBTableColumn addColumn(java.lang.String columnName, DataType type, double size, DataMode dataMode, java.lang.Object defValue)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthdataMode
- determines whether this column is optional, required or auto-generateddefValue
- a Object object
public final DBTableColumn addColumn(java.lang.String columnName, DataType type, double size, DataMode dataMode)
columnName
- the column nametype
- the type of the column e.g. integer, text, datesize
- the column widthdataMode
- determines whether this column is optional, required or auto-generated
public final DBTableColumn addColumn(java.lang.String columnName, DataType type, double size, boolean required, java.lang.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
public final DBTableColumn addColumn(java.lang.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 column
public DBIndex getPrimaryKey()
public java.util.List<DBIndex> getIndexes()
public boolean setPrimaryKey(DBColumn[] columns)
columns
- a array with one or more DBColumn objects
public final void setPrimaryKey(DBColumn column)
column
- the primary key columnpublic final void setPrimaryKey(DBColumn col1, DBColumn col2)
col1
- the first columncol2
- the second columnpublic final void setPrimaryKey(DBColumn col1, DBColumn col2, DBColumn col3)
col1
- the first columncol2
- the second columncol3
- the third columnpublic boolean addIndex(java.lang.String indexName, boolean unique, DBColumn[] indexColumns)
indexName
- the index nameunique
- is this a unique indexindexColumns
- the columns indexed by this index
public DBTableColumn addTimestampColumn(java.lang.String columnName)
columnName
- the column name
public void addSQL(java.lang.StringBuilder buf, long context)
addSQL
in class DBExpr
buf
- the SQL-Commandcontext
- the current SQL-Command contextpublic boolean createRecord(DBRecord rec, java.sql.Connection conn)
createRecord
in class DBRowSet
rec
- the DBRecord object. contains all fields and the field propertiesconn
- a valid connection to the database.
public boolean isCascadeDelete()
public void setCascadeDelete(boolean cascadeDelete)
cascadeDelete
- use cascade deletes or notpublic boolean deleteRecord(java.lang.Object[] key, java.sql.Connection conn)
deleteRecord
in class DBRowSet
key
- an array of the primary key columnsconn
- a valid connection to the database.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |