org.apache.empire.db
Class DBQuery

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

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:

See Also:
Serialized Form

Nested Class Summary
static class DBQuery.DBQueryColumn
           
 
Field Summary
protected  String alias
           
protected  DBCommandExpr cmdExpr
           
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(DBCommandExpr cmd)
          Creaes a DBQuery object from a given command object.
DBQuery(DBCommandExpr cmd, DBColumn keyColumn)
          Constructs a new DBQuery object initialize the query object.
DBQuery(DBCommandExpr 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(StringBuilder buf, long context)
          Adds the select SQL Command of this object to the specified StringBuilder object.
 void createRecord(DBRecord rec, Connection conn)
          Returns an error, because it is not possible to add a record to a query.
 void deleteRecord(Object[] keys, 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.
 String getAlias()
          not applicable - returns null
 DBCommandExpr getCommandExpr()
          returns the underlying command expression
 DBColumn[] getKeyColumns()
          return query key columns
 String getName()
          not applicable - returns null
 DBQuery.DBQueryColumn[] getQueryColumns()
          Gets all columns of this rowset (e.g.
 Object[] getRecordKey(DBRecord record)
          Returns a array of primary key columns by a specified DBRecord object.
 void initRecord(DBRecord rec, Object[] keyValues)
          Initialize specified DBRecord object with primary key columns (the Object[] keyValues).
 boolean isUpdateable()
          Returns whether or not the table supports record updates.
 void readRecord(DBRecord rec, Object[] key, Connection conn)
          Creates a select SQL-Command of the query call the InitRecord method to execute the SQL-Command.
 void updateRecord(DBRecord rec, 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, equals, findById, getColumn, getColumn, getColumnIndex, getColumnIndex, getColumnReferences, getColumns, getComment, getDatabase, getFullName, getId, getRenameTablePhrase, getTimestampColumn, initRecord, isColumnReadOnly, isKeyColumn, prepareInitRecord, readRecord, recordExists, recordExists, setComment, setKeyConstraints, setTimestampColumn
 
Methods inherited from class org.apache.empire.db.DBExpr
getObjectValue, getValueClass
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cmdExpr

protected DBCommandExpr cmdExpr

keyColumns

protected DBColumn[] keyColumns

queryColumns

protected DBQuery.DBQueryColumn[] queryColumns

alias

protected String alias
Constructor Detail

DBQuery

public DBQuery(DBCommandExpr 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(DBCommandExpr 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(DBCommandExpr cmd)
Creaes a DBQuery object from a given command object.

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

getCommandExpr

public DBCommandExpr getCommandExpr()
returns the underlying command expression

Returns:
the command used for this query

getName

public String getName()
not applicable - returns null

Specified by:
getName in class DBRowSet

getAlias

public String getAlias()
not applicable - returns null

Specified by:
getAlias in class DBRowSet

isUpdateable

public boolean isUpdateable()
Returns whether or not the table supports record updates.

Specified by:
isUpdateable in class DBRowSet
Returns:
true if the table allows record updates

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

createRecord

public void createRecord(DBRecord rec,
                         Connection conn)
Returns an error, because it is not possible to add a record to a query.

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

readRecord

public void readRecord(DBRecord rec,
                       Object[] key,
                       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 - 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.

updateRecord

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

addJoinRestriction

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


deleteRecord

public void deleteRecord(Object[] keys,
                         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


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