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();
  }
 protected Object buildOriginalObject() {
   Employee emp = new Employee();
   emp.setFirstName("Sally");
   emp.setLastName("Hamilton");
   emp.setFemale();
   return emp;
 }
Ejemplo n.º 3
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");
  }
  /** Create a new employee and commit. */
  public void test() {
    employee = (Employee) getSession().readObject(Employee.class, expression);

    UnitOfWork uow = getSession().acquireUnitOfWork();
    Employee employeeClone = (Employee) uow.registerObject(employee);
    employeeClone.setSalary(employeeClone.getSalary() + 1);
    manager = new Employee();
    manager.setFirstName("Fred");
    manager.setLastName("Fenster");
    Employee managerClone = (Employee) uow.registerObject(manager);
    employeeClone.setManager(managerClone);
    uow.commit();
  }
  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);
    }
  }
  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);
  }