コード例 #1
0
  public void setup() {
    setReferenceClass(Employee.class);

    // add a mapping for addressId so we can use it in from "emp"
    //        DirectToFieldMapping addressIdMapping = new DirectToFieldMapping();
    //        addressIdMapping.setAttributeName("addressId");
    //        addressIdMapping.setFieldName("EMPLOYEE.ADDR_ID");
    //        addressIdMapping.setGetMethodName("getAddressId");
    //        addressIdMapping.setSetMethodName("setAddressId");
    //        addressIdMapping.setIsReadOnly(true);
    //        getSession().getDescriptor(Employee.class).addMapping(addressIdMapping);
    //        addressIdMapping.initialize(getSession());
    ExpressionBuilder builder = new ExpressionBuilder(Employee.class);
    ExpressionBuilder addressBuilder = new ExpressionBuilder(Address.class);
    Expression whereClause = builder.get("addressId").equal(addressBuilder.get("id"));
    Vector employees = getSession().readAllObjects(Employee.class, whereClause);

    setOriginalOject(employees);
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();

    String ejbqlString;
    ejbqlString =
        "SELECT OBJECT(emp) FROM Employee emp, Address address "
            + "WHERE emp.addressId = address.id";

    setEjbqlString(ejbqlString);
    super.setup();
  }
  public static BinaryOperatorWithParameterTest
      getNumericParameterDivideTestWithBracketsAfterComparison() {
    BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest();
    theTest.setName("Divide with parameter test with brackets after comparison");

    String parameterName = "amountToDivide";
    theTest.setExpressionParameters(new Vector());
    theTest.getExpressionParameters().add(parameterName);

    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause =
        ExpressionBuilder.fromConstant(new Integer(20000), builder)
            .greaterThan(
                ExpressionMath.divide(
                    builder.get("salary"), (builder.getParameter(parameterName))));
    theTest.setOriginalObjectExpression(whereClause);

    String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE 20000 > (emp.salary / ?1)";

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

    theTest.setArguments(new Vector());
    theTest.getArguments().addElement(new Integer(2));

    return theTest;
  }
  public static BinaryOperatorWithParameterTest
      getNumericParameterMultiplyTestWithBracketsBeforeComparison() {
    BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest();
    theTest.setName("Multiply with parameter test with brackets before comparison");

    String parameterName = "amountToMultiply";
    theTest.setExpressionParameters(new Vector());
    theTest.getExpressionParameters().add(parameterName);

    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause =
        ExpressionMath.multiply(builder.get("salary"), (builder.getParameter(parameterName)))
            .lessThanEqual(100000);
    theTest.setOriginalObjectExpression(whereClause);

    String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE (emp.salary * ?1) <= 100000";

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

    theTest.setArguments(new Vector());
    theTest.getArguments().addElement(new Integer(2));

    return theTest;
  }
コード例 #4
0
  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();
  }
コード例 #5
0
  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();
  }
コード例 #6
0
  private void addOuterJoinParallelExpressionTest() {
    ExpressionBuilder emp = new ExpressionBuilder(Employee.class);
    ExpressionBuilder addr = new ExpressionBuilder(Address.class);
    Expression expression =
        emp.get("firstName")
            .equal("Bob")
            .or(emp.getAllowingNull("address").get("city").equal("Ottawa"))
            .or(emp.getAllowingNull("address").equal(addr).and(addr.get("city").equal("Ottawa")));

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 22);
    test.setName("OuterJoinParallelExpressionTest");
    test.setDescription("Test using isNull with outer joins");
    test.setExpression(expression);

    addTest(test);
  }
  public static BinaryOperatorWithParameterTest getNumericParameterDivideTest() {
    BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest();
    theTest.setName("Divide with parameter test");

    String parameterName = "amountToDivide";
    theTest.setExpressionParameters(new Vector());
    theTest.getExpressionParameters().add(parameterName);

    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause =
        ExpressionMath.divide(builder.get("salary"), (builder.getParameter(parameterName)))
            .lessThanEqual(20000);
    theTest.setOriginalObjectExpression(whereClause);

    String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.salary / ?1 <= 20000";

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

    theTest.setArguments(new Vector());
    theTest.getArguments().addElement(new Integer(2));

    return theTest;
  }
コード例 #8
0
  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();
  }
コード例 #9
0
 public ReadQuery getQueryForTest() {
   ReportQuery testQuery = new ReportQuery();
   testQuery.setReferenceClass(Employee.class);
   ExpressionBuilder employees = new ExpressionBuilder();
   Expression exp = employees.get("firstName").like("B%");
   testQuery.setSelectionCriteria(exp);
   testQuery.cacheQueryResults();
   testQuery.addAttribute("firstName");
   return testQuery;
 }
コード例 #10
0
  private void addOuterJoinOrWhereClauseTest3() {
    ExpressionBuilder emp = new ExpressionBuilder();
    Expression expression =
        emp.get("firstName")
            .like("Sarah%")
            .and(emp.get("lastName").like("Smit%"))
            .or(
                emp.getAllowingNull("manager")
                    .get("firstName")
                    .like("Sarah%")
                    .and(emp.getAllowingNull("manager").get("lastName").like("Smit%")));

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 2);
    test.setName("OuterJoinOrWhereClauseTest3");
    test.setDescription("Test expression with outer joins");
    test.setExpression(expression);

    addTest(test);
  }
コード例 #11
0
  private void createEmployeeAndSearchExpression() {
    // Create the example employee
    employee =
        (org.eclipse.persistence.testing.models.employee.domain.Employee)
            new org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator()
                .basicEmployeeExample1();
    employee.setFirstName("Timugen");
    employee.setLastName("Singaera");
    employee.addResponsibility("Answer the phones.");

    // Create an expression to retreive the employee from the database
    ExpressionBuilder expressionBuilder = new ExpressionBuilder();
    Expression exp1;
    Expression exp2;
    Expression expression;

    exp1 = expressionBuilder.get("firstName").equal(employee.getFirstName());
    exp2 = expressionBuilder.get("lastName").equal(employee.getLastName());

    searchExpression = exp1.or(exp2);
  }
コード例 #12
0
  private void addOuterJoinOrWhereClauseTest1() {
    ExpressionBuilder emp = new ExpressionBuilder();
    Expression expression =
        emp.get("firstName")
            .like("Bob%")
            .or(emp.getAllowingNull("address").get("city").like("Ot%"));

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 2);
    test.setName("OuterJoinOrWhereClauseTest1");
    test.setDescription("Test expression with outer joins");
    test.setExpression(expression);

    addTest(test);
  }
コード例 #13
0
  private void addOuterJoinManyToManyTest() {
    ExpressionBuilder emp = new ExpressionBuilder();
    Expression expression =
        emp.get("firstName")
            .like("%")
            .or(emp.anyOfAllowingNone("projects").get("description").like("%"));

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 12);
    test.setName("OuterJoinManytoManyTest");
    test.setDescription("Tests manytomany relationships with outer joins");
    test.setExpression(expression);

    addTest(test);
  }
コード例 #14
0
  private void addOuterJoinDirectCollectionTest() {
    ExpressionBuilder emp = new ExpressionBuilder();
    Expression expression =
        emp.get("firstName")
            .equal("Nancy")
            .or(emp.anyOfAllowingNone("responsibilitiesList").equal("Write lots of Java code."));

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 2);
    test.setName("OuterJoinDirectCollectionTest");
    test.setDescription("Tests direct collection relationships with outer joins");
    test.setExpression(expression);

    addTest(test);
  }
コード例 #15
0
  private void addOuterJoinOrAnyWhereClauseTest() {
    ExpressionBuilder emp = new ExpressionBuilder();
    Expression expression =
        emp.get("firstName")
            .like("Sarah%")
            .or(emp.anyOfAllowingNone("phoneNumbers").get("areaCode").equal("613"));

    ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 10);
    test.setName("OuterJoinOrAnyWhereClauseTest");
    test.setDescription("Test expression anyof with outer joins");
    test.setExpression(expression);

    addTest(test);
  }
コード例 #16
0
  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 static BinaryOperatorWithParameterTest
      getNumericTwoParameterMultipleOperatorsWithBracketsAroundMultiply() {
    BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest();
    theTest.setName("Multiple operators with two parameters with brackets around multiply");

    String parameterNameForDivide = "amountToDivide";
    String parameterNameForMultiply = "amountToMultiply";
    theTest.setExpressionParameters(new Vector());
    theTest.getExpressionParameters().add(parameterNameForDivide);
    theTest.getExpressionParameters().add(parameterNameForMultiply);

    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause =
        builder
            .get("salary")
            .greaterThan(
                ExpressionMath.subtract(
                    ExpressionMath.add(
                        ExpressionBuilder.fromConstant(new Integer(50000), builder), 10000),
                    ExpressionMath.divide(
                        ExpressionBuilder.fromConstant(new Integer(10000), builder),
                        ExpressionMath.multiply(
                            builder.getParameter(parameterNameForMultiply),
                            builder.getParameter(parameterNameForDivide)))));
    theTest.setOriginalObjectExpression(whereClause);

    String ejbqlString =
        "SELECT OBJECT(emp) FROM Employee emp WHERE emp.salary > (50000 + 10000 - 10000 / (?1 * ?2))";

    theTest.setEjbqlString(ejbqlString);
    Vector myArgumentNames = new Vector();
    myArgumentNames.add("1");
    myArgumentNames.add("2");
    theTest.setArgumentNames(myArgumentNames);

    theTest.setArguments(new Vector());
    theTest.getArguments().addElement(new Integer(2));
    theTest.getArguments().addElement(new Integer(5));

    return theTest;
  }
  public static BinaryOperatorWithParameterTest getNumericParameterLessThanEqualTest() {
    BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest();
    theTest.setName("Less than equal to with parameter test");

    String parameterName = "id";
    theTest.setExpressionParameters(new Vector());
    theTest.getExpressionParameters().add(parameterName);

    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause = builder.get("id").lessThanEqual(builder.getParameter(parameterName));
    theTest.setOriginalObjectExpression(whereClause);

    String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE ";
    ejbqlString = ejbqlString + "emp.id <= ?1 ";

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

    return theTest;
  }
  public static BinaryOperatorWithParameterTest
      getNumericTwoParameterMultipleOperatorsWithBracketsAroundPlusMinus() {
    BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest();
    theTest.setName("Multiple operators with two parameters with brackets around plus/minus");

    String parameterNameForDivide = "amountToDivide";
    String parameterNameForMultiply = "amountToMultiply";
    theTest.setExpressionParameters(new Vector());
    theTest.getExpressionParameters().add(parameterNameForDivide);
    theTest.getExpressionParameters().add(parameterNameForMultiply);

    ExpressionBuilder builder = new ExpressionBuilder();
    Expression whereClause =
        ExpressionMath.multiply(
                ExpressionMath.divide(
                    ExpressionMath.subtract(ExpressionMath.add(builder.get("salary"), 10), 20),
                    builder.getParameter(parameterNameForDivide)),
                builder.getParameter(parameterNameForMultiply))
            .greaterThanEqual(70000);
    theTest.setOriginalObjectExpression(whereClause);

    String ejbqlString =
        "SELECT OBJECT(emp) FROM Employee emp WHERE (emp.salary + 10 - 20) / ?1 * ?2 >= 70000";

    theTest.setEjbqlString(ejbqlString);
    Vector myArgumentNames = new Vector();
    myArgumentNames.add("1");
    myArgumentNames.add("2");
    theTest.setArgumentNames(myArgumentNames);

    theTest.setArguments(new Vector());
    theTest.getArguments().addElement(new Integer(2));
    theTest.getArguments().addElement(new Integer(3));

    return theTest;
  }
コード例 #20
0
  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();
  }
  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();
      }
    }
  }
コード例 #22
0
  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();
      }
    }
  }