@Override
public List<UserData> findUsersByAttribute(final String key, final String... values) {
return withContext(new ReturningProcessToolContextCallback<List<UserData>>() {
@Override
public List<UserData> processWithContext(ProcessToolContext ctx) {
UserDataDAO dao = ctx.getUserDataDAO();
DetachedCriteria criteria = dao.getDetachedCriteria()
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
.addOrder(Order.asc("login"))
.createCriteria("attributes")
.add(Restrictions.eq("key", key));
if(values.length == 1)
criteria.add(Restrictions.eq("value", values[0]));
else
criteria.add(Restrictions.in("value", values));
return dao.findByCriteria(criteria);
}
});
}