List of usage examples for org.hibernate.criterion Restrictions isNull
public static Criterion isNull(String propertyName)
From source file:com.jeroensteenbeeke.hyperion.data.Nullable.java
License:Open Source License
public static <T extends Serializable> Nullable<T> isNull(final String property, Class<T> returnType) { return new Nullable<T>() { private static final long serialVersionUID = 1L; @Override/*from www . j a va2 s . c om*/ public void decorateCriteria(Criteria criteria) { Criterion c = Restrictions.isNull(property); criteria.add(c); } @Override public boolean retain(Object object) { Object res = Reflector.invokeGetter(object, property); return res == null; } }; }
From source file:com.jeysan.modules.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./*from ww w . j a v a 2s .com*/ */ 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 ww. ja va 2 s.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.CallAPIMessageDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public Long fetchEntitySize(String date, String type) { System.out.println("*******com.jubination.model.dao.CallAPIMessageDAOImpl.fetchEntitySize()"); Long size = 0l;// w w w. j av a2s .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.like("DateCreated", date, MatchMode.START)); 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.like("DateCreated", date, MatchMode.START)); 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.like("DateCreated", date, MatchMode.START)); 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.like("DateCreated", date, MatchMode.START)); 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.like("DateCreated", date, MatchMode.START)); 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.like("DateCreated", date, MatchMode.START)); 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.like("DateCreated", date, MatchMode.START)); 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.like("DateCreated", date, MatchMode.START)); 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.like("DateCreated", date, MatchMode.START)); 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;/* w w w.j ava 2s. c om*/ 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.klistret.cmdb.dao.ElementTypeDAOImpl.java
License:Open Source License
/** * //from w w w.jav a 2 s . c o m * @param name * @return ElementType */ public ElementType get(String name) { logger.debug("Getting element type by composite id [{}]", name); if (name == null) throw new ApplicationException("Name parameter is null", new IllegalArgumentException()); Criteria criteria = getSession().createCriteria(ElementType.class); criteria.add(Restrictions.isNull("toTimeStamp")); criteria.add(Restrictions.eq("name", name)); try { ElementType elementType = (ElementType) criteria.uniqueResult(); if (elementType != null) logger.debug("Found element type [{}]", elementType.toString()); return elementType; } catch (HibernateException e) { throw new InfrastructureException(e.getMessage(), e); } }
From source file:com.klistret.cmdb.dao.ElementTypeDAOImpl.java
License:Open Source License
/** * Uses ILike expression to match by name and the to-timestamp is forced to * be null.//from w w w . j av a 2 s . co m * * @param name * @return List */ @SuppressWarnings("unchecked") public List<ElementType> find(String name) { logger.debug("Finding element type by composite id [{}]", name); if (name == null) throw new ApplicationException("Name parameter is null", new IllegalArgumentException()); try { Criteria query = getSession().createCriteria(ElementType.class); query.add(Restrictions.ilike("name", name)); query.add(Restrictions.isNull("toTimeStamp")); return query.list(); } catch (HibernateException e) { throw new InfrastructureException(e.getMessage(), e); } }
From source file:com.klistret.cmdb.dao.RelationTypeDAOImpl.java
License:Open Source License
/** * Get relation type by composite ID (name) and the to-timestamp is forced * to be null.//from w w w .jav a 2 s. c om * * @param name * relation type * @return RelationType * @throws InfrastructureException * when Hibernate criteria does not return a unique result */ public RelationType get(String name) { logger.debug("Getting relation type by composite id [{}]", name); Criteria criteria = getSession().createCriteria(RelationType.class); criteria.add(Restrictions.isNull("toTimeStamp")); criteria.add(Restrictions.eq("name", name)); try { RelationType relationType = (RelationType) criteria.uniqueResult(); if (relationType != null) logger.debug("Found relation type [{}]", relationType.toString()); return relationType; } catch (HibernateException e) { throw new InfrastructureException(e.getMessage(), e); } }
From source file:com.klistret.cmdb.dao.RelationTypeDAOImpl.java
License:Open Source License
/** * Uses ILike expression to match by name and the to-timestamp is forced to * be null./*from w ww . j a v a 2 s . c o m*/ * * @param name * @return List */ @SuppressWarnings("unchecked") public List<RelationType> find(String name) { logger.debug("Finding relation type by composite id [{}]", name); if (name == null) throw new ApplicationException("Name parameter is null", new IllegalArgumentException()); try { Criteria query = getSession().createCriteria(RelationType.class); query.add(Restrictions.ilike("name", name)); query.add(Restrictions.isNull("toTimeStamp")); return query.list(); } catch (HibernateException e) { throw new InfrastructureException(e.getMessage(), e); } }
From source file:com.klistret.cmdb.utility.hibernate.XPathCriteria.java
License:Open Source License
/** * //from w w w .ja v a2 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)); } }