Platinum Partner
java,framework,persistence

EasyCriteria 1.0 Released

EasyCriteria is an open source tool to make the JPA Criteria code for any kind of JPA implementation easier . EasyCriteria has 100% of coverage on its tests with JUnit and it is tested with Hibernate, OpenJPA and EclipseLink.

If you want to understand the Criteria ideal and how to apply it to your code check this post: EasyCriteria – An easy way to use the JPA Criteria

The new EasyCriteria functionality includes:

  • Join with conditions
  • Query Pagination

Now it is possible to do a Join and add parameters to it:

EntityManager em = emf.createEntityManager();
EasyCriteria<Person> easyCriteria = EasyCriteriaFactory.createQueryCriteria(em, Person.class);
 
easyCriteria.innerJoin("dogs", Dog.class);
easyCriteria.whereJoinEquals("dogs", "name", "Dark");
easyCriteria.whereJoinStringNotIn("dogs", "name", names); // names is a List<String>
easyCriteria.whereJoinStringLike("dogs", "name", "M%");
easyCriteria.whereJoinListIsEmpty("dogs", "cars");
easyCriteria.whereJoinAttributeIsNull("dogs", "nickName");
easyCriteria.whereJoinStringBetween("dogs", "name", "A", "L");

The query can be paginated:

EasyCriteria<Dog> eascyCriteria = EasyCriteriaFactory.createQueryCriteria(getEntityManager(), Dog.class);
eascyCriteria.setFirstResult(0);
eascyCriteria.setMaxResults(5);

This new version also has 100% of code coverage.

Click here to download the code of this post with EasyCriteria. With this code you can test EasyCriteria as you like.

In the project page (http://easycriteria.uaihebert.com/) you will find all documentation.

If you have any doubt, just post it.

 

 

 

 

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}