List of usage examples for org.hibernate.criterion Projections rowCount
public static Projection rowCount()
From source file:com.ignou.aadhar.dao.hibernate.TransactionDaoHibernate.java
License:Open Source License
/** * Gets the records from the Database based on the parameters provided. * @param searchField The field name on which the search is to be made. * @param searchValue Value which needs to be searched. * @param pageNumber Initial offset of the records. * @param recordsPerPage Total number of records which are selected for * resultset.// w ww .j a v a 2s . com * @param sortField Name of the field on which the data needs to be sorted. * @param sortOrder Order in which the sortField is sorted. * @return Returns the records as list of map where each map stores the * record data as key-value pairs. */ @Override @Transactional public List<Map<String, Object>> getTransactions(String searchField, String searchValue, Integer pageNumber, Integer recordsPerPage, String sortField, String sortOrder) { List<Transaction> records = null; List<Map<String, Object>> returnRecords = new ArrayList<Map<String, Object>>(); Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Transaction.class); /* Add the search parameters to the criteria */ if (searchField != null && !searchField.isEmpty() && searchValue != null && !searchValue.isEmpty()) { /* Prefix and suffix the searchValue with % */ searchValue = "%" + searchValue + "%"; /* Set the matching field accordingly */ if ("uid".equals(searchField)) { criteria.add(Restrictions.ilike("citizen.uid", searchValue)); } else if ("serviceprovider".equals(searchField)) { criteria.add(Restrictions.ilike("serviceProvider.name", searchValue)); } else if ("clientTxnId".equals(searchField)) { criteria.add(Restrictions.ilike("spTransactionId", searchValue)); } else if ("bankTxnId".equals(searchField)) { criteria.add(Restrictions.ilike("bankTransactionId", searchValue)); } else if ("status".equals(searchField)) { criteria.add(Restrictions.ilike("status", searchValue)); } } /* Let's first get the total number of records that satisfy the provided * parameters. */ String totalCount = (String) criteria.setProjection(Projections.rowCount()).uniqueResult().toString(); /* Reset the Criteria specification to remove the projection details */ criteria.setProjection(null); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); /* Set the default sort field if not provided */ if (sortField != null && !sortField.isEmpty()) { /* Check what order was provided for this field */ if ("asc".equals(sortOrder)) { /* Sort in ascending order */ criteria.addOrder(Order.asc(sortField)); } else if ("desc".equals(sortOrder)) { /* Sort in descending order */ criteria.addOrder(Order.desc(sortField)); } else { /* Default sort behaviour other wise */ criteria.addOrder(Order.asc(sortField)); } } /* Set the record filtering on pageCount and recordsPerPage if they are * available. */ if (pageNumber != null && recordsPerPage != null) { records = criteria.setFirstResult(pageNumber).setMaxResults(recordsPerPage).list(); } else { records = criteria.list(); } /* Format the Date */ SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy h:m:s a"); /* Format this data before sending back for any other further usage */ for (Transaction transaction : records) { /* Create new map for current transaction and add it to * master list */ Map<String, Object> returnMap = new LinkedHashMap<String, Object>(); returnMap.put("id", transaction.getId()); returnMap.put("uid", transaction.getCitizen().getUid()); returnMap.put("name", transaction.getCitizen().getName()); returnMap.put("serviceprovider", transaction.getServiceProvider().getName()); returnMap.put("clientTxnId", transaction.getSpTransactionId()); returnMap.put("bankTxnId", transaction.getBankTransactionId()); returnMap.put("status", transaction.getStatus()); returnMap.put("created", format.format(transaction.getCreated())); returnMap.put("amount", transaction.getAmount()); returnMap.put("totalCount", totalCount); returnRecords.add(returnMap); } return returnRecords; }
From source file:com.indicator_engine.dao.GLACategoryDaoImpl.java
License:Open Source License
/** * Returns the Total count of Category Items from Database. * @return Total count of Category Items from Database. *///from www . j av a 2 s . com @Override @Transactional(readOnly = true) public int getTotalCategories() { Session session = factory.getCurrentSession(); return ((Number) session.createCriteria(GLACategory.class).setProjection(Projections.rowCount()) .uniqueResult()).intValue(); }
From source file:com.indicator_engine.dao.GLAEntityDaoImpl.java
License:Open Source License
/** * Returns the Total Number of GLA Entity Objects present in the Database. * @return Total Number of GLA Entity Objects present in the Database. **//*from w w w . j av a2 s . c o m*/ @Override @Transactional(readOnly = true) public int getTotalEntities() { Session session = factory.getCurrentSession(); return ((Number) session.createCriteria(GLAEntity.class).setProjection(Projections.rowCount()) .uniqueResult()).intValue(); }
From source file:com.indicator_engine.dao.GLAEventDaoImpl.java
License:Open Source License
/** * Adds a new GLA Entity Object to the Database. * @param glaEntity New GLA Entity Object to be saved. * @return ID of the Newly Created GLA Entity object in DB. **///from w w w . ja va 2 s .c om @Override @Transactional(readOnly = true) public int getTotalEvents() { Session session = factory.getCurrentSession(); return ((Number) session.createCriteria(GLAEvent.class).setProjection(Projections.rowCount()) .uniqueResult()).intValue(); }
From source file:com.indicator_engine.dao.GLAIndicatorDaoImpl.java
License:Open Source License
/** * Counts the total number of Indicators present in the Database. * @return/*from w ww . j a v a 2 s . c om*/ * Total count of Indicators */ @Override @Transactional public int getTotalIndicators() { Session session = factory.getCurrentSession(); return ((Number) session.createCriteria(GLAIndicator.class).setProjection(Projections.rowCount()) .uniqueResult()).intValue(); }
From source file:com.indicator_engine.dao.GLAOperationsDaoImpl.java
License:Open Source License
@Override @Transactional/*w w w . j ava 2 s .c o m*/ public int getTotalOperations() { Session session = factory.getCurrentSession(); return ((Number) session.createCriteria(GLAOperations.class).setProjection(Projections.rowCount()) .uniqueResult()).intValue(); }
From source file:com.indicator_engine.dao.GLAQuestionDaoImpl.java
License:Open Source License
/** * Counts the total number of Questions present in the Database. * @return/*from ww w .j a v a 2 s . co m*/ * Total count of Questions */ @Override @Transactional public int getTotalQuestions() { Session session = factory.getCurrentSession(); return ((Number) session.createCriteria(GLAQuestion.class).setProjection(Projections.rowCount()) .uniqueResult()).intValue(); }
From source file:com.indicator_engine.dao.GLAUserDaoImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)/*from ww w . j a v a 2 s .c o m*/ public int getTotalUsers() { Session session = factory.getCurrentSession(); return ((Number) session.createCriteria(GLAUser.class).setProjection(Projections.rowCount()).uniqueResult()) .intValue(); }
From source file:com.inet.mail.business.sr.MailHeaderSLBean.java
License:Open Source License
/** * Count the list of mail header from the given criteria. * //from w w w . j a v a2 s . c o m * @param criteria MailHeader - the given mail header. * @return the number of header information. */ @TransactionAttribute(TransactionAttributeType.SUPPORTS) private int count(MailHeader criteria) throws EJBException { // create criteria. Criteria query = this.getCriteria(MailHeader.class); if (criteria == null) { throw new EJBException("The search criteria is not validate !"); } // set projection. query.setProjection(Projections.rowCount()); if (criteria != null) { // search for user. query.add(Property.forName("owner").eq(criteria.getOwner())); if (criteria.getFolder() != null) { // add folder identifier. query.add(Property.forName("folder.id").eq(criteria.getFolder().getId())); } // search on subject. if (StringService.hasLength(criteria.getSubject())) { query.add(Property.forName("subject").like(criteria.getSubject(), MatchMode.ANYWHERE)); } // search on sender. if (StringService.hasLength(criteria.getSender())) { query.add(Property.forName("sender").like(criteria.getSender(), MatchMode.ANYWHERE)); } // search on received. if (criteria.getReceived() != null) { query.add(Property.forName("received").ge(criteria.getReceived())); } // search on sent. if (criteria.getSent() != null) { query.add(Property.forName("sent").ge(criteria.getSent())); } } // count the result. return this.count(query); }
From source file:com.inet.mail.business.sr.MailHeaderSLBean.java
License:Open Source License
/** * Count the list of mail header from the given criteria. * //from w w w . j a va 2 s. co m * @param criteria the given mail header. * @return the number of header information. */ @TransactionAttribute(TransactionAttributeType.SUPPORTS) private int count(String criteria) throws EJBException { if (criteria == null) { throw new EJBException("The search criteria is not validate !"); } // create criteria. Criteria query = this.getCriteria(MailHeader.class); // set projection. query.setProjection(Projections.rowCount()); // build the query. query.add(Restrictions.and( Restrictions.or(Property.forName("subject").like(criteria, MatchMode.ANYWHERE).ignoreCase(), Property.forName("sender").like(criteria, MatchMode.ANYWHERE).ignoreCase()), Property.forName("owner").eq(getUserCode()))); // count the result. return count(query); }