public Long getResults() {
   return (Long)
       getSession()
           .createCriteria(persistentClass)
           .setProjection(Projections.count("id"))
           .uniqueResult();
 }
Example #2
0
 @Override
 @Transactional(readOnly = true)
 public Integer countTotal() {
   Criteria crit = createCriteria();
   crit.setProjection(Projections.count("rid"));
   return ((Number) crit.list().get(0)).intValue();
 }
  public int getUserDetailsCountBySessionId(String searchq, Long sessionPK) {
    Session session = getSession();
    session.getTransaction().begin();

    int totalRowCount = 0;
    Criteria criteria = session.createCriteria(BrowserDetails.class, "browserDetails");
    criteria.createAlias("browserDetails.sessionDetails", "sessionDetails");
    criteria.createAlias("browserDetails.deviceDetails", "deviceDetails");
    criteria.createAlias("browserDetails.eventDetails", "eventDetails");
    criteria.add(Restrictions.eq("sessionDetails.SID", sessionPK));
    criteria.setProjection(Projections.count("eventDetails.EID"));

    if (!searchq.isEmpty()) {
      criteria.add(
          Restrictions.disjunction()
              .add(Restrictions.ilike("deviceDetails.deviceName", searchq, MatchMode.ANYWHERE))
              .add(Restrictions.ilike("browserName", searchq, MatchMode.ANYWHERE))
              .add(Restrictions.ilike("eventDetails.eventName", searchq, MatchMode.ANYWHERE))
              .add(Restrictions.ilike("eventDetails.orientation", searchq, MatchMode.ANYWHERE)));
    }

    Long value = (Long) criteria.uniqueResult();
    totalRowCount = Integer.valueOf(value.intValue());

    session.getTransaction().commit();
    session.close();

    return totalRowCount;
  }
Example #4
0
  public TicketSummary getClosedTicketSummary(Terminal terminal) {

    Session session = null;
    TicketSummary ticketSummary = new TicketSummary();
    try {
      session = getSession();
      Criteria criteria = session.createCriteria(Ticket.class);
      criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.TRUE));
      criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE));
      criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE));
      criteria.add(Restrictions.eq(Ticket.PROP_DRAWER_RESETTED, Boolean.FALSE));
      criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal));

      ProjectionList projectionList = Projections.projectionList();
      projectionList.add(Projections.count(Ticket.PROP_ID));
      projectionList.add(Projections.sum(Ticket.PROP_TOTAL_AMOUNT));
      criteria.setProjection(projectionList);

      List list = criteria.list();
      if (list.size() > 0) {
        Object[] o = (Object[]) list.get(0);
        ticketSummary.setTotalTicket(((Integer) o[0]).intValue());
        ticketSummary.setTotalPrice(o[1] == null ? 0 : ((Double) o[1]).doubleValue());
      }
      return ticketSummary;
    } finally {
      closeSession(session);
    }
  }
  @Override
  @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
  public Long countConsoleInfos() {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConsoleInfo.class);
    criteria.setProjection(Projections.count("id"));

    return (Long) criteria.uniqueResult();
  }
 /**
  * 通过指定的起始数获取总集合
  *
  * @return 集合总数
  */
 @SuppressWarnings("unchecked")
 public int getTotal() {
   Criteria query = this.getSession().createCriteria(FinalEvaluationInfo.class);
   query.setProjection(Projections.count("finalEvaluationID"));
   query.setMaxResults(1);
   List list = query.list();
   int result = 0;
   if (list.size() > 0) {
     result = (Integer) list.get(0);
   }
   return result;
 }
Example #7
0
  public Integer getCountUserValidate(String staffPiority) {
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.add(Restrictions.eq("validateStu", 0));
    criteria.add(Restrictions.like("piority", "%" + staffPiority + "%"));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.count("validateStu"));
    criteria.setProjection(projectionList);

    Integer count = (Integer) criteria.uniqueResult();
    closeSession();
    return count;
  }
Example #8
0
 public int getUnservedOdlist() {
   Session session = sf.openSession();
   int result =
       ((Number)
               session
                   .createCriteria(BdyOrderlist.class)
                   .add(Restrictions.eq("olState", 0))
                   .setProjection(Projections.count("odlistId"))
                   .uniqueResult())
           .intValue();
   session.close();
   return result;
 }
Example #9
0
 @Transactional(readOnly = true)
 @Override
 public boolean contains(String id, String password) {
   Long count =
       (Long)
           currentSession()
               .createCriteria(clazz)
               .setProjection(Projections.count("id"))
               .add(Restrictions.eq("id", id))
               .add(Restrictions.eq("password", password))
               .setMaxResults(1)
               .uniqueResult();
   return count > 0;
 }
Example #10
0
  @Override
  public int obtenhaQuantidadePorUF(UF estado) {

    Criteria c = getSession().createCriteria(Cliente.class);

    c.createAlias("enderecoPrimario", "endp");
    c.createAlias("enderecoSecundario", "ends");
    Disjunction d = Restrictions.disjunction();
    d.add(Restrictions.eq("endp.uf", estado.getSigla()));
    d.add(Restrictions.eq("ends.uf", estado.getSigla()));
    c.setProjection(Projections.count("codigo"));
    c.add(d);

    return (int) c.uniqueResult();
  }
  public int getCurrentUserCount(String searchq) throws Exception {
    Session session = getSession();
    session.getTransaction().begin();

    int totalRowCount = 0;
    Criteria criteria = session.createCriteria(SessionDetails.class);
    criteria.add(Restrictions.eq("status", "ACTIVE")).setProjection(Projections.count("SID"));
    ;

    Long value = (Long) criteria.uniqueResult();
    totalRowCount = Integer.valueOf(value.intValue());

    session.getTransaction().commit();
    session.close();

    return totalRowCount;
  }
 @Transactional
 public Map<OandaAccount, Long> transactionsCountByAccount() {
   final String property = "account";
   Criteria criteria =
       getSession()
           .createCriteria(OandaTransaction.class)
           .setProjection(
               Projections.projectionList()
                   .add(Projections.groupProperty(property))
                   .add(Projections.count(property)));
   @SuppressWarnings("rawtypes")
   List results = criteria.list();
   Map<OandaAccount, Long> accountCountMap = Maps.newLinkedHashMap();
   for (Object row : results) {
     Object[] rowData = (Object[]) row;
     accountCountMap.put((OandaAccount) rowData[0], (Long) rowData[1]);
   }
   return accountCountMap;
 }
  @Override
  public Projection buildProjection(
      String projectionField, ProjectionType projectionType, Iterator argsIterator) {
    Projection projection = new Projection();

    projection.setField(projectionField);

    switch (projectionType) {
      case RowCount:
        projection.setDetails(Projections.rowCount());
        break;

      case Count:
        projection.setDetails(Projections.count(projectionField));
        break;

      case CountDistinct:
        projection.setDetails(Projections.countDistinct(projectionField));
        break;

      case Maximum:
        projection.setDetails(Projections.max(projectionField));
        break;

      case Minimum:
        projection.setDetails(Projections.min(projectionField));
        break;

      case Average:
        projection.setDetails(Projections.avg(projectionField));
        break;

      case Sum:
        projection.setDetails(Projections.sum(projectionField));
        break;

      default:
        throw new RuntimeException("Unexpected projection type: " + projectionType);
    }

    return projection;
  }
Example #14
0
  public static long countChildOrgs(Organisation organisation, Session session) {
    Criteria crit = session.createCriteria(Organisation.class);
    crit.setCacheable(true);
    Disjunction notDeleted = Restrictions.disjunction();
    notDeleted.add(Restrictions.isNull("deleted"));
    notDeleted.add(Restrictions.eq("deleted", Boolean.FALSE));
    crit.add(notDeleted);
    crit.add(Restrictions.ne("id", organisation.getId()));

    Criteria critParentLink = crit.createCriteria("parentOrgLinks");
    critParentLink.add(Restrictions.eq("owner", organisation));
    crit.setProjection(Projections.count("id"));
    Object result = crit.uniqueResult();
    if (result == null) {
      return 0;
    } else if (result instanceof Integer) {
      Integer i = (Integer) result;
      return i.longValue();
    } else {
      return (long) result;
    }
  }