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 populate(DatabaseSession session) { Employee instance; PopulationManager manager = PopulationManager.getDefaultManager(); instance = Employee.example1(); session.writeObject(instance); manager.registerObject(instance, "example1"); manager.registerObject(instance.computer, "example1"); manager.registerObject(instance.shipments.firstElement(), "example1"); manager.registerObject( ((Shipment) instance.shipments.firstElement()).orders.firstElement(), "example1"); instance = Employee.example2(); session.writeObject(instance); manager.registerObject(instance, "example2"); manager.registerObject(instance.computer, "example2"); manager.registerObject(instance.shipments.firstElement(), "example2"); manager.registerObject( ((Shipment) instance.shipments.firstElement()).orders.firstElement(), "example2"); instance = Employee.example3(); session.writeObject(instance); manager.registerObject(instance, "example3"); manager.registerObject(instance.computer, "example3"); manager.registerObject(instance.shipments.firstElement(), "example3"); manager.registerObject( ((Shipment) instance.shipments.firstElement()).orders.firstElement(), "example3"); }
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() { 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(); }
private void createEmployeeAndSearchExpression() { // Create the example employee employee = (org.eclipse.persistence.testing.models.employee.domain.Employee) new org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator() .basicEmployeeExample1(); employee.setFirstName("Timugen"); employee.setLastName("Singaera"); employee.addResponsibility("Answer the phones."); // Create an expression to retreive the employee from the database ExpressionBuilder expressionBuilder = new ExpressionBuilder(); Expression exp1; Expression exp2; Expression expression; exp1 = expressionBuilder.get("firstName").equal(employee.getFirstName()); exp2 = expressionBuilder.get("lastName").equal(employee.getLastName()); searchExpression = exp1.or(exp2); }