}
public SearchResult getAllUserByRange(String search, int start, int max,
String orderby, boolean asc) {
try {
SearchResult sresult = new SearchResult();
sresult.setObjectName(Users.class.getName());
sresult.setRecords(UsersDaoImpl.getInstance().getAllUserMax(search));
String[] searchItems = search.split(" ");
log.debug("getUserContactsBySearch: " + search);
// log.debug("getUserContactsBySearch: "+ userId);
String hql = "select u from Users u "
+ "WHERE u.deleted = 'false' ";
hql += "AND ( ";
for (int i = 0; i < searchItems.length; i++) {
if (i != 0) {
hql += " OR ";
}
hql += "( " + "lower(u.lastname) LIKE '"
+ StringUtils.lowerCase("%" + searchItems[i] + "%")
+ "' " + "OR lower(u.firstname) LIKE '"
+ StringUtils.lowerCase("%" + searchItems[i] + "%")
+ "' " + "OR lower(u.login) LIKE '"
+ StringUtils.lowerCase("%" + searchItems[i] + "%")
+ "' " + "OR lower(u.adresses.email) LIKE '"
+ StringUtils.lowerCase("%" + searchItems[i] + "%")
+ "' " + ") ";
}
hql += " ) ";
if (orderby != null && orderby.length() > 0) {
hql += "ORDER BY " + orderby;
}
if (asc) {
hql += " ASC ";
} else {
hql += " DESC ";
}
log.debug("Show HQL: " + hql);
Object idf = PersistenceSessionUtil.createSession();
EntityManager session = PersistenceSessionUtil.getSession();
EntityTransaction tx = session.getTransaction();
tx.begin();
Query query = session.createQuery(hql);
// query.setParameter("macomUserId", userId);
// query
// if (asc) ((Criteria) query).addOrder(Order.asc(orderby));
// else ((Criteria) query).addOrder(Order.desc(orderby));
query.setFirstResult(start);
query.setMaxResults(max);
List<Users> ll = query.getResultList();
tx.commit();
PersistenceSessionUtil.closeSession(idf);
sresult.setResult(ll);
return sresult;
} catch (Exception ex2) {
log.error("[getAllUserByRange] ", ex2);