org.apache.empire.db
Class DBTable

java.lang.Object
  extended by org.apache.empire.commons.ErrorObject
      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:
java.lang.Cloneable, ErrorInfo
Direct Known Subclasses:
DBDatabaseDriver.DBSeqTable, OracleSYSDatabase.DBColComments, OracleSYSDatabase.DBColInfo, OracleSYSDatabase.DBConstraints, OracleSYSDatabase.DBTabComments, OracleSYSDatabase.DBUserConCol, SampleAdvDB.Departments, SampleAdvDB.EmployeeDepartmentHistory, SampleAdvDB.Employees, SampleDB.Departments, SampleDB.Departments, SampleDB.Employees, SampleDB.Employees, SampleTable

public class DBTable
extends DBRowSet
implements java.lang.Cloneable

This class represent one table of the database. It consits 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 add it to this object.
 DBTableColumn addColumn(java.lang.String columnName, DataType type, double size, boolean required, java.lang.Object defValue)
          Creates a new DBTableColumn object and add it to this object.
 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 object.
 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, 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, 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

DBTable

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

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

getName

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

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

getAlias

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

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

clone

public java.lang.Object clone()
Clones this object.

Overrides:
clone in class java.lang.Object
Returns:
this cloned Object

addColumn

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

Parameters:
column - a column object

addColumn

public final DBTableColumn addColumn(java.lang.String columnName,
                                     DataType type,
                                     double size,
                                     boolean required,
                                     java.lang.Object defValue)
Creates a new DBTableColumn object and add it to this object.

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(java.lang.String columnName,
                                     DataType type,
                                     double size,
                                     boolean required)
Creates a new DBTableColumn object and add it to this object.

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 java.util.List<DBIndex> getIndexes()
Returns the list of indexes (except the primary key).

Returns:
a list of DBIndex objects

setPrimaryKey

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

Parameters:
columns - a array with one or more DBColumn objects
Returns:
true on succes

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 boolean addIndex(java.lang.String indexName,
                        boolean unique,
                        DBColumn[] indexColumns)
Adds an index.

Parameters:
indexName - the index name
unique - is this a unique index
indexColumns - the columns indexed by this index
Returns:
true on succes

addTimestampColumn

public DBTableColumn addTimestampColumn(java.lang.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(java.lang.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 boolean createRecord(DBRecord rec,
                            java.sql.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.
Returns:
true if successful

isCascadeDelete

public boolean isCascadeDelete()
Returns true if cascaded deletes are enabled or false otherwise.

Returns:
true if cascade deletes are enabled

setCascadeDelete

public void setCascadeDelete(boolean cascadeDelete)
Sets true if delete records will.

Parameters:
cascadeDelete - use cascade deletes or not

deleteRecord

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

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


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