Example usage for org.hibernate.criterion Junction conditions

List of usage examples for org.hibernate.criterion Junction conditions

Introduction

In this page you can find the example usage for org.hibernate.criterion Junction conditions.

Prototype

List conditions

To view the source code for org.hibernate.criterion Junction conditions.

Click Source Link

Usage

From source file:apm.common.service.DataService.java

License:Open Source License

/**
 * ?/* www  . j a  va 2s . c o  m*/
 * @param user ?UserUtils.getUser()??
 * @param officeAlias ??dc.createAlias("office", "office");
 * @param userAlias ???
 * @return ql
 */
protected static String dataScopeFilterString(User user, String officeAlias, String userAlias) {
    Junction junction = dataScopeFilter(user, officeAlias, userAlias);
    Iterator<Criterion> it = junction.conditions().iterator();
    StringBuilder ql = new StringBuilder();
    ql.append(" and (");
    if (it.hasNext()) {
        ql.append(it.next());
    }
    String[] strField = { ".parentIds like ", ".type=" }; // ????
    while (it.hasNext()) {
        ql.append(" or (");
        String s = it.next().toString();
        for (String field : strField) {
            s = s.replaceAll(field + "(\\w.*)", field + "'$1'");
        }
        ql.append(s).append(")");
    }
    ql.append(")");
    return ql.toString();
}

From source file:com.sccl.attech.common.service.BaseService.java

License:Open Source License

/**
 * ?//  ww w  . j  ava  2s .c  om
 * @param user ?UserUtils.getUser()??
 * @param officeAlias ??dc.createAlias("office", "office");
 * @param userAlias ???
 * @return ql
 */
protected static String dataScopeFilterString(User user, String officeAlias, String userAlias) {

    Junction junction = dataScopeFilter(user, officeAlias, userAlias);
    Iterator<Criterion> it = junction.conditions().iterator();

    StringBuilder ql = new StringBuilder();
    if (it.hasNext()) {
        String[] strField = { ".parentIds like ", ".type=", ".id=" };// ????
        ql.append(" and (");
        if (it.hasNext()) {
            String s = it.next().toString();
            for (String field : strField) {
                s = s.replaceAll(field + "([\\w,%]+)", field + "'$1'");
            }
            ql.append(s);
        }
        while (it.hasNext()) {
            ql.append(" or (");
            String s = it.next().toString();
            for (String field : strField) {
                s = s.replaceAll(field + "([\\w,%]+)", field + "'$1'");
            }
            ql.append(s).append(")");
        }
        ql.append(")");
    }
    return ql.toString();
}