Пример #1
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();
    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 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");
  }