Example usage for org.hibernate.criterion Restrictions and

List of usage examples for org.hibernate.criterion Restrictions and

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions and.

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:net.firejack.platform.core.store.registry.ResourceLocationStore.java

License:Apache License

@Override
@Transactional(readOnly = true)/*w w  w .  j  ava  2  s.co m*/
public List<ResourceLocationModel> findAllBySearchTermWithFilter(List<Long> registryNodeIds, String term,
        SpecifiedIdsFilter<Long> filter, Paging paging) {
    List<Criterion> criterionList = new ArrayList<Criterion>();
    Criterion registryNodeIdCriterion = Restrictions.in("parent.id", registryNodeIds);
    Criterion nameCriterion = Restrictions.like("lookup", "%" + term + "%");
    LogicalExpression expressionAll = Restrictions.and(registryNodeIdCriterion, nameCriterion);
    criterionList.add(expressionAll);
    return findAllWithFilter(criterionList, filter, paging);
}

From source file:net.firejack.platform.core.store.registry.RoleStore.java

License:Apache License

@Override
@Transactional(readOnly = true)/*from  ww  w.  ja  v a2 s.co  m*/
public List<RoleModel> findAllBySearchTermWithFilter(List<Long> registryNodeIds, String term,
        SpecifiedIdsFilter<Long> filter, boolean isGlobalOnly) {
    List<Criterion> criterions = new ArrayList<Criterion>();
    Map<String, String> alias = new HashMap<String, String>();
    if (isGlobalOnly) {
        Criterion globalRoleCriterion = Restrictions.in("parent.class", new String[] { "DOM", "PKG" });
        alias.put("parent", "parent");
        criterions.add(globalRoleCriterion);
    }
    Criterion registryNodeIdCriterion = Restrictions.in("parent.id", registryNodeIds);
    Criterion nameCriterion = Restrictions.like("lookup", StringUtils.isBlank(term) ? "%" : "%" + term + "%");
    LogicalExpression expressionAll = Restrictions.and(registryNodeIdCriterion, nameCriterion);
    criterions.add(expressionAll);
    List<RoleModel> roles = findAllWithFilter(criterions, alias, filter);
    removePermissions(roles);
    return roles;
}

From source file:net.firejack.platform.core.store.registry.RoleStore.java

License:Apache License

@Override
public List<RoleModel> findAllBySearchTermWithFilter(List<Long> registryNodeIds, String term,
        SpecifiedIdsFilter<Long> filter, Paging paging) {
    List<Criterion> criterions = new ArrayList<Criterion>();
    Criterion registryNodeIdCriterion = Restrictions.in("parent.id", registryNodeIds);
    Criterion nameCriterion = Restrictions.like("lookup", '%' + term + '%');
    LogicalExpression expressionAll = Restrictions.and(registryNodeIdCriterion, nameCriterion);
    criterions.add(expressionAll);//  ww  w .j  a va2 s . c o  m
    return findAllWithFilter(criterions, filter, paging);
}

From source file:net.firejack.platform.core.store.registry.ScheduleStore.java

License:Apache License

@Override
@Transactional(readOnly = true)//from   ww  w  . ja  v  a  2  s  .  co  m
public List<ScheduleModel> findAllBySearchTermWithFilter(List<Long> registryNodeIds, String term,
        SpecifiedIdsFilter<Long> filter) {
    List<Criterion> criterions = new ArrayList<Criterion>();
    Criterion registryNodeIdCriterion = Restrictions.in("parent.id", registryNodeIds);
    Criterion nameCriterion = Restrictions.like("lookup", "%" + term + "%");
    LogicalExpression expressionAll = Restrictions.and(registryNodeIdCriterion, nameCriterion);
    criterions.add(expressionAll);
    return findAllWithFilter(criterions, filter);
}

From source file:net.firejack.platform.core.store.user.BaseUserStore.java

License:Apache License

@Override
@Transactional(readOnly = true)//from   w  w  w .  ja  v a2s.c  o m
public List<M> findAllByRegistryNodeIdsAndSearchTermWithFilter(List<Long> registryNodeIds, String term,
        SpecifiedIdsFilter<Long> filter) {
    List<Criterion> criterions = new ArrayList<Criterion>();
    Criterion usernameCriterion = Restrictions.like("username", "%" + term + "%");
    Criterion emailCriterion = Restrictions.like("email", "%" + term + "%");
    Criterion firstNameCriterion = Restrictions.like("firstName", "%" + term + "%");
    Criterion lastNameCriterion = Restrictions.like("lastName", "%" + term + "%");
    LogicalExpression expression1 = Restrictions.or(usernameCriterion, emailCriterion);
    LogicalExpression expression2 = Restrictions.or(firstNameCriterion, lastNameCriterion);
    LogicalExpression expression = Restrictions.or(expression1, expression2);
    if (registryNodeIds != null) {
        Criterion registryNodeIdCriterion = Restrictions.in("registryNode.id", registryNodeIds);
        LogicalExpression expressionAll = Restrictions.and(registryNodeIdCriterion, expression);
        criterions.add(expressionAll);
    } else {
        criterions.add(expression);
    }
    return findAllWithFilter(criterions, filter);
}

From source file:net.firejack.platform.core.store.user.BaseUserStore.java

License:Apache License

@Override
@Transactional(readOnly = true)//from w w w.  j a v a 2  s  . c  o m
public List<M> findAllByRegistryNodeIdsAndSearchTermWithFilter(List<Long> registryNodeIds, String term,
        SpecifiedIdsFilter<Long> filter, Integer offset, Integer limit, Order... orders) {
    List<Criterion> criterions = new ArrayList<Criterion>();
    Criterion usernameCriterion = Restrictions.like("username", "%" + term + "%");
    Criterion emailCriterion = Restrictions.like("email", "%" + term + "%");
    Criterion firstNameCriterion = Restrictions.like("firstName", "%" + term + "%");
    Criterion lastNameCriterion = Restrictions.like("lastName", "%" + term + "%");
    LogicalExpression expression1 = Restrictions.or(usernameCriterion, emailCriterion);
    LogicalExpression expression2 = Restrictions.or(firstNameCriterion, lastNameCriterion);
    LogicalExpression expression = Restrictions.or(expression1, expression2);
    if (registryNodeIds != null) {
        Criterion registryNodeIdCriterion = Restrictions.in("registryNode.id", registryNodeIds);
        LogicalExpression expressionAll = Restrictions.and(registryNodeIdCriterion, expression);
        criterions.add(expressionAll);
    } else {
        criterions.add(expression);
    }
    return findAllWithFilter(offset, limit, criterions, filter, orders);
}

From source file:net.firejack.platform.service.process.broker.ReadPreviousActivitiesBroker.java

License:Apache License

@Override
protected ServiceResponse<Activity> perform(ServiceRequest<NamedValues<Long>> request) throws Exception {
    Long caseId = request.getData().get(PARAM_CASE_ID);
    Long taskId = request.getData().get(PARAM_TASK_ID);
    ServiceResponse<Activity> response;
    if (caseId == null && taskId == null) {
        response = new ServiceResponse<Activity>("taskId or caseId parameter should be specified.", false);
    } else {//w w  w. ja  va2s  .  co m
        Integer currentActivityPosition = null;
        ProcessModel process = null;
        if (taskId == null) {
            CaseModel caseModel = caseStore.findById(caseId);
            if (caseModel != null) {
                currentActivityPosition = caseModel.getStatus().getSortPosition();
                process = caseModel.getProcess();
            }
        } else {
            TaskModel taskModel = taskStore.findById(taskId);
            if (taskModel != null) {
                currentActivityPosition = taskModel.getActivity().getSortPosition();
                process = taskModel.getCase().getProcess();
            }
        }
        if (currentActivityPosition == null || process == null) {
            response = new ServiceResponse<Activity>("Wrong taskId or caseId parameter value.", false);
        } else {
            LinkedList<Criterion> criterionList = new LinkedList<Criterion>();
            criterionList.add(Restrictions.and(Restrictions.lt("sortPosition", currentActivityPosition),
                    Restrictions.eq("parent.id", process.getId())));
            List<ActivityModel> previousActivities = store.search(criterionList, null);
            if (previousActivities == null || previousActivities.isEmpty()) {
                response = new ServiceResponse<Activity>("No previous activities are available", true);
            } else {
                Boolean multiBranchStrategySupported = taskCaseProcessor
                        .getMultiBranchStrategy(process.getLookup());
                if (Boolean.TRUE.equals(multiBranchStrategySupported)) {
                    List<Activity> activities = factory.convertTo(Activity.class, previousActivities);
                    response = new ServiceResponse<Activity>(activities, "Success", true);
                } else {
                    Activity activity = factory.convertTo(Activity.class, previousActivities.get(0));
                    response = new ServiceResponse<Activity>(activity, "Success", true);
                }
            }
        }
    }
    return response;
}

From source file:net.seedboxer.core.persistence.impl.HibernateContentDao.java

License:Open Source License

@Override
public <T extends Content> List<T> getHistoryContentsFilteredByNameAndUser(Class<T> clazz, String name,
        User user) {/*  w w  w.  j a  va  2 s  .  c  o  m*/
    Criteria criteria = getCurrentSession().createCriteria(clazz);
    Criterion rest1 = Restrictions.and(Restrictions.eq("name", name), Restrictions.eq("history", true));
    rest1 = Restrictions.and(rest1, Restrictions.eq("user", user));
    criteria.add(rest1);
    return criteria.list();
}

From source file:net.webpasswordsafe.server.dao.PasswordDAOHibernate.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<Password> findPasswordByFuzzySearch(String query, User user, boolean activeOnly,
        Collection<Tag> tags, Match tagMatch) {
    //kludge to not use ilike on text column if MSSQL
    boolean isMSSQL = ((SessionFactoryImpl) getSessionFactory()).getDialect().toString().contains("SQLServer");
    Criteria crit = getSession().createCriteria(getPersistentClass());
    crit.setFetchMode("tags", FetchMode.JOIN);
    crit.add(Restrictions.or(//from  ww w  .j a  va2 s. c o  m
            Restrictions.or(Restrictions.ilike("name", query, MatchMode.ANYWHERE),
                    Restrictions.ilike("username", query, MatchMode.ANYWHERE)),
            isMSSQL ? Restrictions.like("notes", query, MatchMode.ANYWHERE)
                    : Restrictions.ilike("notes", query, MatchMode.ANYWHERE)));
    if (activeOnly) {
        crit.add(Restrictions.eq("active", true));
    }
    Criterion tagsCriterion = null;
    for (Tag tag : tags) {
        Criterion tc = Restrictions.sqlRestriction(
                "? in (select tag_id from password_tags where password_id = {alias}.id)", tag.getId(),
                StandardBasicTypes.LONG);
        if (null == tagsCriterion) {
            tagsCriterion = tc;
        } else {
            tagsCriterion = tagMatch.equals(Match.AND) ? Restrictions.and(tagsCriterion, tc)
                    : Restrictions.or(tagsCriterion, tc);
        }
    }
    if (tagsCriterion != null)
        crit.add(tagsCriterion);
    crit.createAlias("permissions", "pm");
    crit.add(Restrictions.in("pm.accessLevel",
            new String[] { AccessLevel.READ.name(), AccessLevel.WRITE.name(), AccessLevel.GRANT.name() }));
    if (!authorizer.isAuthorized(user, Function.BYPASS_PASSWORD_PERMISSIONS.name())) {
        DetachedCriteria groupQuery = DetachedCriteria.forClass(Group.class);
        groupQuery.setProjection(Projections.id());
        groupQuery.createCriteria("users", "u").add(Restrictions.eq("u.id", user.getId()));
        crit.add(Restrictions.or(Restrictions.eq("pm.subject", user),
                Subqueries.propertyIn("pm.subject", groupQuery)));
    }
    crit.addOrder(Order.asc("name"));
    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return crit.list();
}

From source file:net.webpasswordsafe.server.dao.PasswordDAOHibernate.java

License:Open Source License

@Override
public Password findPasswordByName(String passwordName, String username) {
    List<Password> passwords = findByCriteria(
            Restrictions.and(Restrictions.eq("name", passwordName), Restrictions.eq("username", username)));
    return (passwords.size() > 0) ? passwords.get(0) : null;
}