org.rimudb.generic
Class GenericQuery

java.lang.Object
  extended by org.rimudb.generic.AbstractGenericBase
      extended by org.rimudb.generic.GenericQuery

public class GenericQuery
extends AbstractGenericBase

This class provides a way to execute queries for which there is no easy way to use a finder. The class always ensures that the connections are closed so they can be returned to the connection pool. The SQL string can be passed on the constructor and then the executeQuery() method without the SQL string can be used to run the query. This is suitable for applications when the SQL is fixed. In cases where the SQL must vary, it can be passed in on the executeQuery() method.


Constructor Summary
GenericQuery(Database database)
          Constructor for GenericQuery.
GenericQuery(Database database, java.lang.Class<? extends DataObject>[] dataObjectClasses, java.lang.String sql)
          Constructor for GenericQuery.
GenericQuery(Database database, java.lang.Class<? extends DataObject> dataObjectClass, java.lang.String sql)
          Constructor for GenericQuery.
GenericQuery(Database database, IQueryResultSetBinder binder, java.lang.String sql)
          Constructor for GenericQuery.
GenericQuery(Database database, java.lang.String sql)
          Constructor for GenericQuery.
 
Method Summary
 DataObject executeQueryToDataObject(java.lang.Object... parameters)
          Use this method if the SQL statement will return a single row containing a DataObject.
 java.util.List<DataObject> executeQueryToDataObjectList(java.lang.Object... parameters)
          Use this method if the SQL statement will return multiple rows each containing a DataObject.
 java.util.List<DataObject[]> executeQueryToDataObjectListArray(java.lang.Object... parameters)
          Use this method if the SQL statement will return multiple rows each containing multiple DataObjects.
 java.lang.Object executeQueryToObject(java.lang.Object... parameters)
          Use this method if the SQL statement will return a single row containing a single column.
 java.util.List<?> executeQueryToObjectList(java.lang.Object... parameters)
          Use this method if the SQL statement will return multiple rows each containing a single column.
 java.util.List<?> executeQueryWithBinderList(java.lang.Object... parameters)
          Use this method if the SQL statement will return multiple rows each containing a selection of the available columns or scalar results.
 IQueryResultSetBinder getBinder()
          Return the binder.
protected  void log(java.lang.String message)
          Log a message.
 void setBinder(IQueryResultSetBinder binder)
          Set the binder.
 
Methods inherited from class org.rimudb.generic.AbstractGenericBase
buildElementString, buildParameterString, getDatabase, getFetchSize, getSQL, parse, setFetchSize, setSQL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericQuery

public GenericQuery(Database database)
             throws RimuDBException
Constructor for GenericQuery.

Parameters:
database - Database
Throws:
RimuDBException

GenericQuery

public GenericQuery(Database database,
                    java.lang.String sql)
             throws RimuDBException
Constructor for GenericQuery.

Parameters:
database - Database
sql - String
Throws:
RimuDBException

GenericQuery

public GenericQuery(Database database,
                    java.lang.Class<? extends DataObject>[] dataObjectClasses,
                    java.lang.String sql)
             throws RimuDBException
Constructor for GenericQuery.

Parameters:
database - Database
dataObjectClasses - Class[]
sql - String
Throws:
RimuDBException

GenericQuery

public GenericQuery(Database database,
                    java.lang.Class<? extends DataObject> dataObjectClass,
                    java.lang.String sql)
             throws RimuDBException
Constructor for GenericQuery.

Parameters:
database - Database
dataObjectClass - Class
sql - String
Throws:
RimuDBException

GenericQuery

public GenericQuery(Database database,
                    IQueryResultSetBinder binder,
                    java.lang.String sql)
             throws RimuDBException
Constructor for GenericQuery.

Parameters:
database - Database
binder - IQueryResultSetBinder
sql - String
Throws:
RimuDBException
Method Detail

executeQueryToDataObjectListArray

public java.util.List<DataObject[]> executeQueryToDataObjectListArray(java.lang.Object... parameters)
                                                               throws RimuDBException
Use this method if the SQL statement will return multiple rows each containing multiple DataObjects. When the SQL statement contains a join of two or more tables then multiple Data Objects can be returned. Note that in order for this to work, the select statement must return all the columns required by the data objects.

Parameters:
parameters -
Returns:
List
Throws:
RimuDBException

executeQueryToDataObjectList

public java.util.List<DataObject> executeQueryToDataObjectList(java.lang.Object... parameters)
                                                        throws RimuDBException
Use this method if the SQL statement will return multiple rows each containing a DataObject.

Parameters:
parameters -
Returns:
List
Throws:
RimuDBException

executeQueryToDataObject

public DataObject executeQueryToDataObject(java.lang.Object... parameters)
                                    throws RimuDBException
Use this method if the SQL statement will return a single row containing a DataObject.

Parameters:
parameters -
Returns:
DataObject
Throws:
RimuDBException

executeQueryToObject

public java.lang.Object executeQueryToObject(java.lang.Object... parameters)
                                      throws RimuDBException
Use this method if the SQL statement will return a single row containing a single column.

Parameters:
parameters -
Returns:
Object
Throws:
RimuDBException

executeQueryToObjectList

public java.util.List<?> executeQueryToObjectList(java.lang.Object... parameters)
                                           throws RimuDBException
Use this method if the SQL statement will return multiple rows each containing a single column.

Parameters:
parameters -
Returns:
List
Throws:
RimuDBException

executeQueryWithBinderList

public java.util.List<?> executeQueryWithBinderList(java.lang.Object... parameters)
                                             throws RimuDBException
Use this method if the SQL statement will return multiple rows each containing a selection of the available columns or scalar results. This is the most flexible form of the methods, allowing any any values that can be returned by a select statement to be returned. It does however, require that a bean class and a binder class are created for handling the selection. The binder must implement IQueryResultSetBinder, and usually the The bean class would implement IResultSetBean.

Parameters:
parameters -
Returns:
List
Throws:
RimuDBException

log

protected void log(java.lang.String message)
Log a message. This is a separate method so that it can be overridden for testing.

Parameters:
message - String

getBinder

public IQueryResultSetBinder getBinder()
Return the binder.

Returns:
IQueryResultSetBinder

setBinder

public void setBinder(IQueryResultSetBinder binder)
Set the binder.

Parameters:
binder - IQueryResultSetBinder


Copyright © 2008-2011 Simon Ritchie. All Rights Reserved.