Esempio n. 1
0
  // TODO clean this up
  private Query buildFindQuery(final QueryParam qp, final Change filter, final boolean count) {
    final StringBuilder hql = new StringBuilder();
    if (count) {
      hql.append("select count(*) ");
    }
    hql.append(" from Change target where 1=1 ");
    if (filter.getId() != null) {
      hql.append("and target id like :id ");
    }
    if (filter.getMessage() != null) {
      hql.append("and upper(target.message) like :message ");
    }
    if (filter.getChangeDate() != null) {
      hql.append("and target.changeDate like :date ");
    }
    if (!count && qp != null && qp.hasSort()) {
      hql.append("order by upper(target.")
          .append(qp.getSort())
          .append(") ")
          .append(qp.isSortAsc() ? " asc" : " desc");
    }

    final Query query = getEntityManager().createQuery(hql.toString());
    if (filter.getId() != null) {
      query.setParameter("id", "%" + filter.getId() + "%");
    }
    if (filter.getMessage() != null) {
      query.setParameter("message", "%" + filter.getMessage().toUpperCase() + "%");
    }
    if (filter.getChangeDate() != null) {
      query.setParameter("date", "%" + filter.getChangeDate() + "%");
    }
    if (!count && qp != null) {
      query.setFirstResult(qp.getFirst()).setMaxResults(qp.getCount());
    }
    return query;
  }
Esempio n. 2
0
 public void logChange(final String message) {
   final Change change = new Change();
   change.setMessage(message);
   change.setChangeDate(new Date());
   save(change);
 }