List of usage examples for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY
ResultTransformer DISTINCT_ROOT_ENTITY
To view the source code for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY.
Click Source Link
From source file:net.purnama.pureff.dao.WarehouseDao.java
public List<WarehouseEntity> getActiveWarehouseList() { Session session = this.sessionFactory.getCurrentSession(); Criteria c = session.createCriteria(WarehouseEntity.class); c.add(Restrictions.eq("status", true)); c.addOrder(Order.asc("code")); c.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return c.list(); }
From source file:net.purnama.pureff.dao.WarehouseDao.java
public List<WarehouseEntity> getWarehouseList() { Session session = this.sessionFactory.getCurrentSession(); Criteria c = session.createCriteria(WarehouseEntity.class); c.addOrder(Order.asc("code")); c.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return c.list(); }
From source file:net.purnama.pureff.dao.WarehouseDao.java
public List getWarehouseList(int itemperpage, int page, String sort, String keyword) { Session session = this.sessionFactory.getCurrentSession(); Criteria c = session.createCriteria(WarehouseEntity.class); Criterion code = Restrictions.like("code", "%" + keyword + "%"); Criterion desc = Restrictions.like("name", "%" + keyword + "%"); LogicalExpression orExp = Restrictions.or(code, desc); c.add(orExp);/*w w w. j a va 2s. com*/ if (sort.contains("-")) { c.addOrder(Order.desc(sort.substring(1))); } else { c.addOrder(Order.asc(sort)); } c.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); c.setFirstResult(itemperpage * (page - 1)); c.setMaxResults(itemperpage); return c.list(); }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateQuery.java
License:Apache License
@Override public List list() { if (criteria == null) throw new IllegalStateException("Cannot execute query using a detached criteria instance"); int projectionLength = 0; if (hibernateProjectionList != null) { org.hibernate.criterion.ProjectionList projectionList = hibernateProjectionList .getHibernateProjectionList(); projectionLength = projectionList.getLength(); criteria.setProjection(projectionList); }/* w ww .java 2s. c o m*/ if (projectionLength < 2) { criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); } applyFetchStrategies(); return criteria.list(); }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateQuery.java
License:Apache License
@Override public Object singleResult() { if (criteria == null) throw new IllegalStateException("Cannot execute query using a detached criteria instance"); if (hibernateProjectionList != null) { criteria.setProjection(hibernateProjectionList.getHibernateProjectionList()); }/*ww w .j a v a 2 s . c o m*/ criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); applyFetchStrategies(); return criteria.uniqueResult(); }
From source file:org.egov.bpa.masters.service.StakeHolderService.java
License:Open Source License
public Criteria buildSearchCriteria(final StakeHolder stakeHolder) { final Criteria criteria = getCurrentSession().createCriteria(StakeHolder.class, "stakeHolder"); if (stakeHolder.getName() != null) criteria.add(Restrictions.ilike("stakeHolder.name", stakeHolder.getName(), MatchMode.ANYWHERE)); if (stakeHolder.getAadhaarNumber() != null) criteria.add(Restrictions.ilike("stakeHolder.aadhaarNumber", stakeHolder.getAadhaarNumber(), MatchMode.ANYWHERE));//www .jav a 2 s. c o m if (stakeHolder.getPan() != null) criteria.add(Restrictions.ilike("stakeHolder.pan", stakeHolder.getPan(), MatchMode.ANYWHERE)); if (stakeHolder.getBusinessLicenceNumber() != null) criteria.add(Restrictions.ilike("stakeHolder.businessLicenceNumber", stakeHolder.getBusinessLicenceNumber(), MatchMode.ANYWHERE)); if (stakeHolder.getCoaEnrolmentNumber() != null) criteria.add(Restrictions.ilike("stakeHolder.coaEnrolmentNumber", stakeHolder.getCoaEnrolmentNumber(), MatchMode.ANYWHERE)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return criteria; }
From source file:org.egov.mrs.masters.service.MarriageRegistrationUnitService.java
License:Open Source License
@SuppressWarnings("unchecked") public List<MarriageRegistrationUnit> searchMarriageRegistrationUnit( final MarriageRegistrationUnit marriageRegistrationUnit) { final Criteria criteria = getCurrentSession().createCriteria(MarriageRegistrationUnit.class); if (null != marriageRegistrationUnit.getName()) criteria.add(Restrictions.ilike("name", marriageRegistrationUnit.getName(), MatchMode.ANYWHERE)); if (null != marriageRegistrationUnit.getAddress()) criteria.add(Restrictions.ilike("address", marriageRegistrationUnit.getAddress(), MatchMode.ANYWHERE)); if (null != marriageRegistrationUnit.getIsActive() && marriageRegistrationUnit.getIsActive()) criteria.add(Restrictions.eq("isActive", marriageRegistrationUnit.getIsActive())); if (null != marriageRegistrationUnit.getIsMainRegistrationUnit() && marriageRegistrationUnit.getIsMainRegistrationUnit()) criteria.add(Restrictions.eq("isMainRegistrationUnit", marriageRegistrationUnit.getIsMainRegistrationUnit())); if (marriageRegistrationUnit.getZone().getId() != null) criteria.add(Restrictions.eq("zone.id", marriageRegistrationUnit.getZone().getId())); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return criteria.list(); }
From source file:org.egov.pgr.service.ComplaintEscalationService.java
License:Open Source License
public List<Complaint> getComplaintsEligibleForEscalation() { Criteria criteria = entityManager.unwrap(Session.class).createCriteria(Complaint.class, "complaint") .createAlias("complaint.status", "complaintStatus"); criteria.add(Restrictions.disjunction().add(Restrictions.eq(COMPLAINT_STATUS_NAME, REOPENED.name())) .add(Restrictions.eq(COMPLAINT_STATUS_NAME, FORWARDED.name())) .add(Restrictions.eq(COMPLAINT_STATUS_NAME, PROCESSING.name())) .add(Restrictions.eq(COMPLAINT_STATUS_NAME, REGISTERED.name()))) .add(Restrictions.lt("complaint.escalationDate", new Date())) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return criteria.list(); }
From source file:org.egov.ptis.actions.reports.DailyCollectionReportAction.java
License:Open Source License
@SuppressWarnings("unchecked") @ValidationErrorPage("new") @Action(value = "/dialyCollectionReport-generateReport", results = { @Result(name = NEW, location = "/dialyCollectionReport-new.jsp") }) public String generateReport() { LOGGER.debug("Eneterd into generateReport method"); Long reportStartTime = System.currentTimeMillis(); Module module = moduleDao.getModuleByName(PropertyTaxConstants.PTMODULENAME); // UserDAO userDao = new UserDAO(); currInst = instalDao.getInsatllmentByModuleForGivenDate(module, new Date()).getDescription(); StringBuilder qryString = new StringBuilder("from org.egov.erpcollection.models.ReceiptHeader rh") .append(" left join fetch rh.receiptInstrument rcptInst") .append(" left join fetch rcptInst.instrumentType").append(" left join fetch rh.receiptDetails") .append(" left join fetch rh.receiptPayeeDetails").append(" left join fetch rh.receiptMisc") .append(" left join fetch rh.onlinePayment").append(" left join fetch rh.challan") .append(" where rh.manualreceiptnumber is null and rh.manualreceiptdate is null") .append(" and rh.status.description != 'Cancelled' and rh.service.serviceName = 'Property Tax'") .append(" and rh.createdBy.id = :userId").append(" and rh.createdDate >= :fromDate") .append(" and rh.createdDate <= :toDate").append(" order by rh.modifiedDate desc"); Calendar calendar = Calendar.getInstance(); calendar.setTime(toDate);/*from w w w . j av a 2s .c o m*/ calendar.add(Calendar.DATE, 1); Query qry = persistenceService.getSession().createQuery(qryString.toString()) .setParameter("fromDate", fromDate).setParameter("toDate", calendar.getTime()) .setParameter("userId", Integer.valueOf(userId)) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Long qryStartTime = System.currentTimeMillis(); List<ReceiptHeader> rcptHeaderList = qry.list(); LOGGER.debug("Main Query took " + (System.currentTimeMillis() - qryStartTime) / 1000 + "sec(s)..!"); LOGGER.debug("Number of records: " + rcptHeaderList.size()); if (rcptHeaderList != null && !rcptHeaderList.isEmpty()) { Long loopStartTime = System.currentTimeMillis(); List<ReceiptInfo> rcptInfoList = new ArrayList<ReceiptInfo>(); CollectionInfo cashCollInfo = new CollectionInfo(); initializeTotalsInfo(); for (ReceiptHeader rcptHeader : rcptHeaderList) { ReceiptInfo rcptInfo = new ReceiptInfo(); rcptInfo.setReceiptNo(rcptHeader.getReceiptnumber()); String indexNo = org.apache.commons.lang.StringUtils.trim(rcptHeader.getConsumerCode().contains("(") ? rcptHeader.getConsumerCode().substring(0, rcptHeader.getConsumerCode().indexOf('(')) : rcptHeader.getConsumerCode()); rcptInfo.setIndexNo(indexNo); rcptInfo.setWardNo( rcptHeader.getConsumerCode().substring(rcptHeader.getConsumerCode().lastIndexOf(":") + 1, rcptHeader.getConsumerCode().indexOf(")"))); // FIX ME rcptHeader.getReceiptPayeeDetails() is not available // in collection // rcptInfo.setHouseNo(rcptHeader.getReceiptPayeeDetails().getPayeeAddress().split(",")[0]); StringBuffer payMode = new StringBuffer(); Set<String> paymentModes = new HashSet<String>(); StringBuffer instrumentDetails = new StringBuffer(); int i = 1, j = 1; for (InstrumentHeader instrumentHead : rcptHeader.getReceiptInstrument()) { if (i > 1) { instrumentDetails.append("|| "); } if (instrumentHead.getInstrumentNumber() != null) { instrumentDetails.append(instrumentHead.getInstrumentNumber()).append(", ") .append(instrumentHead.getInstrumentDate() != null ? dateFormat.format(instrumentHead.getInstrumentDate()) : " ") .append(", ") .append(instrumentHead.getBankId() != null ? instrumentHead.getBankId().getName() : " "); } paymentModes.add(instrumentHead.getInstrumentType().getType()); i++; } for (String paymentMode : paymentModes) { if (j > 1) { payMode.append(", "); } payMode.append(paymentMode); j++; } rcptInfo.setInstrumentDetails(instrumentDetails.toString()); rcptInfo.setPaymentMode(payMode.toString()); rcptInfo.setPayeeName(rcptHeader.getPaidBy()); rcptInfo.setCollInfoList(getCollectionInfoList(rcptHeader)); rcptInfoList.add(rcptInfo); } List<TaxCollectionInfo> cashTotalsList = new ArrayList<TaxCollectionInfo>(); cashTotalsList.add(currTotalCashCollInfo); cashTotalsList.add(arrTotalCashCollInfo); cashTotalsList.add(rebateTotalCashCollInfo); totalCashRcptInfo.setCollInfoList(cashTotalsList); totalCashRcptInfo.setReceiptNo(TOTAL_BY_CASH); List<TaxCollectionInfo> chequeTotalsList = new ArrayList<TaxCollectionInfo>(); chequeTotalsList.add(currTotalChequeCollInfo); chequeTotalsList.add(arrTotalChequeCollInfo); chequeTotalsList.add(rebateTotalChequeCollInfo); totalChequeRcptInfo.setCollInfoList(chequeTotalsList); totalChequeRcptInfo.setReceiptNo(TOTAL_BY_CHEQUE); List<TaxCollectionInfo> totalsList = new ArrayList<TaxCollectionInfo>(); totalsList.add(currTotalCollInfo); totalsList.add(arrTotalCollInfo); totalsList.add(rebateTotalCollInfo); totalRcptInfo.setCollInfoList(totalsList); totalRcptInfo.setReceiptNo(TOTAL); rcptInfoList.add(totalCashRcptInfo); rcptInfoList.add(totalChequeRcptInfo); rcptInfoList.add(totalRcptInfo); cashCollInfo.setCollByCash(totalCashCollAmt); cashCollInfo.setCollByCheque(totalChequeCollAmt); cashCollInfo.setOtherColl(totalOthersCollAmt); cashCollInfo.setEduEgsArrColl(arrTotalCollInfo.getEduCess().add(arrTotalCollInfo.getEgsCess())); cashCollInfo.setEduEgsCurrColl(currTotalCollInfo.getEduCess().add(currTotalCollInfo.getEgsCess())); cashCollInfo.setTotalArrColl(arrTotalCollInfo.getTotal()); cashCollInfo.setTotalCurrColl(currTotalCollInfo.getTotal().subtract(rebateTotalCollInfo.getTotal())); cashCollInfo.setGrandTotal(arrTotalCollInfo.getTotal().add(currTotalCollInfo.getTotal()) .subtract(rebateTotalCollInfo.getTotal())); cashCollInfo.setRcptInfoList(rcptInfoList); User user = userService.getUserById(Long.valueOf(userId)); cashCollInfo.setOperator(user.getUsername()); LOGGER.debug("Loop took " + (System.currentTimeMillis() - loopStartTime) / 1000 + " sec(s)..!"); ReportRequest reportInput = new ReportRequest(REPORT_TEMPLATENAME_DAILY_COLLECTION, cashCollInfo, null); reportInput.setPrintDialogOnOpenReport(true); reportId = reportViewerUtil.addReportToTempCache(reportService.createReport(reportInput)); LOGGER.debug("Report took " + (System.currentTimeMillis() - reportStartTime) / 1000 + " sec(s)..!"); LOGGER.debug("Exited from generateReport method(if block)"); return REPORT; } else { searchForm = Boolean.FALSE; LOGGER.debug("Exited from generateReport method(else block)"); return NEW; } }
From source file:org.egov.ptis.domain.dao.property.BoundaryCategoryHibDao.java
License:Open Source License
@Override public BoundaryCategory getBoundaryCategoryByBoundaryAndCategory(Criterion criterion) { Criteria criteria = getCurrentSession().createCriteria(BoundaryCategory.class); BoundaryCategory boundaryCategory = null; if (criterion != null) { Criterion dateCondn1 = Restrictions.and(Restrictions.le("fromDate", new Date()), Restrictions.isNull("toDate")); Criterion dateCondn2 = Restrictions.and(Restrictions.le("fromDate", new Date()), Restrictions.ge("toDate", new Date())); Criterion dateCondn = Restrictions.or(dateCondn1, dateCondn2); criteria.add(criterion);/*ww w . j av a 2s .co m*/ criteria.add(dateCondn); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); boundaryCategory = (BoundaryCategory) criteria.uniqueResult(); } return boundaryCategory; }