HHH-4708 - Make CompoundSelectionImpl implement ExpressionImplementor

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18253 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2009-12-17 00:21:49 +00:00
parent da647e7deb
commit cdfd6d950b
28 changed files with 140 additions and 74 deletions

View File

@ -38,8 +38,6 @@ import javax.persistence.Tuple;
import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.EntityType;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* The Hibernate implementation of the JPA {@link CriteriaQuery} contract. Mostly a set of delegation to its
* internal {@link QueryStructure}.
@ -342,7 +340,7 @@ public class CriteriaQueryImpl<T> extends AbstractNode implements CriteriaQuery<
String sep = "";
for ( Order orderSpec : getOrderList() ) {
jpaqlQuery.append( sep )
.append( ( ( ExpressionImplementor ) orderSpec.getExpression() ).render( renderingContext ) )
.append( ( ( Renderable ) orderSpec.getExpression() ).render( renderingContext ) )
.append( orderSpec.isAscending() ? " asc" : " desc" );
sep = ", ";
}

View File

@ -27,19 +27,19 @@ import java.lang.reflect.Member;
import java.util.Map;
import java.util.Map.Entry;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.MapJoin;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.From;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.MapAttribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type.PersistenceType;
import org.hibernate.ejb.criteria.JoinImplementors.JoinImplementor;
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.Type;
@ -293,7 +293,7 @@ public class MapKeyHelpers {
private String path(CriteriaQueryCompiler.RenderingContext renderingContext) {
return origin.getPathIdentifier()
+ '.'
+ ( (ExpressionImplementor) getAttribute() ).renderProjection( renderingContext );
+ ( (Renderable) getAttribute() ).renderProjection( renderingContext );
}
}

View File

@ -43,8 +43,6 @@ import javax.persistence.criteria.Fetch;
import javax.persistence.criteria.JoinType;
import javax.persistence.metamodel.EntityType;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models basic query structure. Used as a delegate in implementing both
* {@link org.hibernate.criterion.CriteriaQuery} and
@ -214,10 +212,10 @@ public class QueryStructure<T> {
if ( getSelection() == null ) {
// we should have only a single root (query validation should have checked this...)
final Root root = getRoots().iterator().next();
jpaqlQuery.append( ( (ExpressionImplementor) root ).renderProjection( renderingContext) );
jpaqlQuery.append( ( (Renderable) root ).renderProjection( renderingContext) );
}
else {
jpaqlQuery.append( ( (ExpressionImplementor) getSelection() ).renderProjection( renderingContext ) );
jpaqlQuery.append( ( (Renderable) getSelection() ).renderProjection( renderingContext ) );
}
jpaqlQuery.append( " from " );
@ -236,7 +234,7 @@ public class QueryStructure<T> {
if ( getRestriction() != null) {
jpaqlQuery.append( " where " )
.append( ( (ExpressionImplementor) getRestriction() ).render( renderingContext ) );
.append( ( (Renderable) getRestriction() ).render( renderingContext ) );
}
if ( ! getGroupings().isEmpty() ) {
@ -244,13 +242,13 @@ public class QueryStructure<T> {
sep = "";
for ( Expression grouping : getGroupings() ) {
jpaqlQuery.append( sep )
.append( ( (ExpressionImplementor) grouping ).render( renderingContext ) );
.append( ( (Renderable) grouping ).render( renderingContext ) );
sep = ", ";
}
if ( getHaving() != null ) {
jpaqlQuery.append( " having " )
.append( ( (ExpressionImplementor) getHaving() ).render( renderingContext ) );
.append( ( (Renderable) getHaving() ).render( renderingContext ) );
}
}
}

View File

@ -0,0 +1,34 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, 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;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public interface Renderable {
public String render(CriteriaQueryCompiler.RenderingContext renderingContext);
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext);
}

View File

@ -28,6 +28,7 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* Models standard arithmetc operations with two operands.
@ -196,8 +197,8 @@ public class BinaryArithmeticOperation<N extends Number>
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return getOperator().apply(
( (ExpressionImplementor) getLeftHandOperand() ).render( renderingContext ),
( (ExpressionImplementor) getRightHandOperand() ).render( renderingContext )
( (Renderable) getLeftHandOperand() ).render( renderingContext ),
( (Renderable) getRightHandOperand() ).render( renderingContext )
);
}

View File

@ -30,6 +30,7 @@ import javax.persistence.criteria.CriteriaBuilder.Coalesce;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* Models an ANSI SQL <tt>COALESCE</tt> expression. <tt>COALESCE</tt> is a specialized <tt>CASE</tt> statement.
@ -85,7 +86,7 @@ public class CoalesceExpression<T> extends ExpressionImpl<T> implements Coalesce
String sep = "";
for ( Expression expression : getExpressions() ) {
buffer.append( sep )
.append( ( (ExpressionImplementor) expression ).render( renderingContext ) );
.append( ( (Renderable) expression ).render( renderingContext ) );
sep = ", ";
}
return buffer.append( ")" ).toString();

View File

@ -24,11 +24,14 @@
package org.hibernate.ejb.criteria.expression;
import java.util.List;
import javax.persistence.Tuple;
import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.Selection;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.Renderable;
/**
* The Hibernate implementation of the JPA {@link CompoundSelection}
@ -36,7 +39,8 @@ import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
*
* @author Steve Ebersole
*/
public class CompoundSelectionImpl<X> extends SelectionImpl<X> implements CompoundSelection<X> {
public class CompoundSelectionImpl<X> extends SelectionImpl<X> implements CompoundSelection<X>, Renderable {
private final boolean isConstructor;
private List<Selection<?>> selectionItems;
public CompoundSelectionImpl(
@ -44,6 +48,7 @@ public class CompoundSelectionImpl<X> extends SelectionImpl<X> implements Compou
Class<X> javaType,
List<Selection<?>> selectionItems) {
super( criteriaBuilder, javaType );
this.isConstructor = !javaType.isArray() && !Tuple.class.isAssignableFrom( javaType );
this.selectionItems = selectionItems;
}
@ -63,4 +68,24 @@ public class CompoundSelectionImpl<X> extends SelectionImpl<X> implements Compou
}
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder buff = new StringBuilder();
if ( isConstructor ) {
buff.append( "new " ).append( getJavaType().getName() ).append( '(' );
}
String sep = "";
for ( Selection selection : selectionItems ) {
buff.append( sep )
.append( ( (Renderable) selection ).renderProjection( renderingContext ) );
sep = ", ";
}
if ( isConstructor ) {
buff.append( ')' );
}
return buff.toString();
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
return render( renderingContext );
}
}

View File

@ -27,6 +27,7 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* A string concatenation.
@ -78,9 +79,9 @@ public class ConcatExpression extends ExpressionImpl<String> {
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( (ExpressionImplementor) getString1() ).render( renderingContext )
return ( (Renderable) getString1() ).render( renderingContext )
+ " || "
+ ( (ExpressionImplementor) getString2() ).render( renderingContext );
+ ( (Renderable) getString2() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {

View File

@ -35,7 +35,9 @@ import org.hibernate.ejb.criteria.expression.function.CastFunction;
*
* @author Steve Ebersole
*/
public abstract class ExpressionImpl<T> extends SelectionImpl<T> implements ExpressionImplementor<T> {
public abstract class ExpressionImpl<T>
extends SelectionImpl<T>
implements ExpressionImplementor<T> {
public ExpressionImpl(CriteriaBuilderImpl criteriaBuilder, Class<T> javaType) {
super( criteriaBuilder, javaType );
}
@ -43,6 +45,7 @@ public abstract class ExpressionImpl<T> extends SelectionImpl<T> implements Expr
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "unchecked" })
public <X> Expression<X> as(Class<X> type) {
return type.equals( getJavaType() )
? (Expression<X>) this

View File

@ -25,14 +25,12 @@ package org.hibernate.ejb.criteria.expression;
import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
public interface ExpressionImplementor<T> extends Expression<T> {
public String render(CriteriaQueryCompiler.RenderingContext renderingContext);
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext);
public interface ExpressionImplementor<T> extends Expression<T>, Renderable {
}

View File

@ -27,6 +27,7 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* Models an ANSI SQL <tt>NULLIF</tt> expression. <tt>NULLIF</tt> is a specialized <tt>CASE</tt> statement.
@ -76,9 +77,9 @@ public class NullifExpression<T> extends ExpressionImpl<T> {
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return "nullif("
+ ( (ExpressionImplementor) getPrimaryExpression() ).render( renderingContext )
+ ( (Renderable) getPrimaryExpression() ).render( renderingContext )
+ ','
+ ( (ExpressionImplementor) getSecondaryExpression() ).render( renderingContext )
+ ( (Renderable) getSecondaryExpression() ).render( renderingContext )
+ ")";
}

View File

@ -30,6 +30,7 @@ import javax.persistence.criteria.CriteriaBuilder.Case;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* Models what ANSI SQL terms a <tt>searched case expression</tt>. This is a <tt>CASE</tt> expression
@ -129,12 +130,12 @@ public class SearchedCaseExpression<R> extends ExpressionImpl<R> implements Case
StringBuilder caseStatement = new StringBuilder( "case" );
for ( WhenClause whenClause : getWhenClauses() ) {
caseStatement.append( " when " )
.append( ( (ExpressionImplementor) whenClause.getCondition() ).render( renderingContext ) )
.append( ( (Renderable) whenClause.getCondition() ).render( renderingContext ) )
.append( " then " )
.append( ( (ExpressionImplementor) whenClause.getResult() ).render( renderingContext ) );
.append( ( (Renderable) whenClause.getResult() ).render( renderingContext ) );
}
caseStatement.append( " else " )
.append( ( (ExpressionImplementor) getOtherwiseResult() ).render( renderingContext ) )
.append( ( (Renderable) getOtherwiseResult() ).render( renderingContext ) )
.append( " end" );
return caseStatement.toString();
}

View File

@ -30,6 +30,7 @@ import javax.persistence.criteria.CriteriaBuilder.SimpleCase;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* Models what ANSI SQL terms a simple case statement. This is a <tt>CASE</tt> expression in the form<pre>
@ -136,15 +137,15 @@ public class SimpleCaseExpression<C,R> extends ExpressionImpl<R> implements Simp
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder caseExpr = new StringBuilder();
caseExpr.append( "case " )
.append( ( (ExpressionImplementor) getExpression() ).render( renderingContext ) )
.append( ( (Renderable) getExpression() ).render( renderingContext ) )
.append( ' ' );
for ( WhenClause whenClause : getWhenClauses() ) {
caseExpr.append( ( (ExpressionImplementor) whenClause.getCondition() ).render( renderingContext ) )
caseExpr.append( ( (Renderable) whenClause.getCondition() ).render( renderingContext ) )
.append( " then " )
.append( ( (ExpressionImplementor) whenClause.getResult() ).render( renderingContext ) );
.append( ( (Renderable) whenClause.getResult() ).render( renderingContext ) );
}
caseExpr.append( " else " )
.append( ( (ExpressionImplementor) getOtherwiseResult() ).render( renderingContext ) )
.append( ( (Renderable) getOtherwiseResult() ).render( renderingContext ) )
.append( " end" );
return caseExpr.toString();
}

View File

@ -27,6 +27,7 @@ import javax.persistence.criteria.Subquery;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* Represents a {@link Modifier#ALL}, {@link Modifier#ANY}, {@link Modifier#SOME} modifier appplied to a subquery as
@ -80,7 +81,7 @@ public class SubqueryComparisonModifierExpression<Y> extends ExpressionImpl<Y> {
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return getModifier().rendered() + ( ( ExpressionImplementor ) getSubquery() ).render( renderingContext );
return getModifier().rendered() + ( (Renderable) getSubquery() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {

View File

@ -27,6 +27,7 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
/**
* Models unary arithmetic operation (unary plus and unary minus).
@ -74,7 +75,7 @@ public class UnaryArithmeticOperation<T>
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( getOperation() == Operation.UNARY_MINUS ? '-' : '+' )
+ ( (ExpressionImplementor) getOperand() ).render( renderingContext );
+ ( (Renderable) getOperand() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {

View File

@ -28,8 +28,8 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>LOCATE</tt> function.
@ -102,12 +102,12 @@ public class LocateFunction extends BasicFunctionExpression<Integer> {
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder buffer = new StringBuilder();
buffer.append( "locate(" )
.append( ( (ExpressionImplementor) getPattern() ).render( renderingContext ) )
.append( ( (Renderable) getPattern() ).render( renderingContext ) )
.append( ',' )
.append( ( (ExpressionImplementor) getString() ).render( renderingContext ) );
.append( ( (Renderable) getString() ).render( renderingContext ) );
if ( getStart() != null ) {
buffer.append( ',' )
.append( ( (ExpressionImplementor) getStart() ).render( renderingContext ) );
.append( ( (Renderable) getStart() ).render( renderingContext ) );
}
buffer.append( ')' );
return buffer.toString();

View File

@ -31,8 +31,8 @@ import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Support for functions with parameters.
@ -94,7 +94,7 @@ public class ParameterizedFunctionExpression<X>
buffer.append( getFunctionName() )
.append( '(' );
for ( Expression argument : argumentExpressions ) {
buffer.append( ( (ExpressionImplementor) argument ).render( renderingContext ) );
buffer.append( ( (Renderable) argument ).render( renderingContext ) );
}
buffer.append( ')' );
return buffer.toString();

View File

@ -28,8 +28,8 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>SUBSTRING</tt> function.
@ -107,12 +107,12 @@ public class SubstringFunction extends BasicFunctionExpression<String> {
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder buffer = new StringBuilder();
buffer.append( "substring(" )
.append( ( (ExpressionImplementor) getValue() ).render( renderingContext ) )
.append( ( (Renderable) getValue() ).render( renderingContext ) )
.append( ',' )
.append( ( (ExpressionImplementor) getStart() ).render( renderingContext ) );
.append( ( (Renderable) getStart() ).render( renderingContext ) );
if ( getLength() != null ) {
buffer.append( ',' )
.append( ( (ExpressionImplementor) getLength() ).render( renderingContext ) );
.append( ( (Renderable) getLength() ).render( renderingContext ) );
}
buffer.append( ')' );
return buffer.toString();

View File

@ -28,8 +28,8 @@ import javax.persistence.criteria.CriteriaBuilder.Trimspec;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>TRIM</tt> function.
@ -118,9 +118,9 @@ public class TrimFunction extends BasicFunctionExpression<String> {
.append( "trim(" )
.append( trimspec.name() )
.append( ' ' )
.append( ( (ExpressionImplementor) trimCharacter ).render( renderingContext ) )
.append( ( (Renderable) trimCharacter ).render( renderingContext ) )
.append( " from " )
.append( ( (ExpressionImplementor) trimSource ).render( renderingContext ) )
.append( ( (Renderable) trimSource ).render( renderingContext ) )
.append( ')' )
.toString();
}

View File

@ -28,7 +28,7 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
import org.hibernate.ejb.criteria.Renderable;
/**
* Models a <tt>BETWEEN</tt> {@link javax.persistence.criteria.Predicate}.
@ -83,11 +83,11 @@ public class BetweenPredicate<Y> extends AbstractSimplePredicate {
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( (ExpressionImplementor) getExpression() ).render( renderingContext )
return ( (Renderable) getExpression() ).render( renderingContext )
+ " between "
+ ( (ExpressionImplementor) getLowerBound() ).render( renderingContext )
+ ( (Renderable) getLowerBound() ).render( renderingContext )
+ " and "
+ ( (ExpressionImplementor) getUpperBound() ).render( renderingContext );
+ ( (Renderable) getUpperBound() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {

View File

@ -29,7 +29,7 @@ import javax.persistence.criteria.Predicate;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
import org.hibernate.ejb.criteria.Renderable;
/**
* Defines a {@link Predicate} used to wrap an {@link Expression Expression&lt;Boolean&gt;}.
@ -58,7 +58,7 @@ public class BooleanExpressionPredicate extends AbstractSimplePredicate {
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( ( ExpressionImplementor) getExpression() ).render( renderingContext );
return ( (Renderable) getExpression() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {

View File

@ -28,9 +28,9 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.BinaryOperatorExpression;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models a basic relational comparison predicate.
@ -66,7 +66,9 @@ public class ComparisonPredicate extends AbstractSimplePredicate implements Bina
}
public ComparisonOperator getComparisonOperator() {
return comparisonOperator;
return isNegated()
? comparisonOperator.negated()
: comparisonOperator;
}
public Expression getLeftHandOperand() {
@ -142,9 +144,9 @@ public class ComparisonPredicate extends AbstractSimplePredicate implements Bina
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( ( ExpressionImplementor) getLeftHandOperand() ).render( renderingContext )
return ( (Renderable) getLeftHandOperand() ).render( renderingContext )
+ getComparisonOperator().rendered()
+ ( ( ExpressionImplementor) getRightHandOperand() ).render( renderingContext );
+ ( (Renderable) getRightHandOperand() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {

View File

@ -32,7 +32,7 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
import org.hibernate.ejb.criteria.Renderable;
/**
* A compound {@link Predicate predicate} is a grouping of other {@link Predicate predicates} in order to apply
@ -113,14 +113,14 @@ public class CompoundPredicate extends AbstractPredicateImpl {
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
if ( getExpressions().size() == 1 ) {
return ( (ExpressionImplementor) getExpressions().get(0) ).render( renderingContext );
return ( (Renderable) getExpressions().get(0) ).render( renderingContext );
}
final StringBuilder buffer = new StringBuilder();
String sep = "";
for ( Expression expression : getExpressions() ) {
buffer.append( sep )
.append( "( " )
.append( ( (ExpressionImplementor) expression ).render( renderingContext ) )
.append( ( (Renderable) expression ).render( renderingContext ) )
.append( " )" );
sep = operatorTextWithSeparator();
}

View File

@ -27,7 +27,7 @@ import javax.persistence.criteria.Subquery;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
import org.hibernate.ejb.criteria.Renderable;
/**
* Models an <tt>EXISTS(<subquery>)</tt> predicate
@ -52,7 +52,7 @@ public class ExistsPredicate extends AbstractSimplePredicate {
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( isNegated() ? "not " : "" ) + "exists "
+ ( ( ExpressionImplementor ) getSubquery() ).render( renderingContext );
+ ( (Renderable) getSubquery() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {

View File

@ -28,7 +28,7 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
import org.hibernate.ejb.criteria.Renderable;
/**
* ANSI-SQL defines <tt>TRUE</tt>, <tt>FALSE</tt> and <tt>UNKNOWN</tt> as <i>truth values</i>. These
@ -64,7 +64,7 @@ public class ExplicitTruthValueCheck extends AbstractSimplePredicate {
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( (ExpressionImplementor) getBooleanExpression() ).render( renderingContext )
return ( (Renderable) getBooleanExpression() ).render( renderingContext )
+ " = "
+ ( getTruthValue() == TruthValue.TRUE ? "true" : "false" );
}

View File

@ -33,8 +33,8 @@ import javax.persistence.criteria.Subquery;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* TODO : javadoc
@ -158,14 +158,14 @@ public class InPredicate<T> extends AbstractSimplePredicate implements CriteriaB
boolean isInSubqueryPredicate = getValues().size() == 1
&& Subquery.class.isInstance( getValues().get( 0 ) );
if ( isInSubqueryPredicate ) {
buffer.append( ( (ExpressionImplementor) getValues().get(0) ).render( renderingContext ) );
buffer.append( ( (Renderable) getValues().get(0) ).render( renderingContext ) );
}
else {
buffer.append( '(' );
String sep = "";
for ( Expression value : getValues() ) {
buffer.append( sep )
.append( ( (ExpressionImplementor) value ).render( renderingContext ) );
.append( ( (Renderable) value ).render( renderingContext ) );
sep = ", ";
}
buffer.append( ')' );

View File

@ -27,8 +27,8 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models a SQL <tt>LIKE</tt> expression.
@ -124,12 +124,12 @@ public class LikePredicate extends AbstractSimplePredicate {
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder likeExpr = new StringBuilder();
likeExpr.append( ( (ExpressionImplementor) getMatchExpression() ).render( renderingContext ) )
likeExpr.append( ( (Renderable) getMatchExpression() ).render( renderingContext ) )
.append( " like " )
.append( ( (ExpressionImplementor) getPattern() ).render( renderingContext ) );
.append( ( (Renderable) getPattern() ).render( renderingContext ) );
if ( escapeCharacter != null ) {
likeExpr.append( " escape " )
.append( ( (ExpressionImplementor) getEscapeCharacter() ).render( renderingContext ) );
.append( ( (Renderable) getEscapeCharacter() ).render( renderingContext ) );
}
return likeExpr.toString();
}

View File

@ -28,8 +28,8 @@ import javax.persistence.criteria.Expression;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.UnaryOperatorExpression;
import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Defines a {@link javax.persistence.criteria.Predicate} for checking the
@ -65,7 +65,7 @@ public class NullnessPredicate extends AbstractSimplePredicate implements UnaryO
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( (ExpressionImplementor) operand ).render( renderingContext ) + check();
return ( (Renderable) operand ).render( renderingContext ) + check();
}
private String check() {