*/
public LogEntry[] match(LogEntryTemplate template, SyrupConnection con)
throws Exception
{
LogEntry l[] = new LogEntry[0];
String qq = null;
List qParts = new LinkedList();
// Add all the qualifiers, mapping from LogEntry attributes to SQL
// attributes.
qParts.add(new QueryOperation(template, "creation_time", "time"));
qParts.add(new QueryOperation(template, "key_", "key"));
qParts.add(new QueryOperation(template, "event", "event"));
qParts.add(new QueryOperation(template, "worker", "worker"));
// Builds the SQL query.
// [TODO: use an StringBuffer to speed up the concatenation of Strings].
// [TODO: factor out this code so that it can be share by the previous match function]
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().selectLogEntriesStatement();
}
else
{
qq = sqlImpl().sqlStatements().selectLogEntriesStatement()
+ "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 logs = new ArrayList();
while (result.next())
{
LogEntry t = sqlImpl().queryFunctions().readLogEntry(result);
logs.add(t);
}
l = new LogEntry[logs.size()];
Object[] o = logs.toArray();