コード例 #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()));
  }
  private void setArgumentsForTestUsing(Vector employees) {
    setArguments(new Vector());

    Enumeration names = getExpressionParameters().elements();
    Enumeration employeeEnum = employees.elements();
    while (names.hasMoreElements()) {
      Employee emp = (Employee) employeeEnum.nextElement();
      getArguments().add(emp.getId());
      names.nextElement();
    }
  }
コード例 #3
0
 public void verify() {
   boolean error = true;
   for (Enumeration enumtr = ((Vector) result).elements(); enumtr.hasMoreElements(); ) {
     if (((Employee) enumtr.nextElement()).getId() == employee.getId()) {
       error = false;
     }
   }
   if (error) {
     throw new TestErrorException(
         "The object deleted from unit of work shows up in ReadAllQuery using conformResultsInUnitOfWork().");
   }
 }
コード例 #4
0
  public void setup() {
    Employee emp1;
    Employee emp2;
    Employee emp3;
    emp1 = (Employee) getSomeEmployees().firstElement();
    emp2 = (Employee) getSomeEmployees().elementAt(1);
    emp3 = (Employee) getSomeEmployees().elementAt(2);

    ExpressionBuilder builder = new ExpressionBuilder();

    Vector idVector = new Vector();
    idVector.add(emp1.getId());
    idVector.add(emp2.getId());
    idVector.add(emp3.getId());

    Expression whereClause = builder.get("id").notIn(idVector);

    ReadAllQuery raq = new ReadAllQuery();
    raq.setReferenceClass(Employee.class);
    raq.setSelectionCriteria(whereClause);

    setOriginalOject(getSession().executeQuery(raq));
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();

    String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.id NOT IN (";
    ejbqlString = ejbqlString + emp1.getId().toString() + ", ";
    ejbqlString = ejbqlString + emp2.getId().toString() + ", ";
    ejbqlString = ejbqlString + emp3.getId().toString();
    ejbqlString = ejbqlString + ")";

    setEjbqlString(ejbqlString);

    super.setup();
  }
コード例 #5
0
 /**
  * Verify that the query ran successfully, and that the number of objects returned matches the
  * number of managed employees.
  */
 protected void verify() throws Exception {
   Vector params = new Vector();
   params.add(someManager.getId()); // numberOfManagedEmployees
   try {
     Vector results = (Vector) getSession().executeQuery(query, params);
     if (!(numberOfManagedEmployees == results.size())) {
       throw new TestErrorException(
           results.size()
               + " objects were read from the database, but originially there were, "
               + numberOfManagedEmployees
               + ".");
     }
   } catch (org.eclipse.persistence.exceptions.DatabaseException e) {
     throw new TestErrorException(
         "Custom SQL subquery with parameters failed with a DatabaseException.");
   }
 }