org.apache.empire.db
Class DBRowSet

java.lang.Object
  extended by org.apache.empire.db.DBObject
      extended by org.apache.empire.db.DBExpr
          extended by org.apache.empire.db.DBRowSet
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DBCommandExpr.DBCmdQuery, DBQuery, DBTable, DBView

public abstract class DBRowSet
extends DBExpr

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

See Also:
Serialized Form

Field Summary
protected  Map<DBColumn,DBColumn> columnReferences
           
protected  List<DBColumn> columns
           
protected  String comment
           
protected  DBDatabase db
           
protected static org.slf4j.Logger log
           
protected  DBIndex primaryKey
           
protected  DBColumn 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
DBRowSet(DBDatabase db)
          Constructs a DBRecord object set the current database object.
 
Method Summary
protected  void addColumnReference(DBColumn source, DBColumn target)
          Adds a column reference to the list of table references.
 void addReferencedColumns(Set<DBColumn> list)
          Internal function to obtain all DBColumnExpr-objects used by this expression.
protected  void completeInitRecord(DBRecord rec)
          Completes the record initialization.
Override this function to do post initialization processing.
 DBColumnExpr count()
          Returns a new DBCountExpr object.
abstract  void createRecord(DBRecord rec, Connection conn)
           
protected  void deleteAllReferences(Object[] key, Connection conn)
          Deletes all records which reference this table.
abstract  void deleteRecord(Object[] keys, Connection conn)
           
 void deleteRecord(Object id, Connection conn)
          Deletes a single record from the database.
protected  void deleteReferenceRecords(DBRelation.DBReference[] refs, Object[] parentKey, Connection conn)
          Deletes all records which are referenced by a particular relation.
 boolean equals(Object other)
           
static DBRowSet findById(String rowsetId)
          returns a rowset by its identifier
abstract  String getAlias()
           
 DBColumn getColumn(int iColumn)
          Returns a DBColumn object by a specified index value.
 DBColumn getColumn(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.
 Map<DBColumn,DBColumn> getColumnReferences()
          Returns the a list of column references.
 List<DBColumn> getColumns()
          Gets all columns of this rowset (e.g.
 String getComment()
           
 DBDatabase getDatabase()
          Returns the current DBDatabase object.
 String getFullName()
          Returns the full qualified name of the rowset.
 String getId()
          Gets an identifier for this RowSet Object
 DBColumn[] getKeyColumns()
          Returns an array of all primary key columns.
abstract  String getName()
           
 Object[] getRecordKey(DBRecord rec)
          Returns a array of primary key columns by a specified DBRecord object.
protected  String getRenameTablePhrase()
          Returns the sql phrase for renaming tables.
 DBColumn getTimestampColumn()
           
 void initRecord(DBRecord rec, DBRecordData recData)
          Initializes a DBRecord for this rowset using the record data provided (i.e.
 void initRecord(DBRecord rec, 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
abstract  boolean isUpdateable()
           
protected  void prepareInitRecord(DBRecord rec, int state, Object rowSetData)
          Initialize this DBRowSet object and sets it's initial state.
protected  void readRecord(DBRecord rec, DBCommand cmd, Connection conn)
          Reads a single record from the database using the given command object.
If a record is found the DBRecord object will hold all record data.
 void readRecord(DBRecord rec, Object[] key, Connection conn)
          Reads the record with the given primary key from the database.
 boolean recordExists(Object[] key, Connection conn)
          Returns true if the record exists in the database or false otherwise.
 boolean recordExists(Object id, Connection conn)
          Returns true if the record exists in the database or false otherwise.
 void setComment(String comment)
           
protected  void setKeyConstraints(DBCommand cmd, Object[] key)
          Set the constraints for a single record from a supplied key
 void setTimestampColumn(DBColumn timestampColumn)
           
 void updateRecord(DBRecord rec, 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.
 
Methods inherited from class org.apache.empire.db.DBExpr
addSQL, getObjectValue, getValueClass
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.slf4j.Logger log

db

protected final transient DBDatabase db

comment

protected String comment

primaryKey

protected DBIndex primaryKey

timestampColumn

protected DBColumn timestampColumn

columnReferences

protected Map<DBColumn,DBColumn> columnReferences

columns

protected List<DBColumn> columns
Constructor Detail

DBRowSet

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

Parameters:
db - the database object
Method Detail

getId

public String getId()
Gets an identifier for this RowSet Object

Returns:
the rowset identifier

findById

public static DBRowSet findById(String rowsetId)
returns a rowset by its identifier

Parameters:
rowsetId - the id of the rowset
Returns:
the rowset object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

getName

public abstract String getName()

getAlias

public abstract String getAlias()

isUpdateable

public abstract boolean isUpdateable()

createRecord

public abstract void createRecord(DBRecord rec,
                                  Connection conn)

deleteRecord

public abstract void deleteRecord(Object[] keys,
                                  Connection conn)

getFullName

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

Returns:
the full qualified name

addReferencedColumns

public void addReferencedColumns(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 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.

Parameters:
column - column the DBColumn to get the index for
Returns:
the position of a column expression

getColumnIndex

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

Parameters:
column - the Column to get the index for
Returns:
the position of a column expression

getColumn

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

Parameters:
iColumn - the index to get the DBColumn for
Returns:
the index value

getColumn

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

Parameters:
name - the name of the column to look for
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.

Parameters:
col - the column object
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 String getComment()
Returns:
Returns the comment.

setComment

public void setComment(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 Map<DBColumn,DBColumn> getColumnReferences()
Returns the a list of column references.

Returns:
a list of references

addColumnReference

protected void addColumnReference(DBColumn source,
                                  DBColumn target)
Adds a column reference to the list of table references. This method is internally called from DBDatabase.addReleation().

Parameters:
source - a column reference for one of this table's column
target - the target column to which the source column references

count

public DBColumnExpr count()
Returns a new DBCountExpr object.

Returns:
a new DBCountExpr object

getRenameTablePhrase

protected String getRenameTablePhrase()
Returns the sql phrase for renaming tables. usually just a space character ' '

Returns:
the table rename phrase

getRecordKey

public 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

prepareInitRecord

protected void prepareInitRecord(DBRecord rec,
                                 int state,
                                 Object rowSetData)
Initialize this DBRowSet object and sets it's initial state.

Parameters:
rec - the DBRecord object to initialize this DBRowSet object
state - the state of this DBRowSet object

initRecord

public void initRecord(DBRecord rec,
                       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

initRecord

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

completeInitRecord

protected void completeInitRecord(DBRecord rec)
Completes the record initialization.
Override this function to do post initialization processing.

Parameters:
rec - the DBRecord object to initialize

setKeyConstraints

protected void setKeyConstraints(DBCommand cmd,
                                 Object[] key)
Set the constraints for a single record from a supplied key

Parameters:
cmd - the command to which to add the constraints
key - the record key

readRecord

protected void readRecord(DBRecord rec,
                          DBCommand cmd,
                          Connection conn)
Reads a single record from the database using the given command object.
If a record is found the DBRecord object will hold all record data.

Parameters:
rec - the DBRecord object which holds the record data
cmd - the SQL-Command used to query the record
conn - a valid JDBC connection.

readRecord

public void readRecord(DBRecord rec,
                       Object[] key,
                       Connection conn)
Reads the record with the given primary key from the database. If the record cannot be found, a RecordNotFoundException is thrown.

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

recordExists

public boolean recordExists(Object[] key,
                            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 the record exists or false otherwise

recordExists

public final boolean recordExists(Object id,
                                  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 the record exists or false otherwise

updateRecord

public void updateRecord(DBRecord rec,
                         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.

deleteRecord

public final void deleteRecord(Object id,
                               Connection conn)
Deletes a single record from the database.

Parameters:
id - the record's primary key
conn - a valid JDBC connection

deleteAllReferences

protected final void deleteAllReferences(Object[] key,
                                         Connection conn)
Deletes all records which reference this table.

Parameters:
key - the key the record to be deleted
conn - a valid connection

deleteReferenceRecords

protected void deleteReferenceRecords(DBRelation.DBReference[] refs,
                                      Object[] parentKey,
                                      Connection conn)
Deletes all records which are referenced by a particular relation.

Parameters:
refs - the reference columns belonging to the relation
parentKey - the key of the parent element
conn - a valid connection


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