net.sf.persism
Class Query

java.lang.Object
  extended by net.sf.persism.Query

public final class Query
extends java.lang.Object

Performs read operations from the database.

Since:
9/8/11 6:07 AM
Author:
Dan Howard

Constructor Summary
Query(java.sql.Connection connection)
           
 
Method Summary
<T> T
read(java.lang.Class<T> objectClass, java.lang.String sql, java.lang.Object... parameters)
          Reads an object of the specified type from the database.
 boolean read(java.lang.Object object)
          Read an object from the database by it's primary key.
<T> java.util.List<T>
readList(java.lang.Class<T> objectClass, java.lang.String sql, java.lang.Object... parameters)
          Read a list of objects of the specified class using the specified SQL query and parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Query

public Query(java.sql.Connection connection)
Method Detail

readList

public <T> java.util.List<T> readList(java.lang.Class<T> objectClass,
                                      java.lang.String sql,
                                      java.lang.Object... parameters)
                           throws PersismException
Read a list of objects of the specified class using the specified SQL query and parameters. The type of the list can be Data Objects or native Java Objects.

Type Parameters:
T -
Parameters:
objectClass - class of objects to return.
sql - query string to execute.
parameters - parameters to the query.
Returns:
a list of objects of the specified class using the specified SQL query and parameters.
Throws:
PersismException

read

public boolean read(java.lang.Object object)
             throws PersismException
Read an object from the database by it's primary key. You should instantiate the object and set the primary key properties before calling this method.

Parameters:
object - Data object to read from the database.
Returns:
true if the object was found by the primary key.
Throws:
PersismException - if something goes wrong.

read

public <T> T read(java.lang.Class<T> objectClass,
                  java.lang.String sql,
                  java.lang.Object... parameters)
       throws PersismException
Reads an object of the specified type from the database. The type can a be Data Object or a native Java Object.

Type Parameters:
T -
Parameters:
objectClass - Type of returned value
sql - query - this would usually be a select OR a select of a single column if the type is a primitive. If this is a primitive type then this method will only look at the 1st column in the result.
parameters - parameters to the query.
Returns:
value read from the database
Throws:
PersismException - if something funny?