コード例 #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
  protected void test() {
    // Read in a Country.
    aCountry = (Country) uow.readObject(Country.class);
    oldName = aCountry.getName();

    // Update the country and commit. Nothing should be written to the db.
    uow.registerObject(aCountry);
    aCountry.setName(aCountry.getName() + " 22");
    uow.commit();
  }
コード例 #3
0
  public void test() {
    transport = Transport.example6();
    UnitOfWork uow = getSession().acquireUnitOfWork();
    uow.registerObject(transport);
    uow.commit();

    transportId = transport.getId();

    DatabaseSession session = (DatabaseSession) getSession();
    ExpressionBuilder exp = new ExpressionBuilder();
    Expression expression = exp.get("id").equal(transportId);
    transport = (Transport) session.readObject(Transport.class, expression);
  }