⚠️ This repository is archived. It is no longer actively developed, but it remains fully functional and can still be used in your projects. Feel free to fork the repository if you'd like to continue its development or adapt it to your needs.
If you want to participate on the development please perform the pull request to the develop branch.
Documentation is available on http://nativecriteria.przemeknowak.com/
<!-- core module -->
<dependency>
<groupId>com.github.pnowy.nc</groupId>
<artifactId>nativeCriteria-core</artifactId>
<version>3.2.0</version>
</dependency>
<!-- spring integration module -->
<dependency>
<groupId>com.github.pnowy.nc</groupId>
<artifactId>nativeCriteria-spring</artifactId>
<version>3.2.0</version>
</dependency>// SELECT a.city FROM address a WHERE a.zip_code IS NULL AND city := ? ORDER BY a.city ASC
NativeCriteria nc = new NativeCriteria(new JpaQueryProvider(entityManager), "address", "a")
.setProjection(NativeExps.projection().addProjection("a.city"))
.add(NativeExps.isNull("a.zip_code"));
.setOrder(NativeExps.order().add("a.city", OrderType.ASC));
// dynamic where part
if (StringUtils.isNotEmpty(city)) {
nc.add(NativeExps.eq("a.city", city))
}
// get the results
CriteriaResult res = c.criteriaResult();
List<String> cityNames = new ArrayList<>();
while (res.next()) {
resp.add(res.getString("a.city"));
}