Author: epbernard
Date: 2007-01-17 18:26:34 -0500 (Wed, 17 Jan 2007)
New Revision: 11057
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java
Log:
ANN-502 skip validator.apply when apply_to_ddl = false
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-17
22:16:33 UTC (rev 11056)
+++
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-01-17
23:26:34 UTC (rev 11057)
@@ -310,17 +310,21 @@
buildUniqueKeyFromColumnNames( columnNames, table, keyName );
}
}
- for ( PersistentClass persistentClazz : (Collection<PersistentClass>)
classes.values() ) {
- //integrate the validate framework
- String className = persistentClazz.getClassName();
- if ( StringHelper.isNotEmpty( className ) ) {
- try {
- new ClassValidator( ReflectHelper.classForName( className ), null, null, null,
reflectionManager )
- .apply( persistentClazz );
+ boolean applyOnDdl = getProperties().getProperty(
org.hibernate.validator.Environment.APPLY_TO_DDL, "true" )
+ .equalsIgnoreCase( "true" );
+ if (applyOnDdl) {
+ for ( PersistentClass persistentClazz : (Collection<PersistentClass>)
classes.values() ) {
+ //integrate the validate framework
+ String className = persistentClazz.getClassName();
+ if ( StringHelper.isNotEmpty( className ) ) {
+ try {
+ new ClassValidator( ReflectHelper.classForName( className ), null, null, null,
reflectionManager )
+ .apply( persistentClazz );
+ }
+ catch (ClassNotFoundException e) {
+ //swallow them
+ }
}
- catch (ClassNotFoundException e) {
- //swallow them
- }
}
}
}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java 2007-01-17
22:16:33 UTC (rev 11056)
+++
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java 2007-01-17
23:26:34 UTC (rev 11057)
@@ -13,4 +13,9 @@
* Message interpolator class used. The same instance is shared across all
ClassValidators
*/
public static final String MESSAGE_INTERPOLATOR_CLASS =
"hibernate.validator.message_interpolator_class";
+
+ /**
+ * Apply DDL changes on Hibernate metamodel when using validator with Hibernate
Annotations
+ */
+ public static final String APPLY_TO_DDL = "hibernate.validator.apply_to_ddl";
}
Added:
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
(rev 0)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java 2007-01-17
23:26:34 UTC (rev 11057)
@@ -0,0 +1,49 @@
+//$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 validate framework integration with the Hibernate
+ * metadata binding
+ *
+ * @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 );
+ }
+}
Show replies by date