org.apache.empire.db
Class DBTable

java.lang.Object
  extended by org.apache.empire.db.DBObject
      extended by org.apache.empire.db.DBExpr
          extended by org.apache.empire.db.DBRowSet
              extended by org.apache.empire.db.DBTable
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
DBDatabaseDriver.DBSeqTable, OracleSYSDatabase.DBColComments, OracleSYSDatabase.DBColInfo, OracleSYSDatabase.DBConstraints, OracleSYSDatabase.DBTabComments, OracleSYSDatabase.DBUserConCol

public class DBTable
extends DBRowSet
implements Cloneable

This class represent one table of the database. It contains methods to get, add, update and delete records from the database.

See Also:
Serialized Form

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

DEFAULT

public static final int DEFAULT
See Also:
Constant Field Values

SMALLINT

public static final int SMALLINT
See Also:
Constant Field Values

MEDIUMINT

public static final int MEDIUMINT
See Also:
Constant Field Values

BIGINT

public static final int BIGINT
See Also:
Constant Field Values
Constructor Detail

DBTable

public 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.

Parameters:
name - the table name
db - the valid database object
Method Detail

getName

public String getName()
Returns the table name of this object.

Specified by:
getName in class DBRowSet
Returns:
the table name of this object

getAlias

public String getAlias()
Returns the table alias name of this object.

Specified by:
getAlias in class DBRowSet
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:
isUpdateable in class DBRowSet
Returns:
true if the table allows record updates

clone

public Object 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:
clone in class Object
Returns:
a table clone with new table alias

addColumn

protected void addColumn(DBTableColumn column)
Adds a column to this table's column list.

Parameters:
column - a column object

addColumn

public final DBTableColumn addColumn(String columnName,
                                     DataType type,
                                     double size,
                                     DataMode dataMode,
                                     Object defValue)
Creates a new DBTableColumn object and adds it to the column collection.

Parameters:
columnName - the column name
type - the type of the column e.g. integer, text, date
size - the column width
dataMode - determines whether this column is optional, required or auto-generated
defValue - a Object object
Returns:
the created DBTableColumn object

addColumn

public final DBTableColumn addColumn(String columnName,
                                     DataType type,
                                     double size,
                                     DataMode dataMode)
Creates a new DBTableColumn object and adds it to the column collection.

Parameters:
columnName - the column name
type - the type of the column e.g. integer, text, date
size - the column width
dataMode - determines whether this column is optional, required or auto-generated
Returns:
the created DBTableColumn 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 name
type - the type of the column e.g. integer, text, date
size - the column width
required - true if not null column
defValue - a Object object
Returns:
the created DBTableColumn object

addColumn

public final DBTableColumn addColumn(String columnName,
                                     DataType type,
                                     double size,
                                     boolean required)
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 name
type - the type of the column e.g. integer, text, date
size - the column width
required - true if not null column
Returns:
the created DBTableColumn object

getPrimaryKey

public DBIndex getPrimaryKey()
Returns the primary key.

Returns:
the the DBIndex object ->primary key

getIndexes

public List<DBIndex> getIndexes()
Returns the list of indexes (except the primary key).

Returns:
a list of DBIndex objects

setPrimaryKey

public void setPrimaryKey(DBColumn[] columns)
Sets the primary keys.

Parameters:
columns - a array with one or more DBColumn objects

setPrimaryKey

public final void setPrimaryKey(DBColumn column)
Sets the primary key to a single column.

Parameters:
column - the primary key column

setPrimaryKey

public final void setPrimaryKey(DBColumn col1,
                                DBColumn col2)
Adds two columns to the primary key list.

Parameters:
col1 - the first column
col2 - the second column

setPrimaryKey

public final void setPrimaryKey(DBColumn col1,
                                DBColumn col2,
                                DBColumn col3)
Adds three columns to the primary key list.

Parameters:
col1 - the first column
col2 - the second column
col3 - the third column

addIndex

public DBIndex addIndex(DBIndex index)
Adds an index.

Parameters:
index - the index to add

addIndex

public final DBIndex addIndex(String name,
                              boolean unique,
                              DBColumn[] columns)
Adds an index.

Parameters:
name - the index name
unique - is this a unique index
columns - the columns indexed by this index
Returns:
the Index object

addTimestampColumn

public DBTableColumn addTimestampColumn(String columnName)
Adds a timestamp column to the table used for optimistic locking.

Parameters:
columnName - the column name
Returns:
the timestamp table column object

addSQL

public void addSQL(StringBuilder buf,
                   long context)
Adds the table's name to the supplied sql command buffer.

Specified by:
addSQL in class DBExpr
Parameters:
buf - the SQL-Command
context - the current SQL-Command context

createRecord

public void createRecord(DBRecord rec,
                         Connection conn)
Gets all table fields and the fields properties. Set this to the specified DBRecord object.

Specified by:
createRecord in class DBRowSet
Parameters:
rec - the DBRecord object. contains all fields and the field properties
conn - a valid connection to the database.

isCascadeDelete

public 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.

Returns:
true if cascade deletes (DBRelation.DBCascadeAction.CASCADE_RECORDS) are enabled

setCascadeDelete

public 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.

Parameters:
cascadeDelete - use cascade deletes (DBRelation.DBCascadeAction.CASCADE_RECORDS)

deleteRecord

public 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.

Specified by:
deleteRecord in class DBRowSet
Parameters:
key - an array of the primary key columns
conn - a valid connection to the database.

getForeignKeyRelations

public List<DBRelation> getForeignKeyRelations()
Returns a list of all foreign key relations for this table

Returns:
the list of foreign key relations


Copyright © 2008-2012 Apache Software Foundation. All Rights Reserved.