Hibernate SVN: r11110 - branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-27 11:24:20 -0500 (Sat, 27 Jan 2007)
New Revision: 11110
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
Log:
ANN-546 support for pure JPA players, tests ready but not commited due to dependencies
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/JPAValidateEventListener.java 2007-01-27 16:24:20 UTC (rev 11110)
@@ -0,0 +1,47 @@
+//$Id: $
+package org.hibernate.validator.event;
+
+import java.lang.ref.WeakReference;
+import java.util.Map;
+import java.util.WeakHashMap;
+import javax.persistence.PrePersist;
+import javax.persistence.PreUpdate;
+
+import org.hibernate.validator.ClassValidator;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class JPAValidateEventListener {
+ //No need for weakReference if the event listener is loaded by the same CL than
+ //the entities, but in a shared env this is not the case
+ //TODO check that this can be hot redeployable
+ private static final Map<Class, WeakReference<ClassValidator>> validators;
+ private static final ClassValidator<JPAValidateEventListener> NO_VALIDATOR;
+ static {
+ validators = new WeakHashMap<Class, WeakReference<ClassValidator>>();
+ NO_VALIDATOR = new ClassValidator<JPAValidateEventListener>(JPAValidateEventListener.class);
+ }
+
+ @PrePersist
+ @PreUpdate
+ @SuppressWarnings( "unchecked" )
+ public void onChange(Object object) {
+ if (object == null) return;
+ Class entity = object.getClass();
+ WeakReference<ClassValidator> weakValidator = validators.get(entity);
+ ClassValidator validator = weakValidator != null ? weakValidator.get() : null;
+ if ( validator == null ) {
+ //initialize
+ //TODO reuse the same reflection manager?
+ validator = new ClassValidator(entity);
+ if ( ! validator.hasValidationRules() ) {
+ validator = NO_VALIDATOR;
+ }
+ validators.put( entity, new WeakReference<ClassValidator>(validator) );
+ }
+ if ( validator != NO_VALIDATOR ) {
+ validator.assertValid( object );
+ }
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-27 02:53:20 UTC (rev 11109)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-27 16:24:20 UTC (rev 11110)
@@ -136,7 +136,6 @@
if ( element == null ) return; //no validation to do
List<InvalidValue> consolidatedInvalidValues = new ArrayList<InvalidValue>();
validateSubElements( element, entity, consolidatedInvalidValues );
- consolidatedInvalidValues.size();
InvalidValue[] invalidValues = element.validator == null ?
null :
element.validator.getInvalidValues( entity );
17 years, 11 months
Hibernate SVN: r11109 - in branches/Branch_3_2/HibernateExt/metadata/src: test/org/hibernate/validator/test and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-26 21:53:20 -0500 (Fri, 26 Jan 2007)
New Revision: 11109
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Version.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Building.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/InterpolationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/PrefixMessageInterpolator.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/
Removed:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MarsAddress.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Martian.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MartianPk.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Music.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Rock.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Venusian.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/VenusianPk.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Building.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/InterpolationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Address.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Contact.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Tv.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/TvOwner.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/ValidatorTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/Car.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/CreditCard.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/LuhnTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/NotEmptyTest.java
Log:
ANN-545 eliminate dep on tests and core validator
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -28,10 +28,9 @@
import org.hibernate.AssertionFailure;
import org.hibernate.Hibernate;
import org.hibernate.MappingException;
-import org.hibernate.cfg.BinderHelper;
-import org.hibernate.cfg.annotations.Version;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
+import org.hibernate.mapping.Component;
import org.hibernate.reflection.Filter;
import org.hibernate.reflection.ReflectionManager;
import org.hibernate.reflection.XClass;
@@ -602,7 +601,7 @@
String propertyName = getPropertyName( getters.next() );
if ( validator instanceof PropertyConstraint ) {
try {
- Property property = BinderHelper.findPropertyByName(persistentClass, propertyName);
+ Property property = findPropertyByName(persistentClass, propertyName);
if (property != null) {
( (PropertyConstraint) validator ).apply( property );
}
@@ -654,4 +653,60 @@
reflectionManager = new JavaReflectionManager();
initValidator( reflectionManager.toXClass( beanClass ), new HashMap<XClass, ClassValidator>() );
}
+
+ /**
+ * Retrieve the property by path in a recursive way, including IndetifierProperty in the loop
+ * If propertyName is null or empty, the IdentifierProperty is returned
+ */
+ public static Property findPropertyByName(PersistentClass associatedClass, String propertyName) {
+ Property property = null;
+ Property idProperty = associatedClass.getIdentifierProperty();
+ String idName = idProperty != null ? idProperty.getName() : null;
+ try {
+ if ( propertyName == null
+ || propertyName.length() == 0
+ || propertyName.equals( idName ) ) {
+ //default to id
+ property = idProperty;
+ }
+ else {
+ if ( propertyName.indexOf( idName + "." ) == 0 ) {
+ property = idProperty;
+ propertyName = propertyName.substring( idName.length() + 1 );
+ }
+ StringTokenizer st = new StringTokenizer( propertyName, ".", false );
+ while ( st.hasMoreElements() ) {
+ String element = (String) st.nextElement();
+ if ( property == null ) {
+ property = associatedClass.getProperty( element );
+ }
+ else {
+ if ( ! property.isComposite() ) return null;
+ property = ( (Component) property.getValue() ).getProperty( element );
+ }
+ }
+ }
+ }
+ catch (MappingException e) {
+ try {
+ //if we do not find it try to check the identifier mapper
+ if ( associatedClass.getIdentifierMapper() == null ) return null;
+ StringTokenizer st = new StringTokenizer( propertyName, ".", false );
+ while ( st.hasMoreElements() ) {
+ String element = (String) st.nextElement();
+ if ( property == null ) {
+ property = associatedClass.getIdentifierMapper().getProperty( element );
+ }
+ else {
+ if ( ! property.isComposite() ) return null;
+ property = ( (Component) property.getValue() ).getProperty( element );
+ }
+ }
+ }
+ catch (MappingException ee) {
+ return null;
+ }
+ }
+ return property;
+ }
}
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Version.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Version.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Version.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -0,0 +1,22 @@
+//$Id: $
+package org.hibernate.validator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Hibernate Vaildator version
+ *
+ * @author Emmanuel Bernard
+ */
+public class Version {
+ public static final String VERSION = "3.2.2.GA";
+ private static Log log = LogFactory.getLog( Version.class );
+
+ static {
+ log.info( "Hibernate Validator " + VERSION );
+ }
+
+ public static void touch() {
+ }
+}
\ No newline at end of file
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Address.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Address.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Address.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,10 +1,6 @@
//$Id$
package org.hibernate.validator.test;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Transient;
-
import org.hibernate.validator.AssertTrue;
import org.hibernate.validator.Length;
import org.hibernate.validator.Min;
@@ -15,7 +11,6 @@
/**
* @author Gavin King
*/
-@Entity
public class Address {
@NotNull
public static String blacklistedZipCode;
@@ -79,13 +74,11 @@
}
@AssertTrue
- @Transient
public boolean isValid() {
return true;
}
@AssertTrue
- @Transient
private boolean isInternalValid() {
return internalValid;
}
@@ -94,7 +87,6 @@
this.internalValid = internalValid;
}
- @Id
@Min(1)
@Range(max = 2000)
public long getId() {
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Building.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Building.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Building.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -0,0 +1,32 @@
+//$Id: $
+package org.hibernate.validator.test;
+
+import org.hibernate.validator.Length;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Building {
+ private Long id;
+
+ @Length( min = 1, message = "{notpresent.Key} and #{key.notPresent} and {key.notPresent2} {min}" )
+ private String address;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+}
+
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Contact.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Contact.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Contact.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,15 +1,11 @@
//$Id$
package org.hibernate.validator.test;
-import javax.persistence.Embeddable;
-
import org.hibernate.validator.NotNull;
/**
* @author Emmanuel Bernard
*/
-
-@Embeddable
public class Contact {
@NotNull
private String name;
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,174 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.event.PreInsertEventListener;
-import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.mapping.Column;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.test.annotations.TestCase;
-import org.hibernate.validator.InvalidStateException;
-import org.hibernate.validator.Environment;
-import org.hibernate.validator.event.ValidatePreInsertEventListener;
-import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-
-/**
- * Test the validate framework integration with the Hibernate
- * metadata binding
- *
- * @author Emmanuel Bernard
- */
-public class HibernateAnnotationIntegrationTest extends TestCase {
- public void testApply() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
- //new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
- Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next();
- assertEquals( stateColumn.getLength(), 3 );
- Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next();
- assertEquals( zipColumn.getLength(), 5 );
- assertFalse( zipColumn.isNullable() );
- }
-
- public void testApplyOnIdColumn() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( Tv.class.getName() );
- Column serialColumn = (Column) classMapping.getIdentifierProperty().getColumnIterator().next();
- assertEquals( "Vaidator annotation not applied on ids", 2, serialColumn.getLength() );
- }
-
- public void testApplyOnManyToOne() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( TvOwner.class.getName() );
- Column serialColumn = (Column) classMapping.getProperty( "tv" ).getColumnIterator().next();
- assertEquals( "Validator annotations not applied on associations", false, serialColumn.isNullable() );
- }
-
- public void testSingleTableAvoidNotNull() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( Rock.class.getName() );
- Column serialColumn = (Column) classMapping.getProperty( "bit" ).getColumnIterator().next();
- assertTrue( "Notnull should not be applised on single tables", serialColumn.isNullable() );
- }
-
- public void testEvents() throws Exception {
- Session s;
- Transaction tx;
- Address a = new Address();
- Address.blacklistedZipCode = "3232";
- a.setId( 12 );
- a.setCountry( "Country" );
- a.setLine1( "Line 1" );
- a.setZip( "nonnumeric" );
- a.setState( "NY" );
- s = openSession();
- tx = s.beginTransaction();
- try {
- s.persist( a );
- tx.commit();
- fail( "bean should have been validated" );
- }
- catch (InvalidStateException e) {
- //success
- assertEquals( 2, e.getInvalidValues().length );
- assertTrue( "Environment.MESSAGE_INTERPOLATOR_CLASS does not work",
- e.getInvalidValues()[0].getMessage().startsWith( "prefix_")
- );
- }
- finally {
- if ( tx != null ) tx.rollback();
- s.close();
- }
- s = openSession();
- tx = s.beginTransaction();
- a.setCountry( "Country" );
- a.setLine1( "Line 1" );
- a.setZip( "4343" );
- a.setState( "NY" );
- s.persist( a );
- a.setState( "TOOLONG" );
- try {
- s.flush();
- fail( "update should have been checked" );
- }
- catch (InvalidStateException e) {
- assertEquals( 1, e.getInvalidValues().length );
- }
- finally {
- if ( tx != null ) tx.rollback();
- s.close();
- }
- }
-
- public void testComponents() throws Exception {
- Session s;
- Transaction tx;
- s = openSession();
- tx = s.beginTransaction();
- Martian martian = new Martian();
- MartianPk pk = new MartianPk();
- pk.setColony( "Liberal" ); //one failure
- pk.setName( "Biboudie" );
- MarsAddress address = new MarsAddress();
- address.setContinent( "cont" ); //one failure
- address.setCanal( "Plus" ); //one failure
- martian.setId( pk );
- martian.setAddress( address );
- s.persist( martian );
- try {
- s.flush();
- fail( "Components are not validated" );
- }
- catch (InvalidStateException e) {
- assertEquals( 2, e.getInvalidValues().length );
- }
- finally {
- tx.rollback();
- s.close();
- }
- }
-
- public void testIdClass() throws Exception {
- Session s;
- Transaction tx;
- s = openSession();
- tx = s.beginTransaction();
- Venusian venus = new Venusian();
- venus.setName( "bibi" );
- venus.setRegion( "ts" );
- s.persist( venus );
- try {
- s.flush();
- fail( "test on embedded properties should have been done" );
- }
- catch (InvalidStateException e) {
- assertEquals( 1, e.getInvalidValues().length );
- }
- finally {
- tx.rollback();
- s.close();
- }
- }
-
- protected void configure(Configuration cfg) {
- cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS, PrefixMessageInterpolator.class.getName() );
- cfg.getEventListeners()
- .setPreInsertEventListeners( new PreInsertEventListener[]{new ValidatePreInsertEventListener()} );
- cfg.getEventListeners()
- .setPreUpdateEventListeners( new PreUpdateEventListener[]{new ValidatePreUpdateEventListener()} );
- }
-
- protected Class[] getMappings() {
- return new Class[]{
- Address.class,
- Martian.class,
- Venusian.class,
- Tv.class,
- TvOwner.class,
- Music.class,
- Rock.class
- };
- }
-
- public HibernateAnnotationIntegrationTest(String x) {
- super( x );
- }
-}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/InterpolationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/InterpolationTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/InterpolationTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -0,0 +1,36 @@
+//$Id: $
+package org.hibernate.validator.test;
+
+import java.util.MissingResourceException;
+
+import junit.framework.TestCase;
+import org.hibernate.validator.ClassValidator;
+import org.hibernate.validator.InvalidValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class InterpolationTest extends TestCase {
+ public void testMissingKey() {
+
+ Building b = new Building();
+ b.setAddress( "2323 Younge St");
+ ClassValidator<Building> validator = new ClassValidator<Building>(Building.class);
+ try {
+ validator.getInvalidValues( b );
+ }
+ catch (MissingResourceException e) {
+ fail("message should be interpolated lazily in DefaultMessageInterpolator");
+ }
+
+ b = new Building();
+ b.setAddress("");
+ boolean failure = false;
+ InvalidValue[] invalidValues = validator.getInvalidValues( b );
+ assertNotSame( "Should have a failure here", 0, invalidValues.length );
+ assertEquals( "Missing key should be left unchanged",
+ "{notpresent.Key} and #{key.notPresent} and {key.notPresent2} 1",
+ invalidValues[0].getMessage() );
+ }
+}
+
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MarsAddress.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MarsAddress.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MarsAddress.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,34 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import javax.persistence.Embeddable;
-
-import org.hibernate.validator.Length;
-import org.hibernate.validator.NotNull;
-
-/**
- * @author Emmanuel Bernard
- */
-@Embeddable
-public class MarsAddress {
- private String continent;
- private String canal;
-
- @NotNull
- public String getContinent() {
- return continent;
- }
-
- public void setContinent(String continent) {
- this.continent = continent;
- }
-
- @Length(min = 5)
- public String getCanal() {
- return canal;
- }
-
- public void setCanal(String canal) {
- this.canal = canal;
- }
-}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Martian.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Martian.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Martian.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,32 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Martian {
- private MartianPk id;
- private MarsAddress address;
-
- @Id
- public MartianPk getId() {
- return id;
- }
-
- public void setId(MartianPk id) {
- this.id = id;
- }
-
- public MarsAddress getAddress() {
- return address;
- }
-
- public void setAddress(MarsAddress address) {
- this.address = address;
- }
-
-}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MartianPk.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MartianPk.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MartianPk.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,52 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import java.io.Serializable;
-import javax.persistence.Embeddable;
-
-import org.hibernate.validator.Length;
-
-/**
- * @author Emmanuel Bernard
- */
-@Embeddable
-public class MartianPk implements Serializable {
- private String name;
- private String colony;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Length(max = 4)
- public String getColony() {
- return colony;
- }
-
- public void setColony(String colony) {
- this.colony = colony;
- }
-
- public boolean equals(Object o) {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- final MartianPk martianPk = (MartianPk) o;
-
- if ( !colony.equals( martianPk.colony ) ) return false;
- if ( !name.equals( martianPk.name ) ) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = name.hashCode();
- result = 29 * result + colony.hashCode();
- return result;
- }
-}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Music.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Music.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Music.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,14 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Music {
- @Id
- public String name;
-}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,48 +0,0 @@
-//$Id: $
-package org.hibernate.validator.test;
-
-import org.hibernate.test.annotations.TestCase;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Column;
-import org.hibernate.event.PreInsertEventListener;
-import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.validator.Environment;
-import org.hibernate.validator.event.ValidatePreInsertEventListener;
-import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-
-/**
- * Test the ability to disable DDL update
- *
- * @author Emmanuel Bernard
- */
-public class NonHibernateAnnotationsIntegrationTest extends TestCase {
- public void testNotApply() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
- //new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
- Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next();
- assertFalse( stateColumn.getLength() == 3 );
- Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next();
- assertFalse( zipColumn.getLength() == 5 );
- assertTrue( zipColumn.isNullable() );
- }
-
- protected void configure(Configuration cfg) {
- cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS, PrefixMessageInterpolator.class.getName() );
- cfg.setProperty( Environment.APPLY_TO_DDL, "false" );
- cfg.getEventListeners()
- .setPreInsertEventListeners( new PreInsertEventListener[]{new ValidatePreInsertEventListener()} );
- cfg.getEventListeners()
- .setPreUpdateEventListeners( new PreUpdateEventListener[]{new ValidatePreUpdateEventListener()} );
- }
-
- protected Class[] getMappings() {
- return new Class[]{
- Address.class,
- };
- }
-
- public NonHibernateAnnotationsIntegrationTest(String x) {
- super( x );
- }
-}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,14 +0,0 @@
-//$Id: $
-package org.hibernate.validator.test;
-
-import org.hibernate.validator.MessageInterpolator;
-import org.hibernate.validator.Validator;
-
-/**
- * @author Emmanuel Bernard
- */
-public class PrefixMessageInterpolator implements MessageInterpolator {
- public String interpolate(String message, Validator validator, MessageInterpolator defaultInterpolator) {
- return "prefix_" + defaultInterpolator.interpolate( message, validator, defaultInterpolator );
- }
-}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Rock.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Rock.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Rock.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,15 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import javax.persistence.Entity;
-
-import org.hibernate.validator.NotNull;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Rock extends Music {
- @NotNull
- public Integer bit;
-}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Tv.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Tv.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Tv.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,10 +1,8 @@
//$Id$
package org.hibernate.validator.test;
-import java.util.Date;
import java.math.BigInteger;
-import javax.persistence.Entity;
-import javax.persistence.Id;
+import java.util.Date;
import org.hibernate.validator.Future;
import org.hibernate.validator.Length;
@@ -13,9 +11,7 @@
/**
* @author Emmanuel Bernard
*/
-@Entity
public class Tv {
- @Id
@Length(max = 2)
public String serial;
public int size;
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/TvOwner.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/TvOwner.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/TvOwner.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,22 +1,16 @@
//$Id$
package org.hibernate.validator.test;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-
import org.hibernate.validator.NotNull;
+import org.hibernate.validator.Valid;
/**
* @author Emmanuel Bernard
*/
-@Entity
public class TvOwner {
- @Id
- @GeneratedValue
public Integer id;
- @ManyToOne
+
@NotNull
+ @Valid
public Tv tv;
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/ValidatorTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/ValidatorTest.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/ValidatorTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,11 +1,11 @@
//$Id$
package org.hibernate.validator.test;
+import java.io.Serializable;
+import java.math.BigInteger;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
-import java.math.BigInteger;
-import java.io.Serializable;
import junit.framework.TestCase;
import org.hibernate.validator.ClassValidator;
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Venusian.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Venusian.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Venusian.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,38 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import java.io.Serializable;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.IdClass;
-
-import org.hibernate.validator.Length;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-(a)IdClass(VenusianPk.class)
-public class Venusian implements Serializable {
- private String region;
- private String name;
-
- @Id
- @Length(min = 3)
- public String getRegion() {
- return region;
- }
-
- public void setRegion(String region) {
- this.region = region;
- }
-
- @Id
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/VenusianPk.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/VenusianPk.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/VenusianPk.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,47 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import java.io.Serializable;
-
-/**
- * @author Emmanuel Bernard
- */
-public class VenusianPk implements Serializable {
- private String region;
- private String name;
-
- public String getRegion() {
- return region;
- }
-
- public void setRegion(String region) {
- this.region = region;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public boolean equals(Object o) {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- final VenusianPk that = (VenusianPk) o;
-
- if ( !name.equals( that.name ) ) return false;
- if ( !region.equals( that.region ) ) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = region.hashCode();
- result = 29 * result + name.hashCode();
- return result;
- }
-}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Building.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Building.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Building.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,38 +0,0 @@
-//$Id: $
-package org.hibernate.validator.test.haintegration;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-
-import org.hibernate.validator.NotNull;
-import org.hibernate.validator.Length;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Building {
- @Id
- @GeneratedValue private Long id;
-
- @Length(min=1, message = "{notpresent.Key} and #{key.notPresent} and {key.notPresent2} {min}")
- private String address;
-
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -8,10 +8,8 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.validator.ClassValidator;
-import org.hibernate.validator.Environment;
import org.hibernate.validator.event.ValidatePreInsertEventListener;
import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-import org.hibernate.validator.test.PrefixMessageInterpolator;
/**
* @author Emmanuel Bernard
Copied: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java (from rev 11108, branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java)
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -0,0 +1,173 @@
+//$Id$
+package org.hibernate.validator.test.haintegration;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.event.PreInsertEventListener;
+import org.hibernate.event.PreUpdateEventListener;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.validator.InvalidStateException;
+import org.hibernate.validator.Environment;
+import org.hibernate.validator.event.ValidateEventListener;
+
+/**
+ * Test the validate framework integration with the Hibernate
+ * metadata binding
+ *
+ * @author Emmanuel Bernard
+ */
+public class HibernateAnnotationIntegrationTest extends TestCase {
+ public void testApply() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
+ //new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
+ Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next();
+ assertEquals( stateColumn.getLength(), 3 );
+ Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next();
+ assertEquals( zipColumn.getLength(), 5 );
+ assertFalse( zipColumn.isNullable() );
+ }
+
+ public void testApplyOnIdColumn() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Tv.class.getName() );
+ Column serialColumn = (Column) classMapping.getIdentifierProperty().getColumnIterator().next();
+ assertEquals( "Vaidator annotation not applied on ids", 2, serialColumn.getLength() );
+ }
+
+ public void testApplyOnManyToOne() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( TvOwner.class.getName() );
+ Column serialColumn = (Column) classMapping.getProperty( "tv" ).getColumnIterator().next();
+ assertEquals( "Validator annotations not applied on associations", false, serialColumn.isNullable() );
+ }
+
+ public void testSingleTableAvoidNotNull() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Rock.class.getName() );
+ Column serialColumn = (Column) classMapping.getProperty( "bit" ).getColumnIterator().next();
+ assertTrue( "Notnull should not be applised on single tables", serialColumn.isNullable() );
+ }
+
+ public void testEvents() throws Exception {
+ Session s;
+ Transaction tx;
+ Address a = new Address();
+ Address.blacklistedZipCode = "3232";
+ a.setId( 12 );
+ a.setCountry( "Country" );
+ a.setLine1( "Line 1" );
+ a.setZip( "nonnumeric" );
+ a.setState( "NY" );
+ s = openSession();
+ tx = s.beginTransaction();
+ try {
+ s.persist( a );
+ tx.commit();
+ fail( "bean should have been validated" );
+ }
+ catch (InvalidStateException e) {
+ //success
+ assertEquals( 2, e.getInvalidValues().length );
+ assertTrue( "Environment.MESSAGE_INTERPOLATOR_CLASS does not work",
+ e.getInvalidValues()[0].getMessage().startsWith( "prefix_")
+ );
+ }
+ finally {
+ if ( tx != null ) tx.rollback();
+ s.close();
+ }
+ s = openSession();
+ tx = s.beginTransaction();
+ a.setCountry( "Country" );
+ a.setLine1( "Line 1" );
+ a.setZip( "4343" );
+ a.setState( "NY" );
+ s.persist( a );
+ a.setState( "TOOLONG" );
+ try {
+ s.flush();
+ fail( "update should have been checked" );
+ }
+ catch (InvalidStateException e) {
+ assertEquals( 1, e.getInvalidValues().length );
+ }
+ finally {
+ if ( tx != null ) tx.rollback();
+ s.close();
+ }
+ }
+
+ public void testComponents() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ Martian martian = new Martian();
+ MartianPk pk = new MartianPk();
+ pk.setColony( "Liberal" ); //one failure
+ pk.setName( "Biboudie" );
+ MarsAddress address = new MarsAddress();
+ address.setContinent( "cont" ); //one failure
+ address.setCanal( "Plus" ); //one failure
+ martian.setId( pk );
+ martian.setAddress( address );
+ s.persist( martian );
+ try {
+ s.flush();
+ fail( "Components are not validated" );
+ }
+ catch (InvalidStateException e) {
+ assertEquals( 2, e.getInvalidValues().length );
+ }
+ finally {
+ tx.rollback();
+ s.close();
+ }
+ }
+
+ public void testIdClass() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ Venusian venus = new Venusian();
+ venus.setName( "bibi" );
+ venus.setRegion( "ts" );
+ s.persist( venus );
+ try {
+ s.flush();
+ fail( "test on embedded properties should have been done" );
+ }
+ catch (InvalidStateException e) {
+ assertEquals( 1, e.getInvalidValues().length );
+ }
+ finally {
+ tx.rollback();
+ s.close();
+ }
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS, PrefixMessageInterpolator.class.getName() );
+ cfg.getEventListeners()
+ .setPreInsertEventListeners( new PreInsertEventListener[]{new ValidateEventListener()} );
+ cfg.getEventListeners()
+ .setPreUpdateEventListeners( new PreUpdateEventListener[]{new ValidateEventListener()} );
+ }
+
+ protected Class[] getMappings() {
+ return new Class[]{
+ Address.class,
+ Martian.class,
+ Venusian.class,
+ Tv.class,
+ TvOwner.class,
+ Music.class,
+ Rock.class
+ };
+ }
+
+ public HibernateAnnotationIntegrationTest(String x) {
+ super( x );
+ }
+}
Property changes on: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/InterpolationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/InterpolationTest.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/InterpolationTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,70 +0,0 @@
-//$Id: $
-package org.hibernate.validator.test.haintegration;
-
-import java.util.MissingResourceException;
-
-import org.hibernate.test.annotations.TestCase;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.event.PreInsertEventListener;
-import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.validator.InvalidStateException;
-import org.hibernate.validator.Environment;
-import org.hibernate.validator.event.ValidatePreInsertEventListener;
-import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-import org.hibernate.validator.test.PrefixMessageInterpolator;
-
-/**
- * @author Emmanuel Bernard
- */
-public class InterpolationTest extends TestCase {
- public void testMissingKey() {
- Session s = openSession();
- Transaction tx = s.beginTransaction();
- Building b = new Building();
- b.setAddress( "2323 Younge St");
- try {
- s.persist( b );
- s.flush();
- }
- catch (MissingResourceException e) {
- fail("message should be interpolated lazily in DefaultMessageInterpolator");
- }
- tx.rollback();
- s.close();
-
- s = openSession();
- tx = s.beginTransaction();
- b = new Building();
- b.setAddress("");
- boolean failure = false;
- try {
- s.persist( b );
- s.flush();
- fail("Insert should fail");
- }
- catch (InvalidStateException e) {
- assertEquals( "Missing key should be left unchanged",
- "{notpresent.Key} and #{key.notPresent} and {key.notPresent2} 1",
- e.getInvalidValues()[0].getMessage() );
- failure = true;
- }
- assertTrue( "No invalid state found", failure );
- tx.rollback();
- s.close();
- }
-
- protected Class[] getMappings() {
- return new Class[] {
- Building.class
- };
- }
-
- protected void configure(Configuration cfg) {
- cfg.getEventListeners()
- .setPreInsertEventListeners( new PreInsertEventListener[]{new ValidatePreInsertEventListener()} );
- cfg.getEventListeners()
- .setPreUpdateEventListeners( new PreUpdateEventListener[]{new ValidatePreUpdateEventListener()} );
- }
-}
Copied: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java (from rev 11108, branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java)
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -0,0 +1,47 @@
+//$Id: $
+package org.hibernate.validator.test.haintegration;
+
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Column;
+import org.hibernate.event.PreInsertEventListener;
+import org.hibernate.event.PreUpdateEventListener;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.validator.Environment;
+import org.hibernate.validator.event.ValidateEventListener;
+
+/**
+ * Test the ability to disable DDL update
+ *
+ * @author Emmanuel Bernard
+ */
+public class NonHibernateAnnotationsIntegrationTest extends TestCase {
+ public void testNotApply() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
+ //new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
+ Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next();
+ assertFalse( stateColumn.getLength() == 3 );
+ Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next();
+ assertFalse( zipColumn.getLength() == 5 );
+ assertTrue( zipColumn.isNullable() );
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS, PrefixMessageInterpolator.class.getName() );
+ cfg.setProperty( Environment.APPLY_TO_DDL, "false" );
+ cfg.getEventListeners()
+ .setPreInsertEventListeners( new PreInsertEventListener[]{new ValidateEventListener()} );
+ cfg.getEventListeners()
+ .setPreUpdateEventListeners( new PreUpdateEventListener[]{new ValidateEventListener()} );
+ }
+
+ protected Class[] getMappings() {
+ return new Class[]{
+ Address.class,
+ };
+ }
+
+ public NonHibernateAnnotationsIntegrationTest(String x) {
+ super( x );
+ }
+}
Copied: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/PrefixMessageInterpolator.java (from rev 11108, branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java)
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/PrefixMessageInterpolator.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/PrefixMessageInterpolator.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -0,0 +1,14 @@
+//$Id: $
+package org.hibernate.validator.test.haintegration;
+
+import org.hibernate.validator.MessageInterpolator;
+import org.hibernate.validator.Validator;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class PrefixMessageInterpolator implements MessageInterpolator {
+ public String interpolate(String message, Validator validator, MessageInterpolator defaultInterpolator) {
+ return "prefix_" + defaultInterpolator.interpolate( message, validator, defaultInterpolator );
+ }
+}
Copied: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators (from rev 11108, branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator)
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/Car.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/Car.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/Car.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,5 +1,5 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
import java.math.BigDecimal;
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/CreditCard.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/CreditCard.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/CreditCard.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,5 +1,5 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
import org.hibernate.validator.EAN;
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/DigitsTest.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,22 +1,17 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
import java.math.BigDecimal;
-import org.hibernate.validator.ClassValidator;
-import org.hibernate.validator.InvalidValue;
-import org.hibernate.validator.Environment;
-import org.hibernate.validator.event.ValidatePreInsertEventListener;
-import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-import org.hibernate.validator.test.Address;
-import org.hibernate.validator.test.PrefixMessageInterpolator;
-import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Column;
+import org.hibernate.mapping.PersistentClass;
import org.hibernate.test.annotations.TestCase;
+import org.hibernate.validator.ClassValidator;
+import org.hibernate.validator.InvalidValue;
+import org.hibernate.validator.event.ValidateEventListener;
/**
* @author Emmanuel Bernard
@@ -47,9 +42,9 @@
protected void configure(Configuration cfg) {
cfg.getEventListeners()
- .setPreInsertEventListeners( new PreInsertEventListener[]{new ValidatePreInsertEventListener()} );
+ .setPreInsertEventListeners( new PreInsertEventListener[]{new ValidateEventListener()} );
cfg.getEventListeners()
- .setPreUpdateEventListeners( new PreUpdateEventListener[]{new ValidatePreUpdateEventListener()} );
+ .setPreUpdateEventListeners( new PreUpdateEventListener[]{new ValidateEventListener()} );
}
protected Class[] getMappings() {
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/LuhnTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/LuhnTest.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/LuhnTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,5 +1,5 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
import junit.framework.TestCase;
import org.hibernate.validator.ClassValidator;
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/NotEmptyTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/NotEmptyTest.java 2007-01-26 21:21:03 UTC (rev 11108)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/NotEmptyTest.java 2007-01-27 02:53:20 UTC (rev 11109)
@@ -1,24 +1,9 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
-import java.util.ResourceBundle;
-import java.util.Locale;
-import java.util.Date;
-import java.io.Serializable;
-import java.math.BigInteger;
-
import junit.framework.TestCase;
-import org.hibernate.validator.test.Address;
-import org.hibernate.validator.test.Brother;
-import org.hibernate.validator.test.Tv;
-import org.hibernate.validator.test.Vase;
-import org.hibernate.validator.test.Site;
-import org.hibernate.validator.test.Contact;
-import org.hibernate.validator.test.ValidatorTest;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
-import org.hibernate.validator.MessageInterpolator;
-import org.hibernate.validator.Validator;
/**
* @author Gavin King
17 years, 11 months
Hibernate SVN: r11108 - branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-26 16:21:03 -0500 (Fri, 26 Jan 2007)
New Revision: 11108
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
Log:
ANN-545 eliminate dep between HAN and Validator
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-26 21:17:27 UTC (rev 11107)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-26 21:21:03 UTC (rev 11108)
@@ -12,7 +12,6 @@
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.event.Initializable;
import org.hibernate.event.PreInsertEvent;
@@ -47,7 +46,7 @@
/**
* initialize the validators, any non significant validators are not kept
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public synchronized void initialize(final Configuration cfg) {
if ( !isInitialized ) {
String interpolatorString = cfg.getProperty( Environment.MESSAGE_INTERPOLATOR_CLASS );
@@ -61,31 +60,36 @@
throw new HibernateException( "Unable to find message interpolator: " + interpolatorString, e );
}
catch (IllegalAccessException e) {
- throw new HibernateException( "Unable to instanciate message interpolator: " + interpolatorString, e );
+ throw new HibernateException( "Unable to instanciate message interpolator: " + interpolatorString,
+ e );
}
catch (InstantiationException e) {
- throw new HibernateException( "Unable to instanciate message interpolator: " + interpolatorString, e );
+ throw new HibernateException( "Unable to instanciate message interpolator: " + interpolatorString,
+ e );
}
catch (ClassCastException e) {
throw new HibernateException( "Class does not implement "
- + MessageInterpolator.class.getName() + ": " + interpolatorString, e );
+ + MessageInterpolator.class.getName() + ": " + interpolatorString, e );
}
}
Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
- ReflectionManager reflectionManager;
- try {
- //TODO introduce q ReflectionManagerHolder interface to avoid reflection
- //I want to avoid hard link between HAN and Validator for usch a simple need
- //reuse the existing reflectionManager one when possible
- reflectionManager = (ReflectionManager) cfg.getClass().getMethod( "getReflectionManager" ).invoke(cfg);
+ ReflectionManager reflectionManager;
+ try {
+ //TODO introduce q ReflectionManagerHolder interface to avoid reflection
+ //I want to avoid hard link between HAN and Validator for usch a simple need
+ //reuse the existing reflectionManager one when possible
+ reflectionManager =
+ (ReflectionManager) cfg.getClass().getMethod( "getReflectionManager" ).invoke( cfg );
- } catch (Exception e) {
- reflectionManager = new JavaReflectionManager();
- }
- while ( classes.hasNext() ) {
+ }
+ catch (Exception e) {
+ reflectionManager = new JavaReflectionManager();
+ }
+ while ( classes.hasNext() ) {
PersistentClass clazz = classes.next();
final Class mappedClass = clazz.getMappedClass();
- ClassValidator validator = new ClassValidator( mappedClass, null, interpolator, null, reflectionManager );
+ ClassValidator validator =
+ new ClassValidator( mappedClass, null, interpolator, null, reflectionManager );
ValidatableElement element = new ValidatableElement( mappedClass, validator );
addSubElement( clazz.getIdentifierProperty(), element );
Iterator properties = clazz.getPropertyIterator();
@@ -100,9 +104,9 @@
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private void addSubElement(Property property, ValidatableElement element) {
- if ( property != null && property.isComposite() && ! property.isBackRef() ) {
+ if ( property != null && property.isComposite() && !property.isBackRef() ) {
Component component = (Component) property.getValue();
if ( component.isEmbedded() ) return;
PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.POJO );
@@ -119,9 +123,9 @@
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
protected void validate(Object entity, EntityMode mode) {
- if ( entity == null || ! EntityMode.POJO.equals( mode ) ) return;
+ if ( entity == null || !EntityMode.POJO.equals( mode ) ) return;
ValidatableElement element;
if ( isInitialized ) {
element = validators.get( entity.getClass() );
@@ -136,7 +140,7 @@
InvalidValue[] invalidValues = element.validator == null ?
null :
element.validator.getInvalidValues( entity );
- if (invalidValues != null) {
+ if ( invalidValues != null ) {
for ( InvalidValue invalidValue : invalidValues ) {
consolidatedInvalidValues.add( invalidValue );
}
@@ -149,7 +153,7 @@
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private void validateSubElements(
ValidatableElement element, Object entity, List<InvalidValue> consolidatedInvalidValues
) {
17 years, 11 months
Hibernate SVN: r11107 - in branches/Branch_3_2/HibernateExt/metadata/src: test/org/hibernate/validator/test and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-26 16:17:27 -0500 (Fri, 26 Jan 2007)
New Revision: 11107
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
Log:
ANN-545 eliminate dep between HAN and Validator
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-26 20:55:59 UTC (rev 11106)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-26 21:17:27 UTC (rev 11107)
@@ -73,11 +73,13 @@
}
Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
ReflectionManager reflectionManager;
- if ( cfg instanceof AnnotationConfiguration ) {
+ try {
+ //TODO introduce q ReflectionManagerHolder interface to avoid reflection
+ //I want to avoid hard link between HAN and Validator for usch a simple need
//reuse the existing reflectionManager one when possible
- reflectionManager = ( (AnnotationConfiguration) cfg).getReflectionManager();
- }
- else {
+ reflectionManager = (ReflectionManager) cfg.getClass().getMethod( "getReflectionManager" ).invoke(cfg);
+
+ } catch (Exception e) {
reflectionManager = new JavaReflectionManager();
}
while ( classes.hasNext() ) {
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java 2007-01-26 20:55:59 UTC (rev 11106)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java 2007-01-26 21:17:27 UTC (rev 11107)
@@ -12,8 +12,7 @@
import org.hibernate.validator.event.ValidatePreUpdateEventListener;
/**
- * Test the validate framework integration with the Hibernate
- * metadata binding
+ * Test the ability to disable DDL update
*
* @author Emmanuel Bernard
*/
17 years, 11 months
Hibernate SVN: r11106 - branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-26 15:55:59 -0500 (Fri, 26 Jan 2007)
New Revision: 11106
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidatePreInsertEventListener.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidatePreUpdateEventListener.java
Log:
deprecate subclasses
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidatePreInsertEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidatePreInsertEventListener.java 2007-01-26 01:54:51 UTC (rev 11105)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidatePreInsertEventListener.java 2007-01-26 20:55:59 UTC (rev 11106)
@@ -2,8 +2,10 @@
package org.hibernate.validator.event;
/**
- * Before update, execute the validator framework
+ * Before insert, execute the validator framework
*
+ * @deprecated use ValidateEventListener
+ *
* @author Gavin King
*/
public class ValidatePreInsertEventListener extends ValidateEventListener {
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidatePreUpdateEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidatePreUpdateEventListener.java 2007-01-26 01:54:51 UTC (rev 11105)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidatePreUpdateEventListener.java 2007-01-26 20:55:59 UTC (rev 11106)
@@ -4,6 +4,8 @@
/**
* Before update, execute the validator framework
*
+ * @deprecated use ValidateEventListener
+ *
* @author Gavin King
*/
public class ValidatePreUpdateEventListener extends ValidateEventListener {
17 years, 11 months
Hibernate SVN: r11105 - branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-25 20:54:51 -0500 (Thu, 25 Jan 2007)
New Revision: 11105
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3OverridenAnnotationReader.java
Log:
ANN-545 remove deps in test
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3OverridenAnnotationReader.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3OverridenAnnotationReader.java 2007-01-25 21:57:37 UTC (rev 11104)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3OverridenAnnotationReader.java 2007-01-26 01:54:51 UTC (rev 11105)
@@ -269,8 +269,7 @@
if ( className != null && propertyName == null ) {
//is a class
Element tree = xmlContext.getXMLTree( className, null );
- // FIXME: this variable is never used. why? is this a bug with overriding that didn't show up yet?
- Annotation[] annotations = getJavaAnnotations();
+ Annotation[] annotations = getJavaAnnotations();
List<Annotation> annotationList = new ArrayList<Annotation>( annotations.length + 5 );
annotationsMap = new HashMap<Class, Annotation>( annotations.length + 5 );
for ( Annotation annotation : annotations ) {
17 years, 11 months
Hibernate SVN: r11104 - branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-25 16:57:37 -0500 (Thu, 25 Jan 2007)
New Revision: 11104
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/Sex.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/JavaXClassTest.java
Log:
ANN-545 remove deps in test
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/JavaXClassTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/JavaXClassTest.java 2007-01-25 19:20:44 UTC (rev 11103)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/JavaXClassTest.java 2007-01-25 21:57:37 UTC (rev 11104)
@@ -3,7 +3,6 @@
import java.io.Serializable;
import java.util.List;
-import org.hibernate.annotations.CacheModeType;
import org.hibernate.reflection.ReflectionManager;
import org.hibernate.reflection.XAnnotatedElement;
import org.hibernate.reflection.XClass;
@@ -80,7 +79,7 @@
public void testCanBeAnEnum() {
assertFalse( fatherAsSeenFromSon.isEnum() );
- assertTrue( factory.toXClass( CacheModeType.class ).isEnum() );
+ assertTrue( factory.toXClass( Sex.class ).isEnum() );
}
@Override
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/Sex.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/Sex.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/Sex.java 2007-01-25 21:57:37 UTC (rev 11104)
@@ -0,0 +1,10 @@
+//$Id: $
+package org.hibernate.test.reflection.java;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public enum Sex {
+ MALE,
+ FEMALE
+}
17 years, 11 months
Hibernate SVN: r11103 - in branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator: event and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-25 14:20:44 -0500 (Thu, 25 Jan 2007)
New Revision: 11103
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
Log:
ANN-545
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-25 13:22:47 UTC (rev 11102)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-25 19:20:44 UTC (rev 11103)
@@ -38,7 +38,7 @@
import org.hibernate.reflection.XMember;
import org.hibernate.reflection.XMethod;
import org.hibernate.reflection.XProperty;
-import org.hibernate.reflection.java.xml.EJB3ReflectionManager;
+import org.hibernate.reflection.java.JavaReflectionManager;
import org.hibernate.util.IdentitySet;
import org.hibernate.validator.interpolator.DefaultMessageInterpolatorAggerator;
@@ -120,7 +120,7 @@
Class<T> beanClass, ResourceBundle resourceBundle, MessageInterpolator interpolator,
Map<XClass, ClassValidator> childClassValidators, ReflectionManager reflectionManager
) {
- this.reflectionManager = reflectionManager != null ? reflectionManager : new EJB3ReflectionManager();
+ this.reflectionManager = reflectionManager != null ? reflectionManager : new JavaReflectionManager();
XClass beanXClass = this.reflectionManager.toXClass( beanClass );
this.beanClass = beanClass;
this.messageBundle = resourceBundle == null ?
@@ -651,7 +651,7 @@
this.messageBundle = rb;
this.userInterpolator = (MessageInterpolator) ois.readObject();
this.defaultMessageBundle = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
- reflectionManager = new EJB3ReflectionManager();
+ reflectionManager = new JavaReflectionManager();
initValidator( reflectionManager.toXClass( beanClass ), new HashMap<XClass, ClassValidator>() );
}
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-25 13:22:47 UTC (rev 11102)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-25 19:20:44 UTC (rev 11103)
@@ -26,7 +26,7 @@
import org.hibernate.property.PropertyAccessor;
import org.hibernate.property.PropertyAccessorFactory;
import org.hibernate.reflection.ReflectionManager;
-import org.hibernate.reflection.java.xml.EJB3ReflectionManager;
+import org.hibernate.reflection.java.JavaReflectionManager;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
import org.hibernate.validator.ClassValidator;
@@ -78,7 +78,7 @@
reflectionManager = ( (AnnotationConfiguration) cfg).getReflectionManager();
}
else {
- reflectionManager = new EJB3ReflectionManager();
+ reflectionManager = new JavaReflectionManager();
}
while ( classes.hasNext() ) {
PersistentClass clazz = classes.next();
17 years, 11 months
Hibernate SVN: r11102 - in branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate: reflection and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: nusco
Date: 2007-01-25 08:22:47 -0500 (Thu, 25 Jan 2007)
New Revision: 11102
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/ReflectionManager.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaReflectionManager.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/generics/TypeEnvironmentFactory.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3OverridenAnnotationReader.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3ReflectionManager.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
Log:
Cleaning up of dependencies and misc refactorings in X layer.
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -162,7 +162,7 @@
private static final Log log = LogFactory.getLog( AnnotationBinder.class );
public static void bindDefaults(ExtendedMappings mappings) {
- Map defaults = ( (EJB3ReflectionManager) mappings.getReflectionManager() ).getDefaults();
+ Map defaults = mappings.getReflectionManager().getDefaults();
{
List<SequenceGenerator> anns = (List<SequenceGenerator>) defaults.get( SequenceGenerator.class );
if (anns != null) {
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -228,7 +228,6 @@
hbmDocuments = new ArrayList<Document>();
namingStrategy = EJB3NamingStrategy.INSTANCE;
setEntityResolver( new EJB3DTDEntityResolver() );
- // TODO
reflectionManager = new EJB3ReflectionManager();
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/ReflectionManager.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/ReflectionManager.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/ReflectionManager.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -2,6 +2,7 @@
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
+import java.util.Map;
/**
* The entry point to the reflection layer (a.k.a. the X* layer).
@@ -24,4 +25,6 @@
public <T> boolean equals(XClass class1, Class<T> class2);
public AnnotationReader buildAnnotationReader(AnnotatedElement annotatedElement);
+
+ public Map getDefaults();
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaReflectionManager.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaReflectionManager.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaReflectionManager.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -52,17 +52,6 @@
private final TypeEnvironmentFactory typeEnvs = new TypeEnvironmentFactory();
- public JavaReflectionManager() {
- reset();
- }
-
- public void reset() {
- xClasses.clear();
- packagesToXPackages.clear();
- xProperties.clear();
- xMethods.clear();
- }
-
public XClass toXClass(Class clazz) {
return toXClass( clazz, IdentityTypeEnvironment.INSTANCE );
}
@@ -189,4 +178,8 @@
public AnnotationReader buildAnnotationReader(AnnotatedElement annotatedElement) {
return new JavaAnnotationReader(annotatedElement);
}
+
+ public Map getDefaults() {
+ return new HashMap();
+ }
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/generics/TypeEnvironmentFactory.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/generics/TypeEnvironmentFactory.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/generics/TypeEnvironmentFactory.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -16,18 +16,22 @@
*/
public class TypeEnvironmentFactory {
- private final Map<Type, TypeEnvironment> typeToEnvironment = new HashMap<Type, TypeEnvironment>();
-
/**
* @return Returns a type environment suitable for resolving types occurring
* in subclasses of the context class.
*/
public TypeEnvironment getEnvironment(Class context) {
- return doGetEnvironment( context );
+ if ( context == null ) {
+ return IdentityTypeEnvironment.INSTANCE;
+ }
+ return createEnvironment( context );
}
public TypeEnvironment getEnvironment(Type context) {
- return doGetEnvironment( context );
+ if ( context == null ) {
+ return IdentityTypeEnvironment.INSTANCE;
+ }
+ return createEnvironment( context );
}
public TypeEnvironment getEnvironment(Type t, TypeEnvironment context) {
@@ -38,18 +42,6 @@
return CompoundTypeEnvironment.create( new ApproximatingTypeEnvironment(), context );
}
- private TypeEnvironment doGetEnvironment(Type context) {
- if ( context == null ) {
- return IdentityTypeEnvironment.INSTANCE;
- }
- TypeEnvironment result = typeToEnvironment.get( context );
- if ( result == null ) {
- result = createEnvironment( context );
- typeToEnvironment.put( context, result );
- }
- return result;
- }
-
private TypeEnvironment createEnvironment(Type context) {
return new TypeSwitch<TypeEnvironment>() {
@Override
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3OverridenAnnotationReader.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3OverridenAnnotationReader.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3OverridenAnnotationReader.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -269,6 +269,7 @@
if ( className != null && propertyName == null ) {
//is a class
Element tree = xmlContext.getXMLTree( className, null );
+ // FIXME: this variable is never used. why? is this a bug with overriding that didn't show up yet?
Annotation[] annotations = getJavaAnnotations();
List<Annotation> annotationList = new ArrayList<Annotation>( annotations.length + 5 );
annotationsMap = new HashMap<Class, Annotation>( annotations.length + 5 );
@@ -278,48 +279,27 @@
annotationList.add( annotation );
}
}
- Annotation current = getEntity( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getMappedSuperclass( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getEmbeddable( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getTable( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getSecondaryTables( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getPrimaryKeyJoinColumns( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getIdClass( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getInheritance( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getDiscriminatorValue( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getDiscriminatorColumn( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getSequenceGenerator( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getTableGenerator( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getNamedQueries( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getNamedNativeQueries( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getSqlResultSetMappings( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getExcludeDefaultListeners( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getExcludeSuperclassListeners( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getAccessType( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getAttributeOverrides( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getAssociationOverrides( tree, defaults );
- if ( current != null ) annotationList.add( current );
- current = getEntityListeners( tree, defaults );
- if ( current != null ) annotationList.add( current );
+ addIfNotNull( annotationList, getEntity( tree, defaults ) );
+ addIfNotNull( annotationList, getMappedSuperclass( tree, defaults ) );
+ addIfNotNull( annotationList, getEmbeddable( tree, defaults ) );
+ addIfNotNull( annotationList, getTable( tree, defaults ) );
+ addIfNotNull( annotationList, getSecondaryTables( tree, defaults ) );
+ addIfNotNull( annotationList, getPrimaryKeyJoinColumns( tree, defaults ) );
+ addIfNotNull( annotationList, getIdClass( tree, defaults ) );
+ addIfNotNull( annotationList, getInheritance( tree, defaults ) );
+ addIfNotNull( annotationList, getDiscriminatorValue( tree, defaults ) );
+ addIfNotNull( annotationList, getDiscriminatorColumn( tree, defaults ) );
+ addIfNotNull( annotationList, getSequenceGenerator( tree, defaults ) );
+ addIfNotNull( annotationList, getTableGenerator( tree, defaults ) );
+ addIfNotNull( annotationList, getNamedQueries( tree, defaults ) );
+ addIfNotNull( annotationList, getNamedNativeQueries( tree, defaults ) );
+ addIfNotNull( annotationList, getSqlResultSetMappings( tree, defaults ) );
+ addIfNotNull( annotationList, getExcludeDefaultListeners( tree, defaults ) );
+ addIfNotNull( annotationList, getExcludeSuperclassListeners( tree, defaults ) );
+ addIfNotNull( annotationList, getAccessType( tree, defaults ) );
+ addIfNotNull( annotationList, getAttributeOverrides( tree, defaults ) );
+ addIfNotNull( annotationList, getAssociationOverrides( tree, defaults ) );
+ addIfNotNull( annotationList, getEntityListeners( tree, defaults ) );
//FIXME use annotationsMap rather than annotationList this will be faster since the annotation type is usually known at put() time
this.annotations = annotationList.toArray( new Annotation[ annotationList.size() ] );
for (Annotation ann : this.annotations) {
@@ -345,7 +325,7 @@
else {
if ( defaults.canUseJavaAnnotations() ) {
Annotation annotation = getJavaAnnotation( AccessType.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
}
getId( annotationList, defaults );
getEmbeddedId( annotationList, defaults );
@@ -356,12 +336,9 @@
getAssociation( OneToOne.class, annotationList, defaults );
getAssociation( OneToMany.class, annotationList, defaults );
getAssociation( ManyToMany.class, annotationList, defaults );
- Annotation current = getSequenceGenerator( elementsForProperty, defaults );
- if ( current != null ) annotationList.add( current );
- current = getTableGenerator( elementsForProperty, defaults );
- if ( current != null ) annotationList.add( current );
- current = getAttributeOverrides( elementsForProperty, defaults );
- if ( current != null ) annotationList.add( current );
+ addIfNotNull(annotationList, getSequenceGenerator( elementsForProperty, defaults ));
+ addIfNotNull(annotationList, getTableGenerator( elementsForProperty, defaults ));
+ addIfNotNull(annotationList, getAttributeOverrides( elementsForProperty, defaults ));
}
processEventAnnotations(annotationList, defaults);
@@ -380,6 +357,16 @@
}
}
+ /**
+ * Addes the Annotation to the list (only if it's not null) and then returns it.
+ */
+ private Annotation addIfNotNull(List<Annotation> annotationList, Annotation element) {
+ if ( element != null ) {
+ annotationList.add( element );
+ }
+ return element;
+ }
+
//TODO mutualize the next 2 methods
private Annotation getTableGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
@@ -454,19 +441,19 @@
}
if ( ! eventElement && defaults.canUseJavaAnnotations() ) {
Annotation ann = getJavaAnnotation(PrePersist.class);
- if (ann != null) annotationList.add( ann );
+ addIfNotNull(annotationList, ann);
ann = getJavaAnnotation(PreRemove.class);
- if (ann != null) annotationList.add( ann );
+ addIfNotNull(annotationList, ann);
ann = getJavaAnnotation(PreUpdate.class);
- if (ann != null) annotationList.add( ann );
+ addIfNotNull(annotationList, ann);
ann = getJavaAnnotation(PostPersist.class);
- if (ann != null) annotationList.add( ann );
+ addIfNotNull(annotationList, ann);
ann = getJavaAnnotation(PostRemove.class);
- if (ann != null) annotationList.add( ann );
+ addIfNotNull(annotationList, ann);
ann = getJavaAnnotation(PostUpdate.class);
- if (ann != null) annotationList.add( ann );
+ addIfNotNull(annotationList, ann);
ann = getJavaAnnotation(PostLoad.class);
- if (ann != null) annotationList.add( ann );
+ addIfNotNull(annotationList, ann);
}
}
@@ -601,7 +588,7 @@
getJoinTable( annotationList, element, defaults );
buildJoinColumns( annotationList, element, defaults );
Annotation annotation = getPrimaryKeyJoinColumns( element, defaults );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
copyBooleanAttribute( ad, element, "optional" );
copyStringAttribute( ad, element, "mapped-by", false );
getOrderBy( annotationList, element, defaults );
@@ -614,71 +601,71 @@
if ( annotation != null ) {
annotationList.add( annotation );
annotation = overridesDefaultsInJoinTable( annotation, defaults );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( JoinColumn.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( JoinColumns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( PrimaryKeyJoinColumn.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( PrimaryKeyJoinColumns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( MapKey.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( OrderBy.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Lob.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Enumerated.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Temporal.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Column.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Columns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
}
else if ( isJavaAnnotationPresent( CollectionOfElements.class ) ) {
annotation = overridesDefaultsInJoinTable( getJavaAnnotation( CollectionOfElements.class ), defaults );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( JoinColumn.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( JoinColumns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( PrimaryKeyJoinColumn.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( PrimaryKeyJoinColumns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( MapKey.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( OrderBy.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Lob.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Enumerated.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Temporal.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Column.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Columns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
}
}
}
@@ -743,13 +730,13 @@
if ( annotation != null ) {
annotationList.add( annotation );
annotation = getJavaAnnotation( AttributeOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
}
}
}
@@ -773,7 +760,7 @@
for ( Element element : elementsForProperty ) {
if ( "version".equals( element.getName() ) ) {
Annotation annotation = buildColumns( element );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
getTemporal( annotationList, element );
AnnotationDescriptor basic = new AnnotationDescriptor( Version.class );
annotationList.add( AnnotationFactory.create( basic ) );
@@ -785,11 +772,11 @@
if ( annotation != null ) {
annotationList.add( annotation );
annotation = getJavaAnnotation( Column.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Columns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Temporal.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
}
}
}
@@ -798,7 +785,7 @@
for ( Element element : elementsForProperty ) {
if ( "basic".equals( element.getName() ) ) {
Annotation annotation = buildColumns( element );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
getTemporal( annotationList, element );
getLob( annotationList, element );
getEnumerated( annotationList, element );
@@ -811,25 +798,25 @@
if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) {
//no annotation presence constraint, basic is the default
Annotation annotation = getJavaAnnotation( Basic.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Lob.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Enumerated.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Temporal.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Column.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Columns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
}
}
@@ -875,9 +862,9 @@
if ( "embedded-id".equals( element.getName() ) ) {
if ( isProcessingId( defaults ) ) {
Annotation annotation = getAttributeOverrides( element, defaults );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getAssociationOverrides( element, defaults );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
AnnotationDescriptor ad = new AnnotationDescriptor( EmbeddedId.class );
annotationList.add( AnnotationFactory.create( ad ) );
}
@@ -903,25 +890,25 @@
if ( annotation != null ) {
annotationList.add( annotation );
annotation = getJavaAnnotation( Column.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Columns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( GeneratedValue.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Temporal.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( TableGenerator.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( SequenceGenerator.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
}
}
}
@@ -953,15 +940,15 @@
boolean processId = isProcessingId( defaults );
if ( processId ) {
Annotation annotation = buildColumns( element );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = buildGeneratedValue( element );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
getTemporal( annotationList, element );
//FIXME: fix the priority of xml over java for generator names
annotation = getTableGenerator( element, defaults );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getSequenceGenerator( element, defaults );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
AnnotationDescriptor id = new AnnotationDescriptor( Id.class );
annotationList.add( AnnotationFactory.create( id ) );
}
@@ -985,25 +972,25 @@
if ( annotation != null ) {
annotationList.add( annotation );
annotation = getJavaAnnotation( Column.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Columns.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( GeneratedValue.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( Temporal.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( TableGenerator.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( SequenceGenerator.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AttributeOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverride.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation( AssociationOverrides.class );
- if ( annotation != null ) annotationList.add( annotation );
+ addIfNotNull(annotationList, annotation);
}
}
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3ReflectionManager.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3ReflectionManager.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/EJB3ReflectionManager.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -22,10 +22,6 @@
private XMLContext xmlContext = new XMLContext();
private HashMap defaults = null;
-
- public EJB3ReflectionManager() {
- System.out.println("hello");
- }
public AnnotationReader buildAnnotationReader(AnnotatedElement annotatedElement) {
if ( xmlContext.hasContext() ) {
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -120,7 +120,6 @@
Class<T> beanClass, ResourceBundle resourceBundle, MessageInterpolator interpolator,
Map<XClass, ClassValidator> childClassValidators, ReflectionManager reflectionManager
) {
- // TODO
this.reflectionManager = reflectionManager != null ? reflectionManager : new EJB3ReflectionManager();
XClass beanXClass = this.reflectionManager.toXClass( beanClass );
this.beanClass = beanClass;
@@ -652,7 +651,6 @@
this.messageBundle = rb;
this.userInterpolator = (MessageInterpolator) ois.readObject();
this.defaultMessageBundle = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
- // TODO
reflectionManager = new EJB3ReflectionManager();
initValidator( reflectionManager.toXClass( beanClass ), new HashMap<XClass, ClassValidator>() );
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-25 11:41:38 UTC (rev 11101)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-25 13:22:47 UTC (rev 11102)
@@ -78,7 +78,6 @@
reflectionManager = ( (AnnotationConfiguration) cfg).getReflectionManager();
}
else {
- // TODO
reflectionManager = new EJB3ReflectionManager();
}
while ( classes.hasNext() ) {
17 years, 11 months
Hibernate SVN: r11101 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-25 06:41:38 -0500 (Thu, 25 Jan 2007)
New Revision: 11101
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java
Log:
HBX-862 - align propertyfile attribute usage to support override
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java 2007-01-25 11:36:34 UTC (rev 11100)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/ConfigurationTask.java 2007-01-25 11:41:38 UTC (rev 11101)
@@ -67,10 +67,6 @@
*/
protected void doConfiguration(Configuration configuration) {
validateParameters();
- Properties p = getProperties();
- if(p!=null) {
- configuration.setProperties(p);
- }
if (entityResolver != null) {
try {
@@ -99,6 +95,10 @@
if (configurationFile != null) configuration.configure( configurationFile );
addMappings(getFiles() );
+ Properties p = getProperties();
+ if(p!=null) {
+ configuration.setProperties(p);
+ }
}
protected Properties getProperties() {
17 years, 11 months