Is there anything inherently wrong with the below code? I'm giving the consumer of the method the ability to pass "%" within the argument so they can use a like statement for the query. Example findContact(company, "Joe%") or findContact(company, "Joe Smith")
Code:
public List<Contact> findContact(Company company, String name) {
return query("FROM Contact c WHERE c.company = :company AND c.name " + likeOrEqual(name) + " :name").
setParameter("company", company).
setParameter("name", name).
list();
}
private String likeOrEqual(String ref) {
return ((ref.startsWith("%") || ref.endsWith("%")) ? "LIKE" : "=");
}