org.apache.deltaspike.data.api.criteria.Criteria Maven / Gradle / Ivy
/*
* 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 super C, P> 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 super C, P> 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 super C, P> 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 super C, P> 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 super C, E, P> att, Criteria criteria);
/**
* Fetch join an attribute.
* @param att The attribute to fetch.
* @return Fluent API: Criteria instance.
*/
Criteria fetch(SingularAttribute super C, P> 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 super C, P> att, JoinType joinType);
/**
* Fetch join an attribute.
* @param att The attribute to fetch.
* @return Fluent API: Criteria instance.
*/
Criteria fetch(PluralAttribute super C, P, E> 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 super C, P, E> 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 super C, P> att);
/**
* Apply sorting by an attribute, descending direction.
* @param att The attribute to order for.
* @return Fluent API: Criteria instance.
*/
Criteria orderDesc(SingularAttribute super C, P> 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 super C, ?>... selection);
/**
* Create a select query.
* @param selection List of selects (attributes, scalars...)
* @return Fluent API: Criteria instance.
*/
Criteria select(QuerySelection super C, ?>... 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 super C, P> 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 super C, String> 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 super C, P> 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 super C, String> 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 super C, String> 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 super C, String> 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 super C, String> 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 super C, String> 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 super C, P> 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 super C, P> 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 super C, P> 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 super C, P> 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 super C, P> att, P lower, P upper);
/**
* IsNull predicate.
* @param att The null attribute.
* @return Fluent API: Criteria instance.
*/
Criteria isNull(SingularAttribute super C, P> att);
/**
* NotNull predicate.
* @param att The non-null attribute.
* @return Fluent API: Criteria instance.
*/
Criteria notNull(SingularAttribute super C, P> att);
/**
* Empty predicate.
* @param att The collection attribute to check for emptyness.
* @return Fluent API: Criteria instance.
*/
> Criteria empty(SingularAttribute super C, P> att);
/**
* Not empty predicate.
* @param att The collection attribute to check for non-emptyness.
* @return Fluent API: Criteria instance.
*/
> Criteria notEmpty(SingularAttribute super C, P> att);
/**
* In predicte.
* @param att The attribute to check for.
* @param values The values for the in predicate.
* @return
*/
Criteria in(SingularAttribute super C, P> 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);
}