List of usage examples for org.hibernate.criterion Restrictions gtProperty
public static PropertyExpression gtProperty(String propertyName, String otherPropertyName)
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriterionAdapter.java
License:Apache License
protected void addPropertyComparisonCriterionAdapters() { criterionAdaptors.put(Query.EqualsProperty.class, new CriterionAdaptor<Query.EqualsProperty>() { @Override/*from w ww . j a va2 s . com*/ public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.EqualsProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.eqProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.GreaterThanProperty.class, new CriterionAdaptor<Query.GreaterThanProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.GreaterThanProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.gtProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.GreaterThanEqualsProperty.class, new CriterionAdaptor<Query.GreaterThanEqualsProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.GreaterThanEqualsProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.geProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.LessThanProperty.class, new CriterionAdaptor<Query.LessThanProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThanProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.ltProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.LessThanEqualsProperty.class, new CriterionAdaptor<Query.LessThanEqualsProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.LessThanEqualsProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.leProperty(propertyName, criterion.getOtherProperty()); } }); criterionAdaptors.put(Query.NotEqualsProperty.class, new CriterionAdaptor<Query.NotEqualsProperty>() { @Override public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.NotEqualsProperty criterion, String alias) { String propertyName = getPropertyName(criterion, alias); return Restrictions.neProperty(propertyName, criterion.getOtherProperty()); } }); }
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 w ww . j av a2s . c om*/ .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.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionAccessImpl.java
License:Apache License
private Criterion makeCriterion(ConditionalCriteria crit) { if (crit == null) { return null; }// w w w . j a v a 2s. c o m ConditionalCriteria.Operator operator = crit.getOperator(); if (Operator.Equal.equals(operator)) { return Restrictions.eq(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant()); } else if (Operator.IgnoreCaseEqual.equals(operator)) { return Restrictions.eq(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant()) .ignoreCase(); } else if (Operator.LessThan.equals(operator)) { return Restrictions.lt(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant()); } else if (Operator.LessThanOrEqual.equals(operator)) { return Restrictions.le(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant()); } else if (Operator.GreatThan.equals(operator)) { return Restrictions.gt(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant()); } else if (Operator.GreatThanOrEqual.equals(operator)) { return Restrictions.ge(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant()); } else if (Operator.Like.equals(operator)) { // Hibernate bug HHH-5339 + PostgreSQL missing 'number like string' conversion return new NumericLikeExpression(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant().toString(), false); } else if (Operator.IgnoreCaseLike.equals(operator)) { // Hibernate bug HHH-5339 + PostgreSQL missing 'number like string' conversion return new NumericLikeExpression(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant().toString(), true); } else if (Operator.IsNull.equals(operator)) { return Restrictions.isNull(makePathWithAlias(crit.getPropertyFullName())); } else if (Operator.IsNotNull.equals(operator)) { return Restrictions.isNotNull(makePathWithAlias(crit.getPropertyFullName())); } else if (Operator.IsEmpty.equals(operator)) { return Restrictions.isEmpty(makePathWithAlias(crit.getPropertyFullName())); } else if (Operator.IsNotEmpty.equals(operator)) { return Restrictions.isNotEmpty(makePathWithAlias(crit.getPropertyFullName())); } else if (Operator.Not.equals(operator)) { return Restrictions.not(makeCriterion((ConditionalCriteria) crit.getFirstOperant())); } else if (Operator.Or.equals(operator) && crit.getFirstOperant() instanceof List<?>) { Disjunction disj = Restrictions.disjunction(); List<?> disjList = (List<?>) crit.getFirstOperant(); for (Object disjPart : disjList) { disj.add(makeCriterion((ConditionalCriteria) disjPart)); } return disj; } else if (Operator.Or.equals(operator)) { return Restrictions.or(makeCriterion((ConditionalCriteria) crit.getFirstOperant()), makeCriterion((ConditionalCriteria) crit.getSecondOperant())); } else if (Operator.And.equals(operator) && crit.getFirstOperant() instanceof List<?>) { Conjunction conj = Restrictions.conjunction(); List<?> conjList = (List<?>) crit.getFirstOperant(); for (Object conjPart : conjList) { conj.add(makeCriterion((ConditionalCriteria) conjPart)); } return conj; } else if (Operator.And.equals(operator)) { return Restrictions.and(makeCriterion((ConditionalCriteria) crit.getFirstOperant()), makeCriterion((ConditionalCriteria) crit.getSecondOperant())); } else if (Operator.In.equals(operator)) { if (crit.getFirstOperant() instanceof Collection<?>) { return Restrictions.in(makePathWithAlias(crit.getPropertyFullName()), (Collection<?>) crit.getFirstOperant()); } else { return Restrictions.in(makePathWithAlias(crit.getPropertyFullName()), (Object[]) crit.getFirstOperant()); } } else if (Operator.Between.equals(operator)) { return Restrictions.between(makePathWithAlias(crit.getPropertyFullName()), crit.getFirstOperant(), crit.getSecondOperant()); } else if (Operator.DistinctRoot.equals(operator)) { realDistinctRoot = true; return null; } else if (Operator.ProjectionRoot.equals(operator)) { resultTransformer = Criteria.PROJECTION; return null; } else if (Operator.EqualProperty.equals(operator)) { return Restrictions.eqProperty(makePathWithAlias(crit.getPropertyFullName()), (String) crit.getFirstOperant()); } else if (Operator.LessThanProperty.equals(operator)) { return Restrictions.ltProperty(makePathWithAlias(crit.getPropertyFullName()), (String) crit.getFirstOperant()); } else if (Operator.LessThanOrEqualProperty.equals(operator)) { return Restrictions.leProperty(makePathWithAlias(crit.getPropertyFullName()), (String) crit.getFirstOperant()); } else if (Operator.GreatThanProperty.equals(operator)) { return Restrictions.gtProperty(makePathWithAlias(crit.getPropertyFullName()), (String) crit.getFirstOperant()); } else if (Operator.GreatThanOrEqualProperty.equals(operator)) { return Restrictions.geProperty(makePathWithAlias(crit.getPropertyFullName()), (String) crit.getFirstOperant()); } else { return null; } }
From source file:to.etc.domui.hibernate.model.CriteriaCreatingVisitor.java
License:Open Source License
@Override public void visitPropertyJoinComparison(@NonNull QPropertyJoinComparison comparison) throws Exception { String alias = m_parentAlias + "." + parseSubcriteria(comparison.getParentProperty()); switch (comparison.getOperation()) { default:/* w w w . j av a2 s .c om*/ throw new QQuerySyntaxException("Unsupported parent-join operation: " + comparison.getOperation()); case EQ: m_last = Restrictions.eqProperty(alias, comparison.getSubProperty()); break; case NE: m_last = Restrictions.neProperty(alias, comparison.getSubProperty()); break; case LT: m_last = Restrictions.ltProperty(alias, comparison.getSubProperty()); break; case LE: m_last = Restrictions.leProperty(alias, comparison.getSubProperty()); break; case GT: m_last = Restrictions.gtProperty(alias, comparison.getSubProperty()); break; case GE: m_last = Restrictions.geProperty(alias, comparison.getSubProperty()); break; } }
From source file:uk.ac.sussex.model.base.RestrictionList.java
License:Open Source License
/** * Attribute 1 must be greater than attribute 2. * @param attributeName1//from w w w . j av a2 s.co m * @param attributeName2 */ public void addGTProperty(String attributeName1, String attributeName2) { this.add(Restrictions.gtProperty(attributeName1, attributeName2)); }