* @return An array of PTasks that match the PTaskTemplate.
*/
public PTask[] match(PTaskTemplate template, SyrupConnection con)
throws Exception
{
PTask p[] = new PTask[0];
String qq = null;
List qParts = new LinkedList();
// Add all the qualifiers, mapping from PTaskTemplate attributes to SQL
// attributes.
qParts.add(new QueryOperation(template, "description", "description"));
qParts.add(new QueryOperation(template, "name", "name"));
qParts.add(new QueryOperation(template, "function_class", "functionClass"));
qParts.add(new QueryOperation(template, "environment", "environment"));
qParts.add(new QueryOperation(template, "parameter", "parameter"));
qParts.add(new QueryOperation(template, "or_type", "orType"));
qParts.add(new QueryOperation(template, "parent_key", "parentKey"));
qParts.add(new QueryOperation(template, "key_", "key"));
qParts.add(new QueryOperation(template, "modifications", "modifications"));
qParts.add(new QueryOperation(template, "modification_time", "modificationTime"));
qParts.add(new QueryOperation(template, "creation_time", "creationTime"));
qParts.add(new QueryOperation(template, "executable", "executable"));
qParts.add(new QueryOperation(template, "done", "done"));
qParts.add(new QueryOperation(template, "worker", "worker"));
qParts.add(new QueryOperation(template, "is_parent", "isParent"));
// Builds the SQL query.
// [TODO: use an StringBuffer to speed up the concatenation of Strings].
Iterator qIterator = qParts.iterator();
while (qIterator.hasNext())
{
QueryOperation op = (QueryOperation) qIterator.next();
if (op.sqlOp != null)
{
if (qq != null)
{
qq = qq
+ " and ";
}
else
{
qq = " ";
}
qq = qq
+ op.sqlAtt + " " + op.sqlOp + " ?";
}
}
if (qq == null)
{
qq = sqlImpl().sqlStatements().selectTasksStatement();
}
else
{
qq = sqlImpl().sqlStatements().selectTasksStatement()
+ "where" + qq;
}
PreparedStatement ps = null;
ps = con.prepareStatement(qq);
qIterator = qParts.iterator();
int ii = 1;
while (qIterator.hasNext())
{
QueryOperation op = (QueryOperation) qIterator.next();
// For each qualifier, the SQL value is set.
if (op.sqlOp != null)
{
ps.setObject(ii++, op.value);
}
}
ResultSet result = null;
try
{
result = ps.executeQuery();
// Build the result array
// [TODO: Make this more efficient without the need of an extra
// ArrayList object]
ArrayList ptasks = new ArrayList();
while (result.next())
{
PTask t = sqlImpl().queryFunctions().readPTask(result);
ptasks.add(t);
}
p = new PTask[ptasks.size()];
Object[] o = ptasks.toArray();