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.CriteriaProcessorTest.java
/** * Find all Students.//w w w . j a v a 2s. c om * Same as 1 but criteria is defined in PersonCritera class. This is the * preferred way. * Makes service more readable. */ @Test public void testFindAllStudent2() { CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); CriteriaComposer<PersonType> studentTypeCriteria = studentCriteria.join(JoinType.INNER, Person_.personType); studentTypeCriteria.where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); List<Person> result = criteriaProcessor.findAllEntity(studentCriteria, true, null); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(9, result.size()); }
From source file:org.easy.test.criteria.CriteriaProcessorTest.java
/** * Find all students enrolled in course1 * // w w w . j a v a 2s . 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<PersonType> studentTypeCriteria = CriteriaComposer.from(PersonType.class); studentTypeCriteria.where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); studentCriteria.join(JoinType.INNER, Person_.personType, studentTypeCriteria); 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.CriteriaProcessorTest.java
/** * Same as ...[1] but using dot operator to chain the method calls. *///from w ww .j a v a 2 s .co m @Test public void testFindAllStudentEnrolledInClass2() { CriteriaComposer<PersonType> studentTypeCriteria = CriteriaComposer.from(PersonType.class); studentTypeCriteria.where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); studentCriteria.join(JoinType.INNER, Person_.personType, studentTypeCriteria); 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.CriteriaProcessorTest.java
/** * Same as ...[1] but criteria is supplied externally, makes service more * readable./*from w w w .j a v a 2 s . com*/ */ @Test public void testFindAllStudentEnrolledInClass3() { CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); CriteriaComposer<PersonType> studentTypeCriteria = studentCriteria.join(JoinType.INNER, Person_.personType); studentTypeCriteria.where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); 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.CriteriaProcessorTest.java
/** * Same as ...[1] but using more fine grained criteria API. * //from w w w.j av a 2 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() { CriteriaComposer<Course> courseCriteria = CriteriaComposer.from(Course.class); courseCriteria.where(Course_.name, ComparisonOperator.EQUAL, "course1"); Course course = criteriaProcessor.findUniqueEntity(courseCriteria, null); CriteriaComposer<PersonType> studentTypeCriteria = CriteriaComposer.from(PersonType.class); studentTypeCriteria.where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); studentCriteria.join(JoinType.INNER, Person_.personType, studentTypeCriteria); 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.CriteriaProcessorTest.java
/** * Tuple search with selected columns/*from www . ja v a2 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).where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); 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.CriteriaProcessorTest.java
/** * Tuple search with selected columns. Same as 1 but select has user defined * alias.//from w ww . ja v a 2 s.c o m */ @Test public void testFindAllStudentTuple2() { CriteriaComposer<PersonType> studentTypeCriteria = CriteriaComposer.from(PersonType.class); studentTypeCriteria.where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); CriteriaComposer<Person> studentCriteria = CriteriaComposer.from(Person.class); studentCriteria.select(Person_.id, "id"); studentCriteria.select(Person_.name, "name"); studentCriteria.join(JoinType.INNER, Person_.personType, studentTypeCriteria); 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.CriteriaProcessorTest.java
/** * Test Order By/* w w w . j a va 2 s . co 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).where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); //Note that dot chaining canot continue any more since the new join is on person table not on person type table. //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")); }
From source file:org.easy.test.criteria.CriteriaProcessorTest.java
/** * Test Order By. Same as 2/*from w w w . j av a 2 s. c om*/ * * Framework is flexible. You can write criteria in any format you want. */ @Test public void testOrderBy2c() { 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).where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); CriteriaComposer<Course> course = studentCriteria.join(Person_.courseSessions).join(CourseSession_.course); course.select(Course_.name); course.where(Course_.name, IN, "course1", "course3"); course.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")); }
From source file:org.easy.test.criteria.CriteriaProcessorTest.java
/** * Test Order By. If there is no attribute is selected then it throws exception * /*w ww .ja v a 2 s . c o m*/ * Framework is flexible. You can write criteria in any format you want. */ @Test(expected = java.lang.IllegalArgumentException.class) public void testOrderBy3() { CriteriaComposer<Person> student = CriteriaComposer.from(Person.class); student.join(JoinType.INNER, Person_.personType).where(PersonType_.name, ComparisonOperator.EQUAL, PersonTypeEnum.STUDENT); CriteriaComposer<Course> course = student.join(Person_.courseSessions).join(CourseSession_.course); course.where(Course_.name, IN, "course1", "course3"); List<Tuple> result = criteriaProcessor.findAllTuple(student, true, null); assertNotNull(result); assertTrue(result.size() > 0); assertEquals(6, result.size()); assertEquals("course3", result.get(0).get("Course.name")); assertEquals("student9", result.get(0).get("Person.name")); }