public void test() {
    // test readAll
    getSession().readAllObjects(Employee.class);
    getSession().getIdentityMapAccessor().initializeIdentityMap(Employee.class);

    // test readObject
    Employee employee =
        (Employee)
            getSession().readObject(Employee.class, new ExpressionBuilder().get("id").equal(99));

    // test delete with an employee read from the database
    employee = (Employee) getSession().readObject(Employee.class);
    try {
      getAbstractSession().deleteObject(employee);
    } catch (DatabaseException exc) {
      // if we get an integrity exception here, the query went to the DB and was not redirected
      redirectedDeleteObject = false;
    }

    UnitOfWork uow = getSession().acquireUnitOfWork();
    // test update with an employee read from the database
    employee = (Employee) uow.readObject(Employee.class);
    employee.setFirstName(employee.getFirstName() + "-changed");

    // insert an employee to test the insert behavior
    employee = new Employee();
    employee.setFirstName("Paul");
    employee.setLastName("Sheldon");
    uow.registerObject(employee);

    uow.commit();
  }
  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();
  }
  public void test() {

    UnitOfWork uow = getSession().acquireUnitOfWork();
    UnitOfWork nestedUow1 = uow.acquireUnitOfWork();
    UnitOfWork nestedNestedUOW = nestedUow1.acquireUnitOfWork();

    Employee employee = (Employee) new EmployeePopulator().basicEmployeeExample1();
    employee.setId(new BigDecimal(15));
    Employee nestedEmployee = (Employee) nestedNestedUOW.registerObject(employee);
    nestedNestedUOW.commit();
    nestedUow1.commit();

    nestedUow1 = uow.acquireUnitOfWork();
    nestedNestedUOW = nestedUow1.acquireUnitOfWork();

    ReadObjectQuery query = new ReadObjectQuery();
    query.setReferenceClass(Employee.class);
    query.setSelectionCriteria(
        new org.eclipse.persistence.expressions.ExpressionBuilder()
            .get("id")
            .equal(new BigDecimal(15)));
    query.conformResultsInUnitOfWork();
    nestedEmployee = (Employee) nestedNestedUOW.executeQuery(query);

    nestedNestedUOW.deleteObject(nestedEmployee);
    nestedNestedUOW.commit();
    nestedUow1.commit();
    if (!((UnitOfWorkImpl) uow).getNewObjectsCloneToOriginal().isEmpty()) {
      throw new TestErrorException("Failed to unregister the Object in the nested unit of work");
    }
  }
  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() {
    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();
  }
  /**
   * Return the first employee that has a long enough name for the test. If no match is found throw
   * a warning exception. See bug 223005
   *
   * @param vectorOfEmployees
   * @param minFirstNameLength
   * @param testName
   * @return
   */
  public Employee getEmployeeWithRequiredNameLength(
      Vector vectorOfEmployees, int minFirstNameLength, String testName) {
    Employee empMatch = null;
    Vector<Employee> employees = vectorOfEmployees;
    String firstName;
    StringBuffer partialFirstName;

    // Loop through the collection of employees to find one that matches our test requirements
    for (int i = 0; i < employees.size(); i++) {
      empMatch = employees.get(i);
      firstName = empMatch.getFirstName();
      // Verify length criteria
      if (firstName.length() >= minFirstNameLength) {
        // exit the for loop - return the last empMatch
        i = employees.size();
      }
    }

    // If we could not find a proper employee for testing - throw a warning
    if (null == empMatch) {
      throw new RuntimeException(
          testName
              + " Setup Failed: unable to find an Employee with firstName size of at least  "
              + minFirstNameLength);
    } else {
      return empMatch;
    }
  }
 protected Object buildOriginalObject() {
   Employee emp = new Employee();
   emp.setFirstName("Sally");
   emp.setLastName("Hamilton");
   emp.setFemale();
   return emp;
 }
  protected void verify() {
    if (!employee.getAddress().getCity().equals("null")) {
      throw new TestErrorException("Null value not converted correctly for string.");
    }

    if (employee.getSalary() != -1) {
      throw new TestErrorException("Null value not converted correctly for int.");
    }
  }
  protected void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    ReadObjectQuery query = new ReadObjectQuery(Employee.class);
    query.setLockMode(ObjectLevelReadQuery.LOCK_NOWAIT);
    Employee emp = (Employee) uow.executeQuery(query);

    emp.setSalary(emp.getSalary() + 1);
    uow.commit();
  }
 protected void changeNestedUnitOfWorkAgain2() {
   // Many to many
   nestedUnitOfWorkWorkingCopy.setProjects(new Vector());
   // Direct collection
   nestedUnitOfWorkWorkingCopy.addResponsibility("dragon boat this summer");
   // One to one private/public
   nestedUnitOfWorkWorkingCopy.setAddress(
       new org.eclipse.persistence.testing.models.employee.domain.Address());
   nestedUnitOfWorkWorkingCopy.setManager(null);
 }
 public void verify() {
   Employee distEmp = (Employee) getObjectFromDistributedSession(this.query);
   Enumeration enumtr = this.numbers.elements();
   while (enumtr.hasMoreElements()) {
     if (distEmp.getPhoneNumbers().contains(enumtr.nextElement())) {
       throw new org.eclipse.persistence.testing.framework.TestErrorException(
           "Failed to delete private owned objects from distributed cache");
     }
   }
 }
  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();
  }
  private void setArgumentsForTestUsing(Vector employees) {
    setArguments(new Vector());

    Enumeration names = getExpressionParameters().elements();
    Enumeration employeeEnum = employees.elements();
    while (names.hasMoreElements()) {
      Employee emp = (Employee) employeeEnum.nextElement();
      getArguments().add(emp.getId());
      names.nextElement();
    }
  }
  protected void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();

    Employee empInsert = new Employee();
    empInsert.setFirstName("TestPerson");
    empInsert.setFemale();
    empInsert.setLastName("Smith");
    empInsert.setSalary(55555);
    uow.registerObject(empInsert);
    uow.commit();
  }
  public void setup() {

    // This method tests the specail operations:
    employee = new Employee();
    policy = new QueryByExamplePolicy();
    employee.setFirstName("J__l");
    employee.setLastName("M%");
    employee.setSalary(60000);

    policy.addSpecialOperation(Integer.class, "lessThan");
    policy.addSpecialOperation(String.class, "like");
  }
  protected void changeObject() {
    Employee employee = (Employee) this.workingCopy;
    employee.setFirstName("Bob");

    employee.setPhoneNumbers(new Vector());
    employee.addPhoneNumber(
        new org.eclipse.persistence.testing.models.employee.domain.PhoneNumber(
            "home", "613", "2263374"));
    employee.addPhoneNumber(
        new org.eclipse.persistence.testing.models.employee.domain.PhoneNumber(
            "office", "416", "8224599"));
  }
  public void setup() {
    Employee emp = (Employee) getSomeEmployees().firstElement();

    String ejbqlString;

    ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE ";
    ejbqlString = ejbqlString + emp.getSalary();
    ejbqlString = ejbqlString + " = ABS(emp.salary)";
    setEjbqlString(ejbqlString);
    setOriginalOject(emp);
    super.setup();
  }
  public void setup() {
    setTestEmployees(getExtraEmployees());
    Employee emp = (Employee) getTestEmployees().firstElement();

    double salarySquareRoot = Math.sqrt((new Double(emp.getSalary()).doubleValue()));
    String ejbqlString;

    ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE ";
    ejbqlString = ejbqlString + "SQRT(emp.salary) = ";
    ejbqlString = ejbqlString + salarySquareRoot;
    setEjbqlString(ejbqlString);
    setOriginalOject(emp);
    super.setup();
  }
  public void test() {
    int size = getCacheIdentityMap().getMaxSize() * factor;

    for (int i = 0; i < size; i++) {
      BigDecimal id = new java.math.BigDecimal(i);
      Employee employee = new Employee();
      Vector pk = new Vector(1);
      employee.setId(id);
      employee.setFirstName("Joe");
      employee.setLastName("Blow");
      pk.add(id);
      getPrimaryKeys().add(pk);
      getCacheIdentityMap().put(primaryKeys, employee, null, 0);
    }
  }
  public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    UnitOfWork uow2 = getSession().acquireUnitOfWork();

    baseEmp = (Employee) uow.readObject(Employee.class);
    for (int count = 20; count > 0; --count) {
      baseEmp.addPhoneNumber(
          new PhoneNumber(String.valueOf(count), String.valueOf(count), "5555555"));
    }
    uow.commit();

    Runnable runnable1 =
        new Runnable() {
          public void run() {}
        };

    Runnable runnable2 =
        new Runnable() {
          public void run() {
            try {
              for (int count = 20; count > 0; --count) {
                UnitOfWork uow = getSession().acquireUnitOfWork();
                Employee emp = (Employee) uow.readObject(baseEmp);
                emp.getPhoneNumbers();
                uow.revertObject(emp);
              }
            } catch (ConcurrentModificationException ex) {
              exception = true;
            }
          }
        };
    Thread thread1 = new Thread(runnable2);
    thread1.start();
    try {
      for (int count = 20; count > 0; --count) {
        uow = getSession().acquireUnitOfWork();
        Employee emp = (Employee) uow.readObject(baseEmp);
        emp.getPhoneNumbers().remove(0);
        uow.commit();
      }
    } catch (ConcurrentModificationException ex) {
      exception = true;
    }
    try {
      thread1.join();
    } catch (InterruptedException ex) {
    }
  }
  public void setup() {
    Employee emp;
    emp = (Employee) getSomeEmployees().firstElement();
    PhoneNumber empPhoneNumbers = (PhoneNumber) emp.getPhoneNumbers().elementAt(0);

    String ejbqlString =
        "SelecT OBJECT(emp) from Employee emp, in (emp.phoneNumbers) phone "
            + "Where phone.areaCode = \""
            + empPhoneNumbers.getAreaCode()
            + "\"";

    setEjbqlString(ejbqlString);
    setOriginalOject(emp);

    super.setup();
  }
  public void test() {

    ReadObjectQuery query = new ReadObjectQuery();
    query.setReferenceClass(Employee.class);
    query.setExampleObject(employee);
    query.setQueryByExamplePolicy(policy);
    Employee emp = new Employee();
    emp = (Employee) getSession().executeQuery(query);
    if (!(emp.getFirstName().charAt(0) == 'J')
        && (emp.getFirstName().charAt(3) == 'l')
        && (emp.getLastName().charAt(0) == 'M')) {
      throw (new TestErrorException("Error in using specail operators."));
    }
    if (!(emp.getSalary() < 60000)) {
      throw (new TestErrorException("Error is using spcial operators."));
    }
  }
  public void setup() {
    if ((getSession().getLogin().getPlatform().isSQLServer())) {
      throw new TestWarningException(
          "This test is not supported on SQL Server. Because 'LENGTH' is not a recognized function name on SQL Server.");
    }

    Employee emp = (Employee) getSomeEmployees().firstElement();

    String ejbqlString;
    ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE ";
    ejbqlString = ejbqlString + emp.getFirstName().length();
    ejbqlString = ejbqlString + " = LENGTH(emp.firstName)";

    setEjbqlString(ejbqlString);
    setOriginalOject(emp);
    super.setup();
  }
  protected void setup() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();

    // This employee as a manager
    someManager = (Employee) getSession().readObject(referenceClass /*,
            bldr.get("firstName").equal("Sarah").and(bldr.get("lastName").equal("Way"))*/);
    // number of managed employees
    numberOfManagedEmployees = someManager.getManagedEmployees().size();
  }
 public void verify() {
   if (getObjectFromDistributedCache(manager) == null) {
     throw new TestErrorException(
         "New employee was not added to distributed cache with "
             + " SEND_NEW_OBJECTS_WITH_CHANGES descriptor CacheSynchronizationTypeSetting.");
   }
   Employee distributedEmployee = (Employee) getObjectFromDistributedCache(employee);
   Employee distributedManager = (Employee) getObjectFromDistributedCache(manager);
   if (!(distributedEmployee.getSalary() == employee.getSalary())) {
     throw new TestErrorException(
         "Changes for existing employee were not sent to the " + "distributed cache.");
   }
   if (!((AbstractSession) getSession())
       .compareObjects(distributedEmployee.getManager(), manager)) {
     throw new TestErrorException(
         "Relationship between employee and manager was not "
             + "properly maintained in distributed cache.");
   }
 }
 public void test() {
   UnitOfWork uow = getSession().acquireUnitOfWork();
   employee = (Employee) uow.readObject(Employee.class);
   originalReadTime =
       ((AbstractSession) getSession())
           .getIdentityMapAccessorInstance()
           .getCacheKeyForObject(employee)
           .getReadTime();
   employee.setFirstName(employee.getFirstName() + "-mutated");
   try {
     Thread.sleep(100);
   } catch (InterruptedException exc) {
   }
   uow.commit();
   secondReadTime =
       getAbstractSession()
           .getIdentityMapAccessorInstance()
           .getCacheKeyForObject(employee)
           .getReadTime();
 }
  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);
  }
 public void verify() {
   boolean error = true;
   for (Enumeration enumtr = ((Vector) result).elements(); enumtr.hasMoreElements(); ) {
     if (((Employee) enumtr.nextElement()).getId() == employee.getId()) {
       error = false;
     }
   }
   if (error) {
     throw new TestErrorException(
         "The object deleted from unit of work shows up in ReadAllQuery using conformResultsInUnitOfWork().");
   }
 }
  protected void setup() {
    // save current null values for later restoration
    saveDefaultDefaultNullValues = ConversionManager.getDefaultManager().getDefaultNullValues();
    saveDefaultNullValues =
        getSession().getLogin().getPlatform().getConversionManager().getDefaultNullValues();
    getSession()
        .getLogin()
        .getPlatform()
        .getConversionManager()
        .setDefaultNullValues(new Hashtable());
    getSession().getLogin().setDefaultNullValue(String.class, "null");
    getSession().getLogin().setDefaultNullValue(int.class, new Integer(-1));
    // Reinit mappings.
    for (DatabaseMapping mapping : getSession().getDescriptor(Address.class).getMappings()) {
      if (mapping.isDirectToFieldMapping()) {
        mapping.preInitialize(getAbstractSession());
      }
    }
    getAbstractSession().beginTransaction();

    employee = new Employee();
    employee.setFirstName("Fred");
    employee.setLastName("Flintstone");
    employee.setSalary(22);
    employee.setGender("Male");
    Address address = new Address();
    address.setCity(null);
    employee.setAddress(address);

    getAbstractSession().writeObject(employee);
    // force the salary to be NULL
    getSession()
        .executeNonSelectingCall(
            new SQLCall("update SALARY set SALARY = null where EMP_ID = " + employee.getId()));
  }
  public void setup() {
    Employee emp = (Employee) getSomeEmployees().firstElement();

    PhoneNumber phone = (PhoneNumber) emp.getPhoneNumbers().firstElement();
    String areaCode = phone.getAreaCode();
    String firstName = emp.getFirstName();

    setReferenceClass(Employee.class);

    ExpressionBuilder employeeBuilder = new ExpressionBuilder();
    Expression phones = employeeBuilder.anyOf("phoneNumbers");
    Expression whereClause =
        phones
            .get("owner")
            .get("firstName")
            .equal(firstName)
            .and(phones.get("areaCode").equal(areaCode));

    ReportQuery rq = new ReportQuery();
    rq.setSelectionCriteria(whereClause);
    rq.addAttribute("number", phones.get("number"));
    rq.setReferenceClass(Employee.class);

    setOriginalOject(getAttributeFromAll("number", (Vector) getSession().executeQuery(rq)));
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();

    String ejbqlString;
    ejbqlString =
        "SELECT phone.number FROM Employee employee, IN(employee.phoneNumbers) phone "
            + "WHERE phone.owner.firstName = \""
            + firstName
            + "\" AND phone.areaCode = \""
            + areaCode
            + "\"";

    useReportQuery();
    setEjbqlString(ejbqlString);
    super.setup();
  }