|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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 |
---|
void setData(java.lang.Object data)
data
- a generic Objectvoid execute(java.util.HashMap outputdata) throws java.lang.Exception
outputdata
- contains the data returned by query and other informations
relative the database interrogation.
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |