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

com.blazebit.persistence.criteria.BlazeCriteriaBuilder Maven / Gradle / Ivy

There is a newer version: 1.6.12
Show newest version
/*
 * Copyright 2014 - 2021 Blazebit.
 *
 * Licensed 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 com.blazebit.persistence.criteria;

import javax.persistence.Tuple;
import javax.persistence.criteria.CollectionJoin;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.MapJoin;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.SetJoin;
import java.util.Map;

/**
 * An extended version of {@link CriteriaBuilder}.
 *
 * @author Christian Beikov
 * @since 1.2.0
 */
public interface BlazeCriteriaBuilder extends CriteriaBuilder {

    /**
     * Create a predicate that tests whether a map is empty.
     *
     * @param map expression
     * @param  map type
     * @return is-empty predicate
     */
    public > Predicate isMapEmpty(Expression map);

    /**
     * Create a predicate that tests whether a map is not empty.
     *
     * @param map expression
     * @param  map type
     * @return is-not-empty predicate
     */
    public > Predicate isMapNotEmpty(Expression map);

    /**
     * Create an expression that tests the size of a map.
     *
     * @param map map
     * @param  map type
     * @return size expression
     */
    public > Expression mapSize(Expression map);

    /**
     * Create an expression that tests the size of a map.
     *
     * @param map map
     * @param  map type
     * @return size expression
     */
    public > Expression mapSize(C map);

    /**
     * Like {@link CriteriaBuilder#asc(Expression)} but allows to also specify the null precedence.
     *
     * @param x          The expression used to define the ordering
     * @param nullsFirst True if nulls should be first, false otherwise
     * @return ascending ordering corresponding to the expression
     */
    public BlazeOrder asc(Expression x, boolean nullsFirst);

    /**
     * Like {@link CriteriaBuilder#desc(Expression)} but allows to also specify the null precedence.
     *
     * @param x          The expression used to define the ordering
     * @param nullsFirst True if nulls should be first, false otherwise
     * @return descending ordering corresponding to the expression
     */
    public BlazeOrder desc(Expression x, boolean nullsFirst);

    /**
     * Like {@link BlazeCriteriaBuilder#createCriteriaUpdate(Class)} but also sets the alias for the entity.
     *
     * @param targetEntity target type for update operation
     * @param alias        The alias for the entity
     * @param           The type of the entity
     * @return the query object
     */
    public  BlazeCriteriaUpdate createCriteriaUpdate(Class targetEntity, String alias);

    /**
     * Like {@link BlazeCriteriaBuilder#createCriteriaDelete(Class)} but also sets the alias for the entity.
     *
     * @param targetEntity target type for delete operation
     * @param alias        The alias for the entity
     * @param           The type of the entity
     * @return the query object
     */
    public  BlazeCriteriaDelete createCriteriaDelete(Class targetEntity, String alias);

    /* covariant overrides */

    @Override
    public BlazeOrder asc(Expression x);

    @Override
    public BlazeOrder desc(Expression x);

    @Override
    public BlazeCriteriaQuery createQuery();

    @Override
    public  BlazeCriteriaQuery createQuery(Class resultClass);

    @Override
    public BlazeCriteriaQuery createTupleQuery();

    /* Compatibility for JPA 2.1 */

    /**
     * Create a query object to perform a bulk update operation.
     *
     * @param targetEntity target type for update operation
     * @param           The type of the entity
     * @return the query object
     */
    public  BlazeCriteriaUpdate createCriteriaUpdate(Class targetEntity);

    /**
     * Create a query object to perform a bulk delete operation.
     *
     * @param targetEntity target type for delete operation
     * @param           The type of the entity
     * @return the query object
     */
    public  BlazeCriteriaDelete createCriteriaDelete(Class targetEntity);

    /**
     * Downcast Join object to the specified type.
     *
     * @param join Join object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The target treat type
     * @return Join object of the specified type
     */
    public  BlazeJoin treat(Join join, Class type);

    /**
     * Downcast CollectionJoin object to the specified type.
     *
     * @param join CollectionJoin object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The target treat type
     * @return CollectionJoin object of the specified type
     */
    public  BlazeCollectionJoin treat(CollectionJoin join, Class type);

    /**
     * Downcast SetJoin object to the specified type.
     *
     * @param join SetJoin object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The target treat type
     * @return SetJoin object of the specified type
     */
    public  BlazeSetJoin treat(SetJoin join, Class type);

    /**
     * Downcast ListJoin object to the specified type.
     *
     * @param join ListJoin object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The target treat type
     * @return ListJoin object of the specified type
     */
    public  BlazeListJoin treat(ListJoin join, Class type);

    /**
     * Downcast MapJoin object to the specified type.
     *
     * @param join MapJoin object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The key type of the joined relation
     * @param   The target treat type
     * @return MapJoin object of the specified type
     */
    public  BlazeMapJoin treat(MapJoin join, Class type);

    /**
     * Downcast Path object to the specified type.
     *
     * @param path path
     * @param type type to be downcast to
     * @param   The path type
     * @param   The target treat type
     * @return Path object of the specified type
     */
    public  BlazePath treat(Path path, Class type);

    /**
     * Downcast Root object to the specified type.
     *
     * @param root root
     * @param type type to be downcast to
     * @param   The root type
     * @param   The target treat type
     * @return Path object of the specified type
     */
    public  BlazeRoot treat(Root root, Class type);

    /**
     * Downcast Join object to the specified type.
     *
     * @param join Join object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The target treat type
     * @return Join object of the specified type
     */
    public  BlazeJoin treat(BlazeJoin join, Class type);

    /**
     * Downcast CollectionJoin object to the specified type.
     *
     * @param join CollectionJoin object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The target treat type
     * @return CollectionJoin object of the specified type
     */
    public  BlazeCollectionJoin treat(BlazeCollectionJoin join, Class type);

    /**
     * Downcast SetJoin object to the specified type.
     *
     * @param join SetJoin object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The target treat type
     * @return SetJoin object of the specified type
     */
    public  BlazeSetJoin treat(BlazeSetJoin join, Class type);

    /**
     * Downcast ListJoin object to the specified type.
     *
     * @param join ListJoin object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The target treat type
     * @return ListJoin object of the specified type
     */
    public  BlazeListJoin treat(BlazeListJoin join, Class type);

    /**
     * Downcast MapJoin object to the specified type.
     *
     * @param join MapJoin object
     * @param type type to be downcast to
     * @param   The source type
     * @param   The type of the joined relation
     * @param   The key type of the joined relation
     * @param   The target treat type
     * @return MapJoin object of the specified type
     */
    public  BlazeMapJoin treat(BlazeMapJoin join, Class type);

    /**
     * Downcast Path object to the specified type.
     *
     * @param path path
     * @param type type to be downcast to
     * @param   The path type
     * @param   The target treat type
     * @return Path object of the specified type
     */
    public  BlazePath treat(BlazePath path, Class type);

    /**
     * Downcast Root object to the specified type.
     *
     * @param root root
     * @param type type to be downcast to
     * @param   The root type
     * @param   The target treat type
     * @return Path object of the specified type
     */
    public  BlazeRoot treat(BlazeRoot root, Class type);
}