/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
 * third-party contributors as indicated by either @author tags or express
 * copyright attribution statements applied by the authors.  All
 * third-party contributions are distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.jpa.criteria.expression;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;

import org.hibernate.jpa.criteria.CriteriaBuilderImpl;
import org.hibernate.jpa.criteria.ExpressionImplementor;
import org.hibernate.jpa.criteria.expression.function.CastFunction;

Models an expression in the criteria query language.
Author:Steve Ebersole
/** * Models an expression in the criteria query language. * * @author Steve Ebersole */
public abstract class ExpressionImpl<T> extends SelectionImpl<T> implements ExpressionImplementor<T>, Serializable { public ExpressionImpl(CriteriaBuilderImpl criteriaBuilder, Class<T> javaType) { super( criteriaBuilder, javaType ); } @Override @SuppressWarnings({ "unchecked" }) public <X> Expression<X> as(Class<X> type) { return type.equals( getJavaType() ) ? (Expression<X>) this : new CastFunction<X, T>( criteriaBuilder(), type, this ); } @Override public Predicate isNull() { return criteriaBuilder().isNull( this ); } @Override public Predicate isNotNull() { return criteriaBuilder().isNotNull( this ); } @Override public Predicate in(Object... values) { return criteriaBuilder().in( this, values ); } @Override public Predicate in(Expression<?>... values) { return criteriaBuilder().in( this, values ); } @Override public Predicate in(Collection<?> values) { return criteriaBuilder().in( this, values.toArray() ); } @Override public Predicate in(Expression<Collection<?>> values) { return criteriaBuilder().in( this, values ); } @Override @SuppressWarnings({ "unchecked" }) public ExpressionImplementor<Long> asLong() { resetJavaType( Long.class ); return (ExpressionImplementor<Long>) this; } @Override @SuppressWarnings({ "unchecked" }) public ExpressionImplementor<Integer> asInteger() { resetJavaType( Integer.class ); return (ExpressionImplementor<Integer>) this; } @Override @SuppressWarnings({ "unchecked" }) public ExpressionImplementor<Float> asFloat() { resetJavaType( Float.class ); return (ExpressionImplementor<Float>) this; } @Override @SuppressWarnings({ "unchecked" }) public ExpressionImplementor<Double> asDouble() { resetJavaType( Double.class ); return (ExpressionImplementor<Double>) this; } @Override @SuppressWarnings({ "unchecked" }) public ExpressionImplementor<BigDecimal> asBigDecimal() { resetJavaType( BigDecimal.class ); return (ExpressionImplementor<BigDecimal>) this; } @Override @SuppressWarnings({ "unchecked" }) public ExpressionImplementor<BigInteger> asBigInteger() { resetJavaType( BigInteger.class ); return (ExpressionImplementor<BigInteger>) this; } @Override @SuppressWarnings({ "unchecked" }) public ExpressionImplementor<String> asString() { resetJavaType( String.class ); return (ExpressionImplementor<String>) this; } }