Hibernate SVN: r19312 - in core/trunk: core/src/main/java/org/hibernate/loader and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-04-28 00:32:00 -0400 (Wed, 28 Apr 2010)
New Revision: 19312
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyMaxFetchDepth0Test.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java
Log:
HHH-4991 ; ManyToMany table not joined due to max_fetch_depth parameter, results to SQL exceptions
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyMaxFetchDepth0Test.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyMaxFetchDepth0Test.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyMaxFetchDepth0Test.java 2010-04-28 04:32:00 UTC (rev 19312)
@@ -0,0 +1,48 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.test.annotations.manytomany;
+
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+
+/**
+ * Many to many tests using max_fetch_depth == 0
+ *
+ * @author Gail Badner
+ */
+@SuppressWarnings("unchecked")
+public class ManyToManyMaxFetchDepth0Test extends ManyToManyTest {
+
+ public ManyToManyMaxFetchDepth0Test(String x) {
+ super( x );
+ }
+
+ @Override
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.MAX_FETCH_DEPTH, "0" );
+ super.configure( cfg );
+ }
+}
\ No newline at end of file
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2010-04-27 23:55:49 UTC (rev 19311)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2010-04-28 04:32:00 UTC (rev 19312)
@@ -15,6 +15,7 @@
import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.criterion.Restrictions;
import org.hibernate.test.annotations.TestCase;
/**
@@ -80,6 +81,29 @@
s.close();
}
+ public void testCanUseCriteriaQuery() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ Store fnac = new Store();
+ fnac.setName( "Fnac" );
+ Supplier emi = new Supplier();
+ emi.setName( "Emmanuel" );
+ emi.setSuppStores( new HashSet<Store>() );
+ fnac.setSuppliers( new HashSet<Supplier>() );
+ fnac.getSuppliers().add( emi );
+ emi.getSuppStores().add( fnac );
+ s.persist( fnac );
+ tx.commit();
+ s.close();
+
+ s = openSession();
+ List result = s.createCriteria( Supplier.class ).createAlias( "suppStores", "s" ).add(
+ Restrictions.eq( "s.name", "Fnac" ) ).list();
+ assertEquals( 1, result.size() );
+ s.close();
+ }
public void testDefaultCompositePk() throws Exception {
Session s;
Transaction tx;
Modified: core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java 2010-04-27 23:55:49 UTC (rev 19311)
+++ core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java 2010-04-28 04:32:00 UTC (rev 19312)
@@ -473,7 +473,7 @@
* {@link JoinFragment#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
* @throws MappingException ??
*/
- private int getJoinType(
+ protected int getJoinType(
AssociationType associationType,
FetchMode config,
String path,
Modified: core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java 2010-04-27 23:55:49 UTC (rev 19311)
+++ core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java 2010-04-28 04:32:00 UTC (rev 19312)
@@ -170,7 +170,31 @@
}
}
}
-
+
+ protected int getJoinType(
+ AssociationType associationType,
+ FetchMode config,
+ String path,
+ String lhsTable,
+ String[] lhsColumns,
+ boolean nullable,
+ int currentDepth,
+ CascadeStyle cascadeStyle) throws MappingException {
+ return ( translator.isJoin( path ) ?
+ translator.getJoinType( path ) :
+ super.getJoinType(
+ associationType,
+ config,
+ path,
+ lhsTable,
+ lhsColumns,
+ nullable,
+ currentDepth,
+ cascadeStyle
+ )
+ );
+ }
+
private static boolean isDefaultFetchMode(FetchMode fetchMode) {
return fetchMode==null || fetchMode==FetchMode.DEFAULT;
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java 2010-04-27 23:55:49 UTC (rev 19311)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java 2010-04-28 04:32:00 UTC (rev 19312)
@@ -31,6 +31,7 @@
import org.hibernate.engine.EntityEntry;
import org.hibernate.impl.SessionImpl;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.proxy.HibernateProxy;
public class ParentChildTest extends LegacyTestCase {
@@ -207,7 +208,7 @@
s.close();
}
- public void testComplexCriteriaFailureExpected() throws Exception {
+ public void testComplexCriteria() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Baz baz = new Baz();
@@ -338,6 +339,109 @@
s.close();
}
+ public void testArrayHQL() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFooArray( new FooProxy[] { foo1 } );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.createQuery("from Baz b left join fetch b.fooArray").uniqueResult();
+ assertEquals( 1, baz.getFooArray().length );
+
+ t.rollback();
+ s.close();
+
+ }
+
+ public void testArrayCriteria() {
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFooArray( new FooProxy[] { foo1 } );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.createCriteria(Baz.class).createCriteria( "fooArray" ).uniqueResult();
+ assertEquals( 1, baz.getFooArray().length );
+
+ t.rollback();
+ s.close();
+ }
+
+ public void testLazyManyToOneHQL() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFoo( foo1 );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.createQuery("from Baz b").uniqueResult();
+ assertFalse( Hibernate.isInitialized( baz.getFoo() ) );
+ assertTrue( baz.getFoo() instanceof HibernateProxy );
+
+ t.rollback();
+ s.close();
+
+ }
+
+ public void testLazyManyToOneCriteria() {
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFoo( foo1 );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.createCriteria( Baz.class ).uniqueResult();
+ assertTrue( Hibernate.isInitialized( baz.getFoo() ) );
+ assertFalse( baz.getFoo() instanceof HibernateProxy );
+
+ t.rollback();
+ s.close();
+ }
+
+ public void testLazyManyToOneGet() {
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFoo( foo1 );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.get( Baz.class, baz.getCode() );
+ assertTrue( Hibernate.isInitialized( baz.getFoo() ) );
+ assertFalse( baz.getFoo() instanceof HibernateProxy );
+
+ t.rollback();
+ s.close();
+ }
+
public void testClassWhere() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
14 years, 10 months
Hibernate SVN: r19311 - in core/branches/Branch_3_5: core/src/main/java/org/hibernate/loader and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-04-27 19:55:49 -0400 (Tue, 27 Apr 2010)
New Revision: 19311
Added:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyMaxFetchDepth0Test.java
Modified:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/loader/JoinWalker.java
core/branches/Branch_3_5/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java
Log:
HHH-4991 ; ManyToMany table not joined due to max_fetch_depth parameter, results to SQL exceptions
Added: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyMaxFetchDepth0Test.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyMaxFetchDepth0Test.java (rev 0)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyMaxFetchDepth0Test.java 2010-04-27 23:55:49 UTC (rev 19311)
@@ -0,0 +1,48 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.test.annotations.manytomany;
+
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+
+/**
+ * Many to many tests using max_fetch_depth == 0
+ *
+ * @author Gail Badner
+ */
+@SuppressWarnings("unchecked")
+public class ManyToManyMaxFetchDepth0Test extends ManyToManyTest {
+
+ public ManyToManyMaxFetchDepth0Test(String x) {
+ super( x );
+ }
+
+ @Override
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.MAX_FETCH_DEPTH, "0" );
+ super.configure( cfg );
+ }
+}
\ No newline at end of file
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2010-04-27 22:51:17 UTC (rev 19310)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2010-04-27 23:55:49 UTC (rev 19311)
@@ -15,6 +15,7 @@
import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.criterion.Restrictions;
import org.hibernate.test.annotations.TestCase;
/**
@@ -80,6 +81,29 @@
s.close();
}
+ public void testCanUseCriteriaQuery() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ Store fnac = new Store();
+ fnac.setName( "Fnac" );
+ Supplier emi = new Supplier();
+ emi.setName( "Emmanuel" );
+ emi.setSuppStores( new HashSet<Store>() );
+ fnac.setSuppliers( new HashSet<Supplier>() );
+ fnac.getSuppliers().add( emi );
+ emi.getSuppStores().add( fnac );
+ s.persist( fnac );
+ tx.commit();
+ s.close();
+
+ s = openSession();
+ List result = s.createCriteria( Supplier.class ).createAlias( "suppStores", "s" ).add(
+ Restrictions.eq( "s.name", "Fnac" ) ).list();
+ assertEquals( 1, result.size() );
+ s.close();
+ }
public void testDefaultCompositePk() throws Exception {
Session s;
Transaction tx;
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/loader/JoinWalker.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/loader/JoinWalker.java 2010-04-27 22:51:17 UTC (rev 19310)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/loader/JoinWalker.java 2010-04-27 23:55:49 UTC (rev 19311)
@@ -473,7 +473,7 @@
* {@link JoinFragment#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
* @throws MappingException ??
*/
- private int getJoinType(
+ protected int getJoinType(
AssociationType associationType,
FetchMode config,
String path,
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java 2010-04-27 22:51:17 UTC (rev 19310)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java 2010-04-27 23:55:49 UTC (rev 19311)
@@ -170,7 +170,31 @@
}
}
}
-
+
+ protected int getJoinType(
+ AssociationType associationType,
+ FetchMode config,
+ String path,
+ String lhsTable,
+ String[] lhsColumns,
+ boolean nullable,
+ int currentDepth,
+ CascadeStyle cascadeStyle) throws MappingException {
+ return ( translator.isJoin( path ) ?
+ translator.getJoinType( path ) :
+ super.getJoinType(
+ associationType,
+ config,
+ path,
+ lhsTable,
+ lhsColumns,
+ nullable,
+ currentDepth,
+ cascadeStyle
+ )
+ );
+ }
+
private static boolean isDefaultFetchMode(FetchMode fetchMode) {
return fetchMode==null || fetchMode==FetchMode.DEFAULT;
}
Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java 2010-04-27 22:51:17 UTC (rev 19310)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java 2010-04-27 23:55:49 UTC (rev 19311)
@@ -31,6 +31,7 @@
import org.hibernate.engine.EntityEntry;
import org.hibernate.impl.SessionImpl;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.proxy.HibernateProxy;
public class ParentChildTest extends LegacyTestCase {
@@ -207,7 +208,7 @@
s.close();
}
- public void testComplexCriteriaFailureExpected() throws Exception {
+ public void testComplexCriteria() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Baz baz = new Baz();
@@ -338,6 +339,109 @@
s.close();
}
+ public void testArrayHQL() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFooArray( new FooProxy[] { foo1 } );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.createQuery("from Baz b left join fetch b.fooArray").uniqueResult();
+ assertEquals( 1, baz.getFooArray().length );
+
+ t.rollback();
+ s.close();
+
+ }
+
+ public void testArrayCriteria() {
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFooArray( new FooProxy[] { foo1 } );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.createCriteria(Baz.class).createCriteria( "fooArray" ).uniqueResult();
+ assertEquals( 1, baz.getFooArray().length );
+
+ t.rollback();
+ s.close();
+ }
+
+ public void testLazyManyToOneHQL() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFoo( foo1 );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.createQuery("from Baz b").uniqueResult();
+ assertFalse( Hibernate.isInitialized( baz.getFoo() ) );
+ assertTrue( baz.getFoo() instanceof HibernateProxy );
+
+ t.rollback();
+ s.close();
+
+ }
+
+ public void testLazyManyToOneCriteria() {
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFoo( foo1 );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.createCriteria( Baz.class ).uniqueResult();
+ assertTrue( Hibernate.isInitialized( baz.getFoo() ) );
+ assertFalse( baz.getFoo() instanceof HibernateProxy );
+
+ t.rollback();
+ s.close();
+ }
+
+ public void testLazyManyToOneGet() {
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Baz baz = new Baz();
+ s.save(baz);
+ Foo foo1 = new Foo();
+ s.save(foo1);
+ baz.setFoo( foo1 );
+
+ s.flush();
+ s.clear();
+
+ baz = ( Baz ) s.get( Baz.class, baz.getCode() );
+ assertTrue( Hibernate.isInitialized( baz.getFoo() ) );
+ assertFalse( baz.getFoo() instanceof HibernateProxy );
+
+ t.rollback();
+ s.close();
+ }
+
public void testClassWhere() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
14 years, 10 months
Hibernate SVN: r19310 - in validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap: checks and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-04-27 18:51:17 -0400 (Tue, 27 Apr 2010)
New Revision: 19310
Added:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AbstractConstraintCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckError.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintChecks.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/GetterCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/MultiValuedChecks.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/PrimitiveCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/SingleValuedChecks.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/StaticCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TypeCheck.java
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintAnnotationVisitor.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/MessagerAdapter.java
Log:
HV-316: extracted check methods from ConstraintAnnotationVisitor
* Created new IF ConstraintCheck
* Converted all check methods from the visitor into classes implementing ConstraintCheck
* Created class ConstraintCheckFactory, that knows which checks are required for which element/annotation combinations
* Visitor retrieves all checks to be executed from factory, executes them and reports any errors
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintAnnotationVisitor.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintAnnotationVisitor.java 2010-04-27 08:40:55 UTC (rev 19309)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintAnnotationVisitor.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -18,27 +18,31 @@
package org.hibernate.validator.ap;
import java.util.List;
+import java.util.Set;
+import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementVisitor;
import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
-import javax.lang.model.type.TypeKind;
-import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementKindVisitor6;
+import javax.tools.Diagnostic.Kind;
+import org.hibernate.validator.ap.checks.ConstraintCheck;
+import org.hibernate.validator.ap.checks.ConstraintCheckError;
+import org.hibernate.validator.ap.checks.ConstraintCheckFactory;
+import org.hibernate.validator.ap.checks.ConstraintChecks;
import org.hibernate.validator.ap.util.AnnotationApiHelper;
import org.hibernate.validator.ap.util.ConstraintHelper;
-import org.hibernate.validator.ap.util.ConstraintHelper.ConstraintCheckResult;
import org.hibernate.validator.ap.util.MessagerAdapter;
/**
- * An {@link ElementVisitor} that visits elements (type declarations, methods
- * and fields) annotated with constraint annotations from the Bean Validation
- * API.
+ * An {@link ElementVisitor} that visits annotated elements (type declarations,
+ * methods and fields) and applies different {@link ConstraintCheck}s to them.
+ * Each {@link ConstraintCheckError} occurred will be reported using the
+ * {@link Messager} API.
*
* @author Gunnar Morling.
*/
@@ -48,6 +52,11 @@
private final MessagerAdapter messager;
+ private ConstraintCheckFactory constraintCheckFactory;
+
+ //TODO GM: establish processor option for this
+ private boolean verbose = true;
+
public ConstraintAnnotationVisitor(ProcessingEnvironment processingEnvironment, MessagerAdapter messager) {
this.messager = messager;
@@ -59,317 +68,156 @@
constraintHelper = new ConstraintHelper(
processingEnvironment.getElementUtils(), processingEnvironment.getTypeUtils(), annotationApiHelper
);
+
+ constraintCheckFactory = new ConstraintCheckFactory( constraintHelper );
}
/**
* <p>
- * Checks whether the given mirrors representing one or more constraint annotations are correctly
- * specified at the given method. The following checks are performed:</p>
+ * Checks whether the given annotations are correctly specified at the given
+ * method. The following checks are performed:
+ * </p>
* <ul>
* <li>
- * The method must be a JavaBeans getter method (name starts with "is", "get" or "has",
- * method has return type, but no parameters).
- * </li>
+ * Constraint annotations may only be given at non-static, JavaBeans getter
+ * methods which's return type is supported by the constraints.</li>
* <li>
- * The return type of the method must be supported by the constraints.
- * </li>
- * <li>
- * The method must not be static.
- * </li>
+ * The <code>@Valid</code> annotation may only be given at non-static,
+ * non-primitive JavaBeans getter methods.</li>
* </ul>
*/
@Override
public Void visitExecutableAsMethod(ExecutableElement method,
List<AnnotationMirror> mirrors) {
- for ( AnnotationMirror oneAnnotationMirror : mirrors ) {
+ checkConstraints( method, mirrors );
-
- switch ( constraintHelper.getAnnotationType( oneAnnotationMirror ) ) {
-
- case CONSTRAINT_ANNOTATION:
- checkConstraintAtMethod( method, oneAnnotationMirror );
- break;
-
- case MULTI_VALUED_CONSTRAINT_ANNOTATION:
- for ( AnnotationMirror onePartOfMultiValuedConstraint :
- constraintHelper.getPartsOfMultiValuedConstraint( oneAnnotationMirror ) ) {
-
- checkConstraintAtMethod( method, onePartOfMultiValuedConstraint );
- }
- break;
-
- case GRAPH_VALIDATION_ANNOTATION:
- checkGraphValidationAnnotationAtMethod( method, oneAnnotationMirror );
- }
-
- }
-
return null;
}
/**
* <p>
- * Checks whether the given mirrors representing one or more constraint annotations are correctly
- * specified at the given field. The following checks are performed:</p>
+ * Checks whether the given annotations are correctly specified at the given
+ * field. The following checks are performed:
+ * </p>
* <ul>
* <li>
- * The type of the field must be supported by the constraints.
- * </li>
+ * Constraint annotations may only be given at non-static fields which's
+ * type is supported by the constraints.</li>
* <li>
- * The field must not be static.
- * </li>
+ * The <code>@Valid</code> annotation may only be given at non-static,
+ * non-primitive fields.</li>
* </ul>
*/
@Override
public Void visitVariableAsField(VariableElement annotatedField, List<AnnotationMirror> mirrors) {
- for ( AnnotationMirror oneAnnotationMirror : mirrors ) {
+ checkConstraints( annotatedField, mirrors );
- switch ( constraintHelper.getAnnotationType( oneAnnotationMirror ) ) {
-
- case CONSTRAINT_ANNOTATION:
- checkConstraintAtField( annotatedField, oneAnnotationMirror );
- break;
-
- case MULTI_VALUED_CONSTRAINT_ANNOTATION:
- for ( AnnotationMirror onePartOfMultiValuedConstraint :
- constraintHelper.getPartsOfMultiValuedConstraint( oneAnnotationMirror ) ) {
-
- checkConstraintAtField( annotatedField, onePartOfMultiValuedConstraint );
- }
- break;
-
- case GRAPH_VALIDATION_ANNOTATION:
- checkGraphValidationAnnotationAtField( annotatedField, oneAnnotationMirror );
- }
- }
-
return null;
}
/**
* <p>
- * Checks whether the given mirrors representing one or more constraint
- * annotations are correctly specified at the given annotation type
- * declaration. The only annotation types allowed to be annotated with a
- * constraint annotation are other (composed) constraint annotation type
- * declarations.
+ * Checks whether the given annotations are correctly specified at the given
+ * annotation type declaration. The following checks are performed:
* </p>
+ * <ul>
+ * <li>
+ * The only annotation types allowed to be annotated with other constraint
+ * annotations are composed constraint annotation type declarations.</li>
+ * </ul>
*/
@Override
public Void visitTypeAsAnnotationType(TypeElement annotationType,
List<AnnotationMirror> mirrors) {
- for ( AnnotationMirror oneAnnotationMirror : mirrors ) {
+ checkConstraints( annotationType, mirrors );
- switch ( constraintHelper.getAnnotationType( oneAnnotationMirror ) ) {
-
- case CONSTRAINT_ANNOTATION:
- checkConstraintAtAnnotationType( annotationType, oneAnnotationMirror );
- break;
-
- case MULTI_VALUED_CONSTRAINT_ANNOTATION:
- for ( AnnotationMirror onePartOfMultiValuedConstraint :
- constraintHelper.getPartsOfMultiValuedConstraint( oneAnnotationMirror ) ) {
-
- checkConstraintAtAnnotationType( annotationType, onePartOfMultiValuedConstraint );
- }
- break;
- }
- }
-
return null;
}
+ /**
+ * <p>
+ * Checks whether the given annotations are correctly specified at the given
+ * class type declaration. The following checks are performed:
+ * </p>
+ * <ul>
+ * <li>
+ * Constraint annotations may at types supported by the constraints.</li>
+ * <li>
+ * </ul>
+ */
@Override
public Void visitTypeAsClass(TypeElement e, List<AnnotationMirror> p) {
- return visitClassOrInterfaceOrEnumType( e, p );
+
+ checkConstraints( e, p );
+ return null;
}
+ /**
+ * <p>
+ * Checks whether the given annotations are correctly specified at the given
+ * enum type declaration. The following checks are performed:
+ * </p>
+ * <ul>
+ * <li>
+ * Constraint annotations may at types supported by the constraints.</li>
+ * <li>
+ * </ul>
+ */
@Override
public Void visitTypeAsEnum(TypeElement e, List<AnnotationMirror> p) {
- return visitClassOrInterfaceOrEnumType( e, p );
+
+ checkConstraints( e, p );
+ return null;
}
+ /**
+ * <p>
+ * Checks whether the given annotations are correctly specified at the given
+ * interface type declaration. The following checks are performed:
+ * </p>
+ * <ul>
+ * <li>
+ * Constraint annotations may at types supported by the constraints.</li>
+ * <li>
+ * </ul>
+ */
@Override
public Void visitTypeAsInterface(TypeElement e, List<AnnotationMirror> p) {
- return visitClassOrInterfaceOrEnumType( e, p );
+
+ checkConstraints( e, p );
+ return null;
}
- // ==================================
- // private API below
- // ==================================
+ /**
+ * Retrieves the checks required for the given element and annotations,
+ * executes them and reports all occurred errors.
+ *
+ * @param annotatedElement The element to check.
+ * @param mirrors The annotations to check.
+ */
+ private void checkConstraints(Element annotatedElement, List<AnnotationMirror> mirrors) {
- private Void visitClassOrInterfaceOrEnumType(TypeElement annotatedType,
- List<AnnotationMirror> mirrors) {
-
for ( AnnotationMirror oneAnnotationMirror : mirrors ) {
- switch ( constraintHelper.getAnnotationType( oneAnnotationMirror ) ) {
+ try {
- case CONSTRAINT_ANNOTATION:
- checkConstraintAtType( annotatedType, oneAnnotationMirror );
- break;
-
- case MULTI_VALUED_CONSTRAINT_ANNOTATION:
- for ( AnnotationMirror onePartOfMultiValuedConstraint :
- constraintHelper.getPartsOfMultiValuedConstraint( oneAnnotationMirror ) ) {
- checkConstraintAtType( annotatedType, onePartOfMultiValuedConstraint );
- }
- break;
+ ConstraintChecks constraintChecks = constraintCheckFactory.getConstraintChecks(
+ annotatedElement, oneAnnotationMirror
+ );
+ Set<ConstraintCheckError> errors = constraintChecks.execute( annotatedElement, oneAnnotationMirror );
+ messager.reportErrors( errors );
}
+ catch ( Exception e ) {
+ if ( verbose ) {
+ messager.getDelegate()
+ .printMessage( Kind.NOTE, e.getMessage(), annotatedElement, oneAnnotationMirror );
+ }
+ }
}
-
- return null;
}
- private void checkConstraintAtType(TypeElement annotatedType, AnnotationMirror mirror) {
-
- if ( constraintHelper.checkConstraint(
- mirror.getAnnotationType(), annotatedType.asType()
- ) != ConstraintCheckResult.ALLOWED ) {
-
- messager.reportError(
- annotatedType, mirror, "NOT_SUPPORTED_TYPE",
- mirror.getAnnotationType().asElement().getSimpleName()
- );
- }
- }
-
- private void checkConstraintAtField(VariableElement annotatedField, AnnotationMirror annotationMirror) {
-
- if ( isStaticElement( annotatedField ) ) {
-
- messager.reportError( annotatedField, annotationMirror, "STATIC_FIELDS_MAY_NOT_BE_ANNOTATED" );
-
- return;
- }
-
- if ( constraintHelper.checkConstraint(
- annotationMirror.getAnnotationType(), annotatedField.asType()
- ) != ConstraintCheckResult.ALLOWED ) {
-
- messager.reportError(
- annotatedField, annotationMirror, "NOT_SUPPORTED_TYPE",
- annotationMirror.getAnnotationType().asElement().getSimpleName()
- );
- }
- }
-
- private void checkConstraintAtMethod(ExecutableElement method, AnnotationMirror mirror) {
-
- if ( !isGetterMethod( method ) ) {
-
- messager.reportError( method, mirror, "ONLY_GETTERS_MAY_BE_ANNOTATED" );
-
- return;
- }
-
- if ( isStaticElement( method ) ) {
-
- messager.reportError( method, mirror, "STATIC_METHODS_MAY_NOT_BE_ANNOTATED" );
-
- return;
- }
-
- if ( constraintHelper.checkConstraint(
- mirror.getAnnotationType(), method.getReturnType()
- ) != ConstraintCheckResult.ALLOWED ) {
-
- messager.reportError(
- method, mirror, "NOT_SUPPORTED_RETURN_TYPE",
- mirror.getAnnotationType().asElement().getSimpleName()
- );
- }
- }
-
- private void checkConstraintAtAnnotationType(TypeElement annotationType, AnnotationMirror annotationMirror) {
-
- if ( !constraintHelper.isConstraintAnnotation( annotationType ) ) {
- messager.reportError( annotationType, annotationMirror, "ONLY_CONSTRAINT_ANNOTATIONS_MAY_BE_ANNOTATED" );
- }
-
- }
-
- private void checkGraphValidationAnnotationAtField(
- VariableElement annotatedField, AnnotationMirror annotationMirror) {
-
- if ( isStaticElement( annotatedField ) ) {
-
- messager.reportError(
- annotatedField, annotationMirror,
- "STATIC_FIELDS_MAY_NOT_BE_ANNOTATED"
- );
-
- return;
- }
-
- if ( isPrimitiveType( annotatedField.asType() ) ) {
-
- messager.reportError(
- annotatedField, annotationMirror,
- "ATVALID_NOT_ALLOWED_AT_PRIMITIVE_FIELD"
- );
- }
- }
-
- private void checkGraphValidationAnnotationAtMethod(
- ExecutableElement method, AnnotationMirror annotationMirror) {
-
- if ( !isGetterMethod( method ) ) {
-
- messager.reportError(
- method, annotationMirror,
- "ONLY_GETTERS_MAY_BE_ANNOTATED"
- );
-
- return;
- }
-
- if ( isStaticElement( method ) ) {
-
- messager.reportError(
- method, annotationMirror,
- "STATIC_METHODS_MAY_NOT_BE_ANNOTATED"
- );
-
- return;
- }
-
- if ( isPrimitiveType( method.getReturnType() ) ) {
-
- messager.reportError(
- method, annotationMirror,
- "ATVALID_NOT_ALLOWED_AT_METHOD_RETURNING_PRIMITIVE_TYPE"
- );
- }
- }
-
- private boolean isGetterMethod(ExecutableElement method) {
- return isJavaBeanGetterName( method.getSimpleName().toString() )
- && !hasParameters( method ) && hasReturnValue( method );
- }
-
- private boolean hasReturnValue(ExecutableElement method) {
- return method.getReturnType().getKind() != TypeKind.VOID;
- }
-
- private boolean hasParameters(ExecutableElement method) {
- return !method.getParameters().isEmpty();
- }
-
- private boolean isJavaBeanGetterName(String methodName) {
- return methodName.startsWith( "is" ) || methodName.startsWith( "has" ) || methodName.startsWith( "get" );
- }
-
- private boolean isStaticElement(Element element) {
- return element.getModifiers().contains( Modifier.STATIC );
- }
-
- private boolean isPrimitiveType(TypeMirror typeMirror) {
- return typeMirror.getKind().isPrimitive();
- }
-
}
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AbstractConstraintCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AbstractConstraintCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AbstractConstraintCheck.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,67 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+
+/**
+ * <p>
+ * Abstract base class for {@link ConstraintCheck} implementations. Concrete
+ * checks should only override those check methods applicable for their
+ * supported element types.
+ * </p>
+ * <p>
+ * For instance would a check ensuring that constraint annotations are only
+ * given at non-static fields or methods only override <code>checkField()</code>
+ * and <code>checkMethod()</code>.
+ * </p>
+ * <p>
+ * All check methods not overridden will return an empty list.
+ * </p>
+ *
+ * @author Gunnar Morling
+ */
+public class AbstractConstraintCheck implements ConstraintCheck {
+
+ public Set<ConstraintCheckError> checkField(VariableElement element, AnnotationMirror annotation) {
+
+ return Collections.emptySet();
+ }
+
+ public Set<ConstraintCheckError> checkMethod(ExecutableElement element, AnnotationMirror annotation) {
+
+ return Collections.emptySet();
+ }
+
+ public Set<ConstraintCheckError> checkAnnotationType(TypeElement element,
+ AnnotationMirror annotation) {
+
+ return Collections.emptySet();
+ }
+
+ public Set<ConstraintCheckError> checkNonAnnotationType(
+ TypeElement element, AnnotationMirror annotation) {
+
+ return Collections.emptySet();
+ }
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AbstractConstraintCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeCheck.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,60 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.TypeElement;
+
+import org.hibernate.validator.ap.util.CollectionHelper;
+import org.hibernate.validator.ap.util.ConstraintHelper;
+
+/**
+ * Checks, that only constraint annotation types are annotated with other
+ * constraint annotations ("constraint composition"), but not non-constraint
+ * annotations.
+ *
+ * @author Gunnar Morling
+ */
+public class AnnotationTypeCheck extends AbstractConstraintCheck {
+
+ private final ConstraintHelper constraintHelper;
+
+ public AnnotationTypeCheck(ConstraintHelper constraintHelper) {
+ this.constraintHelper = constraintHelper;
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkAnnotationType(TypeElement element,
+ AnnotationMirror annotation) {
+
+ if ( !constraintHelper.isConstraintAnnotation( element ) ) {
+
+ return CollectionHelper.asSet(
+ new ConstraintCheckError(
+ element, annotation, "ONLY_CONSTRAINT_ANNOTATIONS_MAY_BE_ANNOTATED"
+ )
+ );
+ }
+
+ return Collections.emptySet();
+ }
+
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheck.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,99 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+
+/**
+ * <p>
+ * Implementations represent checks, which determine whether a given constraint
+ * annotation is allowed at a given element.
+ * </p>
+ * <p>
+ * Implementations should be derived from {@link AbstractConstraintCheck} in
+ * order to implement only those check methods applicable for the element kinds
+ * supported by the check.
+ * </p>
+ *
+ * @author Gunnar Morling
+ */
+public interface ConstraintCheck {
+
+ /**
+ * Checks, whether the given annotation is allowed at the given field.
+ *
+ * @param element An annotated field.
+ * @param annotation An annotation at that field.
+ *
+ * @return A set with errors, that describe, why the given annotation is
+ * not allowed at the given element. In case no errors occur (the
+ * given annotation is allowed at the given element), an empty set
+ * must be returned.
+ */
+ Set<ConstraintCheckError> checkField(VariableElement element,
+ AnnotationMirror annotation);
+
+ /**
+ * Checks, whether the given annotation is allowed at the given method.
+ *
+ * @param element An annotated method.
+ * @param annotation An annotation at that method.
+ *
+ * @return A set with errors, that describe, why the given annotation is
+ * not allowed at the given element. In case no errors occur (the
+ * given annotation is allowed at the given element), an empty set
+ * must be returned.
+ */
+ Set<ConstraintCheckError> checkMethod(ExecutableElement element,
+ AnnotationMirror annotation);
+
+ /**
+ * Checks, whether the given annotation is allowed at the given annotation
+ * type declaration.
+ *
+ * @param element An annotated annotation type declaration.
+ * @param annotation An annotation at that annotation type.
+ *
+ * @return A set with errors, that describe, why the given annotation is
+ * not allowed at the given element. In case no errors occur (the
+ * given annotation is allowed at the given element), an empty set
+ * must be returned.
+ */
+ Set<ConstraintCheckError> checkAnnotationType(TypeElement element,
+ AnnotationMirror annotation);
+
+ /**
+ * Checks, whether the given annotation is allowed at the given type
+ * declaration (class, interface, enum).
+ *
+ * @param element An annotated type declaration.
+ * @param annotation An annotation at that type.
+ *
+ * @return A set with errors, that describe, why the given annotation is
+ * not allowed at the given element. In case no errors occur (the
+ * given annotation is allowed at the given element), an empty set
+ * must be returned.
+ */
+ Set<ConstraintCheckError> checkNonAnnotationType(TypeElement element,
+ AnnotationMirror annotation);
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckError.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckError.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckError.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,143 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.text.MessageFormat;
+import java.util.Arrays;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+
+/**
+ * The result of the execution of a {@link ConstraintCheck}. Comprises
+ * information about the location at which the error occurred and a message
+ * describing the occured error.
+ *
+ * @author Gunnar Morling
+ */
+public class ConstraintCheckError {
+
+ private final Element element;
+
+ private final AnnotationMirror annotationMirror;
+
+ private final String messageKey;
+
+ private final Object[] messageParameters;
+
+ /**
+ * Creates a new ConstraintCheckError.
+ *
+ * @param element The element at which the error occurred.
+ * @param annotationMirror The annotation that causes the error.
+ * @param messageKey A key for retrieving an error message template from the bundle
+ * <p/>
+ * <code>org.hibernate.validator.ap.ValidationProcessorMessages.</code>
+ * @param messageParameters An array with values to put into the error message template
+ * using {@link MessageFormat}. The number of elements must match
+ * the number of place holders in the message template.
+ */
+ public ConstraintCheckError(Element element,
+ AnnotationMirror annotationMirror, String messageKey, Object... messageParameters) {
+
+ this.element = element;
+ this.annotationMirror = annotationMirror;
+ this.messageKey = messageKey;
+ this.messageParameters = messageParameters;
+ }
+
+ public Element getElement() {
+ return element;
+ }
+
+ public AnnotationMirror getAnnotationMirror() {
+ return annotationMirror;
+ }
+
+ public String getMessageKey() {
+ return messageKey;
+ }
+
+ public Object[] getMessageParameters() {
+ return messageParameters;
+ }
+
+ @Override
+ public String toString() {
+ return "ConstraintCheckError [annotationMirror=" + annotationMirror
+ + ", element=" + element + ", messageKey=" + messageKey
+ + ", messageParameters=" + Arrays.toString( messageParameters )
+ + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime
+ * result
+ + ( ( annotationMirror == null ) ? 0 : annotationMirror.hashCode() );
+ result = prime * result + ( ( element == null ) ? 0 : element.hashCode() );
+ result = prime * result
+ + ( ( messageKey == null ) ? 0 : messageKey.hashCode() );
+ result = prime * result + Arrays.hashCode( messageParameters );
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if ( this == obj ) {
+ return true;
+ }
+ if ( obj == null ) {
+ return false;
+ }
+ if ( getClass() != obj.getClass() ) {
+ return false;
+ }
+ ConstraintCheckError other = ( ConstraintCheckError ) obj;
+ if ( annotationMirror == null ) {
+ if ( other.annotationMirror != null ) {
+ return false;
+ }
+ }
+ else if ( !annotationMirror.equals( other.annotationMirror ) ) {
+ return false;
+ }
+ if ( element == null ) {
+ if ( other.element != null ) {
+ return false;
+ }
+ }
+ else if ( !element.equals( other.element ) ) {
+ return false;
+ }
+ if ( messageKey == null ) {
+ if ( other.messageKey != null ) {
+ return false;
+ }
+ }
+ else if ( !messageKey.equals( other.messageKey ) ) {
+ return false;
+ }
+ if ( !Arrays.equals( messageParameters, other.messageParameters ) ) {
+ return false;
+ }
+ return true;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckError.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,150 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Map;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+
+import org.hibernate.validator.ap.util.CollectionHelper;
+import org.hibernate.validator.ap.util.ConstraintHelper;
+import org.hibernate.validator.ap.util.ConstraintHelper.AnnotationType;
+
+/**
+ * A factory in charge of determining the {@link ConstraintCheck}s required for
+ * the validation of annotations at given elements.
+ *
+ * @author Gunnar Morling
+ */
+public class ConstraintCheckFactory {
+
+ /**
+ * Holds the checks to be executed for field elements.
+ */
+ private final Map<AnnotationType, ConstraintChecks> fieldChecks;
+
+ /**
+ * Holds the checks to be executed for method elements keyed.
+ */
+ private final Map<AnnotationType, ConstraintChecks> methodChecks;
+
+ /**
+ * Holds the checks to be executed for annotation type declarations.
+ */
+ private final Map<AnnotationType, ConstraintChecks> annotationTypeChecks;
+
+ /**
+ * Holds the checks to be executed for class/interface/enum declarations.
+ */
+ private final Map<AnnotationType, ConstraintChecks> nonAnnotationTypeChecks;
+
+ private ConstraintHelper constraintHelper;
+
+ private final static SingleValuedChecks NULL_CHECKS = new SingleValuedChecks();
+
+ public ConstraintCheckFactory(ConstraintHelper constraintHelper) {
+
+ this.constraintHelper = constraintHelper;
+
+ fieldChecks = CollectionHelper.newHashMap();
+ fieldChecks.put(
+ AnnotationType.CONSTRAINT_ANNOTATION,
+ new SingleValuedChecks( new StaticCheck(), new TypeCheck( constraintHelper ) )
+ );
+ fieldChecks.put(
+ AnnotationType.MULTI_VALUED_CONSTRAINT_ANNOTATION,
+ new MultiValuedChecks( constraintHelper, new StaticCheck(), new TypeCheck( constraintHelper ) )
+ );
+ fieldChecks.put(
+ AnnotationType.GRAPH_VALIDATION_ANNOTATION,
+ new SingleValuedChecks( new StaticCheck(), new PrimitiveCheck() )
+ );
+ fieldChecks.put( AnnotationType.NO_CONSTRAINT_ANNOTATION, NULL_CHECKS );
+
+ methodChecks = CollectionHelper.newHashMap();
+ methodChecks.put(
+ AnnotationType.CONSTRAINT_ANNOTATION,
+ new SingleValuedChecks( new GetterCheck(), new StaticCheck(), new TypeCheck( constraintHelper ) )
+ );
+ methodChecks.put(
+ AnnotationType.MULTI_VALUED_CONSTRAINT_ANNOTATION, new MultiValuedChecks(
+ constraintHelper, new GetterCheck(), new StaticCheck(), new TypeCheck( constraintHelper )
+ )
+ );
+ methodChecks.put(
+ AnnotationType.GRAPH_VALIDATION_ANNOTATION,
+ new SingleValuedChecks( new GetterCheck(), new StaticCheck(), new PrimitiveCheck() )
+ );
+ methodChecks.put( AnnotationType.NO_CONSTRAINT_ANNOTATION, NULL_CHECKS );
+
+ annotationTypeChecks = CollectionHelper.newHashMap();
+ annotationTypeChecks.put(
+ AnnotationType.CONSTRAINT_ANNOTATION,
+ new SingleValuedChecks( new AnnotationTypeCheck( constraintHelper ) )
+ );
+ annotationTypeChecks.put(
+ AnnotationType.MULTI_VALUED_CONSTRAINT_ANNOTATION,
+ new MultiValuedChecks( constraintHelper, new AnnotationTypeCheck( constraintHelper ) )
+ );
+ annotationTypeChecks.put( AnnotationType.NO_CONSTRAINT_ANNOTATION, NULL_CHECKS );
+
+ nonAnnotationTypeChecks = CollectionHelper.newHashMap();
+ nonAnnotationTypeChecks.put(
+ AnnotationType.CONSTRAINT_ANNOTATION, new SingleValuedChecks( new TypeCheck( constraintHelper ) )
+ );
+ nonAnnotationTypeChecks.put(
+ AnnotationType.MULTI_VALUED_CONSTRAINT_ANNOTATION,
+ new MultiValuedChecks( constraintHelper, new TypeCheck( constraintHelper ) )
+ );
+ nonAnnotationTypeChecks.put( AnnotationType.NO_CONSTRAINT_ANNOTATION, NULL_CHECKS );
+ }
+
+ /**
+ * Returns those checks that have to be performed to validate the given
+ * annotation at the given element. In case no checks have to be performed
+ * (e.g. because the given annotation is no constraint annotation) an empty
+ * {@link ConstraintChecks} instance will be returned. It's therefore always
+ * safe to operate on the returned object.
+ *
+ * @param annotatedElement An annotated element, e.g. a type declaration or a method.
+ * @param annotation An annotation.
+ *
+ * @return The checks to be performed to validate the given annotation at
+ * the given element.
+ */
+ public ConstraintChecks getConstraintChecks(Element annotatedElement, AnnotationMirror annotation) {
+
+ AnnotationType annotationType = constraintHelper.getAnnotationType( annotation );
+
+ switch ( annotatedElement.getKind() ) {
+ case FIELD:
+ return fieldChecks.get( annotationType );
+ case METHOD:
+ return methodChecks.get( annotationType );
+ case ANNOTATION_TYPE:
+ return annotationTypeChecks.get( annotationType );
+ case CLASS:
+ case INTERFACE:
+ case ENUM:
+ return nonAnnotationTypeChecks.get( annotationType );
+ default:
+ return NULL_CHECKS;
+ }
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintCheckFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintChecks.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintChecks.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintChecks.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,45 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+
+/**
+ * Represents an ordered set of {@link ConstraintCheck}s with the ability
+ * to execute these checks against given elements and their annotations.
+ *
+ * @author Gunnar Morling
+ */
+public interface ConstraintChecks {
+
+ /**
+ * Executes the checks contained within this set against the given element
+ * and annotation.
+ *
+ * @param element An annotated element.
+ * @param annotation The annotation to check.
+ *
+ * @return A set with errors. Will be empty in case all checks passed
+ * successfully.
+ */
+ Set<ConstraintCheckError> execute(Element element,
+ AnnotationMirror annotation);
+
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/ConstraintChecks.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/GetterCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/GetterCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/GetterCheck.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,69 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.type.TypeKind;
+
+import org.hibernate.validator.ap.util.CollectionHelper;
+
+/**
+ * Checks whether a given element is a valid getter method.
+ *
+ * @author Gunnar Morling
+ */
+public class GetterCheck extends AbstractConstraintCheck {
+
+ @Override
+ public Set<ConstraintCheckError> checkMethod(ExecutableElement element,
+ AnnotationMirror annotation) {
+
+ if ( !isGetterMethod( element ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError(
+ element, annotation, "ONLY_GETTERS_MAY_BE_ANNOTATED"
+ )
+ );
+ }
+
+ return Collections.emptySet();
+ }
+
+ private boolean isGetterMethod(ExecutableElement method) {
+
+ return isJavaBeanGetterName( method.getSimpleName().toString() )
+ && !hasParameters( method ) && hasReturnValue( method );
+ }
+
+ private boolean hasReturnValue(ExecutableElement method) {
+ return method.getReturnType().getKind() != TypeKind.VOID;
+ }
+
+ private boolean hasParameters(ExecutableElement method) {
+ return !method.getParameters().isEmpty();
+ }
+
+ private boolean isJavaBeanGetterName(String methodName) {
+ return methodName.startsWith( "is" ) || methodName.startsWith( "has" ) || methodName.startsWith( "get" );
+ }
+
+}
+
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/GetterCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/MultiValuedChecks.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/MultiValuedChecks.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/MultiValuedChecks.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,67 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.checks;
+
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+
+import org.hibernate.validator.ap.util.CollectionHelper;
+import org.hibernate.validator.ap.util.ConstraintHelper;
+
+/**
+ * A {@link ConstraintChecks} implementation, that executed the contained checks
+ * against all parts of given multi-valued annotations.
+ *
+ * @author Gunnar Morling
+ */
+public class MultiValuedChecks implements ConstraintChecks {
+
+ private final ConstraintHelper constraintHelper;
+
+ private final SingleValuedChecks delegate;
+
+ /**
+ * Creates a new MultiValuedChecks.
+ *
+ * @param constraintHelper Helper for handling multi-valued constraints.
+ * @param checks The checks to execute.
+ */
+ public MultiValuedChecks(ConstraintHelper constraintHelper,
+ ConstraintCheck... checks) {
+
+ this.constraintHelper = constraintHelper;
+ this.delegate = new SingleValuedChecks( checks );
+ }
+
+ public Set<ConstraintCheckError> execute(Element element,
+ AnnotationMirror annotation) {
+
+ Set<ConstraintCheckError> theValue = CollectionHelper.newHashSet();
+
+ //execute the checks on each element of the multi-valued constraint
+ for ( AnnotationMirror onePartOfMultiValuedConstraint :
+ constraintHelper.getPartsOfMultiValuedConstraint( annotation ) ) {
+
+ theValue.addAll( delegate.execute( element, onePartOfMultiValuedConstraint ) );
+ }
+
+ return theValue;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/MultiValuedChecks.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/PrimitiveCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/PrimitiveCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/PrimitiveCheck.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,69 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeMirror;
+
+import org.hibernate.validator.ap.util.CollectionHelper;
+
+/**
+ * Validates that the given element is not of a primitive type. Applies to
+ * fields and methods (the return type is evaluated).
+ *
+ * @author Gunnar Morling
+ */
+public class PrimitiveCheck extends AbstractConstraintCheck {
+
+ @Override
+ public Set<ConstraintCheckError> checkField(VariableElement element,
+ AnnotationMirror annotation) {
+
+ return checkInternal( element, annotation, element.asType(), "ATVALID_NOT_ALLOWED_AT_PRIMITIVE_FIELD" );
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkMethod(ExecutableElement element,
+ AnnotationMirror annotation) {
+
+ return checkInternal(
+ element, annotation, element.getReturnType(), "ATVALID_NOT_ALLOWED_AT_METHOD_RETURNING_PRIMITIVE_TYPE"
+ );
+ }
+
+ private Set<ConstraintCheckError> checkInternal(Element element,
+ AnnotationMirror annotation, TypeMirror type, String messageKey) {
+
+ if ( type.getKind().isPrimitive() ) {
+
+ return CollectionHelper.asSet(
+ new ConstraintCheckError(
+ element, annotation, messageKey
+ )
+ );
+ }
+
+ return Collections.emptySet();
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/PrimitiveCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/SingleValuedChecks.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/SingleValuedChecks.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/SingleValuedChecks.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,92 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+
+import org.hibernate.validator.ap.util.CollectionHelper;
+
+/**
+ * A {@link ConstraintChecks} implementation that simply executes all
+ * contained checks against given elements and annotations.
+ *
+ * @author Gunnar Morling
+ */
+public class SingleValuedChecks implements ConstraintChecks {
+
+ //TODO GM: the "ordered set" character is currently ensured by adding
+ //each check only once in ConstraintCheckFactory. Should this be a real set?
+ private final List<ConstraintCheck> checks;
+
+ /**
+ * Creates a new SingleValuedChecks.
+ *
+ * @param checks The checks to execute.
+ */
+ public SingleValuedChecks(ConstraintCheck... checks) {
+
+ if ( checks == null ) {
+ this.checks = Collections.emptyList();
+ }
+ else {
+ this.checks = Arrays.asList( checks );
+ }
+ }
+
+ public Set<ConstraintCheckError> execute(Element element, AnnotationMirror annotation) {
+
+ Set<ConstraintCheckError> theValue = CollectionHelper.newHashSet();
+
+ //for each check execute the check method appropriate for the kind of
+ //the given element
+ for ( ConstraintCheck oneCheck : checks ) {
+
+ if ( element.getKind() == ElementKind.FIELD ) {
+ theValue.addAll( oneCheck.checkField( ( VariableElement ) element, annotation ) );
+ }
+ else if ( element.getKind() == ElementKind.METHOD ) {
+ theValue.addAll( oneCheck.checkMethod( ( ExecutableElement ) element, annotation ) );
+ }
+ else if ( element.getKind() == ElementKind.ANNOTATION_TYPE ) {
+ theValue.addAll( oneCheck.checkAnnotationType( ( TypeElement ) element, annotation ) );
+ }
+ else if (
+ element.getKind() == ElementKind.CLASS ||
+ element.getKind() == ElementKind.INTERFACE ||
+ element.getKind() == ElementKind.ENUM ) {
+
+ theValue.addAll( oneCheck.checkNonAnnotationType( ( TypeElement ) element, annotation ) );
+ }
+
+ if ( !theValue.isEmpty() ) {
+ return theValue;
+ }
+ }
+
+ return theValue;
+ }
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/SingleValuedChecks.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/StaticCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/StaticCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/StaticCheck.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,64 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.VariableElement;
+
+import org.hibernate.validator.ap.util.CollectionHelper;
+
+/**
+ * Checks, that the given element is not a static element. Applies to fields
+ * and methods.
+ *
+ * @author Gunnar Morling
+ */
+public class StaticCheck extends AbstractConstraintCheck {
+
+ @Override
+ public Set<ConstraintCheckError> checkField(VariableElement element, AnnotationMirror annotation) {
+
+ return checkInternal( element, annotation, "STATIC_FIELDS_MAY_NOT_BE_ANNOTATED" );
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkMethod(ExecutableElement element, AnnotationMirror annotation) {
+
+ return checkInternal( element, annotation, "STATIC_METHODS_MAY_NOT_BE_ANNOTATED" );
+ }
+
+ private Set<ConstraintCheckError> checkInternal(Element element,
+ AnnotationMirror annotation, String messageKey) {
+ if ( isStaticElement( element ) ) {
+
+ return CollectionHelper.asSet( new ConstraintCheckError( element, annotation, messageKey ) );
+ }
+
+ return Collections.emptySet();
+ }
+
+ private boolean isStaticElement(Element element) {
+ return element.getModifiers().contains( Modifier.STATIC );
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/StaticCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TypeCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TypeCheck.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TypeCheck.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -0,0 +1,87 @@
+// $Id:$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hibernate.validator.ap.checks;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeMirror;
+
+import org.hibernate.validator.ap.util.CollectionHelper;
+import org.hibernate.validator.ap.util.ConstraintHelper;
+import org.hibernate.validator.ap.util.ConstraintHelper.ConstraintCheckResult;
+
+/**
+ * Checks, that constraint annotations are only specified at elements
+ * of a type supported by the constraints. Applies to fields, methods and
+ * non-annotation type declarations.
+ *
+ * @author Gunnar Morling
+ */
+public class TypeCheck extends AbstractConstraintCheck {
+
+ private ConstraintHelper constraintHelper;
+
+ public TypeCheck(ConstraintHelper constraintHelper) {
+ this.constraintHelper = constraintHelper;
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkField(VariableElement element,
+ AnnotationMirror annotation) {
+
+ return checkInternal( element, annotation, element.asType(), "NOT_SUPPORTED_TYPE" );
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkMethod(ExecutableElement element,
+ AnnotationMirror annotation) {
+
+ return checkInternal( element, annotation, element.getReturnType(), "NOT_SUPPORTED_RETURN_TYPE" );
+ }
+
+ @Override
+ public Set<ConstraintCheckError> checkNonAnnotationType(
+ TypeElement element, AnnotationMirror annotation) {
+
+ return checkInternal( element, annotation, element.asType(), "NOT_SUPPORTED_TYPE" );
+ }
+
+ private Set<ConstraintCheckError> checkInternal(Element element,
+ AnnotationMirror annotation, TypeMirror type, String messageKey) {
+
+ if ( constraintHelper.checkConstraint(
+ annotation.getAnnotationType(), type
+ ) != ConstraintCheckResult.ALLOWED ) {
+
+ return CollectionHelper.asSet(
+ new ConstraintCheckError(
+ element, annotation, messageKey,
+ annotation.getAnnotationType().asElement().getSimpleName()
+ )
+ );
+ }
+
+ return Collections.emptySet();
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/TypeCheck.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/MessagerAdapter.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/MessagerAdapter.java 2010-04-27 08:40:55 UTC (rev 19309)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/MessagerAdapter.java 2010-04-27 22:51:17 UTC (rev 19310)
@@ -1,4 +1,4 @@
-// $Id: MessagerAdapter.java 19033 2010-03-19 21:27:15Z gunnar.morling $
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
@@ -19,11 +19,12 @@
import java.text.MessageFormat;
import java.util.ResourceBundle;
+import java.util.Set;
import javax.annotation.processing.Messager;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
import javax.tools.Diagnostic.Kind;
+import org.hibernate.validator.ap.checks.ConstraintCheckError;
+
/**
* Wrapper around {@link Messager}, which adds the ability to format error messages using {@link MessageFormat}.
*
@@ -58,30 +59,43 @@
}
/**
- * Reports an error at the given location using the given message key and
- * optionally the given message parameters.
+ * Returns the messager used by this adapter.
*
- * @param element The element at which the error shall be reported.
- * @param annotation The annotation mirror at which the error shall be reported.
- * @param messageKey The message key to be used to retrieve the text.
- * @param messageParameters An optional array of message parameters to be put into the
- * message using a {@link MessageFormat}.
+ * @return The underlying messager.
*/
- public void reportError(Element element, AnnotationMirror annotation, String messageKey, Object... messageParameters) {
+ public Messager getDelegate() {
+ return messager;
+ }
- String message = errorMessages.getString( messageKey );
+ /**
+ * Reports the given errors against the underlying {@link Messager} using
+ * the specified {@link Kind}.
+ *
+ * @param errors A set with errors to report. May be empty but must not be
+ * null.
+ */
+ public void reportErrors(Set<ConstraintCheckError> errors) {
+ for ( ConstraintCheckError oneError : errors ) {
+ reportError( oneError );
+ }
+ }
- if ( message != null &&
- messageParameters != null ) {
+ /**
+ * Reports the given error. Message parameters will be put into the template
+ * retrieved from the resource bundle if applicable.
+ *
+ * @param error The error to report.
+ */
+ private void reportError(ConstraintCheckError error) {
- message = MessageFormat.format( errorMessages.getString( messageKey ), messageParameters );
+ String message = errorMessages.getString( error.getMessageKey() );
+
+ if ( error.getMessageParameters() != null ) {
+ message = MessageFormat.format( message, error.getMessageParameters() );
}
- else {
- message = messageKey;
- }
messager.printMessage(
- diagnosticKind, message, element, annotation
+ diagnosticKind, message, error.getElement(), error.getAnnotationMirror()
);
}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/MessagerAdapter.java
___________________________________________________________________
Name: svn:keywords
+ Id
14 years, 10 months
Hibernate SVN: r19309 - core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-27 04:40:55 -0400 (Tue, 27 Apr 2010)
New Revision: 19309
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java
Log:
HHH-4773 @CollectionId does not force the id column to not-null
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java 2010-04-27 08:38:27 UTC (rev 19308)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java 2010-04-27 08:40:55 UTC (rev 19309)
@@ -80,6 +80,10 @@
Collections.EMPTY_MAP,
mappings
);
+ //we need to make sure all id columns must be not-null.
+ for(Ejb3Column idColumn:idColumns){
+ idColumn.setNullable(false);
+ }
Table table = collection.getCollectionTable();
simpleValue.setTable( table );
simpleValue.setColumns( idColumns );
14 years, 10 months
Hibernate SVN: r19308 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/onetoone and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: sharathjreddy
Date: 2010-04-27 04:38:27 -0400 (Tue, 27 Apr 2010)
New Revision: 19308
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OwnerAddress.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Party.java
Log:
HHH-5109 @OneToOne - too many joins
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-04-27 08:33:14 UTC (rev 19307)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-04-27 08:38:27 UTC (rev 19308)
@@ -1563,7 +1563,8 @@
}
}
//MapsId means the columns belong to the pk => not null
- final boolean mandatory = !ann.optional() || forcePersist;
+ //@PKJC must be constrained
+ final boolean mandatory = !ann.optional() || forcePersist || trueOneToOne;
bindOneToOne(
getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ),
joinColumns,
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java 2010-04-27 08:33:14 UTC (rev 19307)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java 2010-04-27 08:38:27 UTC (rev 19308)
@@ -3,6 +3,7 @@
import java.util.Iterator;
+import org.hibernate.EmptyInterceptor;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
@@ -174,8 +175,8 @@
party.partyId = "id";
party.partyAffiliate = affiliate;
affiliate.party = party;
+
s.persist( party );
- s.persist( affiliate );
s.getTransaction().commit();
s.clear();
@@ -272,6 +273,41 @@
}
/**
+ * HHH-5109 @OneToOne - too many joins
+ * This test uses an interceptor to verify that correct number of joins
+ * are generated.
+ */
+ public void testPkOneToOneSelectStatementDoesNotGenerateExtraJoin() {
+
+ Session s = openSession(new JoinCounter(1));
+ Transaction tx = s.beginTransaction();
+ Owner owner = new Owner();
+ OwnerAddress address = new OwnerAddress();
+ owner.setAddress( address );
+ address.setOwner( owner );
+ s.persist( owner );
+ s.flush();
+ s.clear();
+
+ owner = ( Owner ) s.get( Owner.class, owner.getId() );
+ assertNotNull( owner );
+ assertNotNull( owner.getAddress() );
+ assertEquals( owner.getId(), owner.getAddress().getId() );
+ s.flush();
+ s.clear();
+
+ address = ( OwnerAddress ) s.get( OwnerAddress.class, address.getId() );
+ assertNotNull( address );
+ assertNotNull( address.getOwner() );
+ assertEquals( address.getId(), address.getOwner().getId() );
+
+ tx.rollback();
+ s.close();
+ }
+
+
+
+ /**
* @see org.hibernate.test.annotations.TestCase#getAnnotatedClasses()
*/
protected Class[] getAnnotatedClasses() {
@@ -299,3 +335,54 @@
return new String[] { "org/hibernate/test/annotations/onetoone/orm.xml" };
}
}
+
+
+/**
+ * Verifies that generated 'select' statement has desired number of joins
+ * @author Sharath Reddy
+ *
+ */
+class JoinCounter extends EmptyInterceptor {
+
+ private static final long serialVersionUID = -3689681272273261051L;
+
+ private int expectedNumberOfJoins = 0;
+
+ public JoinCounter(int val) {
+ super();
+ this.expectedNumberOfJoins = val;
+ }
+
+ public String onPrepareStatement(String sql) {
+
+ int numberOfJoins = 0;
+ if (sql.startsWith("select")) {
+ numberOfJoins = count(sql, "join");
+ TestCase.assertEquals(expectedNumberOfJoins, numberOfJoins);
+ }
+
+ return sql;
+ }
+
+ /**
+ * Count the number of instances of substring within a string.
+ *
+ * @param string String to look for substring in.
+ * @param substring Sub-string to look for.
+ * @return Count of substrings in string.
+ */
+ private int count(final String string, final String substring)
+ {
+ int count = 0;
+ int idx = 0;
+
+ while ((idx = string.indexOf(substring, idx)) != -1)
+ {
+ idx++;
+ count++;
+ }
+
+ return count;
+ }
+
+}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OwnerAddress.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OwnerAddress.java 2010-04-27 08:33:14 UTC (rev 19307)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OwnerAddress.java 2010-04-27 08:38:27 UTC (rev 19308)
@@ -18,7 +18,7 @@
@GenericGenerator(strategy = "foreign", name = "fk", parameters = @Parameter(name="property", value="owner"))
private Integer id;
- @OneToOne(mappedBy="address", optional = false)
+ @OneToOne(mappedBy="address")
private Owner owner;
public Integer getId() {
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Party.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Party.java 2010-04-27 08:33:14 UTC (rev 19307)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Party.java 2010-04-27 08:38:27 UTC (rev 19308)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.test.annotations.onetoone;
+import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@@ -14,7 +15,7 @@
@Id
String partyId;
- @OneToOne
+ @OneToOne(cascade=CascadeType.ALL)
@PrimaryKeyJoinColumn
PartyAffiliate partyAffiliate;
}
14 years, 10 months
Hibernate SVN: r19307 - annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/cfg/annotations.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-27 04:33:14 -0400 (Tue, 27 Apr 2010)
New Revision: 19307
Modified:
annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java
Log:
JBPAPP-4183 HHH-4773 @CollectionId does not force the id column to not-null
Modified: annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java 2010-04-27 08:31:20 UTC (rev 19306)
+++ annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java 2010-04-27 08:33:14 UTC (rev 19307)
@@ -58,6 +58,10 @@
Collections.EMPTY_MAP,
mappings
);
+ //we need to make sure all id columns must be not-null.
+ for(Ejb3Column idColumn:idColumns){
+ idColumn.setNullable(false);
+ }
Table table = collection.getCollectionTable();
simpleValue.setTable( table );
simpleValue.setColumns( idColumns );
14 years, 10 months
Hibernate SVN: r19306 - core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/annotations.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-27 04:31:20 -0400 (Tue, 27 Apr 2010)
New Revision: 19306
Modified:
core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java
Log:
HHH-4773 @CollectionId does not force the id column to not-null
Modified: core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java 2010-04-27 08:26:14 UTC (rev 19305)
+++ core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/annotations/IdBagBinder.java 2010-04-27 08:31:20 UTC (rev 19306)
@@ -80,6 +80,10 @@
Collections.EMPTY_MAP,
mappings
);
+ //we need to make sure all id columns must be not-null.
+ for(Ejb3Column idColumn:idColumns){
+ idColumn.setNullable(false);
+ }
Table table = collection.getCollectionTable();
simpleValue.setTable( table );
simpleValue.setColumns( idColumns );
14 years, 10 months
Hibernate SVN: r19305 - core/trunk/annotations/src/main/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-27 04:26:14 -0400 (Tue, 27 Apr 2010)
New Revision: 19305
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java
Log:
HHH-4773 revert changes
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java 2010-04-27 08:23:55 UTC (rev 19304)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java 2010-04-27 08:26:14 UTC (rev 19305)
@@ -439,11 +439,9 @@
column.setPropertyName(
BinderHelper.getRelativePath( propertyHolder, inferredData.getPropertyName() )
);
- //although in theory, null is an acceptable value in a Map key
- //we need force this column to be not null, as it intended to be the primary key.
- if ( nullability != Nullability.FORCED_NULL ) {
- column.setNullable( false );
- }
+ column.setNullable(
+ col.nullable()
+ ); //TODO force to not null if available? This is a (bad) user choice.
column.setUnique( col.unique() );
column.setInsertable( col.insertable() );
column.setUpdatable( col.updatable() );
14 years, 10 months
Hibernate SVN: r19304 - core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-27 04:23:55 -0400 (Tue, 27 Apr 2010)
New Revision: 19304
Modified:
core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java
Log:
HHH-4773 revert changes
Modified: core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java 2010-04-27 07:43:21 UTC (rev 19303)
+++ core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java 2010-04-27 08:23:55 UTC (rev 19304)
@@ -439,11 +439,10 @@
column.setPropertyName(
BinderHelper.getRelativePath( propertyHolder, inferredData.getPropertyName() )
);
- //although in theory, null is an acceptable value in a Map key
- //we need force this column to be not null, as it intended to be the primary key.
- if ( nullability != Nullability.FORCED_NULL ) {
- column.setNullable( false );
- } column.setUnique( col.unique() );
+ column.setNullable(
+ col.nullable()
+ ); //TODO force to not null if available? This is a (bad) user choice.
+ column.setUnique( col.unique() );
column.setInsertable( col.insertable() );
column.setUpdatable( col.updatable() );
column.setSecondaryTableName( tableName );
14 years, 10 months
Hibernate SVN: r19303 - core/branches/Branch_3_3_2_GA_CP/jdbc3-testing.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-04-27 03:43:21 -0400 (Tue, 27 Apr 2010)
New Revision: 19303
Modified:
core/branches/Branch_3_3_2_GA_CP/jdbc3-testing/
Log:
ignore eclipse metadata files
Property changes on: core/branches/Branch_3_3_2_GA_CP/jdbc3-testing
___________________________________________________________________
Name: svn:ignore
+ .settings
target
.classpath
.project
14 years, 10 months