PSE 2000 Group 4

jobmatch.data
Class PersonQuery

jobmatch.data.PersonQuery

public final class PersonQuery

PersonQuery is used to query the Person table in the database.
It returns objects of type PersonDO.

General usage:

In DODS: Create a Data Object named "Dog", and create an Attribute named "Name", and set that Attribute to "Can be queried." DODS will then generate the method DogQuery.setQueryName().

In your Business Layer, prepare the query:

             DogQuery dq = new DogQuery();
             dq.setQueryName("Rex")
             if ( Rex is a reserved name )
                 dq.requireUniqueInstance();
 
Then, get the query results one of two ways:

#1:

             String names = "";
             DogBDO[] dogs = dq.getBDOArray();
             for ( int i = 0; i < dogs.length; i++ ) {
                 names += dogs[i].getName() + " ";
             }
 
or #2:
             String names = "";
             DogBDO dog;
             while ( null != ( dog = dq.getNextBDO() ) ) {
                 names += dog.getName() + " ";
             }
 
Note: Methods getDOArray() and getNextDO() do exist, but they are not generally used in the Business or Presentation layers of an application. All access to the Data Layer (DO classes) should occur via the Business Layer (BDO classes). Only the Business Layer (BDO classes and classes extending them) should need to manipulate the Data Layer (DO classes). See also the comments in the BDO constructors.

Note: If requireUniqueInstance() was called, then getBDOArray() or getNextBDO() will throw an exception if more than one "Rex" was found.

Note: Results of the query will come from the Data Object cache if: - The cache is available. - Matches were found in the cache. - No other tables (Data Objects of other types) were involved in the query. This can happen if you extend the DogQuery class and you make calls to the QueryBuilder object to add SQL involving other tables. If any of these conditions is not true, then any results from the query will come from the database.

To reuse the query object, call:

             dq.reset();
 

Version:
$Revision: 1.4 $

Constructor Summary
PersonQuery()
          Public constructor.
 
Method Summary
 void addOrderByAdress()
          Add Adress to the ORDER BY clause.
 void addOrderByAdress(boolean direction_flag)
          Add Adress to the ORDER BY clause.
 void addOrderByBirthdate()
          Add Birthdate to the ORDER BY clause.
 void addOrderByBirthdate(boolean direction_flag)
          Add Birthdate to the ORDER BY clause.
 void addOrderByFname()
          Add Fname to the ORDER BY clause.
 void addOrderByFname(boolean direction_flag)
          Add Fname to the ORDER BY clause.
 void addOrderByLname()
          Add Lname to the ORDER BY clause.
 void addOrderByLname(boolean direction_flag)
          Add Lname to the ORDER BY clause.
 void addOrderByNatel()
          Add Natel to the ORDER BY clause.
 void addOrderByNatel(boolean direction_flag)
          Add Natel to the ORDER BY clause.
 void addOrderByNationality()
          Add Nationality to the ORDER BY clause.
 void addOrderByNationality(boolean direction_flag)
          Add Nationality to the ORDER BY clause.
 void addOrderByPhone()
          Add Phone to the ORDER BY clause.
 void addOrderByPhone(boolean direction_flag)
          Add Phone to the ORDER BY clause.
 void addOrderByResidence()
          Add Residence to the ORDER BY clause.
 void addOrderByResidence(boolean direction_flag)
          Add Residence to the ORDER BY clause.
 void addOrderBySex()
          Add Sex to the ORDER BY clause.
 void addOrderBySex(boolean direction_flag)
          Add Sex to the ORDER BY clause.
 void closeParen()
          Place a closing parenthesis in the WHERE clause.
 ResultSet executeQuery(jobmatch.data.DBConnection conn)
          Method to query objects from the database.
 PersonBDO[] getBDOArray()
          Return array of BDOs constructed from ResultSet returned by query.
 PersonDO[] getDOArray()
          Return array of DOs constructed from ResultSet returned by query.
 PersonBDO getNextBDO()
          Return successive BDOs from array built from ResultSet returned by query.
 PersonDO getNextDO()
          Return successive DOs from array built from ResultSet returned by query.
 jobmatch.data.QueryBuilder getQueryBuilder()
          Returns the QueryBuilder that this PersonQuery uses to construct and execute database queries.
 void hitDatabase()
           
 Object next(ResultSet rs)
          WARNING! This method is disabled.
 void openParen()
          Place an open parenthesis in the WHERE clause.
 void or()
          Insert an OR between WHERE clauses.
 void requireUniqueInstance()
          Set "unique instance" assertion bit.
 void reset()
          Reset the query parameters.
 void setQueryAdress(AdressDO x)
          Set the Adress to query
 void setQueryAdress(AdressDO x, boolean exact)
          Set the Adress to query.
 void setQueryBirthdate(Date x)
          Set the Birthdate to query
 void setQueryBirthdate(Date x, boolean exact)
          Set the Birthdate to query.
 void setQueryFname(String x)
          Set the Fname to query
 void setQueryFname(String x, boolean exact)
          Set the Fname to query.
 void setQueryHandle(String handle)
          Set the object handle to query.
 void setQueryLname(String x)
          Set the Lname to query
 void setQueryLname(String x, boolean exact)
          Set the Lname to query.
 void setQueryNatel(String x)
          Set the Natel to query
 void setQueryNatel(String x, boolean exact)
          Set the Natel to query.
 void setQueryNationality(CountryDO x)
          Set the Nationality to query
 void setQueryNationality(CountryDO x, boolean exact)
          Set the Nationality to query.
 void setQueryOId(jobmatch.data.ObjectId oid)
          Set the OID to query.
 void setQueryPhone(String x)
          Set the Phone to query
 void setQueryPhone(String x, boolean exact)
          Set the Phone to query.
 void setQueryResidence(String x)
          Set the Residence to query
 void setQueryResidence(String x, boolean exact)
          Set the Residence to query.
 void setQuerySex(String x)
          Set the Sex to query
 void setQuerySex(String x, boolean exact)
          Set the Sex to query.
 

Constructor Detail

PersonQuery

public PersonQuery()
Public constructor.
Method Detail

hitDatabase

public void hitDatabase()

getDOArray

public PersonDO[] getDOArray()
                      throws jobmatch.data.DataObjectException,
                             jobmatch.data.NonUniqueQueryException
Return array of DOs constructed from ResultSet returned by query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.
jobmatch.data.NonUniqueQueryException - If too many rows were found.

getNextDO

public PersonDO getNextDO()
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.NonUniqueQueryException
Return successive DOs from array built from ResultSet returned by query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.
jobmatch.data.NonUniqueQueryException - If too many rows were found.

getBDOArray

public PersonBDO[] getBDOArray()
                        throws jobmatch.data.DataObjectException,
                               jobmatch.data.NonUniqueQueryException
Return array of BDOs constructed from ResultSet returned by query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.
jobmatch.data.NonUniqueQueryException - If too many rows were found.

getNextBDO

public PersonBDO getNextBDO()
                     throws jobmatch.data.DataObjectException,
                            jobmatch.data.NonUniqueQueryException
Return successive BDOs from array built from ResultSet returned by query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.
jobmatch.data.NonUniqueQueryException - If too many rows were found.

setQueryOId

public void setQueryOId(jobmatch.data.ObjectId oid)
Set the OID to query. WARNING! This method assumes that table Person has a column named "oid". This method is called from the DO classes to retrieve an object by id.
Parameters:
oid - The object id to query.

setQueryHandle

public void setQueryHandle(String handle)
                    throws jobmatch.data.ObjectIdException
Set the object handle to query. This is a variant of setQueryOId().
Parameters:
handle - The string version of the id to query.

requireUniqueInstance

public void requireUniqueInstance()
Set "unique instance" assertion bit. The first call to the next() method will throw an exception if more than one object was found.

reset

public void reset()
Reset the query parameters.

executeQuery

public ResultSet executeQuery(jobmatch.data.DBConnection conn)
                       throws SQLException
Method to query objects from the database. The following call in runQuery() dbQuery.query( this ); causes the dbQuery object to invoke executeQuery()
Parameters:
conn - Handle to database connection.
Throws:
SQLException - If a database access error occurs.

next

public Object next(ResultSet rs)
            throws SQLException,
                   jobmatch.data.ObjectIdException
WARNING! This method is disabled. It's implementation is forced by the Query interface. This method is disabled for 2 reasons: 1) the getDOArray() and getNextDO() methods are better because they return DOs instead of JDBC objects. 2) the createExisting() method throws an exception that we cannot reasonably handle here, and that we cannot throw from here.
Parameters:
rs - JDBC result set from which the next object will be instantiated.
Throws:
SQLException - If a database access error occurs.
com.lutris.appserver.server.sql.ObjectIdException - If an invalid object id was queried from the database.

setQueryAdress

public void setQueryAdress(AdressDO x,
                           boolean exact)
                    throws jobmatch.data.DataObjectException,
                           jobmatch.data.QueryException
Set the Adress to query.
Parameters:
x - The Adress of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQueryAdress

public void setQueryAdress(AdressDO x)
                    throws jobmatch.data.DataObjectException,
                           jobmatch.data.QueryException
Set the Adress to query
Parameters:
x - The Adress of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderByAdress

public void addOrderByAdress(boolean direction_flag)
Add Adress to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderByAdress

public void addOrderByAdress()
Add Adress to the ORDER BY clause. This convenience method assumes ascending order.

setQueryFname

public void setQueryFname(String x,
                          boolean exact)
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.QueryException
Set the Fname to query.
Parameters:
x - The Fname of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQueryFname

public void setQueryFname(String x)
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.QueryException
Set the Fname to query
Parameters:
x - The Fname of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderByFname

public void addOrderByFname(boolean direction_flag)
Add Fname to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderByFname

public void addOrderByFname()
Add Fname to the ORDER BY clause. This convenience method assumes ascending order.

setQueryLname

public void setQueryLname(String x,
                          boolean exact)
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.QueryException
Set the Lname to query.
Parameters:
x - The Lname of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQueryLname

public void setQueryLname(String x)
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.QueryException
Set the Lname to query
Parameters:
x - The Lname of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderByLname

public void addOrderByLname(boolean direction_flag)
Add Lname to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderByLname

public void addOrderByLname()
Add Lname to the ORDER BY clause. This convenience method assumes ascending order.

setQueryNatel

public void setQueryNatel(String x,
                          boolean exact)
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.QueryException
Set the Natel to query.
Parameters:
x - The Natel of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQueryNatel

public void setQueryNatel(String x)
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.QueryException
Set the Natel to query
Parameters:
x - The Natel of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderByNatel

public void addOrderByNatel(boolean direction_flag)
Add Natel to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderByNatel

public void addOrderByNatel()
Add Natel to the ORDER BY clause. This convenience method assumes ascending order.

setQueryPhone

public void setQueryPhone(String x,
                          boolean exact)
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.QueryException
Set the Phone to query.
Parameters:
x - The Phone of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQueryPhone

public void setQueryPhone(String x)
                   throws jobmatch.data.DataObjectException,
                          jobmatch.data.QueryException
Set the Phone to query
Parameters:
x - The Phone of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderByPhone

public void addOrderByPhone(boolean direction_flag)
Add Phone to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderByPhone

public void addOrderByPhone()
Add Phone to the ORDER BY clause. This convenience method assumes ascending order.

setQueryResidence

public void setQueryResidence(String x,
                              boolean exact)
                       throws jobmatch.data.DataObjectException,
                              jobmatch.data.QueryException
Set the Residence to query.
Parameters:
x - The Residence of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQueryResidence

public void setQueryResidence(String x)
                       throws jobmatch.data.DataObjectException,
                              jobmatch.data.QueryException
Set the Residence to query
Parameters:
x - The Residence of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderByResidence

public void addOrderByResidence(boolean direction_flag)
Add Residence to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderByResidence

public void addOrderByResidence()
Add Residence to the ORDER BY clause. This convenience method assumes ascending order.

setQuerySex

public void setQuerySex(String x,
                        boolean exact)
                 throws jobmatch.data.DataObjectException,
                        jobmatch.data.QueryException
Set the Sex to query.
Parameters:
x - The Sex of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQuerySex

public void setQuerySex(String x)
                 throws jobmatch.data.DataObjectException,
                        jobmatch.data.QueryException
Set the Sex to query
Parameters:
x - The Sex of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderBySex

public void addOrderBySex(boolean direction_flag)
Add Sex to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderBySex

public void addOrderBySex()
Add Sex to the ORDER BY clause. This convenience method assumes ascending order.

setQueryBirthdate

public void setQueryBirthdate(Date x,
                              boolean exact)
                       throws jobmatch.data.DataObjectException,
                              jobmatch.data.QueryException
Set the Birthdate to query.
Parameters:
x - The Birthdate of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQueryBirthdate

public void setQueryBirthdate(Date x)
                       throws jobmatch.data.DataObjectException,
                              jobmatch.data.QueryException
Set the Birthdate to query
Parameters:
x - The Birthdate of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderByBirthdate

public void addOrderByBirthdate(boolean direction_flag)
Add Birthdate to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderByBirthdate

public void addOrderByBirthdate()
Add Birthdate to the ORDER BY clause. This convenience method assumes ascending order.

setQueryNationality

public void setQueryNationality(CountryDO x,
                                boolean exact)
                         throws jobmatch.data.DataObjectException,
                                jobmatch.data.QueryException
Set the Nationality to query.
Parameters:
x - The Nationality of the Person to query.
exact - to use matches or not
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

setQueryNationality

public void setQueryNationality(CountryDO x)
                         throws jobmatch.data.DataObjectException,
                                jobmatch.data.QueryException
Set the Nationality to query
Parameters:
x - The Nationality of the Person to query.
Throws:
jobmatch.data.DataObjectException - If a database access error occurs.

addOrderByNationality

public void addOrderByNationality(boolean direction_flag)
Add Nationality to the ORDER BY clause.
Parameters:
direction_flag - True for ascending order, false for descending

addOrderByNationality

public void addOrderByNationality()
Add Nationality to the ORDER BY clause. This convenience method assumes ascending order.

getQueryBuilder

public jobmatch.data.QueryBuilder getQueryBuilder()
Returns the QueryBuilder that this PersonQuery uses to construct and execute database queries. PersonQuery.setQueryXXX methods use the QueryBuilder to append SQL expressions to the "WHERE" clause to be executed. The QueryBuilder.addEndClause method. can be used to append freeform SQL expressions to the WHERE clause, e.g. "ORDER BY name". Notes regarding cache-enabled DO classes: DO classes can be cache-enabled. If when using a PersonQuery, the application developer does not call getQueryBuilder, then PersonQuery.setQueryXXX methods simply prune the DO cache and return the remaining results. However, a QueryBuilder builds SELECT statements for execution by the actual database, and never searches the built-in cache for the DO. So, if the DO class is cache-enabled, and getQueryBuilder is called, this PersonQuery object ignores the cache and hits the actual database.

or

public void or()
Insert an OR between WHERE clauses. Example: find all the persons named Bob or Robert: PersonQuery pq = new PersonQuery(); pq.setQueryFirstName( "Bob" ); pq.or(); pq.setQueryFirstName( "Robert" ); Note: Calls to setQueryXxx methods are implicitly ANDed together, so the following example will always return nothing: PersonQuery pq = new PersonQuery(); pq.setQueryFirstName( "Bob" ); // AND automatically inserted here. pq.setQueryFirstName( "Robert" );
See Also:
to construct more elaborate queries.

openParen

public void openParen()
Place an open parenthesis in the WHERE clause. Example usage: find all the Bobs and Roberts who are 5 or 50 years old: PersonQuery pq = new PersonQuery(); pq.openParen(); pq.setQueryFirstName( "Bob" ); pq.or(); pq.setQueryFirstName( "Robert" ); pq.closeParen(); // AND automatically inserted here. pq.openParen(); pq.setQueryAge( 5 ); pq.or(); pq.setQueryAge( 50 ); pq.closeParen();
See Also:
to construct more elaborate queries.

closeParen

public void closeParen()
Place a closing parenthesis in the WHERE clause.
See Also:
openParen

PSE 2000 Group 4