Example usage for org.hibernate.criterion Restrictions ge

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

Introduction

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

Prototype

public static SimpleExpression ge(String propertyName, Object value) 

Source Link

Document

Apply a "greater than or equal" constraint to the named property

Usage

From source file:com.jeysan.modules.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,.//  ww w.j a v  a  2s  .  c o m
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    //?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case NEQ:
        if (propertyValue == null)
            criterion = Restrictions.isNotNull(propertyName);
        else
            criterion = Restrictions.not(Restrictions.eq(propertyName, propertyValue));
        break;
    case NULL:
        criterion = Restrictions.isNull(propertyName);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
    }
    return criterion;
}

From source file:com.jubination.model.dao.CallAPIMessageDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Long fetchEntitySize(String fromDate, String toDate, String type) {
    System.out.println("*******com.jubination.model.dao.CallAPIMessageDAOImpl.fetchEntitySize()");
    Long size = 0l;/* w w w .j a va 2s .  c  o m*/
    switch (type) {
    case "Total":
        System.out.println("*****Case - Total");
        session = getSessionFactory().getCurrentSession();
        Criteria criteria = session.createCriteria(Call.class, "call");
        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();

        break;
    case "Busy":
        System.out.println("*****Case - Busy");
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.add(Restrictions.like("Status", "busy", MatchMode.ANYWHERE));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();

        break;
    case "Failed":
        System.out.println("*****Case - Failed");
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.add(Restrictions.like("Status", "failed", MatchMode.ANYWHERE));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();

        break;
    case "NoAnswer":
        System.out.println("*****Case - NoAnswer");
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.add(Restrictions.like("Status", "no-answer", MatchMode.ANYWHERE));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();

        break;
    case "RequestedCallBack":
        System.out.println("*****Case - RequestedCallBack");
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.add(Restrictions.like("TrackStatus", "requested for callback", MatchMode.ANYWHERE));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();

        break;
    case "GreetingsHangUp":
        System.out.println("*****Case - GreetingsHangUp");
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.add(Restrictions.like("CallType", "trans", MatchMode.ANYWHERE));
        criteria.add(Restrictions.like("Status", "completed", MatchMode.ANYWHERE));
        criteria.add(Restrictions.isNull("TrackStatus"));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();

        break;
    case "HangUpOnConnect":
        System.out.println("*****Case - HangUpOnConnect");
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");

        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE));
        criteria.add(Restrictions.like("CallType", "client-hangup", MatchMode.ANYWHERE));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();

        break;
    case "MissCall":
        System.out.println("*****Case - MissCall");
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.add(Restrictions.like("TrackStatus", "did not speak", MatchMode.ANYWHERE));
        criteria.add(Restrictions.like("CallType", "incomplete", MatchMode.ANYWHERE));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();
        break;
    case "Spoke":
        System.out.println("*****Case - Spoke");
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Call.class, "call");
        criteria.setReadOnly(true);
        criteria.add(Restrictions.and(Restrictions.ge("DateCreated", fromDate),
                Restrictions.le("DateCreated", toDate), Restrictions.isNull("lead")));
        criteria.add(Restrictions.like("TrackStatus", "spoke", MatchMode.ANYWHERE));
        criteria.setProjection(Projections.rowCount());
        size = (Long) criteria.uniqueResult();

        break;

    }
    return size;
}

From source file:com.jubination.model.dao.ClientDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Object fetchInnerEntities(String param, String type) {
    List<Lead> list = null;
    if (param.equals("Lead")) {
        if (type.equals("NotificationOn")) {
            session = getSessionFactory().getCurrentSession();
            list = (List<Lead>) session.createCriteria(Lead.class).add(Restrictions.isNotNull("followUpDate"))
                    .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();
        }//from  w  ww  . j ava 2s . c  om

        if (type.equals("Pending")) {
            session = getSessionFactory().getCurrentSession();
            list = (List<Lead>) session.createCriteria(Lead.class).add(Restrictions.ge("count", 1))
                    .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();

        }

    } else if (param.equals("Number")) {
        session = getSessionFactory().getCurrentSession();
        list = (List<Lead>) session.createCriteria(Lead.class).createAlias("client", "c")
                .add(Restrictions.eq("c.phoneNumber", type))
                .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();

    } else if (param.equals("MissedAppointmentStatusToday")) {
        session = getSessionFactory().getCurrentSession();
        list = (List<Lead>) session.createCriteria(Lead.class)
                .add(Restrictions.and(Restrictions.like("missedAppointmentStatus", type, MatchMode.ANYWHERE),
                        Restrictions.eq("appointmentDate",
                                new SimpleDateFormat("yyyy-MM-dd").format(new Date()))))
                .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();

    } else if (param.equals("ActiveSourceLeads")) {
        session = getSessionFactory().getCurrentSession();
        list = (List<Lead>) session.createCriteria(Lead.class, "l").createAlias("client", "c")
                .add(Restrictions.and(Restrictions.ge("l.count", 1), Restrictions.eq("c.source", type)))
                .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();

    }
    if (list != null) {
        for (Lead lead : list) {
            if (lead != null) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
            }
        }
    }
    System.out.println("READ LEAD WITH A STATUS :::::::::::::::::::::::::::::::::::::::::::::::CHECK");
    return (T) list;
}

From source file:com.jubination.model.dao.ClientDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List fetchEntities(String paramVal) {
    List list = null;/*from  w  w w.jav  a2s .  c o  m*/

    switch (paramVal) {

    case "PendingMinusOne":
        session = getSessionFactory().getCurrentSession();
        Criteria criteria = session.createCriteria(Client.class, "c");
        criteria.createAlias("c.lead", "l");
        criteria.add(Restrictions.and(Restrictions.lt("l.count", 0), Restrictions.isNull("l.followUpDate"),
                Restrictions.gt("l.leadId", "50000")));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        list = criteria.list();

        for (Client client : (List<Client>) list) {
            client.getLead().size();
            for (Lead lead : client.getLead()) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
                lead.getCall().size();
            }
        }
        break;
    case "PendingInProgress":
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Client.class, "c");
        criteria.createAlias("c.lead", "l");
        criteria.createAlias("l.call", "call");
        criteria.add(Restrictions.and(Restrictions.le("l.count", 0), Restrictions.gt("l.leadId", "50000"),
                Restrictions.eq("call.Status", "in-progress")));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        list = criteria.list();

        for (Client client : (List<Client>) list) {
            client.getLead().size();
            for (Lead lead : client.getLead()) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
                lead.getCall().size();
            }
        }
        break;
    case "PendingAndNotified":
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Client.class, "c");
        criteria.createAlias("c.lead", "l");
        criteria.add(Restrictions.or(Restrictions.and(

                Restrictions.ge("l.count", 1), Restrictions.eq("l.followUpDate", ""),
                Restrictions.isNull("l.followUpDate")),

                Restrictions.and(Restrictions.ge("l.count", 1), Restrictions.ne("l.followUpDate", ""),
                        Restrictions.isNotNull("l.followUpDate"),
                        Restrictions.le("l.followUpDate",
                                new SimpleDateFormat("yyyy-MM-dd").format(new Date()))),
                Restrictions.eq("l.followUpDate", new SimpleDateFormat("yyyy-MM-dd").format(new Date())))

        );
        criteria.addOrder(Order.desc("l.followUpDate"));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        list = criteria.list();

        for (Client client : (List<Client>) list) {
            client.getLead().size();
            for (Lead lead : client.getLead()) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
                lead.getCall().size();
            }
        }
        break;

    case "Pending":
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Client.class, "c");
        criteria.createAlias("c.lead", "l");
        criteria.add(Restrictions.and(Restrictions.and(Restrictions.ge("l.count", 1),
                Restrictions.isNull("l.missedAppointment"), Restrictions.isNull("l.followUpDate"))));

        criteria.addOrder(Order.asc("l.count"));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        list = criteria.list();
        for (Client client : (List<Client>) list) {
            client.getLead().size();
            for (Lead lead : client.getLead()) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
                lead.getCall().size();

            }
        }
        break;
    case "Notified":
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Client.class, "c");
        criteria.createAlias("c.lead", "l");
        criteria.add(
                Restrictions.or(
                        Restrictions.and(
                                Restrictions
                                        .and(Restrictions.ge("l.count", 1),
                                                Restrictions.and(
                                                        Restrictions.le("l.followUpDate",
                                                                new SimpleDateFormat("yyyy-MM-dd")
                                                                        .format(new Date())),
                                                        Restrictions.gt("l.followUpDate", "2016-01-01"))),
                                Restrictions.isNull("l.missedAppointment")),
                        Restrictions.and(
                                Restrictions.eq("l.followUpDate",
                                        new SimpleDateFormat("yyyy-MM-dd").format(new Date())),
                                Restrictions.eq("l.leadStatus", "Follow up/Call back"))));
        criteria.addOrder(Order.asc("l.followUpDate"));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        list = criteria.list();
        for (Client client : (List<Client>) list) {
            client.getLead().size();
            for (Lead lead : client.getLead()) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
                lead.getCall().size();
            }
        }
        break;
    case "PendingMA":
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Client.class, "c");
        criteria.createAlias("c.lead", "l");
        criteria.add(Restrictions.and(Restrictions.ge("l.count", 1),
                Restrictions.eq("l.missedAppointment", true), Restrictions.isNull("l.followUpDate")));

        criteria.addOrder(Order.desc("l.count"));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        list = criteria.list();
        for (Client client : (List<Client>) list) {
            client.getLead().size();
            for (Lead lead : client.getLead()) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
                lead.getCall().size();
            }
        }
        break;
    case "NotifiedMA":
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Client.class);
        criteria.createAlias("lead", "l");
        criteria.add(Restrictions.and(
                Restrictions.and(Restrictions.ge("l.count", 1),
                        Restrictions.and(
                                Restrictions.le("l.followUpDate",
                                        new SimpleDateFormat("yyyy-MM-dd").format(new Date())),
                                Restrictions.gt("l.followUpDate", "2016-01-01"))),
                Restrictions.eq("l.missedAppointment", true)));
        criteria.addOrder(Order.asc("l.followUpDate"));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        list = criteria.list();
        for (Client client : (List<Client>) list) {
            client.getLead().size();
            for (Lead lead : client.getLead()) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
                lead.getCall().size();
            }
        }
        break;

    case "Overnight":
        session = getSessionFactory().getCurrentSession();
        criteria = session.createCriteria(Client.class);
        criteria.add(Restrictions.eq("overnight", true));
        list = criteria.list();
        for (Client client : (List<Client>) list) {
            for (Lead lead : client.getLead()) {
                if (lead.getBeneficiaries() != null) {
                    lead.getBeneficiaries().size();
                }
                lead.getCall().size();
            }
            client.getLead().size();
        }
        break;

    default:

        break;
    }
    if (list != null) {
        System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" + list.size() + "$$$" + paramVal);
    }

    System.out.println(
            "READ CLIENT WITH INNER ELEMENTS WITH STATUS :::::::::::::::::::::::::::::::::::::::::::::::CHECK");
    return list;

}

From source file:com.jubination.model.dao.ClientDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<Object> fetchFreshCallEntity(String fromDate, String toDate) {
    List list = null;/*from  w  w  w.j a va 2  s . co  m*/
    session = getSessionFactory().getCurrentSession();
    Criteria criteria = session.createCriteria(Client.class, "client").add(Restrictions.and(
            Restrictions.ge("client.dateCreation", fromDate), Restrictions.le("client.dateCreation", toDate)));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    list = criteria.list();
    for (Client c : (List<Client>) list) {
        c.getLead().size();
        for (Lead l : c.getLead()) {
            l.getCall().size();
        }
    }

    System.out.println(
            "IMPORTANT:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" + list.size());
    return list;
}

From source file:com.klistret.cmdb.utility.hibernate.XPathCriteria.java

License:Open Source License

/**
 * //from w w w . j  a  va 2s  . c  o m
 * @param predicate
 * @return
 */
protected Criterion getRestriction(Expr predicate, HibernateStep context) {
    logger.debug("Adding restrictions by predicate to context [{}]", context);

    switch (predicate.getType()) {
    case Or:
        /**
         * Recursively breaks down the OrExpr by translating on the first
         * and second operands
         */
        if (((OrExpr) predicate).getOperands().size() != 2)
            throw new ApplicationException(
                    String.format("OrExpr expression [%s] expects 2 operands", predicate));

        return Restrictions.or(getRestriction(((OrExpr) predicate).getOperands().get(0), context),
                getRestriction(((OrExpr) predicate).getOperands().get(1), context));
    case And:
        /**
         * Recursively breaks down the AndExpr by translating on the first
         * and second operands
         */
        if (((AndExpr) predicate).getOperands().size() != 2)
            throw new ApplicationException(
                    String.format("AndExpr expression [%s] expects 2 operands", predicate));

        return Restrictions.and(getRestriction(((AndExpr) predicate).getOperands().get(0), context),
                getRestriction(((AndExpr) predicate).getOperands().get(1), context));
    case Comparison:
        /**
         * Find the literal
         */
        LiteralExpr literal = getLiteralOperand(((ComparisonExpr) predicate).getOperands());

        /**
         * Find the relative path making a Hibernate relative path
         */
        RelativePathExpr rpe = getRelativePathOperand(((ComparisonExpr) predicate).getOperands());
        HibernateRelativePath hRPath = process(rpe, context);
        build(hRPath);

        HibernateStep last = hRPath.getLastHibernateStep();

        /**
         * Property name with alias prefix
         */
        String alias = last.getPrevious() == null ? aliasCache.get(context.getPath())
                : aliasCache.get(last.getPrevious().getPath());
        String propertyName = alias == null ? last.getName() : String.format("%s.%s", alias, last.getName());

        /**
         * Paths with XML properties (always the last step if present)
         * return a XPath restriction.
         */
        if (hRPath.hasXML()) {
            if (!hRPath.isTruncated())
                throw new ApplicationException(String.format(
                        "Predicate relative path ending in an XML property [%s] must be truncated", last));

            /**
             * Last Hibernate step of the Hibernate path marks the property
             * which the restriction acts on.
             */
            StepExpr step = (StepExpr) last.getStep();

            /**
             * A new XPath is created from the last step downwards till the
             * step prior to the ending step.
             */
            String xpath = null;
            for (int depth = step.getDepth(); depth < step.getRelativePath().getDepth() - 1; depth++) {
                Expr expr = step.getRelativePath().getExpr(depth);
                xpath = xpath == null ? expr.getXPath() : String.format("%s/%s", xpath, expr.getXPath());
            }

            Step ending = (Step) step.getRelativePath().getLastExpr();

            /**
             * A new comparison is generated
             */
            List<Expr> operands = new ArrayList<Expr>();
            operands.add(ending);
            operands.add(literal);

            xpath = String.format("%s[%s]", xpath,
                    ComparisonExpr.getXPath(((ComparisonExpr) predicate).getOperator(), operands, false));
            xpath = String.format("%s%s", context.getBaseExpression().getProlog(), xpath);

            PathExpression other = new PathExpression(xpath);
            return new XPathRestriction(propertyName, (Step) other.getRelativePath().getFirstExpr());
        }

        if (((StepExpr) last.getStep()).hasPredicates())
            throw new ApplicationException(String.format(
                    "Comparisons against Hibernate properties may not have an underlying step [] with predicates",
                    last.getStep()));

        logger.debug("Predicate is comparison [{}] against property [{}]",
                ((ComparisonExpr) predicate).getOperator().name(), propertyName);

        switch (((ComparisonExpr) predicate).getOperator()) {
        case ValueEquals:
            logger.debug("Value: {}", literal.getValue().getJavaValue());
            return Restrictions.eq(propertyName, literal.getValue().getJavaValue());
        case ValueGreaterThan:
            logger.debug("Value: {}", literal.getValue().getJavaValue());
            return Restrictions.gt(propertyName, literal.getValue().getJavaValue());
        case ValueGreaterThanOrEquals:
            logger.debug("Value: {}", literal.getValue().getJavaValue());
            return Restrictions.ge(propertyName, literal.getValue().getJavaValue());
        case ValueLessThan:
            logger.debug("Value: {}", literal.getValue().getJavaValue());
            return Restrictions.lt(propertyName, literal.getValue().getJavaValue());
        case ValueLessThanOrEquals:
            logger.debug("Value: {}", literal.getValue().getJavaValue());
            return Restrictions.le(propertyName, literal.getValue().getJavaValue());
        case ValueNotEquals:
            logger.debug("Value: {}", literal.getValue().getJavaValue());
            return Restrictions.ne(propertyName, literal.getValue().getJavaValue());
        case GeneralEquals:
            /**
             * If atomic (not a sequence) then the 'in' restriction is not
             * usable (defaults to 'eq' restriction) since the argument is
             * an array of objects.
             */
            if (literal.isAtomic()) {
                logger.debug("Value: {}", literal.getValue().getJavaValue());
                return Restrictions.eq(propertyName, literal.getValue().getJavaValue());
            }

            logger.debug("Values: {}", literal.getValues());

            Object[] javaValues = new Object[literal.getValues().length];
            for (int index = 0; index < literal.getValues().length; index++)
                javaValues[index] = ((com.klistret.cmdb.utility.saxon.Value) literal.getValues()[index])
                        .getJavaValue();

            return Restrictions.in(propertyName, javaValues);
        case Matches:
            if (((ComparisonExpr) predicate).getOperands().size() != 2)
                throw new ApplicationException(
                        String.format("Matches function [%s] expects 2 operands", predicate));

            logger.debug("Value: {}", literal.getValue().getText());
            return Restrictions.ilike(propertyName, literal.getValue().getText(), MatchMode.EXACT);
        case Exists:
            if (((ComparisonExpr) predicate).getOperands().size() != 1)
                throw new ApplicationException(
                        String.format("Exists function [%s] expects only 1 operand", predicate));

            return Restrictions.isNotNull(propertyName);
        case Empty:
            if (((ComparisonExpr) predicate).getOperands().size() != 1)
                throw new ApplicationException(
                        String.format("Empty function [%s] expects only 1 operand", predicate));

            return Restrictions.isNull(propertyName);
        default:
            throw new ApplicationException(
                    String.format("Unexpected comparison operator [%s] handling predicates",
                            ((ComparisonExpr) predicate).getOperator()));
        }

    default:
        throw new ApplicationException(String.format("Unexpected expr [%s] type for predicate", predicate));
    }
}

From source file:com.kodemore.hibernate.criteria.KmAbstractCriteria.java

License:Open Source License

public void addGreaterThanOrEqualTo(String property, Object value) {
    _add(Restrictions.ge(property, value));
}

From source file:com.krawler.common.util.BuildCriteria.java

License:Open Source License

private static Criterion getCriteriaByCondition(Object value, Integer criteriaVal, String propertyname) {
    Criterion Criteriaobj;/* w ww .ja v  a  2  s. c  o  m*/

    switch (criteriaVal) {
    case ISNOTNULL:
        Criteriaobj = Restrictions.isNotNull(propertyname);
        break;
    case NOTIN:
        String[] strArr = String.valueOf(value).split(",");
        List ls = Arrays.asList(strArr);
        Criteriaobj = Restrictions.not(Restrictions.in(propertyname, ls));
        break;
    case LIKE:
        Criteriaobj = Restrictions.or(Restrictions.like(propertyname, value + "%"),
                Restrictions.like(propertyname, "% " + value + "%"));
        break;
    case LE:
        Criteriaobj = Restrictions.le(propertyname, value);
        break;
    case GE:
        Criteriaobj = Restrictions.ge(propertyname, value);
        break;
    case ISNULL:
        Criteriaobj = Restrictions.isNull(propertyname);
        break;
    case IN:
        strArr = String.valueOf(value).split(",");
        ls = Arrays.asList(strArr);
        Criteriaobj = Restrictions.in(propertyname, ls);
        break;
    case NE:
        Criteriaobj = Restrictions.ne(propertyname, value);
        break;
    case LT:
        Criteriaobj = Restrictions.lt(propertyname, value);
        break;
    case GT:
        Criteriaobj = Restrictions.gt(propertyname, value);
        break;
    case EQ:
    default:
        Criteriaobj = Restrictions.eq(propertyname, value);
        break;
    }
    return Criteriaobj;
}

From source file:com.lakeside.data.sqldb.PageBaseDao.java

License:Apache License

/**
 * ??Criterion,./*from ww  w  .j  a  v a 2  s . c om*/
 */
protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    try {

        //?MatchTypecriterion
        if (MatchType.EQ.equals(matchType)) {
            criterion = Restrictions.eq(propertyName, propertyValue);
        } else if (MatchType.LIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        } else if (MatchType.LE.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue);
        } else if (MatchType.LT.equals(matchType)) {
            criterion = Restrictions.lt(propertyName, propertyValue);
        } else if (MatchType.GE.equals(matchType)) {
            criterion = Restrictions.ge(propertyName, propertyValue);
        } else if (MatchType.GT.equals(matchType)) {
            criterion = Restrictions.gt(propertyName, propertyValue);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
}

From source file:com.lewischooman.dao.MovieShowDAO.java

License:Open Source License

@Override
@SuppressWarnings(value = "unchecked")
public List<MovieShowDB> getMovieShowsByDateTheater(Date dateFrom, Date dateTo, Integer theaterId,
        boolean breakByTheater, Integer movieId) {
    Session session;//from   w w  w . j ava2  s.  co m
    Criteria criteria;

    session = this.sessionFactory.getCurrentSession();
    criteria = session.createCriteria(MovieShowDB.class, "shw");
    if (dateFrom != null) {
        criteria.add(Restrictions.ge("shw.showDate", dateFrom));
    }
    if (dateTo != null) {
        criteria.add(Restrictions.le("shw.showDate", dateTo));
    }
    criteria.createAlias("shw.movie", "mov", JoinType.INNER_JOIN).createAlias("shw.hall", "hal",
            JoinType.INNER_JOIN);
    if (movieId != null) {
        criteria.add(Restrictions.eq("mov.id", movieId));
    }
    if (breakByTheater) {
        criteria.createAlias("hal.theater", "the", JoinType.INNER_JOIN);
        if (theaterId != null) {
            criteria.add(Restrictions.eq("the.id", theaterId));
        }
        criteria.addOrder(Order.asc("the.name"));
    }
    criteria.addOrder(Order.asc("mov.title")).addOrder(Order.asc("shw.showDate"))
            .addOrder(Order.asc("shw.showTime"));

    return (List<MovieShowDB>) criteria.list();
}