HHH-4776 - Add a NullLiteralExpression for CriteriaBuilder#nullLiteral

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18492 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-01-09 20:26:40 +00:00
parent 49a37c3165
commit b5597882ce
2 changed files with 59 additions and 2 deletions

View File

@ -47,6 +47,7 @@ import org.hibernate.ejb.criteria.expression.BinaryArithmeticOperation;
import org.hibernate.ejb.criteria.expression.CoalesceExpression;
import org.hibernate.ejb.criteria.expression.CompoundSelectionImpl;
import org.hibernate.ejb.criteria.expression.ConcatExpression;
import org.hibernate.ejb.criteria.expression.NullLiteralExpression;
import org.hibernate.ejb.criteria.expression.ParameterExpressionImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.NullifExpression;
@ -84,7 +85,7 @@ import org.hibernate.ejb.criteria.predicate.MemberOfPredicate;
import static org.hibernate.ejb.criteria.predicate.ComparisonPredicate.ComparisonOperator;
/**
* TODO : javadoc
* Hibernate implementation of the JPA {@link CriteriaBuilder} contract.
*
* @author Steve Ebersole
*/
@ -619,6 +620,9 @@ public class CriteriaBuilderImpl implements CriteriaBuilder, Serializable {
* {@inheritDoc}
*/
public <T> Expression<T> literal(T value) {
if ( value == null ) {
throw new IllegalArgumentException( "literal value cannot be null" );
}
return new LiteralExpression<T>( this, value );
}
@ -626,7 +630,7 @@ public class CriteriaBuilderImpl implements CriteriaBuilder, Serializable {
* {@inheritDoc}
*/
public <T> Expression<T> nullLiteral(Class<T> resultClass) {
return new LiteralExpression<T>( this, resultClass, null );
return new NullLiteralExpression<T>( this, resultClass );
}

View File

@ -0,0 +1,53 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @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.ejb.criteria.expression;
import java.io.Serializable;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.ParameterRegistry;
/**
* Represents a <tt>NULL</tt>literal expression.
*
* @author Steve Ebersole
*/
public class NullLiteralExpression<T> extends ExpressionImpl<T> implements Serializable {
public NullLiteralExpression(CriteriaBuilderImpl criteriaBuilder, Class<T> type) {
super( criteriaBuilder, type );
}
public void registerParameters(ParameterRegistry registry) {
// nothing to do
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return "null";
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
return render( renderingContext );
}
}