/** INTERNAL: Select all objects for a concrete descriptor. */ protected Object selectAllObjects(ReadAllQuery query) { ReadAllQuery concreteQuery = (ReadAllQuery) query.deepClone(); concreteQuery.setReferenceClass(descriptor.getJavaClass()); concreteQuery.setDescriptor(descriptor); // Avoid cloning the query again ... concreteQuery.setIsExecutionClone(true); concreteQuery .getExpressionBuilder() .setQueryClassAndDescriptor(descriptor.getJavaClass(), descriptor); // Update the selection criteria if needed as well and don't lose // the translation row. if (concreteQuery.getQueryMechanism().getSelectionCriteria() != null) { // make sure query builder is used for the selection criteria as deepClone will create // two separate builders. concreteQuery.setSelectionCriteria( concreteQuery .getQueryMechanism() .getSelectionCriteria() .rebuildOn(concreteQuery.getExpressionBuilder())); return query.getSession().executeQuery(concreteQuery, query.getTranslationRow()); } return query.getSession().executeQuery(concreteQuery); }
public void testProjectOuterJoinTeamLeaderAddressTeamMembersAddressPhonesWhereProjectName() { ReadAllQuery query = new ReadAllQuery(); query.setReferenceClass(Project.class); query.setSelectionCriteria( query .getExpressionBuilder() .get("name") .equal("Problem Reporting System") .or(query.getExpressionBuilder().get("name").equal("Bleep Blob"))); ReadAllQuery controlQuery = (ReadAllQuery) query.clone(); Expression teamLeader = query.getExpressionBuilder().getAllowingNull("teamLeader"); query.addJoinedAttribute(teamLeader); Expression teamLeaderAddress = teamLeader.getAllowingNull("address"); query.addJoinedAttribute(teamLeaderAddress); Expression teamMembers = query.getExpressionBuilder().anyOfAllowingNone("teamMembers"); query.addJoinedAttribute(teamMembers); Expression teamMembersAddress = teamMembers.getAllowingNull("address"); query.addJoinedAttribute(teamMembersAddress); Expression teamMembersPhones = teamMembers.anyOfAllowingNone("phoneNumbers"); query.addJoinedAttribute(teamMembersPhones); String errorMsg = executeQueriesAndCompareResults(controlQuery, query); if (errorMsg.length() > 0) { fail(errorMsg); } }
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(); }
public void findEmployeeWithWorkPhone2258812() { EntityManager em = createEntityManager(); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause1 = builder.anyOf("phoneNumbers").get("type").equal("Work"); Expression whereClause2 = builder.anyOf("phoneNumbers").get("number").equal("2258812"); ReadAllQuery raq = new ReadAllQuery(Employee.class); raq.setSelectionCriteria(whereClause1.and(whereClause2)); if (usesSOP() && getServerSession().getPlatform().isOracle()) { // distinct is incompatible with blob in selection clause on Oracle } else { raq.useDistinct(); } List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString; if (usesSOP() && getServerSession().getPlatform().isOracle()) { // distinct is incompatible with blob in selection clause on Oracle ejbqlString = "SELECT e FROM Employee e JOIN e.phoneNumbers p " + "WHERE p.type = 'Work' AND p.number = '2258812' "; } else { ejbqlString = "SELECT DISTINCT e FROM Employee e JOIN e.phoneNumbers p " + "WHERE p.type = 'Work' AND p.number = '2258812' "; } List result = em.createQuery(ejbqlString).getResultList(); // 8 employees Assert.assertEquals( "Find employee with 2258812 number test failed: data validation error", result.size(), 8); Assert.assertTrue( "Find employee with 2258812 number test failed", comparer.compareObjects(expectedResult, result)); }
public void findAllEmployeesWithPhoneNumbers() { EntityManager em = createEntityManager(); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.isEmpty("phoneNumbers").not(); ReadAllQuery raq = new ReadAllQuery(Employee.class); raq.setSelectionCriteria(whereClause); raq.useDistinct(); List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString = "SELECT DISTINCT e FROM Employee e, IN (e.phoneNumbers) l"; Query query = em.createQuery(ejbqlString); if (usesSOP() && getServerSession().getPlatform().isOracle()) { // distinct is incompatible with blob in selection clause on Oracle query.setHint(QueryHints.SERIALIZED_OBJECT, "false"); } List firstResult = query.getResultList(); String alternateEjbqlString = "SELECT e FROM Employee e WHERE e.phoneNumbers IS NOT EMPTY"; List secondResult = em.createQuery(alternateEjbqlString).getResultList(); // 14 employees returned Assert.assertEquals( "Ejbql statements returned different results: data validation error", firstResult.size(), 14); Assert.assertTrue( "Equivalent Ejbql statements returned different results", comparer.compareObjects(secondResult, firstResult)); Assert.assertTrue( "Find all employees with phone numbers test failed", comparer.compareObjects(expectedResult, firstResult)); }
public void getOrderForCustomer() { EntityManager em = createEntityManager(); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.get("name").equal("Jane Smith"); ReadAllQuery raq = new ReadAllQuery(Customer.class); raq.setSelectionCriteria(whereClause); Customer expectedCustomer = (Customer) (((List) getServerSession().executeQuery(raq)).get(0)); SalesPerson salesPerson = ((Order) (expectedCustomer.getOrders().iterator().next())).getSalesPerson(); String ejbqlString = "SELECT DISTINCT c FROM Customer c JOIN c.orders o JOIN o.salesPerson s WHERE s.id = " + salesPerson.getId(); List firstResult = em.createQuery(ejbqlString).getResultList(); String alternateEjbqlString = "SELECT DISTINCT c FROM Customer c, IN(c.orders) o WHERE o.salesPerson.id = " + salesPerson.getId(); List secondResuslt = em.createQuery(alternateEjbqlString).getResultList(); // only 1 order for this customer Assert.assertEquals( "Get order for customer test failed: data validation error", firstResult.size(), 1); Assert.assertTrue( "Get order for customer test failed: two equivalent ejb queries return different results", comparer.compareObjects(secondResuslt, firstResult)); Assert.assertTrue( "Get order for customer test failed", comparer.compareObjects(expectedCustomer, firstResult)); }
public void getOrderLargerThan() { EntityManager em = createEntityManager(); ExpressionBuilder builder1 = new ExpressionBuilder(Order.class); ExpressionBuilder builder2 = new ExpressionBuilder(Order.class); Expression o1Quantity = builder1.get("quantity"); Expression o2Quantity = builder2.get("quantity"); Expression quantityComparison = o1Quantity.greaterThan(o2Quantity); Expression o2CustomerName = builder2.get("customer").get("name"); Expression nameComparison = o2CustomerName.equal("Jane Smith"); Expression whereClause = quantityComparison.and(nameComparison); ReadAllQuery raq = new ReadAllQuery(); raq.setSelectionCriteria(whereClause); raq.setReferenceClass(Order.class); raq.useDistinct(); List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString = "SELECT DISTINCT o1 FROM OrderBean o1, OrderBean o2 WHERE o1.quantity > o2.quantity AND" + " o2.customer.name = 'Jane Smith' "; List result = em.createQuery(ejbqlString).getResultList(); // only 1 order Assert.assertEquals( "Get order larger than test failed: data validation error", result.size(), 1); Assert.assertTrue( "Get order larger than test failed", comparer.compareObjects(expectedResult, result)); }
public void testDeleteExpression() { if (isOnServer()) { // Not work on server. return; } if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) { getServerSession() .logMessage( "Test testDeleteExpression skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193)."); return; } JpaEntityManager em = (org.eclipse.persistence.jpa.JpaEntityManager) createEntityManager(); try { beginTransaction(em); String orderString = "DELETE FROM OrderBean o WHERE o.customer.name ='Karen McDonald' "; em.createQuery(orderString).executeUpdate(); orderString = "DELETE FROM OrderBean o WHERE o.billedCustomer.name ='Karen McDonald' "; em.createQuery(orderString).executeUpdate(); String ejbqlString = "DELETE FROM Customer c WHERE c.name='Karen McDonald' "; int result = em.createQuery(ejbqlString).executeUpdate(); Assert.assertEquals("Delete Expression test failed: customer to delete not found", 1, result); em.flush(); ReadAllQuery raq = new ReadAllQuery(Customer.class, new ExpressionBuilder()); Expression whereClause = raq.getExpressionBuilder().get("name").equal("Karen McDonald"); raq.setSelectionCriteria(whereClause); List customerFound = (List) em.getActiveSession().executeQuery(raq); Assert.assertEquals("Delete Expression test failed", 0, customerFound.size()); } finally { rollbackTransaction(em); } }
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 static DatabaseQuery buildPersistenceTestGetAllowingNullEqualQuery() { ExpressionBuilder builder = new ExpressionBuilder(Employee.class); Expression expression = builder.getAllowingNull("address").get("city").equal("Toronto"); ReadAllQuery query = new ReadAllQuery(Employee.class); query.setSelectionCriteria(expression); return query; }
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(); }
public static DatabaseQuery buildPersistenceTestAnyOfAllowingNoneEqualQuery() { ExpressionBuilder builder = new ExpressionBuilder(Employee.class); Expression expression = builder.anyOfAllowingNone("phoneNumbers").get("areaCode").equal("613"); ReadAllQuery query = new ReadAllQuery(Employee.class); query.setSelectionCriteria(expression); return query; }
public void run() { org.eclipse.persistence.queries.ReadAllQuery query = new org.eclipse.persistence.queries.ReadAllQuery(ConcurrentLargeProject.class); query.setSelectionCriteria(query.getExpressionBuilder().get("id").equal(idToUse)); query.addJoinedAttribute("location"); query.refreshIdentityMapResult(); session.executeQuery(query); }
public void setup() { getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); allEmployees = new Vector(); queryAll = new ReadAllQuery(); queryAll.setReferenceClass(Employee.class); queryAll.setSelectionCriteria( new ExpressionBuilder().get("address").get("city").greaterThan("Montreal")); allEmployees = (Vector) getSession().executeQuery(queryAll); }
protected void test() { query = new ReadAllQuery(); query.setReferenceClass(referenceClass); ReportQuery hierarchyQuery = new ReportQuery(); hierarchyQuery.setReferenceClass(referenceClass); // The #employeeId is what would cause the error hierarchyQuery.setCall(new SQLCall("SELECT EMP_ID FROM EMPLOYEE WHERE MANAGER_ID=#employeeId")); query.setSelectionCriteria(query.getExpressionBuilder().get("id").in(hierarchyQuery)); // want the argument at the top level query query.addArgument("employeeId"); }
public void setup() { if (getSession().getLogin().getPlatform().isSQLServer() || getSession().getLogin().getPlatform().isSybase()) { throw new TestWarningException( "This test is not supported on SQL Server and Sybase. Because 'MOD' is not a recognized function name on SQL Server and Sybase."); } ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(getReferenceClass()); raq.setSelectionCriteria(getOriginalObjectExpression()); setOriginalOject(getSession().executeQuery(raq)); super.setup(); }
public void test() { ReadAllQuery q = new ReadAllQuery(); q.setBatchFetchType(batchType); q.setReferenceClass(Shipment.class); q.addBatchReadAttribute("employee"); q.setSelectionCriteria( q.getExpressionBuilder() .get("employee") .get("address") .equal(q.getExpressionBuilder().getParameter("ADDRESS"))); q.addArgument("ADDRESS"); Vector r = new Vector(); r.addElement("885 Meadowlands Dr."); UnitOfWork uow = getSession().acquireUnitOfWork(); v = (java.util.Vector) uow.executeQuery(q, r); }
public void findAllEmployeesWithCellPhones() { EntityManager em = createEntityManager(); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.anyOf("phoneNumbers").get("type").equal("Cellular"); ReadAllQuery raq = new ReadAllQuery(Employee.class); raq.setSelectionCriteria(whereClause); if (usesSOP() && getServerSession().getPlatform().isOracle()) { // distinct is incompatible with blob in selection clause on Oracle } else { raq.useDistinct(); } List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString; if (usesSOP() && getServerSession().getPlatform().isOracle()) { // distinct is incompatible with blob in selection clause on Oracle ejbqlString = "SELECT e FROM Employee e JOIN e.phoneNumbers p " + "WHERE p.type = 'Cellular'"; } else { ejbqlString = "SELECT DISTINCT e FROM Employee e JOIN e.phoneNumbers p " + "WHERE p.type = 'Cellular'"; } List firstResult = em.createQuery(ejbqlString).getResultList(); String alternateEjbqlString; if (usesSOP() && getServerSession().getPlatform().isOracle()) { // distinct is incompatible with blob in selection clause on Oracle alternateEjbqlString = "SELECT e FROM Employee e INNER JOIN e.phoneNumbers p " + "WHERE p.type = 'Cellular'"; } else { alternateEjbqlString = "SELECT DISTINCT e FROM Employee e INNER JOIN e.phoneNumbers p " + "WHERE p.type = 'Cellular'"; } List secondResult = em.createQuery(alternateEjbqlString).getResultList(); // 4 employees returned Assert.assertEquals( "Find all employees with cellular phone numbers test failed: data validation error", firstResult.size(), 4); Assert.assertTrue( "Find all employees with cellular phone numbers test failed: two equivalent ejb queries return different results", comparer.compareObjects(secondResult, firstResult)); Assert.assertTrue( "Find all employees with cellular phone numbers test failed", comparer.compareObjects(expectedResult, secondResult)); }
public void test() { // Make a query an search Number greaterThan "00005" ExpressionBuilder phone = new ExpressionBuilder(); Expression exp = phone.get("areaCode").equal(613); ReadAllQuery query = new ReadAllQuery(PhoneNumber.class); query.setSelectionCriteria(exp); query.conformResultsInUnitOfWork(); // set Conforming query.addOrdering(phone.get("owner").get("id").descending()); query.addOrdering(phone.get("type").descending()); UnitOfWork uow = getSession().acquireUnitOfWork(); Vector v = (Vector) uow.executeQuery(query); Vector v2 = (Vector) uow.executeQuery(query); if (!v.equals(v2)) { throw new TestErrorException("Order not maintained when conforming:" + v + " != " + v2); } }
public void testProjectJoinTeamLeaderJoinAddressWhereTeamLeaderNotNull() { ReadAllQuery query = new ReadAllQuery(); query.setReferenceClass(Project.class); Expression teamLeader = query.getExpressionBuilder().get("teamLeader"); query.setSelectionCriteria(teamLeader.notNull()); ReadAllQuery controlQuery = (ReadAllQuery) query.clone(); query.addJoinedAttribute(teamLeader); Expression teamLeaderAddress = teamLeader.get("address"); query.addJoinedAttribute(teamLeaderAddress); String errorMsg = executeQueriesAndCompareResults(controlQuery, query); if (errorMsg.length() > 0) { fail(errorMsg); } }
public void testProblemReporterProjectJoinTeamMembersJoinAddress() { ReadAllQuery query = new ReadAllQuery(); query.setReferenceClass(Project.class); query.setSelectionCriteria(query.getExpressionBuilder().get("name").equal("Problem Reporter")); ReadAllQuery controlQuery = (ReadAllQuery) query.clone(); Expression teamMembers = query.getExpressionBuilder().anyOf("teamMembers"); query.addJoinedAttribute(teamMembers); Expression teamMembersAddress = teamMembers.get("address"); query.addJoinedAttribute(teamMembersAddress); String errorMsg = executeQueriesAndCompareResults(controlQuery, query); if (errorMsg.length() > 0) { fail(errorMsg); } }
public void testEmployeeJoinProjectsJoinTeamLeaderJoinAddressWhereManagerIsNull() { ReadAllQuery query = new ReadAllQuery(); query.setReferenceClass(Employee.class); query.setSelectionCriteria(query.getExpressionBuilder().get("manager").isNull()); ReadAllQuery controlQuery = (ReadAllQuery) query.clone(); Expression projects = query.getExpressionBuilder().anyOf("projects"); query.addJoinedAttribute(projects); Expression teamLeader = projects.get("teamLeader"); query.addJoinedAttribute(teamLeader); Expression teamLeaderAddress = teamLeader.get("address"); query.addJoinedAttribute(teamLeaderAddress); String errorMsg = executeQueriesAndCompareResults(controlQuery, query); if (errorMsg.length() > 0) { fail(errorMsg); } }
public void testOrderByExpression() { EntityManager em = createEntityManager(); ReadAllQuery raq = new ReadAllQuery(PhoneNumber.class, new ExpressionBuilder()); Expression whereClause = raq.getExpressionBuilder().get("owner").get("address").get("province").equal("ONT"); raq.setSelectionCriteria(whereClause); raq.addOrdering(raq.getExpressionBuilder().get("areaCode")); raq.addOrdering(raq.getExpressionBuilder().get("type")); List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString = "SELECT p FROM Employee e JOIN e.phoneNumbers p JOIN e.address a WHERE a.province = 'ONT' " + "ORDER BY p.areaCode, p.type"; List result = em.createQuery(ejbqlString).getResultList(); Assert.assertEquals("OrderBy expression test failed: data validation error", result.size(), 13); Assert.assertTrue( "OrderBy expression test failed", comparer.compareObjects(expectedResult, result)); }
protected void test() { for (int i = 0; i <= 1; i++) { getSession().getPlatform().setShouldBindAllParameters(i != 0); for (int j = 0; j <= 2; j++) { query = new ReadAllQuery(Employee.class); ExpressionBuilder builder = new ExpressionBuilder(); Vector vExp = new Vector(2); vExp.add(builder.getParameter("p1")); query.addArgument("p1"); vExp.add(builder.getParameter("p2")); query.addArgument("p2"); Expression exp = builder.get("id").in(vExp); query.setSelectionCriteria(exp); switch (j) { case 0: // nothing to do - just test the default: // query.bindAllParameters == Undefined break; case 1: // query.bindAllParameters == False query.setShouldBindAllParameters(false); break; case 2: // query.bindAllParameters == True query.setShouldBindAllParameters(true); break; } // clear the writer's buffer ((StringWriter) getSession().getLog()).getBuffer().setLength(0); try { getSession().executeQuery(query, v); } catch (DatabaseException e) { throw new TestProblemException("executeQuery threw DatabaseException"); } if (shouldBind() != wasBound()) { return; } } } }
public void setup() { // JGL: If the arguments are already set by the test, don't // set them again if (!hasArguments()) { setArgumentsForTestUsing(getSomeEmployees()); } ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(Employee.class); raq.setSelectionCriteria(getOriginalObjectExpression()); // Add all the arguments to the query Enumeration enumtr = getExpressionParameters().elements(); while (enumtr.hasMoreElements()) { raq.addArgument((String) enumtr.nextElement()); } // Save the retrieved employees for the verify setOriginalOject(getSession().executeQuery(raq, getArguments())); // Finish the setup super.setup(); }
/** * Tests if SpatialExpressions will work properly without hung up when using ANYINTERACT query * type */ public void testSimpleReadQuery() { if (supported) { JGeometry circle = JGeometry.createCircle(-10, 0, 0, 10, 10, 0, 0); JGeometry newCircle = JGeometry.createCircle(0, -10, 0, 10, 10, 0, 0); EntityManager em = createEntityManager(STRUCT_CONVERTER_PU); try { beginTransaction(em); SimpleSpatial simpleSpatial = new SimpleSpatial(2000, circle); em.persist(simpleSpatial); commitTransaction(em); } catch (RuntimeException ex) { if (isTransactionActive(em)) { rollbackTransaction(em); } throw ex; } clearCache(STRUCT_CONVERTER_PU); ReadAllQuery raq = new ReadAllQuery(SimpleSpatial.class); ExpressionBuilder eb = raq.getExpressionBuilder(); SpatialParameters parameters = new SpatialParameters(); parameters.setQueryType(SpatialParameters.QueryType.WINDOW).setMask(Mask.ANYINTERACT); Expression selectionCriteria = SpatialExpressionFactory.relate(eb.get("jGeometry"), newCircle, parameters); raq.setSelectionCriteria(selectionCriteria); raq.addAscendingOrdering("id"); getServerSession(STRUCT_CONVERTER_PU).executeQuery(raq); // now read using jpql - should generate the same sql as the ReadAllQuery above. clearCache(STRUCT_CONVERTER_PU); Query query = em.createQuery( "SELECT ss FROM SimpleSpatial ss WHERE FUNC('MDSYS.SDO_RELATE', ss.jGeometry, :otherGeometry, :params) = 'TRUE' ORDER BY ss.id ASC"); query.setParameter("otherGeometry", newCircle); query.setParameter("params", parameters.getParameterString()); query.getResultList(); } }
public void findAllEmployeesWithOutPhoneNumbers() { EntityManager em = createEntityManager(); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.isEmpty("phoneNumbers"); ReadAllQuery raq = new ReadAllQuery(Employee.class); raq.setSelectionCriteria(whereClause); raq.useDistinct(); List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString = "SELECT DISTINCT e FROM Employee e WHERE e.phoneNumbers IS EMPTY"; List result = em.createQuery(ejbqlString).getResultList(); // 1 employee w/o phone number returned Assert.assertEquals( "Find all employees WITHOUT phone numbers test failed: data validation error", result.size(), 1); Assert.assertTrue( "Find all employees WITHOUT phone numbers test failed", comparer.compareObjects(expectedResult, result)); }
public void testOuterJoin() { EntityManager em = createEntityManager(); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.anyOfAllowingNone("phoneNumbers").get("type").equal("Cellular"); ReadAllQuery raq = new ReadAllQuery(Employee.class); raq.setSelectionCriteria(whereClause); List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString = "SELECT e FROM Employee e LEFT JOIN e.phoneNumbers p " + "WHERE p.type = 'Cellular'"; List firstResult = em.createQuery(ejbqlString).getResultList(); String alternateEjbqlString = "SELECT e FROM Employee e LEFT OUTER JOIN e.phoneNumbers p " + "WHERE p.type = 'Cellular'"; List secondResult = em.createQuery(alternateEjbqlString).getResultList(); // return 4 employees with cell phones Assert.assertEquals( "Get SalesPerson for Orders test failed: data validation error", firstResult.size(), 4); Assert.assertTrue( "Get Outer Join test failed: two equivalent ejb queries return different results", comparer.compareObjects(secondResult, firstResult)); Assert.assertTrue( "Get Outer Join test failed", comparer.compareObjects(expectedResult, firstResult)); }
public void testEmployeeJoinManagerAddressOuterJoinManagerAddress() { ReadAllQuery query = new ReadAllQuery(); query.setReferenceClass(Employee.class); query.setSelectionCriteria( query .getExpressionBuilder() .get("lastName") .equal("Way") .or(query.getExpressionBuilder().get("lastName").equal("Jones"))); ReadAllQuery controlQuery = (ReadAllQuery) query.clone(); Expression manager = query.getExpressionBuilder().get("manager"); query.addJoinedAttribute(manager); query.addJoinedAttribute(manager.get("address")); Expression managersManager = manager.getAllowingNull("manager"); query.addJoinedAttribute(managersManager); query.addJoinedAttribute(managersManager.get("address")); String errorMsg = executeQueriesAndCompareResults(controlQuery, query); if (errorMsg.length() > 0) { fail(errorMsg); } }
public void findOrdersWithDifferentBilledCustomer() { EntityManager em = createEntityManager(); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.get("customer").equal(builder.get("billedCustomer")).not(); ReadAllQuery raq = new ReadAllQuery(Order.class); raq.setSelectionCriteria(whereClause); List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString = "SELECT o FROM OrderBean o WHERE o.customer <> o.billedCustomer"; List firstResult = em.createQuery(ejbqlString).getResultList(); String alternateEjbqlString = "SELECT o FROM OrderBean o WHERE NOT o.customer.customerId = o.billedCustomer.customerId"; List secondResult = em.createQuery(alternateEjbqlString).getResultList(); // 2 orders returned Assert.assertTrue( "Find orders with different billed customers test failed: two equivalent ejb queries return different results", comparer.compareObjects(secondResult, firstResult)); Assert.assertTrue( "Find orders with different billed customers test failed", comparer.compareObjects(expectedResult, firstResult)); }