public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); changedHolder = (DirectEntityMapHolder) uow.readObject(holder); EntityMapValue value = new EntityMapValue(); value.setId(3); changedHolder.addDirectToEntityMapItem(new Integer(33), value); changedHolder.getDirectToEntityMap().remove(new Integer(11)); uow.commit(); Object holderForComparison = uow.readObject(holder); if (!compareObjects(changedHolder, holderForComparison)) { throw new TestErrorException("Objects do not match after write"); } }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); UnitOfWork uow2 = getSession().acquireUnitOfWork(); baseEmp = (Employee) uow.readObject(Employee.class); for (int count = 20; count > 0; --count) { baseEmp.addPhoneNumber( new PhoneNumber(String.valueOf(count), String.valueOf(count), "5555555")); } uow.commit(); Runnable runnable1 = new Runnable() { public void run() {} }; Runnable runnable2 = new Runnable() { public void run() { try { for (int count = 20; count > 0; --count) { UnitOfWork uow = getSession().acquireUnitOfWork(); Employee emp = (Employee) uow.readObject(baseEmp); emp.getPhoneNumbers(); uow.revertObject(emp); } } catch (ConcurrentModificationException ex) { exception = true; } } }; Thread thread1 = new Thread(runnable2); thread1.start(); try { for (int count = 20; count > 0; --count) { uow = getSession().acquireUnitOfWork(); Employee emp = (Employee) uow.readObject(baseEmp); emp.getPhoneNumbers().remove(0); uow.commit(); } } catch (ConcurrentModificationException ex) { exception = true; } try { thread1.join(); } catch (InterruptedException ex) { } }
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(); }
public void setup() { mapping = (ManyToManyMapping) getSession() .getProject() .getDescriptor(DirectEntityMapHolder.class) .getMappingForAttributeName("directToEntityMap"); oldPrivateOwnedValue = mapping.isPrivateOwned(); mapping.setIsPrivateOwned(usePrivateOwned); UnitOfWork uow = getSession().acquireUnitOfWork(); holder = new DirectEntityMapHolder(); EntityMapValue value = new EntityMapValue(); value.setId(1); holder.addDirectToEntityMapItem(new Integer(11), value); EntityMapValue value2 = new EntityMapValue(); value2.setId(2); holder.addDirectToEntityMapItem(new Integer(22), value2); uow.registerObject(holder); uow.registerObject(value); uow.registerObject(value2); uow.commit(); Object holderForComparison = uow.readObject(holder); if (!compareObjects(holder, holderForComparison)) { throw new TestErrorException("Objects do not match after write"); } getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); this.sales = SalesPerson.example1(); this.sales = (SalesPerson) uow.registerObject(this.sales); this.fieldOfficeClone = (FieldOffice) uow.readObject(FieldOffice.class); this.sales.setFieldOffice(this.fieldOfficeClone); uow.commit(); }
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(); }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); this.fieldOfficeClone = (FieldOffice) uow.readObject(FieldOffice.class); for (Iterator objects = this.fieldOfficeClone.getSalespeople().iterator(); objects.hasNext(); ) { this.sales = (SalesPerson) objects.next(); break; } this.fieldOfficeClone.getSalespeople().remove(this.sales); }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); holders = uow.readAllObjects(DirectAggregateMapHolder.class, holderExp); changedHolder = (DirectAggregateMapHolder) holders.get(0); changedHolder.removeDirectToAggregateMapItem(new Integer(1)); AggregateMapValue mapValue = new AggregateMapValue(); mapValue.setValue(3); changedHolder.addDirectToAggregateMapItem(new Integer(3), mapValue); uow.commit(); Object holderForComparison = uow.readObject(changedHolder); if (!compareObjects(changedHolder, holderForComparison)) { throw new TestErrorException("Objects do not match after write"); } }
public void setup() { m_exceptionCaught = false; m_clientSession = (ClientSession) getSession(); m_clientSession.getIdentityMapAccessor().initializeAllIdentityMaps(); m_clientSession.beginTransaction(); m_uow = m_clientSession.acquireUnitOfWork(); m_employee = (Employee) m_uow.readObject(Employee.class); m_employee.setFirstName("Booyah!"); m_uow.commit(); // Fake out the connection accessor = m_clientSession.getWriteConnection(); m_clientSession.setWriteConnection(null); }
public void test() { UnitOfWork uow = this.serverSession.acquireUnitOfWork(); QueryExecuteListener listener = new QueryExecuteListener(this); getSession().getEventManager().addListener(listener); try { uow.readObject(Employee.class); } catch (Exception ex) { throw new TestErrorException("outside of the transaction TopLink failed to retry the read."); } if (((ClientSession) uow.getParent()) .getParent() .getReadConnectionPool() .getConnectionsAvailable() .contains(this.non_txn_read)) { throw new TestErrorException("Failed to remove accessor from pool on exception"); } }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); Employee_XML emp = (Employee_XML) uow.readObject( Employee_XML.class, new ExpressionBuilder().get("firstName").equal("Frank")); Document resume = emp.resume; // System.out.println(resume); NodeList nodes = resume.getElementsByTagName("last-name"); // System.out.println(nodes); Node lastName = nodes.item(0); Node lastNameText = lastName.getFirstChild(); lastNameText.setNodeValue("Williams"); emp.payroll_xml = "<payroll><salary>50000</salary><pay-period>weekly</pay-period></payroll>"; uow.commit(); }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); employee = (Employee) uow.readObject(Employee.class); originalReadTime = ((AbstractSession) getSession()) .getIdentityMapAccessorInstance() .getCacheKeyForObject(employee) .getReadTime(); employee.setFirstName(employee.getFirstName() + "-mutated"); try { Thread.sleep(100); } catch (InterruptedException exc) { } uow.commit(); secondReadTime = getAbstractSession() .getIdentityMapAccessorInstance() .getCacheKeyForObject(employee) .getReadTime(); }
/** Simulate detching and object and attempting to merge it. */ public void test() { getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); UnitOfWork uow = getSession().acquireUnitOfWork(); PhoneNumber detachedPhone = (PhoneNumber) uow.readObject(PhoneNumber.class); ((DatabaseValueHolder) detachedPhone.owner).setSession(null); uow.release(); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); uow = getSession().acquireUnitOfWork(); DescriptorException caughtException = null; try { uow.deepMergeClone(detachedPhone); } catch (DescriptorException exception) { caughtException = exception; } if ((caughtException == null) || (caughtException.getErrorCode() != DescriptorException.ATTEMPT_TO_REGISTER_DEAD_INDIRECTION)) { throwError("Incorrect exception thrown. " + caughtException); } uow.release(); }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); cat = new Cat(); cat.setName("Bud"); appt = new VetAppointment(); appt.setCost(100); List appts = new ArrayList(); appts.add(appt); appt.getAnimal().setValue(cat); uow.registerObject(cat); uow.registerObject(appt); uow.commit(); cat = (Cat) getSession().refreshObject(cat); appt = (VetAppointment) getSession().refreshObject(appt); catVersion = cat.getVersion(); apptVersion = appt.getVersion(); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); uow = getSession().acquireUnitOfWork(); cat = (Cat) uow.readObject(cat); appt = (VetAppointment) cat.getAppointments().get(0); appt.setCost(99); uow.commit(); }