Example usage for org.hibernate.criterion Restrictions conjunction

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

Introduction

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

Prototype

public static Conjunction conjunction() 

Source Link

Document

Group expressions together in a single conjunction (A and B and C...).

Usage

From source file:com.eucalyptus.simpleworkflow.SimpleWorkflowService.java

License:Open Source License

public DomainInfos listDomains(final ListDomainsRequest request) throws SimpleWorkflowException {
    final DomainInfos domainInfos = new DomainInfos();
    final Context ctx = Contexts.lookup();
    final AccountFullName accountFullName = ctx.getUserFullName().asAccountFullName();
    final Predicate<? super Domain> requestedAndAccessible = SimpleWorkflowMetadatas.filteringFor(Domain.class)
            .byProperty(Optional.fromNullable(request.getRegistrationStatus()).asSet(),
                    Domains.StringFunctions.REGISTRATION_STATUS)
            .byPrivileges().buildPredicate();
    try {/* w  ww. j  a  v a2s. c o  m*/
        domainInfos.getDomainInfos()
                .addAll(domains.list(accountFullName, Restrictions.conjunction(),
                        Collections.<String, String>emptyMap(), requestedAndAccessible,
                        TypeMappers.lookup(Domain.class, DomainInfo.class)));
    } catch (Exception e) {
        throw handleException(e);
    }
    return request.reply(domainInfos);
}

From source file:com.eucalyptus.simpleworkflow.SimpleWorkflowService.java

License:Open Source License

public WorkflowExecutionCount countClosedWorkflowExecutions(final CountClosedWorkflowExecutionsRequest request)
        throws SimpleWorkflowException {
    final Context ctx = Contexts.lookup();
    final UserFullName userFullName = ctx.getUserFullName();
    final AccountFullName accountFullName = userFullName.asAccountFullName();
    final Predicate<? super Domain> accessible = SimpleWorkflowMetadatas.filteringFor(Domain.class)
            .byPrivileges().buildPredicate();

    final WorkflowExecutionCount workflowExecutionCount;
    try {/*from   w w w  .j  av a2 s.  c o m*/
        workflowExecutionCount = domains.lookupByExample(
                Domain.exampleWithName(accountFullName, request.getDomain()), accountFullName,
                request.getDomain(), accessible, new Function<Domain, WorkflowExecutionCount>() {
                    @Override
                    public WorkflowExecutionCount apply(final Domain domain) {
                        final Conjunction filter = Restrictions.conjunction();
                        final Map<String, String> aliases = Maps.newHashMap();
                        buildFilters(request, filter, aliases);
                        return new WorkflowExecutionCount()
                                .withCount((int) Entities.count(WorkflowExecution.exampleForClosedWorkflow(
                                        accountFullName, request.getDomain(), null), filter, aliases))
                                .withTruncated(false);
                    }
                });
    } catch (SwfMetadataNotFoundException e) {
        throw new SimpleWorkflowClientException("UnknownResourceFault",
                "Unknown domain, name = " + request.getDomain());
    } catch (Exception e) {
        throw handleException(e);
    }

    return request.reply(workflowExecutionCount);
}

From source file:com.eucalyptus.simpleworkflow.SimpleWorkflowService.java

License:Open Source License

public WorkflowExecutionCount countOpenWorkflowExecutions(final CountOpenWorkflowExecutionsRequest request)
        throws SimpleWorkflowException {
    final Context ctx = Contexts.lookup();
    final UserFullName userFullName = ctx.getUserFullName();
    final AccountFullName accountFullName = userFullName.asAccountFullName();
    final Predicate<? super Domain> accessible = SimpleWorkflowMetadatas.filteringFor(Domain.class)
            .byPrivileges().buildPredicate();

    final WorkflowExecutionCount workflowExecutionCount;
    try {/*from   w  w w  . j a va 2  s.  c om*/
        workflowExecutionCount = domains.lookupByExample(
                Domain.exampleWithName(accountFullName, request.getDomain()), accountFullName,
                request.getDomain(), accessible, new Function<Domain, WorkflowExecutionCount>() {
                    @Override
                    public WorkflowExecutionCount apply(final Domain domain) {
                        final Conjunction filter = Restrictions.conjunction();
                        final Map<String, String> aliases = Maps.newHashMap();
                        buildFilters(request, filter, aliases);
                        return new WorkflowExecutionCount()
                                .withCount((int) Entities.count(WorkflowExecution.exampleForOpenWorkflow(
                                        accountFullName, request.getDomain(), null), filter, aliases))
                                .withTruncated(false);
                    }
                });
    } catch (SwfMetadataNotFoundException e) {
        throw new SimpleWorkflowClientException("UnknownResourceFault",
                "Unknown domain, name = " + request.getDomain());
    } catch (Exception e) {
        throw handleException(e);
    }

    return request.reply(workflowExecutionCount);
}

From source file:com.eucalyptus.simpleworkflow.SimpleWorkflowService.java

License:Open Source License

public WorkflowExecutionInfos listClosedWorkflowExecutions(final ListClosedWorkflowExecutionsRequest request)
        throws SimpleWorkflowException {
    final Context ctx = Contexts.lookup();
    final UserFullName userFullName = ctx.getUserFullName();
    final AccountFullName accountFullName = userFullName.asAccountFullName();
    final Predicate<? super WorkflowExecution> accessible = SimpleWorkflowMetadatas
            .filteringFor(WorkflowExecution.class).byPrivileges().buildPredicate();

    final WorkflowExecutionInfos workflowExecutionInfos = new WorkflowExecutionInfos();
    try {/*from  w ww .j av  a2  s  .c  om*/
        final Conjunction filter = Restrictions.conjunction();
        final Map<String, String> aliases = Maps.newHashMap();
        buildFilters(request, filter, aliases);
        workflowExecutionInfos.getExecutionInfos()
                .addAll(workflowExecutions.listByExample(
                        WorkflowExecution.exampleForClosedWorkflow(accountFullName, request.getDomain(), null),
                        accessible, filter, aliases,
                        TypeMappers.lookup(WorkflowExecution.class, WorkflowExecutionInfo.class)));
        final Ordering<WorkflowExecutionInfo> ordering = Ordering.natural()
                .onResultOf(WorkflowExecutions.WorkflowExecutionInfoDateFunctions.START_TIMESTAMP);
        Collections.sort(workflowExecutionInfos.getExecutionInfos(),
                Objects.firstNonNull(request.getReverseOrder(), Boolean.FALSE) ? ordering.reverse() : ordering);
    } catch (Exception e) {
        throw handleException(e);
    }
    return request.reply(workflowExecutionInfos);
}

From source file:com.eucalyptus.simpleworkflow.SimpleWorkflowService.java

License:Open Source License

public WorkflowExecutionInfos listOpenWorkflowExecutions(final ListOpenWorkflowExecutionsRequest request)
        throws SimpleWorkflowException {
    final Context ctx = Contexts.lookup();
    final UserFullName userFullName = ctx.getUserFullName();
    final AccountFullName accountFullName = userFullName.asAccountFullName();
    final Predicate<? super WorkflowExecution> accessible = SimpleWorkflowMetadatas
            .filteringFor(WorkflowExecution.class).byPrivileges().buildPredicate();

    final WorkflowExecutionInfos workflowExecutionInfos = new WorkflowExecutionInfos();
    try {/*from   w  w  w.j ava  2s. c om*/
        final Conjunction filter = Restrictions.conjunction();
        final Map<String, String> aliases = Maps.newHashMap();
        buildFilters(request, filter, aliases);
        workflowExecutionInfos.getExecutionInfos()
                .addAll(workflowExecutions.listByExample(
                        WorkflowExecution.exampleForOpenWorkflow(accountFullName, request.getDomain(), null),
                        accessible, filter, aliases,
                        TypeMappers.lookup(WorkflowExecution.class, WorkflowExecutionInfo.class)));
        final Ordering<WorkflowExecutionInfo> ordering = Ordering.natural()
                .onResultOf(WorkflowExecutions.WorkflowExecutionInfoDateFunctions.START_TIMESTAMP);
        Collections.sort(workflowExecutionInfos.getExecutionInfos(),
                Objects.firstNonNull(request.getReverseOrder(), Boolean.FALSE) ? ordering.reverse() : ordering);
    } catch (Exception e) {
        throw handleException(e);
    }
    return request.reply(workflowExecutionInfos);
}

From source file:com.evolveum.midpoint.repo.sql.query.custom.ShadowQueryWithDisjunction.java

License:Apache License

@Override
public RQuery createQuery(ObjectQuery objectQuery, Class<? extends ObjectType> type,
        Collection<SelectorOptions<GetOperationOptions>> options, boolean countingObjects, Session session) {

    DetachedCriteria c1 = DetachedCriteria.forClass(ClassMapper.getHQLTypeClass(ShadowType.class), "s");
    c1.createCriteria("strings", "s1", JoinType.LEFT_OUTER_JOIN);

    ParsedQuery parsedQuery = parse(objectQuery);
    Conjunction conjunction = Restrictions.conjunction();
    conjunction// w w  w.jav a 2 s  .c  o m
            .add(Restrictions.eq("resourceRef.targetOid", parsedQuery.refFilter.getValues().get(0).getOid()));
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(createAttributeEq(parsedQuery.eqUidFilter,
            parsedQuery.eqUidFilter.getPath().lastNamed().getName()));
    disjunction.add(createAttributeEq(parsedQuery.eqNameFilter, SchemaConstantsGenerated.ICF_S_NAME));
    conjunction.add(disjunction);
    c1.add(conjunction);

    if (countingObjects) {
        c1.setProjection(Projections.countDistinct("s.oid"));
        return new RQueryCriteriaImpl(c1.getExecutableCriteria(session));
    }

    c1.setProjection(Projections.distinct(Projections.property("s.oid")));

    Criteria cMain = session.createCriteria(ClassMapper.getHQLTypeClass(ShadowType.class), "o");
    cMain.add(Subqueries.propertyIn("oid", c1));

    if (objectQuery != null && objectQuery.getPaging() != null) {
        cMain = updatePagingAndSorting(cMain, type, objectQuery.getPaging());
    }

    ProjectionList projections = Projections.projectionList();
    projections.add(Projections.property("fullObject"));
    projections.add(Projections.property("stringsCount"));
    projections.add(Projections.property("longsCount"));
    projections.add(Projections.property("datesCount"));
    projections.add(Projections.property("referencesCount"));
    projections.add(Projections.property("polysCount"));
    projections.add(Projections.property("booleansCount"));

    cMain.setProjection(projections);

    cMain.setResultTransformer(GetObjectResult.RESULT_TRANSFORMER);
    return new RQueryCriteriaImpl(cMain);
}

From source file:com.evolveum.midpoint.repo.sql.query.custom.ShadowQueryWithDisjunction.java

License:Apache License

private Criterion createAttributeEq(EqualFilter attributeEqFilter, QName attributeName) {
    Conjunction conjunction = Restrictions.conjunction();
    conjunction.add(Restrictions.eq("s1.ownerType", RObjectExtensionType.ATTRIBUTES));
    conjunction.add(Restrictions.eq("s1.name", RUtil.qnameToString(attributeName)));
    conjunction.add(Restrictions.eq("s1.value",
            ((PrismPropertyValue) attributeEqFilter.getValues().get(0)).getValue()));
    return conjunction;
}

From source file:com.evolveum.midpoint.repo.sql.query.matcher.PolyStringMatcher.java

License:Apache License

@Override
public Criterion match(ItemRestrictionOperation operation, String propertyName, PolyString value,
        String matcher) throws QueryException {

    boolean ignoreCase = STRICT_IGNORE_CASE.equals(matcher) || ORIG_IGNORE_CASE.equals(matcher)
            || NORM_IGNORE_CASE.equals(matcher);

    if (StringUtils.isEmpty(matcher) || STRICT.equals(matcher) || STRICT_IGNORE_CASE.equals(matcher)) {
        Conjunction conjunction = Restrictions.conjunction();
        conjunction.add(createOrigMatch(operation, propertyName, value, ignoreCase));
        conjunction.add(createNormMatch(operation, propertyName, value, ignoreCase));

        return conjunction;
    } else if (ORIG.equals(matcher) || ORIG_IGNORE_CASE.equals(matcher)) {
        return createOrigMatch(operation, propertyName, value, ignoreCase);
    } else if (NORM.equals(matcher) || NORM_IGNORE_CASE.equals(matcher)) {
        return createNormMatch(operation, propertyName, value, ignoreCase);
    } else {/*from  w w w  . ja v  a2 s .  c o m*/
        throw new QueryException("Unknown matcher '" + matcher + "'.");
    }
}

From source file:com.evolveum.midpoint.repo.sql.query.restriction.AndRestriction.java

License:Apache License

@Override
public Criterion interpret(AndFilter filter) throws QueryException {
    validateFilter(filter);//from w w  w .j a v a 2  s. com
    Conjunction conjunction = Restrictions.conjunction();
    updateJunction(filter.getConditions(), conjunction);

    return conjunction;
}

From source file:com.evolveum.midpoint.repo.sql.query.restriction.AnyPropertyRestriction.java

License:Apache License

@Override
public Criterion interpretInternal(ValueFilter filter) throws QueryException {

    ItemDefinition itemDefinition = filter.getDefinition();
    QName name = itemDefinition.getName();
    QName type = itemDefinition.getTypeName();

    if (name == null || type == null) {
        throw new QueryException("Couldn't get name or type for queried item '" + itemDefinition + "'");
    }//from  w w  w .  j  a  v  a  2 s  .  c o  m

    ItemPath anyItemPath = createAnyItemPath(filter.getParentPath(), filter.getDefinition());
    if (!getContext().hasAlias(anyItemPath)) {
        QName anyTypeName = ((NameItemPathSegment) anyItemPath.last()).getName();
        LOGGER.trace("Condition item is from 'any' container, adding new criteria based on any type '{}'",
                new Object[] { anyTypeName.getLocalPart() });
        addNewCriteriaToContext(anyItemPath, null, anyTypeName.getLocalPart());
    }
    String propertyNamePrefix = getContext().getAlias(anyItemPath) + '.';

    Conjunction conjunction = Restrictions.conjunction();

    RObjectExtensionType ownerType = filter.getFullPath().first()
            .equals(new NameItemPathSegment(ObjectType.F_EXTENSION)) ? RObjectExtensionType.EXTENSION
                    : RObjectExtensionType.ATTRIBUTES;
    conjunction.add(Restrictions.eq(propertyNamePrefix + "ownerType", ownerType));

    conjunction.add(Restrictions.eq(propertyNamePrefix + RAnyValue.F_NAME, RUtil.qnameToString(name)));

    Object testedValue = getValue(((PropertyValueFilter) filter).getValues());
    Object value = RAnyConverter.getAggregatedRepoObject(testedValue);
    conjunction.add(createCriterion(propertyNamePrefix + RAnyValue.F_VALUE, value, filter));

    return conjunction;
}