本文整理了Java中org.hibernate.criterion.Restrictions.sqlRestriction
方法的一些代码示例,展示了Restrictions.sqlRestriction
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Restrictions.sqlRestriction
方法的具体详情如下:
包路径:org.hibernate.criterion.Restrictions
类名称:Restrictions
方法名:sqlRestriction
[英]Apply a constraint expressed in SQL with no JDBC parameters. Any occurrences of {alias} will be replaced by the table alias.
[中]应用用SQL表示的约束,不带JDBC参数。任何出现的{alias}都将替换为表别名。
代码示例来源:origin: openmrs/openmrs-core
/**
* @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();
}
代码示例来源:origin: bill1012/AdminEAP
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();
}
代码示例来源:origin: bill1012/AdminEAP
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();
}
}
代码示例来源:origin: OpenNMS/opennms
/**
* 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);
}
}
代码示例来源:origin: openmrs/openmrs-core
conjunction.add(Restrictions.sqlRestriction("identifier regexp ?", regex, StringType.INSTANCE));
代码示例来源:origin: org.n52.series-api.db/dao
/**
* Creates a criterion that is always {@code true}.
*
* @return the criterion
*/
public static Criterion alwaysTrue() {
return Restrictions.sqlRestriction("1=1");
}
代码示例来源:origin: org.n52.series-api.db/dao
/**
* Creates a criterion that is always {@code false}.
*
* @return the criterion
*/
public static Criterion alwaysFalse() {
return Restrictions.sqlRestriction("0=1");
}
代码示例来源:origin: DSpace/DSpace
public Criterion buildPredicate(String val, String regexClause) {
return Restrictions.sqlRestriction(regexClause, val, StandardBasicTypes.STRING);
}
},
代码示例来源:origin: pl.edu.icm.sedno/sedno-tools
private static Criterion nullOrEmpty(String propertyName, boolean nullMatters) {
if (nullMatters) {
return Restrictions.isNull(propertyName);
}
return Restrictions.sqlRestriction(" 0=0 ");
}
代码示例来源:origin: de.tudarmstadt.ukp.uby/de.tudarmstadt.ukp.uby.lmf.api-asl
/**
* 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();
}
代码示例来源:origin: OpenNMS/opennms
@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));
}
}
代码示例来源:origin: OpenNMS/opennms
@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()));
}
}
代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-deskmanager
@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());
}
代码示例来源:origin: OpenNMS/opennms
/** {@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);
}
}
代码示例来源:origin: dhis2/dhis2-core
@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 ) + "' " );
}
代码示例来源:origin: org.geomajas/geomajas-project-deskmanager
@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());
}
代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-deskmanager
@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());
}
代码示例来源:origin: OpenNMS/opennms
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 + "')"));
}
}
代码示例来源:origin: org.opennms/opennms-web-api
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 + "')"));
}
}
代码示例来源:origin: OpenNMS/opennms
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()));
}
内容来源于网络,如有侵权,请联系作者删除!