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();
  }
예제 #2
0
  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()));
  }
  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");
  }
  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();
   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 static TestSuite getComplexUpdateObjectTestSuite() {
    TestSuite suite = new TestSuite();
    suite.setName("EmployeeComplexUpdateTestSuite");
    suite.setDescription(
        "This suite tests the updating of each an employee by adding and/or removing managed employees and/or phones.");

    Class employeeClass = Employee.class;
    PopulationManager manager = PopulationManager.getDefaultManager();
    Employee originalEmployee = (Employee) manager.getObject(employeeClass, "0001");
    Employee otherEmployee = (Employee) manager.getObject(employeeClass, "0002");

    // add a managed Employee from other Employee managed List; remove the first managed Employee.
    suite.addTest(
        new EmployeeComplexUpdateTest(
            originalEmployee,
            otherEmployee.getManagedEmployees().get(0),
            originalEmployee.getManagedEmployees().get(0)));
    // remove the first Phone.
    suite.addTest(
        new EmployeeComplexUpdateTest(
            originalEmployee, (Object) null, originalEmployee.getPhoneNumbers().get(0)));
    // add a managed Employee from other Employee managed List and new phone;
    // remove the first two managed Employees and the first Phone.
    Employee newEmployee = new Employee();
    newEmployee.setFirstName("New");
    PhoneNumber newPhoneNumber = new PhoneNumber("home", "001", "0000001");
    suite.addTest(
        new EmployeeComplexUpdateTest(
            originalEmployee,
            new Object[] {otherEmployee.getManagedEmployees().get(0), newEmployee, newPhoneNumber},
            new Object[] {
              originalEmployee.getManagedEmployees().get(0),
              originalEmployee.getManagedEmployees().get(1),
              originalEmployee.getPhoneNumbers().get(0)
            }));
    suite.addTest(new CascadeLockingTest());
    suite.addTest(new TargetLockingTest_AddRemoveTarget());

    return suite;
  }
    public void test() {
      // setup
      Employee manager = new Employee();
      manager.setFirstName("Manager");
      Employee employee = new Employee();
      employee.setFirstName("Employee");

      UnitOfWork uow = getSession().acquireUnitOfWork();
      uow.registerObject(manager);
      uow.registerObject(employee);
      uow.commit();

      Vector pk = new Vector(1);
      pk.add(manager.getId());

      version[0] =
          ((Long)
                  getSession()
                      .getDescriptor(Employee.class)
                      .getOptimisticLockingPolicy()
                      .getWriteLockValue(manager, pk, getAbstractSession()))
              .longValue();

      // test1 - add managed employee, manager's version should increment.
      uow = getSession().acquireUnitOfWork();
      Employee managerClone = (Employee) uow.registerObject(manager);
      Employee employeeClone = (Employee) uow.registerObject(employee);
      managerClone.addManagedEmployee(employeeClone);
      uow.commit();
      version[1] =
          ((Long)
                  getSession()
                      .getDescriptor(Employee.class)
                      .getOptimisticLockingPolicy()
                      .getWriteLockValue(manager, pk, getAbstractSession()))
              .longValue();

      // test2 - alter managed employee, manager's version should NOT increment.
      uow = getSession().acquireUnitOfWork();
      employeeClone = (Employee) uow.registerObject(employee);
      employeeClone.setFirstName("Altered");
      uow.commit();
      version[2] =
          ((Long)
                  getSession()
                      .getDescriptor(Employee.class)
                      .getOptimisticLockingPolicy()
                      .getWriteLockValue(manager, pk, getAbstractSession()))
              .longValue();

      // test3- remove managed employee, manager's version should increment.
      uow = getSession().acquireUnitOfWork();
      managerClone = (Employee) uow.registerObject(manager);
      employeeClone = (Employee) uow.registerObject(employee);
      managerClone.removeManagedEmployee(employeeClone);
      uow.commit();
      version[3] =
          ((Long)
                  getSession()
                      .getDescriptor(Employee.class)
                      .getOptimisticLockingPolicy()
                      .getWriteLockValue(manager, pk, getAbstractSession()))
              .longValue();

      PhoneNumber phone = new PhoneNumber("home", "613", "1111111");

      // test4 - add phone, manager's version should increment.
      uow = getSession().acquireUnitOfWork();
      managerClone = (Employee) uow.registerObject(manager);
      PhoneNumber phoneClone = (PhoneNumber) uow.registerObject(phone);
      managerClone.addPhoneNumber(phoneClone);
      uow.commit();
      version[4] =
          ((Long)
                  getSession()
                      .getDescriptor(Employee.class)
                      .getOptimisticLockingPolicy()
                      .getWriteLockValue(manager, pk, getAbstractSession()))
              .longValue();

      // test5- alter phone, manager's version should increment.
      uow = getSession().acquireUnitOfWork();
      phoneClone = (PhoneNumber) uow.registerObject(phone);
      phoneClone.setType("work");
      uow.commit();
      version[5] =
          ((Long)
                  getSession()
                      .getDescriptor(Employee.class)
                      .getOptimisticLockingPolicy()
                      .getWriteLockValue(manager, pk, getAbstractSession()))
              .longValue();

      // test6- remove phone, manager's version should increment.
      uow = getSession().acquireUnitOfWork();
      managerClone = (Employee) uow.registerObject(manager);
      phoneClone = (PhoneNumber) uow.registerObject(phone);
      managerClone.removePhoneNumber(phoneClone);
      uow.commit();
      version[6] =
          ((Long)
                  getSession()
                      .getDescriptor(Employee.class)
                      .getOptimisticLockingPolicy()
                      .getWriteLockValue(manager, pk, getAbstractSession()))
              .longValue();
    }