Hibernate SVN: r14372 - in core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test: cache/jbc2/collection and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-02-27 13:36:29 -0500 (Wed, 27 Feb 2008)
New Revision: 14372
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticInvalidatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticReadOnlyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticInvalidatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticReadOnlyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticInvalidatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticReadOnlyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticInvalidatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticReadOnlyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestUtil.java
Log:
Factor out usage of createFailureExpectedTestSuite
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,13 +23,7 @@
*/
package org.hibernate.test.cache.jbc2;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import org.hibernate.cache.RegionFactory;
import org.hibernate.junit.UnitTestCase;
@@ -102,44 +96,4 @@
protected void avoidConcurrentFlush() {
testSupport.avoidConcurrentFlush();
}
-
-
- /**
- * Supports easy creation of a TestSuite where a subclass' "FailureExpected"
- * version of a base test is included in the suite, while the base test
- * is excluded. E.g. test class FooTestCase includes method testBar(), while test
- * class SubFooTestCase extends FooTestCase includes method testBarFailureExcluded().
- * Passing SubFooTestCase.class to this method will return a suite that
- * does not include testBar().
- *
- * FIXME Move this to UnitTestCase
- */
- public static TestSuite createFailureExpectedSuite(Class testClass) {
-
- TestSuite allTests = new TestSuite(testClass);
- Set failureExpected = new HashSet();
- Enumeration tests = allTests.tests();
- while (tests.hasMoreElements()) {
- Test t = (Test) tests.nextElement();
- if (t instanceof TestCase) {
- String name = ((TestCase) t).getName();
- if (name.endsWith("FailureExpected"))
- failureExpected.add(name);
- }
- }
-
- TestSuite result = new TestSuite();
- tests = allTests.tests();
- while (tests.hasMoreElements()) {
- Test t = (Test) tests.nextElement();
- if (t instanceof TestCase) {
- String name = ((TestCase) t).getName();
- if (!failureExpected.contains(name + "FailureExpected")) {
- result.addTest(t);
- }
- }
- }
-
- return result;
- }
}
\ No newline at end of file
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticInvalidatedTransactionalTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticInvalidatedTransactionalTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticInvalidatedTransactionalTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,6 +23,8 @@
*/
package org.hibernate.test.cache.jbc2.collection;
+import org.hibernate.test.util.CacheTestUtil;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -45,7 +47,7 @@
}
public static Test suite() throws Exception {
- TestSuite suite = createFailureExpectedSuite(OptimisticInvalidatedTransactionalTestCase.class);
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(OptimisticInvalidatedTransactionalTestCase.class);
return getTestSetup(suite, "optimistic-entity");
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticReadOnlyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticReadOnlyTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticReadOnlyTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,6 +23,8 @@
*/
package org.hibernate.test.cache.jbc2.collection;
+import org.hibernate.test.util.CacheTestUtil;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -44,7 +46,7 @@
}
public static Test suite() throws Exception {
- TestSuite suite = createFailureExpectedSuite(OptimisticReadOnlyTestCase.class);
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(OptimisticReadOnlyTestCase.class);
return getTestSetup(suite, "optimistic-entity");
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticInvalidatedTransactionalTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticInvalidatedTransactionalTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticInvalidatedTransactionalTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,6 +23,8 @@
*/
package org.hibernate.test.cache.jbc2.collection;
+import org.hibernate.test.util.CacheTestUtil;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -44,7 +46,7 @@
}
public static Test suite() throws Exception {
- TestSuite suite = createFailureExpectedSuite(PessimisticInvalidatedTransactionalTestCase.class);
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(PessimisticInvalidatedTransactionalTestCase.class);
return getTestSetup(suite, "pessimistic-entity");
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticReadOnlyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticReadOnlyTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticReadOnlyTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,6 +23,8 @@
*/
package org.hibernate.test.cache.jbc2.collection;
+import org.hibernate.test.util.CacheTestUtil;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -44,7 +46,7 @@
}
public static Test suite() throws Exception {
- TestSuite suite = createFailureExpectedSuite(PessimisticReadOnlyTestCase.class);
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(PessimisticReadOnlyTestCase.class);
return getTestSetup(suite, "pessimistic-entity");
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticInvalidatedTransactionalTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticInvalidatedTransactionalTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticInvalidatedTransactionalTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,6 +23,8 @@
*/
package org.hibernate.test.cache.jbc2.entity;
+import org.hibernate.test.util.CacheTestUtil;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -44,7 +46,7 @@
}
public static Test suite() throws Exception {
- TestSuite suite = createFailureExpectedSuite(OptimisticInvalidatedTransactionalTestCase.class);
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(OptimisticInvalidatedTransactionalTestCase.class);
return getTestSetup(suite, "optimistic-entity");
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticReadOnlyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticReadOnlyTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticReadOnlyTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,6 +23,8 @@
*/
package org.hibernate.test.cache.jbc2.entity;
+import org.hibernate.test.util.CacheTestUtil;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -44,7 +46,7 @@
}
public static Test suite() throws Exception {
- TestSuite suite = createFailureExpectedSuite(OptimisticReadOnlyTestCase.class);
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(OptimisticReadOnlyTestCase.class);
return getTestSetup(suite, "optimistic-entity");
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticInvalidatedTransactionalTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticInvalidatedTransactionalTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticInvalidatedTransactionalTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,6 +23,8 @@
*/
package org.hibernate.test.cache.jbc2.entity;
+import org.hibernate.test.util.CacheTestUtil;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -44,7 +46,7 @@
}
public static Test suite() throws Exception {
- TestSuite suite = createFailureExpectedSuite(PessimisticInvalidatedTransactionalTestCase.class);
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(PessimisticInvalidatedTransactionalTestCase.class);
return getTestSetup(suite, "pessimistic-entity");
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticReadOnlyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticReadOnlyTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticReadOnlyTestCase.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,6 +23,8 @@
*/
package org.hibernate.test.cache.jbc2.entity;
+import org.hibernate.test.util.CacheTestUtil;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -44,7 +46,7 @@
}
public static Test suite() throws Exception {
- TestSuite suite = createFailureExpectedSuite(PessimisticReadOnlyTestCase.class);
+ TestSuite suite = CacheTestUtil.createFailureExpectedSuite(PessimisticReadOnlyTestCase.class);
return getTestSetup(suite, "pessimistic-entity");
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -22,7 +22,12 @@
package org.hibernate.test.cache.jbc2.functional.bulk;
+import junit.framework.Test;
+import org.hibernate.test.cache.jbc2.collection.OptimisticInvalidatedTransactionalTestCase;
+import org.hibernate.test.util.CacheTestUtil;
+
+
/**
* Optimistic version of BulkOperationsUnitTestCase.
*
@@ -32,6 +37,10 @@
public class OptimisticBulkOperationsTest
extends PessimisticBulkOperationsTest
{
+
+ public static Test suite() throws Exception {
+ return CacheTestUtil.createFailureExpectedSuite(OptimisticBulkOperationsTest.class);
+ }
/**
* @param name
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestUtil.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestUtil.java 2008-02-27 18:06:19 UTC (rev 14371)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestUtil.java 2008-02-27 18:36:29 UTC (rev 14372)
@@ -23,8 +23,15 @@
*/
package org.hibernate.test.util;
+import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Properties;
+import java.util.Set;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
import org.hibernate.cache.jbc2.JBossCacheRegionFactory;
import org.hibernate.cache.jbc2.SharedJBossCacheRegionFactory;
import org.hibernate.cache.jbc2.builder.SharedCacheInstanceManager;
@@ -113,4 +120,43 @@
private CacheTestUtil() {
}
+ /**
+ * Supports easy creation of a TestSuite where a subclass' "FailureExpected"
+ * version of a base test is included in the suite, while the base test
+ * is excluded. E.g. test class FooTestCase includes method testBar(), while test
+ * class SubFooTestCase extends FooTestCase includes method testBarFailureExcluded().
+ * Passing SubFooTestCase.class to this method will return a suite that
+ * does not include testBar().
+ *
+ * FIXME Move this to UnitTestCase
+ */
+ public static TestSuite createFailureExpectedSuite(Class testClass) {
+
+ TestSuite allTests = new TestSuite(testClass);
+ Set failureExpected = new HashSet();
+ Enumeration tests = allTests.tests();
+ while (tests.hasMoreElements()) {
+ Test t = (Test) tests.nextElement();
+ if (t instanceof TestCase) {
+ String name = ((TestCase) t).getName();
+ if (name.endsWith("FailureExpected"))
+ failureExpected.add(name);
+ }
+ }
+
+ TestSuite result = new TestSuite();
+ tests = allTests.tests();
+ while (tests.hasMoreElements()) {
+ Test t = (Test) tests.nextElement();
+ if (t instanceof TestCase) {
+ String name = ((TestCase) t).getName();
+ if (!failureExpected.contains(name + "FailureExpected")) {
+ result.addTest(t);
+ }
+ }
+ }
+
+ return result;
+ }
+
}
16 years, 11 months
Hibernate SVN: r14371 - core/trunk/testing/src/main/java/org/hibernate/junit.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-02-27 13:06:19 -0500 (Wed, 27 Feb 2008)
New Revision: 14371
Modified:
core/trunk/testing/src/main/java/org/hibernate/junit/UnitTestCase.java
Log:
Add utility to create a TestSuite where a subclass' "FailureExpected" version of a base test is included in the suite, while the base test is excluded
Modified: core/trunk/testing/src/main/java/org/hibernate/junit/UnitTestCase.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/junit/UnitTestCase.java 2008-02-27 17:51:32 UTC (rev 14370)
+++ core/trunk/testing/src/main/java/org/hibernate/junit/UnitTestCase.java 2008-02-27 18:06:19 UTC (rev 14371)
@@ -23,11 +23,17 @@
*/
package org.hibernate.junit;
+import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
/**
@@ -104,4 +110,43 @@
protected void reportSkip(String reason, String testDescription) {
SkipLog.LOG.warn( "*** skipping [" + fullTestName() + "] - " + testDescription + " : " + reason, new Exception() );
}
+
+ // testsuite utitities ---------------------------------------------------
+
+ /**
+ * Supports easy creation of TestSuites where a subclass' "FailureExpected"
+ * version of a base test is included in the suite, while the base test
+ * is excluded. E.g. test class FooTestCase includes method testBar(), while test
+ * class SubFooTestCase extends FooTestCase includes method testBarFailureExcluded().
+ * Passing SubFooTestCase.class to this method will return a suite that
+ * does not include testBar().
+ */
+ public static TestSuite createFailureExpectedSuite(Class testClass) {
+
+ TestSuite allTests = new TestSuite(testClass);
+ Set failureExpected = new HashSet();
+ Enumeration tests = allTests.tests();
+ while (tests.hasMoreElements()) {
+ Test t = (Test) tests.nextElement();
+ if (t instanceof TestCase) {
+ String name = ((TestCase) t).getName();
+ if (name.endsWith("FailureExpected"))
+ failureExpected.add(name);
+ }
+ }
+
+ TestSuite result = new TestSuite();
+ tests = allTests.tests();
+ while (tests.hasMoreElements()) {
+ Test t = (Test) tests.nextElement();
+ if (t instanceof TestCase) {
+ String name = ((TestCase) t).getName();
+ if (!failureExpected.contains(name + "FailureExpected")) {
+ result.addTest(t);
+ }
+ }
+ }
+
+ return result;
+ }
}
16 years, 11 months
Hibernate SVN: r14370 - in core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional: bulk and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-02-27 12:51:32 -0500 (Wed, 27 Feb 2008)
New Revision: 14370
Added:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/PessimisticBulkOperationsTest.java
Log:
Add tests of bulk deletes/updates
Added: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java 2008-02-27 17:51:32 UTC (rev 14370)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.hibernate.test.cache.jbc2.functional.bulk;
+
+
+/**
+ * Optimistic version of BulkOperationsUnitTestCase.
+ *
+ * @author Brian Stansberry
+ *
+ */
+public class OptimisticBulkOperationsTest
+ extends PessimisticBulkOperationsTest
+{
+
+ /**
+ * @param name
+ */
+ public OptimisticBulkOperationsTest(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected String getEntityCacheConfigName()
+ {
+ return "optimistic-entity";
+ }
+
+ public void testBulkOperationsFailureExpected() throws Exception
+ {
+ super.testBulkOperations();
+ }
+
+
+
+}
Property changes on: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/OptimisticBulkOperationsTest.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/PessimisticBulkOperationsTest.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/PessimisticBulkOperationsTest.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/PessimisticBulkOperationsTest.java 2008-02-27 17:51:32 UTC (rev 14370)
@@ -0,0 +1,307 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.hibernate.test.cache.jbc2.functional.bulk;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.hibernate.FlushMode;
+import org.hibernate.cache.RegionFactory;
+import org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory;
+import org.hibernate.cache.jbc2.builder.MultiplexingCacheInstanceManager;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.classic.Session;
+import org.hibernate.test.cache.jbc2.functional.CacheTestCaseBase;
+import org.hibernate.test.cache.jbc2.functional.Contact;
+import org.hibernate.test.cache.jbc2.functional.Customer;
+import org.hibernate.test.tm.SimpleJtaTransactionManagerImpl;
+import org.hibernate.transaction.CMTTransactionFactory;
+
+/**
+ * Sample client for the jboss container.
+ *
+ * @author Brian Stansberry
+ * @version $Id: EntityUnitTestCase.java 60697 2007-02-20 05:08:31Z bstansberry(a)jboss.com $
+ */
+public class PessimisticBulkOperationsTest
+extends CacheTestCaseBase
+{
+ public PessimisticBulkOperationsTest(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected Class<? extends RegionFactory> getCacheRegionFactory()
+ {
+ return MultiplexedJBossCacheRegionFactory.class;
+ }
+
+ @Override
+ protected void configureCacheFactory(Configuration cfg)
+ {
+ cfg.setProperty(MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP,
+ getEntityCacheConfigName());
+ }
+
+ protected String getEntityCacheConfigName() {
+ return "pessimistic-entity";
+ }
+
+ @Override
+ protected boolean getUseQueryCache()
+ {
+ return false;
+ }
+
+ @Override
+ protected Class getTransactionFactoryClass() {
+ return CMTTransactionFactory.class;
+ }
+
+ public void testBulkOperations() throws Exception
+ {
+ System.out.println("*** testBulkOperations()");
+ try
+ {
+ createContacts();
+
+ List<Integer> rhContacts = getContactsByCustomer("Red Hat");
+ assertNotNull("Red Hat contacts exist", rhContacts);
+ assertEquals("Created expected number of Red Hat contacts", 10, rhContacts.size());
+
+ assertEquals("Deleted all Red Hat contacts", 10, deleteContacts());
+
+ List<Integer> jbContacts = getContactsByCustomer("JBoss");
+ assertNotNull("JBoss contacts exist", jbContacts);
+ assertEquals("JBoss contacts remain", 10, jbContacts.size());
+
+ for (Integer id : rhContacts)
+ {
+ assertNull("Red Hat contact " + id + " cannot be retrieved",
+ getContact(id));
+ }
+ rhContacts = getContactsByCustomer("Red Hat");
+ if (rhContacts != null)
+ {
+ assertEquals("No Red Hat contacts remain", 0, rhContacts.size());
+ }
+
+ updateContacts("Kabir", "Updated");
+ for (Integer id : jbContacts)
+ {
+ Contact contact = getContact(id);
+ assertNotNull("JBoss contact " + id + " exists", contact);
+ String expected = ("Kabir".equals(contact.getName())) ? "Updated" : "2222";
+ assertEquals("JBoss contact " + id + " has correct TLF",
+ expected, contact.getTlf());
+ }
+
+ List<Integer> updated = getContactsByTLF("Updated");
+ assertNotNull("Got updated contacts", updated);
+ assertEquals("Updated contacts", 5, updated.size());
+ }
+ finally
+ {
+ // cleanup the db so we can run this test multiple times w/o restarting the cluster
+ cleanup();
+ }
+ }
+
+ public void createContacts() throws Exception
+ {
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+ try {
+ for (int i = 0; i < 10; i++)
+ createCustomer(i);
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ }
+ catch (Exception e) {
+ SimpleJtaTransactionManagerImpl.getInstance().rollback();
+ throw e;
+ }
+ }
+
+ public int deleteContacts() throws Exception
+ {
+ String deleteHQL = "delete Contact where customer in ";
+ deleteHQL += " (select customer FROM Customer as customer ";
+ deleteHQL += " where customer.name = :cName)";
+
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+ try {
+
+ Session session = getSessions().getCurrentSession();
+ int rowsAffected = session.createQuery(deleteHQL)
+ .setFlushMode(FlushMode.AUTO)
+ .setParameter("cName", "Red Hat")
+ .executeUpdate();
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ return rowsAffected;
+ }
+ catch (Exception e) {
+ SimpleJtaTransactionManagerImpl.getInstance().rollback();
+ throw e;
+ }
+ }
+
+ public List<Integer> getContactsByCustomer(String customerName)
+ throws Exception
+ {
+ String selectHQL = "select contact.id from Contact contact";
+ selectHQL += " where contact.customer.name = :cName";
+
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+ try {
+
+ Session session = getSessions().getCurrentSession();
+ List results = session.createQuery(selectHQL)
+ .setFlushMode(FlushMode.AUTO)
+ .setParameter("cName", customerName)
+ .list();
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ return results;
+ }
+ catch (Exception e) {
+ SimpleJtaTransactionManagerImpl.getInstance().rollback();
+ throw e;
+ }
+ }
+
+ public List<Integer> getContactsByTLF(String tlf) throws Exception
+ {
+ String selectHQL = "select contact.id from Contact contact";
+ selectHQL += " where contact.tlf = :cTLF";
+
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+ try {
+
+ Session session = getSessions().getCurrentSession();
+ List results = session.createQuery(selectHQL)
+ .setFlushMode(FlushMode.AUTO)
+ .setParameter("cTLF", tlf)
+ .list();
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ return results;
+ }
+ catch (Exception e) {
+ SimpleJtaTransactionManagerImpl.getInstance().rollback();
+ throw e;
+ }
+ }
+
+ public int updateContacts(String name, String newTLF) throws Exception
+ {
+ String updateHQL = "update Contact set tlf = :cNewTLF where name = :cName";
+
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+ try {
+
+ Session session = getSessions().getCurrentSession();
+ int rowsAffected = session.createQuery(updateHQL)
+ .setFlushMode(FlushMode.AUTO)
+ .setParameter("cNewTLF", newTLF)
+ .setParameter("cName", name)
+ .executeUpdate();
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ return rowsAffected;
+ }
+ catch (Exception e) {
+ SimpleJtaTransactionManagerImpl.getInstance().rollback();
+ throw e;
+ }
+ }
+
+ public Contact getContact(Integer id) throws Exception
+ {
+
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+ try {
+
+ Session session = getSessions().getCurrentSession();
+ Contact contact = (Contact) session.get(Contact.class, id);
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ return contact;
+ }
+ catch (Exception e) {
+ SimpleJtaTransactionManagerImpl.getInstance().rollback();
+ throw e;
+ }
+ }
+
+ public void cleanup() throws Exception
+ {
+ String deleteContactHQL = "delete from Contact";
+ String deleteCustomerHQL = "delete from Customer";
+
+ SimpleJtaTransactionManagerImpl.getInstance().begin();
+ try {
+
+ Session session = getSessions().getCurrentSession();
+ session.createQuery(deleteContactHQL)
+ .setFlushMode(FlushMode.AUTO)
+ .executeUpdate();
+ session.createQuery(deleteCustomerHQL)
+ .setFlushMode(FlushMode.AUTO)
+ .executeUpdate();
+ SimpleJtaTransactionManagerImpl.getInstance().commit();
+ }
+ catch (Exception e) {
+ SimpleJtaTransactionManagerImpl.getInstance().rollback();
+ throw e;
+ }
+
+ }
+
+ private Customer createCustomer(int id) throws Exception
+ {
+ System.out.println("CREATE CUSTOMER " + id);
+ try
+ {
+ Customer customer = new Customer();
+ customer.setName((id % 2 == 0) ? "JBoss" : "Red Hat");
+ Set<Contact> contacts = new HashSet<Contact>();
+
+ Contact kabir = new Contact();
+ kabir.setCustomer(customer);
+ kabir.setName("Kabir");
+ kabir.setTlf("1111");
+ contacts.add(kabir);
+
+ Contact bill = new Contact();
+ bill.setCustomer(customer);
+ bill.setName("Bill");
+ bill.setTlf("2222");
+ contacts.add(bill);
+
+ customer.setContacts(contacts);
+
+ getSessions().getCurrentSession().persist(customer);
+ return customer;
+ }
+ finally
+ {
+ System.out.println("CREATE CUSTOMER " + id + " - END");
+ }
+ }
+}
Property changes on: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/bulk/PessimisticBulkOperationsTest.java
___________________________________________________________________
Name: svn:executable
+ *
16 years, 11 months
Hibernate SVN: r14369 - core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-02-27 12:48:50 -0500 (Wed, 27 Feb 2008)
New Revision: 14369
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/DualNodeTestCaseBase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticEntityReplicationTest.java
Log:
Refactor configuration of TransactionFactory
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java 2008-02-27 17:47:36 UTC (rev 14368)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java 2008-02-27 17:48:50 UTC (rev 14369)
@@ -69,8 +69,11 @@
cfg.setProperty(Environment.USE_QUERY_CACHE, String.valueOf(getUseQueryCache()));
cfg.setProperty(Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName());
cfg.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, getTransactionManagerLookupClass().getName());
-// cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
+ Class transactionFactory = getTransactionFactoryClass();
+ if (transactionFactory != null)
+ cfg.setProperty( Environment.TRANSACTION_STRATEGY, transactionFactory.getName() );
+
configureCacheFactory(cfg);
}
@@ -96,6 +99,10 @@
protected Class getTransactionManagerLookupClass() {
return org.hibernate.test.tm.TransactionManagerLookupImpl.class;
}
+
+ protected Class getTransactionFactoryClass() {
+ return null;
+ }
@Override
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/DualNodeTestCaseBase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/DualNodeTestCaseBase.java 2008-02-27 17:47:36 UTC (rev 14368)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/DualNodeTestCaseBase.java 2008-02-27 17:48:50 UTC (rev 14369)
@@ -26,6 +26,7 @@
import org.hibernate.test.cache.jbc2.functional.util.DualNodeTestUtil;
import org.hibernate.test.cache.jbc2.functional.util.DualNodeTransactionManagerLookup;
import org.hibernate.test.cache.jbc2.functional.util.TestCacheInstanceManager;
+import org.hibernate.transaction.CMTTransactionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -94,6 +95,11 @@
@Override
protected Class getTransactionManagerLookupClass() {
return DualNodeTransactionManagerLookup.class;
+ }
+
+ @Override
+ protected Class getTransactionFactoryClass() {
+ return CMTTransactionFactory.class;
}
@Override
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticEntityReplicationTest.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticEntityReplicationTest.java 2008-02-27 17:47:36 UTC (rev 14368)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticEntityReplicationTest.java 2008-02-27 17:48:50 UTC (rev 14369)
@@ -68,18 +68,7 @@
{
super(name);
}
-
-
-
- @Override
- public void configure(Configuration cfg)
- {
- cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
- super.configure(cfg);
- }
-
-
@Override
protected Class<? extends RegionFactory> getCacheRegionFactory()
{
16 years, 11 months
Hibernate SVN: r14368 - in core/trunk/cache-jbosscache2/src: main/java/org/hibernate/cache/jbc2/access and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-02-27 12:47:36 -0500 (Wed, 27 Feb 2008)
New Revision: 14368
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/BasicRegionAdapter.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/access/OptimisticTransactionalAccessDelegate.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/access/TransactionalAccessDelegate.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/query/QueryResultsRegionImpl.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/ClusteredConcurrentTimestampsRegionImpl.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/TimestampsRegionImpl.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java
Log:
Redo handling of invalidated region root nodes
Modified: core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/BasicRegionAdapter.java
===================================================================
--- core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/BasicRegionAdapter.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/BasicRegionAdapter.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -31,6 +31,10 @@
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.Region;
+import org.hibernate.cache.jbc2.util.CacheHelper;
+import org.hibernate.cache.jbc2.util.NonLockingDataVersion;
import org.jboss.cache.Cache;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -39,20 +43,10 @@
import org.jboss.cache.config.Option;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.notifications.annotation.CacheListener;
-import org.jboss.cache.notifications.annotation.NodeCreated;
-import org.jboss.cache.notifications.annotation.NodeRemoved;
-import org.jboss.cache.notifications.event.NodeCreatedEvent;
-import org.jboss.cache.notifications.event.NodeRemovedEvent;
import org.jboss.cache.optimistic.DataVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.Region;
-import org.hibernate.cache.jbc2.builder.JndiMultiplexingCacheInstanceManager;
-import org.hibernate.cache.jbc2.util.CacheHelper;
-import org.hibernate.cache.jbc2.util.NonLockingDataVersion;
-
/**
* General support for writing {@link Region} implementations for JBoss Cache
* 2.x.
@@ -74,7 +68,7 @@
protected final Logger log;
protected final Object regionRootMutex = new Object();
- protected RegionRootListener listener;
+// protected RegionRootListener listener;
public BasicRegionAdapter(Cache jbcCache, String regionName, String regionPrefix) {
this.jbcCache = jbcCache;
@@ -103,17 +97,31 @@
}
}
- // If we are using replication, we may remove the root node
- // and then need to re-add it. In that case, the fact
- // that it is resident will not replicate, so use a listener
- // to set it as resident
- if (CacheHelper.isClusteredReplication(cfg.getCacheMode())
- || CacheHelper.isClusteredInvalidation(cfg.getCacheMode())) {
- listener = new RegionRootListener();
- jbcCache.addCacheListener(listener);
+// // If we are using replication, we may remove the root node
+// // and then need to re-add it. In that case, the fact
+// // that it is resident will not replicate, so use a listener
+// // to set it as resident
+// if (CacheHelper.isClusteredReplication(cfg.getCacheMode())
+// || CacheHelper.isClusteredInvalidation(cfg.getCacheMode())) {
+// listener = new RegionRootListener();
+// jbcCache.addCacheListener(listener);
+// }
+
+ regionRoot = jbcCache.getRoot().getChild( regionFqn );
+ if (regionRoot == null || !regionRoot.isValid()) {
+ // Establish the region root node with a non-locking data version
+ DataVersion version = optimistic ? NonLockingDataVersion.INSTANCE : null;
+ regionRoot = CacheHelper.addNode(jbcCache, regionFqn, true, true, version);
}
-
- establishRegionRootNode();
+ else if (optimistic && regionRoot instanceof NodeSPI) {
+ // FIXME Hacky workaround to JBCACHE-1202
+ if ( !( ( ( NodeSPI ) regionRoot ).getVersion() instanceof NonLockingDataVersion ) ) {
+ ((NodeSPI) regionRoot).setVersion(NonLockingDataVersion.INSTANCE);
+ }
+ }
+ if (!regionRoot.isResident()) {
+ regionRoot.setResident(true);
+ }
}
catch (Exception e) {
throw new CacheException(e.getMessage(), e);
@@ -123,30 +131,48 @@
private void establishRegionRootNode()
{
synchronized (regionRootMutex) {
- if (regionRoot != null && regionRoot.isValid())
+ // If we've been blocking for the mutex, perhaps another
+ // thread has already reestablished the root.
+ // In case the node was reestablised via replication, confirm it's
+ // marked "resident" (a status which doesn't replicate)
+ if (regionRoot != null && regionRoot.isValid()) {
return;
+ }
+
+ // For pessimistic locking, we just want to toss out our ref
+ // to any old invalid root node and get the latest (may be null)
+ if (!optimistic) {
+ regionRoot = jbcCache.getRoot().getChild( regionFqn );
+ return;
+ }
+
+ // The rest only matters for optimistic locking, where we
+ // need to establish the proper data version on the region root
+
// Don't hold a transactional lock for this
Transaction tx = suspend();
+ Node newRoot = null;
try {
// Make sure the root node for the region exists and
// has a DataVersion that never complains
- regionRoot = jbcCache.getRoot().getChild( regionFqn );
- if (regionRoot == null) {
+ newRoot = jbcCache.getRoot().getChild( regionFqn );
+ if (newRoot == null || !newRoot.isValid()) {
// Establish the region root node with a non-locking data version
DataVersion version = optimistic ? NonLockingDataVersion.INSTANCE : null;
- regionRoot = CacheHelper.addNode(jbcCache, regionFqn, true, true, version);
+ newRoot = CacheHelper.addNode(jbcCache, regionFqn, true, true, version);
}
- else if (optimistic && regionRoot instanceof NodeSPI) {
+ else if (newRoot instanceof NodeSPI) {
// FIXME Hacky workaround to JBCACHE-1202
- if ( !( ( ( NodeSPI ) regionRoot ).getVersion() instanceof NonLockingDataVersion ) ) {
- ((NodeSPI) regionRoot).setVersion(NonLockingDataVersion.INSTANCE);
+ if ( !( ( ( NodeSPI ) newRoot ).getVersion() instanceof NonLockingDataVersion ) ) {
+ ((NodeSPI) newRoot).setVersion(NonLockingDataVersion.INSTANCE);
}
}
- // Never evict this node
- regionRoot.setResident(true);
+ // Never evict this node
+ newRoot.setResident(true);
}
finally {
resume(tx);
+ regionRoot = newRoot;
}
}
}
@@ -164,20 +190,22 @@
}
/**
- * If the cache is configured for optimistic locking, checks for the
- * validity of the root cache node for this region,
- * creating a new one if it does not exist or is invalid. Suspends any
+ * Checks for the validity of the root cache node for this region,
+ * creating a new one if it does not exist or is invalid, and also
+ * ensuring that the root node is marked as resident. Suspends any
* transaction while doing this to ensure no transactional locks are held
* on the region root.
*
- * This is only needed for optimistic locking, as with optimistic the
- * region root node has a special version that must be established.
- *
* TODO remove this once JBCACHE-1250 is resolved.
*/
public void ensureRegionRootExists() {
- if (optimistic && (regionRoot == null || !regionRoot.isValid()))
+
+ if (regionRoot == null || !regionRoot.isValid())
establishRegionRootNode();
+
+ // Fix up the resident flag
+ if (regionRoot != null && regionRoot.isValid() && !regionRoot.isResident())
+ regionRoot.setResident(true);
}
public void destroy() throws CacheException {
@@ -202,10 +230,10 @@
} catch (Exception e) {
throw new CacheException(e);
}
- finally {
- if (listener != null)
- jbcCache.removeCacheListener(listener);
- }
+// finally {
+// if (listener != null)
+// jbcCache.removeCacheListener(listener);
+// }
}
protected void deactivateLocalNode() {
@@ -364,17 +392,17 @@
return escaped;
}
- @CacheListener
- public class RegionRootListener {
-
- @NodeCreated
- public void nodeCreated(NodeCreatedEvent event) {
- if (!event.isPre() && event.getFqn().equals(getRegionFqn())) {
- log.debug("Node created for " + getRegionFqn());
- Node regionRoot = jbcCache.getRoot().getChild(getRegionFqn());
- regionRoot.setResident(true);
- }
- }
-
- }
+// @CacheListener
+// public class RegionRootListener {
+//
+// @NodeCreated
+// public void nodeCreated(NodeCreatedEvent event) {
+// if (!event.isPre() && event.getFqn().equals(getRegionFqn())) {
+// log.debug("Node created for " + getRegionFqn());
+// Node regionRoot = jbcCache.getRoot().getChild(getRegionFqn());
+// regionRoot.setResident(true);
+// }
+// }
+//
+// }
}
Modified: core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/access/OptimisticTransactionalAccessDelegate.java
===================================================================
--- core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/access/OptimisticTransactionalAccessDelegate.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/access/OptimisticTransactionalAccessDelegate.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -169,9 +169,6 @@
Option opt = NonLockingDataVersion.getInvocationOption();
CacheHelper.removeAll(cache, regionFqn, opt);
-
- // Restablish the region root node with a non-locking data version
- CacheHelper.addNode(cache, regionFqn, false, true, NonLockingDataVersion.INSTANCE);
}
}
Modified: core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/access/TransactionalAccessDelegate.java
===================================================================
--- core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/access/TransactionalAccessDelegate.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/access/TransactionalAccessDelegate.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -56,16 +56,23 @@
}
public Object get(Object key, long txTimestamp) throws CacheException {
+
+ region.ensureRegionRootExists();
+
return CacheHelper.get(cache, regionFqn, key);
}
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException {
+
+ region.ensureRegionRootExists();
return CacheHelper.putForExternalRead(cache, regionFqn, key, value);
}
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException {
+
+ region.ensureRegionRootExists();
// We ignore minimalPutOverride. JBossCache putForExternalRead is
// already about as minimal as we can get; it will promptly return
@@ -88,6 +95,8 @@
}
public boolean insert(Object key, Object value, Object version) throws CacheException {
+
+ region.ensureRegionRootExists();
CacheHelper.put(cache, regionFqn, key, value);
return true;
@@ -99,6 +108,8 @@
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException {
+
+ region.ensureRegionRootExists();
CacheHelper.put(cache, regionFqn, key, value);
return true;
@@ -110,6 +121,8 @@
}
public void remove(Object key) throws CacheException {
+
+ region.ensureRegionRootExists();
CacheHelper.remove(cache, regionFqn, key);
}
@@ -119,6 +132,9 @@
}
public void evict(Object key) throws CacheException {
+
+ region.ensureRegionRootExists();
+
CacheHelper.remove(cache, regionFqn, key);
}
@@ -127,8 +143,6 @@
}
private void evictOrRemoveAll() throws CacheException {
- CacheHelper.removeAll(cache, regionFqn);
- // Restore the region root node
- CacheHelper.addNode(cache, regionFqn, false, true, null);
+ CacheHelper.removeAll(cache, regionFqn);
}
}
Modified: core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/query/QueryResultsRegionImpl.java
===================================================================
--- core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/query/QueryResultsRegionImpl.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/query/QueryResultsRegionImpl.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -89,8 +89,6 @@
if (localOnly)
opt.setCacheModeLocal(true);
CacheHelper.removeAll(getCacheInstance(), getRegionFqn(), opt);
- // Restore the region root node
- CacheHelper.addNode(getCacheInstance(), getRegionFqn(), false, true, null);
}
public Object get(Object key) throws CacheException {
Modified: core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/ClusteredConcurrentTimestampsRegionImpl.java
===================================================================
--- core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/ClusteredConcurrentTimestampsRegionImpl.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/ClusteredConcurrentTimestampsRegionImpl.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -93,8 +93,6 @@
public void evictAll() throws CacheException {
Option opt = getNonLockingDataVersionOption(true);
CacheHelper.removeAll(getCacheInstance(), getRegionFqn(), opt);
- // Restore the region root node
- CacheHelper.addNode(getCacheInstance(), getRegionFqn(), false, true, null);
}
public Object get(Object key) throws CacheException {
Modified: core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/TimestampsRegionImpl.java
===================================================================
--- core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/TimestampsRegionImpl.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/TimestampsRegionImpl.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -97,8 +97,6 @@
// TODO Is this a valid operation on a timestamps cache?
Option opt = getNonLockingDataVersionOption(true);
CacheHelper.removeAll(getCacheInstance(), getRegionFqn(), opt);
- // Restore the region root node
- CacheHelper.addNode(getCacheInstance(), getRegionFqn(), false, true, null);
}
public Object get(Object key) throws CacheException {
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -212,42 +212,35 @@
localRegion.evictAll();
+ // This should re-establish the region root node in the optimistic case
+ assertNull(localRegion.get(KEY));
+
regionRoot = localCache.getRoot().getChild(regionFqn);
- assertFalse(regionRoot == null);
- assertEquals(0, regionRoot.getChildrenNames().size());
- assertTrue(regionRoot.isResident());
-
- if (CacheHelper.isClusteredInvalidation(remoteCache)) {
- // With invalidation, a node that removes the region root cannot reestablish
- // it on remote nodes, since the only message the propagates is "invalidate".
- // So, we have to reestablish it ourselves
-
- // First, do a get to help test whether a get messes up the optimistic version
- String msg = "Known issue JBCACHE-1251 -- problem reestablishing invalidated region root";
- try {
- assertEquals(null, remoteRegion.get(KEY));
- }
- catch (CacheException ce) {
- log.error(msg, ce);
- fail(msg + " -- cause: " + ce);
- }
- remoteRegion.put(KEY, VALUE1);
- assertEquals(msg, VALUE1, remoteRegion.get(KEY));
+ if (optimistic) {
+ assertFalse(regionRoot == null);
+ assertEquals(0, regionRoot.getChildrenNames().size());
+ assertTrue(regionRoot.isValid());
+ assertTrue(regionRoot.isResident());
}
-
+ else {
+ assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
+ }
+
+ // Re-establishing the region root on the local node doesn't
+ // propagate it to other nodes. Do a get on the remote node to re-establish
+ // This only adds a node in the case of optimistic locking
+ assertEquals(null, remoteRegion.get(KEY));
+
regionRoot = remoteCache.getRoot().getChild(regionFqn);
- assertFalse(regionRoot == null);
- if (invalidation) {
- // JBC seems broken: see http://www.jboss.com/index.html?module=bb&op=viewtopic&t=121408
- // FIXME replace with the following when JBCACHE-1199 and JBCACHE-1200 are done:
- //assertFalse(regionRoot.isValid());
- checkNodeIsEmpty(regionRoot);
+ if (optimistic) {
+ assertFalse(regionRoot == null);
+ assertEquals(0, regionRoot.getChildrenNames().size());
+ assertTrue(regionRoot.isValid());
+ assertTrue(regionRoot.isResident());
}
else {
- // Same assertion, just different assertion msg
- assertEquals(0, regionRoot.getChildrenNames().size());
- }
- assertTrue(regionRoot.isResident());
+ assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
+ }
assertEquals("local is clean", null, localRegion.get(KEY));
assertEquals("remote is clean", null, remoteRegion.get(KEY));
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -460,8 +460,6 @@
// Wait for async propagation
sleep(250);
-
-
if (isUsingOptimisticLocking()) {
regionRoot = localCache.getRoot().getChild(regionFqn);
assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
@@ -474,43 +472,54 @@
else
localAccessStrategy.removeAll();
+ // This should re-establish the region root node in the optimistic case
+ assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));
+
regionRoot = localCache.getRoot().getChild(regionFqn);
- assertFalse(regionRoot == null);
- assertEquals(0, getValidChildrenCount(regionRoot));
- assertTrue(regionRoot.isResident());
-
- if (isUsingInvalidation()) {
- // With invalidation, a node that removes the region root cannot reestablish
- // it on remote nodes, since the only message the propagates is "invalidate".
- // So, we have to reestablish it ourselves
-
- // First, do a get to help test whether a get messes up the optimistic version
- String msg = "Known issue JBCACHE-1251 -- problem reestablishing invalidated region root";
- try {
- assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
- }
- catch (CacheException ce) {
- log.error(msg, ce);
- fail(msg + " -- cause: " + ce);
- }
- remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
- assertEquals(msg, VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
+ if (isUsingOptimisticLocking()) {
+ assertFalse(regionRoot == null);
+ assertEquals(0, getValidChildrenCount(regionRoot));
+ assertTrue(regionRoot.isValid());
+ assertTrue(regionRoot.isResident());
}
+ else {
+ assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
+ }
+ // Re-establishing the region root on the local node doesn't
+ // propagate it to other nodes. Do a get on the remote node to re-establish
+ // This only adds a node in the case of optimistic locking
+ assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
+
regionRoot = remoteCache.getRoot().getChild(regionFqn);
+ if (isUsingOptimisticLocking()) {
+ assertFalse(regionRoot == null);
+ assertTrue(regionRoot.isValid());
+ assertTrue(regionRoot.isResident());
+ // Not invalidation, so we didn't insert a child above
+ assertEquals(0, getValidChildrenCount(regionRoot));
+ }
+ else {
+ assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
+ }
+
+ // Test whether the get above messes up the optimistic version
+ remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
+ assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
+
+ // Revalidate the region root
+ regionRoot = remoteCache.getRoot().getChild(regionFqn);
assertFalse(regionRoot == null);
- if (isUsingInvalidation()) {
- // Region root should have 1 child -- the one we added above
- assertEquals(1, getValidChildrenCount(regionRoot));
- }
- else {
- // Same assertion, just different assertion msg
- assertEquals(0, getValidChildrenCount(regionRoot));
- }
+ assertTrue(regionRoot.isValid());
assertTrue(regionRoot.isResident());
+ // Region root should have 1 child -- the one we added above
+ assertEquals(1, getValidChildrenCount(regionRoot));
- assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
- assertEquals("remote is correct", (isUsingInvalidation() ? VALUE1 : null), remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
+ // Wait for async propagation of the putFromLoad
+ sleep(250);
+
+ assertEquals("local is correct", (isUsingInvalidation() ? null : VALUE1), localAccessStrategy.get(KEY, System.currentTimeMillis()));
+ assertEquals("remote is correct", VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
}
private int getValidChildrenCount(Node node) {
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java 2008-02-27 15:31:40 UTC (rev 14367)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java 2008-02-27 17:47:36 UTC (rev 14368)
@@ -24,7 +24,6 @@
package org.hibernate.test.cache.jbc2.entity;
import java.util.Iterator;
-import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -34,7 +33,6 @@
import junit.framework.TestSuite;
import org.hibernate.cache.CacheDataDescription;
-import org.hibernate.cache.CacheException;
import org.hibernate.cache.EntityRegion;
import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.access.EntityRegionAccessStrategy;
@@ -684,43 +682,53 @@
else
localAccessStrategy.removeAll();
+ // This should re-establish the region root node in the optimistic case
+ assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));
+
regionRoot = localCache.getRoot().getChild(regionFqn);
- assertFalse(regionRoot == null);
- assertEquals(0, getValidChildrenCount(regionRoot));
- assertTrue(regionRoot.isResident());
+ if (isUsingOptimisticLocking()) {
+ assertFalse(regionRoot == null);
+ assertEquals(0, getValidChildrenCount(regionRoot));
+ assertTrue(regionRoot.isValid());
+ assertTrue(regionRoot.isResident());
+ }
+ else {
+ assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
+ }
- if (isUsingInvalidation()) {
- // With invalidation, a node that removes the region root cannot reestablish
- // it on remote nodes, since the only message the propagates is "invalidate".
- // So, we have to reestablish it ourselves
-
- // First, do a get to help test whether a get messes up the optimistic version
- String msg = "Known issue JBCACHE-1251 -- problem reestablishing invalidated region root";
- try {
- assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
- }
- catch (CacheException ce) {
- log.error(msg, ce);
- fail(msg + " -- cause: " + ce);
- }
- remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
- assertEquals(msg, VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
- }
+ // Re-establishing the region root on the local node doesn't
+ // propagate it to other nodes. Do a get on the remote node to re-establish
+ assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
+
+ regionRoot = remoteCache.getRoot().getChild(regionFqn);
+ if (isUsingOptimisticLocking()) {
+ assertFalse(regionRoot == null);
+ assertTrue(regionRoot.isValid());
+ assertTrue(regionRoot.isResident());
+ // Not invalidation, so we didn't insert a child above
+ assertEquals(0, getValidChildrenCount(regionRoot));
+ }
+ else {
+ assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());
+ }
+ // Test whether the get above messes up the optimistic version
+ remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
+ assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
+
+ // Revalidate the region root
regionRoot = remoteCache.getRoot().getChild(regionFqn);
assertFalse(regionRoot == null);
- if (isUsingInvalidation()) {
- // Region root should have 1 child -- the one we added above
- assertEquals(1, getValidChildrenCount(regionRoot));
- }
- else {
- // Same assertion, just different assertion msg
- assertEquals(0, getValidChildrenCount(regionRoot));
- }
+ assertTrue(regionRoot.isValid());
assertTrue(regionRoot.isResident());
+ // Region root should have 1 child -- the one we added above
+ assertEquals(1, getValidChildrenCount(regionRoot));
- assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
- assertEquals("remote is correct", (isUsingInvalidation() ? VALUE1 : null), remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
+ // Wait for async propagation
+ sleep(250);
+
+ assertEquals("local is correct", (isUsingInvalidation() ? null : VALUE1), localAccessStrategy.get(KEY, System.currentTimeMillis()));
+ assertEquals("remote is correct", VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
}
private int getValidChildrenCount(Node node) {
16 years, 11 months
Hibernate SVN: r14367 - in core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test: util and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-02-27 10:31:40 -0500 (Wed, 27 Feb 2008)
New Revision: 14367
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/optimistic-local-cache.xml
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/pessimistic-local-cache.xml
Log:
Remove deprecated JGroups attributes
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml 2008-02-26 21:54:02 UTC (rev 14366)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml 2008-02-27 15:31:40 UTC (rev 14367)
@@ -105,13 +105,11 @@
<FD shun="true"/>
<FD_SOCK/>
<VERIFY_SUSPECT timeout="1500"/>
- <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
- max_xmit_size="8192"/>
- <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"/>
+ <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"/>
+ <UNICAST timeout="600,1200,2400" min_threshold="10"/>
<pbcast.STABLE desired_avg_gossip="20000"/>
<FRAG frag_size="8192"/>
- <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
- shun="true" print_local_addr="true"/>
+ <pbcast.GMS join_timeout="5000" shun="true" print_local_addr="true"/>
<pbcast.STATE_TRANSFER/>
</config>
</attribute>
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml 2008-02-26 21:54:02 UTC (rev 14366)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml 2008-02-27 15:31:40 UTC (rev 14367)
@@ -89,10 +89,9 @@
<VERIFY_SUSPECT timeout="1500"/>
<pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"/>
<pbcast.STABLE desired_avg_gossip="20000"/>
- <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"/>
+ <UNICAST timeout="600,1200,2400" min_threshold="10"/>
<FRAG frag_size="8192"/>
- <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
- shun="true" print_local_addr="true"/>
+ <pbcast.GMS join_timeout="5000" shun="true" print_local_addr="true"/>
<pbcast.STATE_TRANSFER/>
</config>
</attribute>
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/optimistic-local-cache.xml
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/optimistic-local-cache.xml 2008-02-26 21:54:02 UTC (rev 14366)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/optimistic-local-cache.xml 2008-02-27 15:31:40 UTC (rev 14367)
@@ -105,13 +105,11 @@
<FD shun="true"/>
<FD_SOCK/>
<VERIFY_SUSPECT timeout="1500"/>
- <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
- max_xmit_size="8192"/>
- <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"/>
+ <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"/>
+ <UNICAST timeout="600,1200,2400" min_threshold="10"/>
<pbcast.STABLE desired_avg_gossip="20000"/>
<FRAG frag_size="8192"/>
- <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
- shun="true" print_local_addr="true"/>
+ <pbcast.GMS join_timeout="5000" shun="true" print_local_addr="true"/>
<pbcast.STATE_TRANSFER/>
</config>
</attribute>
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/pessimistic-local-cache.xml
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/pessimistic-local-cache.xml 2008-02-26 21:54:02 UTC (rev 14366)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/pessimistic-local-cache.xml 2008-02-27 15:31:40 UTC (rev 14367)
@@ -89,10 +89,9 @@
<VERIFY_SUSPECT timeout="1500"/>
<pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"/>
<pbcast.STABLE desired_avg_gossip="20000"/>
- <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"/>
+ <UNICAST timeout="600,1200,2400" min_threshold="10"/>
<FRAG frag_size="8192"/>
- <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
- shun="true" print_local_addr="true"/>
+ <pbcast.GMS join_timeout="5000" shun="true" print_local_addr="true"/>
<pbcast.STATE_TRANSFER/>
</config>
</attribute>
16 years, 11 months
Hibernate SVN: r14366 - core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-02-26 16:54:02 -0500 (Tue, 26 Feb 2008)
New Revision: 14366
Modified:
core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/configuration.xml
core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/introduction.xml
Log:
Document JTA requirement
Modified: core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/configuration.xml 2008-02-26 18:53:26 UTC (rev 14365)
+++ core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/configuration.xml 2008-02-26 21:54:02 UTC (rev 14366)
@@ -37,11 +37,20 @@
<title>Basics</title>
<para>
- There are four basic steps to configuring the
+ There are five basic steps to configuring the
<literal>SessionFactory</literal>:
<itemizedlist>
+
<listitem>
+ <para>
+ Make sure your Hibernate is configured to use JTA transactions.
+ See <xref linkend="introduction-requirements-transactions"/>
+ for details.
+ </para>
+ </listitem>
+
+ <listitem>
<para>
Tell Hibernate you whether to enable caching of entities and
collections. No need to set this property if you don't:
Modified: core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/introduction.xml
===================================================================
--- core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/introduction.xml 2008-02-26 18:53:26 UTC (rev 14365)
+++ core/trunk/documentation/jbosscache2/src/main/docbook/en-US/content/introduction.xml 2008-02-26 21:54:02 UTC (rev 14366)
@@ -65,6 +65,8 @@
<sect1 id="introduction-requirements" revision="1">
<title>Requirements</title>
+ <sect2 id="introduction-requirements-dependencies" revision="1">
+ <title>Dependencies</title>
<para>
Second level caching with JBoss Cache 2 requires the use of JBoss
Cache 2.1.0 or later. The core JBoss Cache project is used; the
@@ -104,7 +106,44 @@
and tell the <literal>SessionFactory</literal> to use them; see
<xref linkend="sessionfactory"/> for details.
</para>
+ </sect2>
+ <sect2 id="introduction-requirements-transactions" revision="1">
+ <title>JTA Transactional Support</title>
+ <para>
+ JBoss Cache requires integration with a JTA
+ <literal>TransactionManager</literal> in order to meet the requirements
+ of the second level caching use case. This means your Hibernate
+ application must be configured to use JTA:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ You must configure a <literal>hibernate.transaction.manager_lookup_class</literal>.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ You must configure a <literal>hibernate.transaction.factory_class</literal>,
+ specifying a transaction factory that supports JTA. In practice, this means
+ <literal>org.hibernate.transaction.JTATransactionFactory</literal> if
+ you are using JTA directly, or <literal>org.hibernate.transaction.CMTTransactionFactory</literal>
+ if you are accessing Hibernate via a CMT session bean.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Finally, make sure <literal>hibernate.current_session_context_class</literal>
+ is either unset (backwards compatiblity), or set to <literal>"jta"</literal>.
+ </para>
+ </listitem>
+ </itemizedlist>
+
+ <para>
+ See the <emphasis>Hibernate Reference Documentation</emphasis> for
+ an in-depth discussion of using Hibernate with JTA
+ </para>
+ </sect2>
</sect1>
<sect1 id="introduction-configuration" revision="1">
16 years, 11 months
Hibernate SVN: r14365 - annotations/trunk/src/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-02-26 13:53:26 -0500 (Tue, 26 Feb 2008)
New Revision: 14365
Modified:
annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java
Log:
ANN-699 Wrong Javassist field handler type
Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java 2008-02-25 23:20:08 UTC (rev 14364)
+++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java 2008-02-26 18:53:26 UTC (rev 14365)
@@ -1093,7 +1093,7 @@
//TODO make those hardcoded tests more portable (through the bytecode provider?)
return property.isAnnotationPresent( Transient.class )
|| "net.sf.cglib.transform.impl.InterceptFieldCallback".equals( property.getType().getName() )
- || "org.hibernate.tool.instrument.javassist.FieldHandler".equals( property.getType().getName() );
+ || "org.hibernate.bytecode.javassist.FieldHandler".equals( property.getType().getName() );
}
/**
16 years, 11 months
Hibernate SVN: r14364 - in core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional: util and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-02-25 18:20:08 -0500 (Mon, 25 Feb 2008)
New Revision: 14364
Added:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeConnectionProviderImpl.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionImpl.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionManagerImpl.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeTestUtil.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeTransactionManagerLookup.java
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/DualNodeTestCaseBase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticEntityReplicationTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/TestCacheInstanceManager.java
Log:
Isolate the transaction managers between the primary environment and the second node environment
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java 2008-02-25 21:06:19 UTC (rev 14363)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -29,7 +29,6 @@
import org.hibernate.cfg.Mappings;
import org.hibernate.dialect.Dialect;
import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.transaction.CMTTransactionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,9 +67,9 @@
cfg.setProperty(Environment.CACHE_REGION_FACTORY, getCacheRegionFactory().getName());
cfg.setProperty(Environment.USE_QUERY_CACHE, String.valueOf(getUseQueryCache()));
- cfg.setProperty(Environment.CONNECTION_PROVIDER, org.hibernate.test.tm.ConnectionProviderImpl.class.getName());
- cfg.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, org.hibernate.test.tm.TransactionManagerLookupImpl.class.getName());
- cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
+ cfg.setProperty(Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName());
+ cfg.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, getTransactionManagerLookupClass().getName());
+// cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
configureCacheFactory(cfg);
}
@@ -89,6 +88,14 @@
protected abstract Class<? extends RegionFactory> getCacheRegionFactory();
protected abstract boolean getUseQueryCache();
+
+ protected Class getConnectionProviderClass() {
+ return org.hibernate.test.tm.ConnectionProviderImpl.class;
+ }
+
+ protected Class getTransactionManagerLookupClass() {
+ return org.hibernate.test.tm.TransactionManagerLookupImpl.class;
+ }
@Override
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/DualNodeTestCaseBase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/DualNodeTestCaseBase.java 2008-02-25 21:06:19 UTC (rev 14363)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/DualNodeTestCaseBase.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -22,6 +22,10 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.junit.functional.ExecutionEnvironment;
+import org.hibernate.test.cache.jbc2.functional.util.DualNodeConnectionProviderImpl;
+import org.hibernate.test.cache.jbc2.functional.util.DualNodeTestUtil;
+import org.hibernate.test.cache.jbc2.functional.util.DualNodeTransactionManagerLookup;
+import org.hibernate.test.cache.jbc2.functional.util.TestCacheInstanceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,6 +39,8 @@
{
private static final Logger log = LoggerFactory.getLogger( CacheTestCaseBase.class );
+ public static final String CACHE_MANAGER_NAME_PROP = "hibernate.test.cluster.node.id";
+
private ExecutionEnvironment secondNodeEnvironment;
private org.hibernate.classic.Session secondNodeSession;
@@ -64,14 +70,31 @@
*
* @param the Configuration to update.
*/
- protected abstract void configureFirstNode(Configuration cfg);
-
+ protected void configureFirstNode(Configuration cfg)
+ {
+ cfg.setProperty(DualNodeTestUtil.NODE_ID_PROP,
+ DualNodeTestUtil.LOCAL);
+ }
/**
* Apply any node-specific configurations to our second node.
*
* @param the Configuration to update.
*/
- protected abstract void configureSecondNode(Configuration cfg);
+ protected void configureSecondNode(Configuration cfg)
+ {
+ cfg.setProperty(DualNodeTestUtil.NODE_ID_PROP,
+ DualNodeTestUtil.REMOTE);
+ }
+
+ @Override
+ protected Class getConnectionProviderClass() {
+ return DualNodeConnectionProviderImpl.class;
+ }
+
+ @Override
+ protected Class getTransactionManagerLookupClass() {
+ return DualNodeTransactionManagerLookup.class;
+ }
@Override
protected void prepareTest() throws Exception
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticEntityReplicationTest.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticEntityReplicationTest.java 2008-02-25 21:06:19 UTC (rev 14363)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/PessimisticEntityReplicationTest.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -34,8 +34,11 @@
import org.hibernate.cache.RegionFactory;
import org.hibernate.cache.jbc2.builder.MultiplexingCacheInstanceManager;
import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.test.cache.jbc2.functional.util.DualNodeTestUtil;
import org.hibernate.test.cache.jbc2.functional.util.TestCacheInstanceManager;
import org.hibernate.test.cache.jbc2.functional.util.TestJBossCacheRegionFactory;
+import org.hibernate.transaction.CMTTransactionFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheManager;
import org.jboss.cache.Fqn;
@@ -55,11 +58,8 @@
{
protected final Logger log = LoggerFactory.getLogger(getClass());
- private static final long SLEEP_TIME = 100l;
+ private static final long SLEEP_TIME = 50l;
- private static final String LOCAL = "local";
- private static final String REMOTE = "remote";
-
private static final Integer CUSTOMER_ID = new Integer(1);
static int test = 0;
@@ -74,6 +74,7 @@
@Override
public void configure(Configuration cfg)
{
+ cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
super.configure(cfg);
}
@@ -97,21 +98,7 @@
cfg.setProperty(MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP,
getEntityCacheConfigName());
}
-
- @Override
- protected void configureFirstNode(Configuration cfg)
- {
- cfg.setProperty(TestCacheInstanceManager.CACHE_MANAGER_NAME_PROP,
- LOCAL);
- }
- @Override
- protected void configureSecondNode(Configuration cfg)
- {
- cfg.setProperty(TestCacheInstanceManager.CACHE_MANAGER_NAME_PROP,
- REMOTE);
- }
-
protected String getEntityCacheConfigName() {
return "pessimistic-shared";
}
@@ -123,7 +110,7 @@
// Bind a listener to the "local" cache
// Our region factory makes its CacheManager available to us
- CacheManager localManager = TestCacheInstanceManager.getTestCacheManager(LOCAL);
+ CacheManager localManager = TestCacheInstanceManager.getTestCacheManager(DualNodeTestUtil.LOCAL);
Cache localCache = localManager.getCache(getEntityCacheConfigName(), true);
MyListener localListener = new MyListener();
localCache.addCacheListener(localListener);
@@ -131,7 +118,7 @@
TransactionManager localTM = localCache.getConfiguration().getRuntimeConfig().getTransactionManager();
// Bind a listener to the "remote" cache
- CacheManager remoteManager = TestCacheInstanceManager.getTestCacheManager(REMOTE);
+ CacheManager remoteManager = TestCacheInstanceManager.getTestCacheManager(DualNodeTestUtil.REMOTE);
Cache remoteCache = remoteManager.getCache(getEntityCacheConfigName(), true);
MyListener remoteListener = new MyListener();
remoteCache.addCacheListener(remoteListener);
@@ -154,7 +141,9 @@
// This actually brings the collection into the cache
getCustomer(ids.customerId, localFactory, localTM);
- // Now the collection is in the cache so, we the 2nd "get"
+ sleep(SLEEP_TIME);
+
+ // Now the collection is in the cache so, the 2nd "get"
// should read everything from the cache
System.out.println("Find(2) node 0");
localListener.clear();
@@ -163,10 +152,6 @@
//Check the read came from the cache
System.out.println("Check cache 0");
assertLoadedFromCache(localListener, ids.customerId, ids.contactIds);
-
- // The above placement of the collection in the cache is replicated async
- // so pause a bit before checking node 1
- sleep(SLEEP_TIME);
System.out.println("Find node 1");
getCustomer(ids.customerId, remoteFactory, remoteTM);
Added: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeConnectionProviderImpl.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeConnectionProviderImpl.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeConnectionProviderImpl.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -0,0 +1,86 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, 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.cache.jbc2.functional.util;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.hibernate.HibernateException;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.connection.ConnectionProviderFactory;
+
+/**
+ * A {@link ConnectionProvider} implementation adding JTA-style transactionality
+ * around the returned connections using the {@link DualNodeJtaTransactionManagerImpl}.
+ *
+ * @author Brian Stansberry
+ */
+public class DualNodeConnectionProviderImpl implements ConnectionProvider {
+ private static ConnectionProvider actualConnectionProvider = ConnectionProviderFactory.newConnectionProvider();
+
+ private String nodeId;
+ private boolean isTransactional;
+
+ public static ConnectionProvider getActualConnectionProvider() {
+ return actualConnectionProvider;
+ }
+
+ public void configure(Properties props) throws HibernateException {
+ nodeId = props.getProperty(DualNodeTestUtil.NODE_ID_PROP);
+ if (nodeId == null)
+ throw new HibernateException(DualNodeTestUtil.NODE_ID_PROP + " not configured");
+ }
+
+ public Connection getConnection() throws SQLException {
+ DualNodeJtaTransactionImpl currentTransaction = DualNodeJtaTransactionManagerImpl.getInstance(nodeId).getCurrentTransaction();
+ if ( currentTransaction == null ) {
+ isTransactional = false;
+ return actualConnectionProvider.getConnection();
+ }
+ else {
+ isTransactional = true;
+ Connection connection = currentTransaction.getEnlistedConnection();
+ if ( connection == null ) {
+ connection = actualConnectionProvider.getConnection();
+ currentTransaction.enlistConnection( connection );
+ }
+ return connection;
+ }
+ }
+
+ public void closeConnection(Connection conn) throws SQLException {
+ if ( !isTransactional ) {
+ conn.close();
+ }
+ }
+
+ public void close() throws HibernateException {
+ actualConnectionProvider.close();
+ }
+
+ public boolean supportsAggressiveRelease() {
+ return true;
+ }
+}
Added: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionImpl.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionImpl.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionImpl.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -0,0 +1,160 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, 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.cache.jbc2.functional.util;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.LinkedList;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.xa.XAResource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SimpleJtaTransactionImpl variant that works with DualNodeTransactionManagerImpl.
+ *
+ * @author Brian Stansberry
+ */
+public class DualNodeJtaTransactionImpl implements Transaction {
+ private static final Logger log = LoggerFactory.getLogger( DualNodeJtaTransactionImpl.class );
+
+ private int status;
+ private LinkedList synchronizations;
+ private Connection connection; // the only resource we care about is jdbc connection
+ private final DualNodeJtaTransactionManagerImpl jtaTransactionManager;
+
+ public DualNodeJtaTransactionImpl(DualNodeJtaTransactionManagerImpl jtaTransactionManager) {
+ this.jtaTransactionManager = jtaTransactionManager;
+ this.status = Status.STATUS_ACTIVE;
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void commit()
+ throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
+
+ if ( status == Status.STATUS_MARKED_ROLLBACK ) {
+ log.trace( "on commit, status was marked for rollback-only" );
+ rollback();
+ }
+ else {
+ status = Status.STATUS_PREPARING;
+
+ for ( int i = 0; i < synchronizations.size(); i++ ) {
+ Synchronization s = ( Synchronization ) synchronizations.get( i );
+ s.beforeCompletion();
+ }
+
+ status = Status.STATUS_COMMITTING;
+
+ if ( connection != null ) {
+ try {
+ connection.commit();
+ connection.close();
+ }
+ catch ( SQLException sqle ) {
+ status = Status.STATUS_UNKNOWN;
+ throw new SystemException();
+ }
+ }
+
+ status = Status.STATUS_COMMITTED;
+
+ for ( int i = 0; i < synchronizations.size(); i++ ) {
+ Synchronization s = ( Synchronization ) synchronizations.get( i );
+ s.afterCompletion( status );
+ }
+
+ //status = Status.STATUS_NO_TRANSACTION;
+ jtaTransactionManager.endCurrent( this );
+ }
+ }
+
+ public void rollback() throws IllegalStateException, SystemException {
+ status = Status.STATUS_ROLLEDBACK;
+
+ if ( connection != null ) {
+ try {
+ connection.rollback();
+ connection.close();
+ }
+ catch ( SQLException sqle ) {
+ status = Status.STATUS_UNKNOWN;
+ throw new SystemException();
+ }
+ }
+
+ for ( int i = 0; i < synchronizations.size(); i++ ) {
+ Synchronization s = ( Synchronization ) synchronizations.get( i );
+ s.afterCompletion( status );
+ }
+
+ //status = Status.STATUS_NO_TRANSACTION;
+ jtaTransactionManager.endCurrent( this );
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException {
+ status = Status.STATUS_MARKED_ROLLBACK;
+ }
+
+ public void registerSynchronization(Synchronization synchronization)
+ throws RollbackException, IllegalStateException, SystemException {
+ // todo : find the spec-allowable statuses during which synch can be registered...
+ if ( synchronizations == null ) {
+ synchronizations = new LinkedList();
+ }
+ synchronizations.add( synchronization );
+ }
+
+ public void enlistConnection(Connection connection) {
+ if ( this.connection != null ) {
+ throw new IllegalStateException( "Connection already registered" );
+ }
+ this.connection = connection;
+ }
+
+ public Connection getEnlistedConnection() {
+ return connection;
+ }
+
+
+ public boolean enlistResource(XAResource xaResource)
+ throws RollbackException, IllegalStateException, SystemException {
+ return false;
+ }
+
+ public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException {
+ return false;
+ }
+}
Added: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionManagerImpl.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionManagerImpl.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionManagerImpl.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -0,0 +1,115 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, 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.cache.jbc2.functional.util;
+
+import java.util.Hashtable;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * Variant of SimpleJtaTransactionManagerImpl that doesn't use a VM-singleton,
+ * but rather a set of impls keyed by a node id.
+ *
+ * @author Brian Stansberry
+ */
+public class DualNodeJtaTransactionManagerImpl implements TransactionManager {
+ private static final Hashtable INSTANCES = new Hashtable();
+
+ private DualNodeJtaTransactionImpl currentTransaction;
+
+ public synchronized static DualNodeJtaTransactionManagerImpl getInstance(String nodeId) {
+ DualNodeJtaTransactionManagerImpl tm = (DualNodeJtaTransactionManagerImpl) INSTANCES.get(nodeId);
+ if (tm == null) {
+ tm = new DualNodeJtaTransactionManagerImpl();
+ INSTANCES.put(nodeId, tm);
+ }
+ return tm;
+ }
+
+ public int getStatus() throws SystemException {
+ return currentTransaction == null ? Status.STATUS_NO_TRANSACTION : currentTransaction.getStatus();
+ }
+
+ public Transaction getTransaction() throws SystemException {
+ return currentTransaction;
+ }
+
+ public DualNodeJtaTransactionImpl getCurrentTransaction() {
+ return currentTransaction;
+ }
+
+ public void begin() throws NotSupportedException, SystemException {
+ currentTransaction = new DualNodeJtaTransactionImpl( this );
+ }
+
+ public Transaction suspend() throws SystemException {
+ DualNodeJtaTransactionImpl suspended = currentTransaction;
+ currentTransaction = null;
+ return suspended;
+ }
+
+ public void resume(Transaction transaction)
+ throws InvalidTransactionException, IllegalStateException, SystemException {
+ currentTransaction = ( DualNodeJtaTransactionImpl ) transaction;
+ }
+
+ public void commit()
+ throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
+ if ( currentTransaction == null ) {
+ throw new IllegalStateException( "no current transaction to commit" );
+ }
+ currentTransaction.commit();
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException, SystemException {
+ if ( currentTransaction == null ) {
+ throw new IllegalStateException( "no current transaction" );
+ }
+ currentTransaction.rollback();
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException {
+ if ( currentTransaction == null ) {
+ throw new IllegalStateException( "no current transaction" );
+ }
+ currentTransaction.setRollbackOnly();
+ }
+
+ public void setTransactionTimeout(int i) throws SystemException {
+ }
+
+ void endCurrent(DualNodeJtaTransactionImpl transaction) {
+ if ( transaction == currentTransaction ) {
+ currentTransaction = null;
+ }
+ }
+}
Added: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeTestUtil.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeTestUtil.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeTestUtil.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Brian Stansberry
+ */
+
+package org.hibernate.test.cache.jbc2.functional.util;
+
+/**
+ * A DualNodeTestUtil.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class DualNodeTestUtil
+{
+ public static final String NODE_ID_PROP = "hibernate.test.cluster.node.id";
+
+ public static final String LOCAL = "local";
+ public static final String REMOTE = "remote";
+}
Added: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeTransactionManagerLookup.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeTransactionManagerLookup.java (rev 0)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeTransactionManagerLookup.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, 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.cache.jbc2.functional.util;
+
+import java.util.Properties;
+import javax.transaction.TransactionManager;
+
+import org.hibernate.transaction.TransactionManagerLookup;
+import org.hibernate.HibernateException;
+
+/**
+ * SimpleJtaTransactionManagerLookupImpl subclass that finds a different
+ * DualNodeTransactionManager based on the value of property
+ * {@link DualNodeTestUtil#NODE_ID_PROP}.
+ *
+ * @author Brian Stansberry
+ */
+public class DualNodeTransactionManagerLookup implements TransactionManagerLookup {
+
+ public TransactionManager getTransactionManager(Properties props) throws HibernateException {
+ String nodeId = props.getProperty(DualNodeTestUtil.NODE_ID_PROP);
+ if (nodeId == null)
+ throw new HibernateException(DualNodeTestUtil.NODE_ID_PROP + " not configured");
+ return DualNodeJtaTransactionManagerImpl.getInstance(nodeId);
+ }
+
+ public String getUserTransactionName() {
+ throw new UnsupportedOperationException( "jndi currently not implemented for these tests" );
+ }
+}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/TestCacheInstanceManager.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/TestCacheInstanceManager.java 2008-02-25 21:06:19 UTC (rev 14363)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/TestCacheInstanceManager.java 2008-02-25 23:20:08 UTC (rev 14364)
@@ -43,8 +43,6 @@
private static final Hashtable cacheManagers = new Hashtable();
- public static final String CACHE_MANAGER_NAME_PROP = "hibernate.test.cache.jbc2.cache.manager.name";
-
public static CacheManager getTestCacheManager(String name) {
return (CacheManager) cacheManagers.get(name);
}
@@ -63,7 +61,7 @@
super.start(settings, properties);
- cacheManagerName = properties.getProperty(CACHE_MANAGER_NAME_PROP);
+ cacheManagerName = properties.getProperty(DualNodeTestUtil.NODE_ID_PROP);
cacheManagers.put(cacheManagerName, getCacheFactory());
}
16 years, 11 months
Hibernate SVN: r14363 - in core/trunk: core/src/main/java/org/hibernate/engine and 7 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-02-25 16:06:19 -0500 (Mon, 25 Feb 2008)
New Revision: 14363
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Entity.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassMapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToManySubclass.java
Modified:
core/trunk/core/src/main/java/org/hibernate/action/CollectionRecreateAction.java
core/trunk/core/src/main/java/org/hibernate/action/CollectionRemoveAction.java
core/trunk/core/src/main/java/org/hibernate/action/CollectionUpdateAction.java
core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java
core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
core/trunk/core/src/main/java/org/hibernate/event/AbstractCollectionEvent.java
core/trunk/core/src/main/java/org/hibernate/event/InitializeCollectionEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEvent.java
core/trunk/core/src/main/java/org/hibernate/type/CollectionType.java
core/trunk/core/src/main/resources/org/hibernate/hibernate-configuration-3.0.dtd
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Child.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildEntity.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildValue.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ParentWithCollection.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java
Log:
HHH-2616 : added owner ID and name getters to collection events; added partial support for property-refs; added Javadoc
Modified: core/trunk/core/src/main/java/org/hibernate/action/CollectionRecreateAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/CollectionRecreateAction.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/action/CollectionRecreateAction.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -53,7 +53,7 @@
.getPreCollectionRecreateEventListeners();
if (preListeners.length > 0) {
PreCollectionRecreateEvent preEvent = new PreCollectionRecreateEvent(
- getCollection(), ( EventSource ) getSession() );
+ getPersister(), getCollection(), ( EventSource ) getSession() );
for ( int i = 0; i < preListeners.length; i++ ) {
preListeners[i].onPreRecreateCollection( preEvent );
}
@@ -65,7 +65,7 @@
.getPostCollectionRecreateEventListeners();
if (postListeners.length > 0) {
PostCollectionRecreateEvent postEvent = new PostCollectionRecreateEvent(
- getCollection(), ( EventSource ) getSession() );
+ getPersister(), getCollection(), ( EventSource ) getSession() );
for ( int i = 0; i < postListeners.length; i++ ) {
postListeners[i].onPostRecreateCollection( postEvent );
}
Modified: core/trunk/core/src/main/java/org/hibernate/action/CollectionRemoveAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/CollectionRemoveAction.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/action/CollectionRemoveAction.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -45,7 +45,7 @@
// the loaded owner will be set to null after the collection is removed,
// so capture its value as the affected owner so it is accessible to
// both pre- and post- events
- this.affectedOwner = session.getPersistenceContext().getLoadedCollectionOwner( collection );
+ this.affectedOwner = session.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection );
}
/**
@@ -68,7 +68,7 @@
final SessionImplementor session)
throws CacheException {
super( persister, null, id, session );
- if (affectedOwner == null) { throw new AssertionFailure("affectedOwner == null"); };
+ if (affectedOwner == null) { throw new AssertionFailure("affectedOwner == null"); }
this.emptySnapshot = emptySnapshot;
this.affectedOwner = affectedOwner;
}
@@ -106,9 +106,7 @@
.getPreCollectionRemoveEventListeners();
if (preListeners.length>0) {
PreCollectionRemoveEvent preEvent = new PreCollectionRemoveEvent(
- getCollection(),
- affectedOwner,
- ( EventSource )getSession() );
+ getPersister(), getCollection(), ( EventSource ) getSession(), affectedOwner );
for ( int i = 0; i < preListeners.length; i++ ) {
preListeners[i].onPreRemoveCollection(preEvent);
}
@@ -120,9 +118,7 @@
.getPostCollectionRemoveEventListeners();
if (postListeners.length>0) {
PostCollectionRemoveEvent postEvent = new PostCollectionRemoveEvent(
- getCollection(),
- affectedOwner,
- ( EventSource )getSession() );
+ getPersister(), getCollection(), ( EventSource ) getSession(), affectedOwner );
for ( int i = 0; i < postListeners.length; i++ ) {
postListeners[i].onPostRemoveCollection(postEvent);
}
Modified: core/trunk/core/src/main/java/org/hibernate/action/CollectionUpdateAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/CollectionUpdateAction.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/action/CollectionUpdateAction.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -82,7 +82,7 @@
.getPreCollectionUpdateEventListeners();
if (preListeners.length > 0) {
PreCollectionUpdateEvent preEvent = new PreCollectionUpdateEvent(
- getCollection(), ( EventSource ) getSession() );
+ getPersister(), getCollection(), ( EventSource ) getSession() );
for ( int i = 0; i < preListeners.length; i++ ) {
preListeners[i].onPreUpdateCollection( preEvent );
}
@@ -94,7 +94,7 @@
.getPostCollectionUpdateEventListeners();
if (postListeners.length > 0) {
PostCollectionUpdateEvent postEvent = new PostCollectionUpdateEvent(
- getCollection(), ( EventSource ) getSession() );
+ getPersister(), getCollection(), ( EventSource ) getSession() );
for ( int i = 0; i < postListeners.length; i++ ) {
postListeners[i].onPostUpdateCollection( postEvent );
}
Modified: core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -1,4 +1,4 @@
-//$Id: PersistenceContext.java 11319 2007-03-20 03:12:56Z steve.ebersole(a)jboss.com $
+//$Id: PersistenceContext.java 14312 2008-02-05 23:55:35Z gbadner $
package org.hibernate.engine;
import java.io.Serializable;
@@ -22,7 +22,7 @@
public interface PersistenceContext {
public boolean isStateless();
-
+
/**
* Get the session to which this persistence context is bound.
*
@@ -89,7 +89,7 @@
* corresponding row.
*/
public Object[] getNaturalIdSnapshot(Serializable id, EntityPersister persister)
- throws HibernateException;
+ throws HibernateException;
/**
* Add a canonical mapping from entity key to entity instance
@@ -252,10 +252,22 @@
/**
* Get the entity that owned this persistent collection when it was loaded
+ *
+ * @param collection The persistent collection
+ * @return the owner if its entity ID is available from the collection's loaded key
+ * and the owner entity is in the persistence context; otherwise, returns null
*/
- Object getLoadedCollectionOwner(PersistentCollection collection);
+ Object getLoadedCollectionOwnerOrNull(PersistentCollection collection);
/**
+ * Get the ID for the entity that owned this persistent collection when it was loaded
+ *
+ * @param collection The persistent collection
+ * @return the owner ID if available from the collection's loaded key; otherwise, returns null
+ */
+ public Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection);
+
+ /**
* add a collection we just loaded up (still needs initializing)
*/
public void addUninitializedCollection(CollectionPersister persister,
Modified: core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -680,13 +680,49 @@
/**
* Get the entity that owned this persistent collection when it was loaded
+ *
+ * @param collection The persistent collection
+ * @return the owner, if its entity ID is available from the collection's loaded key
+ * and the owner entity is in the persistence context; otherwise, returns null
*/
- public Object getLoadedCollectionOwner(PersistentCollection collection) {
- CollectionEntry ce = getCollectionEntry(collection);
- if ( ce.getLoadedKey() == null || ce.getLoadedPersister() == null ) {
+ public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection) {
+ CollectionEntry ce = getCollectionEntry( collection );
+ if ( ce.getLoadedPersister() == null ) {
+ return null; // early exit...
+ }
+ Object loadedOwner = null;
+ // TODO: an alternative is to check if the owner has changed; if it hasn't then
+ // return collection.getOwner()
+ Serializable entityId = getLoadedCollectionOwnerIdOrNull( ce );
+ if ( entityId != null ) {
+ loadedOwner = getCollectionOwner( entityId, ce.getLoadedPersister() );
+ }
+ return loadedOwner;
+ }
+
+ /**
+ * Get the ID for the entity that owned this persistent collection when it was loaded
+ *
+ * @param collection The persistent collection
+ * @return the owner ID if available from the collection's loaded key; otherwise, returns null
+ */
+ public Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection) {
+ return getLoadedCollectionOwnerIdOrNull( getCollectionEntry( collection ) );
+ }
+
+ /**
+ * Get the ID for the entity that owned this persistent collection when it was loaded
+ *
+ * @param ce The collection entry
+ * @return the owner ID if available from the collection's loaded key; otherwise, returns null
+ */
+ private Serializable getLoadedCollectionOwnerIdOrNull(CollectionEntry ce) {
+ if ( ce == null || ce.getLoadedKey() == null || ce.getLoadedPersister() == null ) {
return null;
}
- return getCollectionOwner(ce.getLoadedKey(), ce.getLoadedPersister());
+ // TODO: an alternative is to check if the owner has changed; if it hasn't then
+ // get the ID from collection.getOwner()
+ return ce.getLoadedPersister().getCollectionType().getIdOfOwnerOrNull( ce.getLoadedKey(), session );
}
/**
Modified: core/trunk/core/src/main/java/org/hibernate/event/AbstractCollectionEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/AbstractCollectionEvent.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/event/AbstractCollectionEvent.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -1,32 +1,12 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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
- */
-
//$Id: $
package org.hibernate.event;
+import java.io.Serializable;
+
import org.hibernate.collection.PersistentCollection;
-import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.CollectionEntry;
+import org.hibernate.engine.EntityEntry;
+import org.hibernate.persister.collection.CollectionPersister;
/**
* Defines a base class for events involving collections.
@@ -37,22 +17,99 @@
private final PersistentCollection collection;
private final Object affectedOwner;
+ private final Serializable affectedOwnerId;
+ private final String affectedOwnerEntityName;
- public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) {
+ /**
+ * Constructs an AbstractCollectionEvent object.
+ *
+ * @param collection - the collection
+ * @param source - the Session source
+ * @param affectedOwner - the owner that is affected by this event;
+ * can be null if unavailable
+ * @param affectedOwnerId - the ID for the owner that is affected
+ * by this event; can be null if unavailable
+ * that is affected by this event; can be null if unavailable
+ */
+ public AbstractCollectionEvent( CollectionPersister collectionPersister,
+ PersistentCollection collection,
+ EventSource source,
+ Object affectedOwner,
+ Serializable affectedOwnerId) {
super(source);
this.collection = collection;
this.affectedOwner = affectedOwner;
+ this.affectedOwnerId = affectedOwnerId;
+ this.affectedOwnerEntityName =
+ getAffectedOwnerEntityName( collectionPersister, affectedOwner, source );
}
- protected static Object getLoadedOwner( PersistentCollection collection, EventSource source ) {
- return ( ( SessionImplementor ) source ).getPersistenceContext().getLoadedCollectionOwner( collection );
+ protected static CollectionPersister getLoadedCollectionPersister( PersistentCollection collection, EventSource source ) {
+ CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection );
+ return ( ce == null ? null : ce.getLoadedPersister() );
}
+ protected static Object getLoadedOwnerOrNull( PersistentCollection collection, EventSource source ) {
+ return source.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection );
+ }
+
+ protected static Serializable getLoadedOwnerIdOrNull( PersistentCollection collection, EventSource source ) {
+ return source.getPersistenceContext().getLoadedCollectionOwnerIdOrNull( collection );
+ }
+
+ protected static Serializable getOwnerIdOrNull( Object owner, EventSource source ) {
+ EntityEntry ownerEntry = source.getPersistenceContext().getEntry( owner );
+ return ( ownerEntry == null ? null : ownerEntry.getId() );
+ }
+
+ protected static String getAffectedOwnerEntityName(CollectionPersister collectionPersister, Object affectedOwner, EventSource source ) {
+
+ // collectionPersister should not be null, but we don't want to throw
+ // an exception if it is null
+ String entityName =
+ ( collectionPersister == null ? null : collectionPersister.getOwnerEntityPersister().getEntityName() );
+ if ( affectedOwner != null ) {
+ EntityEntry ee = source.getPersistenceContext().getEntry( affectedOwner );
+ if ( ee != null && ee.getEntityName() != null) {
+ entityName = ee.getEntityName();
+ }
+ }
+ return entityName;
+ }
+
public PersistentCollection getCollection() {
return collection;
}
- public Object getAffectedOwner() {
+ /**
+ * Get the collection owner entity that is affected by this event.
+ *
+ * @return the affected owner; returns null if the entity is not in the persistence context
+ * (e.g., because the collection from a detached entity was moved to a new owner)
+ */
+ public Object getAffectedOwnerOrNull() {
return affectedOwner;
}
+
+ /**
+ * Get the ID for the collection owner entity that is affected by this event.
+ *
+ * @return the affected owner ID; returns null if the ID cannot be obtained
+ * from the collection's loaded key (e.g., a property-ref is used for the
+ * collection and does not include the entity's ID)
+ */
+ public Serializable getAffectedOwnerIdOrNull() {
+ return affectedOwnerId;
+ }
+
+ /**
+ * Get the entity name for the collection owner entity that is affected by this event.
+ *
+ * @return the entity name; if the owner is not in the PersistenceContext, the
+ * returned value may be a superclass name, instead of the actual class name
+ */
+ public String getAffectedOwnerEntityName() {
+ return affectedOwnerEntityName;
+ }
+
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/InitializeCollectionEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/InitializeCollectionEvent.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/event/InitializeCollectionEvent.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -1,4 +1,4 @@
-//$Id: InitializeCollectionEvent.java 6929 2005-05-27 03:54:08Z oneovthafew $
+//$Id: InitializeCollectionEvent.java 14313 2008-02-06 07:46:52Z gbadner $
package org.hibernate.event;
import org.hibernate.collection.PersistentCollection;
@@ -11,7 +11,11 @@
*/
public class InitializeCollectionEvent extends AbstractCollectionEvent {
- public InitializeCollectionEvent(PersistentCollection collection, EventSource source) {
- super(collection, source, getLoadedOwner( collection, source ) );
- }
+ public InitializeCollectionEvent(PersistentCollection collection, EventSource source ) {
+ super( getLoadedCollectionPersister( collection, source ),
+ collection,
+ source,
+ getLoadedOwnerOrNull( collection, source ),
+ getLoadedOwnerIdOrNull( collection, source ) );
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEvent.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEvent.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -2,6 +2,7 @@
package org.hibernate.event;
import org.hibernate.collection.PersistentCollection;
+import org.hibernate.persister.collection.CollectionPersister;
/**
* An event that occurs after a collection is recreated
@@ -10,7 +11,11 @@
*/
public class PostCollectionRecreateEvent extends AbstractCollectionEvent {
- public PostCollectionRecreateEvent(PersistentCollection collection, EventSource source) {
- super(collection, source, collection.getOwner());
+ public PostCollectionRecreateEvent( CollectionPersister collectionPersister,
+ PersistentCollection collection,
+ EventSource source ) {
+ super( collectionPersister, collection, source,
+ collection.getOwner(),
+ getOwnerIdOrNull( collection.getOwner(), source ) );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEvent.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEvent.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -2,6 +2,7 @@
package org.hibernate.event;
import org.hibernate.collection.PersistentCollection;
+import org.hibernate.persister.collection.CollectionPersister;
/**
* An event that occurs after a collection is removed
@@ -10,7 +11,12 @@
*/
public class PostCollectionRemoveEvent extends AbstractCollectionEvent {
- public PostCollectionRemoveEvent(PersistentCollection collection, Object loadedOwner, EventSource source) {
- super(collection, source, loadedOwner);
+ public PostCollectionRemoveEvent(CollectionPersister collectionPersister,
+ PersistentCollection collection,
+ EventSource source,
+ Object loadedOwner ) {
+ super( collectionPersister, collection, source,
+ loadedOwner,
+ getOwnerIdOrNull( loadedOwner, source ) );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEvent.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEvent.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -2,6 +2,7 @@
package org.hibernate.event;
import org.hibernate.collection.PersistentCollection;
+import org.hibernate.persister.collection.CollectionPersister;
/**
* An event that occurs after a collection is updated
@@ -10,7 +11,11 @@
*/
public class PostCollectionUpdateEvent extends AbstractCollectionEvent {
- public PostCollectionUpdateEvent(PersistentCollection collection, EventSource source) {
- super(collection, source, getLoadedOwner( collection, source ));
+ public PostCollectionUpdateEvent(CollectionPersister collectionPersister,
+ PersistentCollection collection,
+ EventSource source) {
+ super( collectionPersister, collection, source,
+ getLoadedOwnerOrNull( collection, source ),
+ getLoadedOwnerIdOrNull( collection, source ) );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEvent.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEvent.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -2,6 +2,7 @@
package org.hibernate.event;
import org.hibernate.collection.PersistentCollection;
+import org.hibernate.persister.collection.CollectionPersister;
/**
* An event that occurs before a collection is recreated
@@ -10,7 +11,11 @@
*/
public class PreCollectionRecreateEvent extends AbstractCollectionEvent {
- public PreCollectionRecreateEvent(PersistentCollection collection, EventSource source) {
- super(collection, source, collection.getOwner());
+ public PreCollectionRecreateEvent(CollectionPersister collectionPersister,
+ PersistentCollection collection,
+ EventSource source) {
+ super( collectionPersister, collection, source,
+ collection.getOwner(),
+ getOwnerIdOrNull( collection.getOwner(), source ) );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEvent.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEvent.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -1,31 +1,8 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, 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
- */
-
//$Id: $
package org.hibernate.event;
import org.hibernate.collection.PersistentCollection;
+import org.hibernate.persister.collection.CollectionPersister;
/**
* An event that occurs before a collection is removed
@@ -34,7 +11,12 @@
*/
public class PreCollectionRemoveEvent extends AbstractCollectionEvent {
- public PreCollectionRemoveEvent(PersistentCollection collection, Object loadedOwner, EventSource source) {
- super(collection, source, loadedOwner);
+ public PreCollectionRemoveEvent(CollectionPersister collectionPersister,
+ PersistentCollection collection,
+ EventSource source,
+ Object loadedOwner) {
+ super( collectionPersister, collection, source,
+ loadedOwner,
+ getOwnerIdOrNull( loadedOwner, source ) );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEvent.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEvent.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -2,6 +2,7 @@
package org.hibernate.event;
import org.hibernate.collection.PersistentCollection;
+import org.hibernate.persister.collection.CollectionPersister;
/**
* An event that occurs before a collection is updated
@@ -10,7 +11,11 @@
*/
public class PreCollectionUpdateEvent extends AbstractCollectionEvent {
- public PreCollectionUpdateEvent(PersistentCollection collection, EventSource source) {
- super(collection, source, getLoadedOwner( collection, source ));
+ public PreCollectionUpdateEvent(CollectionPersister collectionPersister,
+ PersistentCollection collection,
+ EventSource source) {
+ super( collectionPersister, collection, source,
+ getLoadedOwnerOrNull( collection, source ),
+ getLoadedOwnerIdOrNull( collection, source ) );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/CollectionType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CollectionType.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/java/org/hibernate/type/CollectionType.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -13,6 +13,7 @@
import org.dom4j.Element;
import org.dom4j.Node;
+
import org.hibernate.EntityMode;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
@@ -26,6 +27,7 @@
import org.hibernate.engine.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.QueryableCollection;
+import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Joinable;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
@@ -260,6 +262,13 @@
return getPersister( session ).getOwnerEntityPersister().isVersioned();
}
+ /**
+ * Get our underlying collection persister (using the session to access the
+ * factory).
+ *
+ * @param session The session from which the request is originating.
+ * @return The underlying collection persister
+ */
private CollectionPersister getPersister(SessionImplementor session) {
return session.getFactory().getCollectionPersister( role );
}
@@ -335,6 +344,7 @@
}
// NOTE VERY HACKISH WORKAROUND!!
+ // TODO: Fix this so it will work for non-POJO entity mode
Type keyType = getPersister( session ).getKeyType();
if ( !keyType.getReturnedClass().isInstance( id ) ) {
id = (Serializable) keyType.semiResolve(
@@ -348,6 +358,37 @@
}
}
+ /**
+ * Get the id value from the owning entity key, usually the same as the key, but might be some
+ * other property, in the case of property-ref
+ *
+ * @param key The collection owner key
+ * @param session The session from which the request is originating.
+ * @return The collection owner's id, if it can be obtained from the key;
+ * otherwise, null is returned
+ */
+ public Serializable getIdOfOwnerOrNull(Serializable key, SessionImplementor session) {
+ Serializable ownerId = null;
+ if ( foreignKeyPropertyName == null ) {
+ ownerId = key;
+ }
+ else {
+ Type keyType = getPersister( session ).getKeyType();
+ EntityPersister ownerPersister = getPersister( session ).getOwnerEntityPersister();
+ // TODO: Fix this so it will work for non-POJO entity mode
+ Class ownerMappedClass = ownerPersister.getMappedClass( session.getEntityMode() );
+ if ( ownerMappedClass.isAssignableFrom( keyType.getReturnedClass() ) &&
+ keyType.getReturnedClass().isInstance( key ) ) {
+ // the key is the owning entity itself, so get the ID from the key
+ ownerId = ownerPersister.getIdentifier( key, session.getEntityMode() );
+ }
+ else {
+ // TODO: check if key contains the owner ID
+ }
+ }
+ return ownerId;
+ }
+
public Object hydrate(ResultSet rs, String[] name, SessionImplementor session, Object owner) {
// can't just return null here, since that would
// cause an owning component to become null
Modified: core/trunk/core/src/main/resources/org/hibernate/hibernate-configuration-3.0.dtd
===================================================================
--- core/trunk/core/src/main/resources/org/hibernate/hibernate-configuration-3.0.dtd 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/core/src/main/resources/org/hibernate/hibernate-configuration-3.0.dtd 2008-02-25 21:06:19 UTC (rev 14363)
@@ -34,10 +34,10 @@
<!ATTLIST collection-cache usage (read-only|read-write|nonstrict-read-write|transactional) #REQUIRED>
<!ELEMENT event (listener*)>
-<!ATTLIST event type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|post-load|post-update|post-insert|post-delete|post-commit-update|post-commit-insert|post-commit-delete) #REQUIRED>
+<!ATTLIST event type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|pre-collection-recreate|pre-collection-remove|pre-collection-update|post-load|post-update|post-insert|post-delete|post-collection-recreate|post-collection-remove|post-collection-update|post-commit-update|post-commit-insert|post-commit-delete) #REQUIRED>
<!ELEMENT listener EMPTY>
-<!ATTLIST listener type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|post-load|post-update|post-insert|post-delete|post-commit-update|post-commit-insert|post-commit-delete) #IMPLIED>
+<!ATTLIST listener type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|pre-collection-recreate|pre-collection-remove|pre-collection-update|post-load|post-update|post-insert|post-delete|post-collection-recreate|post-collection-remove|post-collection-update|post-commit-update|post-commit-insert|post-commit-delete) #IMPLIED>
<!ATTLIST listener class CDATA #REQUIRED>
<!ELEMENT session-factory (property*, mapping*, (class-cache|collection-cache)*, event*, listener*)>
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -94,9 +94,9 @@
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
Child child = ( Child ) parent.getChildren().iterator().next();
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -119,9 +119,9 @@
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -143,9 +143,9 @@
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -167,9 +167,9 @@
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -183,8 +183,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.addChild( child );
tx.commit();
@@ -193,16 +193,20 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ ChildWithBidirectionalManyToMany childWithManyToMany = null;
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
+ if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
+ }
}
if ( !( parent.getChildren() instanceof PersistentSet ) ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() && !( getParents( child ) instanceof PersistentSet ) ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( childWithManyToMany != null && !( childWithManyToMany.getParents() instanceof PersistentSet ) ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), childWithManyToMany, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), childWithManyToMany, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -226,9 +230,9 @@
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, collectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, collectionOrig, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@@ -254,9 +258,9 @@
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@@ -272,8 +276,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( ChildEntity ) s.get( child.getClass(), ( ( ChildEntity ) child).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child).getId() );
}
Collection oldCollection = parent.getChildren();
parent.newChildren( createCollection() );
@@ -284,16 +288,19 @@
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
- if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
+ if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
// hmmm, the same parent was removed and re-added to the child's collection;
// should this be considered an update?
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@@ -309,8 +316,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( oldChild instanceof ChildEntity ) {
- oldChild = ( ChildEntity ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild).getId() );
+ if ( oldChild instanceof Entity ) {
+ oldChild = ( Child ) s.get( oldChild.getClass(), ( ( Entity ) oldChild).getId() );
}
Collection oldCollection = parent.getChildren();
parent.newChildren( createCollection() );
@@ -321,16 +328,19 @@
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
- if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
+ if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@@ -346,8 +356,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
tx.commit();
@@ -356,14 +366,17 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
+ if ( ( ( PersistentCollection ) childWithManyToMany.getParents( ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -377,8 +390,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.clearChildren();
tx.commit();
@@ -387,14 +400,17 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
+ if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -415,8 +431,8 @@
s = openSession();
tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( oldChild instanceof ChildEntity ) {
- oldChild = ( Child ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild ).getId() );
+ if ( oldChild instanceof Entity ) {
+ oldChild = ( Child ) s.get( oldChild.getClass(), ( ( Entity ) oldChild ).getId() );
}
parent.removeChild( oldChild );
tx.commit();
@@ -425,14 +441,17 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
+ if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -479,11 +498,11 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
- if ( child instanceof ChildEntity ) {
+ if ( child instanceof Entity ) {
s.delete( child );
}
s.delete( parent );
@@ -491,14 +510,14 @@
s.close();
int index = 0;
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRemoveListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionRemoveListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRemoveListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionRemoveListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -513,8 +532,8 @@
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
otherParent.addChild( child );
@@ -524,8 +543,8 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
@@ -534,9 +553,9 @@
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -551,8 +570,8 @@
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( ChildEntity ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
otherParent.addAllChildren( parent.getChildren() );
parent.clearChildren();
@@ -565,16 +584,16 @@
if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
}
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -598,24 +617,24 @@
if ( ( ( PersistentCollection ) otherCollectionOrig ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, otherCollectionOrig, index++ );
otherChildOrig = ( Child ) otherCollectionOrig.iterator().next();
- if ( otherChildOrig.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), otherChildOrig, index++ );
+ if ( otherChildOrig instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
}
}
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherParent.getChildren(), index++ );
Child otherChild = ( Child ) otherParent.getChildren().iterator().next();
- if ( otherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), otherChild, index++ );
+ if ( otherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, otherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, otherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
- if ( otherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChildOrig, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChildOrig, index++ );
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChild, index++ );
+ if ( otherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, index++ );
@@ -649,24 +668,24 @@
if ( ( ( PersistentCollection ) otherCollectionOrig ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, otherCollectionOrig, index++ );
otherChildOrig = ( Child ) otherCollectionOrig.iterator().next();
- if ( otherChildOrig.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), otherChildOrig, index++ );
+ if ( otherChildOrig instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
}
}
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherOtherParent.getChildren(), index++ );
Child otherOtherChild = ( Child ) otherOtherParent.getChildren().iterator().next();
- if ( otherOtherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), otherOtherChild, index++ );
+ if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
- if ( otherOtherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChildOrig, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChildOrig, index++ );
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherOtherChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherOtherChild, index++ );
+ if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ );
@@ -677,9 +696,9 @@
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherOtherParent, otherOtherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherOtherParent, otherOtherCollectionOrig, index++ );
- if ( otherOtherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherOtherChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherOtherChild, index++ );
+ if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherOtherParent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherOtherParent, index++ );
@@ -721,11 +740,6 @@
return parent;
}
- protected Collection getParents( Child child ) {
- return ( ( child instanceof ChildWithBidirectionalManyToMany )
- ? ( ( ChildWithBidirectionalManyToMany ) child ).getParents()
- : null );
- }
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
ParentWithCollection parent,
@@ -734,21 +748,29 @@
}
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
- Child child,
+ ChildWithBidirectionalManyToMany child,
int index) {
- checkResult( listeners, listenerExpected, child, getParents( child ), index );
+ checkResult( listeners, listenerExpected, child, child.getParents(), index );
}
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
- Object ownerExpected,
+ Entity ownerExpected,
Collection collExpected,
int index) {
assertSame( listenerExpected, listeners.getListenersCalled().get( index ) );
assertSame(
ownerExpected,
- ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerOrNull()
);
+ assertEquals(
+ ownerExpected.getId(),
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerIdOrNull()
+ );
+ assertEquals(
+ ownerExpected.getClass().getName(),
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerEntityName()
+ );
assertSame(
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
);
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -112,7 +112,7 @@
/*
public void testUpdateDetachedParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
- AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
Child oldChild = ( Child ) parent.getChildren().iterator().next();
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
@@ -126,9 +126,9 @@
int index = 0;
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@@ -186,7 +186,7 @@
/*
public void testUpdateParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
- AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
Child oldChild = ( Child ) parent.getChildren().iterator().next();
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
@@ -204,14 +204,18 @@
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
- if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
+ ChildWithBidirectionalManyToMany oldChildWithManyToMany = null;
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
+ if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
+ if ( oldChildWithManyToMany != null ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChildWithManyToMany, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChildWithManyToMany, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@@ -221,7 +225,7 @@
public void testUpdateMergedParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
- AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
Session s = openSession();
@@ -233,14 +237,18 @@
s.close();
int index = 0;
Child oldChild = ( Child ) oldCollection.iterator().next();
- if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
+ ChildWithBidirectionalManyToMany oldChildWithManyToMany = null;
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
+ if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
}
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
+ }
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
+ if ( oldChildWithManyToMany != null ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChildWithManyToMany, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChildWithManyToMany, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@@ -282,34 +290,37 @@
return parent;
}
- private Collection getParents( Child child ) {
- return ( ( child instanceof ChildWithBidirectionalManyToMany )
- ? ( ( ChildWithBidirectionalManyToMany ) child ).getParents()
- : null );
- }
- private void checkResult(CollectionListeners listeners,
+ protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
ParentWithCollection parent,
int index) {
checkResult( listeners, listenerExpected, parent, parent.getChildren(), index );
}
- private void checkResult(CollectionListeners listeners,
+ protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
- Child child,
+ ChildWithBidirectionalManyToMany child,
int index) {
- checkResult( listeners, listenerExpected, child, getParents( child ), index );
+ checkResult( listeners, listenerExpected, child, child.getParents(), index );
}
- private void checkResult(CollectionListeners listeners,
+ protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
- Object ownerExpected,
+ Entity ownerExpected,
Collection collExpected,
int index) {
assertSame( listenerExpected, listeners.getListenersCalled().get( index ) );
assertSame(
ownerExpected,
- ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerOrNull()
);
+ assertEquals(
+ ownerExpected.getId(),
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerIdOrNull()
+ );
+ assertEquals(
+ ownerExpected.getClass().getName(),
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerEntityName()
+ );
assertSame(
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
);
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Child.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Child.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Child.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -27,8 +27,6 @@
*/
public interface Child {
- boolean hasBidirectionalManyToMany();
-
String getName();
void setName(String name);
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildEntity.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildEntity.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildEntity.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -25,10 +25,9 @@
*
* @author Gail Badner
*/
-public class ChildEntity extends ChildValue {
+public class ChildEntity extends ChildValue implements Entity {
private Long id;
-
public ChildEntity() {
super();
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildValue.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildValue.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildValue.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -35,10 +35,6 @@
this.name = name;
}
- public boolean hasBidirectionalManyToMany() {
- return false;
- }
-
public String getName() {
return name;
}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Entity.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Entity.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Entity.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -0,0 +1,14 @@
+package org.hibernate.test.event.collection;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gbadner
+ * Date: Jan 30, 2008
+ * Time: 2:39:37 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface Entity {
+ Long getId();
+
+ void setId(Long id);
+}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ParentWithCollection.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ParentWithCollection.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ParentWithCollection.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -27,7 +27,7 @@
*
* @author Gail Badner
*/
-public interface ParentWithCollection {
+public interface ParentWithCollection extends Entity {
void newChildren(Collection collection);
Child createChild(String name);
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -21,12 +21,13 @@
*/
package org.hibernate.test.event.collection.association;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
import org.hibernate.test.event.collection.AbstractCollectionEventTest;
+import org.hibernate.test.event.collection.ChildEntity;
import org.hibernate.test.event.collection.CollectionListeners;
-import org.hibernate.test.event.collection.ChildEntity;
import org.hibernate.test.event.collection.ParentWithCollection;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
+import org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToMany;
/**
*
@@ -52,14 +53,14 @@
s.close();
int index = 0;
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java 2008-02-25 20:15:43 UTC (rev 14362)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -40,10 +40,6 @@
this.parents = parents;
}
- public boolean hasBidirectionalManyToMany() {
- return true;
- }
-
public Collection getParents() {
return parents;
}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassCollectionEventTest.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -0,0 +1,57 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, 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.event.collection.association.bidirectional.onetomany;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.event.collection.Child;
+import org.hibernate.test.event.collection.ParentWithCollection;
+import org.hibernate.test.event.collection.association.AbstractAssociationCollectionEventTest;
+import org.hibernate.test.event.collection.association.bidirectional.onetomany.ChildWithManyToOne;
+import org.hibernate.test.event.collection.association.bidirectional.onetomany.ParentWithBidirectionalOneToMany;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class BidirectionalOneToManyBagSubclassCollectionEventTest extends BidirectionalOneToManyBagCollectionEventTest {
+
+ public BidirectionalOneToManyBagSubclassCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BidirectionalOneToManyBagSubclassCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithBidirectionalOneToManySubclass( name );
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassMapping.hbm.xml 2008-02-25 21:06:19 UTC (rev 14363)
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!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.event.collection.association.bidirectional.onetomany">
+
+ <class name="ParentWithBidirectionalOneToMany" table="PARENT" discriminator-value="P">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+
+ <discriminator column="TYPE" type="string" length="1"/>
+
+ <bag name="children"
+ inverse="true"
+ cascade="all">
+ <key column="parent_id"/>
+ <one-to-many class="ChildWithManyToOne"/>
+ </bag>
+
+ <subclass name="ParentWithBidirectionalOneToManySubclass"
+ discriminator-value="S">
+ </subclass>
+ </class>
+
+ <class name="ChildWithManyToOne" table="CHILD">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ <many-to-one name="parent" column="parent_id" class="ParentWithBidirectionalOneToMany" cascade="none"/>
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToManySubclass.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToManySubclass.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToManySubclass.java 2008-02-25 21:06:19 UTC (rev 14363)
@@ -0,0 +1,42 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, 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.event.collection.association.bidirectional.onetomany;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.hibernate.test.event.collection.Child;
+import org.hibernate.test.event.collection.AbstractParentWithCollection;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class ParentWithBidirectionalOneToManySubclass extends ParentWithBidirectionalOneToMany {
+ public ParentWithBidirectionalOneToManySubclass() {
+ }
+
+ public ParentWithBidirectionalOneToManySubclass(String name) {
+ super( name );
+ }
+
+}
\ No newline at end of file
16 years, 11 months