BAEL-4852: Add IN example (#10568)
Co-authored-by: Krzysztof Woyke <krzysztof.woyke.sp@lhsystems.com>
This commit is contained in:
parent
dd288575da
commit
a0a766c123
|
@ -162,6 +162,25 @@ public class ApplicationView {
|
|||
return betweenItems;
|
||||
}
|
||||
|
||||
// To get records having itemName in 'Skate Board', 'Paint' and 'Glue'
|
||||
public String[] inCriteria() {
|
||||
final Session session = HibernateUtil.getHibernateSession();
|
||||
final CriteriaBuilder cb = session.getCriteriaBuilder();
|
||||
final CriteriaQuery<Item> cr = cb.createQuery(Item.class);
|
||||
final Root<Item> root = cr.from(Item.class);
|
||||
cr.select(root)
|
||||
.where(root.get("itemName").in("Skate Board", "Paint", "Glue"));
|
||||
Query<Item> query = session.createQuery(cr);
|
||||
final List<Item> inItemsList = query.getResultList();
|
||||
final String inItems[] = new String[inItemsList.size()];
|
||||
for (int i = 0; i < inItemsList.size(); i++) {
|
||||
inItems[i] = inItemsList.get(i)
|
||||
.getItemName();
|
||||
}
|
||||
session.close();
|
||||
return inItems;
|
||||
}
|
||||
|
||||
// To check if the given property is null
|
||||
public String[] nullCriteria() {
|
||||
final Session session = HibernateUtil.getHibernateSession();
|
||||
|
|
|
@ -189,6 +189,18 @@ public class HibernateCriteriaIntegrationTest {
|
|||
assertArrayEquals(expectedPriceBetweenItems, av.betweenCriteria());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inCriteriaQuery() {
|
||||
final Session session = HibernateUtil.getHibernateSession();
|
||||
final List<Item> expectedInList = session.createQuery("From Item where itemName in ('Skate Board', 'Paint', 'Glue')").list();
|
||||
final String expectedNameInItems[] = new String[expectedInList.size()];
|
||||
for (int i = 0; i < expectedInList.size(); i++) {
|
||||
expectedNameInItems[i] = expectedInList.get(i).getItemName();
|
||||
}
|
||||
session.close();
|
||||
assertArrayEquals(expectedNameInItems, av.inCriteria());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNewItemPrice_whenCriteriaUpdate_thenReturnAffectedResult() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue