List of usage examples for javax.persistence.criteria JoinType INNER
JoinType INNER
To view the source code for javax.persistence.criteria JoinType INNER.
Click Source Link
From source file:org.easy.test.criteria.CriteriaProcessorTest2.java
/** * Find all Students//from ww w. ja va 2 s . c om * * select * from person inner join person_type on * person.person_type_id=persontype.id where persontype.name=STUDENT */ @Test public void testFindAllStudent1() { CriteriaComposer<Person> student = CriteriaComposer.from(Person.class); student.join(JoinType.INNER, Person_.personType, PersonTypeCriteria.forStudentType()); List<Person> result = criteriaProcessor.findAllEntity(student, true, null); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(9, result.size()); }
From source file:org.easy.test.criteria.CriteriaProcessorTest2.java
/** * Find all students enrolled in course1 * // w w w . ja va 2 s. c o m * select * from person * inner join person_type * inner join course_session * inner join course * where persontype.name=STUDENT and course3.name=COURSE1 */ @Test public void testFindAllStudentEnrolledInClass1() { CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); studentCriteria.join(JoinType.INNER, Person_.personType, PersonTypeCriteria.forStudentType()); studentCriteria.join(JoinType.INNER, Person_.courseSessions).join(JoinType.INNER, CourseSession_.course) .where(Course_.name, EQUAL, "course1"); List<Person> result = criteriaProcessor.findAllEntity(studentCriteria, true, null); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(6, result.size()); assertEquals("student1", result.get(0).getName()); }
From source file:org.easy.test.criteria.CriteriaProcessorTest2.java
/** * Same as ...[1] but using dot operator to chain the method calls. *///ww w.j a va 2s . c om @Test public void testFindAllStudentEnrolledInClass2() { CriteriaComposer<Person> studentCriteria = PersonCriteria.findStudent(); studentCriteria.join(JoinType.INNER, Person_.courseSessions).join(JoinType.INNER, CourseSession_.course) .where(Course_.name, EQUAL, "course1"); List<Person> result = criteriaProcessor.findAllEntity(studentCriteria, true, null); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(6, result.size()); assertEquals("student1", result.get(0).getName()); }
From source file:org.easy.test.criteria.CriteriaProcessorTest2.java
/** * Same as ...[1] but using more fine grained criteria API. * /*from w w w.j a va2 s .co m*/ * select courseId from course where course.name=? * select * from person inner join person_type * inner join course_session * where persontype.name=STUDENT and course.id=courseId */ @Test public void testFindAllStudentEnrolledInClass4() { //find course first Course course = criteriaProcessor.findUniqueEntity(CourseCriteria.findCourseByName("course1"), null); //find students matching with above couse CriteriaComposer<Person> studentCriteria = PersonCriteria.findStudent(); studentCriteria.join(JoinType.INNER, Person_.courseSessions).where(CourseSession_.course, EQUAL, course); List<Person> result = criteriaProcessor.findAllEntity(studentCriteria); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(6, result.size()); assertEquals("student1", result.get(0).getName()); }
From source file:org.easy.test.criteria.CriteriaProcessorTest2.java
/** * Tuple search with selected columns//from w ww .j a v a 2 s . c o m * * select person.id, person.name from person * inner join person_type * where persontype.name=STUDENT */ @Test public void testFindAllStudentTuple1() { CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); studentCriteria.select(Person_.id, Person_.name); studentCriteria.join(JoinType.INNER, Person_.personType, PersonTypeCriteria.forStudentType()); List<Tuple> result = criteriaProcessor.findAllTuple(studentCriteria, true, null); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(9, result.size()); assertEquals("student1", result.get(0).get("Person.name")); }
From source file:org.easy.test.criteria.CriteriaProcessorTest2.java
/** * Tuple search with selected columns. Same as 1 but select has user defined * alias.//ww w .j av a 2 s . c o m */ @Test public void testFindAllStudentTuple2() { CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); studentCriteria.select(Person_.id, "id"); studentCriteria.select(Person_.name, "name"); studentCriteria.join(JoinType.INNER, Person_.personType, PersonTypeCriteria.forStudentType()); List<Tuple> result = criteriaProcessor.findAllTuple(studentCriteria, true, null); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(9, result.size()); assertEquals("student1", result.get(0).get("name")); }
From source file:org.easy.test.criteria.CriteriaProcessorTest2.java
/** * Test Order By//from w w w . ja va 2 s . c o m * OrderBy can be provided for any and for multiple entities who are part of * a criteria. * OrderBy can be ranked independent of join order. * If we change rank for Course_name to 2 then this orderBy will be ignored * since higher level * entity Person has the orderBy with the same rank. * * select person.name, person.id, course.name from person * inner join person_type * inner join course_session * inner join course * where persontype.name=? and (course.name in (? , ?)) * order by course.name desc, person.name desc */ @Test public void testOrderBy2() { //select student CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); studentCriteria.select(Person_.name, Person_.id); studentCriteria.orderBy(Person_.name, false, 2); studentCriteria.join(JoinType.INNER, Person_.personType, PersonTypeCriteria.forStudentType()); //select course CriteriaComposer<Course> courseCriteria = studentCriteria.join(Person_.courseSessions) .join(CourseSession_.course); courseCriteria.select(Course_.name); courseCriteria.where(Course_.name, IN, "course1", "course3"); courseCriteria.orderBy(Course_.name, false, 1); List<Tuple> result = criteriaProcessor.findAllTuple(studentCriteria, true, null); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(11, result.size()); assertEquals("course3", result.get(0).get("Course.name")); assertEquals("student9", result.get(0).get("Person.name")); }