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

com.impetus.kundera.persistence.KunderaCriteriaBuilder Maven / Gradle / Ivy

There is a newer version: 3.13
Show newest version
/*******************************************************************************
 * * Copyright 2014 Impetus Infotech.
 *  *
 *  * 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.impetus.kundera.persistence;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Tuple;
import javax.persistence.criteria.CollectionJoin;
import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.CriteriaUpdate;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.MapJoin;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.SetJoin;
import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.Metamodel;

import com.impetus.kundera.persistence.AbstractPredicate.ConditionalOperator;
import com.impetus.kundera.query.KunderaQuery.SortOrder;

/**
 * Implements criteria builder {@link CriteriaBuilder}.
 * 
 * @author vivek.mishra
 * 
 */
public class KunderaCriteriaBuilder implements CriteriaBuilder
{

    private EntityManagerFactory entityManagerFactory;

    KunderaCriteriaBuilder(EntityManagerFactory entityManagerFactory)
    {
        this.entityManagerFactory = entityManagerFactory;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#abs(javax.persistence.criteria
     * .Expression)
     */
    @Override
    public  Expression abs(Expression arg0)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#all(javax.persistence.criteria
     * .Subquery)
     */
    @Override
    public  Expression all(Subquery arg0)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#and(javax.persistence.criteria
     * .Predicate[])
     */
    @Override
    public Predicate and(Predicate... predicates)
    {
        return new ConjuctionPredicate(predicates);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#and(javax.persistence.criteria
     * .Expression, javax.persistence.criteria.Expression)
     */
    @Override
    public Predicate and(Expression arg0, Expression arg1)
    {
        if (arg0 != null && arg1 != null)
        {
           return new ConjuctionPredicate((Predicate)arg0, (Predicate)arg1);
        }
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#any(javax.persistence.criteria
     * .Subquery)
     */
    @Override
    public  Expression any(Subquery arg0)
    {
        // TODO Auto-generated method stub
        return null;
    }

    
    CompoundSelection array( Class resultClazz, Selection... arg0)
    {
        return new DefaultCompoundSelection(Arrays.asList(arg0), resultClazz);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#array(javax.persistence.criteria
     * .Selection[])
     */
    @Override
    public CompoundSelection array(Selection... arg0)
    {
        return new DefaultCompoundSelection(Arrays.asList(arg0), Object.class);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#asc(javax.persistence.criteria
     * .Expression)
     */
    @Override
    public Order asc(Expression arg0)
    {
        return new QueryOrder(arg0, SortOrder.ASC);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#avg(javax.persistence.criteria
     * .Expression)
     */
    @Override
    public  Expression avg(Expression arg0)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#between(javax.persistence.
     * criteria.Expression, javax.persistence.criteria.Expression,
     * javax.persistence.criteria.Expression)
     */
    @Override
    public > Predicate between(Expression arg0,
            Expression arg1, Expression arg2)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#between(javax.persistence.
     * criteria.Expression, java.lang.Comparable, java.lang.Comparable)
     */
    @Override
    public > Predicate between(Expression arg0, Y arg1, Y arg2)
    {
        return new BetweenPredicate(arg0,arg1,arg2);
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.persistence.criteria.CriteriaBuilder#coalesce()
     */
    @Override
    public  Coalesce coalesce()
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#coalesce(javax.persistence
     * .criteria.Expression, javax.persistence.criteria.Expression)
     */
    @Override
    public  Expression coalesce(Expression arg0, Expression arg1)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#coalesce(javax.persistence
     * .criteria.Expression, java.lang.Object)
     */
    @Override
    public  Expression coalesce(Expression arg0, Y arg1)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#concat(javax.persistence.criteria
     * .Expression, javax.persistence.criteria.Expression)
     */
    @Override
    public Expression concat(Expression arg0, Expression arg1)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#concat(javax.persistence.criteria
     * .Expression, java.lang.String)
     */
    @Override
    public Expression concat(Expression arg0, String arg1)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.persistence.criteria.CriteriaBuilder#concat(java.lang.String,
     * javax.persistence.criteria.Expression)
     */
    @Override
    public Expression concat(String arg0, Expression arg1)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.persistence.criteria.CriteriaBuilder#conjunction()
     */
    @Override
    public Predicate conjunction()
    {
        return new ConjuctionPredicate();
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#construct(java.lang.Class,
     * javax.persistence.criteria.Selection[])
     */
    @Override
    public  CompoundSelection construct(Class arg0, Selection... arg1)
    {
        return new DefaultCompoundSelection(Arrays.asList(arg1), arg0);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#count(javax.persistence.criteria
     * .Expression)
     */
    @Override
    public Expression count(Expression arg0)
    {
        // TODO Auto-generated method stub
        String arg1 = "Count("+arg0.getAlias()+")";
        return new AggregateExpression(arg0, arg1);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#countDistinct(javax.persistence
     * .criteria.Expression)
     */
    @Override
    public Expression countDistinct(Expression arg0)
    {
        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.persistence.criteria.CriteriaBuilder#createQuery()
     */
    @Override
    public CriteriaQuery createQuery()
    {
        return new KunderaCritieriaQuery(this);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * javax.persistence.criteria.CriteriaBuilder#createQuery(java.lang.Class)
     */
    @Override
    public  CriteriaQuery createQuery(Class returnClazz)
    {
        return new KunderaCritieriaQuery(this, returnClazz);
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.persistence.criteria.CriteriaBuilder#createTupleQuery()
     */
    @Override
    public CriteriaQuery createTupleQuery()
    {
        return new KunderaCritieriaQuery(this, Tuple.class);
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.persistence.criteria.CriteriaBuilder#currentDate()
     */
    @Override
    public Expression currentDate()
    {
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.persistence.criteria.CriteriaBuilder#currentTime()
     */
    @Override
    public Expression