Report
by Post Office
The original message was received at Tue, 11 Aug 2009 09:42:16 +0700
from lists.jboss.org [109.245.173.144]
----- The following addresses had permanent fatal errors -----
hibernate-commits(a)lists.jboss.org
15 years, 3 months
Hibernate SVN: r17261 - in validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation: engine/resolver and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-10 21:01:18 -0400 (Mon, 10 Aug 2009)
New Revision: 17261
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java
Log:
HV-171 partial implementation adding due doPriviledge when needed
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java 2009-08-11 00:53:08 UTC (rev 17260)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -17,10 +17,13 @@
*/
package org.hibernate.validation.engine;
+import java.security.AccessController;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.ValidationException;
+import org.hibernate.validation.util.priviledgedactions.NewInstance;
+
/**
* Default <code>ConstraintValidatorFactory</code> using a no-arg constructor.
*
@@ -30,17 +33,12 @@
public class ConstraintValidatorFactoryImpl implements ConstraintValidatorFactory {
public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
- try {
- return key.newInstance();
+ NewInstance<T> newInstance = NewInstance.action( key, "" );
+ if ( System.getSecurityManager() != null ) {
+ return AccessController.doPrivileged( newInstance );
}
- catch ( InstantiationException e ) {
- throw new ValidationException( "Unable to instanciate " + key, e );
+ else {
+ return newInstance.run();
}
- catch ( IllegalAccessException e ) {
- throw new ValidationException( "Unable to instanciate " + key, e );
- }
- catch ( RuntimeException e ) {
- throw new ValidationException( "Unable to instanciate " + key, e );
- }
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java 2009-08-11 00:53:08 UTC (rev 17260)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/resolver/DefaultTraversableResolver.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -1,13 +1,16 @@
package org.hibernate.validation.engine.resolver;
import java.lang.annotation.ElementType;
+import java.security.AccessController;
import javax.validation.Path;
import javax.validation.TraversableResolver;
+import javax.validation.ValidationException;
import org.slf4j.Logger;
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
+import org.hibernate.validation.util.priviledgedactions.NewInstance;
/**
* A JPA 2 aware <code>TraversableResolver</code>.
@@ -56,10 +59,16 @@
}
try {
- Class jpaAwareResolverClass = ReflectionHelper.classForName(
- JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME, this.getClass()
- );
- jpaTraversableResolver = ( TraversableResolver ) jpaAwareResolverClass.newInstance();
+ @SuppressWarnings( "unchecked" )
+ Class<? extends TraversableResolver> jpaAwareResolverClass = (Class<? extends TraversableResolver>)
+ ReflectionHelper.classForName(JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME, this.getClass() );
+ NewInstance<? extends TraversableResolver> newInstance = NewInstance.action( jpaAwareResolverClass, "" );
+ if ( System.getSecurityManager() != null ) {
+ jpaTraversableResolver = AccessController.doPrivileged( newInstance );
+ }
+ else {
+ jpaTraversableResolver = newInstance.run();
+ }
log.info(
"Instantiated an instance of {}.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
);
@@ -70,18 +79,12 @@
JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
);
}
- catch ( IllegalAccessException e ) {
+ catch ( ValidationException e ) {
log.info(
"Unable to instantiate JPA aware resolver {}. All properties will per default be traversable.",
JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
);
}
- catch ( InstantiationException e ) {
- log.info(
- "Unable to instantiate JPA aware resolver {}. All properties will per default be traversable.",
- JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
- );
- }
}
public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java 2009-08-11 00:53:08 UTC (rev 17260)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -28,6 +28,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import javax.validation.Constraint;
import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintPayload;
@@ -42,6 +44,9 @@
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
+import org.hibernate.validation.util.priviledgedactions.GetMethods;
+import org.hibernate.validation.util.priviledgedactions.GetMethod;
+import org.hibernate.validation.util.priviledgedactions.GetAnnotationParameter;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
@@ -121,12 +126,13 @@
Class<ConstraintPayload>[] payloadFromAnnotation;
try {
//TODO be extra safe and make sure this is an array of ConstraintPayload
- @SuppressWarnings("unchecked")
- Class<ConstraintPayload>[] unsafePayloadFromAnnotation = ( Class<ConstraintPayload>[] )
- ReflectionHelper.getAnnotationParameter(
- annotation, PAYLOAD, Class[].class
- );
- payloadFromAnnotation = unsafePayloadFromAnnotation;
+ GetAnnotationParameter<Class[]> action = GetAnnotationParameter.action( annotation, PAYLOAD, Class[].class );
+ if (System.getSecurityManager() != null) {
+ payloadFromAnnotation = AccessController.doPrivileged( action );
+ }
+ else {
+ payloadFromAnnotation = action.run();
+ }
}
catch ( ValidationException e ) {
//ignore people not defining payloads
@@ -140,9 +146,14 @@
private Set<Class<?>> buildGroupSet(Class<?> implicitGroup) {
Set<Class<?>> groupSet = new HashSet<Class<?>>();
- Class<?>[] groupsFromAnnotation = ReflectionHelper.getAnnotationParameter(
- annotation, GROUPS, Class[].class
- );
+ final Class<?>[] groupsFromAnnotation;
+ GetAnnotationParameter<Class[]> action = GetAnnotationParameter.action( annotation, GROUPS, Class[].class );
+ if (System.getSecurityManager() != null) {
+ groupsFromAnnotation = AccessController.doPrivileged( action );
+ }
+ else {
+ groupsFromAnnotation = action.run();
+ }
if ( groupsFromAnnotation.length == 0 ) {
groupSet.add( Default.class );
}
@@ -270,7 +281,16 @@
private Map<ClassIndexWrapper, Map<String, Object>> parseOverrideParameters() {
Map<ClassIndexWrapper, Map<String, Object>> overrideParameters = new HashMap<ClassIndexWrapper, Map<String, Object>>();
- for ( Method m : annotation.annotationType().getMethods() ) {
+ final Method[] methods;
+ final GetMethods getMethods = GetMethods.action( annotation.annotationType() );
+ if ( System.getSecurityManager() != null ) {
+ methods = AccessController.doPrivileged( getMethods );
+ }
+ else {
+ methods = getMethods.run();
+ }
+
+ for ( Method m : methods ) {
if ( m.getAnnotation( OverridesAttribute.class ) != null ) {
addOverrideAttributes(
overrideParameters, m, m.getAnnotation( OverridesAttribute.class )
@@ -306,21 +326,25 @@
}
private void ensureAttributeIsOverridable(Method m, OverridesAttribute overridesAttribute) {
- try {
- Class<?> returnTypeOfOverridenConstraint = overridesAttribute.constraint()
- .getMethod( overridesAttribute.name() )
- .getReturnType();
- if ( !returnTypeOfOverridenConstraint.equals( m.getReturnType() ) ) {
- String message = "The overiding type of a composite constraint must be identical to the overwridden one. Expected " + returnTypeOfOverridenConstraint
- .getName() + " found " + m.getReturnType();
- throw new ConstraintDefinitionException( message );
- }
+ final GetMethod getMethod = GetMethod.action( overridesAttribute.constraint(), overridesAttribute.name() );
+ final Method method;
+ if ( System.getSecurityManager() != null ) {
+ method = AccessController.doPrivileged( getMethod );
}
- catch ( NoSuchMethodException nsme ) {
+ else {
+ method = getMethod.run();
+ }
+ if (method == null) {
throw new ConstraintDefinitionException(
"Overriden constraint does not define an attribute with name " + overridesAttribute.name()
);
}
+ Class<?> returnTypeOfOverridenConstraint = method.getReturnType();
+ if ( !returnTypeOfOverridenConstraint.equals( m.getReturnType() ) ) {
+ String message = "The overiding type of a composite constraint must be identical to the overwridden one. Expected " + returnTypeOfOverridenConstraint
+ .getName() + " found " + m.getReturnType();
+ throw new ConstraintDefinitionException( message );
+ }
}
private Set<ConstraintDescriptor<?>> parseComposingConstraints() {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintHelper.java 2009-08-11 00:53:08 UTC (rev 17260)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintHelper.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
+import java.security.AccessController;
import javax.validation.Constraint;
import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintValidator;
@@ -72,6 +73,9 @@
import org.hibernate.validation.constraints.impl.SizeValidatorForMap;
import org.hibernate.validation.constraints.impl.SizeValidatorForString;
import org.hibernate.validation.util.ReflectionHelper;
+import org.hibernate.validation.util.priviledgedactions.GetMethods;
+import org.hibernate.validation.util.priviledgedactions.GetMethod;
+import org.hibernate.validation.util.priviledgedactions.GetAnnotationParameter;
/**
* Keeps track of builtin constraints and their validator implementations, as well as already resolved validator definitions.
@@ -193,24 +197,30 @@
public boolean isMultiValueConstraint(Annotation annotation) {
boolean isMultiValueConstraint = false;
try {
- Method m = annotation.getClass().getMethod( "value" );
- Class returnType = m.getReturnType();
- if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
- Annotation[] annotations = ( Annotation[] ) m.invoke( annotation );
- for ( Annotation a : annotations ) {
- if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a.annotationType() ) ) {
- isMultiValueConstraint = true;
+ final GetMethod getMethod = GetMethod.action( annotation.getClass(), "value" );
+ final Method method;
+ if ( System.getSecurityManager() != null ) {
+ method = AccessController.doPrivileged( getMethod );
+ }
+ else {
+ method = getMethod.run();
+ }
+ if (method != null) {
+ Class returnType = method.getReturnType();
+ if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
+ Annotation[] annotations = ( Annotation[] ) method.invoke( annotation );
+ for ( Annotation a : annotations ) {
+ if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a.annotationType() ) ) {
+ isMultiValueConstraint = true;
+ }
+ else {
+ isMultiValueConstraint = false;
+ break;
+ }
}
- else {
- isMultiValueConstraint = false;
- break;
- }
}
}
}
- catch ( NoSuchMethodException nsme ) {
- // ignore
- }
catch ( IllegalAccessException iae ) {
// ignore
}
@@ -232,20 +242,26 @@
public <A extends Annotation> List<Annotation> getMultiValueConstraints(A annotation) {
List<Annotation> annotationList = new ArrayList<Annotation>();
try {
- Method m = annotation.getClass().getMethod( "value" );
- Class returnType = m.getReturnType();
- if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
- Annotation[] annotations = ( Annotation[] ) m.invoke( annotation );
- for ( Annotation a : annotations ) {
- if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a.annotationType() ) ) {
- annotationList.add( a );
+ final GetMethod getMethod = GetMethod.action( annotation.getClass(), "value" );
+ final Method method;
+ if ( System.getSecurityManager() != null ) {
+ method = AccessController.doPrivileged( getMethod );
+ }
+ else {
+ method = getMethod.run();
+ }
+ if (method != null) {
+ Class returnType = method.getReturnType();
+ if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
+ Annotation[] annotations = ( Annotation[] ) method.invoke( annotation );
+ for ( Annotation a : annotations ) {
+ if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a.annotationType() ) ) {
+ annotationList.add( a );
+ }
}
}
}
}
- catch ( NoSuchMethodException nsme ) {
- // ignore
- }
catch ( IllegalAccessException iae ) {
// ignore
}
@@ -287,7 +303,14 @@
}
private void assertNoParameterStartsWithValid(Annotation annotation) {
- Method[] methods = annotation.getClass().getMethods();
+ final Method[] methods;
+ final GetMethods getMethods = GetMethods.action( annotation.annotationType() );
+ if ( System.getSecurityManager() != null ) {
+ methods = AccessController.doPrivileged( getMethods );
+ }
+ else {
+ methods = getMethods.run();
+ }
for ( Method m : methods ) {
if ( m.getName().startsWith( "valid" ) ) {
String msg = "Parameters starting with 'valid' are not allowed in a constraint.";
@@ -298,9 +321,20 @@
private void assertPayloadParameterExists(Annotation annotation) {
try {
- Class<?>[] defaultPayload = ( Class<?>[] ) annotation.annotationType()
- .getMethod( "payload" )
- .getDefaultValue();
+ final GetMethod getMethod = GetMethod.action( annotation.annotationType(), "payload" );
+ final Method method;
+ if ( System.getSecurityManager() != null ) {
+ method = AccessController.doPrivileged( getMethod );
+ }
+ else {
+ method = getMethod.run();
+ }
+ if (method == null) {
+ String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
+ "not contain a payload parameter.";
+ throw new ConstraintDefinitionException( msg );
+ }
+ Class<?>[] defaultPayload = ( Class<?>[] ) method.getDefaultValue();
if ( defaultPayload.length != 0 ) {
String msg = annotation.annotationType()
.getName() + " contains Constraint annotation, but the payload " +
@@ -313,18 +347,24 @@
"payload parameter is of wrong type.";
throw new ConstraintDefinitionException( msg );
}
- catch ( NoSuchMethodException nsme ) {
- String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
- "not contain a payload parameter.";
- throw new ConstraintDefinitionException( msg );
- }
}
private void assertGroupsParameterExists(Annotation annotation) {
try {
- Class<?>[] defaultGroups = ( Class<?>[] ) annotation.annotationType()
- .getMethod( "groups" )
- .getDefaultValue();
+ final GetMethod getMethod = GetMethod.action( annotation.annotationType(), "groups" );
+ final Method method;
+ if ( System.getSecurityManager() != null ) {
+ method = AccessController.doPrivileged( getMethod );
+ }
+ else {
+ method = getMethod.run();
+ }
+ if (method == null) {
+ String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
+ "not contain a groups parameter.";
+ throw new ConstraintDefinitionException( msg );
+ }
+ Class<?>[] defaultGroups = ( Class<?>[] ) method.getDefaultValue();
if ( defaultGroups.length != 0 ) {
String msg = annotation.annotationType()
.getName() + " contains Constraint annotation, but the groups " +
@@ -337,16 +377,17 @@
"groups parameter is of wrong type.";
throw new ConstraintDefinitionException( msg );
}
- catch ( NoSuchMethodException nsme ) {
- String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
- "not contain a groups parameter.";
- throw new ConstraintDefinitionException( msg );
- }
}
private void assertMessageParameterExists(Annotation annotation) {
try {
- ReflectionHelper.getAnnotationParameter( annotation, "message", String.class );
+ GetAnnotationParameter<?> action = GetAnnotationParameter.action( annotation, "message", String.class );
+ if (System.getSecurityManager() != null) {
+ AccessController.doPrivileged( action );
+ }
+ else {
+ action.run();
+ }
}
catch ( Exception e ) {
String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-08-11 00:53:08 UTC (rev 17260)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -50,6 +50,7 @@
private ReflectionHelper() {
}
+ //run client in priviledge block
@SuppressWarnings("unchecked")
public static <T> T getAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
try {
@@ -355,19 +356,6 @@
}
/**
- * Checks whether the specified class contains a field or property matching the given name.
- *
- * @param clazz The class to check.
- * @param property The property name.
- *
- * @return Returns <code>true</code> if the cass contains a field or member for the specified property, <code>
- * false</code> otherwise.
- */
- public static boolean containsMember(Class<?> clazz, String property) {
- return containsField( clazz, property ) || containsMethod( clazz, property );
- }
-
- /**
* Checks whether the specified class contains a field matching the specified name.
*
* @param clazz The class to check.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java 2009-08-11 00:53:08 UTC (rev 17260)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/annotationfactory/AnnotationFactory.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -22,8 +22,11 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
+import java.security.AccessController;
+import org.hibernate.validation.util.priviledgedactions.GetConstructor;
+
/**
* Creates live annotations (actually <code>AnnotationProxies</code>) from <code>AnnotationDescriptors</code>.
*
@@ -53,7 +56,14 @@
private static <T extends Annotation> T getProxyInstance(Class<T> proxyClass, InvocationHandler handler) throws
SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
IllegalAccessException, InvocationTargetException {
- Constructor<T> constructor = proxyClass.getConstructor( new Class[]{InvocationHandler.class} );
+ GetConstructor<T> action = GetConstructor.action( proxyClass, InvocationHandler.class );
+ final Constructor<T> constructor;
+ if ( System.getSecurityManager() != null ) {
+ constructor = AccessController.doPrivileged( action );
+ }
+ else {
+ constructor = action.run();
+ }
return constructor.newInstance( new Object[]{handler} );
}
}
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/ContainsMethod.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -0,0 +1,27 @@
+package org.hibernate.validation.util.priviledgedactions;
+
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validation.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ContainsMethod implements PrivilegedAction<Boolean> {
+ private final Class<?> clazz;
+ private final String property;
+
+ public static ContainsMethod action(Class<?> clazz, String property) {
+ return new ContainsMethod( clazz, property );
+ }
+
+ private ContainsMethod(Class<?> clazz, String property) {
+ this.clazz = clazz;
+ this.property = property;
+ }
+
+ public Boolean run() {
+ return ReflectionHelper.containsMethod( clazz, property );
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetAnnotationParameter.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -0,0 +1,31 @@
+package org.hibernate.validation.util.priviledgedactions;
+
+import java.lang.reflect.Method;
+import java.lang.annotation.Annotation;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validation.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetAnnotationParameter<T> implements PrivilegedAction<T> {
+ private final Annotation annotation;
+ private final String parameterName;
+ private final Class<T> type;
+
+
+ public static <T> GetAnnotationParameter<T> action(Annotation annotation, String parameterName, Class<T> type) {
+ return new GetAnnotationParameter<T>( annotation, parameterName, type );
+ }
+
+ private GetAnnotationParameter(Annotation annotation, String parameterName, Class<T> type) {
+ this.annotation = annotation;
+ this.parameterName = parameterName;
+ this.type = type;
+ }
+
+ public T run() {
+ return ReflectionHelper.getAnnotationParameter( annotation, parameterName, type );
+ }
+}
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetConstructor.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -0,0 +1,31 @@
+package org.hibernate.validation.util.priviledgedactions;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetConstructor<T> implements PrivilegedAction<Constructor<T>> {
+ private final Class<T> clazz;
+ private final Class<?>[] params;
+
+ public static <T> GetConstructor<T> action(Class<T> clazz, Class<?>... params) {
+ return new GetConstructor<T>( clazz, params );
+ }
+
+ private GetConstructor(Class<T> clazz, Class<?>... params) {
+ this.clazz = clazz;
+ this.params = params;
+ }
+
+ public Constructor<T> run() {
+ try {
+ return clazz.getConstructor(params);
+ }
+ catch ( NoSuchMethodException e ) {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethod.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -0,0 +1,30 @@
+package org.hibernate.validation.util.priviledgedactions;
+
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethod implements PrivilegedAction<Method> {
+ private final Class<?> clazz;
+ private final String methodName;
+
+ public static GetMethod action(Class<?> clazz, String methodName) {
+ return new GetMethod( clazz, methodName );
+ }
+
+ private GetMethod(Class<?> clazz, String methodName) {
+ this.clazz = clazz;
+ this.methodName = methodName;
+ }
+
+ public Method run() {
+ try {
+ return clazz.getMethod(methodName);
+ }
+ catch ( NoSuchMethodException e ) {
+ return null;
+ }
+ }
+}
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethodFromPropertyName.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -0,0 +1,27 @@
+package org.hibernate.validation.util.priviledgedactions;
+
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+
+import org.hibernate.validation.util.ReflectionHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethodFromPropertyName implements PrivilegedAction<Method> {
+ private final Class<?> clazz;
+ private final String property;
+
+ public static GetMethodFromPropertyName action(Class<?> clazz, String property) {
+ return new GetMethodFromPropertyName( clazz, property );
+ }
+
+ private GetMethodFromPropertyName(Class<?> clazz, String property) {
+ this.clazz = clazz;
+ this.property = property;
+ }
+
+ public Method run() {
+ return ReflectionHelper.getMethod( clazz, property );
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/GetMethods.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -0,0 +1,23 @@
+package org.hibernate.validation.util.priviledgedactions;
+
+import java.security.PrivilegedAction;
+import java.lang.reflect.Method;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetMethods implements PrivilegedAction<Method[]> {
+ private final Class<?> clazz;
+
+ public static GetMethods action(Class<?> clazz) {
+ return new GetMethods( clazz );
+ }
+
+ private GetMethods(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public Method[] run() {
+ return clazz.getMethods();
+ }
+}
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/priviledgedactions/NewInstance.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -0,0 +1,37 @@
+package org.hibernate.validation.util.priviledgedactions;
+
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+import javax.validation.ValidationException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class NewInstance<T> implements PrivilegedAction<T> {
+ private final Class<T> clazz;
+ private final String message;
+
+ public static <T> NewInstance<T> action(Class<T> clazz, String message) {
+ return new NewInstance<T>( clazz, message );
+ }
+
+ private NewInstance(Class<T> clazz, String message) {
+ this.clazz = clazz;
+ this.message = message;
+ }
+
+ public T run() {
+ try {
+ return clazz.newInstance();
+ }
+ catch ( InstantiationException e ) {
+ throw new ValidationException( "Unable to instanciate " + message + ": " + clazz, e );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException( "Unable to instanciate " + clazz, e );
+ }
+ catch ( RuntimeException e ) {
+ throw new ValidationException( "Unable to instanciate " + clazz, e );
+ }
+ }
+}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java 2009-08-11 00:53:08 UTC (rev 17260)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/ValidationXmlParser.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -19,6 +19,7 @@
import java.io.InputStream;
import java.net.URL;
+import java.security.AccessController;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
@@ -37,6 +38,7 @@
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
+import org.hibernate.validation.util.priviledgedactions.NewInstance;
import org.hibernate.validation.xml.PropertyType;
import org.hibernate.validation.xml.ValidationConfigType;
@@ -80,7 +82,13 @@
Class<ConstraintValidatorFactory> clazz = ( Class<ConstraintValidatorFactory> ) ReflectionHelper.classForName(
constraintFactoryClass, this.getClass()
);
- xmlParameters.constraintValidatorFactory = clazz.newInstance();
+ NewInstance<ConstraintValidatorFactory> newInstance = NewInstance.action( clazz, "constraint factory class" );
+ if ( System.getSecurityManager() != null ) {
+ xmlParameters.constraintValidatorFactory = AccessController.doPrivileged( newInstance );
+ }
+ else {
+ xmlParameters.constraintValidatorFactory = newInstance.run();
+ }
log.info( "Using {} as constraint factory.", constraintFactoryClass );
}
catch ( ClassNotFoundException e ) {
@@ -88,16 +96,6 @@
"Unable to instantiate constraint factory class " + constraintFactoryClass + ".", e
);
}
- catch ( InstantiationException e ) {
- throw new ValidationException(
- "Unable to instantiate constraint factory class " + constraintFactoryClass + ".", e
- );
- }
- catch ( IllegalAccessException e ) {
- throw new ValidationException(
- "Unable to instantiate constraint factory class " + constraintFactoryClass + ".", e
- );
- }
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java 2009-08-11 00:53:08 UTC (rev 17260)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/xml/XmlMappingParser.java 2009-08-11 01:01:18 UTC (rev 17261)
@@ -33,6 +33,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.security.AccessController;
import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ValidationException;
@@ -53,6 +54,9 @@
import org.hibernate.validation.metadata.AnnotationIgnores;
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
+import org.hibernate.validation.util.priviledgedactions.GetMethodFromPropertyName;
+import org.hibernate.validation.util.priviledgedactions.ContainsMethod;
+import org.hibernate.validation.util.priviledgedactions.GetMethod;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
import org.hibernate.validation.xml.AnnotationType;
@@ -267,10 +271,25 @@
private void parsePropertyLevelOverrides(List<GetterType> getters, Class<?> beanClass, String defaultPackage) {
for ( GetterType getterType : getters ) {
String getterName = getterType.getName();
- if ( !ReflectionHelper.containsMethod( beanClass, getterName ) ) {
+ ContainsMethod cmAction = ContainsMethod.action( beanClass, getterName );
+ boolean containsMethod;
+ if ( System.getSecurityManager() != null ) {
+ containsMethod = AccessController.doPrivileged( cmAction );
+ }
+ else {
+ containsMethod = cmAction.run();
+ }
+ if ( !containsMethod ) {
throw new ValidationException( beanClass.getName() + " does not contain the property " + getterName );
}
- Method method = ReflectionHelper.getMethod( beanClass, getterName );
+ final Method method;
+ GetMethodFromPropertyName action = GetMethodFromPropertyName.action( beanClass, getterName );
+ if ( System.getSecurityManager() != null ) {
+ method = AccessController.doPrivileged( action );
+ }
+ else {
+ method = action.run();
+ }
// ignore annotations
boolean ignoreGetterAnnotation = getterType.isIgnoreAnnotations() == null ? false : getterType.isIgnoreAnnotations();
@@ -383,10 +402,15 @@
private <A extends Annotation> Class<?> getAnnotationParamterType(Class<A> annotationClass, String name) {
Method m;
- try {
- m = annotationClass.getMethod( name );
+ GetMethod action = GetMethod.action( annotationClass, name );
+ if ( System.getSecurityManager() != null ) {
+ m = AccessController.doPrivileged( action );
}
- catch ( NoSuchMethodException e ) {
+ else {
+ m = action.run();
+ }
+
+ if ( m == null ) {
throw new ValidationException( "Annotation of type " + annotationClass.getName() + " does not contain a paramter " + name + "." );
}
return m.getReturnType();
15 years, 3 months
Hibernate SVN: r17260 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-10 20:53:08 -0400 (Mon, 10 Aug 2009)
New Revision: 17260
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java
Log:
fix NPE when identifier is not a property
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java 2009-08-11 00:26:13 UTC (rev 17259)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/EntityTypeImpl.java 2009-08-11 00:53:08 UTC (rev 17260)
@@ -49,18 +49,23 @@
}
private <A> SingularAttribute<X, A> buildIdAttribute(PersistentClass persistentClass) {
- final Property identifierProperty = persistentClass.getIdentifierProperty();
- @SuppressWarnings( "unchecked" )
- Class<A> idClass = identifierProperty.getType().getReturnedClass();
- final Type<A> attrType = new BasicTypeImpl<A>( idClass,
- identifierProperty.isComposite() ?
- PersistenceType.EMBEDDABLE :
- PersistenceType.BASIC);
- return SingularAttributeImpl.create(this, attrType )
- .property(identifierProperty)
- //.member( null ) //TODO member
- .id()
- .build();
+ if ( hasIdentifierProperty ) {
+ final Property identifierProperty = persistentClass.getIdentifierProperty();
+ @SuppressWarnings( "unchecked" )
+ Class<A> idClass = identifierProperty.getType().getReturnedClass();
+ final Type<A> attrType = new BasicTypeImpl<A>( idClass,
+ identifierProperty.isComposite() ?
+ PersistenceType.EMBEDDABLE :
+ PersistenceType.BASIC);
+ return SingularAttributeImpl.create(this, attrType )
+ .property(identifierProperty)
+ //.member( null ) //TODO member
+ .id()
+ .build();
+ }
+ else {
+ return null;
+ }
}
private <A> SingularAttribute<X, A> buildVersionAttribute(PersistentClass persistentClass) {
@@ -101,11 +106,16 @@
public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) {
//TODO check that type and id.getJavaType() are related
+ checkId();
@SuppressWarnings( "unchecked")
final SingularAttribute<? super X, Y> result = ( SingularAttribute<? super X, Y> ) id;
return result;
}
+ private void checkId() {
+ if ( ! hasSingleIdAttribute() ) throw new IllegalArgumentException("This is an @IdClass");
+ }
+
public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
//TODO check that type and version.getJavaType() are related
@SuppressWarnings( "unchecked")
@@ -114,6 +124,7 @@
}
public <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type) {
+ checkId();
//TODO check that type and id.getJavaType() are related
@SuppressWarnings("unchecked")
final SingularAttribute<X, Y> result = ( SingularAttribute<X, Y> ) id;
@@ -147,6 +158,7 @@
}
public Type<?> getIdType() {
+ checkId();
return id.getType();
}
15 years, 3 months
Hibernate SVN: r17259 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-10 20:26:13 -0400 (Mon, 10 Aug 2009)
New Revision: 17259
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java
Log:
make Metamodel and its dependencies serializable
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java 2009-08-10 22:13:04 UTC (rev 17258)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/ManagedTypeImpl.java 2009-08-11 00:26:13 UTC (rev 17259)
@@ -6,6 +6,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
+import java.io.Serializable;
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.Attribute;
@@ -23,12 +24,13 @@
/**
* @author Emmanuel Bernard
*/
-public abstract class ManagedTypeImpl<X> implements ManagedType<X> {
+public abstract class ManagedTypeImpl<X> implements ManagedType<X>, Serializable {
private final Class<X> javaClass;
private final Map<String,Attribute<X, ?>> declaredAttributes;
private final Map<String,SingularAttribute<X, ?>> declaredSingularAttributes;
private final Map<String,PluralAttribute<X, ?, ?>> declaredCollections;
+
ManagedTypeImpl(Class<X> clazz, Iterator<Property> properties, MetadataContext context) {
this.javaClass = clazz;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java 2009-08-10 22:13:04 UTC (rev 17258)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/PluralAttributeImpl.java 2009-08-11 00:26:13 UTC (rev 17259)
@@ -5,6 +5,7 @@
import java.util.List;
import java.util.Set;
import java.util.Collection;
+import java.io.Serializable;
import javax.persistence.metamodel.PluralAttribute;
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.Type;
@@ -18,7 +19,7 @@
/**
* @author Emmanuel Bernard
*/
-public abstract class PluralAttributeImpl<X, C, E> implements PluralAttribute<X, C, E> {
+public abstract class PluralAttributeImpl<X, C, E> implements PluralAttribute<X, C, E>, Serializable {
private final ManagedType<X> ownerType;
private final Type<E> elementType;
15 years, 3 months
Hibernate SVN: r17258 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression and 2 other directories.
by hibernate-commits@lists.jboss.org
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 );
+ }
}
15 years, 3 months
Hibernate SVN: r17257 - core/trunk/core/src/main/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-10 11:13:12 -0400 (Mon, 10 Aug 2009)
New Revision: 17257
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
Log:
HHH-4077 improper use of logicalColumnName
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2009-08-10 06:40:43 UTC (rev 17256)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2009-08-10 15:13:12 UTC (rev 17257)
@@ -1074,11 +1074,12 @@
column.setValue( simpleValue );
column.setTypeIndex( count++ );
bindColumn( columnElement, column, isNullable );
+ final String columnName = columnElement.attributeValue( "name" );
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
- columnElement.attributeValue( "name" ), propertyPath
+ columnName, propertyPath
);
column.setName( mappings.getNamingStrategy().columnName(
- logicalColumnName ) );
+ columnName ) );
if ( table != null ) {
table.addColumn( column ); // table=null -> an association
// - fill it in later
@@ -1115,10 +1116,11 @@
Column column = new Column();
column.setValue( simpleValue );
bindColumn( node, column, isNullable );
+ final String columnName = columnAttribute.getValue();
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
- columnAttribute.getValue(), propertyPath
+ columnName, propertyPath
);
- column.setName( mappings.getNamingStrategy().columnName( logicalColumnName ) );
+ column.setName( mappings.getNamingStrategy().columnName( columnName ) );
if ( table != null ) {
table.addColumn( column ); // table=null -> an association - fill
// it in later
15 years, 3 months
Hibernate SVN: r17256 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-08-10 02:40:43 -0400 (Mon, 10 Aug 2009)
New Revision: 17256
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
Log:
JBPAPP-1547 HHH-3686 : Sybase - QueryCacheTest.testQueryCacheInvalidation fails
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java 2009-08-10 03:59:59 UTC (rev 17255)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java 2009-08-10 06:40:43 UTC (rev 17256)
@@ -64,7 +64,13 @@
public boolean supportsCascadeDelete() {
return false;
}
-
+ /**
+ * By default, Sybase string comparisons are case-insensitive.<br>
+ * If the DB is configured to be case-sensitive, then the return value will be incorrect.
+ */
+ public boolean areStringComparisonsCaseInsensitive() {
+ return true;
+ }
public boolean supportsExpectedLobUsagePattern() {
return false;
}
15 years, 3 months
Hibernate SVN: r17255 - in core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test: metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-08-09 23:59:59 -0400 (Sun, 09 Aug 2009)
New Revision: 17255
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
EJB-456 start core of tests
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java 2009-08-10 03:59:59 UTC (rev 17255)
@@ -0,0 +1,31 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class FoodItem {
+ private Long id;
+ private String name;
+
+ @Id @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java 2009-08-10 03:59:59 UTC (rev 17255)
@@ -0,0 +1,43 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Fridge {
+ private Long id;
+ private String brand;
+ private int temperature;
+ //dimensions
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getBrand() {
+ return brand;
+ }
+
+ public void setBrand(String brand) {
+ this.brand = brand;
+ }
+
+ public int getTemperature() {
+ return temperature;
+ }
+
+ public void setTemperature(int temperature) {
+ this.temperature = temperature;
+ }
+}
+
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-10 03:59:59 UTC (rev 17255)
@@ -0,0 +1,46 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.Bindable;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.hibernate.ejb.test.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class MetadataTest extends TestCase {
+
+ public void testBaseOfService() throws Exception {
+ EntityManagerFactory emf = factory;
+ assertNotNull( emf.getMetamodel() );
+ final EntityType<Fridge> entityType = emf.getMetamodel().entity( Fridge.class );
+ assertNotNull( entityType );
+ }
+
+ public void testBindable() throws Exception {
+ EntityManagerFactory emf = factory;
+ final EntityType<Fridge> entityType = emf.getMetamodel().entity( Fridge.class );
+ assertEquals( Fridge.class, entityType.getBindableJavaType() );
+ assertEquals( Bindable.BindableType.ENTITY_TYPE, entityType.getBindableType() );
+ final SingularAttribute<? super Fridge,Integer> singularAttribute = entityType.getDeclaredSingularAttribute(
+ "temperature",
+ Integer.class
+ );
+ assertEquals( Integer.class, singularAttribute.getBindableJavaType() );
+ assertEquals( Bindable.BindableType.SINGULAR_ATTRIBUTE, singularAttribute.getBindableType() );
+
+ //TODO test embedded
+ //todo test plural
+ }
+
+ @Override
+ public Class[] getAnnotatedClasses() {
+ return new Class[]{
+ Fridge.class,
+ FoodItem.class
+ };
+ }
+
+}
15 years, 3 months