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() { // 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(); }
/** * 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() { 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 reset() { UnitOfWork uow = getSession().acquireUnitOfWork(); uow.deleteObject(this.person); uow.commit(); getSession().getDescriptor(ConcurrentAddress.class).getEventManager().removeListener(listener); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); }
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 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(); 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(); }
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(); }
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(); }
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 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); }
protected void setup() { beginTransaction(); // Acquire a unit of work with a class read-only. Vector readOnlyClasses = new Vector(); readOnlyClasses.addElement(Country.class); uow = getSession().acquireUnitOfWork(); uow.removeAllReadOnlyClasses(); uow.addReadOnlyClasses(readOnlyClasses); }
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(); }
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(); }
/** 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 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(); }
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() { // 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(); }
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 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(); }
/** 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'")); }
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(); }
public void test() { transport = Transport.example6(); UnitOfWork uow = getSession().acquireUnitOfWork(); uow.registerObject(transport); uow.commit(); transportId = transport.getId(); DatabaseSession session = (DatabaseSession) getSession(); ExpressionBuilder exp = new ExpressionBuilder(); Expression expression = exp.get("id").equal(transportId); transport = (Transport) session.readObject(Transport.class, expression); }
/** 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(); }
/** 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() { 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"); } }