public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); UnitOfWork nestedUow1 = uow.acquireUnitOfWork(); UnitOfWork nestedNestedUOW = nestedUow1.acquireUnitOfWork(); Employee employee = (Employee) new EmployeePopulator().basicEmployeeExample1(); employee.setId(new BigDecimal(15)); Employee nestedEmployee = (Employee) nestedNestedUOW.registerObject(employee); nestedNestedUOW.commit(); nestedUow1.commit(); nestedUow1 = uow.acquireUnitOfWork(); nestedNestedUOW = nestedUow1.acquireUnitOfWork(); ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(Employee.class); query.setSelectionCriteria( new org.eclipse.persistence.expressions.ExpressionBuilder() .get("id") .equal(new BigDecimal(15))); query.conformResultsInUnitOfWork(); nestedEmployee = (Employee) nestedNestedUOW.executeQuery(query); nestedNestedUOW.deleteObject(nestedEmployee); nestedNestedUOW.commit(); nestedUow1.commit(); if (!((UnitOfWorkImpl) uow).getNewObjectsCloneToOriginal().isEmpty()) { throw new TestErrorException("Failed to unregister the Object in the nested unit of work"); } }
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) { } }
protected void clear() { UnitOfWork uow = acquireUnitOfWork(); // use alternate way for Symfoware as it doesn't support UpdateAll/DeleteAll on multi-table // objects (see rfe 298193) if (!(JUnitTestCase.getServerSession("fieldaccess")).getPlatform().isSymfoware()) { UpdateAllQuery updateEmployees = new UpdateAllQuery(Employee.class); updateEmployees.addUpdate("manager", null); updateEmployees.addUpdate("address", null); uow.executeQuery(updateEmployees); uow.executeQuery(new DeleteAllQuery(Employee.class)); } else { Iterator<Employee> emps = uow.readAllObjects(Employee.class).iterator(); while (emps.hasNext()) { Employee emp = emps.next(); emp.setManager(null); emp.setAddress(null); uow.deleteObject(emp); } ; } UpdateAllQuery updateProjects = new UpdateAllQuery(Project.class); updateProjects.addUpdate("teamLeader", null); uow.executeQuery(updateProjects); uow.executeQuery(new DeleteAllQuery(PhoneNumber.class)); uow.executeQuery(new DeleteAllQuery(Address.class)); uow.executeQuery(new DeleteAllQuery(Project.class)); uow.commit(); dbSessionClearCache(); }
public void reset() { UnitOfWork uow = getSession().acquireUnitOfWork(); uow.deleteObject(this.person); uow.commit(); getSession().getDescriptor(ConcurrentAddress.class).getEventManager().removeListener(listener); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); }
/** * This method will instantiate all of the example instances and insert them into the database * using the given session. */ public void populate(DatabaseSession session) { UnitOfWork unitOfWork = session.acquireUnitOfWork(); unitOfWork.registerObject(Dist_Employee.example1()); unitOfWork.registerObject(Company.example1()); unitOfWork.commit(); }
public void setup() { // create 3 Employees. employee = new Employee[3]; employee[0] = new Employee(); employee[0].setFirstName("Manager"); // 1 and 2 have manager 0. employee[1] = new Employee(); employee[1].setFirstName("Employee_1"); employee[0].addManagedEmployee(employee[1]); employee[2] = new Employee(); employee[2].setFirstName("Employee_2"); employee[0].addManagedEmployee(employee[2]); // insert all the Employees into the db. UnitOfWork uow = getSession().acquireUnitOfWork(); for (int i = 0; i < employee.length; i++) { uow.registerObject(employee[i]); } uow.commit(); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); }
public void setup() { mapping = (ManyToManyMapping) getSession() .getProject() .getDescriptor(AggregateEntityMapHolder.class) .getMappingForAttributeName("aggregateToEntityMap"); oldFetchJoinValue = mapping.getJoinFetch(); mapping.setJoinFetch(fetchJoinRelationship); getSession() .getProject() .getDescriptor(AggregateEntityMapHolder.class) .reInitializeJoinedAttributes(); UnitOfWork uow = getSession().acquireUnitOfWork(); AggregateEntityMapHolder holder = new AggregateEntityMapHolder(); EntityMapValue value = new EntityMapValue(); value.setId(1); AggregateMapKey key = new AggregateMapKey(); key.setKey(11); holder.addAggregateToEntityMapItem(key, value); EntityMapValue value2 = new EntityMapValue(); value2.setId(2); key = new AggregateMapKey(); key.setKey(22); holder.addAggregateToEntityMapItem(key, value2); uow.registerObject(holder); uow.registerObject(value); uow.registerObject(value2); uow.commit(); holderExp = (new ExpressionBuilder()).get("id").equal(holder.getId()); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); }
public void setup() { // create 5 Employees. employee = new Employee[5]; employee[0] = new Employee(); employee[0].setFirstName("Manager"); // 1 and 2 have manager 0. employee[1] = new Employee(); employee[1].setFirstName("Employee_1"); employee[0].addManagedEmployee(employee[1]); employee[2] = new Employee(); employee[2].setFirstName("Employee_2"); employee[0].addManagedEmployee(employee[2]); // 3 and 4 don't have a manager. employee[3] = new Employee(); employee[3].setFirstName("Employee_3"); employee[4] = new Employee(); employee[4].setFirstName("Employee_4"); // insert all the Employees into the db. UnitOfWork uow = getSession().acquireUnitOfWork(); for (int i = 0; i < employee.length; i++) { uow.registerObject(employee[i]); } uow.commit(); }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); this.emp = Employee.example1(); this.emp.asset1.asset = Vehicle.example1(); uow.registerObject(this.emp); uow.commit(); uow = getSession().acquireUnitOfWork(); Employee empClone = (Employee) uow.registerObject(this.emp); Employee newClone = (Employee) empClone.clone(); ((Vehicle) newClone.asset1.asset).make = "Beamer"; uow.deepMergeClone(newClone); uow.commit(); if (!((AbstractSession) getSession()).compareObjects(newClone, this.emp)) { throw new TestErrorException("Failed to merge the Variable 1 to 1 properly"); } }
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(); }
public void reset() { UnitOfWork uow = getSession().acquireUnitOfWork(); uow.deleteAllObjects(holders); uow.commit(); if (!verifyDelete(holders.get(0))) { throw new TestErrorException("Delete was unsuccessful."); } mapping.setJoinFetch(oldFetchJoinValue); }
public void test() { this.employee = (IsolatedEmployee) getSession().readObject(IsolatedEmployee.class, this.expression); UnitOfWork uow = getSession().acquireUnitOfWork(); IsolatedEmployee employeeClone = (IsolatedEmployee) uow.registerObject(this.employee); employeeClone.setSalary(employeeClone.getSalary() + 1000); uow.commit(); }
public void reset() { UnitOfWork uow = getSession().acquireUnitOfWork(); for (int i = 0; i < employee.length; i++) { if (employee[i] != null) { uow.deleteObject(employee[i]); } } uow.commit(); }
public void reset() { // Remove the transport added for this test DatabaseSession session = (DatabaseSession) getSession(); UnitOfWork uow = session.acquireUnitOfWork(); ExpressionBuilder transport = new ExpressionBuilder(); Expression expression = transport.get("id").equal(transportId); uow.deleteAllObjects(uow.readAllObjects(Transport.class, expression)); uow.commit(); }
public void test() { UnitOfWork uow = ((SessionBroker) getSession()).acquireUnitOfWork(); for (int i = 0; i < NUM_INSERTS; i++) { uow.registerObject(new Employee()); } uow.commit(); }
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(); }
/** This method was created in VisualAge. */ public void test() { // READ A GRASSHOPPER GrassHopper grassHopper = (GrassHopper) getSession().readObject(GrassHopper.class); // MODIFY THE GRASSHOPPER UnitOfWork uow = getSession().acquireUnitOfWork(); GrassHopper tempGrassHopper = (GrassHopper) uow.registerObject(grassHopper); tempGrassHopper.setGh_maximumJump(new Integer(150)); 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 persistExample(Session session) { Vector allObjects = new Vector(); UnitOfWork unitOfWork = session.acquireUnitOfWork(); PopulationManager.getDefaultManager().addAllObjectsForClass(Person.class, allObjects); PopulationManager.getDefaultManager().addAllObjectsForClass(AAA.class, allObjects); PopulationManager.getDefaultManager().addAllObjectsForClass(Company.class, allObjects); PopulationManager.getDefaultManager().addAllObjectsForClass(Computer.class, allObjects); unitOfWork.registerAllObjects(allObjects); unitOfWork.commit(); }
public void reset() { UnitOfWork uow = getSession().acquireUnitOfWork(); Iterator j = holder.getDirectToEntityMap().keySet().iterator(); while (j.hasNext()) { uow.deleteObject(holder.getDirectToEntityMap().get(j.next())); } uow.deleteObject(holder); uow.commit(); mapping.setIsPrivateOwned(oldPrivateOwnedValue); }
public void reset() { // Compatibility for Oracle 9 and above is checked in the setup() method Oracle9Platform platform = (Oracle9Platform) getSession().getPlatform(); // platform.setPrintCalendarIntoTimestampTZ(this.oldPrintingValue); platform.setShouldBindAllParameters(this.oldBindingValue); // delete myself UnitOfWork uow = getSession().acquireUnitOfWork(); uow.deleteObject(this); 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 reset() { ConcurrentProject.RUNNING_TEST = ConcurrentProject.NONE; UnitOfWork uow = getSession().acquireUnitOfWork(); uow.deleteObject(person); uow.deleteObject(project); uow.deleteObject(project.getLocation()); uow.commit(); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); this.getExecutor().resetSession(); }
/** This method was created in VisualAge. */ public void test() { // Insert a car org.eclipse.persistence.sessions.UnitOfWork uow = getSession().acquireUnitOfWork(); uow.registerObject(this.theCar); uow.commit(); // Get the car's ID Car carRead = (Car) getSession().readObject(this.theCar); this.carID = carRead.id; // Initialize idmaps getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); }
public void test() { UnitOfWork uow = getSession().acquireUnitOfWork(); Employee managerClone = (Employee) uow.registerObject(employee[0]); // remove all managed Employees (1 and 2) managerClone.getManagedEmployees().clear(); // add to managed list new Employees (3 and 4) Employee employee3Clone = (Employee) uow.registerObject(employee[3]); Employee employee4Clone = (Employee) uow.registerObject(employee[4]); managerClone.addManagedEmployee(employee3Clone); managerClone.addManagedEmployee(employee4Clone); // after commit the versions of all Employees should be changed. uow.commit(); }
/** This method was created in VisualAge. */ protected void setup() { getAbstractSession().beginTransaction(); // CREATE A GRASSHOPPER GrassHopper grassHopper = new GrassHopper(); grassHopper.setIn_numberOfLegs(new Integer(6)); grassHopper.setGh_maximumJump(new Integer(100)); // ADD THE GRASSHOPPER TO THE DATABASE UnitOfWork uow = getSession().acquireUnitOfWork(); uow.registerObject(grassHopper); uow.commit(); }
/** Insert address and then reset database/cache. */ public void test() throws Exception { UnitOfWork uow = getSession().acquireUnitOfWork(); Address address = new Address(); address.setCity("NewCity"); address.setPostalCode("N5J2N5"); address.setProvince("ON"); address.setStreet("1111 Mountain Blvd. Floor 13, suite 1"); address.setCountry("Canada"); uow.registerObject(address); uow.commit(); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); getSession().executeNonSelectingCall(new SQLCall("Delete from ADDRESS where CITY = 'NewCity'")); }
/** 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(); }