org.apache.empire.db
Class DBRowSet

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
All Implemented Interfaces:
ErrorInfo
Direct Known Subclasses:
DBQuery, DBTable, DBView

public abstract class DBRowSet
extends DBExpr

This class is the base class for all the DBTable, CBView and DBQuery classes this class contains all the columns of the tables, views or querys


Field Summary
 
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
DBRowSet(DBDatabase db)
          Constructs a DBRecord object set the current database object.
 
Method Summary
 void addReferencedColumns(java.util.Set<DBColumn> list)
          Internal function to obtain all DBColumnExpr-objects used by this expression.
 DBColumnExpr count()
          Returns a new DBCountExpr object.
abstract  boolean createRecord(DBRecord rec, java.sql.Connection conn)
           
abstract  boolean deleteRecord(java.lang.Object[] keys, java.sql.Connection conn)
           
 boolean deleteRecord(java.lang.Object id, java.sql.Connection conn)
          Deletes a single record from the database.
abstract  java.lang.String getAlias()
           
 DBColumn getColumn(int iColumn)
          Returns a DBColumn object by a specified index value.
 DBColumn getColumn(java.lang.String name)
          Gets the column Expression with a particular name.
 int getColumnIndex(Column column)
          Gets the index of a particular column expression.
 int getColumnIndex(DBColumn column)
          Gets the index of a particular column expression.
 java.util.Map<DBColumn,DBColumn> getColumnReferences()
          Returns the a list of column references.
 java.util.List<DBColumn> getColumns()
          Gets all columns of this rowset (e.g. for cmd.select()).
 java.lang.String getComment()
           
 DBDatabase getDatabase()
          Returns the current DBDatabase object.
 java.lang.String getFullName()
          Returns the full qualified name of the rowset.
 DBColumn[] getKeyColumns()
          Returns an array of all primary key columns.
abstract  java.lang.String getName()
           
 java.lang.Object[] getRecordKey(DBRecord rec)
          Returns a array of primary key columns by a specified DBRecord object.
 DBColumn getTimestampColumn()
           
 boolean initRecord(DBRecord rec, DBRecordData recData)
          Initializes a DBRecord for this rowset using the record data provided (i.e. from a DBReader)
The record may then be modified and updated.
 boolean initRecord(DBRecord rec, java.lang.Object[] keyValues)
          Initializes a DBRecord for this RowSet and sets primary key values (the Object[] keyValues).
 boolean isColumnReadOnly(DBColumn col)
          Checks whether a column is read only or writable.
 boolean isKeyColumn(DBColumn column)
          Checks whether a given column is part of the primary key for this RowSet
 boolean readRecord(DBRecord rec, java.lang.Object[] key, java.sql.Connection conn)
          Reads the record with the given primary key from the database.
 boolean recordExists(java.lang.Object[] key, java.sql.Connection conn)
          Returns true if the record exists in the database or false otherwise.
 boolean recordExists(java.lang.Object id, java.sql.Connection conn)
          Returns true if the record exists in the database or false otherwise.
 void setComment(java.lang.String comment)
           
 void setTimestampColumn(DBColumn timestampColumn)
           
 boolean updateRecord(DBRecord rec, java.sql.Connection conn)
          Updates or Inserts a record in the database.
 
Methods inherited from class org.apache.empire.db.DBExpr
addSQL, getValueClass
 
Methods inherited from class org.apache.empire.commons.ErrorObject
clearError, getErrorMessage, getErrorParams, getErrorSource, getErrorType, getMessage, hasError, isExceptionsEnabled, setExceptionsEnabled
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBRowSet

public DBRowSet(DBDatabase db)
Constructs a DBRecord object set the current database object.

Method Detail

getName

public abstract java.lang.String getName()

getAlias

public abstract java.lang.String getAlias()

createRecord

public abstract boolean createRecord(DBRecord rec,
                                     java.sql.Connection conn)

deleteRecord

public abstract boolean deleteRecord(java.lang.Object[] keys,
                                     java.sql.Connection conn)

getFullName

public java.lang.String getFullName()
Returns the full qualified name of the rowset.

Returns:
the full qualified name

addReferencedColumns

public void addReferencedColumns(java.util.Set<DBColumn> list)
Description copied from class: DBExpr
Internal function to obtain all DBColumnExpr-objects used by this expression.

Specified by:
addReferencedColumns in class DBExpr
Parameters:
list - list to which all used column expressions must be added
See Also:
DBExpr.addReferencedColumns(Set)

getDatabase

public final DBDatabase getDatabase()
Returns the current DBDatabase object.

Specified by:
getDatabase in class DBObject
Returns:
the current DBDatabase object

getColumns

public java.util.List<DBColumn> getColumns()
Gets all columns of this rowset (e.g. for cmd.select()).

Returns:
all columns of this rowset

getColumnIndex

public int getColumnIndex(DBColumn column)
Gets the index of a particular column expression.

Returns:
the position of a column expression

getColumnIndex

public final int getColumnIndex(Column column)
Gets the index of a particular column expression.

Returns:
the position of a column expression

getColumn

public DBColumn getColumn(int iColumn)
Returns a DBColumn object by a specified index value.

Returns:
the index value

getColumn

public DBColumn getColumn(java.lang.String name)
Gets the column Expression with a particular name.

Returns:
the column Expression at position

isColumnReadOnly

public boolean isColumnReadOnly(DBColumn col)
Checks whether a column is read only or writable. Only the timestamp column is read only by default. The primary is read only if the column is of type.

Returns:
a new DBCountExpr object

getKeyColumns

public DBColumn[] getKeyColumns()
Returns an array of all primary key columns.

Returns:
an array of all primary key columns

isKeyColumn

public boolean isKeyColumn(DBColumn column)
Checks whether a given column is part of the primary key for this RowSet

Parameters:
column - the column to check
Returns:
true if the column is part of the primary key or false otherwise

getComment

public java.lang.String getComment()
Returns:
Returns the comment.

setComment

public void setComment(java.lang.String comment)
Parameters:
comment - The comment to set.

getTimestampColumn

public DBColumn getTimestampColumn()
Returns:
Returns the timestampColumn.

setTimestampColumn

public void setTimestampColumn(DBColumn timestampColumn)
Parameters:
timestampColumn - The timestampColumn to set.

getColumnReferences

public java.util.Map<DBColumn,DBColumn> getColumnReferences()
Returns the a list of column references.

Returns:
a list of references

count

public DBColumnExpr count()
Returns a new DBCountExpr object.

Returns:
a new DBCountExpr object

getRecordKey

public java.lang.Object[] getRecordKey(DBRecord rec)
Returns a array of primary key columns by a specified DBRecord object.

Parameters:
rec - the DBRecord object, contains all fields and the field properties
Returns:
a array of primary key columns

initRecord

public boolean initRecord(DBRecord rec,
                          java.lang.Object[] keyValues)
Initializes a DBRecord for this RowSet and sets primary key values (the Object[] keyValues). The record may then be modified and updated.

Parameters:
rec - the Record object
keyValues - an array of the primary key columns
Returns:
true if successful

initRecord

public boolean initRecord(DBRecord rec,
                          DBRecordData recData)
Initializes a DBRecord for this rowset using the record data provided (i.e. from a DBReader)
The record may then be modified and updated.
At least all primary key columns must be supplied.
We strongly recommend to supply the value of the update timestamp column in order to detect concurrent changes.
Fields for which no value is supplied with the recData paramter are set to NO_VALUE

Parameters:
rec - the record object
recData - the record data from which to initialized the record
Returns:
true if successful

readRecord

public boolean readRecord(DBRecord rec,
                          java.lang.Object[] key,
                          java.sql.Connection conn)
Reads the record with the given primary key from the database.

Parameters:
rec - the DBRecord object which will hold the record data
key - the primary key values
conn - a valid JDBC connection.
Returns:
true if successful

recordExists

public boolean recordExists(java.lang.Object[] key,
                            java.sql.Connection conn)
Returns true if the record exists in the database or false otherwise.

Parameters:
key - an array of the primary key columns
conn - a valid JDBC connection.
Returns:
true if successful or false otherwise

recordExists

public final boolean recordExists(java.lang.Object id,
                                  java.sql.Connection conn)
Returns true if the record exists in the database or false otherwise.

Parameters:
id - id of the record
conn - a valid JDBC connection.
Returns:
true if successful or false otherwise

updateRecord

public boolean updateRecord(DBRecord rec,
                            java.sql.Connection conn)
Updates or Inserts a record in the database.
Whether an update or insert is performed depends on the record state.
Only modified fields will be inserted or updated in the database.

If a timestamp-column is set for this RowSet then a constraint will be added in the update statement in order to detect concurrent changes.
If the record has been modified by another user, an error of type DBErrors.RecordUpdateFailed will be set.

Parameters:
rec - the DBRecord object. contains all fields and the field properties
conn - a valid JDBC connection.
Returns:
true if the update was sucessful or false otherwise

deleteRecord

public final boolean deleteRecord(java.lang.Object id,
                                  java.sql.Connection conn)
Deletes a single record from the database.

Parameters:
id - the record's primary key
conn - a valid JDBC connection
Returns:
true if the record has been successfully deleted or false otherwise