toolkit.db.api
Class QueryInfo

java.lang.Object
  extended by toolkit.db.api.QueryInfo

public class QueryInfo
extends java.lang.Object

Class QueryInfo wraps all info of a query, users can retrieve info from it and build the query statement string of their own.


Constructor Summary
QueryInfo()
          Construct an empty QueryInfo.
 
Method Summary
 void addAnd(java.lang.String sLeftExpr, java.lang.String sOperator, java.lang.String sRightExpr, java.lang.String sLogic, boolean bEndOfGroup)
          Add a AndInfo.
 void addColumn(java.lang.String sColumnMappingName, java.lang.String sColumnName, java.lang.String sExpression, boolean bCompCol, java.lang.String sTableMappingName, int iColumnIndex)
          Add a ColumnInfo.
 void addFormula(java.lang.String sName, java.lang.String sExpression, boolean bNonSQLCriterion)
          Add a FormulaInfo.
 void addFormula(java.lang.String sName, java.lang.String sExpression, java.lang.String value, boolean bNonSQLCriterion)
          Add a FormulaInfo.
 void addJoin(java.lang.String sColumnFrom, java.lang.String sOperator, java.lang.String sColumnTo, int iJoinType, boolean bSQL92, boolean bSelfJoin)
          Add a JoinInfo.
 void addOrderBy(java.lang.String sColumnMappingName, java.lang.String order)
          Add a OrderByInfo.
 void addParameter(java.lang.String sName, java.lang.String sType, java.lang.String sValue)
          Add a ParameterInfo.
 void addQbeCriterion(java.lang.String sColumnMappingName, int iRowNumber, java.lang.String sExpression)
          Add a QBE criterion to this query.
 void addSubLink(java.lang.String sSubColumnMappingName, java.lang.String sOperator, java.lang.String sValue)
          Add a SubLinkInfo.
 void addTable(java.lang.String sMappingName, java.lang.String sTableName, java.lang.String sCorrelationName, java.lang.String sSchemaName, java.lang.String sCatalogName)
          Add a TableInfo.
 AndInfo[] getAnds()
          Get array of AndInfo in this query.
 ColumnInfo getColumn(java.lang.String name)
           
 ColumnInfo[] getColumns()
          Get array of ColumnInfo of all columns in this query, no matter it is a select column or not.
 ConnectionInfo getConnection()
          Get ConnectionInfo of this query.
 java.lang.Object getEntityByName(java.lang.String sMappingName)
          Get an entity (column, parameter or formula) by specified name.
 FormulaInfo[] getFormulas()
          Get array of FormulaInfo of this query.
 JoinInfo[] getJoins()
          Get array of JoinInfo in this query.
 OrderByInfo[] getOrderBys()
          Get array of OrderByInfo of this query.
 ParameterInfo[] getParameters()
          Get array of ParameterInfo of this query.
 QBEInfo[] getQbes()
          Get array of QBEInfo in this query.
 java.lang.String getQueryName()
          Get the name of this QueryInfo.
 ColumnInfo[] getSelectColumns()
          Get array of ColumnInfo of referenced select columns in this query.
 ColumnInfo[] getSelectColumns(boolean referencedOnly)
          Get array of ColumnInfo of select columns in this query.
 SubLinkInfo[] getSubLinks()
          Get array of SubLinkInfo of this query.
 TableInfo[] getTables()
          Get a Vector of TableInfo of all used tables in this query.
 java.lang.String getWherePortionString()
          Get where portion string.
 boolean isDistinct()
          Get whether this query is select distinct.
 boolean isIgnorePredicateIfParamIsNull()
          Get the value of option "ignore predicate if parameter is null" of this query.
 void removeAllParameters()
          Remove all ParameterInfos in this QeuryInfo.
 void removeAllSubLinks()
          Remove all SubLinkInfos in this query.
 ParameterInfo removeParameter(java.lang.String sParameterName)
          Remove a specified ParameterInfo.
 SubLinkInfo removeSubLink(java.lang.String sSubColName)
          Remove a specified SubLinkInfo.
 void setConnection(java.lang.String sDriver, java.lang.String sURL, java.lang.String sUser, java.lang.String sPassword, java.lang.String sDateFormat, java.lang.String sTimeFormat, java.lang.String sTimestampFormat, int iTransactionIsolation, int iReadOnly, int iQualifiedNamePattern, int iExtraNamePattern, int iEncodingPattern)
          Set connectionInfo's variables to the specified values.
 void setDistinct(boolean bDistinct)
          Set flag of select distinct of this query to specified value.
 void setIgnorePredicateIfParamIsNull(boolean bIgnorePredicateIfParamIsNull)
          Set flag of option "Ignore Predicate If Param Is Null" of this query to the specified value.
 void setQueryName(java.lang.String sQueryName)
          Set the name of this QueryInfo to specified value.
 void setWherePortionString(java.lang.String sWherePortion)
          Set where portion string which .
 void updateParameterValue(java.lang.String sParameterName, java.lang.String sValue)
          Update the value of a specific ParameterInfo in a query.
 void updateSubLinkValue(java.lang.String sSubColName, java.lang.String sValue)
          Update the value of a specific SubLinkInfo in a query.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryInfo

public QueryInfo()
Construct an empty QueryInfo.

Method Detail

setQueryName

public void setQueryName(java.lang.String sQueryName)
Set the name of this QueryInfo to specified value.

Parameters:
sQueryName - name of query.

getQueryName

public java.lang.String getQueryName()
Get the name of this QueryInfo.

Returns:
the name of this QueryInfo.

setConnection

public void setConnection(java.lang.String sDriver,
                          java.lang.String sURL,
                          java.lang.String sUser,
                          java.lang.String sPassword,
                          java.lang.String sDateFormat,
                          java.lang.String sTimeFormat,
                          java.lang.String sTimestampFormat,
                          int iTransactionIsolation,
                          int iReadOnly,
                          int iQualifiedNamePattern,
                          int iExtraNamePattern,
                          int iEncodingPattern)
Set connectionInfo's variables to the specified values.

Parameters:
sDriver - driver name used to connect to database.
sURL - jdbc url.
sUser - the user name used to connect to database.
sPassword - the user's password.
sDateFormat - format of date type.
sTimeFormat - format of time type.
sTimestampFormat - format of timestemp type.
iTransactionIsolation - transaction level of connectionInfo.
iReadOnly - read-only property of connectionInfo.
iQualifiedNamePattern - qualified pattern of table name.
iExtraNamePattern - qualified name pattern.
iEncodingPattern - encoding option when getting string from ResultSet.

getConnection

public ConnectionInfo getConnection()
Get ConnectionInfo of this query.

Returns:
the ConnectionInfo of this query.

setDistinct

public void setDistinct(boolean bDistinct)
Set flag of select distinct of this query to specified value.

Parameters:
bDistince - select distinct value to set.

isDistinct

public boolean isDistinct()
Get whether this query is select distinct.

Returns:
the value of select distinct flag.

setIgnorePredicateIfParamIsNull

public void setIgnorePredicateIfParamIsNull(boolean bIgnorePredicateIfParamIsNull)
Set flag of option "Ignore Predicate If Param Is Null" of this query to the specified value.

Parameters:
bIgnorePredicateIfParamIsNull - value of option "Ignore Predicate If Param Is Null" to set.

isIgnorePredicateIfParamIsNull

public boolean isIgnorePredicateIfParamIsNull()
Get the value of option "ignore predicate if parameter is null" of this query.

Returns:
the value of option "ignore predicate if parameter is null".

addTable

public void addTable(java.lang.String sMappingName,
                     java.lang.String sTableName,
                     java.lang.String sCorrelationName,
                     java.lang.String sSchemaName,
                     java.lang.String sCatalogName)
Add a TableInfo.

Parameters:
sMappingName - the mapping name of the newly added TableInfo.
sTableName - the real database name of the newly added TableInfo.
sCorrelationName - the correlation name of the newly added TableInfo.
sSchemaName - the schema name of the newly added TableInfo.
sCatalogName - the catalog name of the newly added TableInfo.

getTables

public TableInfo[] getTables()
Get a Vector of TableInfo of all used tables in this query.

Returns:
the array of TableInfo of this query.

addColumn

public void addColumn(java.lang.String sColumnMappingName,
                      java.lang.String sColumnName,
                      java.lang.String sExpression,
                      boolean bCompCol,
                      java.lang.String sTableMappingName,
                      int iColumnIndex)
Add a ColumnInfo.

Parameters:
sMappingName - the mapping name of the newly added column.
sColumnName - the real database name of the newly added column.
sExpression - the expression of the newly added column, if it represents a computed column.
bCompCol - flag which indicates whether the newly added column is a computed column.
sTableMappingName - the mapping name of table
iColumnIndex - the index of added column

getColumn

public ColumnInfo getColumn(java.lang.String name)

getColumns

public ColumnInfo[] getColumns()
Get array of ColumnInfo of all columns in this query, no matter it is a select column or not.

Returns:
array of all ColumnInfo of this query.

getSelectColumns

public ColumnInfo[] getSelectColumns()
Get array of ColumnInfo of referenced select columns in this query. This is a shorthand for:
                getSelectColumns(true)
        
Note, all columns in this array are in order as they should appear in select clause when creating a runtime SQL statement.

Returns:
array of ColumnInfo that will appear in select clause.
See Also:
getSelectColumns(boolean), ColumnInfo.getColumnIndex()

getSelectColumns

public ColumnInfo[] getSelectColumns(boolean referencedOnly)
Get array of ColumnInfo of select columns in this query. When a PSQL query is bound to a report, there may be some select columns which are not referenced in this report. Then it's not necessary to include them in the runtime SQL statement. So if you give a true to the parameter referencedOnly, only the referenced select columns of the report will be included in the return array, otherwise all select columns will be included.
Note, all referenced columns in this array are in order as they should appear in select clause when creating a runtime SQL statement.

Parameters:
referencedOnly - only select the columns that referenced in a report at runtime or not.
Returns:
array of ColumnInfo that will appear in select clause.
See Also:
getSelectColumns(), ColumnInfo.getColumnIndex()

addJoin

public void addJoin(java.lang.String sColumnFrom,
                    java.lang.String sOperator,
                    java.lang.String sColumnTo,
                    int iJoinType,
                    boolean bSQL92,
                    boolean bSelfJoin)
Add a JoinInfo.

Parameters:
sColumnFrom - the mapping name of FROM column of the newly added JoinInfo.
sOperator - the operator of the newly add JoinInfo.
sColumnTo - the mapping name of To column of the newly added JoinInfo.

getJoins

public JoinInfo[] getJoins()
Get array of JoinInfo in this query.

Returns:
array of JoinInfo of this query.

addQbeCriterion

public void addQbeCriterion(java.lang.String sColumnMappingName,
                            int iRowNumber,
                            java.lang.String sExpression)
Add a QBE criterion to this query.

Parameters:
sColumnMappingName - the mapping name of column which this criterion will based on.
iRowNumber - row numver of criterion.
sExpression - criterion in corresponding row.

getQbes

public QBEInfo[] getQbes()
Get array of QBEInfo in this query.

Returns:
array of QBEInfo in this query.

addAnd

public void addAnd(java.lang.String sLeftExpr,
                   java.lang.String sOperator,
                   java.lang.String sRightExpr,
                   java.lang.String sLogic,
                   boolean bEndOfGroup)
Add a AndInfo.

Parameters:
sLeftExpr - left expression value of the newly added AndInfo.
sOperator - operator value of the newly added AndInfo.
sLeftExpr - right expression value of the newly added AndInfo.
sLogic - logic value of the newly added AndInfo.
bEndOfGroup - flag to indicate whether this newly added AndInfo is the last condition of a group.

getAnds

public AndInfo[] getAnds()
Get array of AndInfo in this query. Usually, the AndInfos are pre-defined in the query, but if you run reports through JREngine and call JREngine.setNamedWherePortion(String) to set a pre-defined where portion, the return AndInfo are those conditions in that where portion.

Returns:
array of AndInfo in this query.
See Also:
JREngine.setNamedWherePortion(String)

setWherePortionString

public void setWherePortionString(java.lang.String sWherePortion)
Set where portion string which .

Parameters:
sWherePortion - where condition string to be set to this query.

getWherePortionString

public java.lang.String getWherePortionString()
Get where portion string. If you run report through jet.bean.JREngine, you can all setWherePortion(String) replace the Where clause by the specified string. In that case, you can call this method to retrieve the string you just set.

Returns:
the where condition string applied to this query.
See Also:
JREngine.setWherePortion(String)

addSubLink

public void addSubLink(java.lang.String sSubColumnMappingName,
                       java.lang.String sOperator,
                       java.lang.String sValue)
Add a SubLinkInfo.

Parameters:
sSubColumnMappingName - the mapping name of the ColumnInfo of the SubLinkInfo to be added to this query.
sOperator - operator the SubLinkInfo to be added to this query.
sValue - value of the field in main report of the SubLink to be added to this query.

updateSubLinkValue

public void updateSubLinkValue(java.lang.String sSubColName,
                               java.lang.String sValue)
Update the value of a specific SubLinkInfo in a query. This method does nothing if the specified sub link is not in this query.

Parameters:
sSubColName - mapping name of the SubLinkInfo that will be updated.
sValue - value of the SubLinkInfo that will be updated.

removeSubLink

public SubLinkInfo removeSubLink(java.lang.String sSubColName)
Remove a specified SubLinkInfo. This method does nothing if the specified sub link is not in this QueryInfo.

Parameters:
sSubColName - mapping name of the SubLinkInfo that will be removed.
Returns:
the SubLinkInfo removed by this method, or null if no SubLinkInfo is removed.

removeAllSubLinks

public void removeAllSubLinks()
Remove all SubLinkInfos in this query.


getSubLinks

public SubLinkInfo[] getSubLinks()
Get array of SubLinkInfo of this query.

Returns:
array of SubLinkInfo in this query.

addOrderBy

public void addOrderBy(java.lang.String sColumnMappingName,
                       java.lang.String order)
Add a OrderByInfo.

Parameters:
sColumnMappingName - mapping name of ColumnInfo of OrderByInfo to be added to this query.
order - the order of the OrderByInfo to be added to this query.

getOrderBys

public OrderByInfo[] getOrderBys()
Get array of OrderByInfo of this query. Note, all OrderByInfo in this Vector is in order.

Returns:
array of OrderByInfo in this query.

addParameter

public void addParameter(java.lang.String sName,
                         java.lang.String sType,
                         java.lang.String sValue)
Add a ParameterInfo.

Parameters:
sName - the mapping name of the ParameterInfo to be added to this query.
stype - the data type of the ParameterInfo to be added to this query, represented in string.
sValue - the value of the ParameterInfo to be added to this query, represented in string.

updateParameterValue

public void updateParameterValue(java.lang.String sParameterName,
                                 java.lang.String sValue)
Update the value of a specific ParameterInfo in a query. This method does nothing if the specified ParameterInfo is not in this QueryInfo.

Parameters:
sParameterName - mapping name of the ParameterInfo that will be updated.
sValue - value of the ParameterInfo that will be updated.

removeParameter

public ParameterInfo removeParameter(java.lang.String sParameterName)
Remove a specified ParameterInfo. This method does nothing if the specified parameter is not in this query.

Parameters:
sParameterName - mapping name of the ParameterInfo that will be removed.
Returns:
the ParameterInfo removed by this method, or null if no ParameterInfo is removed.

removeAllParameters

public void removeAllParameters()
Remove all ParameterInfos in this QeuryInfo.


getParameters

public ParameterInfo[] getParameters()
Get array of ParameterInfo of this query.

Returns:
array of ParameterInfo in this query.

addFormula

public void addFormula(java.lang.String sName,
                       java.lang.String sExpression,
                       boolean bNonSQLCriterion)
Add a FormulaInfo.

Parameters:
sName - the mapping name of the FormulaInfo to be added to this query.
sExpression - the expression of the FormulaInfo to be added to this query.
bNonSQLCriterion - the flag which indecates if this formula is a non SQL criterion one or not.

addFormula

public void addFormula(java.lang.String sName,
                       java.lang.String sExpression,
                       java.lang.String value,
                       boolean bNonSQLCriterion)
Add a FormulaInfo.

Parameters:
sName - the mapping name of the FormulaInfo to be added to this query.
sExpression - the expression of the FormulaInfo to be added to this query.
value - the value of the FormulaInfo to be added to this query.
bNonSQLCriterion - the flag which indecates if this formula is a non SQL criterion one or not.

getFormulas

public FormulaInfo[] getFormulas()
Get array of FormulaInfo of this query.

Returns:
array of FormulaInfo in this query.

getEntityByName

public java.lang.Object getEntityByName(java.lang.String sMappingName)
Get an entity (column, parameter or formula) by specified name.

Parameters:
sMappingName - the name of enrity to be searched for.
Returns:
A ColumnInfo if found in this query, or a ParameterInfo if found in this query, or a FormulaInfo found in this query, otherwise null.