List of usage examples for org.hibernate.criterion Restrictions le
public static SimpleExpression le(String propertyName, Object value)
From source file:com.ivanbiz.dao.impl.KelasDAOImpl.java
@Override public List getData(Date start, Date end) throws Exception { List list = null;/*from www .j av a 2s . co m*/ try { Session session = HibernateUtil.getSession(); HibernateUtil.beginTransaction(); start.setHours(0); start.setMinutes(0); start.setSeconds(0); end.setHours(0); end.setMinutes(0); end.setSeconds(0); Criteria crit = session.createCriteria(Kelas.class).add(Restrictions.ge("tanggalKelas", start)) .add(Restrictions.le("tanggalKelas", end)).addOrder(Order.asc("pengajar.id")) .addOrder(Order.asc("tanggalKelas")); list = crit.list(); HibernateUtil.commitTransaction(); } catch (Exception e) { HibernateUtil.rollbackTransaction(); throw e; } finally { HibernateUtil.closeSession(); } return list; }
From source file:com.ivanbiz.dao.impl.KelasDAOImpl.java
@Override public List getData(Pengajar pengajar, Date start, Date end) throws Exception { List list = null;/*from w ww . ja v a2 s .c o m*/ try { Session session = HibernateUtil.getSession(); HibernateUtil.beginTransaction(); start.setHours(0); start.setMinutes(0); start.setSeconds(0); end.setHours(0); end.setMinutes(0); end.setSeconds(0); Criteria crit = session.createCriteria(Kelas.class) .add(Restrictions.eq("pengajar.id", pengajar.getId())) .add(Restrictions.ge("tanggalKelas", start)).add(Restrictions.le("tanggalKelas", end)); list = crit.list(); HibernateUtil.commitTransaction(); } catch (Exception e) { HibernateUtil.rollbackTransaction(); throw e; } finally { HibernateUtil.closeSession(); } return list; }
From source file:com.jeroensteenbeeke.hyperion.data.Expression.java
License:Open Source License
public static <T extends Comparable<T> & Serializable> Expression<T> lessThanOrEquals(final String property, final T value) { return new Expression<T>() { private static final long serialVersionUID = 1L; @Override/*from w w w .jav a2 s. c o m*/ public void decorateCriteria(Criteria criteria) { criteria.add(Restrictions.le(property, value)); } @SuppressWarnings("unchecked") @Override public boolean retain(Object object) { T objectValue = (T) Reflector.invokeGetter(object, property); return objectValue.compareTo(value) <= 0; } }; }
From source file:com.jeysan.modules.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,.//from ww w .j a v a 2s . c om */ 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. ja v a 2 s . c om 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 List fetchEntities(String paramVal) { List list = null;/*from w w w . j a va 2 s. com*/ 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 ww w. j av a 2 s. c o 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
/** * // w w w . j av a 2 s . c om * @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 addLessThanOrEqualTo(String property, Object value) { _add(Restrictions.le(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;/*from w ww. ja v a 2s.co 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; }