Hibernate SVN: r16291 - in annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations: entitynonentity and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-04-09 19:07:59 -0400 (Thu, 09 Apr 2009)
New Revision: 16291
Modified:
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/entity/Ransom.java
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/entitynonentity/Interaction.java
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/indexcoll/Version.java
Log:
JBPAPP-1072 : Annotations - Oracle - "date"/"number" is reserved in Oracle
Modified: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/entity/Ransom.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/entity/Ransom.java 2009-04-09 22:14:29 UTC (rev 16290)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/entity/Ransom.java 2009-04-09 23:07:59 UTC (rev 16291)
@@ -50,7 +50,7 @@
public void setAmount(MonetaryAmount amount) {
this.amount = amount;
}
-
+ @Column(name="ransom_date")
public Date getDate() {
return date;
}
Modified: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/entitynonentity/Interaction.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/entitynonentity/Interaction.java 2009-04-09 22:14:29 UTC (rev 16290)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/entitynonentity/Interaction.java 2009-04-09 23:07:59 UTC (rev 16291)
@@ -2,11 +2,13 @@
package org.hibernate.test.annotations.entitynonentity;
import javax.persistence.MappedSuperclass;
+import javax.persistence.Column;
/**
* @author Emmanuel Bernard
*/
@MappedSuperclass
public class Interaction {
+ @Column(name="int_nbr")
public int number;
}
Modified: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/indexcoll/Version.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/indexcoll/Version.java 2009-04-09 22:14:29 UTC (rev 16290)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/indexcoll/Version.java 2009-04-09 23:07:59 UTC (rev 16291)
@@ -38,6 +38,7 @@
this.codeName = codeName;
}
+ @Column(name="version_nbr")
public String getNumber() {
return number;
}
15 years, 7 months
Hibernate SVN: r16290 - in annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations: tuplizer and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-04-09 18:14:29 -0400 (Thu, 09 Apr 2009)
New Revision: 16290
Modified:
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/tuplizer/TuplizerTest.java
Log:
JBPAPP-1878 ANN-817 - 8-bit characters in string values cause unit test failures
Modified: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java 2009-04-09 22:09:50 UTC (rev 16289)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java 2009-04-09 22:14:29 UTC (rev 16290)
@@ -20,7 +20,7 @@
Postman pm = new Postman( "Bob", "A01" );
House house = new House();
house.setPostman( pm );
- house.setAddress( "Rue des pr�s" );
+ house.setAddress( "Rue des pres" );
s.persist( pm );
s.persist( house );
tx.commit();
Modified: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/tuplizer/TuplizerTest.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/tuplizer/TuplizerTest.java 2009-04-09 22:09:50 UTC (rev 16289)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/tuplizer/TuplizerTest.java 2009-04-09 22:14:29 UTC (rev 16290)
@@ -10,7 +10,7 @@
public class TuplizerTest extends TestCase {
public void testEntityTuplizer() throws Exception {
Cuisine cuisine = ProxyHelper.newCuisineProxy( null );
- cuisine.setName( "Fran�aise" );
+ cuisine.setName( "Francaise" );
Country country = ProxyHelper.newCountryProxy( null );
country.setName( "France" );
cuisine.setCountry( country );
@@ -21,7 +21,7 @@
s.clear();
cuisine = (Cuisine) s.get(Cuisine.class, cuisine.getId() );
assertNotNull( cuisine );
- assertEquals( "Fran�aise", cuisine.getName() );
+ assertEquals( "Francaise", cuisine.getName() );
assertEquals( "France", country.getName() );
s.getTransaction().rollback();
s.close();
15 years, 7 months
Hibernate SVN: r16289 - in annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations: tuplizer and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-04-09 18:09:50 -0400 (Thu, 09 Apr 2009)
New Revision: 16289
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/tuplizer/TuplizerTest.java
Log:
JBPAPP-1878 ANN-817 : 8-bit characters in string values cause unit test failures
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java 2009-04-09 22:02:13 UTC (rev 16288)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java 2009-04-09 22:09:50 UTC (rev 16289)
@@ -20,7 +20,7 @@
Postman pm = new Postman( "Bob", "A01" );
House house = new House();
house.setPostman( pm );
- house.setAddress( "Rue des pr�s" );
+ house.setAddress( "Rue des pres" );
s.persist( pm );
s.persist( house );
tx.commit();
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/tuplizer/TuplizerTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/tuplizer/TuplizerTest.java 2009-04-09 22:02:13 UTC (rev 16288)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/tuplizer/TuplizerTest.java 2009-04-09 22:09:50 UTC (rev 16289)
@@ -10,7 +10,7 @@
public class TuplizerTest extends TestCase {
public void testEntityTuplizer() throws Exception {
Cuisine cuisine = ProxyHelper.newCuisineProxy( null );
- cuisine.setName( "Fran�aise" );
+ cuisine.setName( "Francaise" );
Country country = ProxyHelper.newCountryProxy( null );
country.setName( "France" );
cuisine.setCountry( country );
@@ -21,7 +21,7 @@
s.clear();
cuisine = (Cuisine) s.get(Cuisine.class, cuisine.getId() );
assertNotNull( cuisine );
- assertEquals( "Fran�aise", cuisine.getName() );
+ assertEquals( "Francaise", cuisine.getName() );
assertEquals( "France", country.getName() );
s.getTransaction().rollback();
s.close();
15 years, 7 months
Hibernate SVN: r16288 - in core/trunk/annotations/src/test/java/org/hibernate/test/annotations: tuplizer and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-04-09 18:02:13 -0400 (Thu, 09 Apr 2009)
New Revision: 16288
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/tuplizer/TuplizerTest.java
Log:
ANN-817 : 8-bit characters in string values cause unit test failures
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java 2009-04-09 16:07:22 UTC (rev 16287)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/referencedcolumnname/ReferencedColumnNameTest.java 2009-04-09 22:02:13 UTC (rev 16288)
@@ -20,7 +20,7 @@
Postman pm = new Postman( "Bob", "A01" );
House house = new House();
house.setPostman( pm );
- house.setAddress( "Rue des pr�s" );
+ house.setAddress( "Rue des pres" );
s.persist( pm );
s.persist( house );
tx.commit();
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/tuplizer/TuplizerTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/tuplizer/TuplizerTest.java 2009-04-09 16:07:22 UTC (rev 16287)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/tuplizer/TuplizerTest.java 2009-04-09 22:02:13 UTC (rev 16288)
@@ -10,7 +10,7 @@
public class TuplizerTest extends TestCase {
public void testEntityTuplizer() throws Exception {
Cuisine cuisine = ProxyHelper.newCuisineProxy( null );
- cuisine.setName( "Fran�aise" );
+ cuisine.setName( "Francaise" );
Country country = ProxyHelper.newCountryProxy( null );
country.setName( "France" );
cuisine.setCountry( country );
@@ -21,7 +21,7 @@
s.clear();
cuisine = (Cuisine) s.get(Cuisine.class, cuisine.getId() );
assertNotNull( cuisine );
- assertEquals( "Fran�aise", cuisine.getName() );
+ assertEquals( "Francaise", cuisine.getName() );
assertEquals( "France", country.getName() );
s.getTransaction().rollback();
s.close();
15 years, 7 months
Hibernate SVN: r16287 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validation/engine/xml and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-04-09 12:07:22 -0400 (Thu, 09 Apr 2009)
New Revision: 16287
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorDefinitionsCache.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml
Log:
HV-112
Added support for constraint validator configuration.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-04-09 12:23:07 UTC (rev 16286)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -279,13 +279,13 @@
return propertyDescriptor;
}
- private <A extends Annotation> void initClassConstraints(Class clazz, AnnotationIgnores annotationIgnores) {
+ private <A extends Annotation> void initClassConstraints(Class<?> clazz, AnnotationIgnores annotationIgnores) {
if ( annotationIgnores.isIgnoreAnnotations( clazz ) ) {
return;
}
List<ConstraintDescriptorImpl> classMetadata = findClassLevelConstraints( clazz );
for ( ConstraintDescriptorImpl constraintDescription : classMetadata ) {
- MetaConstraint<T, A> metaConstraint = new MetaConstraint<T, A>( clazz, constraintDescription );
+ MetaConstraint<T, A> metaConstraint = new MetaConstraint<T, A>( beanClass, constraintDescription );
metaConstraintList.add( metaConstraint );
}
}
@@ -304,7 +304,7 @@
List<Annotation> constraints = new ArrayList<Annotation>();
if ( constraintHelper.isConstraintAnnotation( annotation ) ||
- constraintHelper.isBuiltinConstraint( annotation ) ) {
+ constraintHelper.isBuiltinConstraint( annotation.annotationType() ) ) {
constraints.add( annotation );
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-04-09 12:23:07 UTC (rev 16286)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -265,9 +265,21 @@
xmlParameters.constraintValidatorFactory = clazz.newInstance();
log.info( "Using {} as constraint factory.", constraintFactoryClass );
}
- catch ( Exception e ) {
- throw new ValidationException( "Unable to instantiate message interpolator class " + constraintFactoryClass + "." );
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException(
+ "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
+ );
+ }
}
}
@@ -310,9 +322,21 @@
xmlParameters.messageInterpolator = clazz.newInstance();
log.info( "Using {} as message interpolator.", messageInterpolatorClass );
}
- catch ( Exception e ) {
- throw new ValidationException( "Unable to instantiate message interpolator class " + messageInterpolatorClass + "." );
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException(
+ "Unable to instantiate message interpolator class " + messageInterpolatorClass + ".", e
+ );
}
+ catch ( InstantiationException e ) {
+ throw new ValidationException(
+ "Unable to instantiate message interpolator class " + messageInterpolatorClass + ".", e
+ );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException(
+ "Unable to instantiate message interpolator class " + messageInterpolatorClass + ".", e
+ );
+ }
}
}
@@ -327,9 +351,21 @@
xmlParameters.traversableResolver = clazz.newInstance();
log.info( "Using {} as traversable resolver.", traversableResolverClass );
}
- catch ( Exception e ) {
- throw new ValidationException( "Unable to instantiate message interpolator class " + traversableResolverClass + "." );
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException(
+ "Unable to instantiate traversable resolver class " + traversableResolverClass + ".", e
+ );
}
+ catch ( InstantiationException e ) {
+ throw new ValidationException(
+ "Unable to instantiate traversable resolver class " + traversableResolverClass + ".", e
+ );
+ }
+ catch ( IllegalAccessException e ) {
+ throw new ValidationException(
+ "Unable to instantiate traversable resolver class " + traversableResolverClass + ".", e
+ );
+ }
}
}
@@ -398,7 +434,7 @@
return schema;
}
- private class ParameterHolder {
+ private static class ParameterHolder {
ConstraintValidatorFactory constraintValidatorFactory;
MessageInterpolator messageInterpolator;
TraversableResolver traversableResolver;
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-04-09 12:23:07 UTC (rev 16286)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -113,28 +113,43 @@
ReportAsSingleViolation.class
);
- findConstraintClasses();
+ findConstraintValidatorClasses();
Map<ClassIndexWrapper, Map<String, Object>> overrideParameters = parseOverrideParameters();
parseComposingConstraints( overrideParameters );
}
- private void findConstraintClasses() {
- if ( constraintHelper.isBuiltinConstraint( annotation ) ) {
- constraintValidatorDefinitonClasses.addAll( constraintHelper.getBuiltInConstraints( annotation ) );
+ private void findConstraintValidatorClasses() {
+ if ( ConstraintValidatorDefinitionsCache.containsConstraintValidatorDefinition( annotation.annotationType())) {
+ for ( Class<? extends ConstraintValidator<? extends Annotation, ?>> validator : ConstraintValidatorDefinitionsCache
+ .getConstraintValidatorDefinition(
+ annotation.annotationType()
+ ) ) {
+ constraintValidatorDefinitonClasses.add( ( Class<? extends ConstraintValidator<T, ?>> ) validator );
+ }
+ return;
}
+
+ List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> constraintDefinitonClasses = new ArrayList<Class<? extends ConstraintValidator<? extends Annotation, ?>>>();
+ if ( constraintHelper.isBuiltinConstraint( annotation.annotationType() ) ) {
+ constraintDefinitonClasses.addAll( constraintHelper.getBuiltInConstraints( annotation.annotationType() ) );
+ }
else {
final Class<? extends Annotation> annotationType = annotation.annotationType();
Class<? extends ConstraintValidator<?, ?>>[] validatedBy = annotationType
.getAnnotation( Constraint.class )
.validatedBy();
- for ( Class<? extends ConstraintValidator<?, ?>> validator : validatedBy ) {
- //FIXME does this create a CCE at runtime?
- //FIXME if yes wrap into VE, if no we need to test the type here
- //Once resolved,we can @SuppressWarning("unchecked") on the cast
- Class<? extends ConstraintValidator<T, ?>> safeValidator = ( Class<? extends ConstraintValidator<T, ?>> ) validator;
- constraintValidatorDefinitonClasses.add( safeValidator );
- }
+ constraintDefinitonClasses.addAll( Arrays.asList( validatedBy ) );
}
+
+ ConstraintValidatorDefinitionsCache.addConstraintValidatorDefinition(
+ annotation.annotationType(), constraintDefinitonClasses
+ );
+
+ for ( Class<? extends ConstraintValidator<? extends Annotation, ?>> validator : constraintDefinitonClasses ) {
+ @SuppressWarnings("unchecked")
+ Class<? extends ConstraintValidator<T, ?>> safeValidator = ( Class<? extends ConstraintValidator<T, ?>> ) validator;
+ constraintValidatorDefinitonClasses.add( safeValidator );
+ }
}
public T getAnnotation() {
@@ -239,7 +254,7 @@
private void parseComposingConstraints(Map<ClassIndexWrapper, Map<String, Object>> overrideParameters) {
for ( Annotation declaredAnnotation : annotation.annotationType().getDeclaredAnnotations() ) {
if ( constraintHelper.isConstraintAnnotation( declaredAnnotation )
- || constraintHelper.isBuiltinConstraint( declaredAnnotation ) ) {
+ || constraintHelper.isBuiltinConstraint( declaredAnnotation.annotationType() ) ) {
ConstraintDescriptorImpl<?> descriptor = createComposingConstraintDescriptor(
declaredAnnotation, overrideParameters, OVERRIDES_PARAMETER_DEFAULT_INDEX
);
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java 2009-04-09 12:23:07 UTC (rev 16286)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -132,30 +132,32 @@
builtinConstraints.put( Pattern.class, constraintList );
}
- public <T extends Annotation> List<Class<? extends ConstraintValidator<T, ?>>> getBuiltInConstraints(T annotation) {
- final List<Class<? extends ConstraintValidator<?, ?>>> builtInList = getBuiltInFromAnnotationType( annotation.annotationType() );
+ public List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> getBuiltInConstraints(Class<? extends Annotation> annotationType) {
+ final List<Class<? extends ConstraintValidator<?, ?>>> builtInList = getBuiltInFromAnnotationType(
+ annotationType
+ );
- if (builtInList == null || builtInList.size() == 0) {
- throw new ValidationException( "Unable to find constraints for " + annotation.annotationType() );
+ if ( builtInList == null || builtInList.size() == 0 ) {
+ throw new ValidationException( "Unable to find constraints for " + annotationType );
}
- List<Class<? extends ConstraintValidator<T, ?>>> constraints =
- new ArrayList<Class<? extends ConstraintValidator<T, ?>>>( builtInList.size() );
- for (Class<? extends ConstraintValidator<?, ?>> validatorClass : builtInList) {
+ List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> constraints =
+ new ArrayList<Class<? extends ConstraintValidator<? extends Annotation, ?>>>( builtInList.size() );
+ for ( Class<? extends ConstraintValidator<?, ?>> validatorClass : builtInList ) {
//safe cause all CV for a given annotation A are CV<A, ?>
- @SuppressWarnings( "unchecked" )
- Class<ConstraintValidator<T, ?>> safeValdiatorClass = (Class<ConstraintValidator<T, ?>>) validatorClass;
+ @SuppressWarnings("unchecked")
+ Class<ConstraintValidator<? extends Annotation, ?>> safeValdiatorClass = ( Class<ConstraintValidator<? extends Annotation, ?>> ) validatorClass;
constraints.add( safeValdiatorClass );
}
return constraints;
}
- private List<Class<? extends ConstraintValidator<?, ?>>> getBuiltInFromAnnotationType(Class<?> annotationType) {
+ private List<Class<? extends ConstraintValidator<? , ?>>> getBuiltInFromAnnotationType(Class<? extends Annotation> annotationType) {
return builtinConstraints.get( annotationType );
}
- public boolean isBuiltinConstraint(Annotation annotation) {
- return builtinConstraints.containsKey( annotation.annotationType() );
+ public boolean isBuiltinConstraint(Class<? extends Annotation> annotationType) {
+ return builtinConstraints.containsKey( annotationType );
}
/**
@@ -174,7 +176,7 @@
if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
Annotation[] annotations = ( Annotation[] ) m.invoke( annotation );
for ( Annotation a : annotations ) {
- if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a ) ) {
+ if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a.annotationType() ) ) {
isMultiValueConstraint = true;
}
else {
@@ -213,7 +215,7 @@
if ( returnType.isArray() && returnType.getComponentType().isAnnotation() ) {
Annotation[] annotations = ( Annotation[] ) m.invoke( annotation );
for ( Annotation a : annotations ) {
- if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a ) ) {
+ if ( isConstraintAnnotation( a ) || isBuiltinConstraint( a.annotationType() ) ) {
annotationList.add( a );
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java 2009-04-09 12:23:07 UTC (rev 16286)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorDefinitionsCache.java (from rev 16270, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataCache.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorDefinitionsCache.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorDefinitionsCache.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -0,0 +1,48 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.engine;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.validation.ConstraintValidator;
+
+/**
+ * Caches the constraint classes for a given annotation.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ConstraintValidatorDefinitionsCache {
+ private static final Map<Class<? extends Annotation>, List<Class<? extends ConstraintValidator<? extends Annotation, ?>>>> constraintValidatorDefinitons = new HashMap<Class<? extends Annotation>, List<Class<? extends ConstraintValidator<? extends Annotation, ?>>>>();
+
+ public static List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> getConstraintValidatorDefinition(Class<? extends Annotation> annotationClass) {
+ if ( annotationClass == null ) {
+ throw new IllegalArgumentException( "Class cannot be null" );
+ }
+ return constraintValidatorDefinitons.get( annotationClass );
+ }
+
+ public static <A extends Annotation> void addConstraintValidatorDefinition(Class<A> annotationClass, List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> definitionClasses) {
+ constraintValidatorDefinitons.put( annotationClass, definitionClasses );
+ }
+
+ public static boolean containsConstraintValidatorDefinition(Class<? extends Annotation> annotationClass) {
+ return constraintValidatorDefinitons.containsKey( annotationClass );
+ }
+}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java 2009-04-09 12:23:07 UTC (rev 16286)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -57,8 +57,8 @@
while ( providerDefinitions.hasMoreElements() ) {
URL url = providerDefinitions.nextElement();
InputStream stream = url.openStream();
+ BufferedReader reader = new BufferedReader( new InputStreamReader( stream ), 100 );
try {
- BufferedReader reader = new BufferedReader( new InputStreamReader( stream ), 100 );
name = reader.readLine();
while ( name != null ) {
name = name.trim();
@@ -76,7 +76,7 @@
}
}
finally {
- stream.close();
+ reader.close();
}
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java 2009-04-09 12:23:07 UTC (rev 16286)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -32,6 +32,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
@@ -58,6 +60,7 @@
import org.hibernate.validation.xml.AnnotationType;
import org.hibernate.validation.xml.BeanType;
import org.hibernate.validation.xml.ClassType;
+import org.hibernate.validation.xml.ConstraintDefinitionType;
import org.hibernate.validation.xml.ConstraintMappingsType;
import org.hibernate.validation.xml.ConstraintType;
import org.hibernate.validation.xml.ElementType;
@@ -65,6 +68,7 @@
import org.hibernate.validation.xml.GetterType;
import org.hibernate.validation.xml.GroupSequenceType;
import org.hibernate.validation.xml.GroupsType;
+import org.hibernate.validation.xml.ValidatedByType;
/**
* @author Emmanuel Bernard
@@ -76,12 +80,12 @@
private static final String VALIDATION_MAPPING_XSD = "META-INF/validation-mapping-1.0.xsd";
private static final String MESSAGE_PARAM = "message";
private static final String GROUPS_PARAM = "groups";
+ private static final String PACKAGE_SEPERATOR = ".";
private final MessageInterpolator messageInterpolator;
private final TraversableResolver traversableResolver;
private final ConstraintValidatorFactory constraintValidatorFactory;
private final ConstraintHelper constraintHelper = new ConstraintHelper();
- private static final String PACKAGE_SEPERATOR = ".";
private final Set<Class<?>> processedClasses = new HashSet<Class<?>>();
@@ -143,9 +147,10 @@
private void parseMappingFiles(Set<InputStream> mappingStreams) {
for ( InputStream in : mappingStreams ) {
try {
- ConstraintMappingsType mappings = getValidationConfig( in );
- String defaultPackage = mappings.getDefaultPackage();
- for ( BeanType bean : mappings.getBean() ) {
+ ConstraintMappingsType mapping = getValidationConfig( in );
+ parseConstraintDefinitions( mapping.getConstraintDefinition() );
+ String defaultPackage = mapping.getDefaultPackage();
+ for ( BeanType bean : mapping.getBean() ) {
Class<?> beanClass = getClass( bean.getClazz(), defaultPackage );
checkClassHasNotBeenProcessed( processedClasses, beanClass );
annotationIgnores.setDefaultIgnoreAnnotation( beanClass, bean.isIgnoreAnnotations() );
@@ -166,6 +171,44 @@
}
}
+ private void parseConstraintDefinitions(List<ConstraintDefinitionType> constraintDefinitionList) {
+ for ( ConstraintDefinitionType constraintDefinition : constraintDefinitionList ) {
+ String annotationClassName = constraintDefinition.getAnnotation();
+ Class<? extends Annotation> annotationClass;
+ try {
+ annotationClass = ( Class<? extends Annotation> ) ReflectionHelper.classForName(
+ annotationClassName, this.getClass()
+ );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException( "Unable to load class " + annotationClassName );
+ }
+
+ ValidatedByType validatedByType = constraintDefinition.getValidatedBy();
+ List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> constraintValidatorClasses = new ArrayList<Class<? extends ConstraintValidator<? extends Annotation, ?>>>();
+ if ( validatedByType.isIncludeExistingValidators() != null && validatedByType.isIncludeExistingValidators() ) {
+ constraintValidatorClasses.addAll( findConstraintValidatorClasses( annotationClass ) );
+ }
+ for ( String validatorClassName : validatedByType.getValue() ) {
+ Class<? extends ConstraintValidator<?, ?>> validatorClass;
+ try {
+ // TODO validate this class!
+ validatorClass = ( Class<? extends ConstraintValidator<?, ?>> ) ReflectionHelper.classForName(
+ validatorClassName,
+ this.getClass()
+ );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new ValidationException( "Unable to load class " + validatorClassName );
+ }
+ constraintValidatorClasses.add( validatorClass );
+ }
+ ConstraintValidatorDefinitionsCache.addConstraintValidatorDefinition(
+ annotationClass, constraintValidatorClasses
+ );
+ }
+ }
+
private void checkClassHasNotBeenProcessed(Set<Class<?>> processedClasses, Class<?> beanClass) {
if ( processedClasses.contains( beanClass ) ) {
throw new ValidationException( beanClass.getName() + " has already be configured in xml." );
@@ -557,4 +600,24 @@
BeanMetaDataCache.addBeanMetaData( beanClass, metaData );
}
}
+
+ private List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> findConstraintValidatorClasses(Class<? extends Annotation> annotationType) {
+ List<Class<? extends ConstraintValidator<? extends Annotation, ?>>> constraintValidatorDefinitonClasses = new ArrayList<Class<? extends ConstraintValidator<? extends Annotation, ?>>>();
+ if ( constraintHelper.isBuiltinConstraint( annotationType ) ) {
+ constraintValidatorDefinitonClasses.addAll( constraintHelper.getBuiltInConstraints( annotationType ) );
+ }
+ else {
+ Class<? extends ConstraintValidator<?, ?>>[] validatedBy = annotationType
+ .getAnnotation( Constraint.class )
+ .validatedBy();
+ for ( Class<? extends ConstraintValidator<?, ?>> validator : validatedBy ) {
+ //FIXME does this create a CCE at runtime?
+ //FIXME if yes wrap into VE, if no we need to test the type here
+ //Once resolved,we can @SuppressWarning("unchecked") on the cast
+ Class<? extends ConstraintValidator<? extends Annotation, ?>> safeValidator = validator;
+ constraintValidatorDefinitonClasses.add( safeValidator );
+ }
+ }
+ return constraintValidatorDefinitonClasses;
+ }
}
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java 2009-04-09 16:07:22 UTC (rev 16287)
@@ -0,0 +1,36 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.engine.xml;
+
+import javax.validation.ConstraintValidatorContext;
+
+import org.slf4j.Logger;
+
+import org.hibernate.validation.util.LoggerFactory;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CustomConsistentUserValidator extends ConsistentUserValidator {
+ private static final Logger log = LoggerFactory.make();
+
+ public boolean isValid(User user, ConstraintValidatorContext constraintValidatorContext) {
+ log.debug( "is valid in CustomConsistentUserValidator is called." );
+ return super.isValid( user, constraintValidatorContext );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/CustomConsistentUserValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml
===================================================================
--- validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml 2009-04-09 12:23:07 UTC (rev 16286)
+++ validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml 2009-04-09 16:07:22 UTC (rev 16287)
@@ -52,4 +52,9 @@
</constraint>
</getter>
</bean>
+ <constraint-definition annotation="org.hibernate.validation.engine.xml.ConsistentUserInformation">
+ <validated-by include-existing-validators="false">
+ <value>org.hibernate.validation.engine.xml.CustomConsistentUserValidator</value>
+ </validated-by>
+ </constraint-definition>
</constraint-mappings>
15 years, 7 months
Hibernate SVN: r16286 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validation/engine/xml and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-04-09 08:23:07 -0400 (Thu, 09 Apr 2009)
New Revision: 16286
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/UserType.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/ConsistentUserInformation.java
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml
Log:
HV-112
Enum and Annotation types in constraint definitions.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java 2009-04-09 11:45:43 UTC (rev 16285)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorFactoryImpl.java 2009-04-09 12:23:07 UTC (rev 16286)
@@ -55,6 +55,7 @@
import org.hibernate.validation.util.ReflectionHelper;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+import org.hibernate.validation.xml.AnnotationType;
import org.hibernate.validation.xml.BeanType;
import org.hibernate.validation.xml.ClassType;
import org.hibernate.validation.xml.ConstraintMappingsType;
@@ -241,7 +242,7 @@
}
// group sequence
- List<Class<?>> groupSequence = createGroupSequence( classType.getGroupSequence(), beanClass, defaultPackage );
+ List<Class<?>> groupSequence = createGroupSequence( classType.getGroupSequence(), defaultPackage );
if ( !groupSequence.isEmpty() ) {
defaultSequences.put( beanClass, groupSequence );
}
@@ -253,7 +254,7 @@
}
}
- private List<Class<?>> createGroupSequence(GroupSequenceType groupSequenceType, Class<?> beanClass, String defaultPackage) {
+ private List<Class<?>> createGroupSequence(GroupSequenceType groupSequenceType, String defaultPackage) {
List<Class<?>> groupSequence = new ArrayList<Class<?>>();
for ( String groupName : groupSequenceType.getValue() ) {
Class<?> group = getClass( groupName, defaultPackage );
@@ -364,25 +365,52 @@
}
private Object getSingleValue(Serializable serializable, Class<?> returnType) {
- String value;
+
+ Object returnValue;
if ( serializable instanceof String ) {
- value = ( String ) serializable;
+ String value = ( String ) serializable;
+ returnValue = convertStringToReturnType( returnType, value );
}
- else if ( serializable instanceof JAXBElement ) {
+ else if ( serializable instanceof JAXBElement && ( ( JAXBElement ) serializable ).getDeclaredType()
+ .equals( String.class ) ) {
JAXBElement<?> elem = ( JAXBElement<?> ) serializable;
- // this is safe due to the underlying schema
- value = ( String ) elem.getValue();
+ String value = ( String ) elem.getValue();
+ returnValue = convertStringToReturnType( returnType, value );
}
+ else if ( serializable instanceof JAXBElement && ( ( JAXBElement ) serializable ).getDeclaredType()
+ .equals( AnnotationType.class ) ) {
+ JAXBElement<?> elem = ( JAXBElement<?> ) serializable;
+ AnnotationType annotationType = ( AnnotationType ) elem.getValue();
+ try {
+ @SuppressWarnings("unchecked")
+ Class<Annotation> annotationClass = ( Class<Annotation> ) returnType;
+ returnValue = createAnnotation( annotationType, annotationClass );
+ }
+ catch ( ClassCastException e ) {
+ throw new ValidationException( "Unexpected paramter value" );
+ }
+ }
else {
throw new ValidationException( "Unexpected paramter value" );
}
+ return returnValue;
- return convertStringToReturnType( returnType, value );
}
+ private <A extends Annotation> Annotation createAnnotation(AnnotationType annotationType, Class<A> returnType) {
+ AnnotationDescriptor<A> annotationDescriptor = new AnnotationDescriptor<A>( returnType );
+ for ( ElementType elementType : annotationType.getElement() ) {
+ String name = elementType.getName();
+ Class<?> paramterType = getAnnotationParamterType( returnType, name );
+ Object elementValue = getElementValue( elementType, paramterType );
+ annotationDescriptor.setValue( name, elementValue );
+ }
+ return AnnotationFactory.create( annotationDescriptor );
+ }
+
private Object convertStringToReturnType(Class<?> returnType, String value) {
Object returnValue;
- if ( returnType.isPrimitive() && returnType.getName().equals( byte.class.getName() ) ) {
+ if ( returnType.getName().equals( byte.class.getName() ) ) {
try {
returnValue = Byte.parseByte( value );
}
@@ -390,7 +418,7 @@
throw new ValidationException( "Invalid byte format", e );
}
}
- else if ( returnType.isPrimitive() && returnType.getName().equals( short.class.getName() ) ) {
+ else if ( returnType.getName().equals( short.class.getName() ) ) {
try {
returnValue = Short.parseShort( value );
}
@@ -398,7 +426,7 @@
throw new ValidationException( "Invalid short format", e );
}
}
- else if ( returnType.isPrimitive() && returnType.getName().equals( int.class.getName() ) ) {
+ else if ( returnType.getName().equals( int.class.getName() ) ) {
try {
returnValue = Integer.parseInt( value );
}
@@ -406,7 +434,7 @@
throw new ValidationException( "Invalid int format", e );
}
}
- else if ( returnType.isPrimitive() && returnType.getName().equals( long.class.getName() ) ) {
+ else if ( returnType.getName().equals( long.class.getName() ) ) {
try {
returnValue = Long.parseLong( value );
}
@@ -414,7 +442,7 @@
throw new ValidationException( "Invalid long format", e );
}
}
- else if ( returnType.isPrimitive() && returnType.getName().equals( float.class.getName() ) ) {
+ else if ( returnType.getName().equals( float.class.getName() ) ) {
try {
returnValue = Float.parseFloat( value );
}
@@ -422,7 +450,7 @@
throw new ValidationException( "Invalid float format", e );
}
}
- else if ( returnType.isPrimitive() && returnType.getName().equals( double.class.getName() ) ) {
+ else if ( returnType.getName().equals( double.class.getName() ) ) {
try {
returnValue = Double.parseDouble( value );
}
@@ -430,10 +458,10 @@
throw new ValidationException( "Invalid double format", e );
}
}
- else if ( returnType.isPrimitive() && returnType.getName().equals( boolean.class.getName() ) ) {
+ else if ( returnType.getName().equals( boolean.class.getName() ) ) {
returnValue = Boolean.parseBoolean( value );
}
- else if ( returnType.isPrimitive() && returnType.getName().equals( char.class.getName() ) ) {
+ else if ( returnType.getName().equals( char.class.getName() ) ) {
if ( value.length() != 1 ) {
throw new ValidationException( "Invalid char value: " + value );
}
@@ -451,7 +479,14 @@
}
}
else {
- throw new ValidationException( "Invalid return type: " + returnType );
+ try {
+ @SuppressWarnings("unchecked")
+ Class<Enum> enumClass = ( Class<Enum> ) returnType;
+ returnValue = Enum.valueOf( enumClass, value );
+ }
+ catch ( ClassCastException e ) {
+ throw new ValidationException( "Invalid return type: " + returnType + ". Should be a enumeration type." );
+ }
}
return returnValue;
}
@@ -508,7 +543,6 @@
}
private void initBeanMetaData() {
-
for ( Class<?> beanClass : processedClasses ) {
BeanMetaDataImpl<?> metaData = new BeanMetaDataImpl( beanClass, constraintHelper, annotationIgnores );
for ( MetaConstraint<?, ?> constraint : constraintMap.get( beanClass ) ) {
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/ConsistentUserInformation.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/ConsistentUserInformation.java 2009-04-09 11:45:43 UTC (rev 16285)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/ConsistentUserInformation.java 2009-04-09 12:23:07 UTC (rev 16286)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.constraints.Pattern;
/**
@@ -44,4 +45,8 @@
public abstract String[] stringArrayParam() default { };
public abstract int intParam() default 0;
+
+ public abstract Pattern[] patterns();
+
+ public abstract UserType userType() default UserType.BUYER;
}
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/UserType.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/UserType.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/UserType.java 2009-04-09 12:23:07 UTC (rev 16286)
@@ -0,0 +1,26 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.engine.xml;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public enum UserType {
+ BUYER,
+ SELLER
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/xml/UserType.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml
===================================================================
--- validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml 2009-04-09 11:45:43 UTC (rev 16285)
+++ validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml 2009-04-09 12:23:07 UTC (rev 16286)
@@ -21,23 +21,21 @@
<element name="intParam">
<value>42</value>
</element>
+ <element name="patterns">
+ <annotation>
+ <element name="regexp">myRegExp1</element>
+ </annotation>
+ <annotation>
+ <element name="regexp">myRegExp2</element>
+ </annotation>
+ </element>
+ <element name="userType">SELLER</element>
</constraint>
</class>
<field name="lastname">
<constraint annotation="javax.validation.constraints.Pattern">
<message>Last name has to start with with a capital letter.</message>
<element name="regexp">^[A-Z][a-z]+</element>
- <!--element name="patterns">
- <annotation>
- <element name="value">myRegExp</element>
- <element name="flag">
- <value>INSENSITIVE</value>
- </element>
- </annotation>
- <annotation>
- <element name="value">my2ndRegExp</element>
- </annotation>
- </element-->
</constraint>
</field>
<field name="creditcard">
15 years, 7 months
Hibernate SVN: r16285 - in search/trunk/src/main/java/org/hibernate/search: bridge and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-04-09 07:45:43 -0400 (Thu, 09 Apr 2009)
New Revision: 16285
Modified:
search/trunk/src/main/java/org/hibernate/search/annotations/ClassBridge.java
search/trunk/src/main/java/org/hibernate/search/bridge/BridgeFactory.java
search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
Log:
HSEARCH-352 fix programmatic mapping failure due to global analyzerDef
HSEARCH-358 @ClassBridge.impl is no longer defaulted
Modified: search/trunk/src/main/java/org/hibernate/search/annotations/ClassBridge.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/annotations/ClassBridge.java 2009-04-08 23:19:54 UTC (rev 16284)
+++ search/trunk/src/main/java/org/hibernate/search/annotations/ClassBridge.java 2009-04-09 11:45:43 UTC (rev 16285)
@@ -57,7 +57,7 @@
* User supplied class to manipulate document in
* whatever mysterious ways they wish to.
*/
- public Class impl() default void.class;
+ public Class<?> impl();
/**
* Array of fields to work with. The impl class
Modified: search/trunk/src/main/java/org/hibernate/search/bridge/BridgeFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/bridge/BridgeFactory.java 2009-04-08 23:19:54 UTC (rev 16284)
+++ search/trunk/src/main/java/org/hibernate/search/bridge/BridgeFactory.java 2009-04-09 11:45:43 UTC (rev 16285)
@@ -113,7 +113,7 @@
FieldBridge bridge = null;
if ( cb != null ) {
- Class impl = cb.impl();
+ Class<?> impl = cb.impl();
//TODO better error information ( see guessType() )
if (impl != null) {
try {
@@ -141,7 +141,7 @@
}
}
catch (Exception e) {
- throw new HibernateException( "Unable to instantiate FieldBridge for " + ClassBridge.class.getName(), e );
+ throw new HibernateException( "Unable to instantiate ClassBridge for " + impl.getName(), e );
}
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-04-08 23:19:54 UTC (rev 16284)
+++ search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-04-09 11:45:43 UTC (rev 16285)
@@ -458,6 +458,7 @@
private void initProgrammaticAnalyzers(InitContext context, ReflectionManager reflectionManager) {
final Map defaults = reflectionManager.getDefaults();
+
if (defaults != null) {
AnalyzerDef[] defs = (AnalyzerDef[]) defaults.get( AnalyzerDefs.class );
if ( defs != null ) {
15 years, 7 months
Hibernate SVN: r16284 - in search/trunk/src: main/java/org/hibernate/search/impl and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-04-08 19:19:54 -0400 (Wed, 08 Apr 2009)
New Revision: 16284
Modified:
search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
Log:
HSEARCH-352 add boost for class level on programmatic mapping
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-04-08 23:11:28 UTC (rev 16283)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-04-08 23:19:54 UTC (rev 16284)
@@ -12,6 +12,7 @@
private Map<String, Object> indexed;
private Map<PropertyKey, PropertyDescriptor> properties = new HashMap<PropertyKey, PropertyDescriptor>();
private Map<String, Object> similarity;
+ private Map<String, Object> boost;
public Map<String, Object> getIndexed() {
return indexed;
@@ -47,6 +48,14 @@
return similarity;
}
+ public void setBoost(Map<String, Object> boost) {
+ this.boost = boost;
+ }
+
+ public Map<String, Object> getBoost() {
+ return boost;
+ }
+
private static class PropertyKey {
private String name;
private ElementType type;
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-04-08 23:11:28 UTC (rev 16283)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-04-08 23:19:54 UTC (rev 16284)
@@ -30,6 +30,13 @@
return this;
}
+ public EntityMapping boost(float boost) {
+ final Map<String, Object> boostAnn = new HashMap<String, Object>();
+ boostAnn.put( "value", boost );
+ entity.setBoost(boostAnn);
+ return this;
+ }
+
public PropertyMapping property(String name, ElementType type) {
return new PropertyMapping(name, type, entity, mapping);
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-04-08 23:11:28 UTC (rev 16283)
+++ search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-04-08 23:19:54 UTC (rev 16284)
@@ -305,7 +305,6 @@
annotations.put( Fields.class, AnnotationFactory.create( fieldsAnnotation ) );
}
- //TODO add something around Similarity
private void createIndexed(EntityDescriptor entity) {
Class<? extends Annotation> annotationType = Indexed.class;
AnnotationDescriptor annotation = new AnnotationDescriptor( annotationType );
@@ -319,8 +318,16 @@
for ( Map.Entry<String, Object> entry : entity.getSimilarity().entrySet() ) {
annotation.setValue( entry.getKey(), entry.getValue() );
}
- annotations.put( annotationType, AnnotationFactory.create( annotation ) );
+ annotations.put( Similarity.class, AnnotationFactory.create( annotation ) );
}
+
+ if ( entity.getBoost() != null ) {
+ annotation = new AnnotationDescriptor( Boost.class );
+ for ( Map.Entry<String, Object> entry : entity.getBoost().entrySet() ) {
+ annotation.setValue( entry.getKey(), entry.getValue() );
+ }
+ annotations.put( Boost.class, AnnotationFactory.create( annotation ) );
+ }
}
private void populateAnnotationArray() {
Modified: search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-04-08 23:11:28 UTC (rev 16283)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-04-08 23:19:54 UTC (rev 16284)
@@ -10,6 +10,7 @@
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.search.DefaultSimilarity;
import org.hibernate.search.cfg.SearchMapping;
import org.hibernate.search.cfg.ConcatStringBridge;
@@ -165,6 +166,8 @@
.param( "maxGramSize", "3" )
.indexedClass( Address.class )
+ .similarity( DefaultSimilarity.class )
+ .boost( 2 )
.property( "addressId", ElementType.FIELD ).documentId().name( "id" )
.property( "street1", ElementType.FIELD )
.field()
15 years, 7 months
Hibernate SVN: r16283 - in search/trunk/src: main/java/org/hibernate/search/cfg and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-04-08 19:11:28 -0400 (Wed, 08 Apr 2009)
New Revision: 16283
Added:
search/trunk/src/main/java/org/hibernate/search/cfg/DocumentIdMapping.java
Modified:
search/trunk/src/main/java/org/hibernate/search/annotations/Similarity.java
search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java
search/trunk/src/main/java/org/hibernate/search/cfg/PropertyMapping.java
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/Address.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
Log:
HSEARCH-352 similarity and documentId support for programmatic mapping
Modified: search/trunk/src/main/java/org/hibernate/search/annotations/Similarity.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/annotations/Similarity.java 2009-04-08 16:58:37 UTC (rev 16282)
+++ search/trunk/src/main/java/org/hibernate/search/annotations/Similarity.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -11,10 +11,10 @@
@Target( ElementType.TYPE )
@Documented
/**
- * Specifies a similarity implementation to use.
+ * Specifies a similarity implementation to use for a given class
*
* @author Nick Vincent
*/
public @interface Similarity {
- public Class impl();
+ public Class<?> impl();
}
Copied: search/trunk/src/main/java/org/hibernate/search/cfg/DocumentIdMapping.java (from rev 16269, search/trunk/src/main/java/org/hibernate/search/cfg/FieldMapping.java)
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/DocumentIdMapping.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/DocumentIdMapping.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -0,0 +1,54 @@
+package org.hibernate.search.cfg;
+
+import java.lang.annotation.ElementType;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.solr.analysis.TokenizerFactory;
+
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Store;
+import org.hibernate.search.annotations.TermVector;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class DocumentIdMapping {
+ private final SearchMapping mapping;
+ private final EntityDescriptor entity;
+ private final PropertyDescriptor property;
+ private final Map<String, Object> documentId = new HashMap<String, Object>();
+
+ public DocumentIdMapping(PropertyDescriptor property, EntityDescriptor entity, SearchMapping mapping) {
+ this.mapping = mapping;
+ this.entity = entity;
+ this.property = property;
+ property.setDocumentId( documentId );
+ }
+
+ public DocumentIdMapping name(String fieldName) {
+ documentId.put( "name", fieldName );
+ return this;
+ }
+
+ public FieldMapping field() {
+ return new FieldMapping(property, entity, mapping);
+ }
+
+ public PropertyMapping property(String name, ElementType type) {
+ return new PropertyMapping(name, type, entity, mapping);
+ }
+
+ public AnalyzerDefMapping analyzerDef(String name, Class<? extends TokenizerFactory> tokenizerFactory) {
+ return new AnalyzerDefMapping(name, tokenizerFactory, mapping);
+ }
+
+ public EntityMapping indexedClass(Class<?> entityType) {
+ return new EntityMapping(entityType, null, mapping);
+ }
+
+ public EntityMapping indexedClass(Class<?> entityType, String indexName) {
+ return new EntityMapping(entityType, indexName, mapping);
+ }
+
+}
\ No newline at end of file
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-04-08 16:58:37 UTC (rev 16282)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -11,6 +11,7 @@
private Class<?> entityType;
private Map<String, Object> indexed;
private Map<PropertyKey, PropertyDescriptor> properties = new HashMap<PropertyKey, PropertyDescriptor>();
+ private Map<String, Object> similarity;
public Map<String, Object> getIndexed() {
return indexed;
@@ -38,7 +39,14 @@
return properties.get( new PropertyKey( name, type ) );
}
+ public void setSimilariy(Map<String, Object> similarity) {
+ this.similarity = similarity;
+ }
+ public Map<String, Object> getSimilarity() {
+ return similarity;
+ }
+
private static class PropertyKey {
private String name;
private ElementType type;
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-04-08 16:58:37 UTC (rev 16282)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -23,6 +23,13 @@
entity.setIndexed(indexed);
}
+ public EntityMapping similarity(Class<?> impl) {
+ Map<String, Object> similarity = new HashMap<String, Object>(1);
+ similarity.put( "impl", impl );
+ entity.setSimilariy(similarity);
+ return this;
+ }
+
public PropertyMapping property(String name, ElementType type) {
return new PropertyMapping(name, type, entity, mapping);
}
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java 2009-04-08 16:58:37 UTC (rev 16282)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -14,11 +14,16 @@
private ElementType type;
private String name;
private Collection<Map<String, Object>> fields = new ArrayList<Map<String, Object>>();
+ private Map<String, Object> documentId;
public PropertyDescriptor(String name, ElementType type) {
this.name = name;
this.type = type;
}
+
+ public void setDocumentId(Map<String, Object> documentId) {
+ this.documentId = documentId;
+ }
public void addField(Map<String, Object> field) {
fields.add( field );
@@ -27,4 +32,8 @@
public Collection<Map<String, Object>> getFields() {
return fields;
}
+
+ public Map<String, Object> getDocumentId() {
+ return documentId;
+ }
}
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/PropertyMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/PropertyMapping.java 2009-04-08 16:58:37 UTC (rev 16282)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/PropertyMapping.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -18,6 +18,10 @@
property = entity.getProperty(name, type);
}
+ public DocumentIdMapping documentId() {
+ return new DocumentIdMapping( property, entity, mapping );
+ }
+
public FieldMapping field() {
return new FieldMapping(property, entity, mapping);
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-04-08 16:58:37 UTC (rev 16282)
+++ search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -32,6 +32,8 @@
import org.hibernate.search.annotations.AnalyzerDefs;
import org.hibernate.search.annotations.Boost;
import org.hibernate.search.annotations.FieldBridge;
+import org.hibernate.search.annotations.Similarity;
+import org.hibernate.search.annotations.DocumentId;
/**
* @author Emmanuel Bernard
@@ -224,6 +226,7 @@
final PropertyDescriptor property = entity.getPropertyDescriptor( propertyName, elementType );
if (property != null) {
// property name overriding
+ createDocumentId( property );
createFields( property );
}
}
@@ -237,6 +240,17 @@
}
}
+ private void createDocumentId(PropertyDescriptor property) {
+ Map<String, Object> documentId = property.getDocumentId();
+ if (documentId != null) {
+ AnnotationDescriptor documentIdAnnotation = new AnnotationDescriptor( DocumentId.class );
+ for ( Map.Entry<String, Object> entry : documentId.entrySet() ) {
+ documentIdAnnotation.setValue( entry.getKey(), entry.getValue() );
+ }
+ annotations.put( DocumentId.class, AnnotationFactory.create( documentIdAnnotation ) );
+ }
+ }
+
private void createFields(PropertyDescriptor property) {
final Collection<Map<String,Object>> fields = property.getFields();
List<org.hibernate.search.annotations.Field> fieldAnnotations =
@@ -291,6 +305,7 @@
annotations.put( Fields.class, AnnotationFactory.create( fieldsAnnotation ) );
}
+ //TODO add something around Similarity
private void createIndexed(EntityDescriptor entity) {
Class<? extends Annotation> annotationType = Indexed.class;
AnnotationDescriptor annotation = new AnnotationDescriptor( annotationType );
@@ -298,6 +313,14 @@
annotation.setValue( entry.getKey(), entry.getValue() );
}
annotations.put( annotationType, AnnotationFactory.create( annotation ) );
+
+ if ( entity.getSimilarity() != null ) {
+ annotation = new AnnotationDescriptor( Similarity.class );
+ for ( Map.Entry<String, Object> entry : entity.getSimilarity().entrySet() ) {
+ annotation.setValue( entry.getKey(), entry.getValue() );
+ }
+ annotations.put( annotationType, AnnotationFactory.create( annotation ) );
+ }
}
private void populateAnnotationArray() {
Modified: search/trunk/src/test/java/org/hibernate/search/test/configuration/Address.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/Address.java 2009-04-08 16:58:37 UTC (rev 16282)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/Address.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -12,12 +12,16 @@
public class Address {
@Id
@GeneratedValue
- private Long id;
+ private Long addressId;
private String street1;
private String street2;
@ManyToOne
private Country country;
+ public Long getAddressId() {
+ return addressId;
+ }
+
public String getStreet1() {
return street1;
}
Modified: search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-04-08 16:58:37 UTC (rev 16282)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-04-08 23:11:28 UTC (rev 16283)
@@ -46,8 +46,13 @@
tx = s.beginTransaction();
QueryParser parser = new QueryParser( "id", new StandardAnalyzer( ) );
- org.apache.lucene.search.Query luceneQuery = parser.parse( "street1:peachtree" );
- FullTextQuery query = s.createFullTextQuery( luceneQuery ).setProjection( "idx_street2", FullTextQuery.THIS );
+ org.apache.lucene.search.Query luceneQuery = parser.parse( "" + address.getAddressId() );
+ System.out.println(luceneQuery.toString( ));
+ FullTextQuery query = s.createFullTextQuery( luceneQuery );
+ assertEquals( "documenId does not work properly", 1, query.getResultSize() );
+
+ luceneQuery = parser.parse( "street1:peachtree" );
+ query = s.createFullTextQuery( luceneQuery ).setProjection( "idx_street2", FullTextQuery.THIS );
assertEquals( "Not properly indexed", 1, query.getResultSize() );
Object[] firstResult = (Object[]) query.list().get( 0 );
assertEquals( "@Field.store not respected", "JBoss", firstResult[0] );
@@ -160,6 +165,7 @@
.param( "maxGramSize", "3" )
.indexedClass( Address.class )
+ .property( "addressId", ElementType.FIELD ).documentId().name( "id" )
.property( "street1", ElementType.FIELD )
.field()
.field().name( "street1_ngram" ).analyzer( "ngram" )
15 years, 7 months
Hibernate SVN: r16282 - /.
by hibernate-commits@lists.jboss.org
Author: scottmarlownovell
Date: 2009-04-08 12:58:37 -0400 (Wed, 08 Apr 2009)
New Revision: 16282
Removed:
cglib/
Log:
HHH-3832 Upgrade to cglib-2.2 (asm 3.1)
15 years, 7 months