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

javax.persistence.criteria.CriteriaBuilder Maven / Gradle / Ivy

There is a newer version: 4.0.1
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.
 */

//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.persistence.criteria;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import javax.persistence.Tuple;

public interface CriteriaBuilder {

    CriteriaQuery createQuery();

     CriteriaQuery createQuery(Class resultClass);

    CriteriaQuery createTupleQuery();

    // methods to construct queries for bulk updates and deletes:

     CriteriaUpdate createCriteriaUpdate(Class targetEntity);

     CriteriaDelete createCriteriaDelete(Class targetEntity);


    // selection construction methods:
	
     CompoundSelection construct(Class resultClass, Selection... selections);

    CompoundSelection tuple(Selection... selections);

    CompoundSelection array(Selection... selections);


    //ordering:
	
    Order asc(Expression x);

    Order desc(Expression x);

	
    //aggregate functions:
	
     Expression avg(Expression x);

     Expression sum(Expression x);

    Expression sumAsLong(Expression x);

    Expression sumAsDouble(Expression x);

     Expression max(Expression x);

     Expression min(Expression x);

    > Expression greatest(Expression x);
    
    > Expression least(Expression x);

    Expression count(Expression x);

    Expression countDistinct(Expression x);



    //subqueries:
	
    Predicate exists(Subquery subquery);

     Expression all(Subquery subquery);

     Expression some(Subquery subquery);

     Expression any(Subquery subquery);


    //boolean functions:
	
    Predicate and(Expression x, Expression y);

    Predicate and(Predicate... restrictions);

    Predicate or(Expression x, Expression y);

    Predicate or(Predicate... restrictions);

    Predicate not(Expression restriction);

    Predicate conjunction();

    Predicate disjunction();

	
    //turn Expression into a Predicate
    //useful for use with varargs methods

    Predicate isTrue(Expression x);

    Predicate isFalse(Expression x);

	
    //null tests:

    Predicate isNull(Expression x);

    Predicate isNotNull(Expression x);

    //equality:
	
    Predicate equal(Expression x, Expression y);

    Predicate equal(Expression x, Object y);

    Predicate notEqual(Expression x, Expression y);

    Predicate notEqual(Expression x, Object y);

	
    //comparisons for generic (non-numeric) operands:

    > Predicate greaterThan(Expression x, Expression y);

    > Predicate greaterThan(Expression x, Y y);

    > Predicate greaterThanOrEqualTo(Expression x, Expression y);

    > Predicate greaterThanOrEqualTo(Expression x, Y y);

    > Predicate lessThan(Expression x, Expression y);

    > Predicate lessThan(Expression x, Y y);

    > Predicate lessThanOrEqualTo(Expression x, Expression y);

    > Predicate lessThanOrEqualTo(Expression x, Y y);

    > Predicate between(Expression v, Expression x, Expression y);

    > Predicate between(Expression v, Y x, Y y);


    //comparisons for numeric operands:
	
    Predicate gt(Expression x, Expression y);

    Predicate gt(Expression x, Number y);

    Predicate ge(Expression x, Expression y);

    Predicate ge(Expression x, Number y);

    Predicate lt(Expression x, Expression y);

    Predicate lt(Expression x, Number y);

    Predicate le(Expression x, Expression y);

    Predicate le(Expression x, Number y);


    //numerical operations:
	
     Expression neg(Expression x);

     Expression abs(Expression x);

     Expression sum(Expression x, Expression y);

     Expression sum(Expression x, N y);

     Expression sum(N x, Expression y);

     Expression prod(Expression x, Expression y);

     Expression prod(Expression x, N y);

     Expression prod(N x, Expression y);

     Expression diff(Expression x, Expression y);

     Expression diff(Expression x, N y);

     Expression diff(N x, Expression y);

    Expression quot(Expression x, Expression y);

    Expression quot(Expression x, Number y);

    Expression quot(Number x, Expression y);

    Expression mod(Expression x, Expression y);

    Expression mod(Expression x, Integer y);

    Expression mod(Integer x, Expression y);

    Expression sqrt(Expression x);

	
    //typecasts:
    
    Expression toLong(Expression number);

    Expression toInteger(Expression number);

    Expression toFloat(Expression number);

    Expression toDouble(Expression number);

    Expression toBigDecimal(Expression number);

    Expression toBigInteger(Expression number);

    Expression toString(Expression character);

	
    //literals:

     Expression literal(T value);

     Expression nullLiteral(Class resultClass);

    //parameters:

     ParameterExpression parameter(Class paramClass);

     ParameterExpression parameter(Class paramClass, String name);


    //collection operations:
	
    > Predicate isEmpty(Expression collection);

    > Predicate isNotEmpty(Expression collection);

    > Expression size(Expression collection);

    > Expression size(C collection);

    > Predicate isMember(Expression elem, Expression collection);

    > Predicate isMember(E elem, Expression collection);

    > Predicate isNotMember(Expression elem, Expression collection);

    > Predicate isNotMember(E elem, Expression collection);


    //get the values and keys collections of the Map, which may then
    //be passed to size(), isMember(), isEmpty(), etc

    > Expression> values(M map);

    > Expression> keys(M map);

	
    //string functions:
	
    Predicate like(Expression x, Expression pattern);

    Predicate like(Expression x, String pattern);

    Predicate like(Expression x, Expression pattern, Expression escapeChar);

    Predicate like(Expression x, Expression pattern, char escapeChar);

    Predicate like(Expression x, String pattern, Expression escapeChar);

    Predicate like(Expression x, String pattern, char escapeChar);

    Predicate notLike(Expression x, Expression pattern);

    Predicate notLike(Expression x, String pattern);

    Predicate notLike(Expression x, Expression pattern, Expression escapeChar);

    Predicate notLike(Expression x, Expression pattern, char escapeChar);

    Predicate notLike(Expression x, String pattern, Expression escapeChar);

    Predicate notLike(Expression x, String pattern, char escapeChar);

    Expression concat(Expression x, Expression y);

    Expression concat(Expression x, String y);

    Expression concat(String x, Expression y);

    Expression substring(Expression x, Expression from);

    Expression substring(Expression x, int from);

    Expression substring(Expression x, Expression from, Expression len);

    Expression substring(Expression x, int from, int len);

    public static enum Trimspec { 

        LEADING,
 
        TRAILING, 

        BOTH 
    }

    Expression trim(Expression x);

    Expression trim(Trimspec ts, Expression x);

    Expression trim(Expression t, Expression x);

    Expression trim(Trimspec ts, Expression t, Expression x);

    Expression trim(char t, Expression x);

    Expression trim(Trimspec ts, char t, Expression x);

    Expression lower(Expression x);

    Expression upper(Expression x);

    Expression length(Expression x);

	
    Expression locate(Expression x, Expression pattern);

    Expression locate(Expression x, String pattern);

    Expression locate(Expression x, Expression pattern, Expression from);

    Expression locate(Expression x, String pattern, int from);


    // Date/time/timestamp functions:

    Expression currentDate();

    Expression currentTimestamp();

    Expression currentTime();


    //in builders:
	
    public static interface In extends Predicate {

         Expression getExpression();
	
         In value(T value);

         In value(Expression value);
     }

     In in(Expression expression);


    // coalesce, nullif:

     Expression coalesce(Expression x, Expression y);

     Expression coalesce(Expression x, Y y);

     Expression nullif(Expression x, Expression y);

     Expression nullif(Expression x, Y y);


    // coalesce builder:

    public static interface Coalesce extends Expression {

         Coalesce value(T value);

         Coalesce value(Expression value);
    }
	
     Coalesce coalesce();


    //case builders:

    public static interface SimpleCase extends Expression {

        Expression getExpression();

        SimpleCase when(C condition, R result);

        SimpleCase when(C condition, Expression result);

        Expression otherwise(R result);

        Expression otherwise(Expression result);
    }

     SimpleCase selectCase(Expression expression);


    public static interface Case extends Expression {

        Case when(Expression condition, R result);

        Case when(Expression condition, Expression result);

        Expression otherwise(R result);

        Expression otherwise(Expression result);
    }

     Case selectCase();

    Expression function(String name, Class type,
Expression... args);
   

    // methods for downcasting:

    Join treat(Join join, Class type);
   
    CollectionJoin treat(CollectionJoin join, Class type);
   
    SetJoin treat(SetJoin join, Class type);
   
    ListJoin treat(ListJoin join, Class type);
   
    MapJoin treat(MapJoin join, Class type);
   
   
     Path treat(Path path, Class type);
   
     Root treat(Root root, Class type);
   
}