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

com.blazebit.persistence.SubqueryInitiator Maven / Gradle / Ivy

There is a newer version: 1.6.11
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;

import javax.persistence.metamodel.EntityType;
import java.util.Collection;

/**
 * An interface used to create subquery builders.
 *
 * @param  The builder type that is returned on terminal operations
 * @author Christian Beikov
 * @since 1.0.0
 */
public interface SubqueryInitiator extends FromBaseBuilder> {

    /**
     * Returns the parent query builder.
     *
     * @return The parent query builder
     * @since 1.3.0
     */
    public CommonQueryBuilder getParentQueryBuilder();

    /**
     * Like {@link SubqueryInitiator#from(String, String)} with the
     * alias equivalent to the camel cased result of the class of the correlation parent.
     *
     * @param correlationPath The correlation path which should be queried
     * @return A new subquery builder
     * @since 1.2.0
     */
    public SubqueryBuilder from(String correlationPath);

    /**
     * Creates a new subquery builder with the given correlation path in the FROM clause with the given alias.
     *
     * @param correlationPath The correlation path which should be queried
     * @param alias The alias for the entity
     * @return A new subquery builder
     * @since 1.2.0
     */
    public SubqueryBuilder from(String correlationPath, String alias);

    /**
     * Starts a nested set operation builder which is used as subquery.
     * Doing this is like starting a nested query that will be connected via a set operation.
     *
     * @return A new set operation builder for the subquery
     * @since 1.2.0
     */
    public StartOngoingSetOperationSubqueryBuilder> startSet();

    /* Overrides for proper JavaDoc */

    /**
     * Like {@link SubqueryInitiator#from(java.lang.Class, java.lang.String)} with the
     * alias equivalent to the camel cased result of what {@link Class#getSimpleName()} of the entity class returns.
     *
     * @param entityClass The entity class which should be the entity
     * @return A new subquery builder
     */
    @Override
    public SubqueryBuilder from(Class entityClass);

    /**
     * Creates a new subquery builder with the given entity class as entity in the FROM clause with the given alias.
     *
     * @param entityClass The entity class which should be the entity
     * @param alias The alias for the entity
     * @return A new subquery builder
     */
    @Override
    public SubqueryBuilder from(Class entityClass, String alias);

    /**
     * Like {@link SubqueryInitiator#from(EntityType, String)} with the
     * alias equivalent to the camel cased result of what {@link EntityType#getName()} of the entity class returns.
     *
     * @param entityType The entity type which should be queried
     * @return A new subquery builder
     * @since 1.3.0
     */
    @Override
    SubqueryBuilder from(EntityType entityType);

    /**
     * Creates a new subquery builder with the entity class on which the query should be based on with the given alias.
     *
     * @param entityType The entity type which should be queried
     * @param alias The alias for the entity
     * @return A new subquery builder
     * @since 1.3.0
     */
    @Override
    SubqueryBuilder from(EntityType entityType, String alias);

    /**
     * Like {@link SubqueryInitiator#from(Class)} but explicitly queries the data before any side effects happen because of CTEs.
     *
     * @param entityClass The entity class which should be queried
     * @return A new subquery builder
     * @since 1.2.0
     */
    @Override
    public SubqueryBuilder fromOld(Class entityClass);

    /**
     * Like {@link SubqueryInitiator#from(Class, String)} but explicitly queries the data before any side effects happen because of CTEs.
     *
     * @param entityClass The entity class which should be queried
     * @param alias The alias for the entity
     * @return A new subquery builder
     * @since 1.2.0
     */
    @Override
    public SubqueryBuilder fromOld(Class entityClass, String alias);

    /**
     * Like {@link SubqueryInitiator#from(Class)} but explicitly queries the data after any side effects happen because of CTEs.
     *
     * @param entityClass The entity class which should be queried
     * @return A new subquery builder
     * @since 1.2.0
     */
    @Override
    public SubqueryBuilder fromNew(Class entityClass);

    /**
     * Like {@link SubqueryInitiator#from(Class, String)} but explicitly queries the data after any side effects happen because of CTEs.
     *
     * @param entityClass The entity class which should be queried
     * @param alias The alias for the entity
     * @return A new subquery builder
     * @since 1.2.0
     */
    @Override
    public SubqueryBuilder fromNew(Class entityClass, String alias);

    /**
     * Creates a new subquery builder with a VALUES clause for values of the given value class in the from clause.
     * This introduces a parameter named like the given alias.
     *
     * To set the values invoke {@link SubqueryBuilder#setParameter(String, Object)}
     * or {@link javax.persistence.Query#setParameter(String, Object)} with the alias and a collection.
     *
     * @param valueClass The class of the basic or managed type for which to create a VALUES clause
     * @param alias The alias for the entity
     * @param valueCount The number of values to use for the values clause
     * @return A new subquery builder
     * @since 1.2.0
     */
    @Override
    public SubqueryBuilder fromValues(Class valueClass, String alias, int valueCount);

    /**
     * Creates a new subquery builder with a VALUES clause for values of the type as determined by the given entity attribute to the from clause.
     * This introduces a parameter named like the given alias.
     *
     * To set the values invoke {@link CommonQueryBuilder#setParameter(String, Object)}
     * or {@link javax.persistence.Query#setParameter(String, Object)} with the alias and a collection.
     *
     * @param entityBaseClass The entity class on which the attribute is located
     * @param attributeName The attribute name within the entity class which to use for determining the values type
     * @param alias The alias for the entity
     * @param valueCount The number of values to use for the values clause
     * @return The new subquery builder
     * @since 1.3.0
     */
    @Override
    SubqueryBuilder fromValues(Class entityBaseClass, String attributeName, String alias, int valueCount);

    /**
     * Creates a new subquery builder with a VALUES clause for values of the given value class in the from clause.
     * This introduces a parameter named like the given alias.
     *
     * In contrast to {@link SubqueryInitiator#fromValues(Class, String, int)} this will only bind the id attribute.
     *
     * To set the values invoke {@link SubqueryBuilder#setParameter(String, Object)}
     * or {@link javax.persistence.Query#setParameter(String, Object)} with the alias and a collection.
     *
     * @param valueClass The class of the identifiable type for which to create a VALUES clause
     * @param alias The alias for the entity
     * @param valueCount The number of values to use for the values clause
     * @return A new subquery builder
     * @since 1.2.0
     */
    @Override
    public SubqueryBuilder fromIdentifiableValues(Class valueClass, String alias, int valueCount);

    /**
     * Like {@link SubqueryInitiator#fromValues(Class, String, int)} but passes the collection size
     * as valueCount and directly binds the collection as parameter via {@link SubqueryBuilder#setParameter(String, Object)}.
     *
     * @param valueClass The class of the basic or managed type for which to create a VALUES clause
     * @param alias The alias for the entity
     * @param values The values to use for the values clause
     * @param  The type of the values
     * @return A new subquery builder
     * @since 1.2.0
     */
    @Override
    public  SubqueryBuilder fromValues(Class valueClass, String alias, Collection values);

    /**
     * Like {@link SubqueryInitiator#fromValues(Class, String, String, int)} but passes the collection size
     * as valueCount and directly binds the collection as parameter via {@link SubqueryBuilder#setParameter(String, Object)}.
     *
     * @param entityBaseClass The entity class on which the attribute is located
     * @param attributeName The attribute name within the entity class which to use for determining the values type
     * @param alias The alias for the entity
     * @param values The values to use for the values clause
     * @return The new subquery builder
     * @since 1.3.0
     */
    @Override
    SubqueryBuilder fromValues(Class entityBaseClass, String attributeName, String alias, Collection values);

    /**
     * Like {@link SubqueryInitiator#fromIdentifiableValues(Class, String, int)} but passes the collection size
     * as valueCount and directly binds the collection as parameter via {@link SubqueryBuilder#setParameter(String, Object)}.
     *
     * @param valueClass The class of the identifiable type for which to create a VALUES clause
     * @param alias The alias for the entity
     * @param values The values to use for the values clause
     * @param  The type of the values
     * @return A new subquery builder
     * @since 1.2.0
     */
    @Override
    public  SubqueryBuilder fromIdentifiableValues(Class valueClass, String alias, Collection values);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy