org.apache.empire.db
Class DBQuery

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.DBQuery
All Implemented Interfaces:
ErrorInfo

public class DBQuery
extends DBRowSet

This class can be used to wrap a query from a DBCommand and use it like a DBRowSet.
You may use this class for two purposes:


Nested Class Summary
static class DBQuery.DBQueryColumn
           
 
Nested classes/interfaces inherited from class org.apache.empire.commons.ErrorObject
ErrorObject.ObjectErrorInfo
 
Field Summary
protected  java.lang.String alias
           
protected  DBCommand cmd
           
protected  DBColumn[] keyColumns
           
protected  DBQuery.DBQueryColumn[] queryColumns
           
 
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
DBQuery(DBCommand cmd)
          Creaes a DBQuery object from a given command object.
DBQuery(DBCommand cmd, DBColumn keyColumn)
          Constructs a new DBQuery object initialize the query object.
DBQuery(DBCommand cmd, DBColumn[] keyColumns)
          Constructor initializes the query object.
 
Method Summary
protected  boolean addJoinRestriction(DBCommand upd, DBColumn updCol, DBColumn keyCol, DBColumn[] keyColumns, DBRecord rec)
          Adds join restrictions to the supplied command object.
 void addSQL(java.lang.StringBuilder buf, long context)
          Adds the select SQL Command of this object to the specified StringBuilder object.
 boolean createRecord(DBRecord rec, java.sql.Connection conn)
          Returns an error, because querys could't add new records to the database.
 boolean deleteRecord(java.lang.Object[] keys, java.sql.Connection conn)
          Deletes a record identified by its primary key from the database.
 DBQuery.DBQueryColumn findQueryColumn(DBColumnExpr expr)
          This function searchs for equal columns given by the specified DBColumnExpr object.
 java.lang.String getAlias()
          not applicable - returns null
 DBColumn[] getKeyColumns()
          return query key columns
 java.lang.String getName()
          not applicable - returns null
 DBQuery.DBQueryColumn[] getQueryColumns()
          Gets all columns of this rowset (e.g.
 java.lang.Object[] getRecordKey(DBRecord record)
          Returns a array of primary key columns by a specified DBRecord object.
 boolean initRecord(DBRecord rec, java.lang.Object[] keyValues)
          Initialize specified DBRecord object with primary key columns (the Object[] keyValues).
 boolean readRecord(DBRecord rec, java.lang.Object[] key, java.sql.Connection conn)
          Creates a select SQL-Command of the query call the InitRecord method to execute the SQL-Command.
 boolean updateRecord(DBRecord rec, java.sql.Connection conn)
          Updates a query record by creating individual update commands for each table.
 
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, getRenameTablePhrase, getTimestampColumn, initRecord, isColumnReadOnly, isKeyColumn, prepareInitRecord, readRecord, recordExists, recordExists, setComment, setTimestampColumn
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cmd

protected DBCommand cmd

keyColumns

protected DBColumn[] keyColumns

queryColumns

protected DBQuery.DBQueryColumn[] queryColumns

alias

protected java.lang.String alias
Constructor Detail

DBQuery

public DBQuery(DBCommand cmd,
               DBColumn[] keyColumns)
Constructor initializes the query object. Saves the columns and the primary keys of this query.

Parameters:
cmd - the SQL-Command
keyColumns - an array of the primary key columns

DBQuery

public DBQuery(DBCommand cmd,
               DBColumn keyColumn)
Constructs a new DBQuery object initialize the query object. Save the columns and the primary key of this query.

Parameters:
cmd - the SQL-Command
keyColumn - the primary key column

DBQuery

public DBQuery(DBCommand cmd)
Creaes a DBQuery object from a given command object.

Parameters:
cmd - the command object representing an SQL-Command.
Method Detail

getName

public java.lang.String getName()
not applicable - returns null

Specified by:
getName in class DBRowSet

getAlias

public java.lang.String getAlias()
not applicable - returns null

Specified by:
getAlias in class DBRowSet

getQueryColumns

public DBQuery.DBQueryColumn[] getQueryColumns()
Gets all columns of this rowset (e.g. for cmd.select()).

Returns:
all columns of this rowset

findQueryColumn

public DBQuery.DBQueryColumn findQueryColumn(DBColumnExpr expr)
This function searchs for equal columns given by the specified DBColumnExpr object.

Parameters:
expr - the DBColumnExpr object
Returns:
the located column (only DBViewColumn onjects)

getKeyColumns

public DBColumn[] getKeyColumns()
return query key columns

Overrides:
getKeyColumns in class DBRowSet
Returns:
an array of all primary key columns

getRecordKey

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

Overrides:
getRecordKey in class DBRowSet
Parameters:
record - the DBRecord object, contains all fields and the field properties
Returns:
a array of primary key columns

addSQL

public void addSQL(java.lang.StringBuilder buf,
                   long context)
Adds the select SQL Command of this object to the specified StringBuilder object.

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

initRecord

public boolean initRecord(DBRecord rec,
                          java.lang.Object[] keyValues)
Initialize specified DBRecord object with primary key columns (the Object[] keyValues).

Overrides:
initRecord in class DBRowSet
Parameters:
rec - the Record object
keyValues - an array of the primary key columns
Returns:
true if successful

createRecord

public boolean createRecord(DBRecord rec,
                            java.sql.Connection conn)
Returns an error, because querys could't add new records to the database.

Specified by:
createRecord in class DBRowSet
Parameters:
rec - the DBRecord object, contains all fields and the field properties
conn - a valid database connection
Returns:
an error, because querys could't add new records to the database

readRecord

public boolean readRecord(DBRecord rec,
                          java.lang.Object[] key,
                          java.sql.Connection conn)
Creates a select SQL-Command of the query call the InitRecord method to execute the SQL-Command.

Overrides:
readRecord in class DBRowSet
Parameters:
rec - rec the DBRecord object, contains all fields and the field properties
key - an array of the primary key columns
conn - a valid connection to the database.
Returns:
true if successful

updateRecord

public boolean updateRecord(DBRecord rec,
                            java.sql.Connection conn)
Updates a query record by creating individual update commands for each table.

Overrides:
updateRecord 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 succesfull

addJoinRestriction

protected boolean addJoinRestriction(DBCommand upd,
                                     DBColumn updCol,
                                     DBColumn keyCol,
                                     DBColumn[] keyColumns,
                                     DBRecord rec)
Adds join restrictions to the supplied command object.


deleteRecord

public boolean deleteRecord(java.lang.Object[] keys,
                            java.sql.Connection conn)
Deletes a record identified by its primary key from the database.

Specified by:
deleteRecord in class DBRowSet
Parameters:
keys - array of primary key values
conn - a valid database connection
Returns:
true if the record has been successfully deleted or false otherwise


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