Hello, how are you?
It is with a great joy that I announce a new version of the EasyCriteria framework. This new version will make easier and increase the framework utilization (click here if you do not know nothing about the EasyCriteria framework).
2 new features and a huge refactoring are present in this new version, these features/refactoring deserve a new major version in the framework. The new version is now 3.0.
Let us see what is new:
This refactoring was done to reduce the code complexity, to apply more code patterns, using “final” attribute to make a better memory use and changing “pom.xml” dependences.
Notice in the pictures above that the Cyclomatic complexity has been reduced a lot (click here to know more about Cyclomatic complexity). Just the “utils” package that had a small increase of complexity but it had some lines removed.
Multiple Joins! o/
It might look that multiple joins are something easy, but until this version, it was the major feature to be released. Now it is possible to do all the joins that you want, take a look at the code below:
EasyCriteria<Person> easyCriteria = EasyCriteriaFactory.createQueryCriteria(getEntityManager(), Person.class); easyCriteria.innerJoin("dogs.toys.manufacturer"); easyCriteria.andEquals("dogs.toys.manufacturer.name", "ACME"); easyCriteria.orderByDesc("dogs.toys.name");
Looking at the code above it is possible to see that it is possible to do “joins” for every method in the framework. Notice that the “andEquals” method is crossing all possible relationships in the entity Person.
The orderBy method also supports multiple joins.
This change will make the EasyCriteria API simpler, now it will not be necessary to call any method with Join in the name to create a “where”. The andJoinEquals method (or any other method with the word “Join” that creates a condition, e.g.: andJoinGreaterThan, andJoinStringIn), is deprecated and will be removed in future versions.
This method allows doing a count in the query result. Take a look at the code below:
EasyCriteria<Person> easyCriteria = EasyCriteriaFactory.createQueryCriteria(getEntityManager(), Person.class); System.out.println(easyCriteria.count());
The code above would count all Person found in the database. But, what about the complicated queries… would it do the count?
The query below would work without problems:
List<String> names = new ArrayList<String>(); names.add("John"); names.add("Mary"); EasyCriteria<Manufacturer> easyCriteria = EasyCriteriaFactory.createQueryCriteria(getEntityManager(), Manufacturer.class); easyCriteria.setDistinctTrue(); easyCriteria.innerJoin("products.sellers"); easyCriteria.andStringNotIn("products.sellers.name", names); easyCriteria.setFirstResult(0); easyCriteria.setMaxResults(50); System.out.println(easyCriteria.count()); List<Manufacturer> manufactures = easyCriteria.getResultList();
Notice in the code above that it is possible to do a count and with the same object execute the query.
One important thing to notice is that the count method ignores the values defined in the methods setFirstResult and setMaxResults. To do a count with firstResult and maxResults it would be necessary to do a SubQuery, and this is not supported yet.
100% of Coverage
This project still with 100% of coverage in the unit tests with OpenJPA, EclipseLink and Hibernate, JUnit and the Cobertura framework.
I hope that this tool will be really useful to you.
To use it with maven, just add to the pom:
<dependency> <groupId>uaihebert.com</groupId> <artifactId>EasyCriteria</artifactId> <version>3.0.0</version> </dependency>
To manually download it, click here: http://uaihebert.com/wp-content/uploads/EasyCriteria/EasyCriteria-3.0.0_2013-08-02.jar
See you later.