If I understood you correctly, you'd like to validate a login by checking both the email
and the password
fields. I'm not sure why you need a JPAContainer instead of a simple CriteriaQuery, but here's the answer to your question (off the top of my head):
JPAContainer<Person> container =
JPAContainerFactory.<Person>makeReadOnly(Person.class, entityManager);
container.addContainerFilter(new Compare.Equal("email", emailInput));
container.addContainerFilter(new Compare.Equal("password", passwordInput));
// Query container size, eg
if(container.size()==1) { ... }
If you add multiple container filters in this manner, they will implicitly be understood as the intersection thereof, ie. AND.
If you want the union of filter, ie. OR, you'll have to build it yourself as such (if that makes any sense is at your discretion):
Filter filter = new Compare.OR(new Compare.Equal("email", emailInput), new Compare.Equal("password", passwordInput));
container.addContainerFilter(filter);
However, I'll repeat that using a plain CriteriaQuery may be more appropriate.
Moreover —and don't take this lightly— from your Person
entity, I infer that you're storing the passwords in clear in the database which is a big no-no, and
- can put your users at risk if the database is compromised, and
- could be a rough blow to your own reputation if your code is audited/reviewed.
EDIT:
With CriteriaQuery, you could something like:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> q = qb.createQuery(Long.class);
Root<Person> root = q.from(Person.class);
Path<String> email = root.get("email");
Path<String> password = root.get("password");
cq.select(cb.count(root)).where(
cb.and(
cb.equal(email, emailInput),
cb.equal(password, passwordInput)
)
);
return entityManager.createQuery(cq).getSingleResult();
Replace cb.and(...)
with cb.or(...)
if you so wish. HTH.