Author: steve.ebersole(a)jboss.com
Date: 2009-08-10 18:13:04 -0400 (Mon, 10 Aug 2009)
New Revision: 17258
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ParameterContainer.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ParameterRegistry.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SizeOfCollectionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/IsEmptyPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/MemberOfPredicate.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicMapJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapJoinImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/PathImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CollectionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/EntityTypeExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ListIndexExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ParameterExpressionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SelectionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractPredicateImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java
Log:
EJB-447 : Implement JPA 2.0 criteria apis
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicMapJoinImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicMapJoinImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/BasicMapJoinImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -129,8 +129,7 @@
* {@inheritDoc}
*/
public Expression<Entry<K, V>> entry() {
- // TODO : ???
- throw new UnsupportedOperationException("Not supported yet.");
+ return new MapKeyHelpers.MapEntryExpression( queryBuilder(), Map.Entry.class,
getAttribute() );
}
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -37,8 +37,8 @@
import javax.persistence.metamodel.EntityType;
/**
- * The Hibernate implementation of the JPA {@link CriteriaQuery}
- * contract.
+ * The Hibernate implementation of the JPA {@link CriteriaQuery} contract. Mostlty a set
of delegation to its
+ * internal {@link QueryStructure}.
*
* @author Steve Ebersole
*/
@@ -229,8 +229,7 @@
}
public Set<ParameterExpression<?>> getParameters() {
- // TODO-STEVE : implement
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ return queryStructure.getParameters();
}
public <U> Subquery<U> subquery(Class<U> subqueryType) {
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -29,6 +29,7 @@
import javax.persistence.criteria.Join;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.MapJoin;
+import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.SetJoin;
@@ -61,7 +62,13 @@
return parent;
}
+ public void registerParameters(ParameterRegistry registry) {
+ for ( ParameterExpression param : queryStructure.getParameters() ) {
+ registry.registerParameter( param );
+ }
+ }
+
// ROOTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public Set<Root<?>> getRoots() {
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapJoinImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapJoinImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapJoinImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -122,8 +122,7 @@
* {@inheritDoc}
*/
public Expression<Entry<K, V>> entry() {
- // TODO : ???
- throw new UnsupportedOperationException("Not supported yet.");
+ return new MapKeyHelpers.MapEntryExpression( queryBuilder(), Map.Entry.class,
getAttribute() );
}
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -23,6 +23,8 @@
import java.lang.reflect.Member;
import java.util.Map;
+import java.util.Map.Entry;
+import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.MapJoin;
@@ -33,6 +35,7 @@
import javax.persistence.metamodel.MapAttribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type.PersistenceType;
+import org.hibernate.ejb.criteria.expression.ExpressionImpl;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.Type;
@@ -237,6 +240,29 @@
}
}
+ public static class MapEntryExpression<K,V>
+ extends ExpressionImpl<Map.Entry<K,V>>
+ implements Expression<Map.Entry<K,V>> {
+ private final MapAttribute<?, K, V> attribute;
+
+ public MapEntryExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<Entry<K, V>> javaType,
+ MapAttribute<?, K, V> attribute) {
+ super(queryBuilder, javaType);
+ this.attribute = attribute;
+ }
+
+ public MapAttribute<?, K, V> getAttribute() {
+ return attribute;
+ }
+
+ public void registerParameters(ParameterRegistry registry) {
+ // none to register
+ }
+
+ }
+
/**
* Disallow instantiation
*/
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ParameterContainer.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ParameterContainer.java
(rev 0)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ParameterContainer.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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;
+
+import javax.persistence.criteria.Selection;
+
+/**
+ * Contract for query components capable of eirther being a parameter or containing
parameters.
+ *
+ * @author Steve Ebersole
+ */
+public interface ParameterContainer {
+ /**
+ * Register any parameters contained within this query component with the given
registry.
+ *
+ * @param registry The parameter registry with which to register.
+ */
+ public void registerParameters(ParameterRegistry registry);
+
+ /**
+ * Helper to deal with potential parameter container nodes.
+ */
+ public static class Helper {
+ public static void possibleParameter(Selection selection, ParameterRegistry registry)
{
+ if ( ParameterContainer.class.isInstance( selection ) ) {
+ ( (ParameterContainer) selection ).registerParameters( registry );
+ }
+ }
+ }
+}
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ParameterRegistry.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ParameterRegistry.java
(rev 0)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ParameterRegistry.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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;
+
+import javax.persistence.criteria.ParameterExpression;
+
+/**
+ * A registry for parameters. In criteria queries, parameters must be actively seeked
out as expressions and predicates
+ * are added to the {@link org.hibernate.criterion.CriteriaQuery}; this contract allows
the various subcomponents to
+ * register any parameters they contain.
+ *
+ * @author Steve Ebersole
+ */
+public interface ParameterRegistry {
+ /**
+ * Registers the given parameter with this regitry.
+ *
+ * @param parameter The parameter to register.
+ */
+ public void registerParameter(ParameterExpression<?> parameter);
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/PathImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/PathImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/PathImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -139,4 +139,8 @@
throw illegalDereference();
}
+ public void registerParameters(ParameterRegistry registry) {
+ // none to register
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryBuilderImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -43,14 +43,15 @@
import org.hibernate.ejb.EntityManagerFactoryImpl;
import org.hibernate.ejb.criteria.expression.BinaryArithmeticOperation;
import org.hibernate.ejb.criteria.expression.CoalesceExpression;
+import org.hibernate.ejb.criteria.expression.CollectionExpression;
import org.hibernate.ejb.criteria.expression.CompoundSelectionImpl;
import org.hibernate.ejb.criteria.expression.ConcatExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImpl;
import org.hibernate.ejb.criteria.expression.ParameterExpressionImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
import org.hibernate.ejb.criteria.expression.NullifExpression;
import org.hibernate.ejb.criteria.expression.SearchedCaseExpression;
import org.hibernate.ejb.criteria.expression.SimpleCaseExpression;
+import org.hibernate.ejb.criteria.expression.SizeOfCollectionExpression;
import org.hibernate.ejb.criteria.expression.SubqueryComparisonModifierExpression;
import org.hibernate.ejb.criteria.expression.UnaryArithmeticOperation;
import org.hibernate.ejb.criteria.expression.function.AbsFunction;
@@ -62,6 +63,7 @@
import org.hibernate.ejb.criteria.expression.function.LengthFunction;
import org.hibernate.ejb.criteria.expression.function.LocateFunction;
import org.hibernate.ejb.criteria.expression.function.LowerFunction;
+import org.hibernate.ejb.criteria.expression.function.ParameterizedFunctionExpression;
import org.hibernate.ejb.criteria.expression.function.SqrtFunction;
import org.hibernate.ejb.criteria.expression.function.SubstringFunction;
import org.hibernate.ejb.criteria.expression.function.TrimFunction;
@@ -75,7 +77,9 @@
import org.hibernate.ejb.criteria.predicate.InPredicate;
import org.hibernate.ejb.criteria.predicate.BetweenPredicate;
import org.hibernate.ejb.criteria.predicate.ExistsPredicate;
+import org.hibernate.ejb.criteria.predicate.IsEmptyPredicate;
import org.hibernate.ejb.criteria.predicate.LikePredicate;
+import org.hibernate.ejb.criteria.predicate.MemberOfPredicate;
import static
org.hibernate.ejb.criteria.predicate.ComparisonPredicate.ComparisonOperator;
/**
@@ -680,10 +684,24 @@
* {@inheritDoc}
*/
public <T> Expression<T> function(String name, Class<T> returnType,
Expression<?>... arguments) {
- return new BasicFunctionExpression<T>( this, returnType, name, arguments );
+ return new ParameterizedFunctionExpression<T>( this, returnType, name, arguments
);
}
/**
+ * Create a reference to a function taking no params.
+ *
+ * @param name The function name.
+ * @param returnType The return type.
+ *
+ * @param <T> The type of the function return.
+ *
+ * @return The function expression
+ */
+ public <T> Expression<T> function(String name, Class<T> returnType) {
+ return new BasicFunctionExpression<T>( this, returnType, name );
+ }
+
+ /**
* {@inheritDoc}
*/
public <N extends Number> Expression<N> abs(Expression<N> expression)
{
@@ -1137,6 +1155,9 @@
return new NullifExpression<Y>( this, type, exp1, exp2 );
}
+ /**
+ * {@inheritDoc}
+ */
public <Y> Expression<Y> nullif(Expression<Y> exp1, Y exp2) {
return nullif( (Class<Y>)null, exp1, exp2 );
}
@@ -1145,6 +1166,9 @@
return new NullifExpression<Y>( this, type, exp1, exp2 );
}
+ /**
+ * {@inheritDoc}
+ */
public <C, R> SimpleCase<C, R> selectCase(Expression<? extends C>
expression) {
return selectCase( (Class<R>)null, expression );
}
@@ -1153,6 +1177,9 @@
return new SimpleCaseExpression<C, R>( this, type, expression );
}
+ /**
+ * {@inheritDoc}
+ */
public <R> Case<R> selectCase() {
return selectCase( (Class<R>)null );
}
@@ -1161,49 +1188,109 @@
return new SearchedCaseExpression<R>( this, type );
}
+ /**
+ * {@inheritDoc}
+ */
+ public <C extends Collection<?>> Expression<Integer> size(C c) {
+ int size = c == null ? 0 : c.size();
+ return new LiteralExpression<Integer>(this, Integer.class, size);
+ }
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ /**
+ * {@inheritDoc}
+ */
+ public <C extends Collection<?>> Expression<Integer>
size(Expression<C> exp) {
+ if ( LiteralExpression.class.isInstance(exp) ) {
+ return size( ( (LiteralExpression<C>) exp ).getLiteral() );
+ }
+ else if ( CollectionExpression.class.isInstance(exp) ) {
+ return new SizeOfCollectionExpression<C>(this,
(CollectionExpression<C>)null);
+ }
+ // TODO : what other specific types? any?
+ throw new IllegalArgumentException("unknown collection expression type [" +
exp.getClass().getName() + "]" );
+ }
- public <C extends Collection<?>> Predicate isEmpty(Expression<C>
cExpression) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ /**
+ * {@inheritDoc}
+ */
+ public <V, M extends Map<?, V>> Expression<Collection<V>>
values(M map) {
+ return new LiteralExpression<Collection<V>>( this, map.values() );
}
- public <C extends Collection<?>> Predicate isNotEmpty(Expression<C>
colelctionExpression) {
- return isEmpty( colelctionExpression ).negate();
+ /**
+ * {@inheritDoc}
+ */
+ public <K, M extends Map<K, ?>> Expression<Set<K>> keys(M map)
{
+ return new LiteralExpression<Set<K>>( this, map.keySet() );
}
- public <C extends Collection<?>> Expression<Integer> size(C c) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
+
+ /**
+ * {@inheritDoc}
+ */
+ public <C extends Collection<?>> Predicate isEmpty(Expression<C>
collectionExpression) {
+ if ( CollectionExpression.class.isInstance(collectionExpression) ) {
+ return new IsEmptyPredicate(
+ this,
+ (CollectionExpression<C>) collectionExpression
+ );
+ }
+ // TODO : what other specific types? any?
+ throw new IllegalArgumentException(
+ "unknown collection expression type [" +
collectionExpression.getClass().getName() + "]"
+ );
}
- public <C extends Collection<?>> Expression<Integer>
size(Expression<C> cExpression) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ /**
+ * {@inheritDoc}
+ */
+ public <C extends Collection<?>> Predicate isNotEmpty(Expression<C>
collectionExpression) {
+ return isEmpty( collectionExpression ).negate();
}
- public <E, C extends Collection<E>> Predicate isMember(E e,
Expression<C> cExpression) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ /**
+ * {@inheritDoc}
+ */
+ public <E, C extends Collection<E>> Predicate isMember(E e,
Expression<C> collectionExpression) {
+ if ( ! CollectionExpression.class.isInstance(collectionExpression) ) {
+ throw new IllegalArgumentException(
+ "unknown collection expression type [" +
collectionExpression.getClass().getName() + "]"
+ );
+ }
+ return new MemberOfPredicate<E, C>(
+ this,
+ e,
+ (CollectionExpression<C>)collectionExpression
+ );
}
+ /**
+ * {@inheritDoc}
+ */
public <E, C extends Collection<E>> Predicate isNotMember(E e,
Expression<C> cExpression) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ return isMember(e, cExpression).negate();
}
- public <E, C extends Collection<E>> Predicate isMember(Expression<E>
eExpression, Expression<C> cExpression) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ /**
+ * {@inheritDoc}
+ */
+ public <E, C extends Collection<E>> Predicate isMember(Expression<E>
elementExpression, Expression<C> collectionExpression) {
+ if ( ! CollectionExpression.class.isInstance(collectionExpression) ) {
+ throw new IllegalArgumentException(
+ "unknown collection expression type [" +
collectionExpression.getClass().getName() + "]"
+ );
+ }
+ return new MemberOfPredicate<E, C>(
+ this,
+ elementExpression,
+ (CollectionExpression<C>)collectionExpression
+ );
}
+ /**
+ * {@inheritDoc}
+ */
public <E, C extends Collection<E>> Predicate
isNotMember(Expression<E> eExpression, Expression<C> cExpression) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
+ return isMember(eExpression, cExpression).negate();
}
-
- public <V, M extends Map<?, V>> Expression<Collection<V>>
values(M map) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
- }
-
- public <K, M extends Map<K, ?>> Expression<Set<K>> keys(M m) {
- throw new UnsupportedOperationException( "Not yet implemented!" );
- }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -21,15 +21,18 @@
*/
package org.hibernate.ejb.criteria;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.Collections;
+import java.util.LinkedHashSet;
import javax.persistence.criteria.AbstractQuery;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.EntityType;
@@ -63,6 +66,27 @@
private List<Subquery<?>> subqueries;
+ // PARAMETERS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public Set<ParameterExpression<?>> getParameters() {
+ final Set<ParameterExpression<?>> parameters = new
LinkedHashSet<ParameterExpression<?>>();
+ final ParameterRegistry registry = new ParameterRegistry() {
+ public void registerParameter(ParameterExpression<?> parameter) {
+ parameters.add( parameter );
+ }
+ };
+
+ ParameterContainer.Helper.possibleParameter(selection, registry);
+ ParameterContainer.Helper.possibleParameter(restriction, registry);
+ ParameterContainer.Helper.possibleParameter(having, registry);
+ for ( Subquery subquery : getSubqueries() ) {
+ ParameterContainer.Helper.possibleParameter(subquery, registry);
+ }
+
+ return parameters;
+ }
+
+
// SELECTION
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public boolean isDistinction() {
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -23,6 +23,8 @@
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -89,4 +91,10 @@
public Expression<? extends N> getLeftHandOperand() {
return lhs;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getRightHandOperand(), registry );
+ Helper.possibleParameter( getLeftHandOperand(), registry );
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -25,6 +25,8 @@
import java.util.List;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.QueryBuilder.Coalesce;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -65,4 +67,15 @@
return this;
}
+ public List<Expression<? extends T>> getExpressions() {
+ return expressions;
+ }
+
+ public void registerParameters(ParameterRegistry registry) {
+ for ( Expression expression : getExpressions() ) {
+ Helper.possibleParameter(expression, registry);
+ }
+ }
+
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CollectionExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CollectionExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CollectionExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -22,6 +22,7 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.metamodel.PluralAttribute;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.collection.CollectionPersister;
@@ -71,4 +72,7 @@
return persister;
}
+ public void registerParameters(ParameterRegistry registry) {
+ // none to register
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -25,6 +25,8 @@
import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.Selection;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -53,4 +55,11 @@
public List<Selection<?>> getCompoundSelectionItems() {
return selectionItems;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ for ( Selection selectionItem : getCompoundSelectionItems() ) {
+ Helper.possibleParameter(selectionItem, registry);
+ }
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -22,6 +22,8 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -68,4 +70,9 @@
return string2;
}
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getString1(), registry );
+ Helper.possibleParameter( getString2(), registry );
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/EntityTypeExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/EntityTypeExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/EntityTypeExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -21,6 +21,7 @@
*/
package org.hibernate.ejb.criteria.expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -32,4 +33,9 @@
public EntityTypeExpression(QueryBuilderImpl queryBuilder, Class<T> javaType) {
super( queryBuilder, javaType );
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ // nothign to do
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -33,7 +33,7 @@
*
* @author Steve Ebersole
*/
-public class ExpressionImpl<T> extends SelectionImpl<T> implements
Expression<T> {
+public abstract class ExpressionImpl<T> extends SelectionImpl<T> implements
Expression<T> {
public ExpressionImpl(QueryBuilderImpl queryBuilder, Class<T> javaType) {
super( queryBuilder, javaType );
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ListIndexExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ListIndexExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ListIndexExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -1,6 +1,7 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.metamodel.ListAttribute;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -20,4 +21,7 @@
return listAttribute;
}
+ public void registerParameters(ParameterRegistry registry) {
+ // nothign to do
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -21,10 +21,11 @@
*/
package org.hibernate.ejb.criteria.expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
- * TODO : javadoc
+ * Represents a literal expression.
*
* @author Steve Ebersole
*/
@@ -47,4 +48,8 @@
public T getLiteral() {
return literal;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ // nothign to do
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -22,6 +22,8 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -65,4 +67,9 @@
return secondaryExpression;
}
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getPrimaryExpression(), registry );
+ Helper.possibleParameter( getSecondaryExpression(), registry );
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ParameterExpressionImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ParameterExpressionImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ParameterExpressionImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -23,6 +23,7 @@
import javax.persistence.criteria.ParameterExpression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -68,4 +69,9 @@
public Integer getPosition() {
return position;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ registry.registerParameter( this );
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -25,10 +25,12 @@
import java.util.List;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.QueryBuilder.Case;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
- * TODO : javadoc
+ * Models what ANSI SQL terms a <tt>searched case expression</tt
*
* @author Steve Ebersole
*/
@@ -104,5 +106,12 @@
return whenClauses;
}
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getOtherwiseResult(), registry );
+ for ( WhenClause whenClause : getWhenClauses() ) {
+ Helper.possibleParameter( whenClause.getCondition(), registry );
+ Helper.possibleParameter( whenClause.getResult(), registry );
+ }
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SelectionImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SelectionImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SelectionImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -24,6 +24,7 @@
import java.util.List;
import javax.persistence.criteria.Selection;
+import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -32,7 +33,9 @@
*
* @author Steve Ebersole
*/
-public class SelectionImpl<X> extends AbstractTupleElement<X> implements
Selection<X> {
+public abstract class SelectionImpl<X>
+ extends AbstractTupleElement<X>
+ implements Selection<X>, ParameterContainer {
public SelectionImpl(QueryBuilderImpl queryBuilder, Class<X> javaType) {
super( queryBuilder, javaType );
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -25,10 +25,12 @@
import java.util.List;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.QueryBuilder.SimpleCase;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
- * TODO : javadoc
+ * Models what ANSI SQL terms a simple case statement.
*
* @author Steve Ebersole
*/
@@ -111,4 +113,13 @@
public List<WhenClause> getWhenClauses() {
return whenClauses;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getExpression(), registry );
+ for ( WhenClause whenClause : getWhenClauses() ) {
+ Helper.possibleParameter( whenClause.getResult(), registry );
+ }
+ Helper.possibleParameter( getOtherwiseResult(), registry );
+ }
+
}
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SizeOfCollectionExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SizeOfCollectionExpression.java
(rev 0)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SizeOfCollectionExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.util.Collection;
+import org.hibernate.ejb.criteria.ParameterRegistry;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+
+/**
+ * Represents a "size of" expression in regards to a persistent collection; the
implication is
+ * that of a subquery.
+ *
+ * @author Steve Ebersole
+ */
+public class SizeOfCollectionExpression<C extends Collection>
+ extends ExpressionImpl<Integer> {
+ private final CollectionExpression<C> collectionExpression;
+
+ public SizeOfCollectionExpression(
+ QueryBuilderImpl queryBuilder,
+ CollectionExpression<C> collectionExpression) {
+ super(queryBuilder, Integer.class);
+ this.collectionExpression = collectionExpression;
+ }
+
+ public CollectionExpression<C> getCollectionExpression() {
+ return collectionExpression;
+ }
+
+ public void registerParameters(ParameterRegistry registry) {
+ // nothign to do
+ }
+
+}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -1,6 +1,7 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.criteria.Subquery;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -33,4 +34,8 @@
return subquery;
}
+ public void registerParameters(ParameterRegistry registry) {
+ // nothign to do (the subquery should be handled directly, and the modified itself is
not parameterized)
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -1,6 +1,8 @@
package org.hibernate.ejb.criteria.expression;
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -36,4 +38,8 @@
return operation;
}
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getOperand(), registry );
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AbsFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -30,7 +30,7 @@
* @author Steve Ebersole
*/
public class AbsFunction<N extends Number>
- extends BasicFunctionExpression<N> {
+ extends ParameterizedFunctionExpression<N> {
public static final String NAME = "abs";
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -30,22 +30,8 @@
*
* @author Steve Ebersole
*/
-public class AggregationFunction<T> extends BasicFunctionExpression<T> {
+public class AggregationFunction<T> extends
ParameterizedFunctionExpression<T> {
/**
- * Constructs an aggregation function with no arguments (<tt>COUNT(*)</tt>
e.g.).
- *
- * @param queryBuilder The query builder instance.
- * @param returnType The function return type.
- * @param functionName The name of the function.
- */
- public AggregationFunction(
- QueryBuilderImpl queryBuilder,
- Class<T> returnType,
- String functionName) {
- super( queryBuilder, returnType, functionName, NO_ARGS );
- }
-
- /**
* Constructs an aggregation function with a single literal argument.
*
* @param queryBuilder The query builder instance.
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/BasicFunctionExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -21,14 +21,10 @@
*/
package org.hibernate.ejb.criteria.expression.function;
-import java.util.ArrayList;
-import org.hibernate.ejb.criteria.expression.*;
-import java.util.List;
-import java.util.Arrays;
-import java.util.Collections;
-import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.ExpressionImpl;
/**
* Models the basic conept of a SQL function.
@@ -39,46 +35,16 @@
extends ExpressionImpl<X>
implements FunctionExpression<X> {
- public static final List<Expression<?>> NO_ARGS = Collections.emptyList();
-
private final String functionName;
- private final List<Expression<?>> argumentExpressions;
public BasicFunctionExpression(
QueryBuilderImpl queryBuilder,
Class<X> javaType,
String functionName) {
- this( queryBuilder, javaType, functionName, NO_ARGS );
- }
-
- public BasicFunctionExpression(
- QueryBuilderImpl queryBuilder,
- Class<X> javaType,
- String functionName,
- List<Expression<?>> argumentExpressions) {
super( queryBuilder, javaType );
this.functionName = functionName;
- this.argumentExpressions = argumentExpressions;
}
- public BasicFunctionExpression(
- QueryBuilderImpl queryBuilder,
- Class<X> javaType,
- String functionName,
- Expression<?>... argumentExpressions) {
- super( queryBuilder, javaType );
- this.functionName = functionName;
- this.argumentExpressions = Arrays.asList( argumentExpressions );
- }
-
- protected static List<Expression<?>> wrapAsLiterals(QueryBuilderImpl
queryBuilder, Object... literalArguments) {
- List<Expression<?>> arguments = new ArrayList<Expression<?>>(
properSize( literalArguments.length) );
- for ( Object o : literalArguments ) {
- arguments.add( new LiteralExpression( queryBuilder, o ) );
- }
- return arguments;
- }
-
protected static int properSize(int number) {
return number + (int)( number*.75 ) + 1;
}
@@ -91,8 +57,7 @@
return false;
}
-
- public List<Expression<?>> getArgumentExpressions() {
- return argumentExpressions;
+ public void registerParameters(ParameterRegistry registry) {
+ // nothing to do here...
}
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -21,6 +21,7 @@
*/
package org.hibernate.ejb.criteria.expression.function;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
@@ -32,7 +33,7 @@
*
* @author Steve Ebersole
*/
-public class CastFunction<T,Y> extends ExpressionImpl<T> implements
FunctionExpression<T> {
+public class CastFunction<T,Y> extends BasicFunctionExpression<T> implements
FunctionExpression<T> {
public static final String CAST_NAME = "cast";
private final ExpressionImpl<Y> castSource;
@@ -41,20 +42,17 @@
QueryBuilderImpl queryBuilder,
Class<T> javaType,
ExpressionImpl<Y> castSource) {
- super( queryBuilder, javaType );
+ super( queryBuilder, javaType, CAST_NAME );
this.castSource = castSource;
}
- public String getFunctionName() {
- return CAST_NAME;
- }
-
- public boolean isAggregation() {
- return false;
- }
-
public ExpressionImpl<Y> getCastSource() {
return castSource;
}
+ @Override
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getCastSource(), registry );
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LengthFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -29,7 +29,7 @@
*
* @author Steve Ebersole
*/
-public class LengthFunction extends BasicFunctionExpression<Integer> {
+public class LengthFunction extends ParameterizedFunctionExpression<Integer> {
public static final String NAME = "length";
public LengthFunction(QueryBuilderImpl queryBuilder, Expression<String> value) {
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -22,6 +22,8 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
@@ -85,4 +87,10 @@
return string;
}
+ @Override
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getPattern(), registry );
+ Helper.possibleParameter( getStart(), registry );
+ Helper.possibleParameter( getString(), registry );
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LowerFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -29,7 +29,7 @@
*
* @author Steve Ebersole
*/
-public class LowerFunction extends BasicFunctionExpression<String> {
+public class LowerFunction extends ParameterizedFunctionExpression<String> {
public static final String NAME = "lower";
public LowerFunction(QueryBuilderImpl queryBuilder, Expression<String> string) {
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
(rev 0)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.function;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.LiteralExpression;
+
+/**
+ * Support for functions with parameters.
+ *
+ * @author Steve Ebersole
+ */
+public class ParameterizedFunctionExpression<X>
+ extends BasicFunctionExpression<X>
+ implements FunctionExpression<X> {
+
+ private final List<Expression<?>> argumentExpressions;
+
+ public ParameterizedFunctionExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<X> javaType,
+ String functionName,
+ List<Expression<?>> argumentExpressions) {
+ super( queryBuilder, javaType, functionName );
+ this.argumentExpressions = argumentExpressions;
+ }
+
+ public ParameterizedFunctionExpression(
+ QueryBuilderImpl queryBuilder,
+ Class<X> javaType,
+ String functionName,
+ Expression<?>... argumentExpressions) {
+ super( queryBuilder, javaType, functionName );
+ this.argumentExpressions = Arrays.asList( argumentExpressions );
+ }
+
+ protected static List<Expression<?>> wrapAsLiterals(QueryBuilderImpl
queryBuilder, Object... literalArguments) {
+ List<Expression<?>> arguments = new ArrayList<Expression<?>>(
properSize( literalArguments.length) );
+ for ( Object o : literalArguments ) {
+ arguments.add( new LiteralExpression( queryBuilder, o ) );
+ }
+ return arguments;
+ }
+
+ protected static int properSize(int number) {
+ return number + (int)( number*.75 ) + 1;
+ }
+
+ public List<Expression<?>> getArgumentExpressions() {
+ return argumentExpressions;
+ }
+
+ @Override
+ public void registerParameters(ParameterRegistry registry) {
+ for ( Expression argument : getArgumentExpressions() ) {
+ if ( ParameterContainer.class.isInstance( argument ) ) {
+ ( (ParameterContainer) argument ).registerParameters(registry);
+ }
+ }
+ }
+
+}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SqrtFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -29,7 +29,7 @@
*
* @author Steve Ebersole
*/
-public class SqrtFunction extends BasicFunctionExpression<Double> {
+public class SqrtFunction extends ParameterizedFunctionExpression<Double> {
public static final String NAME = "sqrt";
public SqrtFunction(QueryBuilderImpl queryBuilder, Expression<? extends Number>
expression) {
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -1,6 +1,8 @@
package org.hibernate.ejb.criteria.expression.function;
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
@@ -70,5 +72,11 @@
return value;
}
+ @Override
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getLength(), registry );
+ Helper.possibleParameter( getStart(), registry );
+ Helper.possibleParameter( getValue(), registry );
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -2,6 +2,8 @@
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.QueryBuilder.Trimspec;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
@@ -80,4 +82,10 @@
return trimspec;
}
+ @Override
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getTrimCharacter(), registry );
+ Helper.possibleParameter( getTrimSource(), registry );
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/UpperFunction.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -29,7 +29,7 @@
*
* @author Steve Ebersole
*/
-public class UpperFunction extends BasicFunctionExpression<String> {
+public class UpperFunction extends ParameterizedFunctionExpression<String> {
public static final String NAME = "upper";
public UpperFunction(QueryBuilderImpl queryBuilder, Expression<String> string) {
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractPredicateImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractPredicateImpl.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractPredicateImpl.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -53,11 +53,13 @@
// Selection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ @Override
public final boolean isCompoundSelection() {
// Should always be false for predicates
return super.isCompoundSelection();
}
+ @Override
public final List<Selection<?>> getCompoundSelectionItems() {
// Should never have sub selection items for predicates
return super.getCompoundSelectionItems();
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/AbstractSimplePredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -32,7 +32,7 @@
*
* @author Steve Ebersole
*/
-public class AbstractSimplePredicate extends AbstractPredicateImpl {
+public abstract class AbstractSimplePredicate extends AbstractPredicateImpl {
private static final List<Expression<Boolean>> NO_EXPRESSIONS =
Collections.emptyList();
public AbstractSimplePredicate(QueryBuilderImpl queryBuilder) {
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -23,6 +23,8 @@
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -70,4 +72,11 @@
public Expression<? extends Y> getUpperBound() {
return upperBound;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getExpression(), registry );
+ Helper.possibleParameter( getLowerBound(), registry );
+ Helper.possibleParameter( getUpperBound(), registry );
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -24,6 +24,7 @@
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -47,4 +48,8 @@
public Expression<Boolean> getExpression() {
return expression;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter(expression, registry);
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -23,7 +23,9 @@
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.BinaryOperatorExpression;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
/**
@@ -31,7 +33,7 @@
*
* @author Steve Ebersole
*/
-public class ComparisonPredicate extends AbstractSimplePredicate {
+public class ComparisonPredicate extends AbstractSimplePredicate implements
BinaryOperatorExpression<Boolean> {
private final ComparisonOperator comparisonOperator;
private final Expression<?> leftHandSide;
private final Expression<?> rightHandSide;
@@ -62,14 +64,19 @@
return comparisonOperator;
}
- public Expression<?> getLeftHandSide() {
+ public Expression getLeftHandOperand() {
return leftHandSide;
}
- public Expression<?> getRightHandSide() {
+ public Expression getRightHandOperand() {
return rightHandSide;
}
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getLeftHandOperand(), registry );
+ Helper.possibleParameter( getRightHandOperand(), registry );
+ }
+
/**
* Defines the comparison operators. We could also get away with
* only 3 and use negation...
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -27,6 +27,8 @@
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterContainer;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -99,4 +101,11 @@
public List<Expression<Boolean>> getExpressions() {
return expressions;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ for ( Expression expression : getExpressions() ) {
+ Helper.possibleParameter(expression, registry);
+ }
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -22,6 +22,7 @@
package org.hibernate.ejb.criteria.predicate;
import javax.persistence.criteria.Subquery;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -41,4 +42,8 @@
return subquery;
}
+ public void registerParameters(ParameterRegistry registry) {
+ // nothing to do here
+ }
+
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -23,6 +23,7 @@
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
/**
@@ -53,5 +54,9 @@
public TruthValue getTruthValue() {
return truthValue;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getBooleanExpression(), registry );
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -27,6 +27,7 @@
import java.util.Collection;
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
@@ -136,4 +137,11 @@
values.add( value );
return this;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getExpressionInternal(), registry );
+ for ( Expression value : getValues() ) {
+ Helper.possibleParameter(value, registry);
+ }
+ }
}
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/IsEmptyPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/IsEmptyPredicate.java
(rev 0)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/IsEmptyPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.predicate;
+
+import java.util.Collection;
+import org.hibernate.ejb.criteria.ParameterRegistry;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.CollectionExpression;
+import org.hibernate.ejb.criteria.expression.UnaryOperatorExpression;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class IsEmptyPredicate<C extends Collection>
+ extends AbstractSimplePredicate
+ implements UnaryOperatorExpression<Boolean> {
+
+ private final CollectionExpression<C> collectionExpression;
+
+ public IsEmptyPredicate(
+ QueryBuilderImpl queryBuilder,
+ CollectionExpression<C> collectionExpression) {
+ super(queryBuilder);
+ this.collectionExpression = collectionExpression;
+ }
+
+ public CollectionExpression<C> getOperand() {
+ return collectionExpression;
+ }
+
+ public void registerParameters(ParameterRegistry registry) {
+ // nothing to do
+ }
+
+}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -22,6 +22,7 @@
package org.hibernate.ejb.criteria.predicate;
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
@@ -111,5 +112,11 @@
return pattern;
}
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getEscapeCharacter(), registry );
+ Helper.possibleParameter( getMatchExpression(), registry );
+ Helper.possibleParameter( getPattern(), registry );
+ }
+
}
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/MemberOfPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/MemberOfPredicate.java
(rev 0)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/MemberOfPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.predicate;
+
+import java.util.Collection;
+import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
+import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.CollectionExpression;
+import org.hibernate.ejb.criteria.expression.LiteralExpression;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class MemberOfPredicate<E, C extends Collection<E>>
+ extends AbstractSimplePredicate {
+
+ private final Expression<E> elementExpression;
+ private final CollectionExpression<C> collectionExpression;
+
+ public MemberOfPredicate(
+ QueryBuilderImpl queryBuilder,
+ Expression<E> elementExpression,
+ CollectionExpression<C> collectionExpression) {
+ super(queryBuilder);
+ this.elementExpression = elementExpression;
+ this.collectionExpression = collectionExpression;
+ }
+
+ public MemberOfPredicate(
+ QueryBuilderImpl queryBuilder,
+ E element,
+ CollectionExpression<C> collectionExpression) {
+ this(
+ queryBuilder,
+ new LiteralExpression<E>( queryBuilder, element ),
+ collectionExpression
+ );
+ }
+
+ public CollectionExpression<C> getCollectionExpression() {
+ return collectionExpression;
+ }
+
+ public Expression<E> getElementExpression() {
+ return elementExpression;
+ }
+
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getCollectionExpression(), registry );
+ Helper.possibleParameter( getElementExpression(), registry );
+ }
+
+}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java 2009-08-10
15:13:12 UTC (rev 17257)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java 2009-08-10
22:13:04 UTC (rev 17258)
@@ -23,7 +23,9 @@
import javax.persistence.criteria.Expression;
+import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.QueryBuilderImpl;
+import org.hibernate.ejb.criteria.expression.UnaryOperatorExpression;
/**
* Defines a {@link javax.persistence.criteria.Predicate} for checking the
@@ -34,8 +36,8 @@
*
* @author Steve Ebersole
*/
-public class NullnessPredicate extends AbstractSimplePredicate{
- private final Expression<?> nullnessCheckExpression;
+public class NullnessPredicate extends AbstractSimplePredicate implements
UnaryOperatorExpression<Boolean> {
+ private final Expression<?> operand;
/**
* Constructs the affirmitive form of nullness checking (<i>IS NULL</i>).
To
@@ -45,12 +47,16 @@
* @param queryBuilder The query builder from whcih this originates.
* @param expression The expression to check.
*/
- public NullnessPredicate(QueryBuilderImpl queryBuilder, Expression<?> expression)
{
+ public NullnessPredicate(QueryBuilderImpl queryBuilder, Expression<?> operand) {
super( queryBuilder );
- this.nullnessCheckExpression = expression;
+ this.operand = operand;
}
- public Expression<?> getNullnessCheckExpression() {
- return nullnessCheckExpression;
+ public Expression<?> getOperand() {
+ return operand;
}
+
+ public void registerParameters(ParameterRegistry registry) {
+ Helper.possibleParameter( getOperand(), registry );
+ }
}