public void setup() {
    Vector employees = getSomeEmployees();
    // Bug 223005: Verify that we have at least 1 employee with the required field length otherwise
    // an EclipseLinkException will be thrown
    Employee emp = getEmployeeWithRequiredNameLength(employees, MIN_FIRSTNAME_LENGTH, getName());

    String partialFirstName = "%" + emp.getFirstName().substring(0, 3) + "%";

    ReadAllQuery raq = new ReadAllQuery();
    raq.setReferenceClass(Employee.class);

    Vector parameters = new Vector();
    parameters.add(partialFirstName);

    ExpressionBuilder eb = new ExpressionBuilder();
    Expression whereClause = eb.get("firstName").like(partialFirstName);
    raq.setSelectionCriteria(whereClause);
    employees = (Vector) getSession().executeQuery(raq);

    String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.firstName LIKE ?1";

    setEjbqlString(ejbqlString);
    setOriginalOject(employees);
    setArguments(parameters);

    Vector myArgumentNames = new Vector();
    myArgumentNames.add("1");
    setArgumentNames(myArgumentNames);

    super.setup();
  }
  protected void buildExpectedResults() {
    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(Employee.class);

    Vector employees = (Vector) getSession().executeQuery(query);
    Vector distinctEmployees = new Vector();

    // initialize distinctEmployees
    distinctEmployees.addElement(employees.elementAt(0));

    // check employees with duplicate province and add only distinct employees to distinctEmployees
    for (int i = 1; i < employees.size(); i++) {
      boolean duplicateFound = false;

      // iterate through distinctEmployees to check for duplicate provinces, if found, employee not
      // added
      for (int j = 0; j < distinctEmployees.size(); j++) {
        if ((((Employee) employees.elementAt(i)).getAddress().getProvince())
            .equals((((Employee) distinctEmployees.elementAt(j)).getAddress().getProvince()))) {
          duplicateFound = true;
        }
      }
      if (!duplicateFound) {
        distinctEmployees.addElement(employees.elementAt(i));
      }
    }

    for (Enumeration e = distinctEmployees.elements(); e.hasMoreElements(); ) {
      Employee emp = (Employee) e.nextElement();
      Object[] result = new Object[1];
      result[0] = emp.getAddress().getProvince();
      addResult(result, null);
    }
  }
  public void setup() {
    Employee emp1;
    Employee emp2;
    Employee emp3;
    emp1 = (Employee) getSomeEmployees().firstElement();
    emp2 = (Employee) getSomeEmployees().elementAt(1);
    emp3 = (Employee) getSomeEmployees().elementAt(2);

    ExpressionBuilder builder = new ExpressionBuilder();

    Vector idVector = new Vector();
    idVector.add(emp1.getId());
    idVector.add(emp2.getId());
    idVector.add(emp3.getId());

    Expression whereClause = builder.get("id").notIn(idVector);

    ReadAllQuery raq = new ReadAllQuery();
    raq.setReferenceClass(Employee.class);
    raq.setSelectionCriteria(whereClause);

    setOriginalOject(getSession().executeQuery(raq));
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();

    String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.id NOT IN (";
    ejbqlString = ejbqlString + emp1.getId().toString() + ", ";
    ejbqlString = ejbqlString + emp2.getId().toString() + ", ";
    ejbqlString = ejbqlString + emp3.getId().toString();
    ejbqlString = ejbqlString + ")";

    setEjbqlString(ejbqlString);

    super.setup();
  }
  public void setup() {
    Employee emp = (Employee) getSomeEmployees().firstElement();

    String partOne;
    String partTwo;
    String ejbqlString;

    partOne = emp.getFirstName();

    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause = builder.get("firstName").concat("Smith").like(partOne + "Smith");

    ReadAllQuery raq = new ReadAllQuery();
    raq.setReferenceClass(Employee.class);
    raq.setSelectionCriteria(whereClause);

    Vector employees = (Vector) getSession().executeQuery(raq);

    ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE ";
    ejbqlString = ejbqlString + "CONCAT(emp.firstName,\"Smith\") LIKE ";
    ejbqlString = ejbqlString + "\"" + partOne + "Smith\"";

    setEjbqlString(ejbqlString);
    setOriginalOject(employees);
    super.setup();
  }
  /** INTERNAL: Clone the query. */
  public Object clone() {
    ReadAllQuery cloneQuery = (ReadAllQuery) super.clone();

    // Don't use setters as that will trigger unprepare
    cloneQuery.containerPolicy = getContainerPolicy().clone(cloneQuery);

    return cloneQuery;
  }
 public void setup() {
   getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
   allEmployees = new Vector();
   queryAll = new ReadAllQuery();
   queryAll.setReferenceClass(Employee.class);
   queryAll.setSelectionCriteria(
       new ExpressionBuilder().get("address").get("city").greaterThan("Montreal"));
   allEmployees = (Vector) getSession().executeQuery(queryAll);
 }
  private void addOuterJoinJoiningTest() {
    ExpressionBuilder emp = new ExpressionBuilder();

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 12);
    test.setName("OuterJoinJoiningTest");
    test.setDescription("Test joining with outer joins");
    ReadAllQuery query = new ReadAllQuery(Employee.class);
    query.addJoinedAttribute(emp.getAllowingNull("address"));
    test.setQuery(query);

    addTest(test);
  }
  private void addOuterJoinJoiningComplexTest() {
    ExpressionBuilder emp = new ExpressionBuilder();

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Project.class, 15);
    test.setName("OuterJoinJoiningComplexTest");
    test.setDescription("Test joining with outer joins");
    ReadAllQuery query = new ReadAllQuery(Project.class);
    query.addJoinedAttribute(emp.getAllowingNull("teamLeader"));
    test.setQuery(query);

    addTest(test);
  }
  private void addOuterJoinOrderByTest() {
    ExpressionBuilder emp = new ExpressionBuilder();

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 12);
    test.setName("OuterJoinOrderByTest");
    test.setDescription("Test order by with outer joins");
    ReadAllQuery query = new ReadAllQuery(Employee.class);
    query.addOrdering(emp.getAllowingNull("address").get("city"));
    test.setQuery(query);

    addTest(test);
  }
 /**
  * INTERNAL: Return if the query is equal to the other. This is used to allow dynamic expression
  * query SQL to be cached.
  */
 public boolean equals(Object object) {
   if (this == object) {
     return true;
   }
   if (!super.equals(object)) {
     return false;
   }
   ReadAllQuery query = (ReadAllQuery) object;
   if (!getContainerPolicy().equals(query.getContainerPolicy())) {
     return false;
   }
   return true;
 }
  private void addOuterJoinJoiningTest2() {
    ExpressionBuilder emp = new ExpressionBuilder();

    ReadAllExpressionTest test =
        new ReadAllOuterJoinExpressionTest2(
            org.eclipse.persistence.testing.models.insurance.PolicyHolder.class, 4);
    test.setName("OuterJoinJoiningTest2");
    test.setDescription("Test joining with outer joins");
    ReadAllQuery query =
        new ReadAllQuery(org.eclipse.persistence.testing.models.insurance.PolicyHolder.class);
    query.addJoinedAttribute(emp.getAllowingNull("address"));
    test.setQuery(query);

    addTest(test);
  }
  public static TestSuite getReadAllTestSuite() {
    TestSuite suite = new TestSuite();
    suite.setName("InterfaceWithoutTablesReadAllTestSuite");
    suite.setDescription(
        "This suite tests the reading of all the objects of each class in the interface model (without tables).");

    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(Unionized.class);
    query.useCollectionClass(java.util.ArrayList.class);
    ReadAllTest aTest = new ReadAllTest(Unionized.class, 6);
    aTest.setQuery(query);
    suite.addTest(aTest);

    suite.addTest(new ReadAllTest(Actor.class, 4));
    suite.addTest(new ReadAllTest(Documentary.class, 1));
    suite.addTest(new ReadAllTest(Film.class, 3));
    suite.addTest(new ReadAllTest(Job.class, 18));
    suite.addTest(new ReadAllTest(ManagerialJob.class, 6));
    suite.addTest(new ReadAllTest(VIP.class, 3));
    // Used to test Cursored Streams
    ReadAllTest test = new ReadAllTest(VIP.class, 3);
    test.setQuery(new ReadAllQuery());
    test.getQuery().setReferenceClass(VIP.class);
    test.getQuery().useCursoredStream();
    suite.addTest(test);

    // Test the non-availability of batch reading
    test = new ReadAllBatchTest(Employee.class, 3);
    test.setName("Batch Read Test");
    test.setQuery(new ReadAllQuery());
    test.getQuery().setReferenceClass(Employee.class);
    test.getQuery().addBatchReadAttribute("contact");
    suite.addTest(test);

    suite.addTest(new OneToManyVariableBackBatchReadingTest());

    // Test cascading
    test = new ReadAllTest(Employee.class, 4);
    test.setQuery(new ReadAllQuery());
    test.getQuery().setReferenceClass(Employee.class);
    test.getQuery().cascadeAllParts();
    suite.addTest(test);

    suite.addTest(new ReadAllTest(Employee.class, 4));
    suite.addTest(new ReadAllConformInUowTest());
    return suite;
  }
  private void addOuterJoinAcrossInheritanceTest() {
    ExpressionBuilder emp = new ExpressionBuilder();

    ReadAllExpressionTest test =
        new ReadAllOuterJoinExpressionTest(
            org.eclipse.persistence.testing.models.inheritance.Person.class, 1);
    test.setName("OuterJoinAcrossInheritanceTest");
    test.setDescription("Test joining with outer joins across inheritance");
    ReadAllQuery query =
        new ReadAllQuery(org.eclipse.persistence.testing.models.inheritance.Person.class);

    // This test used to make no sense...
    // query.setSelectionCriteria(emp.getAllowingNull("representitive").get("name").equalOuterJoin("Richard"));
    query.addOrdering(emp.getAllowingNull("representitive").get("name"));
    test.setQuery(query);

    addTest(test);
  }
  public void setup() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    getAbstractSession().beginTransaction();

    descriptor = getSession().getProject().getDescriptors().get(Employee.class);

    // Read Object
    readObjectQuery = descriptor.getQueryManager().getReadObjectQuery();
    QueryRedirector redirector =
        new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "readObject");
    ReadObjectQuery roq = new ReadObjectQuery(descriptor.getJavaClass());
    roq.setRedirector(redirector);
    descriptor.getQueryManager().setReadObjectQuery(roq);

    // Read All
    readAllQuery = descriptor.getQueryManager().getReadAllQuery();
    redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "readAll");
    ReadAllQuery raq = new ReadAllQuery(descriptor.getJavaClass());
    raq.setRedirector(redirector);
    descriptor.getQueryManager().setReadAllQuery(raq);

    // Delete Object
    deleteObjectQuery = descriptor.getQueryManager().getDeleteQuery();
    redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "deleteObject");
    DeleteObjectQuery doq = new DeleteObjectQuery();
    doq.setRedirector(redirector);
    descriptor.getQueryManager().setDeleteQuery(doq);

    // Insert Object
    insertQuery = descriptor.getQueryManager().getInsertQuery();
    redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "insertObject");
    InsertObjectQuery ioq = new InsertObjectQuery();
    ioq.setRedirector(redirector);
    descriptor.getQueryManager().setInsertQuery(ioq);

    // Update Object
    updateQuery = descriptor.getQueryManager().getUpdateQuery();
    redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "updateObject");
    UpdateObjectQuery uoq = new UpdateObjectQuery();
    uoq.setRedirector(redirector);
    descriptor.getQueryManager().setUpdateQuery(uoq);
  }
  protected void test() {
    for (int i = 0; i <= 1; i++) {
      getSession().getPlatform().setShouldBindAllParameters(i != 0);
      for (int j = 0; j <= 2; j++) {
        query = new ReadAllQuery(Employee.class);
        ExpressionBuilder builder = new ExpressionBuilder();
        Vector vExp = new Vector(2);
        vExp.add(builder.getParameter("p1"));
        query.addArgument("p1");
        vExp.add(builder.getParameter("p2"));
        query.addArgument("p2");
        Expression exp = builder.get("id").in(vExp);
        query.setSelectionCriteria(exp);

        switch (j) {
          case 0:
            // nothing to do - just test the default:
            // query.bindAllParameters == Undefined
            break;
          case 1:
            // query.bindAllParameters == False
            query.setShouldBindAllParameters(false);
            break;
          case 2:
            // query.bindAllParameters == True
            query.setShouldBindAllParameters(true);
            break;
        }

        // clear the writer's buffer
        ((StringWriter) getSession().getLog()).getBuffer().setLength(0);
        try {
          getSession().executeQuery(query, v);
        } catch (DatabaseException e) {
          throw new TestProblemException("executeQuery threw DatabaseException");
        }
        if (shouldBind() != wasBound()) {
          return;
        }
      }
    }
  }
  public void setup() {
    // JGL: If the arguments are already set by the test, don't
    // set them again
    if (!hasArguments()) {
      setArgumentsForTestUsing(getSomeEmployees());
    }
    ReadAllQuery raq = new ReadAllQuery();
    raq.setReferenceClass(Employee.class);
    raq.setSelectionCriteria(getOriginalObjectExpression());
    // Add all the arguments to the query
    Enumeration enumtr = getExpressionParameters().elements();
    while (enumtr.hasMoreElements()) {
      raq.addArgument((String) enumtr.nextElement());
    }

    // Save the retrieved employees for the verify
    setOriginalOject(getSession().executeQuery(raq, getArguments()));

    // Finish the setup
    super.setup();
  }
 /** INTERNAL: Set the properties needed to be cascaded into the custom query. */
 protected void prepareCustomQuery(DatabaseQuery customQuery) {
   ReadAllQuery customReadQuery = (ReadAllQuery) customQuery;
   customReadQuery.setContainerPolicy(getContainerPolicy());
   customReadQuery.setCascadePolicy(getCascadePolicy());
   customReadQuery.setShouldRefreshIdentityMapResult(shouldRefreshIdentityMapResult());
   customReadQuery.setShouldMaintainCache(shouldMaintainCache());
   customReadQuery.setShouldUseWrapperPolicy(shouldUseWrapperPolicy());
 }
  public void setup() {
    // Get the baseline employees for the verify
    Employee emp = (Employee) getSomeEmployees().firstElement();

    String parameterName = "firstName";
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause = builder.get("firstName").equal(builder.getParameter(parameterName));

    ReadAllQuery raq = new ReadAllQuery();
    raq.setReferenceClass(Employee.class);
    raq.setSelectionCriteria(whereClause);
    raq.addArgument(parameterName);

    Vector parameters = new Vector();
    parameters.add(emp.getFirstName());

    Vector employees = (Vector) getSession().executeQuery(raq, parameters);

    emp = (Employee) employees.firstElement();

    // Set up the EJBQL using the retrieved employees
    String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE ";
    ejbqlString = ejbqlString + "?1 = emp.firstName ";

    setEjbqlString(ejbqlString);
    setOriginalOject(employees);

    setArguments(parameters);

    Vector myArgumentNames = new Vector();
    myArgumentNames.add("1");
    setArgumentNames(myArgumentNames);

    // Finish the setup
    super.setup();
  }
 /**
  * INTERNAL: Prepare the query from the prepared query. This allows a dynamic query to prepare
  * itself directly from a prepared query instance. This is used in the JPQL parse cache to allow
  * preparsed queries to be used to prepare dynamic queries. This only copies over properties that
  * are configured through JPQL.
  */
 public void prepareFromQuery(DatabaseQuery query) {
   super.prepareFromQuery(query);
   if (query.isReadAllQuery()) {
     ReadAllQuery readQuery = (ReadAllQuery) query;
     this.containerPolicy = readQuery.containerPolicy;
     if (readQuery.hasHierarchicalExpressions()) {
       this.orderSiblingsByExpressions = readQuery.getOrderSiblingsByExpressions();
       this.connectByExpression = readQuery.getConnectByExpression();
       this.startWithExpression = readQuery.getStartWithExpression();
     }
     if (readQuery.hasBatchReadAttributes()) {
       this.batchReadAttributeExpressions = readQuery.batchReadAttributeExpressions;
       this.batchReadMappingQueries = readQuery.batchReadMappingQueries;
       this.batchReadAttributes = readQuery.batchReadAttributes;
     }
   }
 }
  public void test() {

    ReadAllQuery query = new ReadAllQuery();
    ScrollableCursor cursor = null;

    try {
      query.setReferenceClass(Employee.class);
      if (TYPE_SCROLL_INSENSITIVE_isSupported && CONCUR_UPDATABLE_isSupported) {
        query.useScrollableCursor(2);
      } else {
        ScrollableCursorPolicy policy = new ScrollableCursorPolicy();
        if (!TYPE_SCROLL_INSENSITIVE_isSupported) {
          policy.setResultSetType(ScrollableCursorPolicy.TYPE_SCROLL_SENSITIVE);
        }
        if (!CONCUR_UPDATABLE_isSupported) {
          policy.setResultSetConcurrency(ScrollableCursorPolicy.CONCUR_READ_ONLY);
        }
        policy.setPageSize(2);
        query.useScrollableCursor(policy);
      }
      //
      if (configuration != null) {
        ExpressionBuilder builder = new ExpressionBuilder();
        Expression exp = builder.get("salary").greaterThan(50000);
        query.setSelectionCriteria(exp);
        query.conformResultsInUnitOfWork();
      }
      cursor = (ScrollableCursor) getSession().executeQuery(query);

      try {
        // test to see if we can iterate through a list and then iterate
        // in reverse through the same list.
        int totalItems = 0;
        while (cursor.hasNext()) {
          readWithNext.addElement(cursor.next());
          totalItems++;
        }
        while (cursor.hasPrevious()) {
          readWithPrevious.addElement(cursor.previous());
          totalItems--;
        }

        cursorSuccess = (totalItems == 0);

        int size = readWithPrevious.size();
        for (int i = 0; i < readWithNext.size(); i++) {
          cursorSuccess =
              (cursorSuccess
                  && (readWithNext.elementAt(i) == readWithPrevious.elementAt((size - 1) - i)));
        }

      } catch (org.eclipse.persistence.exceptions.QueryException ex) {
        caughtException = ex;
      }

    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
 protected boolean shouldBind() {
   return (!query.shouldIgnoreBindAllParameters() && query.shouldBindAllParameters())
       || (query.shouldIgnoreBindAllParameters()
           && getSession().getPlatform().shouldBindAllParameters());
 }
  /**
   * Load the last test result from the test result database. Find only the results run on the same
   * machine and database. Compare the current test run result with the previous results do
   * determine if the test passes or fails.
   */
  public static void verify(PerformanceRegressionTest test) {
    // Ensures all tests pass to reset baseline,
    // Required when tests or environment change to be slower to avoid failures.
    if (reset) {
      throw new TestWarningException("Reseting baseline.");
    }
    Session session = LoadBuildSystem.getSystem().getSession();

    // Query all previous successful test results for this test on the same machine and database.
    // Find only the baseline version, or last version run different than current version.
    // If you need to compare results against the current version you must change the TopLink
    // version string.
    ReadAllQuery query = new ReadAllQuery(TestResult.class);
    ExpressionBuilder result = new ExpressionBuilder();
    query.setSelectionCriteria(
        result
            .get("name")
            .equal(test.getName())
            .and(
                result
                    .get("loadBuildSummary")
                    .get("machine")
                    .equal(LoadBuildSystem.getSummary().getMachine()))
            .and(
                result
                    .get("loadBuildSummary")
                    .get("loginChoice")
                    .equal(LoadBuildSystem.getSummary().getLoginChoice())));
    // Allow comparing to a set version through a system property.
    String currentVersion = LoadBuildSystem.getSummary().getToplinkVersion();
    String baselineVersion = null;
    if (System.getProperties().containsKey("toplink.loadbuild.baseline-version")) {
      baselineVersion = System.getProperties().getProperty("toplink.loadbuild.baseline-version");
      // System properties cannot store spaces so need to replace them from \b.
      baselineVersion = baselineVersion.replace('_', ' ');
      ((PerformanceComparisonTestResult) ((TestCase) test).getTestResult()).baselineVersion =
          baselineVersion;
    } else {
      // Compare against the last successful version.
      ReportQuery reportQuery = new ReportQuery(TestResult.class, query.getExpressionBuilder());
      reportQuery.useDistinct();
      reportQuery.returnSingleValue();
      reportQuery.addAttribute("version", result.get("loadBuildSummary").get("toplinkVersion"));
      reportQuery.setSelectionCriteria(
          query
              .getSelectionCriteria()
              .and(
                  (result.get("outcome").equal(TestResult.PASSED))
                      .or(result.get("outcome").equal(TestResult.WARNING)))
              .and(result.get("loadBuildSummary").get("toplinkVersion").notEqual(currentVersion)));
      reportQuery.addOrdering(result.get("loadBuildSummary").get("timestamp").descending());
      baselineVersion = (String) session.executeQuery(reportQuery);
    }
    query.setSelectionCriteria(
        query
            .getSelectionCriteria()
            .and(result.get("loadBuildSummary").get("toplinkVersion").equal(baselineVersion)));
    query.addOrdering(result.get("loadBuildSummary").get("timestamp").descending());
    query.setMaxRows(10);
    query.useCursoredStream(1, 1);
    CursoredStream stream = (CursoredStream) session.executeQuery(query);
    if (!stream.hasMoreElements()) {
      throw new TestWarningException("No previous test result to compare performance with.");
    }
    TestResult lastResult = (TestResult) stream.nextElement();
    double lastCount = lastResult.getTestTime();
    PerformanceComparisonTestResult testResult =
        (PerformanceComparisonTestResult) ((TestCase) test).getTestResult();
    testResult.getBaselineVersionResults().add(new Double(lastCount));
    // Average last 5 runs.
    int numberOfRuns = 0;
    while (stream.hasMoreElements() && (numberOfRuns < 4)) {
      TestResult nextResult = (TestResult) stream.nextElement();
      testResult.getBaselineVersionResults().add(new Double(nextResult.getTestTime()));
      numberOfRuns++;
    }
    stream.close();
    double baselineAverage =
        PerformanceComparisonTestResult.averageResults(testResult.getBaselineVersionResults());
    double currentCount = ((TestCase) test).getTestResult().getTestTime();
    testResult.baselineVersion = lastResult.getLoadBuildSummary().getToplinkVersion();
    testResult.percentageDifferenceLastRun =
        PerformanceComparisonTestResult.percentageDifference(currentCount, lastCount);

    // Query the current version last 5 runs for averaging.
    query = new ReadAllQuery(TestResult.class);
    result = new ExpressionBuilder();
    query.setSelectionCriteria(
        result
            .get("name")
            .equal(((TestCase) test).getName())
            .and(
                result
                    .get("loadBuildSummary")
                    .get("machine")
                    .equal(LoadBuildSystem.getSummary().getMachine()))
            .and(
                result
                    .get("loadBuildSummary")
                    .get("loginChoice")
                    .equal(LoadBuildSystem.getSummary().getLoginChoice()))
            .and(result.get("loadBuildSummary").get("toplinkVersion").equal(currentVersion)));
    query.addOrdering(result.get("loadBuildSummary").get("timestamp").descending());
    query.useCursoredStream(1, 1);
    stream = (CursoredStream) session.executeQuery(query);
    // Average last 5 runs.
    testResult.getCurrentVersionResults().add(new Double(currentCount));
    numberOfRuns = 0;
    while (stream.hasMoreElements() && (numberOfRuns < 4)) {
      TestResult nextResult = (TestResult) stream.nextElement();
      testResult.getCurrentVersionResults().add(new Double(nextResult.getTestTime()));
      numberOfRuns++;
    }
    stream.close();
    double currentAverage =
        PerformanceComparisonTestResult.averageResults(testResult.getCurrentVersionResults());
    testResult.percentageDifferenceAverage =
        PerformanceComparisonTestResult.percentageDifference(currentAverage, baselineAverage);

    testResult.baselineStandardDeviation =
        PerformanceComparisonTestResult.standardDeviationResults(
            testResult.getBaselineVersionResults());
    testResult.currentStandardDeviation =
        PerformanceComparisonTestResult.standardDeviationResults(
            testResult.getCurrentVersionResults());

    if (testResult.percentageDifferenceAverage < test.getAllowableDecrease()) {
      throw new TestErrorException(
          "Test is "
              + ((long) testResult.percentageDifferenceAverage)
              + "% slower than last successful execution.");
    }
  }
  public void test() {

    ReadAllQuery query = new ReadAllQuery();

    if (configuration != null) {
      ExpressionBuilder emp = new ExpressionBuilder();
      Expression exp = emp.get("salary").greaterThan(50000);
      query.setSelectionCriteria(exp);
      query.conformResultsInUnitOfWork();
    }
    ScrollableCursor cursor = null;

    try {
      query.setReferenceClass(Employee.class);
      if (TYPE_SCROLL_INSENSITIVE_isSupported && CONCUR_UPDATABLE_isSupported) {
        query.useScrollableCursor(2);
      } else {
        ScrollableCursorPolicy policy = new ScrollableCursorPolicy();
        if (!TYPE_SCROLL_INSENSITIVE_isSupported) {
          policy.setResultSetType(ScrollableCursorPolicy.TYPE_SCROLL_SENSITIVE);
        }
        if (!CONCUR_UPDATABLE_isSupported) {
          policy.setResultSetConcurrency(ScrollableCursorPolicy.CONCUR_READ_ONLY);
        }
        policy.setPageSize(2);
        query.useScrollableCursor(policy);
      }
      cursor = (ScrollableCursor) getSession().executeQuery(query);

      try {
        boolean isFirst = cursor.first();
        if (!cursor.isFirst() || !isFirst) {
          navigationError = "cursor.first() does not result in cursor.isFirst() returning true.";
        }
        Object second = cursor.next();
        Object first = cursor.previous();
        if (first.equals(second)) {
          navigationError = "cursor.next() and cursor.previous() are not complementary.";
        }
        if (!second.equals(cursor.next())) {
          navigationError = "cursor.next() does not move the cursor forward.";
        }
        boolean isRelative = cursor.relative(1);
        if (!isRelative || !second.equals(cursor.previous())) {
          navigationError =
              "cursor.relative() does not move the cursor the proper number of spaces.";
        }
        boolean isAbsolute = cursor.absolute(1);
        if (!second.equals(cursor.next())) {
          navigationError = "cursor.absolute(0) move a cursor to the beginning of the cursor.";
        }
        cursor.beforeFirst();
        if (!cursor.isBeforeFirst()) {
          navigationError =
              "cursor.beforeFirst() does not result in cursor.isBeforeFirst() returning true.";
        }
        if (!first.equals(cursor.next())) {
          navigationError = "cursor.beforeFirst() does not set the cursor position properly.";
        }

        boolean isLast = cursor.last();
        if (!isLast || !cursor.isLast()) {
          navigationError = "cursor.last() does not result in cursor.isLast() returning true.";
        }
        cursor.afterLast();

        if (!cursor.isAfterLast()) {
          navigationError =
              "cursor.afterLast() does not result in cursor.isAfterLast() returning true.";
        }
        Object last = cursor.previous();
        int size = cursor.size();
        cursor.relative(size);
        Object lastBySize = cursor.previous();
        if (!last.equals(lastBySize)) {
          navigationError = "The last item in the list is not correct.";
        }

      } catch (org.eclipse.persistence.exceptions.QueryException ex) {
        caughtException = ex;
      }

    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
 /** Read all employees with salary > 0. */
 public void test() throws Exception {
   ReadAllQuery query = new ReadAllQuery(Employee.class);
   ExpressionBuilder builder = new ExpressionBuilder();
   query.setSelectionCriteria(builder.get("salary").greaterThan(0));
   List results = (List) getSession().executeQuery(query);
 }