コード例 #1
0
  @Override
  public int removeAll(Filter clause) {
    logger.debug("invoke removeAll on " + type.getSimpleName());

    Session session = getSession();
    FilterToHibernateClauseTranslator translator = new FilterToHibernateClauseTranslator();
    String hql =
        translator.translateToHQLDelete(clause, getSessionFactory().getClassMetadata(type));
    logger.debug("hql = " + hql);
    return session.createQuery(hql).executeUpdate();
  }
コード例 #2
0
 @Override
 public long count(Filter clause) {
   if (clause == null) clause = Filter.getNewEmptyFilter();
   Session session = getSession();
   FilterToHibernateClauseTranslator translator = new FilterToHibernateClauseTranslator();
   String hql = translator.translateToHQLCount(clause, getSessionFactory().getClassMetadata(type));
   logger.debug("hql = " + hql);
   if (translator.getValues().isEmpty())
     return ((Long) session.createQuery(hql).uniqueResult()).longValue();
   else {
     Query query = session.createQuery(hql);
     int pos = 0;
     for (Object value : translator.getValues()) {
       query.setParameter(pos++, value);
     }
     return ((Long) query.uniqueResult()).longValue();
   }
 }
コード例 #3
0
  /* (non-Javadoc)
   * @see fr.certu.chouette.dao.IDaoTemplate#select(fr.certu.chouette.filter.Filter)
   */
  @SuppressWarnings("unchecked")
  public List<T> select(final Filter filter) {
    logger.debug("invoke select on " + type.getSimpleName());

    Session session = getSession();

    Criteria criteria = session.createCriteria(type);

    // DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    if (!filter.isEmpty()) {
      FilterToHibernateClauseTranslator translator = new FilterToHibernateClauseTranslator();
      criteria.add(
          translator.translate(filter, criteria, getSessionFactory().getClassMetadata(type)));
    }
    if (filter.getOrderList() != null) {
      for (FilterOrder order : filter.getOrderList()) {
        switch (order.getType()) {
          case ASC:
            criteria.addOrder(Order.asc(order.getAttribute()));
            break;
          case DESC:
            criteria.addOrder(Order.desc(order.getAttribute()));
            break;

          default:
            break;
        }
      }
    }
    // HibernateTemplate ht = getHibernateTemplate();
    List<T> beans = null;
    if (filter.getLimit() > 0 || filter.getStart() > 0) {
      logger.debug("call with start and/or limit");
      criteria.setFirstResult(filter.getStart());
      criteria.setMaxResults(filter.getLimit());
      beans = criteria.list(); // ht.findByCriteria(criteria,filter.getStart(),filter.getLimit());
    } else {
      beans = criteria.list(); // ht.findByCriteria(criteria);
    }
    logger.debug(type.getSimpleName() + " founds = " + beans.size());

    return beans;
  }