com.sun.mdm.index.query
Class QueryObject

java.lang.Object
  extended bycom.sun.mdm.index.query.QueryObject
All Implemented Interfaces:
QueryConstants, java.io.Serializable

public class QueryObject
extends java.lang.Object
implements java.io.Serializable, QueryConstants

The QueryObject class represents the criteria and conditions of an object query in the master index. It is the primary class for interacting with the Query Manager (class QueryManager), which executes each query. QueryObject holds the query information read by the Query Manager, and is used to set select fields for an object and to set conditions on object fields. The Query Manager transforms the query object into a relational database SQL query. The generated SQL statements contain select fields and conditions as the WHERE clause of the SQL query and always include primary keys of the objects. The statements might also include an "ORDER BY primary_key" clause.

You can query from multiple objects and set conditions on any object attributes. The relationship between objects does not need to be specified by the client; they are obtained internally and mapped by the Query Manager. Use the qualified field name syntax to specify fields (see the Master Index Studio or eIndex Single Patient Identifier User's Guide for more information about field syntax conventions).

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.sun.mdm.index.query.QueryConstants
MULTIPLE_QUERY, SINGLE_QUERY
 
Constructor Summary
QueryObject()
          Creates a new instance of the QueryObject class.
QueryObject(QueryObject qo)
          This a copy constructor for the QueryObject class and creates a copy of the specified query object.
 
Method Summary
 void addCondition(Condition condition)
          Adds a condition, specified by an instance of the Condition class to the query object.
 void addCondition(java.lang.String field, java.lang.String value)
          This is an overload method of addCondition, differing in that the default operator is = (equal to) and the value is a string.
 void addCondition(java.lang.String field, java.lang.String operator, java.lang.Object value)
          Specifies a condition for the WHERE clause of the SQL query.
 void addCondition(java.lang.String field, java.lang.String operator, java.lang.String value)
          This is an overload method of addCondition, differing in that the value parameter is a String.
 void addSelect(java.lang.String field)
          Adds a field to the SELECT portion of the SQL statement.
(package private)  void calcConditionsBlocks()
           
 void clearQueryConditions()
           
(package private)  boolean compareSelectFields(QueryObject otherQueryObject)
           
(package private)  boolean compareWith(QueryObject otherQueryObject, java.util.Map bindingAssociation)
           
(package private)  boolean containsCondition()
          Indicates whether the given query object includes conditions.
 boolean equals(java.lang.Object theOther)
           
(package private)  AssembleDescriptor getAssembleDescriptor()
          Retrieves the assemble descriptor (class AssembleDescriptor) for the query object.
(package private)  QueryObjectCache getCacheRef()
           
(package private)  Condition[] getConditionsUnion()
          Retrieves the conditions defined for the query object.
(package private)  int getFetchSize()
          Retrieves the specified number of objects to return in each batch.
(package private)  java.lang.String[][] getHints()
          Retrieves the SQL hints defined for the query object.
(package private)  int getMaxObjects()
          Retrieves the maximum number of objects to be returned from the query.
(package private)  int getMaxRows()
          Retrieves the maximum number of rows to be returned from the query.
(package private)  QueryParser getParser()
           
(package private)  int getQueryOption()
           
(package private)  Condition[] getReconstructedConditionsUnion()
           
(package private)  int getResultSetType()
          Return the ResultSet Type for the query object.
(package private)  java.lang.String getRoot()
           
(package private)  java.lang.String[] getRootId()
          Retrieves the fully qualified path for the primary keys of the root object in the query object.
(package private)  java.lang.String[] getSelectFields()
           
(package private)  SQLDescriptor[] getSQLDescriptor()
           
 int hashCode()
           
(package private)  void initializeOriginalConditionsForPrepare()
           
(package private)  boolean isOldFormatConditionExpression(Condition[] conditions)
           
(package private)  boolean isPrepare()
           
(package private)  SQLDescriptor[] parse()
          Parses the conditions of the query object, creating the SQL statements to use for the query.
(package private)  void parseOriginalConditionsTree()
           
(package private)  void preInitializeForCacheComparision()
          Initializes the query object prior to parsing the conditions.
(package private)  void reconstructConditionExpression()
           
 void setAssembleDescriptor(AssembleDescriptor assDesc)
          Sets the assemble descriptor (class AssembleDescriptor) for the QueryObject.
(package private)  void setCacheRef(QueryObjectCache qoc)
           
 void setCondition(Condition[] conditions)
          Specifies all the conditions of the query.
 void setCondition(Condition[][] conditions)
          Specifies multiple sets of conditions so the query object (more specifically the Query Manager) will logically use a UNION operator between each set of conditions in the SQL statement.
 void setFetchSize(int fetchSize)
          Specifies the number of objects to return in each batch.
 void setHints(java.lang.String[][] hints)
          Adds Oracle hints to the SELECT statements of the SQL query.
 void setMaxObjects(int maxObjects)
          Limits the maximum number of objects returned from a query.
(package private)  void setMaxRows(int rows)
          Limits the maximum number of rows returned from the query.
 void setOrderBy(java.lang.String orderbyField)
          Specify the order of results using order by field.
 void setPreparedId(java.lang.String identifier)
          Sets an identification for the query object to be used for prepared statements.
 void setQueryOption(int option)
          Specifies a query option that indicates to the parser whether to perform a single or multiple query.
(package private)  void setQueryParser()
           
(package private)  void setQueryParser(QueryParser queryParser)
           
 void setResultSetType(int type)
          Sets ResultSet type for this QueryObject tree.
 void setSelect(java.lang.String[] fields)
          Specifies multiple fields for the SELECT portion of the SQL statement.
(package private)  void setSQLDescriptor(SQLDescriptor[] sqlDesc)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryObject

public QueryObject()
Creates a new instance of the QueryObject class.

Parameters:
None.
Throws:
None.


QueryObject

public QueryObject(QueryObject qo)
This a copy constructor for the QueryObject class and creates a copy of the specified query object. Fields that are constructed after parsing are not copied into the new object, so the new QueryObject must be parsed (using QueryObject.parse).

Parameters:
qo - The query object to copy.
Throws:
None.
Method Detail

addCondition

public void addCondition(Condition condition)
Adds a condition, specified by an instance of the Condition class to the query object.

Parameters:
condition - The condition to be added to the query object.
Returns:
void - None.
Throws:
None.

addCondition

public void addCondition(java.lang.String field,
                         java.lang.String value)
This is an overload method of addCondition, differing in that the default operator is = (equal to) and the value is a string. This method specifies a condition for the WHERE clause of the SQL query, using an AND operator to join any previous conditions. If a field is of the type "varchar2", the query object automatically encloses the value in quotes.

Parameters:
field - The fully qualified field name for the WHERE clause.
value - The value for the WHERE clause.
Returns:
void - None.
Throws:
None.

addCondition

public void addCondition(java.lang.String field,
                         java.lang.String operator,
                         java.lang.Object value)
Specifies a condition for the WHERE clause of the SQL query. This method joins the condition to any previous conditions using the AND operator. If a field is of the type "varchar2", the query object will automatically enclose the value in quotes.

Parameters:
field - The fully qualified field name for the WHERE clause.
operator - The SQL operator for the WHERE clause. Available operators are = (equal to) and LIKE.
value - The value for the WHERE clause. The value can be of the type java.sql.
Returns:
void - None.
Throws:
None.

addCondition

public void addCondition(java.lang.String field,
                         java.lang.String operator,
                         java.lang.String value)
This is an overload method of addCondition, differing in that the value parameter is a String. This method specifies a condition for the WHERE clause of the SQL query, using an AND operator to join any previous conditions added. If a field is of the type "varchar2", the query object automatically encloses the value in quotes.

Parameters:
field - The fully qualified field name for the WHERE clause.
operator - The SQL operator for the WHERE clause. Available operators are = (equal to) and LIKE.
value - The value for the WHERE clause.
Returns:
void - None.
Throws:
None.

addSelect

public void addSelect(java.lang.String field)
Adds a field to the SELECT portion of the SQL statement. This field is returned by SQL to the query object. Call this method for each field in the SELECT statement, using the fully qualified field name.

Parameters:
field - The name of a field to include in the SELECT portion of t the SQL statement.
Returns:
void - None.
Throws:
None.

calcConditionsBlocks

void calcConditionsBlocks()

clearQueryConditions

public void clearQueryConditions()

compareSelectFields

boolean compareSelectFields(QueryObject otherQueryObject)

compareWith

boolean compareWith(QueryObject otherQueryObject,
                    java.util.Map bindingAssociation)

containsCondition

boolean containsCondition()
Indicates whether the given query object includes conditions.

Parameters:
None.

Returns:
boolean - Boolean true or false. This method returns true if the query object includes conditions; it returns false the object does not include conditions.
Throws:
None.

equals

public boolean equals(java.lang.Object theOther)

getAssembleDescriptor

AssembleDescriptor getAssembleDescriptor()
Retrieves the assemble descriptor (class AssembleDescriptor) for the query object. The assemble descriptor contains information used by the assembling engine, such as the structure of the enterprise or system object, the iterator type, and the result object assembler.

Parameters:
None.

Returns:
AssembleDescriptor - The assemble descriptor for the query object.
Throws:
None.

getCacheRef

QueryObjectCache getCacheRef()

getConditionsUnion

Condition[] getConditionsUnion()
Retrieves the conditions defined for the query object.

Parameters:
None.

Returns:
Condition[] - An array of conditions defined for the query object.
Throws:
None.

getFetchSize

int getFetchSize()
Retrieves the specified number of objects to return in each batch.

Parameters:
None.

Returns:
int - The specified batch size.
Throws:
None.

getHints

java.lang.String[][] getHints()
Retrieves the SQL hints defined for the query object.

Parameters:
None.

Returns:
String[][] - Arrays of hints defined for the query object.
Throws:
None.

getMaxObjects

int getMaxObjects()
Retrieves the maximum number of objects to be returned from the query.

Parameters:
None.

Returns:
int - The maximum number of objects to be returned.
Throws:
None.

getMaxRows

int getMaxRows()
Retrieves the maximum number of rows to be returned from the query.

Parameters:
None.

Returns:
int - The maximum number of rows to be returned.
Throws:
None.

getParser

QueryParser getParser()

getQueryOption

int getQueryOption()

getReconstructedConditionsUnion

Condition[] getReconstructedConditionsUnion()

getResultSetType

int getResultSetType()
Return the ResultSet Type for the query object.

Returns:
int - Type of ResultSet
Throws:
None.

getRoot

java.lang.String getRoot()

getRootId

java.lang.String[] getRootId()
                       throws QMException
Retrieves the fully qualified path for the primary keys of the root object in the query object.

Parameters:
None.

Returns:
String[] - An array of root object primary keys.
Throws:
QMException - Thrown if an error occurs while retrieving the primary keys.

getSelectFields

java.lang.String[] getSelectFields()

getSQLDescriptor

SQLDescriptor[] getSQLDescriptor()

hashCode

public int hashCode()

initializeOriginalConditionsForPrepare

void initializeOriginalConditionsForPrepare()

isOldFormatConditionExpression

boolean isOldFormatConditionExpression(Condition[] conditions)

isPrepare

boolean isPrepare()

parse

SQLDescriptor[] parse()
                throws QMException
Parses the conditions of the query object, creating the SQL statements to use for the query.

Parameters:
None.

Returns:
SQLDescriptor[] - An array of SQL descriptors for the query object.
Throws:
QMException - Thrown if an error occurs while parsing the conditions.

parseOriginalConditionsTree

void parseOriginalConditionsTree()

preInitializeForCacheComparision

void preInitializeForCacheComparision()
Initializes the query object prior to parsing the conditions.

Parameters:
None.
Returns:
void - None.
Throws:
None.


reconstructConditionExpression

void reconstructConditionExpression()

setAssembleDescriptor

public void setAssembleDescriptor(AssembleDescriptor assDesc)
Sets the assemble descriptor (class AssembleDescriptor) for the QueryObject. The assemble descriptor contains information used by the assembling engine, such as the structure of the enterprise or system object, the iterator type, and the result object assembler to be used by the assembling engine.

Note: This method is not required if you intend to delay the assembly of the query object. Use the QueryManager.execute() method instead.

Parameters:
assDesc - The assemble descriptor to use for this query object.
Returns:
void - None.
Throws:
None.

setCacheRef

void setCacheRef(QueryObjectCache qoc)

setCondition

public void setCondition(Condition[] conditions)
Specifies all the conditions of the query. All the conditions for this query object can be set by calling this method once.

Parameters:
conditions - An array of query conditions (including the name operator, and value).
Returns:
void - None.
Throws:
None.

setCondition

public void setCondition(Condition[][] conditions)
Specifies multiple sets of conditions so the query object (more specifically the Query Manager) will logically use a UNION operator between each set of conditions in the SQL statement. The Condition[] array contains an array of conditions, and the Condition array implicitly contains a UNION operator for all Condition[] arrays.

Parameters:
conditions - An array of query condition arrays.
Returns:
void - None.
Throws:
None.

setFetchSize

public void setFetchSize(int fetchSize)
Specifies the number of objects to return in each batch.

Parameters:
fetchSize - The maximum number of objects to return in each batch.
Returns:
void - None.
Throws:
None.

setHints

public void setHints(java.lang.String[][] hints)
Adds Oracle hints to the SELECT statements of the SQL query. The text of each hint is passed to the select statement with no modification. The inner array hints are used when multiple SQL queries are generated by the Query Manager. Each inner String[] element is used for a different SQL query. Each outer array hint (String[][]) is used to add a hint to the corresponding SELECT statement in the UNION generated by the Query Manager (due to the condition added by the setCondition method). For example, "hints[x][y]" adds hints to (x+1) SQL query and to (y+1) UNION SELECT statement.

To use this method properly, determine how many queries are generated by running in DEBUG mode first. Then you can set the SQL text appropriately. If the number of hints is less than the number of generated SELECT statements, the remaining SELECT statements are not passed any hints. If the number of hints is greater than the number of SELECT statements, the extra hints are ignored. The Query Manager automatically adds any necessary delimiters, such as "/*+" to the hint.

Usage example: To pass the hint "FIRST_ROWS_100" to only the first SELECT statement, use the following: String hints[][] = {{"FIRST_ROWS_100"}}

Parameters:
hints - An array of hints to add to the SELECT statements generated by the Query Manager.
Returns:
void - None.
Throws:
None.

setMaxObjects

public void setMaxObjects(int maxObjects)
Limits the maximum number of objects returned from a query. Only the required rows are retrieved from the database, so the rows are cut off at the database server rather than at the client. Use this method to improve database performance.

Note: Internally, the Query Manager may convert maxObjects to "rownum < X" in the WHERE clause (where "X" is the maximum number of objects you specify). The Query Manager may retrieve more rows than specified in order to create the maximum number of objects.

Parameters:
maxObjects - The maximum number of objects to be retrieved.
Returns:
void - None.
Throws:
None.

setMaxRows

void setMaxRows(int rows)
Limits the maximum number of rows returned from the query. The rows correspond to the rows in the JDBC result set. Only the required rows are retrieved from the database, so the rows are cut off at the database server rather than at the client. Use this method to improve database performance.

Parameters:
rows - The maximum number of rows to be retrieved.
Returns:
void - None.
Throws:
None.

setOrderBy

public void setOrderBy(java.lang.String orderbyField)
Specify the order of results using order by field. Note: the orderbyField should belong to root object of the composite object. So if the value set has primary object as its root (most of times, say Person ), then the order by columns will be from the primary object. Note: This is reserved for future use

Parameters:
orderbyField - order by

setPreparedId

public void setPreparedId(java.lang.String identifier)
Sets an identification for the query object to be used for prepared statements. If no identification is set, executeQuery is executed; if an identification is set, the prepared statement is executed. If you call QueryManager multiple times for the same query object, the object is prepared for the first call (if it is not already in the prepared statement pool). After the first call, values are used to bind the object to the already prepared statement.

Parameters:
identifier - The name of the query object (QueryObject).
Returns:
void - None.
Throws:
None.

setQueryOption

public void setQueryOption(int option)
Specifies a query option that indicates to the parser whether to perform a single or multiple query. Possible options are QueryConstants.SINGLE_QUERY or QueryConstants.MULTIPLE_QUERY. SINGLE_QUERY is used for a tuple query. MULTIPLE_QUERY is used for an object construction query. The default is MULTIPLE_QUERY, which is less redundant than the SINGLE_QUERY option.

Parameters:
option - An identification code that indicates which query option to use. 1 indicates SINGLE_QUERY; 2 indicates MULTIPLE_QUERY.
Returns:
void - None.
Throws:
None.

setQueryParser

void setQueryParser()

setQueryParser

void setQueryParser(QueryParser queryParser)

setResultSetType

public void setResultSetType(int type)
Sets ResultSet type for this QueryObject tree. This is optional method.

Parameters:
type - ResultSet Type

setSelect

public void setSelect(java.lang.String[] fields)
Specifies multiple fields for the SELECT portion of the SQL statement.

Parameters:
fields - An array of fields to be selected in the SQL query.
Returns:
void - None.
Throws:
None.

setSQLDescriptor

void setSQLDescriptor(SQLDescriptor[] sqlDesc)

toString

public java.lang.String toString()


Sun Microsystems, Inc.