/** * @see org.openmrs.api.PersonService#getRelationshipTypes(java.lang.String, java.lang.Boolean) * @see org.openmrs.api.db.PersonDAO#getRelationshipTypes(java.lang.String, java.lang.Boolean) */ @Override @SuppressWarnings("unchecked") public List<RelationshipType> getRelationshipTypes(String relationshipTypeName, Boolean preferred) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RelationshipType.class); criteria.add(Restrictions.sqlRestriction("CONCAT(a_Is_To_B, CONCAT('/', b_Is_To_A)) like (?)", relationshipTypeName, new StringType())); if (preferred != null) { criteria.add(Restrictions.eq("preferred", preferred)); } return criteria.list(); }
public List findByExample(Object example, String condition, boolean enableLike) { Criteria ec = this.getCurrentSession().createCriteria(example.getClass()); if (enableLike) ec.add(Example.create(example).enableLike()); else ec.add(Example.create(example)); if (condition != null && !condition.equals("")) { String newCondition = condition.replaceAll("`", "'"); ec.add(Restrictions.sqlRestriction(newCondition)); } return ec.list(); }
public Object getMaxByExample(final Object exampleEntity, final String maxProperty, final String condition, final boolean enableLike) { Criteria executableCriteria = this.getCurrentSession().createCriteria(exampleEntity.getClass()); executableCriteria.setProjection(Projections.max(maxProperty)); if (enableLike) { executableCriteria.add(Example.create(exampleEntity).enableLike()); } else { executableCriteria.add(Example.create(exampleEntity)); } if (condition != null && !condition.equals("")) { String newCondition = condition.replaceAll("`", "'"); executableCriteria.add(Restrictions.sqlRestriction(newCondition)); } return executableCriteria.uniqueResult(); } }
/** * Performs an iplike match on the ipAddr column of the current table. * * @param value iplike match * @return SQL restriction for this iplike match */ public static Criterion ipLike(String value) { return Restrictions.sqlRestriction("iplike({alias}.ipAddr, ?)", value, STRING_TYPE); } }
conjunction.add(Restrictions.sqlRestriction("identifier regexp ?", regex, StringType.INSTANCE));
/** * Creates a criterion that is always {@code true}. * * @return the criterion */ public static Criterion alwaysTrue() { return Restrictions.sqlRestriction("1=1"); }
/** * Creates a criterion that is always {@code false}. * * @return the criterion */ public static Criterion alwaysFalse() { return Restrictions.sqlRestriction("0=1"); }
public Criterion buildPredicate(String val, String regexClause) { return Restrictions.sqlRestriction(regexClause, val, StandardBasicTypes.STRING); } },
private static Criterion nullOrEmpty(String propertyName, boolean nullMatters) { if (nullMatters) { return Restrictions.isNull(propertyName); } return Restrictions.sqlRestriction(" 0=0 "); }
/** * Return the semantic predicate with the given Id * * @param predicateId * the id of the predicate * @return semantic predicate */ public SemanticPredicate getSemanticPredicateById(String predicateId){ Criteria criteria = session.createCriteria(SemanticPredicate.class); criteria=criteria.add(Restrictions.sqlRestriction("semanticPredicateId='"+predicateId+"'")); return (SemanticPredicate) criteria.uniqueResult(); }
@Override public void visitIplike(final IplikeRestriction restriction) { String attribute = restriction.getAttribute(); if (Strings.isNullOrEmpty(attribute)) { attribute = "ipAddr"; } final String sql = String.format("ipLike({alias}.%s, ?)", attribute); m_criterions.add(org.hibernate.criterion.Restrictions.sqlRestriction(sql, restriction.getValue(), STRING_TYPE)); } }
@Override public void visitIn(final InRestriction restriction) { if (restriction.getValues() == null || restriction.getValues().size() == 0) { m_criterions.add(org.hibernate.criterion.Restrictions.sqlRestriction("0")); } else { m_criterions.add(org.hibernate.criterion.Restrictions.in(restriction.getAttribute(), restriction.getValues())); } }
@Override public Criterion getFilterLayerModels() { if (getRole() == Role.ADMINISTRATOR) { return null; } else if (getRole() == Role.DESK_MANAGER) { return Restrictions.and(Restrictions.eq("active", true), Restrictions.eq("owner", getTerritory())); } return Restrictions.sqlRestriction("1 = ?", 2, new IntegerType()); }
/** {@inheritDoc} */ @Override public List<OnmsCategory> getCategoriesWithAuthorizedGroup(String groupName) { OnmsCriteria crit = new OnmsCriteria(OnmsCategory.class); crit.add(Restrictions.sqlRestriction("{alias}.categoryId in (select cg.categoryId from category_group cg where cg.groupId = ?)", groupName, StringType.INSTANCE)); return findMatching(crit); } }
@Override public Criterion getHibernateCriterion( QueryPath queryPath ) { String value = caseSensitive ? getValue( String.class ) : getValue( String.class ).toLowerCase(); return Restrictions.sqlRestriction( "c_." + queryPath.getPath() + " !~* '" + TokenUtils.createRegex( value ) + "' " ); }
@Override public Criterion getFilterLayerModels() { if (getRole() == Role.ADMINISTRATOR) { return null; } else if (getRole() == Role.DESK_MANAGER) { return Restrictions.and(Restrictions.eq("active", true), Restrictions.eq("owner", getTerritory())); } return Restrictions.sqlRestriction("1 = ?", 2, new IntegerType()); }
@Override public Criterion getFilterBlueprints() { if (getRole() == Role.ADMINISTRATOR) { return null; } else if (getRole() == Role.DESK_MANAGER) { // You must add an alias for the groups collection or // this // won't // work! return Restrictions.and(Restrictions.eq("active", true), Restrictions.eq("groups.id", getTerritory().getId())); } return Restrictions.sqlRestriction("1 = ?", 2, new IntegerType()); }
private static void addCriteriaForSnmpParm(OnmsCriteria criteria, String snmpParm, String snmpParmValue, String snmpParmMatchType) { criteria.createAlias("node.ipInterfaces", "ipInterface"); criteria.add(Restrictions.ne("ipInterface.isManaged", "D")); criteria.createAlias("node.snmpInterfaces", "snmpInterface"); criteria.add(Restrictions.ne("snmpInterface.collect", "D")); if(snmpParmMatchType.equals("contains")) { criteria.add(Restrictions.ilike("snmpInterface.".concat(snmpParm), snmpParmValue, MatchMode.ANYWHERE)); } else if(snmpParmMatchType.equals("equals")) { snmpParmValue = snmpParmValue.toLowerCase(); criteria.add(Restrictions.sqlRestriction("{alias}.nodeid in (select nodeid from snmpinterface where snmpcollect != 'D' and lower(snmp" + snmpParm + ") = '" + snmpParmValue + "')")); } }
private static void addCriteriaForSnmpParm(OnmsCriteria criteria, String snmpParm, String snmpParmValue, String snmpParmMatchType) { criteria.createAlias("node.ipInterfaces", "ipInterface"); criteria.add(Restrictions.ne("ipInterface.isManaged", "D")); criteria.createAlias("node.snmpInterfaces", "snmpInterface"); criteria.add(Restrictions.ne("snmpInterface.collect", "D")); if(snmpParmMatchType.equals("contains")) { criteria.add(Restrictions.ilike("snmpInterface.".concat(snmpParm), snmpParmValue, MatchMode.ANYWHERE)); } else if(snmpParmMatchType.equals("equals")) { snmpParmValue = snmpParmValue.toLowerCase(); criteria.add(Restrictions.sqlRestriction("{alias}.nodeid in (select nodeid from snmpinterface where snmpcollect != 'D' and lower(snmp" + snmpParm + ") = '" + snmpParmValue + "')")); } }
private void addCriteriaForSiteStatusView(OnmsCriteria criteria, String statusViewName, String statusSite, String rowLabel) { View view = m_siteStatusViewConfigDao.getView(statusViewName); RowDef rowDef = getRowDef(view, rowLabel); Set<String> categoryNames = getCategoryNamesForRowDef(rowDef); addCriteriaForCategories(criteria, categoryNames.toArray(new String[categoryNames.size()])); String sql = "{alias}.nodeId in (select nodeId from assets where " + view.getColumnName() + " = ?)"; criteria.add(Restrictions.sqlRestriction(sql, statusSite, new StringType())); }