/** Tests saving a new object with a reference to a read-only object. */
  public TransactionalTestCase buildRefReadOnlyTest() {
    TransactionalTestCase test =
        new TransactionalTestCase() {
          public void setup() {
            super.setup();
            if (getSession().isRemoteSession()) {
              throwWarning("Test not supported on remote session.");
            }
            getSession().getDescriptor(Address.class).setReadOnly();
          }

          public void test() {
            UnitOfWork uow = getSession().acquireUnitOfWork();
            Address address = (Address) uow.readObject(Address.class);
            Employee employee = new Employee();
            // Delete the phone but do not remove the employee reference.
            employee = (Employee) uow.registerObject(employee);
            employee.setAddress(address);
            uow.commit();
          }

          public void reset() {
            super.reset();
            getSession().getDescriptor(Address.class).setShouldBeReadOnly(false);
          }
        };
    test.setName("RefReadOnlyTest");
    test.setDescription("Tests saving a new object with a reference to a read-only object.");
    return test;
  }
 /** Test issue of loss of identity causing loop in cloning with invalidation. */
 public TransactionalTestCase buildRefreshDeletedObjectTest() {
   TransactionalTestCase test =
       new TransactionalTestCase() {
         public void test() {
           List employees = getSession().readAllObjects(Employee.class);
           Employee employee = null;
           // Find an employee with a phone.
           for (Iterator iterator = employees.iterator(); iterator.hasNext(); ) {
             employee = (Employee) iterator.next();
             if (employee.getPhoneNumbers().size() > 0) {
               break;
             }
           }
           UnitOfWork uow = getSession().acquireUnitOfWork();
           // Delete the phone but do not remove the employee reference.
           uow.deleteObject(employee.getPhoneNumbers().get(0));
           uow.commit();
           // Invalidate the phone numbers to cause them to be refreshed.
           getSession().getIdentityMapAccessor().invalidateClass(PhoneNumber.class);
           uow = getSession().acquireUnitOfWork();
           employee = (Employee) uow.readObject(employee);
           // Trigger register of dead phone number, this cause a loop and error.
           employee.getPhoneNumbers().get(0);
           uow.commit();
         }
       };
   test.setName("RefreshDeletedObjectTest");
   test.setDescription(
       "Test issue of loss of identity causing loop in cloning with invalidation.");
   return test;
 }
Ejemplo n.º 3
0
 public void reset() {
   // Force the query to be rebuilt each time...
   setQuery(null);
   super.reset();
 }
 public void setup() {
   super.setup();
   for (int i = 0; i < version.length; i++) {
     version[i] = 0;
   }
 }