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(); }
/** * Return the first employee that has a long enough name for the test. If no match is found throw * a warning exception. See bug 223005 * * @param vectorOfEmployees * @param minFirstNameLength * @param testName * @return */ public Employee getEmployeeWithRequiredNameLength( Vector vectorOfEmployees, int minFirstNameLength, String testName) { Employee empMatch = null; Vector<Employee> employees = vectorOfEmployees; String firstName; StringBuffer partialFirstName; // Loop through the collection of employees to find one that matches our test requirements for (int i = 0; i < employees.size(); i++) { empMatch = employees.get(i); firstName = empMatch.getFirstName(); // Verify length criteria if (firstName.length() >= minFirstNameLength) { // exit the for loop - return the last empMatch i = employees.size(); } } // If we could not find a proper employee for testing - throw a warning if (null == empMatch) { throw new RuntimeException( testName + " Setup Failed: unable to find an Employee with firstName size of at least " + minFirstNameLength); } else { return empMatch; } }
public void setup() { Vector employees = getSomeEmployees(); // Bug 223005: Verify that we have at least 1 employee with the required field length otherwise // an EclipseLinkException will be thrown Employee emp = getEmployeeWithRequiredNameLength(employees, MIN_FIRSTNAME_LENGTH, getName()); String partialFirstName = "%" + emp.getFirstName().substring(0, 3) + "%"; ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(Employee.class); Vector parameters = new Vector(); parameters.add(partialFirstName); ExpressionBuilder eb = new ExpressionBuilder(); Expression whereClause = eb.get("firstName").like(partialFirstName); raq.setSelectionCriteria(whereClause); employees = (Vector) getSession().executeQuery(raq); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.firstName LIKE ?1"; setEjbqlString(ejbqlString); setOriginalOject(employees); setArguments(parameters); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); setArgumentNames(myArgumentNames); super.setup(); }
protected void buildExpectedResults() { ReadAllQuery query = new ReadAllQuery(); query.setReferenceClass(Employee.class); Vector employees = (Vector) getSession().executeQuery(query); Vector distinctEmployees = new Vector(); // initialize distinctEmployees distinctEmployees.addElement(employees.elementAt(0)); // check employees with duplicate province and add only distinct employees to distinctEmployees for (int i = 1; i < employees.size(); i++) { boolean duplicateFound = false; // iterate through distinctEmployees to check for duplicate provinces, if found, employee not // added for (int j = 0; j < distinctEmployees.size(); j++) { if ((((Employee) employees.elementAt(i)).getAddress().getProvince()) .equals((((Employee) distinctEmployees.elementAt(j)).getAddress().getProvince()))) { duplicateFound = true; } } if (!duplicateFound) { distinctEmployees.addElement(employees.elementAt(i)); } } for (Enumeration e = distinctEmployees.elements(); e.hasMoreElements(); ) { Employee emp = (Employee) e.nextElement(); Object[] result = new Object[1]; result[0] = emp.getAddress().getProvince(); addResult(result, null); } }
public void setup() { Employee emp = (Employee) getSomeEmployees().firstElement(); String partOne; String partTwo; String ejbqlString; partOne = emp.getFirstName(); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.get("firstName").concat("Smith").like(partOne + "Smith"); ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(Employee.class); raq.setSelectionCriteria(whereClause); Vector employees = (Vector) getSession().executeQuery(raq); ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE "; ejbqlString = ejbqlString + "CONCAT(emp.firstName,\"Smith\") LIKE "; ejbqlString = ejbqlString + "\"" + partOne + "Smith\""; setEjbqlString(ejbqlString); setOriginalOject(employees); super.setup(); }
public void setup() { super.setup(); // Fully load the cache and fire indirection. allObjects = getSession().readAllObjects(Employee.class); for (Iterator iterator = allObjects.iterator(); iterator.hasNext(); ) { Employee employee = (Employee) iterator.next(); employee.getAddress(); employee.getPhoneNumbers().size(); } }
public void setup() { Employee emp1; Employee emp2; Employee emp3; emp1 = (Employee) getSomeEmployees().firstElement(); emp2 = (Employee) getSomeEmployees().elementAt(1); emp3 = (Employee) getSomeEmployees().elementAt(2); ExpressionBuilder builder = new ExpressionBuilder(); Vector idVector = new Vector(); idVector.add(emp1.getId()); idVector.add(emp2.getId()); idVector.add(emp3.getId()); Expression whereClause = builder.get("id").notIn(idVector); ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(Employee.class); raq.setSelectionCriteria(whereClause); setOriginalOject(getSession().executeQuery(raq)); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.id NOT IN ("; ejbqlString = ejbqlString + emp1.getId().toString() + ", "; ejbqlString = ejbqlString + emp2.getId().toString() + ", "; ejbqlString = ejbqlString + emp3.getId().toString(); ejbqlString = ejbqlString + ")"; setEjbqlString(ejbqlString); super.setup(); }
private void setArgumentsForTestUsing(Vector employees) { setArguments(new Vector()); Enumeration names = getExpressionParameters().elements(); Enumeration employeeEnum = employees.elements(); while (names.hasMoreElements()) { Employee emp = (Employee) employeeEnum.nextElement(); getArguments().add(emp.getId()); names.nextElement(); } }
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); }
public void setup() { Employee emp = (Employee) getSomeEmployees().firstElement(); PhoneNumber phone = (PhoneNumber) emp.getPhoneNumbers().firstElement(); String areaCode = phone.getAreaCode(); String firstName = emp.getFirstName(); setReferenceClass(Employee.class); ExpressionBuilder employeeBuilder = new ExpressionBuilder(); Expression phones = employeeBuilder.anyOf("phoneNumbers"); Expression whereClause = phones .get("owner") .get("firstName") .equal(firstName) .and(phones.get("areaCode").equal(areaCode)); ReportQuery rq = new ReportQuery(); rq.setSelectionCriteria(whereClause); rq.addAttribute("number", phones.get("number")); rq.setReferenceClass(Employee.class); setOriginalOject(getAttributeFromAll("number", (Vector) getSession().executeQuery(rq))); getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); String ejbqlString; ejbqlString = "SELECT phone.number FROM Employee employee, IN(employee.phoneNumbers) phone " + "WHERE phone.owner.firstName = \"" + firstName + "\" AND phone.areaCode = \"" + areaCode + "\""; useReportQuery(); setEjbqlString(ejbqlString); super.setup(); }
public void setup() { // Get the baseline employees for the verify Employee emp = (Employee) getSomeEmployees().firstElement(); String parameterName = "firstName"; ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.get("firstName").equal(builder.getParameter(parameterName)); ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(Employee.class); raq.setSelectionCriteria(whereClause); raq.addArgument(parameterName); Vector parameters = new Vector(); parameters.add(emp.getFirstName()); Vector employees = (Vector) getSession().executeQuery(raq, parameters); emp = (Employee) employees.firstElement(); // Set up the EJBQL using the retrieved employees String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE "; ejbqlString = ejbqlString + "?1 = emp.firstName "; setEjbqlString(ejbqlString); setOriginalOject(employees); setArguments(parameters); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); setArgumentNames(myArgumentNames); // Finish the setup super.setup(); }