Home / 1.0-alpha
Name Modified Size InfoDownloads / Week
Parent folder
This folder has no files.
Totals: 0 Items   0
-----------------------------------------------------------------------------------------------------
    NOTE: THIS PROJECT IS RENAMED TO EASY-CRITERIA (https://sourceforge.net/projects/easy-criteria/). 
-----------------------------------------------------------------------------------------------------















Tired of writing SQL in Java? Afraid of fragility of named queries?  Want to write metadata based type-safe queries, but lost in verbose JPA api? Then this framework is for you. Now you can now write metadata based, type-safe, debugable, readable, and maintainable queries in Object Oriented way easily. No prior knowledge of SQL or JPA required.
----------- 
HOW TO USE:
-----------
There are two main classes in this framework; 1- CriteriaComposer, 2- CriteriaProcessor

Use CriteriaComposer to construct your query using one or all of the following constructs: Select, Where, 
Group by, Order By, Join, Logical Operators (AND, OR, NOT), Comparison Operator (EQUAL, LIKE, IN, etc..), 
AggregateFunction (SUM, COUNT, AVERAGE, etc..). 

Use CrieriaProcessor to execute this query and get the results. There are two types of API in this class; 1- Entity based, 2- Tuple based

Use Entity based API when you want to get all columns of the root entity. Use Tuple based API when you to 
retrieve selected columns from one or more than one entities. Please note that Entity based API ignores the 
Select clause that you may have in you criteria.

----------- 
EXAMPLE 1: SQL : select person.name, sum(course.unit) from person inner join course_session inner join course group by person.name
-----------
CriteriaComposer<Person> studentUnitCount = CriteriaComposer.createComposer(Person.class).select(Person_.name).groupBy(Person_.name);
studentUnitCount.join(Person_.courseSessions).join(CourseSession_.course).select(AggregateFunction.SUM, Course_.unit);		
		
List<Tuple>  result= criteriaProcessor.findAllTuple(studentUnitCount);

for(Tuple tuple: result)
    System.print(tuple.get("Person.name"));
    
Alternatively you can define your own alias e.g. {select(Person_.name, "name")}. This alias should be unique across your criteria, if you select another column with the same alias e.g.{select(Course_.name, "name")} then it would result in an error. 

-----------
EXAMPLE 2: SQL: select * from course where course.last_update_date_time between ? and ?
----------- 
CriteriaComposer<Course> courseCriteria = new CriteriaComposer<Course>(Course.class);
criteria.where(Course_.lastUpdateDateTime, ComparisonOperator.BETWEEN, thatDate, toDate);
 
List<Course> result = criteriaProcessor.findAllEntity(courseCriteria);
	
Source: readme.txt, updated 2011-05-25