Hibernate SVN: r17001 - jpamodelgen.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-06 05:53:47 -0400 (Mon, 06 Jul 2009)
New Revision: 17001
Added:
jpamodelgen/tags/
Log:
create JPA annotation processor model generator structure
14 years, 9 months
Hibernate SVN: r17000 - jpamodelgen.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-06 05:53:21 -0400 (Mon, 06 Jul 2009)
New Revision: 17000
Added:
jpamodelgen/branches/
Log:
create JPA annotation processor model generator structure
14 years, 9 months
Hibernate SVN: r16999 - jpamodelgen.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-06 05:52:20 -0400 (Mon, 06 Jul 2009)
New Revision: 16999
Added:
jpamodelgen/trunk/
Log:
create JPA annotation processor model generator structure
14 years, 9 months
Hibernate SVN: r16998 - /.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-06 05:51:14 -0400 (Mon, 06 Jul 2009)
New Revision: 16998
Added:
jpamodelgen/
Log:
create JPA annotation processor model generator structure
14 years, 9 months
Hibernate SVN: r16997 - in core/branches/Branch_3_2: src/org/hibernate/loader/collection and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-07-05 23:01:30 -0400 (Sun, 05 Jul 2009)
New Revision: 16997
Added:
core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/
core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java
core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/Group.java
core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/User.java
core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml
Modified:
core/branches/Branch_3_2/src/org/hibernate/loader/JoinWalker.java
core/branches/Branch_3_2/src/org/hibernate/loader/collection/BatchingCollectionInitializer.java
core/branches/Branch_3_2/src/org/hibernate/persister/collection/AbstractCollectionPersister.java
Log:
HHH-4003 - many-to-many loaders should use inner joins from the collection table to element table
Modified: core/branches/Branch_3_2/src/org/hibernate/loader/JoinWalker.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/loader/JoinWalker.java 2009-07-06 03:00:36 UTC (rev 16996)
+++ core/branches/Branch_3_2/src/org/hibernate/loader/JoinWalker.java 2009-07-06 03:01:30 UTC (rev 16997)
@@ -579,11 +579,14 @@
* is the "first" join in a series
*/
protected int getJoinType(boolean nullable, int currentDepth) {
- //TODO: this is too conservative; if all preceding joins were
+ //TODO: this is too conservative; if all preceding joins were
// also inner joins, we could use an inner join here
- return !nullable && currentDepth==0 ?
- JoinFragment.INNER_JOIN :
- JoinFragment.LEFT_OUTER_JOIN;
+ //
+ // IMPL NOTE : currentDepth might be less-than zero if this is the
+ // root of a many-to-many collection initializer
+ return !nullable && currentDepth <= 0
+ ? JoinFragment.INNER_JOIN
+ : JoinFragment.LEFT_OUTER_JOIN;
}
protected boolean isTooDeep(int currentDepth) {
Modified: core/branches/Branch_3_2/src/org/hibernate/loader/collection/BatchingCollectionInitializer.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/loader/collection/BatchingCollectionInitializer.java 2009-07-06 03:00:36 UTC (rev 16996)
+++ core/branches/Branch_3_2/src/org/hibernate/loader/collection/BatchingCollectionInitializer.java 2009-07-06 03:01:30 UTC (rev 16997)
@@ -22,7 +22,6 @@
* @author Gavin King
*/
public class BatchingCollectionInitializer implements CollectionInitializer {
-
private final Loader[] loaders;
private final int[] batchSizes;
private final CollectionPersister collectionPersister;
@@ -33,6 +32,18 @@
this.collectionPersister = collPersister;
}
+ public CollectionPersister getCollectionPersister() {
+ return collectionPersister;
+ }
+
+ public Loader[] getLoaders() {
+ return loaders;
+ }
+
+ public int[] getBatchSizes() {
+ return batchSizes;
+ }
+
public void initialize(Serializable id, SessionImplementor session)
throws HibernateException {
Modified: core/branches/Branch_3_2/src/org/hibernate/persister/collection/AbstractCollectionPersister.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/persister/collection/AbstractCollectionPersister.java 2009-07-06 03:00:36 UTC (rev 16996)
+++ core/branches/Branch_3_2/src/org/hibernate/persister/collection/AbstractCollectionPersister.java 2009-07-06 03:01:30 UTC (rev 16997)
@@ -1782,4 +1782,14 @@
protected Dialect getDialect() {
return dialect;
}
+
+ /**
+ * Intended for internal use only. In fact really only currently used from
+ * test suite for assertion purposes.
+ *
+ * @return The default collection initializer for this persister/collection.
+ */
+ public CollectionInitializer getInitializer() {
+ return initializer;
+ }
}
Added: core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java 2009-07-06 03:01:30 UTC (rev 16997)
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.List;
+import java.util.Iterator;
+
+import junit.framework.Test;
+import junit.framework.Assert;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.Interceptor;
+import org.hibernate.EmptyInterceptor;
+import org.hibernate.jdbc.BatcherFactory;
+import org.hibernate.jdbc.NonBatchingBatcher;
+import org.hibernate.jdbc.Batcher;
+import org.hibernate.jdbc.ConnectionManager;
+import org.hibernate.stat.CollectionStatistics;
+import org.hibernate.loader.collection.BatchingCollectionInitializer;
+import org.hibernate.persister.collection.AbstractCollectionPersister;
+
+/**
+ * Tests loading of many-to-many collection which should trigger
+ * a batch load.
+ *
+ * @author Steve Ebersole
+ */
+public class BatchedManyToManyTest extends FunctionalTestCase {
+ public BatchedManyToManyTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BatchedManyToManyTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "manytomany/batchload/UserGroupBatchLoad.hbm.xml" };
+ }
+
+ public void configure(Configuration cfg) {
+ cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ cfg.setProperty( Environment.BATCH_STRATEGY, TestingBatcherFactory.class.getName() );
+ }
+
+ public static class TestingBatcherFactory implements BatcherFactory {
+ public Batcher createBatcher(ConnectionManager connectionManager, Interceptor interceptor) {
+ return new TestingBatcher( connectionManager, interceptor );
+ }
+ }
+
+ public static class TestingBatcher extends NonBatchingBatcher {
+ public TestingBatcher(ConnectionManager connectionManager, Interceptor interceptor) {
+ super( connectionManager, interceptor );
+ }
+
+ }
+
+ public void testProperLoaderSetup() {
+ AbstractCollectionPersister cp = ( AbstractCollectionPersister )
+ sfi().getCollectionPersister( User.class.getName() + ".groups" );
+ assertClassAssignability( BatchingCollectionInitializer.class, cp.getInitializer().getClass() );
+ BatchingCollectionInitializer initializer = ( BatchingCollectionInitializer ) cp.getInitializer();
+ assertEquals( 50, findMaxBatchSize( initializer.getBatchSizes() ) );
+ }
+
+ private int findMaxBatchSize(int[] batchSizes) {
+ int max = 0;
+ for ( int i = 0; i < batchSizes.length; i++ ) {
+ int size = batchSizes[i];
+ if ( size > max ) {
+ max = size;
+ }
+ }
+ return max;
+ }
+
+ public void testLoadingNonInverseSide() {
+ prepareTestData();
+
+ sfi().getStatistics().clear();
+ CollectionStatistics userGroupStats = sfi().getStatistics()
+ .getCollectionStatistics( User.class.getName() + ".groups" );
+ CollectionStatistics groupUserStats = sfi().getStatistics()
+ .getCollectionStatistics( Group.class.getName() + ".users" );
+
+ Interceptor testingInterceptor = new EmptyInterceptor() {
+ public String onPrepareStatement(String sql) {
+ // ugh, this is the best way I could come up with to assert this.
+ // unfortunately, this is highly dependent on the dialect and its
+ // outer join fragment. But at least this wil fail on the majority
+ // of dialects...
+ Assert.assertFalse(
+ "batch load of many-to-many should use inner join",
+ sql.toLowerCase().contains( "left outer join" )
+ );
+ return super.onPrepareStatement( sql );
+ }
+ };
+
+ Session s = openSession( testingInterceptor );
+ s.beginTransaction();
+ List users = s.createQuery( "from User u" ).list();
+ User user = ( User ) users.get( 0 );
+ assertTrue( Hibernate.isInitialized( user ) );
+ assertTrue( Hibernate.isInitialized( user.getGroups() ) );
+ user = ( User ) users.get( 1 );
+ assertTrue( Hibernate.isInitialized( user ) );
+ assertTrue( Hibernate.isInitialized( user.getGroups() ) );
+ assertEquals( 1, userGroupStats.getFetchCount() ); // should have been just one fetch (the batch fetch)
+ assertEquals( 1, groupUserStats.getFetchCount() ); // should have been just one fetch (the batch fetch)
+ s.getTransaction().commit();
+ s.close();
+
+ cleanupTestData();
+ }
+
+ protected void prepareTestData() {
+ // set up the test data
+ User me = new User( "steve" );
+ User you = new User( "not steve" );
+ Group developers = new Group( "developers" );
+ Group translators = new Group( "translators" );
+ Group contributors = new Group( "contributors" );
+ me.getGroups().add( developers );
+ developers.getUsers().add( me );
+ you.getGroups().add( translators );
+ translators.getUsers().add( you );
+ you.getGroups().add( contributors );
+ contributors.getUsers().add( you );
+ Session s = openSession();
+ s.beginTransaction();
+ s.save( me );
+ s.save( you );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ protected void cleanupTestData() {
+ // clean up the test data
+ Session s = openSession();
+ s.beginTransaction();
+ // User is the non-inverse side...
+ List users = s.createQuery( "from User" ).list();
+ Iterator itr = users.iterator();
+ while ( itr.hasNext() ) {
+ User user = ( User ) itr.next();
+ s.delete( user );
+ }
+ s.flush();
+ s.createQuery( "delete Group" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/Group.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/Group.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/Group.java 2009-07-06 03:01:30 UTC (rev 16997)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Group {
+ private Long id;
+ private String name;
+ private Set users = new HashSet();
+
+ public Group() {
+ }
+
+ public Group(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getUsers() {
+ return users;
+ }
+
+ public void setUsers(Set users) {
+ this.users = users;
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/User.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/User.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/User.java 2009-07-06 03:01:30 UTC (rev 16997)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class User {
+ private Long id;
+ private String name;
+ private Set groups = new HashSet();
+
+ public User() {
+ }
+
+ public User(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getGroups() {
+ return groups;
+ }
+
+ public void setGroups(Set groups) {
+ this.groups = groups;
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml 2009-07-06 03:01:30 UTC (rev 16997)
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!--
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+
+<hibernate-mapping package="org.hibernate.test.manytomany.batchload">
+
+ <class name="User" table="M2N_BATCHED_USER">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string"/>
+ <set name="groups" table="M2N_BATCHED_GROUPUSER" inverse="false" cascade="all" lazy="false" batch-size="50" >
+ <key column="USER_ID"/>
+ <many-to-many class="Group" column="GROUP_ID"/>
+ </set>
+ </class>
+
+ <class name="Group" table="M2N_BATCHED_GROUP">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string"/>
+ <set name="users" table="M2N_BATCHED_GROUPUSER" inverse="true" cascade="all" lazy="false" batch-size="50">
+ <key column="GROUP_ID"/>
+ <many-to-many class="User" column="USER_ID"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
14 years, 9 months
Hibernate SVN: r16996 - in core/branches/Branch_3_3: core/src/main/java/org/hibernate/loader/collection and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-07-05 23:00:36 -0400 (Sun, 05 Jul 2009)
New Revision: 16996
Added:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/Group.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/User.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/JoinWalker.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/collection/BatchingCollectionInitializer.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
Log:
HHH-4003 - many-to-many loaders should use inner joins from the collection table to element table
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/JoinWalker.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/JoinWalker.java 2009-07-06 02:59:17 UTC (rev 16995)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/JoinWalker.java 2009-07-06 03:00:36 UTC (rev 16996)
@@ -602,11 +602,14 @@
* is the "first" join in a series
*/
protected int getJoinType(boolean nullable, int currentDepth) {
- //TODO: this is too conservative; if all preceding joins were
+ //TODO: this is too conservative; if all preceding joins were
// also inner joins, we could use an inner join here
- return !nullable && currentDepth==0 ?
- JoinFragment.INNER_JOIN :
- JoinFragment.LEFT_OUTER_JOIN;
+ //
+ // IMPL NOTE : currentDepth might be less-than zero if this is the
+ // root of a many-to-many collection initializer
+ return !nullable && currentDepth <= 0
+ ? JoinFragment.INNER_JOIN
+ : JoinFragment.LEFT_OUTER_JOIN;
}
protected boolean isTooDeep(int currentDepth) {
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/collection/BatchingCollectionInitializer.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/collection/BatchingCollectionInitializer.java 2009-07-06 02:59:17 UTC (rev 16995)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/collection/BatchingCollectionInitializer.java 2009-07-06 03:00:36 UTC (rev 16996)
@@ -56,6 +56,18 @@
this.collectionPersister = collPersister;
}
+ public CollectionPersister getCollectionPersister() {
+ return collectionPersister;
+ }
+
+ public Loader[] getLoaders() {
+ return loaders;
+ }
+
+ public int[] getBatchSizes() {
+ return batchSizes;
+ }
+
public void initialize(Serializable id, SessionImplementor session)
throws HibernateException {
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java 2009-07-06 02:59:17 UTC (rev 16995)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java 2009-07-06 03:00:36 UTC (rev 16996)
@@ -1804,4 +1804,14 @@
protected Dialect getDialect() {
return dialect;
}
+
+ /**
+ * Intended for internal use only. In fact really only currently used from
+ * test suite for assertion purposes.
+ *
+ * @return The default collection initializer for this persister/collection.
+ */
+ public CollectionInitializer getInitializer() {
+ return initializer;
+ }
}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java 2009-07-06 03:00:36 UTC (rev 16996)
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.Assert;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.Interceptor;
+import org.hibernate.EmptyInterceptor;
+import org.hibernate.stat.CollectionStatistics;
+import org.hibernate.loader.collection.BatchingCollectionInitializer;
+import org.hibernate.persister.collection.AbstractCollectionPersister;
+
+/**
+ * Tests loading of many-to-many collection which should trigger
+ * a batch load.
+ *
+ * @author Steve Ebersole
+ */
+public class BatchedManyToManyTest extends FunctionalTestCase {
+ public BatchedManyToManyTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BatchedManyToManyTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "manytomany/batchload/UserGroupBatchLoad.hbm.xml" };
+ }
+
+ public void configure(Configuration cfg) {
+ cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ }
+
+ public void testProperLoaderSetup() {
+ AbstractCollectionPersister cp = ( AbstractCollectionPersister )
+ sfi().getCollectionPersister( User.class.getName() + ".groups" );
+ assertClassAssignability( BatchingCollectionInitializer.class, cp.getInitializer().getClass() );
+ BatchingCollectionInitializer initializer = ( BatchingCollectionInitializer ) cp.getInitializer();
+ assertEquals( 50, findMaxBatchSize( initializer.getBatchSizes() ) );
+ }
+
+ private int findMaxBatchSize(int[] batchSizes) {
+ int max = 0;
+ for ( int size : batchSizes ) {
+ if ( size > max ) {
+ max = size;
+ }
+ }
+ return max;
+ }
+
+ public void testLoadingNonInverseSide() {
+ prepareTestData();
+
+ sfi().getStatistics().clear();
+ CollectionStatistics userGroupStats = sfi().getStatistics()
+ .getCollectionStatistics( User.class.getName() + ".groups" );
+ CollectionStatistics groupUserStats = sfi().getStatistics()
+ .getCollectionStatistics( Group.class.getName() + ".users" );
+
+ Interceptor testingInterceptor = new EmptyInterceptor() {
+ public String onPrepareStatement(String sql) {
+ // ugh, this is the best way I could come up with to assert this.
+ // unfortunately, this is highly dependent on the dialect and its
+ // outer join fragment. But at least this wil fail on the majority
+ // of dialects...
+ Assert.assertFalse(
+ "batch load of many-to-many should use inner join",
+ sql.toLowerCase().contains( "left outer join" )
+ );
+ return super.onPrepareStatement( sql );
+ }
+ };
+
+ Session s = openSession( testingInterceptor );
+ s.beginTransaction();
+ List users = s.createQuery( "from User u" ).list();
+ User user = ( User ) users.get( 0 );
+ assertTrue( Hibernate.isInitialized( user ) );
+ assertTrue( Hibernate.isInitialized( user.getGroups() ) );
+ user = ( User ) users.get( 1 );
+ assertTrue( Hibernate.isInitialized( user ) );
+ assertTrue( Hibernate.isInitialized( user.getGroups() ) );
+ assertEquals( 1, userGroupStats.getFetchCount() ); // should have been just one fetch (the batch fetch)
+ assertEquals( 1, groupUserStats.getFetchCount() ); // should have been just one fetch (the batch fetch)
+ s.getTransaction().commit();
+ s.close();
+
+ cleanupTestData();
+ }
+
+ protected void prepareTestData() {
+ // set up the test data
+ User me = new User( "steve" );
+ User you = new User( "not steve" );
+ Group developers = new Group( "developers" );
+ Group translators = new Group( "translators" );
+ Group contributors = new Group( "contributors" );
+ me.getGroups().add( developers );
+ developers.getUsers().add( me );
+ you.getGroups().add( translators );
+ translators.getUsers().add( you );
+ you.getGroups().add( contributors );
+ contributors.getUsers().add( you );
+ Session s = openSession();
+ s.beginTransaction();
+ s.save( me );
+ s.save( you );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ protected void cleanupTestData() {
+ // clean up the test data
+ Session s = openSession();
+ s.beginTransaction();
+ // User is the non-inverse side...
+ List<User> users = s.createQuery( "from User" ).list();
+ for ( User user : users ) {
+ s.delete( user );
+ }
+ s.flush();
+ s.createQuery( "delete Group" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/Group.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/Group.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/Group.java 2009-07-06 03:00:36 UTC (rev 16996)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Group {
+ private Long id;
+ private String name;
+ private Set<User> users = new HashSet<User>();
+
+ public Group() {
+ }
+
+ public Group(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<User> getUsers() {
+ return users;
+ }
+
+ public void setUsers(Set<User> users) {
+ this.users = users;
+ }
+}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/User.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/User.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/User.java 2009-07-06 03:00:36 UTC (rev 16996)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class User {
+ private Long id;
+ private String name;
+ private Set<Group> groups = new HashSet<Group>();
+
+ public User() {
+ }
+
+ public User(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<Group> getGroups() {
+ return groups;
+ }
+
+ public void setGroups(Set<Group> groups) {
+ this.groups = groups;
+ }
+}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml 2009-07-06 03:00:36 UTC (rev 16996)
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!--
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+
+<hibernate-mapping package="org.hibernate.test.manytomany.batchload">
+
+ <class name="User" table="M2N_BATCHED_USER">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string"/>
+ <set name="groups" table="M2N_BATCHED_GROUPUSER" inverse="false" cascade="all" lazy="false" batch-size="50" >
+ <key column="USER_ID"/>
+ <many-to-many class="Group" column="GROUP_ID"/>
+ </set>
+ </class>
+
+ <class name="Group" table="M2N_BATCHED_GROUP">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string"/>
+ <set name="users" table="M2N_BATCHED_GROUPUSER" inverse="true" cascade="all" lazy="false" batch-size="50">
+ <key column="GROUP_ID"/>
+ <many-to-many class="User" column="USER_ID"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
14 years, 9 months
Hibernate SVN: r16995 - in core/trunk: core/src/main/java/org/hibernate/loader/collection and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-07-05 22:59:17 -0400 (Sun, 05 Jul 2009)
New Revision: 16995
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/
core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/Group.java
core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/User.java
core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml
Modified:
core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java
core/trunk/core/src/main/java/org/hibernate/loader/collection/BatchingCollectionInitializer.java
core/trunk/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
Log:
HHH-4003 - many-to-many loaders should use inner joins from the collection table to element table
Modified: core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java 2009-07-03 11:49:16 UTC (rev 16994)
+++ core/trunk/core/src/main/java/org/hibernate/loader/JoinWalker.java 2009-07-06 02:59:17 UTC (rev 16995)
@@ -689,7 +689,10 @@
protected int getJoinType(boolean nullable, int currentDepth) {
//TODO: this is too conservative; if all preceding joins were
// also inner joins, we could use an inner join here
- return !nullable && currentDepth == 0
+ //
+ // IMPL NOTE : currentDepth might be less-than zero if this is the
+ // root of a many-to-many collection initializer
+ return !nullable && currentDepth <= 0
? JoinFragment.INNER_JOIN
: JoinFragment.LEFT_OUTER_JOIN;
}
Modified: core/trunk/core/src/main/java/org/hibernate/loader/collection/BatchingCollectionInitializer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/collection/BatchingCollectionInitializer.java 2009-07-03 11:49:16 UTC (rev 16994)
+++ core/trunk/core/src/main/java/org/hibernate/loader/collection/BatchingCollectionInitializer.java 2009-07-06 02:59:17 UTC (rev 16995)
@@ -25,7 +25,6 @@
package org.hibernate.loader.collection;
import java.io.Serializable;
-import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
@@ -46,7 +45,6 @@
* @author Gavin King
*/
public class BatchingCollectionInitializer implements CollectionInitializer {
-
private final Loader[] loaders;
private final int[] batchSizes;
private final CollectionPersister collectionPersister;
@@ -57,6 +55,18 @@
this.collectionPersister = collPersister;
}
+ public CollectionPersister getCollectionPersister() {
+ return collectionPersister;
+ }
+
+ public Loader[] getLoaders() {
+ return loaders;
+ }
+
+ public int[] getBatchSizes() {
+ return batchSizes;
+ }
+
public void initialize(Serializable id, SessionImplementor session)
throws HibernateException {
Modified: core/trunk/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java 2009-07-03 11:49:16 UTC (rev 16994)
+++ core/trunk/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java 2009-07-06 02:59:17 UTC (rev 16995)
@@ -1832,4 +1832,14 @@
protected Dialect getDialect() {
return dialect;
}
+
+ /**
+ * Intended for internal use only. In fact really only currently used from
+ * test suite for assertion purposes.
+ *
+ * @return The default collection initializer for this persister/collection.
+ */
+ public CollectionInitializer getInitializer() {
+ return initializer;
+ }
}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/BatchedManyToManyTest.java 2009-07-06 02:59:17 UTC (rev 16995)
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.List;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import junit.framework.Test;
+import junit.framework.Assert;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.Interceptor;
+import org.hibernate.HibernateException;
+import org.hibernate.EmptyInterceptor;
+import org.hibernate.jdbc.BatcherFactory;
+import org.hibernate.jdbc.NonBatchingBatcher;
+import org.hibernate.jdbc.Batcher;
+import org.hibernate.jdbc.ConnectionManager;
+import org.hibernate.stat.CollectionStatistics;
+import org.hibernate.loader.collection.BatchingCollectionInitializer;
+import org.hibernate.persister.collection.AbstractCollectionPersister;
+
+/**
+ * Tests loading of many-to-many collection which should trigger
+ * a batch load.
+ *
+ * @author Steve Ebersole
+ */
+public class BatchedManyToManyTest extends FunctionalTestCase {
+ public BatchedManyToManyTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BatchedManyToManyTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "manytomany/batchload/UserGroupBatchLoad.hbm.xml" };
+ }
+
+ public void configure(Configuration cfg) {
+ cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ cfg.setProperty( Environment.BATCH_STRATEGY, TestingBatcherFactory.class.getName() );
+ }
+
+ public static class TestingBatcherFactory implements BatcherFactory {
+ public Batcher createBatcher(ConnectionManager connectionManager, Interceptor interceptor) {
+ return new TestingBatcher( connectionManager, interceptor );
+ }
+ }
+
+ public static class TestingBatcher extends NonBatchingBatcher {
+ public TestingBatcher(ConnectionManager connectionManager, Interceptor interceptor) {
+ super( connectionManager, interceptor );
+ }
+
+ }
+
+ public void testProperLoaderSetup() {
+ AbstractCollectionPersister cp = ( AbstractCollectionPersister )
+ sfi().getCollectionPersister( User.class.getName() + ".groups" );
+ assertClassAssignability( BatchingCollectionInitializer.class, cp.getInitializer().getClass() );
+ BatchingCollectionInitializer initializer = ( BatchingCollectionInitializer ) cp.getInitializer();
+ assertEquals( 50, findMaxBatchSize( initializer.getBatchSizes() ) );
+ }
+
+ private int findMaxBatchSize(int[] batchSizes) {
+ int max = 0;
+ for ( int size : batchSizes ) {
+ if ( size > max ) {
+ max = size;
+ }
+ }
+ return max;
+ }
+
+ public void testLoadingNonInverseSide() {
+ prepareTestData();
+
+ sfi().getStatistics().clear();
+ CollectionStatistics userGroupStats = sfi().getStatistics()
+ .getCollectionStatistics( User.class.getName() + ".groups" );
+ CollectionStatistics groupUserStats = sfi().getStatistics()
+ .getCollectionStatistics( Group.class.getName() + ".users" );
+
+ Interceptor testingInterceptor = new EmptyInterceptor() {
+ public String onPrepareStatement(String sql) {
+ // ugh, this is the best way I could come up with to assert this.
+ // unfortunately, this is highly dependent on the dialect and its
+ // outer join fragment. But at least this wil fail on the majority
+ // of dialects...
+ Assert.assertFalse(
+ "batch load of many-to-many should use inner join",
+ sql.toLowerCase().contains( "left outer join" )
+ );
+ return super.onPrepareStatement( sql );
+ }
+ };
+
+ Session s = openSession( testingInterceptor );
+ s.beginTransaction();
+ List users = s.createQuery( "from User u" ).list();
+ User user = ( User ) users.get( 0 );
+ assertTrue( Hibernate.isInitialized( user ) );
+ assertTrue( Hibernate.isInitialized( user.getGroups() ) );
+ user = ( User ) users.get( 1 );
+ assertTrue( Hibernate.isInitialized( user ) );
+ assertTrue( Hibernate.isInitialized( user.getGroups() ) );
+ assertEquals( 1, userGroupStats.getFetchCount() ); // should have been just one fetch (the batch fetch)
+ assertEquals( 1, groupUserStats.getFetchCount() ); // should have been just one fetch (the batch fetch)
+ s.getTransaction().commit();
+ s.close();
+
+ cleanupTestData();
+ }
+
+ protected void prepareTestData() {
+ // set up the test data
+ User me = new User( "steve" );
+ User you = new User( "not steve" );
+ Group developers = new Group( "developers" );
+ Group translators = new Group( "translators" );
+ Group contributors = new Group( "contributors" );
+ me.getGroups().add( developers );
+ developers.getUsers().add( me );
+ you.getGroups().add( translators );
+ translators.getUsers().add( you );
+ you.getGroups().add( contributors );
+ contributors.getUsers().add( you );
+ Session s = openSession();
+ s.beginTransaction();
+ s.save( me );
+ s.save( you );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ protected void cleanupTestData() {
+ // clean up the test data
+ Session s = openSession();
+ s.beginTransaction();
+ // User is the non-inverse side...
+ List<User> users = s.createQuery( "from User" ).list();
+ for ( User user : users ) {
+ s.delete( user );
+ }
+ s.flush();
+ s.createQuery( "delete Group" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/Group.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/Group.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/Group.java 2009-07-06 02:59:17 UTC (rev 16995)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Group {
+ private Long id;
+ private String name;
+ private Set<User> users = new HashSet<User>();
+
+ public Group() {
+ }
+
+ public Group(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<User> getUsers() {
+ return users;
+ }
+
+ public void setUsers(Set<User> users) {
+ this.users = users;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/User.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/User.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/User.java 2009-07-06 02:59:17 UTC (rev 16995)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.manytomany.batchload;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class User {
+ private Long id;
+ private String name;
+ private Set<Group> groups = new HashSet<Group>();
+
+ public User() {
+ }
+
+ public User(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<Group> getGroups() {
+ return groups;
+ }
+
+ public void setGroups(Set<Group> groups) {
+ this.groups = groups;
+ }
+}
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml (from rev 16091, core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/UserGroup.hbm.xml)
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml 2009-07-06 02:59:17 UTC (rev 16995)
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!--
+ ~ Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+
+<hibernate-mapping package="org.hibernate.test.manytomany.batchload">
+
+ <class name="User" table="M2N_BATCHED_USER">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string"/>
+ <set name="groups" table="M2N_BATCHED_GROUPUSER" inverse="false" cascade="all" lazy="false" batch-size="50" >
+ <key column="USER_ID"/>
+ <many-to-many class="Group" column="GROUP_ID"/>
+ </set>
+ </class>
+
+ <class name="Group" table="M2N_BATCHED_GROUP">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string"/>
+ <set name="users" table="M2N_BATCHED_GROUPUSER" inverse="true" cascade="all" lazy="false" batch-size="50">
+ <key column="GROUP_ID"/>
+ <many-to-many class="User" column="USER_ID"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
14 years, 9 months
Hibernate SVN: r16994 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-03 07:49:16 -0400 (Fri, 03 Jul 2009)
New Revision: 16994
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidatorContext.java
Log:
minor JavaDoc clarification
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidatorContext.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidatorContext.java 2009-07-02 18:33:25 UTC (rev 16993)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidatorContext.java 2009-07-03 11:49:16 UTC (rev 16994)
@@ -18,8 +18,11 @@
package javax.validation;
/**
- * Provide contextual data and operation when applying a given constraint validator
+ * Provide contextual data and operation when applying a given constraint validator.
*
+ * At least one error must be defined (either the default one, of if the default error
+ * is disabled, a custom one).
+ *
* @author Emmanuel Bernard
*/
public interface ConstraintValidatorContext {
14 years, 9 months
Hibernate SVN: r16993 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-02 14:33:25 -0400 (Thu, 02 Jul 2009)
New Revision: 16993
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
Log:
fix validateValue javaDoc
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-07-02 12:40:48 UTC (rev 16992)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-07-02 18:33:25 UTC (rev 16993)
@@ -79,7 +79,7 @@
*
* @return constraint violations or an empty Set if none
*
- * @throws IllegalArgumentException if object is null, if propertyName null, empty
+ * @throws IllegalArgumentException if beanType is null, if propertyName null, empty
* or not a valid object property
* or if null is passed to the varargs groups
* @throws ValidationException if a non recoverable error happens
14 years, 9 months
Hibernate SVN: r16992 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-02 08:40:48 -0400 (Thu, 02 Jul 2009)
New Revision: 16992
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java
Log:
BVAL-171 PathBuilder prototype
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java 2009-07-02 12:39:38 UTC (rev 16991)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/PathBuilder.java 2009-07-02 12:40:48 UTC (rev 16992)
@@ -29,13 +29,15 @@
public interface PathBuilder {
/**
- * Start the creation of a Path object whose root node is
- * named rootNode.
+ * Add a subNode to the path.
*
- * @param rootNode root node name
- * @return a builder representing the root node
+ * name describes a single property. In particular,
+ * dot (.) are not allowed.
+ *
+ * @param name property
+ * @return a builder representing this node
*/
- PathBuilder.NodeBuilderWithDefinedContext buildPath(String rootNode);
+ PathBuilder.NodeBuilderWithDefinedContext addSubNode(String name);
/**
* Represent a node whose context is known
@@ -43,8 +45,11 @@
*/
interface NodeBuilderWithDefinedContext {
/**
- * Add a subNode to the path
+ * Add a subNode to the path.
*
+ * name describes a single property. In particular,
+ * dot (.) are not allowed.
+ *
* @param name property
* @return a builder representing this node
*/
@@ -73,8 +78,11 @@
NodeContextBuilder inIterable();
/**
- * Add a subNode to the path
+ * Add a subNode to the path.
*
+ * name describes a single property. In particular,
+ * dot (.) are not allowed.
+ *
* @param name property
* @return a builder representing this node
*/
@@ -115,8 +123,11 @@
NodeBuilderWithDefinedContext atIndex(Integer index);
/**
- * Add a subNode to the path
+ * Add a subNode to the path.
*
+ * name describes a single property. In particular,
+ * dot (.) are not allowed.
+ *
* @param name property
* @return a builder representing this node
*/
14 years, 9 months