com.jfw.database
Interface QueryGatewayInterface

All Known Implementing Classes:
AppVersionDB, GroupServiceDB, SearchDB, Sequence, ServicesDB, Update1, Update2, UserAddDB, UserDataDB, UserDataUpdateDB, UserGroupAddDB, UserGroupServiceAddDB, UserServiceDB

public interface QueryGatewayInterface

Must be implemented by all classes interacting with database.
The QueryGateway must be used for the execution of the query.

Example of implementing class

 public class GetDataDB implements QueryGatewayInterface
 {
   //Used for logging
   private String className = getClass().getName();
 
   //Query to use. Is set it in class static code
   private static String query;
 
   //Contains query parameters
   private Object data;
 
   static
   {
    StringBuilder querySB = new StringBuilder();
    querySB.append("select ? from dual");
    query = querySB.toString();
   }
 
   public void setData(Object data)
   {
     this.data = data;
   }
 
   public void execute(HashMap outputdata) throws DatabaseException
   {
     QueryGateway queryGateway = null;
     boolean commit = false;
     try
     {
       //array list of parameters to use int the query
       ArrayList queryData = new ArrayList();
       //paramaters from object set in setData method
       queryData.add(data.get(...));
       queryGateway = new QueryGateway();
       queryGateway.executeQuery(query, queryData);
       if(queryGateway.next())
       {
         //read data from result set and set them in HashMap outputdata
         outputdata.put("key", "value");
       }
       commit = true;
     }
     catch(DatabaseException de)
     {
       throw de;
     }
     catch(Throwable t)
     {
       com.jfw.util.JFWLogger.error(className, "execute", "", "JFW", t.toString(), t);
       throw new DatabaseException(t.toString());
     }
     finally
     {
       if(queryGateway != null)
       {
         queryGateway.close(commit);
       }
     }
   }
 
 }


Method Summary
 void execute(java.util.HashMap outputdata)
          Execute the query defined in class static method.
 void setData(java.lang.Object data)
          Set object containing parameters to use.
 

Method Detail

setData

void setData(java.lang.Object data)
Set object containing parameters to use.
The parameter data can be null.

Parameters:
data - a generic Object

execute

void execute(java.util.HashMap outputdata)
             throws java.lang.Exception
Execute the query defined in class static method.

Parameters:
outputdata - contains the data returned by query and other informations relative the database interrogation.
Throws:
java.lang.Exception