Extending db4o's Predicate Class

Listing 2. The business logic of a Native Query resides in an extension of db4o's Predicate Class.

// Predicate class sub-class for native query example
public class NativeQueryQuery extends Predicate<TestSuite>
{
  ObjectContainer db;
  private long startdate;
  private long enddate;
	
  // Constructor to acquire the ObjectContainer and the
  //  date range locally
  public NativeQueryQuery(ObjectContainer _db,
    long _start, long _end)
  {
    db = _db;
    startdate = _start;
    enddate = _end;
  }

  // This is the actual query body	
  public boolean match(TestSuite testsuite)
  {
    float passed;
    float total;
    TestCase testcase;
		
    // See if the testsuite is in date range
    if(testsuite.getDateExec()<startdate ||
      testsuite.getDateExec()>enddate) return false;

    // Reject if no test cases		
    if(testsuite.getNumberOfCases()==0)
      return false;
		
    // Check that more than 50% of the cases pass
    passed = 0.0f;
    total = 0.0f;
    for(int i=0; i<testsuite.getNumberOfCases(); i++)
    {
      testcase = testsuite.getTestCase(i);
      if(testcase.getStatus()=='P')
        passed+=1.0f;
      total+=1.0f;
    }
    if((passed/total)<.5) return false;
      return true;
  }
}