|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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.
Field Summary | |
---|---|
static int |
BIGINT
|
static int |
DEFAULT
|
static int |
MEDIUMINT
|
static int |
SMALLINT
|
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(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 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 DBTableColumn object and adds it to the column collection. |
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,
DataMode dataMode)
Creates a new DBTableColumn object and adds it to the column collection. |
DBTableColumn |
addColumn(String columnName,
DataType type,
double size,
DataMode dataMode,
Object defValue)
Creates a new DBTableColumn object and adds it to the column collection. |
DBIndex |
addIndex(DBIndex index)
Adds an index. |
DBIndex |
addIndex(String name,
boolean unique,
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. |
Object |
clone()
Clones this table and assigns a new table alias. |
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. |
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. |
boolean |
isCascadeDelete()
Deprecated. Deprecated flag that indicates whether cascaded deletes are enabled on this table. This property will be removed in future releases. Use DBRelation.getOnDeleteAction() instead. |
boolean |
isUpdateable()
Returns whether or not the table supports record updates. |
void |
setCascadeDelete(boolean cascadeDelete)
Deprecated. Deprecated flag that enables cascaded deletes on foreign key relations. WARING: The flag only affects newly created relations referring to this table. This property will be removed in future releases. Use DBRelation.setOnDeleteAction() instead. |
void |
setPrimaryKey(DBColumn column)
Sets the primary key to a single column. |
void |
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, equals, findById, getColumn, getColumn, getColumnIndex, getColumnIndex, getColumnReferences, getColumns, getComment, getDatabase, getFullName, getId, 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 java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT
public static final int SMALLINT
public static final int MEDIUMINT
public static final int BIGINT
Constructor Detail |
---|
public DBTable(String name, DBDatabase db)
name
- the table namedb
- the valid database objectMethod Detail |
---|
public String getName()
getName
in class DBRowSet
public String getAlias()
getAlias
in class DBRowSet
public boolean isUpdateable()
isUpdateable
in class DBRowSet
public 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 Object
protected void addColumn(DBTableColumn column)
column
- a column objectpublic final DBTableColumn addColumn(String columnName, DataType type, double size, DataMode dataMode, 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(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(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
public 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 column
public DBIndex getPrimaryKey()
public List<DBIndex> getIndexes()
public void setPrimaryKey(DBColumn[] columns)
columns
- a array with one or more DBColumn objectspublic 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 DBIndex addIndex(DBIndex index)
index
- the index to addpublic final DBIndex addIndex(String name, boolean unique, DBColumn[] columns)
name
- the index nameunique
- is this a unique indexcolumns
- the columns indexed by this index
public DBTableColumn addTimestampColumn(String columnName)
columnName
- the column name
public void addSQL(StringBuilder buf, long context)
addSQL
in class DBExpr
buf
- the SQL-Commandcontext
- the current SQL-Command contextpublic 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 boolean isCascadeDelete()
public void setCascadeDelete(boolean cascadeDelete)
cascadeDelete
- use cascade deletes (DBRelation.DBCascadeAction.CASCADE_RECORDS)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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |