All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.deltaspike.data.api.criteria.Criteria Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.deltaspike.data.api.criteria;

import java.util.Collection;
import java.util.List;

import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.metamodel.CollectionAttribute;
import javax.persistence.metamodel.ListAttribute;
import javax.persistence.metamodel.MapAttribute;
import javax.persistence.metamodel.PluralAttribute;
import javax.persistence.metamodel.SetAttribute;
import javax.persistence.metamodel.SingularAttribute;

/**
 * Criteria API utilities.
 *
 * @param  Entity type.
 * @param  Result type.
 */
public interface Criteria
{

    /**
     * Executes the query and returns the result list.
     * @return List of entities matching the query.
     */
    List getResultList();

    /**
     * Executes the query which has a single result.
     * @return Entity matching the search query.
     */
    R getSingleResult();

    /**
     * Executes the query which has a single result. Returns {@code null}
     * if there is no result.
     * @return Entity matching the search query, or {@code null} if there is none.
     */
    R getOptionalResult();

    /**
     * Executes the query and returns a single result. If there are
     * multiple results, the first received is returned.
     * @return Entity matching the search query.
     */
    R getAnyResult();

    /**
     * Creates a JPA query object to be executed.
     * @return A {@link TypedQuery} object ready to return results.
     */
    TypedQuery createQuery();

    /**
     * Boolean OR with another Criteria.
     * @param criteria      The right side of the boolean OR.
     * @return              Fluent API: Criteria instance.
     */
    Criteria or(Criteria... criteria);

    /**
     * Boolean OR with another Criteria.
     * @param criteria      The right side of the boolean OR.
     * @return              Fluent API: Criteria instance.
     */
    Criteria or(Collection> criteria);

    /**
     * Join an attribute with another Criteria.
     * @param att           The attribute to join.
     * @param criteria      The join criteria.
     * @return              Fluent API: Criteria instance.
     */
     Criteria join(SingularAttribute att, Criteria criteria);

    /**
     * Join a collection attribute with another Criteria.
     * @param att           The attribute to join.
     * @param criteria      The join criteria.
     * @return              Fluent API: Criteria instance.
     */
     Criteria join(ListAttribute att, Criteria criteria);

    /**
     * Join a collection attribute with another Criteria.
     * @param att           The attribute to join.
     * @param criteria      The join criteria.
     * @return              Fluent API: Criteria instance.
     */
     Criteria join(CollectionAttribute att, Criteria criteria);

    /**
     * Join a collection attribute with another Criteria.
     * @param att           The attribute to join.
     * @param criteria      The join criteria.
     * @return              Fluent API: Criteria instance.
     */
     Criteria join(SetAttribute att, Criteria criteria);

    /**
     * Join a collection attribute with another Criteria.
     * @param att           The attribute to join.
     * @param criteria      The join criteria.
     * @return              Fluent API: Criteria instance.
     */
     Criteria join(MapAttribute att, Criteria criteria);


    /**
     * Fetch join an attribute.
     * @param att           The attribute to fetch.
     * @return              Fluent API: Criteria instance.
     */
     Criteria fetch(SingularAttribute att);

    /**
     * Fetch join an attribute.
     * @param att           The attribute to fetch.
     * @param joinType      The JoinType to use.
     * @return              Fluent API: Criteria instance.
     */
     Criteria fetch(SingularAttribute att, JoinType joinType);

    /**
     * Fetch join an attribute.
     * @param att           The attribute to fetch.
     * @return              Fluent API: Criteria instance.
     */
     Criteria fetch(PluralAttribute att);

    /**
     * Fetch join an attribute.
     * @param att           The attribute to fetch.
     * @param joinType      The JoinType to use.
     * @return              Fluent API: Criteria instance.
     */
     Criteria fetch(PluralAttribute att, JoinType joinType);

    /**
     * Apply sorting by an attribute, ascending direction.
     * @param att           The attribute to order for.
     * @return              Fluent API: Criteria instance.
     */
    

Criteria orderAsc(SingularAttribute att); /** * Apply sorting by an attribute, descending direction. * @param att The attribute to order for. * @return Fluent API: Criteria instance. */

Criteria orderDesc(SingularAttribute att); /** * Create a select query. * @param resultClass The query result class. * @param selection List of selects (attributes, scalars...) * @return Fluent API: Criteria instance. */ Criteria select(Class resultClass, QuerySelection... selection); /** * Create a select query. * @param selection List of selects (attributes, scalars...) * @return Fluent API: Criteria instance. */ Criteria select(QuerySelection... selection); /** * Apply a distinct on the query. * @return Fluent API: Criteria instance. */ Criteria distinct(); /** * Equals predicate. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

Criteria eq(SingularAttribute att, P value); /** * Equals predicate, case insensitive. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

Criteria eqIgnoreCase(SingularAttribute att, String value); /** * Not Equals predicate. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

Criteria notEq(SingularAttribute att, P value); /** * Not Equals predicate, case insensitive. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

Criteria notEqIgnoreCase(SingularAttribute att, String value); /** * Like predicate. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

Criteria like(SingularAttribute att, String value); /** * Like predicate, case insensitive. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

Criteria likeIgnoreCase(SingularAttribute att, String value); /** * Not like predicate. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

Criteria notLike(SingularAttribute att, String value); /** * Not like predicate, case insensitive. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

Criteria notLikeIgnoreCase(SingularAttribute att, String value); /** * Less than predicate. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

> Criteria lt(SingularAttribute att, P value); /** * Less than or equals predicate. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

> Criteria ltOrEq(SingularAttribute att, P value); /** * Greater than predicate. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

> Criteria gt(SingularAttribute att, P value); /** * Greater than or equals predicate. * @param att The attribute to compare with. * @param value The comparison value. * @return Fluent API: Criteria instance. */

> Criteria gtOrEq(SingularAttribute att, P value); /** * Between predicate. * @param att The attribute to compare with. * @param lower The lower bound comparison value. * @param upper The upper bound comparison value. * @return Fluent API: Criteria instance. */

> Criteria between(SingularAttribute att, P lower, P upper); /** * IsNull predicate. * @param att The null attribute. * @return Fluent API: Criteria instance. */

Criteria isNull(SingularAttribute att); /** * NotNull predicate. * @param att The non-null attribute. * @return Fluent API: Criteria instance. */

Criteria notNull(SingularAttribute att); /** * Empty predicate. * @param att The collection attribute to check for emptyness. * @return Fluent API: Criteria instance. */

> Criteria empty(SingularAttribute att); /** * Not empty predicate. * @param att The collection attribute to check for non-emptyness. * @return Fluent API: Criteria instance. */

> Criteria notEmpty(SingularAttribute att); /** * In predicte. * @param att The attribute to check for. * @param values The values for the in predicate. * @return */

Criteria in(SingularAttribute att, P... values); /** * Return the list of predicates applicable for this Criteria instance. * @param builder A CriteriaBuilder used to instantiate the Predicates. * @param path Current path. * @return List of predicates applicable to this Criteria. */ List predicates(CriteriaBuilder builder, Path path); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy