Example usage for org.hibernate.criterion Restrictions ne

List of usage examples for org.hibernate.criterion Restrictions ne

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions ne.

Prototype

public static SimpleExpression ne(String propertyName, Object value) 

Source Link

Document

Apply a "not equal" constraint to the named property

Usage

From source file:org.egov.council.service.CouncilPreambleService.java

License:Open Source License

@SuppressWarnings({ "unchecked", "deprecation" })
public List<CouncilPreamble> searchFinalizedPreamble(CouncilPreamble councilPreamble) {
    final Criteria criteria = buildSearchCriteria(councilPreamble);
    criteria.createAlias("councilPreamble.implementationStatus", "implementationStatus",
            CriteriaSpecification.LEFT_JOIN)
            .add(Restrictions.or(Restrictions.isNull("implementationStatus.code"),
                    Restrictions.ne("implementationStatus.code", IMPLEMENTATION_STATUS_FINISHED)))
            .add(Restrictions.and(Restrictions.in(STATUS_CODE, RESOLUTION_APPROVED_PREAMBLE)));
    return criteria.list();
}

From source file:org.egov.egf.web.actions.masters.JQueryGridActionSupport.java

License:Open Source License

/**
 * Used to convert jqgrid search operator to hibernate restriction.
 **///  ww w .  j a va  2 s.co  m
private Criterion applyRestriction() {
    final Object convertedValue = convertValueType(searchField, searchString);

    if ("eq".equals(searchOper))
        return Restrictions.eq(searchField, convertedValue);
    else if ("ne".equals(searchOper))
        return Restrictions.ne(searchField, convertedValue);

    if (convertedValue instanceof String) {
        if ("bw".equals(searchOper))
            return Restrictions.ilike(searchField, searchString + "%");
        else if ("cn".equals(searchOper))
            return Restrictions.ilike(searchField, "%" + searchString + "%");
        else if ("ew".equals(searchOper))
            return Restrictions.ilike(searchField, "%" + searchString);
        else if ("bn".equals(searchOper))
            return Restrictions.not(Restrictions.ilike(searchField, searchString + "%"));
        else if ("en".equals(searchOper))
            return Restrictions.not(Restrictions.ilike(searchField, "%" + searchString));
        else if ("nc".equals(searchOper))
            return Restrictions.not(Restrictions.ilike(searchField, "%" + searchString + "%"));
        else if ("in".equals(searchOper))
            return Restrictions.in(searchField, searchString.split(","));
        else if ("ni".equals(searchOper))
            return Restrictions.not(Restrictions.in(searchField, searchString.split(",")));
    } else if ("lt".equals(searchOper))
        return Restrictions.lt(searchField, convertedValue);
    else if ("le".equals(searchOper))
        return Restrictions.le(searchField, convertedValue);
    else if ("gt".equals(searchOper))
        return Restrictions.gt(searchField, convertedValue);
    else if ("ge".equals(searchOper))
        return Restrictions.ge(searchField, convertedValue);
    return null;
}

From source file:org.egov.egf.web.actions.report.FundFlowManualEntryReportAction.java

License:Open Source License

@SuppressWarnings("unchecked")
public void getResultList() {

    // manualEntryReportList = new ArrayList<Map<String,Object>>();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Inside  getResultList ");
    Date startdt = null;/*from   www .  jav a  2  s. c om*/
    Date enddt = null;
    grandTotal = BigDecimal.ZERO;
    try {
        startdt = Constants.DDMMYYYYFORMAT2.parse(reportSearch.getStartDate());
        enddt = Constants.DDMMYYYYFORMAT2.parse(reportSearch.getEndDate());
    } catch (final ParseException e) {
        LOGGER.error("Error in parsing Date ");
    }
    final Criteria critQuery = persistenceService.getSession().createCriteria(FundFlowBean.class)

            .add(Restrictions.between("reportDate", startdt, enddt))
            .add(Restrictions.ne("currentReceipt", BigDecimal.ZERO))
            .add(Restrictions.eq("bankAccountId", BigDecimal.valueOf(reportSearch.getBankAccount().getId())))
            .addOrder(Order.asc("reportDate"));
    entryReportList.addAll(critQuery.list());

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("No of Fund flow Manual entry during the period " + reportSearch.getStartDate() + "to "
                + reportSearch.getEndDate() + "is " + entryReportList.size());

    for (final FundFlowBean entry : entryReportList) {
        manualEntry = new FundFlowBean();
        // manulEntryMap.put("slNo", ++index);
        manualEntry.setReportDate(entry.getReportDate());
        manualEntry.setCurrentReceipt(entry.getCurrentReceipt());
        grandTotal = grandTotal.add(entry.getCurrentReceipt());
        manualEntryReportList.add(manualEntry);
        // }
    }
    getSession().put("entryResultReportList", entryReportList);
    getSession().put("headingStr", heading);
    getSession().put("total", grandTotal);
    getSession().put("manualEntryReportList", manualEntryReportList);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("manualEntryReportList+" + manualEntryReportList.size());
}

From source file:org.egov.infra.persistence.validator.CompositeUniqueCheckValidator.java

License:Open Source License

private boolean checkCompositeUniqueKey(final Object arg0, final Number id) throws IllegalAccessException {
    final Criteria criteria = entityManager.unwrap(Session.class)
            .createCriteria(unique.isSuperclass() ? arg0.getClass().getSuperclass() : arg0.getClass())
            .setReadOnly(true);//from  www.  ja  v a 2 s  .c  om
    final Conjunction conjunction = Restrictions.conjunction();
    for (final String fieldName : unique.fields()) {
        final Object fieldValue = FieldUtils.readField(arg0, fieldName, true);
        if (unique.checkForNull() && fieldValue == null)
            conjunction.add(Restrictions.isNull(fieldName));
        else if (fieldValue instanceof String)
            conjunction.add(Restrictions.eq(fieldName, fieldValue).ignoreCase());
        else
            conjunction.add(Restrictions.eq(fieldName, fieldValue));
    }
    if (id != null)
        conjunction.add(Restrictions.ne(unique.id(), id));
    return criteria.add(conjunction).setProjection(Projections.id()).setMaxResults(1).uniqueResult() == null;
}

From source file:org.egov.infra.persistence.validator.UniqueCheckValidator.java

License:Open Source License

private boolean checkUnique(final Object arg0, final Number id, final String fieldName)
        throws IllegalAccessException {
    final Criteria criteria = entityManager.unwrap(Session.class)
            .createCriteria(unique.isSuperclass() ? arg0.getClass().getSuperclass() : arg0.getClass())
            .setReadOnly(true);/* w  w w . jav  a  2 s .c o m*/
    final Object fieldValue = FieldUtils.readField(arg0, fieldName, true);
    if (fieldValue instanceof String)
        criteria.add(Restrictions.eq(fieldName, fieldValue).ignoreCase());
    else
        criteria.add(Restrictions.eq(fieldName, fieldValue));
    if (id != null)
        criteria.add(Restrictions.ne(unique.id(), id));
    return criteria.setProjection(Projections.id()).setMaxResults(1).uniqueResult() == null;
}

From source file:org.egov.infra.persistence.validator.UniqueDateOverlapValidator.java

License:Open Source License

private boolean checkUnique(Object object) throws IllegalAccessException {
    Number id = (Number) FieldUtils.readField(object, uniqueDateOverlap.id(), true);
    Criteria uniqueDateOverlapChecker = entityManager.unwrap(Session.class).createCriteria(object.getClass())
            .setReadOnly(true);/* w  w w  .j  a v  a 2s  .c  om*/
    Conjunction uniqueCheck = Restrictions.conjunction();
    for (String fieldName : uniqueDateOverlap.uniqueFields()) {
        Object fieldValue = FieldUtils.readField(object, fieldName, true);
        if (fieldValue instanceof String)
            uniqueCheck.add(Restrictions.eq(fieldName, fieldValue).ignoreCase());
        else
            uniqueCheck.add(Restrictions.eq(fieldName, fieldValue));
    }
    Date fromDate = startOfDay((Date) FieldUtils.readField(object, uniqueDateOverlap.fromField(), true));
    Date toDate = endOfDay((Date) FieldUtils.readField(object, uniqueDateOverlap.toField(), true));
    Conjunction checkFromDate = Restrictions.conjunction();
    checkFromDate.add(Restrictions.le(uniqueDateOverlap.fromField(), fromDate));
    checkFromDate.add(Restrictions.ge(uniqueDateOverlap.toField(), fromDate));
    Conjunction checkToDate = Restrictions.conjunction();
    checkToDate.add(Restrictions.le(uniqueDateOverlap.fromField(), toDate));
    checkToDate.add(Restrictions.ge(uniqueDateOverlap.toField(), toDate));
    Conjunction checkFromAndToDate = Restrictions.conjunction();
    checkFromAndToDate.add(Restrictions.ge(uniqueDateOverlap.fromField(), fromDate));
    checkFromAndToDate.add(Restrictions.le(uniqueDateOverlap.toField(), toDate));
    Disjunction dateRangeChecker = Restrictions.disjunction();
    dateRangeChecker.add(checkFromDate).add(checkToDate).add(checkFromAndToDate);
    uniqueCheck.add(dateRangeChecker);
    if (id != null)
        uniqueCheck.add(Restrictions.ne(uniqueDateOverlap.id(), id));
    return uniqueDateOverlapChecker.add(uniqueCheck).setProjection(Projections.id()).setMaxResults(1)
            .uniqueResult() == null;
}

From source file:org.egov.infra.workflow.matrix.service.WorkFlowAdditionalDetailsService.java

License:Open Source License

public WorkFlowAdditionalRule getObjectbyTypeandRule(final Long objectId, final Long objectType,
        final String additionalRules) {
    final Criteria crit = entityQueryService.getSession().createCriteria(WorkFlowAdditionalRule.class);
    crit.add(Restrictions.eq(OBJECTTYPEID_ID, objectType));
    crit.add(Restrictions.ne("id", objectId));
    if (additionalRules == null) {
        crit.add(Restrictions.isNull(ADDITIONAL_RULE));
    } else {/*w  w w . ja  v  a  2s  . c o  m*/
        crit.add(Restrictions.eq(ADDITIONAL_RULE, additionalRules));
    }
    List<WorkFlowAdditionalRule> wfAdditionalRules = crit.list();
    if (!wfAdditionalRules.isEmpty()) {
        return wfAdditionalRules.get(0);
    } else {
        return null;
    }

}

From source file:org.egov.tl.service.TradeLicenseService.java

License:Open Source License

@ReadOnly
public List<DemandNoticeForm> getLicenseDemandNotices(final DemandNoticeForm demandNoticeForm) {
    final Criteria searchCriteria = entityManager.unwrap(Session.class).createCriteria(TradeLicense.class);
    searchCriteria.createAlias("licensee", "licc").createAlias("category", "cat")
            .createAlias("tradeName", "subcat").createAlias("status", "licstatus")
            .createAlias("natureOfBusiness", "nob").createAlias("licenseDemand", "licDemand")
            .createAlias("licenseAppType", "appType")
            .add(Restrictions.ne("appType.code", CLOSURE_APPTYPE_CODE));
    if (isNotBlank(demandNoticeForm.getLicenseNumber()))
        searchCriteria.add(Restrictions.eq("licenseNumber", demandNoticeForm.getLicenseNumber()).ignoreCase());
    if (isNotBlank(demandNoticeForm.getOldLicenseNumber()))
        searchCriteria//from  www  . j  av a  2  s. com
                .add(Restrictions.eq("oldLicenseNumber", demandNoticeForm.getOldLicenseNumber()).ignoreCase());
    if (demandNoticeForm.getCategoryId() != null)
        searchCriteria.add(Restrictions.eq("cat.id", demandNoticeForm.getCategoryId()));
    if (demandNoticeForm.getSubCategoryId() != null)
        searchCriteria.add(Restrictions.eq("subcat.id", demandNoticeForm.getSubCategoryId()));
    if (demandNoticeForm.getWardId() != null)
        searchCriteria.createAlias("parentBoundary", "wards")
                .add(Restrictions.eq("wards.id", demandNoticeForm.getWardId()));
    if (demandNoticeForm.getElectionWard() != null)
        searchCriteria.createAlias("adminWard", "electionWard")
                .add(Restrictions.eq("electionWard.id", demandNoticeForm.getElectionWard()));
    if (demandNoticeForm.getLocalityId() != null)
        searchCriteria.createAlias("boundary", "locality")
                .add(Restrictions.eq("locality.id", demandNoticeForm.getLocalityId()));
    if (demandNoticeForm.getStatusId() == null)
        searchCriteria.add(Restrictions.ne("licstatus.statusCode", StringUtils.upperCase("CAN")));
    else
        searchCriteria.add(Restrictions.eq("status.id", demandNoticeForm.getStatusId()));
    searchCriteria.add(Restrictions.eq("isActive", true))
            .add(Restrictions.eq("nob.name", PERMANENT_NATUREOFBUSINESS))
            .add(Restrictions.gtProperty("licDemand.baseDemand", "licDemand.amtCollected"))
            .addOrder(Order.asc("id"));
    final List<DemandNoticeForm> finalList = new LinkedList<>();

    for (final TradeLicense license : (List<TradeLicense>) searchCriteria.list()) {
        LicenseDemand licenseDemand = license.getCurrentDemand();
        if (licenseDemand != null) {
            Installment currentInstallment = licenseDemand.getEgInstallmentMaster();
            List<Installment> previousInstallment = installmentDao
                    .fetchPreviousInstallmentsInDescendingOrderByModuleAndDate(
                            licenseUtils.getModule(TRADE_LICENSE), currentInstallment.getToDate(), 1);
            Map<String, Map<String, BigDecimal>> outstandingFees = getOutstandingFeeForDemandNotice(license,
                    currentInstallment, previousInstallment.get(0));
            Map<String, BigDecimal> licenseFees = outstandingFees.get(LICENSE_FEE_TYPE);
            finalList.add(new DemandNoticeForm(license, licenseFees, getOwnerName(license)));
        }
    }
    return finalList;
}

From source file:org.emonocot.persistence.dao.hibernate.TaxonDaoImpl.java

License:Open Source License

/**
 * Returns the child taxa of a given taxon.
 *
 * @param identifier/*from  ww w  .  j  ava 2 s .  c o  m*/
 *            set the identifier
 * @param pageSize
 *            The maximum number of results to return
 * @param pageNumber
 *            The offset (in pageSize chunks, 0-based) from the beginning of
 *            the recordset
 * @param fetch
 *            Set the fetch profile
 * @return a Page from the resultset
 */
public final List<Taxon> loadChildren(final String identifier, final Integer pageSize, final Integer pageNumber,
        final String fetch) {
    Criteria criteria = getSession().createCriteria(Taxon.class);
    if (identifier == null) {
        // return the root taxa
        ////         criteria.add(Restrictions.isNull("parentNameUsage"));
        criteria.add(Restrictions.isNotNull("scientificName"));
        ////      criteria.add(Restrictions.eq("taxonomicStatus", TaxonomicStatus.Accepted));
        criteria.add(Restrictions.isNotNull("parentNameUsage"));
        criteria.add(Restrictions.ne("taxonomicStatus", TaxonomicStatus.Synonym));
        if (rootRank != null) {
            criteria.add(Restrictions.eq("taxonRank", rootRank));
        }
    } else {
        criteria.createAlias("parentNameUsage", "p");
        criteria.add(Restrictions.eq("p.identifier", identifier));
    }

    if (pageSize != null) {
        criteria.setMaxResults(pageSize);
        if (pageNumber != null) {
            criteria.setFirstResult(pageSize * pageNumber);
        }
    }
    criteria.addOrder(Order.asc("scientificName"));
    enableProfilePreQuery(criteria, fetch);
    List<Taxon> results = (List<Taxon>) criteria.list();

    for (Taxon t : results) {
        enableProfilePostQuery(t, fetch);
    }
    return results;
}

From source file:org.encuestame.persistence.dao.imp.CommentDao.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Comment> getCommentsByKeyword(final String keyword, final Integer maxResults,
        final Long[] excludes) {
    log.info("keyword " + keyword);
    List<Comment> searchResult = (List<Comment>) getHibernateTemplate().execute(new HibernateCallback() {
        @SuppressWarnings("deprecation")
        public Object doInHibernate(org.hibernate.Session session) {
            final Criteria criteria = session.createCriteria(Comment.class);
            final QueryBuilder<Comment> query = new QueryBuilder(getSessionFactory());
            if (excludes != null && excludes.length > 0) {
                for (int i = 0; i < excludes.length; i++) {
                    log.debug("excluding hashtag... " + excludes[i]);
                    criteria.add(Restrictions.ne("commentId", excludes[i]));
                }/*from www .j a  v a  2  s  .c  o m*/
            }
            List<Comment> results = query.build(criteria, keyword, maxResults, 0, new String[] { "comment" },
                    "comment", Comment.class);
            return results;
        }
    });
    return searchResult;
}