test.tester.model
Class Query

java.lang.Object
  |
  +--test.tester.model.Query

public class Query
extends java.lang.Object

This class encapsulate a SQL prepared statement.

You can execute the query, and then get the result as a Collection of one MappedTable. Look at the following example:

     Query q = new Query(connection, "select * from tableX");
     q.execute();
     Collection c = q.getResultAs(TableX.class);     
 

You will get a Collection with all the rows returned by the sql query.
And it will be a Collection of TableX instances.

Everytime that you call a method inside TableXBroker class, it creates a query, bind some valued to it, than return the result in a appropriate format.


Constructor Summary
Query(java.sql.Connection conn, java.lang.String query)
          Creates a new query, given a Connection and a string with the query.
 
Method Summary
 void execute()
          Execute the query.
protected  void finalize()
          Do a basic cleanup.
 java.util.Collection getResultAs(java.lang.Class c)
          Gets the result of the query as an Collection of Class c objects.
 java.sql.ResultSet getResultSet()
          Simply returns the ResultSet, if any.
 void setObject(int id, java.lang.Object o)
          Binds one object to one variable inside this query.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

public Query(java.sql.Connection conn,
             java.lang.String query)
      throws DAOException
Creates a new query, given a Connection and a string with the query.

Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Do a basic cleanup. Also release the database connection from the pool.

Overrides:
finalize in class java.lang.Object
java.lang.Throwable

setObject

public void setObject(int id,
                      java.lang.Object o)
               throws DAOException
Binds one object to one variable inside this query. The same thing as the PreparedStatement.setObject() method.

DAOException

execute

public void execute()
             throws DAOException
Execute the query. Keeps the result set of the query, if available (select-like queries).

DAOException

getResultAs

public java.util.Collection getResultAs(java.lang.Class c)
                                 throws DAOException
Gets the result of the query as an Collection of Class c objects.

Never returns null, but can return an empty ArrayList. This method relies on the set() method implemention in the MappedTable implementations.

DAOException
See Also:
MappedTable

getResultSet

public java.sql.ResultSet getResultSet()
                                throws DAOException
Simply returns the ResultSet, if any. You will get an exception if you call this method before executing the query or if the query is something that does not give a ResultSet back.

DAOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object