DODS 5.1 API

com.lutris.appserver.server.sql
Interface DBQuery

All Known Implementing Classes:
StandardDBQuery

public interface DBQuery

Utility for querying object from a database. Allocates connections from the database connection pool, ensures the integrity of those connections, and manages result sets after a query is performed. Returns objects representing data in the database.

Example - querying a user:

 
 	import org.enhydra.dods.DODS;
 	import com.lutris.appserver.server.sql.*;

      DBQuery dbQuery =
      	DODS.getDatabaseManager().createQuery(DATABASE_NAME);
      	
      // NOTE: class CustomerQuery implements Query { ... }
      CustomerQuery
          customerQuery = new CustomerQuery();
      String [] loginIds = { "customer1", "customer2" };

      try {
          for (int idx=0; idx < loginIds.length; idx++) {

              customerQuery.setQueryLoginId(loginIds[idx]);
              dbQuery.query(customerQuery); // query the database

              // Print all query results.
              CustomerDO customerResult;
              while ((customerResult =
                     (CustomerDO)dbQuery.next()) != null) {
                  System.out.println("Customer name for " + 
                                      loginIds[idx] + 
                                     " is " + customerResult.getName());
              }

          }
      }
      finally {
          // 
          // Return database connections used by
          // this object back to the connection pool
          // and free any other resources consumed
          // by this object.
          // 
          dbQuery.release();
      }

 

Since:
LBS1.8
Version:
$Revision: 1.2 $
Author:
Kyle Clark

Method Summary
 boolean handleException(java.sql.SQLException e)
          Exception handler.
 java.lang.Object next()
          Returns a new object representing the next result form the query.
 void query(Query q)
          Query the database.
 void release()
          Frees all resources consumed by this query.
 void validate()
          Method to ensure this object is still valid.
 

Method Detail

query

public void query(Query q)
           throws java.sql.SQLException
Query the database.

Parameters:
q - Query interface via which the query will be executed.
Throws:
java.sql.SQLException - If a database access error occurs.

next

public java.lang.Object next()
                      throws java.sql.SQLException,
                             ObjectIdException
Returns a new object representing the next result form the query.

Returns:
New instance of object representing query results. null is returned when there are no more results.
Throws:
java.sql.SQLException - If a database access error occurs.
ObjectIdException - If ObjectId was not found.

release

public void release()
Frees all resources consumed by this query. Connections are returned to the connection pool. Subsequent queries via this object, will throw an exception.


handleException

public boolean handleException(java.sql.SQLException e)
Exception handler. This object is should not be used for subsequent queries if this method returns false.

Returns:
True if the exception can be handled and the object is still valid, false otherwise.

validate

public void validate()
              throws java.sql.SQLException
Method to ensure this object is still valid. Once this object has been released it cannot be used any more.

Throws:
java.sql.SQLException - If a database access error occurs.

DODS 5.1 API