use of org.eclipse.persistence.testing.models.jpa.advanced.Employee in project eclipselink by eclipse-ee4j.
the class SQLResultSetMappingTestSuite method testComplicateResults.
/**
* tests that embeddable and dot notation for fieldresults work
*/
public void testComplicateResults() throws Exception {
SQLResultSetMapping resultSetMapping = new SQLResultSetMapping("ComplicatedInheritance");
EntityResult entityResult;
entityResult = new EntityResult(Employee.class);
entityResult.addFieldResult(new FieldResult("period.startDate", "STARTDATE"));
entityResult.addFieldResult(new FieldResult("address.id", "EMP_ADDR"));
resultSetMapping.addResult(entityResult);
SQLCall call = new SQLCall("SELECT t0.EMP_ID, t1.EMP_ID, t0.F_NAME, t0.L_NAME, t0.VERSION, t1.SALARY, t0.START_DATE AS STARTDATE, t0.END_DATE, t0.ADDR_ID AS EMP_ADDR, t0.MANAGER_EMP_ID FROM CMP3_EMPLOYEE t0, CMP3_SALARY t1 WHERE ((t1.EMP_ID = t0.EMP_ID) AND ( t0.L_NAME = 'Smith' ))");
ResultSetMappingQuery query = new ResultSetMappingQuery(call);
query.setSQLResultSetMapping(resultSetMapping);
List results = (List) getServerSession().executeQuery(query);
assertNotNull("No result returned", results);
assertTrue("Incorrect number of results returned, expected 2 got " + results.size(), (results.size() == 2));
for (Iterator iterator = results.iterator(); iterator.hasNext(); ) {
Object resultElement = iterator.next();
assertTrue("Failed to return Employee", (resultElement instanceof Employee));
Employee emp = (Employee) resultElement;
assertNotNull("Failed to get an address for Employee " + emp.getFirstName(), emp.getAddress());
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Employee in project eclipselink by eclipse-ee4j.
the class JUnitCriteriaSimpleTestSuiteBase method baseTestCase.
// Test case for selecting ALL employees from the database
public void baseTestCase() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
List expectedResult = getServerSession().readAllObjects(Employee.class);
clearCache();
// "SELECT OBJECT(emp) FROM Employee emp"
List<Employee> result = em.createQuery(em.getCriteriaBuilder().createQuery(Employee.class)).getResultList();
assertTrue("Base Test Case Failed", comparer.compareObjects(result, expectedResult));
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Employee in project eclipselink by eclipse-ee4j.
the class JUnitCriteriaSimpleTestSuiteBase method distinctTest.
public void distinctTest() {
EntityManager em = createEntityManager();
ReadAllQuery raq = new ReadAllQuery();
ExpressionBuilder employee = new ExpressionBuilder();
Expression whereClause = employee.get("lastName").equal("Smith");
raq.setReferenceClass(Employee.class);
raq.setSelectionCriteria(whereClause);
raq.useDistinct();
Vector expectedResult = (Vector) getServerSession().executeQuery(raq);
clearCache();
// "SELECT DISTINCT OBJECT(emp) FROM Employee emp WHERE emp.lastName = \'Smith\'"
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Employee> cq = qb.createQuery(Employee.class);
cq.distinct(true);
cq.where(qb.equal(wrapper.get(wrapper.from(cq, Employee.class), Employee_lastName), "Smith"));
List result = null;
beginTransaction(em);
try {
result = em.createQuery(cq).getResultList();
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
assertTrue("Distinct test failed", comparer.compareObjects(result, expectedResult));
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Employee in project eclipselink by eclipse-ee4j.
the class JUnitCriteriaSimpleTestSuiteBase method simpleNotBetweenTest.
public void simpleNotBetweenTest() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee emp1 = (Employee) getServerSession().readAllObjects(Employee.class).firstElement();
Employee emp2 = (Employee) getServerSession().readAllObjects(Employee.class).lastElement();
ReadAllQuery raq = new ReadAllQuery();
raq.setReferenceClass(Employee.class);
ExpressionBuilder eb = new ExpressionBuilder();
Expression whereClause = eb.get("id").between(emp1.getId(), emp2.getId()).not();
raq.setSelectionCriteria(whereClause);
Vector expectedResult = (Vector) getServerSession().executeQuery(raq);
clearCache();
// "SELECT OBJECT(emp) FROM Employee emp WHERE emp.id NOT BETWEEN " + emp1.getId() + " AND "+ emp2.getId()
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Employee> cq = qb.createQuery(Employee.class);
Root<Employee> root = wrapper.from(cq, Employee.class);
cq.where(qb.not(qb.between(wrapper.get(root, Employee_id), emp1.getId(), emp2.getId())));
List<Employee> result = em.createQuery(cq).getResultList();
assertTrue("Simple Not Between Test failed", comparer.compareObjects(result, expectedResult));
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Employee in project eclipselink by eclipse-ee4j.
the class JUnitCriteriaSimpleTestSuiteBase method simpleThreeArgConcatTest.
public void simpleThreeArgConcatTest() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee expectedResult = (Employee) (getServerSession().readAllObjects(Employee.class).firstElement());
clearCache();
String partOne, partTwo, partThree;
partOne = expectedResult.getFirstName().substring(0, 1);
partTwo = expectedResult.getFirstName().substring(1, 2);
partThree = expectedResult.getFirstName().substring(2);
// "SELECT OBJECT(emp) FROM Employee emp WHERE emp.firstName = CONCAT(\"" + partOne + "\", CONCAT(\"" + partTwo
// + "\", \"" + partThree + "\") )"
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Employee> cq = qb.createQuery(Employee.class);
Root<Employee> root = wrapper.from(cq, Employee.class);
cq.where(qb.equal(wrapper.get(root, Employee_firstName), qb.concat(qb.literal(partOne), qb.concat(qb.literal(partTwo), qb.literal(partThree)))));
List<Employee> result = em.createQuery(cq).getResultList();
assertTrue("Concat test failed", comparer.compareObjects(result, expectedResult));
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
Aggregations