Example usage for org.hibernate.criterion Restrictions disjunction

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

Introduction

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

Prototype

public static Disjunction disjunction() 

Source Link

Document

Group expressions together in a single disjunction (A or B or C...).

Usage

From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateFilter.java

License:Open Source License

public void applyDisjunction(List filterElements) {
    Disjunction disjunction = Restrictions.disjunction();
    applyJunction(filterElements, disjunction);
}

From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.util.ResourceCriterionUtils.java

License:Open Source License

/**
 * Creates text criterion which allows to search occurrence of each word of the text in some of the possible
 * targeted properties of the resource. Example:
 * let say we have "Hello World" text to search resources by. In this case each word can be either in label or in
 * description. The SQL for this criterion should be:
 * (lower(label) like "hello" or lower(description) like "hello") &&
 * (lower(label) like "world" or lower(description) like "world")
 *
 * @param text the text to search./*from  w  ww.j a  v  a2  s  .  c om*/
 * @return text criterion.
 */
public static Criterion getTextCriterion(String text) {
    String[] words = text.trim().split("\\s+");

    Conjunction wordsCriterion = Restrictions.conjunction();

    for (String word : words) {
        Disjunction wordCriterion = Restrictions.disjunction();

        // Each word should be in label or in description.
        wordCriterion.add(new IlikeEscapeAwareExpression("label", word, MatchMode.ANYWHERE));
        wordCriterion.add(new IlikeEscapeAwareExpression("description", word, MatchMode.ANYWHERE));

        // Resource should contain all the words.
        wordsCriterion.add(wordCriterion);
    }

    return wordsCriterion;
}

From source file:com.jaspersoft.jasperserver.api.metadata.tenant.service.impl.TenantServiceImpl.java

License:Open Source License

private DetachedCriteria createSubTenantsCriteria(RepoTenant parentTenant, String text, int depth) {
    DetachedCriteria criteria = DetachedCriteria.forClass(persistentTenantClass());
    String value = "/%";

    if ("/".equals(parentTenant.getTenantUri())) {
        /* Excluding root parent from sub list. */
        criteria.add(Restrictions.ne("tenantId", parentTenant.getTenantId()));
    } else {//from  w  w w .  j a  v  a2  s  . com
        value = parentTenant.getTenantUri() + value;
    }

    criteria.add(Restrictions.like("tenantUri", value));

    if (depth > 0) {
        StringBuilder boundary = new StringBuilder(value);
        for (; depth > 0; depth--) {
            boundary.append("/%");
        }
        criteria.add(Restrictions.not(Restrictions.like("tenantUri", boundary.toString())));
    }

    if (text != null) {
        text = databaseCharactersEscapeResolver.getEscapedText(text.trim());
        if (text.length() > 0) {
            Disjunction disjunction = Restrictions.disjunction();

            disjunction.add(new IlikeEscapeAwareExpression("tenantId", text, MatchMode.ANYWHERE));
            disjunction.add(new IlikeEscapeAwareExpression("tenantAlias", text, MatchMode.ANYWHERE));
            disjunction.add(new IlikeEscapeAwareExpression("tenantName", text, MatchMode.ANYWHERE));
            disjunction.add(new IlikeEscapeAwareExpression("tenantDesc", text, MatchMode.ANYWHERE));

            criteria.add(disjunction);
        }
    }
    return criteria;
}

From source file:com.jaspersoft.jasperserver.api.metadata.tenant.service.impl.TenantServiceImpl.java

License:Open Source License

private DetachedCriteria createSearchTenantsCriteria(String parentTenantId, String text) {
    DetachedCriteria criteria = DetachedCriteria.forClass(persistentTenantClass());

    criteria.createAlias("parent", "p");
    criteria.add(Restrictions.naturalId().set("p.tenantId", parentTenantId));

    if (text != null) {
        text = databaseCharactersEscapeResolver.getEscapedText(text.trim());
        if (text.length() > 0) {
            Disjunction disjunction = Restrictions.disjunction();

            //                disjunction.add(Restrictions.ilike("tenantId", "%" + text + "%"));
            //                disjunction.add(Restrictions.ilike("tenantAlias", "%" + text + "%"));
            //                disjunction.add(Restrictions.ilike("tenantName", "%" + text + "%"));
            //                disjunction.add(Restrictions.ilike("tenantDesc", "%" + text + "%"));

            disjunction.add(new IlikeEscapeAwareExpression("tenantId", text, MatchMode.ANYWHERE));
            disjunction.add(new IlikeEscapeAwareExpression("tenantAlias", text, MatchMode.ANYWHERE));
            disjunction.add(new IlikeEscapeAwareExpression("tenantName", text, MatchMode.ANYWHERE));
            disjunction.add(new IlikeEscapeAwareExpression("tenantDesc", text, MatchMode.ANYWHERE));

            criteria.add(disjunction);//from  w ww.jav a2s  .  c  o  m
        }
    }

    return criteria;
}

From source file:com.jaspersoft.jasperserver.search.filter.ScheduleFilter.java

License:Open Source License

private void createCriteria(SearchCriteria criteria, User user, boolean scheduled, boolean scheduledByUser) {
    SearchCriteria uriCriteria = SearchCriteria.forClass(PersistentReportJob.class);
    if (scheduledByUser) {
        addOwnerCriteria(uriCriteria, user);
    }//  w  w w .  ja  va 2  s  .  co  m
    uriCriteria.addProjection(Projections.property("source.reportUnitURI"));
    List uriList = getHibernateTemplate().findByCriteria(uriCriteria);

    if (!uriList.isEmpty()) {
        SearchCriteria idCriteria = SearchCriteria.forClass(RepoResource.class);
        Disjunction disjunction = Restrictions.disjunction();
        String alias = idCriteria.getAlias("parent", "p");
        for (Object o : uriList) {
            String uri = (String) o;

            disjunction.add(getResourceCriterion(alias, uri));
        }

        idCriteria.add(disjunction);
        idCriteria.addProjection(Projections.id());

        List idList = getHibernateTemplate().findByCriteria(idCriteria);

        if (!idList.isEmpty()) {
            if (scheduled) {
                criteria.add(Restrictions.in("id", idList));
            } else {
                criteria.add(Restrictions.not(Restrictions.in("id", idList)));
            }
        } else {
            throw new RuntimeException("No resources found for URI list " + uriList);
        }
    } else {
        if (scheduled || scheduledByUser) {
            criteria.add(Restrictions.isNull("id"));
        }
    }
}

From source file:com.jeysan.modules.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ?Criterion,./*from   ww w.java 2  s. c om*/
 */
protected Criterion[] buildCriterionByPropertyFilter(final List<PropertyFilter> filters) {
    if (filters == null || filters.size() == 0)
        return new Criterion[] {};
    List<Criterion> criterionList = new ArrayList<Criterion>();
    for (PropertyFilter filter : filters) {
        if (filter == null)
            continue;
        if (!filter.hasMultiProperties()) { //??.
            Criterion criterion = buildCriterion(filter.getPropertyName(), filter.getMatchValue(),
                    filter.getMatchType());
            criterionList.add(criterion);
        } else {//??,or?.
            Disjunction disjunction = Restrictions.disjunction();
            for (String param : filter.getPropertyNames()) {
                Criterion criterion = buildCriterion(param, filter.getMatchValue(), filter.getMatchType());
                disjunction.add(criterion);
            }
            criterionList.add(disjunction);
        }
    }
    return criterionList.toArray(new Criterion[criterionList.size()]);
}

From source file:com.kodemore.hibernate.criteria.KmAbstractCriteria.java

License:Open Source License

public KmJunction addOr() {
    Junction j = Restrictions.disjunction();
    _add(j);
    return new KmJunction(this, j);
}

From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java

License:Open Source License

protected void addSearchByUserRolesCriterion(Criteria criteria, Boolean searchByUserRoles,
        ServiceContext serviceContext) throws SystemException {

    if (searchByUserRoles == null) {
        return;//from   w w w. j av  a  2s .c  o  m
    }

    Criteria assigneesCriteria = criteria.createCriteria("assignees");

    if (!searchByUserRoles) {
        assigneesCriteria.add(Restrictions.eq("assigneeClassName", User.class.getName()));
        assigneesCriteria.add(Restrictions.eq("assigneeClassPK", serviceContext.getUserId()));

        return;
    }

    List<Long> roleIds = RoleRetrievalUtil.getRoleIds(serviceContext);

    List<UserGroupRole> userGroupRoles = UserGroupRoleLocalServiceUtil
            .getUserGroupRoles(serviceContext.getUserId());

    if (userGroupRoles.isEmpty()) {
        assigneesCriteria.add(Restrictions.eq("assigneeClassName", Role.class.getName()));
        assigneesCriteria.add(Restrictions.in("assigneeClassPK", roleIds.toArray(new Long[roleIds.size()])));
    } else {
        Junction junction = Restrictions.disjunction();

        junction.add(Restrictions.and(Restrictions.eq("assigneeClassName", Role.class.getName()),
                Restrictions.in("assigneeClassPK", roleIds.toArray(new Long[roleIds.size()]))));

        for (UserGroupRole userGroupRole : userGroupRoles) {
            junction.add(Restrictions.and(Restrictions.eq("groupId", userGroupRole.getGroupId()),
                    Restrictions.and(Restrictions.eq("assigneeClassName", Role.class.getName()),
                            Restrictions.eq("assigneeClassPK", userGroupRole.getRoleId()))));
        }

        assigneesCriteria.add(junction);
    }
}

From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java

License:Open Source License

protected Criteria buildTaskInstanceExtensionSearchCriteria(String taskName, String assetType,
        Long[] assetPrimaryKeys, Date dueDateGT, Date dueDateLT, Boolean completed, Boolean searchByUserRoles,
        boolean andOperator, ServiceContext serviceContext) throws SystemException {

    Criteria criteria = _session.createCriteria(TaskInstanceExtensionImpl.class);

    criteria.createAlias("taskInstance", "taskInstance");

    criteria.add(Restrictions.eq("companyId", serviceContext.getCompanyId()));

    if (Validator.isNotNull(taskName) || Validator.isNotNull(assetType) || (dueDateGT != null)
            || (dueDateLT != null)) {/*from  w  w w .ja  va2  s.com*/

        Junction junction = null;

        if (andOperator) {
            junction = Restrictions.conjunction();
        } else {
            junction = Restrictions.disjunction();
        }

        if (Validator.isNotNull(taskName)) {
            String[] taskNameKeywords = StringUtil.split(taskName, StringPool.SPACE);

            for (String taskNameKeyword : taskNameKeywords) {
                junction.add(Restrictions.like("taskInstance.name", "%" + taskNameKeyword + "%"));
            }
        }

        if (Validator.isNotNull(assetType)) {
            String[] assetTypeKeywords = StringUtil.split(assetType, StringPool.SPACE);

            for (String assetTypeKeyword : assetTypeKeywords) {
                junction.add(
                        Restrictions.like("workflowContext", "%\"entryType\":\"%" + assetTypeKeyword + "%\"%"));
            }
        }

        if (Validator.isNotNull(assetPrimaryKeys)) {
            for (Long assetPrimaryKey : assetPrimaryKeys) {
                junction.add(Restrictions.like("workflowContext",
                        "%\"entryClassPK\":\"%" + assetPrimaryKey + "%\"%"));
            }
        }

        if (dueDateGT != null) {
            junction.add(Restrictions.ge("taskInstance.dueDate", dueDateGT));
        }

        if (dueDateLT != null) {
            junction.add(Restrictions.lt("taskInstance.dueDate", dueDateGT));
        }

        criteria.add(junction);
    }

    addSearchByUserRolesCriterion(criteria, searchByUserRoles, serviceContext);

    if (completed != null) {
        if (completed.booleanValue()) {
            criteria.add(Restrictions.isNotNull("taskInstance.end"));
        } else {
            criteria.add(Restrictions.isNull("taskInstance.end"));
        }
    }

    return criteria;
}

From source file:com.liferay.portal.workflow.jbpm.WorkflowLogManagerImpl.java

License:Open Source License

protected void addLogTypesJunction(Criteria criteria, List<Integer> logTypes) {

    if ((logTypes == null) || logTypes.isEmpty()) {
        return;/*from   w w w . j  a v  a  2s  . c  o m*/
    }

    Junction junction = Restrictions.disjunction();

    for (Integer logType : logTypes) {
        junction.add(Restrictions.eq("type", logType));
    }

    criteria.add(junction);
}