コード例 #1
0
  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
 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();
 }