Expressing a Native Query

Listing 3. By expressing a Native Query with this code, you can locate all the test suites that are executed in a given week, that have an overall score of 'failed,' but for which more than half of the associated test cases are scored as 'passed.'

   . . .
TestSuite testsuite;
NativeQueryQuery nqqClass;
Date now;

// Open the database
ObjectContainer db = Db4o.openFile("testsuites.YAP");
		
// Instantiate a NativeQueryQuery object,
//  setting the start and end dates for
//  any test in the past week
//  604800000 = milliseconds in a week
now = new Date();
nqqClass = new NativeQueryQuery(db,
  now.getTime()-604800000L,
  now.getTime());
		
// Execute the query and display the
//  results
System.out.println("Results:");
ObjectSet results = db.query(nqqClass);
if(results.isEmpty())
  System.out.println("  NOTHING TO DISPLAY");
		
while(results.hasNext())
{
  testsuite = (TestSuite)(results.next());
  System.out.println(testsuite.toString());
}

db.close();
   . . .