|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.jcorporate.expresso.core.dbobj.MultiDBObject
This class handles joins the 'old' way. It is not deprectated, but
for a more modern, flexible approach to joins
A MultiDBObject is a group of dbobjects that are "related" - e.g. defined
as being part of a foreign-key/primary-key relationship. This may be
master/detail or a more complex relationship, but it can be expressed as a
"join" operation between the tables.
After establishing the relationships between the objects, the MultiDBObject
can have search criteria set for it & searchAndRetrieve operations done just
like a 'regular' DBObject, but these operations affect the entire related
group of objects. At the moment, MultiDBObjects are read-only, though that
may change in the future.
Add 'model' objects, which may have criteria already set in their fields for a search,
via addDBObj(). After a query (via searchAndRetrieveList()),
each resulting MultiDBObject instance represents a
'join' row, and has its own encapsulated instances of whatever DBObject
models have been set with addDBObj()
before the query. In order to access these instances, use getDBObject().
Creation date: (9/18/00 11:32:03 AM)
author Michael Nash| Field Summary | |
protected static int |
INNER_JOIN
Static variables for join type |
protected static int |
LEFT_JOIN
|
protected DBConnection |
localConnection
Local connection that we use if it's initialized, but if it's null we generate our own connection |
protected int |
maxRecords
|
protected int |
offsetRecord
The number of records we must skip over before we start reading the ResultSet proper in a searchAndRetrieve.
0 means no limit
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001 |
protected static int |
RIGHT_JOIN
|
protected static String |
SHORT_NAME
Constant for shortName DBObject attribute |
| Constructor Summary | |
MultiDBObject()
MultiDBObject constructor. calls setupFields. |
|
MultiDBObject(ControllerRequest request)
MultiDBObject constructor which sets dbname from request |
|
| Method Summary | |
void |
addDBObj(DBObject oneDBObj,
String shortName)
|
void |
addDBObj(String dbobjClassName,
String shortName)
Add a DB Object to the objects being used for this multidbobj query. |
DBObject |
assembleObject(String shortName)
Deprecated. v. 5.5+; 9/04; use getDBObject() instead |
boolean |
buildFromClause()
Build a string consisting of an SQL 'from' clause using the customFromClause, the foreign-key or the join definitions. |
String |
buildWhereClause(boolean useAllFields)
Build and return a string consisting of an SQL 'where' clause using the current field values as criteria for the search. |
protected String |
buildWhereClauseBuffer(boolean useAllFields,
FastStringBuffer myStatement)
Build and return a string consisting of an SQL 'where' clause using the current field values as criteria for the search. |
protected String |
buildWhereClauseBuffer(boolean useAllFields,
FastStringBuffer myStatement,
String dboAlias)
Build and return a string consisting of an SQL 'where' clause using the current field values as criteria for the search. |
void |
clear()
Insert the method's description here. |
int |
count()
Just like find, but only retrieves the count, not the records themselves. |
int |
count(String expr)
Just like find, but only retrieves the count, not the records themselves. |
boolean |
getAppendCustomWhereClause()
Gets the settings of appendCustomWhereClause. |
Object |
getAttribute(String attribName)
Return an "attribute". |
DBConnection |
getConnection()
|
String |
getCustomFromClause()
Gets the customFromClause |
String |
getCustomWhereClause()
Gets the customWhereClause |
String |
getDataContext()
Return the name of the context/database connection that this DB object is using. |
String |
getDBName()
Return the name of the context/database connection that this DB object is using. |
DBObject |
getDBObject(String shortName)
This returns the encapsulated instance of the 'model' DBObject that was provided in 'addDBObj()'; After a searchAndRetrieveList(), each MultiDBObject in the list has, encapsulated, an object of each type which was previously added as a model. |
String |
getField(String shortName,
String fieldName)
Get the actual DBField value specified by fieldname Creation date: (9/18/00 11:37:10 AM) |
BigDecimal |
getFieldBigDecimal(String shortName,
String fieldName)
Returns a BigDecimal object author Peter Pilgrim |
Date |
getFieldDate(String shortName,
String fieldName)
|
String |
getFieldDecimalFormatted(String shortName,
String fieldName,
String formatPattern)
|
double |
getFieldDouble(String shortName,
String fieldName)
Returns a double object author Peter Pilgrim |
float |
getFieldFloat(String shortName,
String fieldName)
|
int |
getFieldInt(String shortName,
String fieldName)
|
long |
getFieldLong(String shortName,
String fieldName)
|
int |
getMaxRecords()
A DB Object can be told to only retrieve a certain number of records. |
int |
getOffsetRecord()
Gets the number of records that be skipped. |
boolean |
getShortNameAsAlias()
Get whether the shortName specified when a DBObject is added is also used as an alias for the table in the query. |
protected MultiDBObject |
getThisMultiDBObj()
Construct a new MultiDBObject |
boolean |
isFieldNull(String shortName,
String fieldName)
|
List |
makeDirectQueryList(String sqlQuery,
int fieldCount)
Execute custom SQL query |
protected String |
makeLimitationStub(DBConnection theConnection)
Creates the limitation syntax optimisation stub to embed inside the SQL command that performs search and retrieve. |
List |
searchAndRetrieveList()
Search and retrieve in a particular order |
List |
searchAndRetrieveList(String sortKeyString)
Search and retrieve in a particular order |
String |
selectFieldString(DBObject oneObj,
String fieldName)
Build an appropriate String for use in the select part of an SQL statement |
void |
setAppendCustomWhereClause(boolean newValue)
Specify if the customWhereClause should be appended to a generated whereClause. |
void |
setAttribute(String attribName,
Object attribValue)
Set an attribute. |
void |
setCaseSensitiveQuery(boolean isCaseSensitiveQuery)
This tells the buildWhereClause to either respect case (true) or ignore case (false). |
void |
setConnection(DBConnection connection)
|
void |
setCustomFromClause(String newCustomFrom)
Specify a custom "from" clause for the SQL used to retrieve records for this object. |
void |
setCustomWhereClause(String newCustomWhere)
Specify a custom "where" clause for the SQL used to retrieve records for this object. |
void |
setCustomWhereClause(String newCustomWhere,
boolean append)
Specify a custom "where" clause for the SQL used to retrieve records for this object. |
void |
setDBName(String newOther)
Set the database name/context for this multi db object. |
void |
setField(String shortName,
String fieldName,
String fieldValue)
Insert the method's description here. |
void |
setFieldDistinct(String shortName,
String fieldName,
boolean flag)
Specify a field to be retieved uniquely froma component DBObject |
void |
setFieldsToRetrieve(String shortName,
String fieldNames)
Specify a select list of fields to retrieve from a particular DBObject component |
void |
setFieldsToRetrieveToNone(String shortName)
Specify to retrieve NO fields from a particular DBObject component author Zaz Harris, SRI International |
void |
setForeignKey(String shortName,
String foreignKey,
String shortName2,
String primaryKey)
Insert the method's description here. |
void |
setInnerJoin(String leftShortName,
String leftColumn,
String rightShortName,
String rightColumn)
Builds a 'FROM' clause using the 'INNER JOIN' syntax. |
void |
setLeftJoin(String leftShortName,
String leftColumn,
String rightShortName,
String rightColumn)
Builds a 'FROM' clause using the 'LEFT JOIN' syntax. |
void |
setMaxRecords(int newMax)
Specify a maximum number of records to be retrieved in any subsequent searchAndRetrieve() call. |
void |
setOffsetRecord(int newOffset)
Specifies the number of records that should be skipped over before any data from the ResultSet
is retrieved in any subsequent
searchAndRetrieve() call. |
void |
setRightJoin(String leftShortName,
String leftColumn,
String rightShortName,
String rightColumn)
Builds a 'FROM' clause using the 'LEFT JOIN' syntax. |
void |
setSelectDistinct(boolean flag)
Specify that the DISTINCT keyword for unique rows must be specified right after the SELECT keyword |
void |
setShortNameAsAlias(boolean flag)
Specify whether the shortName specified when a DBObject is added is also used as an alias for the table in the query. |
protected void |
setupFields()
Method to set up the fields for this database object. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected transient int offsetRecord
ResultSet proper in a searchAndRetrieve.
0 means no limit
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001
protected static final int INNER_JOIN
protected static final int RIGHT_JOIN
protected static final int LEFT_JOIN
protected static final String SHORT_NAME
protected DBConnection localConnection
protected int maxRecords
| Constructor Detail |
public MultiDBObject()
throws DBException
public MultiDBObject(ControllerRequest request)
throws DBException
| Method Detail |
public Object getAttribute(String attribName)
attribName - The attribute name to check
public void setAttribute(String attribName,
Object attribValue)
attribName - The name of the attribute being definedattribValue - The object to store under this attribute namepublic int getMaxRecords()
public void setOffsetRecord(int newOffset)
throws DBException
ResultSet
is retrieved in any subsequent
searchAndRetrieve() call. Records will be skipped over (in the specified
sort order) until the record counts is equal to or greater
than the offset record. Specifying zero indicates that no
records should be skipped over and the
ResultSet immediately from the start.
newOffset - The maximum number of records to retrieve.
DBException - If the max number is less than 0
author Peter Pilgrim public int getOffsetRecord()
ResultSet.
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001
setOffsetRecord(int)public void setCustomFromClause(String newCustomFrom)
newCustomFrom - java.lang.Stringpublic String getCustomFromClause()
public boolean buildFromClause()
throws DBException
DBException
public int count(String expr)
throws DBException
DBException - If the search could not be completed
public int count()
throws DBException
DBException - If the search could not be completedprotected String makeLimitationStub(DBConnection theConnection)
This method takes the limitation syntax string and performs a string replacement on the following tokens
ResultSet to skip
before reading the data.
ResultSet.
Also known as the rowlength.
ResultSet that the
search and retrieved should retrieve. The end record number
is equal to ( %offset% + %maxrecord% - 1 )
theConnection - the db connection to make this stub from
#searchAndRetrieve(),
setOffsetRecord( int ),
setMaxRecords( int )
public void addDBObj(String dbobjClassName,
String shortName)
throws DBException
dbobjClassName - java.lang.StringshortName - java.lang.String
DBException
public void addDBObj(DBObject oneDBObj,
String shortName)
throws DBException
DBException
public String buildWhereClause(boolean useAllFields)
throws DBException
useAllFields - True if all fields are to be used,
false for only key fields
DBException
protected String buildWhereClauseBuffer(boolean useAllFields,
FastStringBuffer myStatement)
throws DBException
useAllFields - True if all fields are to be used, false for only key fields
DBException
protected String buildWhereClauseBuffer(boolean useAllFields,
FastStringBuffer myStatement,
String dboAlias)
throws DBException
useAllFields - True if all fields are to be used, false for only key fieldsmyStatement - Buffer for to build the new where-clause.dboAlias - Build the where-clause for this DBObject. If empty,
work with all DBObjects that are not marked to be ignored.
DBException
public void clear()
throws DBException
DBException - The exception description.public String getDBName()
public String getDataContext()
public DBObject getDBObject(String shortName)
throws DBException
shortName - the shortname of the model object
DBException - upon errorCreation date: (02/01/2002 9:33 AM)
public String getField(String shortName,
String fieldName)
throws DBException
shortName - the shortname of the fieldfieldName - name of the field to retrieve
DBException
public String getFieldDecimalFormatted(String shortName,
String fieldName,
String formatPattern)
throws DBException
DBException
public float getFieldFloat(String shortName,
String fieldName)
throws DBException
DBException
public double getFieldDouble(String shortName,
String fieldName)
throws DBException
DBException
public BigDecimal getFieldBigDecimal(String shortName,
String fieldName)
throws DBException
DBException
public Date getFieldDate(String shortName,
String fieldName)
throws DBException
DBException
public int getFieldInt(String shortName,
String fieldName)
throws DBException
DBException
public long getFieldLong(String shortName,
String fieldName)
throws DBException
DBException
protected MultiDBObject getThisMultiDBObj()
throws DBException
DBException - upon error
public List searchAndRetrieveList(String sortKeyString)
throws DBException
sortKeyString - A pipe-delimited list of key fields to sort
the returned set by
DBException - If the search could not be completed
public List searchAndRetrieveList()
throws DBException
DBException - If the search could not be completedpublic void setCaseSensitiveQuery(boolean isCaseSensitiveQuery)
isCaseSensitiveQuery - booleanpublic void setCustomWhereClause(String newCustomWhere)
newCustomWhere - java.lang.String
public void setCustomWhereClause(String newCustomWhere,
boolean append)
newCustomWhere - java.lang.Stringappend - true if the custom where clause is to be appended to the 'built'
where clause; THIS IS DIFFERENT THAN DBObject where 'append' means to append another condition onto the custom where clausepublic String getCustomWhereClause()
public void setAppendCustomWhereClause(boolean newValue)
newValue - true = append to whereClause, else overwrite it.public boolean getAppendCustomWhereClause()
public void setDBName(String newOther)
throws DBException
newOther - The name of the context or database to use
DBExceptionpublic void setSelectDistinct(boolean flag)
flag - true if DISTINCT supported right after SELECT, false (default) otherwise.
public void setFieldsToRetrieve(String shortName,
String fieldNames)
throws DBException
shortName - The alias for the DBObjectfieldNames - Pipe("|")-separated list of fieldnames
DBException
public void setFieldsToRetrieveToNone(String shortName)
throws DBException
shortName - The alias for the DBObject
DBException
public void setFieldDistinct(String shortName,
String fieldName,
boolean flag)
throws DBException
shortName - The alias for the DBObjectfieldName - The field to mark as uniqueflag - true=distinct, flase=all matching rows
DBException
public void setField(String shortName,
String fieldName,
String fieldValue)
throws DBException
shortName - the short name to setfieldName - the fieldname to setfieldValue - the value to set the field at.
DBException
public void setForeignKey(String shortName,
String foreignKey,
String shortName2,
String primaryKey)
throws DBException
shortName - java.lang.StringforeignKey - java.lang.StringshortName2 - java.lang.StringprimaryKey - java.lang.String
DBException
public void setInnerJoin(String leftShortName,
String leftColumn,
String rightShortName,
String rightColumn)
throws DBException
leftShortName - short name for the left hand table.leftColumn - name of the column from the left hand table for the JOIN conditionrightShortName - short name for the right hand table.rightColumn - name of the column from the right hand table for the JOIN condition
DBException
public void setLeftJoin(String leftShortName,
String leftColumn,
String rightShortName,
String rightColumn)
throws DBException
leftShortName - short name for the left hand table.leftColumn - name of the column from the left hand table for the JOIN conditionrightShortName - short name for the right hand table.rightColumn - name of the column from the right hand table for the JOIN condition
DBException
public void setRightJoin(String leftShortName,
String leftColumn,
String rightShortName,
String rightColumn)
throws DBException
leftShortName - short name for the left hand table.leftColumn - name of the column from the left hand table for the JOIN conditionrightShortName - short name for the right hand table.rightColumn - name of the column from the right hand table for the JOIN condition
DBException
public void setMaxRecords(int newMax)
throws DBException
newMax - The maximum number of records to retrieve.
DBException - If the max number is less than 0
protected void setupFields()
throws DBException
DBException - If there is an error setting up the fields
as requested.
public String selectFieldString(DBObject oneObj,
String fieldName)
throws DBException
oneObj - Database object containing the fieldfieldName - The name of the field to be handled
DBException
public List makeDirectQueryList(String sqlQuery,
int fieldCount)
throws DBException
sqlQuery - The SQL queryfieldCount - The number of fields returned by the query
DBException - If the query could not be completed
public DBObject assembleObject(String shortName)
throws DBException
shortName - name of join object
DBExceptionpublic void setShortNameAsAlias(boolean flag)
flag - True if the shortName should be used as an aliaspublic boolean getShortNameAsAlias()
public DBConnection getConnection()
public void setConnection(DBConnection connection)
connection -
public boolean isFieldNull(String shortName,
String fieldName)
throws DBException
DBException
|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||