public void complexDistinctCountTest() {
    oracle.toplink.essentials.ejb.cmp3.EntityManager em =
        (oracle.toplink.essentials.ejb.cmp3.EntityManager) createEntityManager();

    ExpressionBuilder expbldr = new ExpressionBuilder();

    ReportQuery rq = new ReportQuery(Employee.class, expbldr);

    Expression exp = expbldr.get("lastName").equal("Smith");

    rq.setReferenceClass(Employee.class);
    rq.setSelectionCriteria(exp);
    rq.useDistinct();
    rq.returnSingleAttribute();
    rq.dontRetrievePrimaryKeys();
    rq.addCount("COUNT", expbldr.get("lastName").distinct(), Long.class);
    Vector expectedResultVector = (Vector) em.getActiveSession().executeQuery(rq);
    Long expectedResult = (Long) expectedResultVector.get(0);

    String ejbqlString =
        "SELECT COUNT(DISTINCT emp.lastName) FROM Employee emp WHERE emp.lastName = \"Smith\"";
    Long result = (Long) em.createQuery(ejbqlString).getSingleResult();

    Assert.assertEquals("Complex DISTINCT COUNT test failed", expectedResult, result);
  }
 // shchool buses without drivers
 public static void test_schoolBusNullDriver() {
   ExpressionBuilder builder = new ExpressionBuilder();
   Expression exp =
       builder
           .get("description")
           .equalsIgnoreCase("School bus")
           .and(builder.get("busDriver").isNull());
   deleteAllQueryInternal_Deferred_Children(Bus.class, exp);
 }
  // FueledVehicles owned by Companies that also own NonFueledVehicles
  public static void test_ownerOwnsNonFueledVehicle() {
    ExpressionBuilder builder = new ExpressionBuilder();

    ExpressionBuilder subBuilder = new ExpressionBuilder();
    ReportQuery rq = new ReportQuery(NonFueledVehicle.class, subBuilder);
    rq.addAttribute("id");
    Expression subExpression = subBuilder.get("owner").equal(builder.get("owner"));
    rq.setSelectionCriteria(subExpression);

    Expression exp = builder.exists(rq);
    deleteAllQueryInternal_Deferred_Children(FueledVehicle.class, exp);
  }
  /*
   * test for gf675, using count, group by and having fails.  This test is specific for a a use case
   * where DISTINCT is used with Count and group by
   */
  public void complexCountDistinctWithGroupByTest2() {
    oracle.toplink.essentials.ejb.cmp3.EntityManager em =
        (oracle.toplink.essentials.ejb.cmp3.EntityManager) createEntityManager();

    // need to set the class in the expressionbuilder, as the Count(Distinct) will cause the
    // query to change and be built around the Employee class instead of the Address class.
    ExpressionBuilder expbldr = new ExpressionBuilder(Address.class);

    ReportQuery rq = new ReportQuery(Address.class, expbldr);
    Expression exp = expbldr.anyOf("employees");

    Expression exp2 = expbldr.get("city");
    rq.addAttribute("city", exp2);
    rq.addCount("COUNT1", exp, Long.class);
    rq.addCount("COUNT2", exp.get("lastName").distinct(), Long.class);
    rq.addGrouping(exp2);
    Vector expectedResult = (Vector) em.getActiveSession().executeQuery(rq);

    String ejbqlString3 =
        "SELECT a.city, COUNT( e ), COUNT( DISTINCT e.lastName ) FROM Address a JOIN a.employees e GROUP BY a.city";
    Query q = em.createQuery(ejbqlString3);
    List result = (List) q.getResultList();

    Assert.assertTrue(
        "Complex COUNT(Distinct) with Group By test failed",
        comparer.compareObjects(result, expectedResult));
  }
  public void complexSumTest() {
    oracle.toplink.essentials.ejb.cmp3.EntityManager em =
        (oracle.toplink.essentials.ejb.cmp3.EntityManager) createEntityManager();

    ExpressionBuilder expbldr = new ExpressionBuilder();

    ReportQuery rq = new ReportQuery(Employee.class, expbldr);
    rq.setReferenceClass(Employee.class);
    rq.returnSingleAttribute();
    rq.dontRetrievePrimaryKeys();
    rq.addAttribute("salary", expbldr.get("salary").distinct().sum(), Long.class);
    Vector expectedResultVector = (Vector) em.getActiveSession().executeQuery(rq);
    Long expectedResult = (Long) expectedResultVector.get(0);

    String ejbqlString = "SELECT SUM(DISTINCT emp.salary) FROM Employee emp";
    Long result = (Long) em.createQuery(ejbqlString).getSingleResult();

    Assert.assertEquals("Complex SUMtest failed", expectedResult, result);
  }
 // FueledVehicles running on Petrol
 public static void test_fuelTypePetrol() {
   ExpressionBuilder builder = new ExpressionBuilder();
   Expression exp = builder.get("fuelType").equalsIgnoreCase("Petrol");
   deleteAllQueryInternal_Deferred_Children(FueledVehicle.class, exp);
 }
 // Vehicles owned by TOP Company
 public static void test_ownerTOP() {
   ExpressionBuilder builder = new ExpressionBuilder();
   Expression exp = builder.get("owner").get("name").equal("TOP");
   deleteAllQueryInternal_Deferred_Children(Vehicle.class, exp);
 }