[hibernate-commits] Hibernate SVN: r18492 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Sat Jan 9 15:26:40 EST 2010


Author: steve.ebersole at jboss.com
Date: 2010-01-09 15:26:40 -0500 (Sat, 09 Jan 2010)
New Revision: 18492

Added:
   core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullLiteralExpression.java
Modified:
   core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java
Log:
HHH-4776 - Add a NullLiteralExpression for CriteriaBuilder#nullLiteral 


Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java	2010-01-09 20:17:47 UTC (rev 18491)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java	2010-01-09 20:26:40 UTC (rev 18492)
@@ -47,6 +47,7 @@
 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 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 @@
 	 * {@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 @@
 	 * {@inheritDoc}
 	 */
 	public <T> Expression<T> nullLiteral(Class<T> resultClass) {
-		return new LiteralExpression<T>( this, resultClass, null );
+		return new NullLiteralExpression<T>( this, resultClass );
 	}
 
 

Copied: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullLiteralExpression.java (from rev 18486, core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java)
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullLiteralExpression.java	                        (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullLiteralExpression.java	2010-01-09 20:26:40 UTC (rev 18492)
@@ -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 );
+	}
+}
\ No newline at end of file



More information about the hibernate-commits mailing list