Hibernate SVN: r15447 - core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-10-29 19:14:36 -0400 (Wed, 29 Oct 2008)
New Revision: 15447
Modified:
core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml
core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml
Log:
Update configs for JBC3
Modified: core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml
===================================================================
--- core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml 2008-10-29 22:16:17 UTC (rev 15446)
+++ core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/optimistic-treecache.xml 2008-10-29 23:14:36 UTC (rev 15447)
@@ -56,7 +56,8 @@
<!--
Node locking scheme:
OPTIMISTIC
- PESSIMISTIC (default)
+ PESSIMISTIC
+ MVCC (default)
-->
<attribute name="NodeLockingScheme">OPTIMISTIC</attribute>
@@ -137,6 +138,9 @@
<!-- Must match the value of "useRegionBasedMarshalling" -->
<attribute name="InactiveOnStartup">true</attribute>
+ <!-- For now. disable asynchronous RPC marshalling/sending -->
+ <attribute name="SerializationExecutorPoolSize">0</attribute>
+
<!-- Specific eviction policy configurations. This is LRU -->
<attribute name="EvictionPolicyConfig">
<config>
Modified: core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml
===================================================================
--- core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml 2008-10-29 22:16:17 UTC (rev 15446)
+++ core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/pessimistic-treecache.xml 2008-10-29 23:14:36 UTC (rev 15447)
@@ -45,7 +45,16 @@
<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
+
<!--
+ Node locking scheme:
+ OPTIMISTIC
+ PESSIMISTIC
+ MVCC (default)
+ -->
+ <attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
+
+ <!--
TransactionManager configuration not required for Hibernate!
Hibernate will plug in its own transaction manager integration.
-->
@@ -110,6 +119,9 @@
<!-- Max number of milliseconds to wait for a lock acquisition -->
<attribute name="LockAcquisitionTimeout">15000</attribute>
+ <!-- For now. disable asynchronous RPC marshalling/sending -->
+ <attribute name="SerializationExecutorPoolSize">0</attribute>
+
<!-- Specific eviction policy configurations. This is LRU -->
<attribute name="EvictionPolicyConfig">
<config>
16 years, 2 months
Hibernate SVN: r15446 - in core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2: entity and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-10-29 18:16:17 -0400 (Wed, 29 Oct 2008)
New Revision: 15446
Modified:
core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java
core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java
Log:
Add hooks for changing the JBC config resource
Modified: core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java
===================================================================
--- core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java 2008-10-29 21:33:52 UTC (rev 15445)
+++ core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java 2008-10-29 22:16:17 UTC (rev 15446)
@@ -171,9 +171,12 @@
node2Failure = null;
}
- protected static Configuration createConfiguration(String configName) {
+ protected static Configuration createConfiguration(String configName, String configResource) {
Configuration cfg = CacheTestUtil.buildConfiguration(REGION_PREFIX, MultiplexedJBossCacheRegionFactory.class, true, false);
cfg.setProperty(MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP, configName);
+ if (configResource != null) {
+ cfg.setProperty(MultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP, configResource);
+ }
return cfg;
}
@@ -546,12 +549,18 @@
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
- private String configName;
+ private final String configResource;
+ private final String configName;
private String preferIPv4Stack;
public AccessStrategyTestSetup(Test test, String configName) {
+ this(test, configName, null);
+ }
+
+ public AccessStrategyTestSetup(Test test, String configName, String configResource) {
super(test);
this.configName = configName;
+ this.configResource = configResource;
}
@Override
@@ -562,11 +571,11 @@
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
System.setProperty(PREFER_IPV4STACK, "true");
- localCfg = createConfiguration(configName);
+ localCfg = createConfiguration(configName, configResource);
localRegionFactory = CacheTestUtil.startRegionFactory(localCfg);
localCache = localRegionFactory.getCacheInstanceManager().getCollectionCacheInstance();
- remoteCfg = createConfiguration(configName);
+ remoteCfg = createConfiguration(configName, configResource);
remoteRegionFactory = CacheTestUtil.startRegionFactory(remoteCfg);
remoteCache = remoteRegionFactory.getCacheInstanceManager().getCollectionCacheInstance();
}
Modified: core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java
===================================================================
--- core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java 2008-10-29 21:33:52 UTC (rev 15445)
+++ core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java 2008-10-29 22:16:17 UTC (rev 15446)
@@ -95,15 +95,23 @@
public static Test getTestSetup(Class testClass, String configName) {
- TestSuite suite = new TestSuite(testClass);
- return new AccessStrategyTestSetup(suite, configName);
+ return getTestSetup(testClass, configName, null);
}
public static Test getTestSetup(Test test, String configName) {
- return new AccessStrategyTestSetup(test, configName);
+ return getTestSetup(test, configName, null);
+ }
+
+ public static Test getTestSetup(Class testClass, String configName, String configResource) {
+ TestSuite suite = new TestSuite(testClass);
+ return new AccessStrategyTestSetup(suite, configName, configResource);
}
+ public static Test getTestSetup(Test test, String configName, String configResource) {
+ return new AccessStrategyTestSetup(test, configName, configResource);
+ }
+
/**
* Create a new TransactionalAccessTestCase.
*
@@ -169,9 +177,12 @@
node2Failure = null;
}
- protected static Configuration createConfiguration(String configName) {
+ protected static Configuration createConfiguration(String configName, String configResource) {
Configuration cfg = CacheTestUtil.buildConfiguration(REGION_PREFIX, MultiplexedJBossCacheRegionFactory.class, true, false);
cfg.setProperty(MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP, configName);
+ if (configResource != null) {
+ cfg.setProperty(MultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP, configResource);
+ }
return cfg;
}
@@ -755,12 +766,18 @@
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
- private String configName;
+ private final String configResource;
+ private final String configName;
private String preferIPv4Stack;
public AccessStrategyTestSetup(Test test, String configName) {
+ this(test, configName, null);
+ }
+
+ public AccessStrategyTestSetup(Test test, String configName, String configResource) {
super(test);
this.configName = configName;
+ this.configResource = configResource;
}
@Override
@@ -779,11 +796,11 @@
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
System.setProperty(PREFER_IPV4STACK, "true");
- localCfg = createConfiguration(configName);
+ localCfg = createConfiguration(configName, configResource);
localRegionFactory = CacheTestUtil.startRegionFactory(localCfg);
localCache = localRegionFactory.getCacheInstanceManager().getEntityCacheInstance();
- remoteCfg = createConfiguration(configName);
+ remoteCfg = createConfiguration(configName, configResource);
remoteRegionFactory = CacheTestUtil.startRegionFactory(remoteCfg);
remoteCache = remoteRegionFactory.getCacheInstanceManager().getEntityCacheInstance();
16 years, 2 months
Hibernate SVN: r15445 - in core/trunk: testsuite/src/test/java/org/hibernate/test/deletetransient and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-10-29 17:33:52 -0400 (Wed, 29 Oct 2008)
New Revision: 15445
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java
core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java
core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java
core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml
Log:
HHH-2146 : NullpointerException in DefaultDeleteEventListener.deleteTransientEntity
Modified: core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2008-10-29 21:21:07 UTC (rev 15444)
+++ core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2008-10-29 21:33:52 UTC (rev 15445)
@@ -25,6 +25,7 @@
package org.hibernate.engine;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import org.slf4j.Logger;
@@ -375,7 +376,7 @@
if ( log.isTraceEnabled() ) {
log.trace("deleting orphaned entity instance: " + entityName);
}
- eventSource.delete( entityName, orphan, false, null );
+ eventSource.delete( entityName, orphan, false, new HashSet() );
}
}
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java 2008-10-29 21:21:07 UTC (rev 15444)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java 2008-10-29 21:33:52 UTC (rev 15445)
@@ -1,5 +1,8 @@
package org.hibernate.test.deletetransient;
+import java.util.Set;
+import java.util.HashSet;
+
/**
* todo: describe Address
*
@@ -8,6 +11,7 @@
public class Address {
private Long id;
private String info;
+ private Set suites = new HashSet();
public Address() {
}
@@ -31,4 +35,12 @@
public void setInfo(String info) {
this.info = info;
}
+
+ public Set getSuites() {
+ return suites;
+ }
+
+ public void setSuites(Set suites) {
+ this.suites = suites;
+ }
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2008-10-29 21:21:07 UTC (rev 15444)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2008-10-29 21:33:52 UTC (rev 15445)
@@ -105,4 +105,70 @@
t.commit();
s.close();
}
+
+ public void testCascadeAllFromClearedPersistentAssnToTransientEntity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ p.getAddresses().add( address );
+ s.save( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Suite suite = new Suite();
+ address.getSuites().add( suite );
+ p.getAddresses().clear();
+ s.saveOrUpdate( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ p = ( Person ) s.get( p.getClass(), p.getId() );
+ assertEquals( "persistent collection not cleared", 0, p.getAddresses().size() );
+ Long count = ( Long ) s.createQuery( "select count(*) from Address" ).list().get( 0 );
+ assertEquals( 1, count.longValue() );
+ count = ( Long ) s.createQuery( "select count(*) from Suite" ).list().get( 0 );
+ assertEquals( 0, count.longValue() );
+ s.delete( p );
+ t.commit();
+ s.close();
+ }
+
+ public void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ Suite suite = new Suite();
+ address.getSuites().add( suite );
+ s.save( address );
+ t.commit();
+ s.close();
+
+
+ s = openSession();
+ t = s.beginTransaction();
+ Note note = new Note();
+ note.setDescription( "a description" );
+ suite.getNotes().add( note );
+ address.getSuites().clear();
+ s.saveOrUpdate( address );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Long count = ( Long ) s.createQuery( "select count(*) from Suite" ).list().get( 0 );
+ assertEquals( "all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue() );
+ count = ( Long ) s.createQuery( "select count(*) from Note" ).list().get( 0 );
+ assertEquals( 0, count.longValue() );
+ s.delete( address );
+ t.commit();
+ s.close();
+ }
}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java 2008-10-29 21:33:52 UTC (rev 15445)
@@ -0,0 +1,33 @@
+package org.hibernate.test.deletetransient;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class Note {
+ private Long id;
+ private String description;
+
+ public Note() {
+ }
+
+ public Note(String description) {
+ this.description = description;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
\ No newline at end of file
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml 2008-10-29 21:21:07 UTC (rev 15444)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml 2008-10-29 21:33:52 UTC (rev 15445)
@@ -29,6 +29,28 @@
<generator class="increment"/>
</id>
<property name="info" type="string"/>
+ <set name="suites" lazy="true" inverse="false" cascade="all-delete-orphan">
+ <key column="ADDRESS_ID"/>
+ <one-to-many class="Suite"/>
+ </set>
</class>
-
+
+ <class name="Suite" table="T_SUITE">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="location" type="string"/>
+ <set name="notes" lazy="true" inverse="false" cascade="all-delete-orphan">
+ <key column="SUITE_ID"/>
+ <one-to-many class="Note"/>
+ </set>
+ </class>
+
+ <class name="Note" table="T_NOTE">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="description" type="string"/>
+ </class>
+
</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java 2008-10-29 21:33:52 UTC (rev 15445)
@@ -0,0 +1,47 @@
+package org.hibernate.test.deletetransient;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class Suite {
+ private Long id;
+ private String location;
+ private Set notes = new HashSet();
+
+ public Suite() {
+ }
+
+ public Suite(String location) {
+ this.location = location;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public Set getNotes() {
+ return notes;
+ }
+
+ public void setNotes(Set notes) {
+ this.notes = notes;
+ }
+}
\ No newline at end of file
16 years, 2 months
Hibernate SVN: r15444 - in core/branches/Branch_3_3: testsuite/src/test/java/org/hibernate/test/deletetransient and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-10-29 17:21:07 -0400 (Wed, 29 Oct 2008)
New Revision: 15444
Added:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/Cascade.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml
Log:
HHH-2146 : NullpointerException in DefaultDeleteEventListener.deleteTransientEntity
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/Cascade.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/Cascade.java 2008-10-29 20:40:17 UTC (rev 15443)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/Cascade.java 2008-10-29 21:21:07 UTC (rev 15444)
@@ -25,6 +25,7 @@
package org.hibernate.engine;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import org.slf4j.Logger;
@@ -375,7 +376,7 @@
if ( log.isTraceEnabled() ) {
log.trace("deleting orphaned entity instance: " + entityName);
}
- eventSource.delete( entityName, orphan, false, null );
+ eventSource.delete( entityName, orphan, false, new HashSet() );
}
}
}
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java 2008-10-29 20:40:17 UTC (rev 15443)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java 2008-10-29 21:21:07 UTC (rev 15444)
@@ -1,5 +1,8 @@
package org.hibernate.test.deletetransient;
+import java.util.Set;
+import java.util.HashSet;
+
/**
* todo: describe Address
*
@@ -8,6 +11,7 @@
public class Address {
private Long id;
private String info;
+ private Set suites = new HashSet();
public Address() {
}
@@ -31,4 +35,12 @@
public void setInfo(String info) {
this.info = info;
}
+
+ public Set getSuites() {
+ return suites;
+ }
+
+ public void setSuites(Set suites) {
+ this.suites = suites;
+ }
}
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2008-10-29 20:40:17 UTC (rev 15443)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2008-10-29 21:21:07 UTC (rev 15444)
@@ -105,4 +105,70 @@
t.commit();
s.close();
}
+
+ public void testCascadeAllFromClearedPersistentAssnToTransientEntity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ p.getAddresses().add( address );
+ s.save( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Suite suite = new Suite();
+ address.getSuites().add( suite );
+ p.getAddresses().clear();
+ s.saveOrUpdate( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ p = ( Person ) s.get( p.getClass(), p.getId() );
+ assertEquals( "persistent collection not cleared", 0, p.getAddresses().size() );
+ Long count = ( Long ) s.createQuery( "select count(*) from Address" ).list().get( 0 );
+ assertEquals( 1, count.longValue() );
+ count = ( Long ) s.createQuery( "select count(*) from Suite" ).list().get( 0 );
+ assertEquals( 0, count.longValue() );
+ s.delete( p );
+ t.commit();
+ s.close();
+ }
+
+ public void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ Suite suite = new Suite();
+ address.getSuites().add( suite );
+ s.save( address );
+ t.commit();
+ s.close();
+
+
+ s = openSession();
+ t = s.beginTransaction();
+ Note note = new Note();
+ note.setDescription( "a description" );
+ suite.getNotes().add( note );
+ address.getSuites().clear();
+ s.saveOrUpdate( address );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Long count = ( Long ) s.createQuery( "select count(*) from Suite" ).list().get( 0 );
+ assertEquals( "all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue() );
+ count = ( Long ) s.createQuery( "select count(*) from Note" ).list().get( 0 );
+ assertEquals( 0, count.longValue() );
+ s.delete( address );
+ t.commit();
+ s.close();
+ }
}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java 2008-10-29 21:21:07 UTC (rev 15444)
@@ -0,0 +1,33 @@
+package org.hibernate.test.deletetransient;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class Note {
+ private Long id;
+ private String description;
+
+ public Note() {
+ }
+
+ public Note(String description) {
+ this.description = description;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
\ No newline at end of file
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml 2008-10-29 20:40:17 UTC (rev 15443)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml 2008-10-29 21:21:07 UTC (rev 15444)
@@ -29,6 +29,28 @@
<generator class="increment"/>
</id>
<property name="info" type="string"/>
+ <set name="suites" lazy="true" inverse="false" cascade="all-delete-orphan">
+ <key column="ADDRESS_ID"/>
+ <one-to-many class="Suite"/>
+ </set>
</class>
-
+
+ <class name="Suite" table="T_SUITE">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="location" type="string"/>
+ <set name="notes" lazy="true" inverse="false" cascade="all-delete-orphan">
+ <key column="SUITE_ID"/>
+ <one-to-many class="Note"/>
+ </set>
+ </class>
+
+ <class name="Note" table="T_NOTE">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="description" type="string"/>
+ </class>
+
</hibernate-mapping>
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java 2008-10-29 21:21:07 UTC (rev 15444)
@@ -0,0 +1,47 @@
+package org.hibernate.test.deletetransient;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class Suite {
+ private Long id;
+ private String location;
+ private Set notes = new HashSet();
+
+ public Suite() {
+ }
+
+ public Suite(String location) {
+ this.location = location;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public Set getNotes() {
+ return notes;
+ }
+
+ public void setNotes(Set notes) {
+ this.notes = notes;
+ }
+}
\ No newline at end of file
16 years, 2 months
Hibernate SVN: r15443 - in core/branches/Branch_3_2: test/org/hibernate/test/deletetransient and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-10-29 16:40:17 -0400 (Wed, 29 Oct 2008)
New Revision: 15443
Added:
core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Note.java
core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Suite.java
Modified:
core/branches/Branch_3_2/src/org/hibernate/engine/Cascade.java
core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Address.java
core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Person.hbm.xml
Log:
HHH-2146 : NullpointerException in DefaultDeleteEventListener.deleteTransientEntity
Modified: core/branches/Branch_3_2/src/org/hibernate/engine/Cascade.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/engine/Cascade.java 2008-10-29 20:02:22 UTC (rev 15442)
+++ core/branches/Branch_3_2/src/org/hibernate/engine/Cascade.java 2008-10-29 20:40:17 UTC (rev 15443)
@@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.Iterator;
+import java.util.HashSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -352,7 +353,7 @@
if ( log.isTraceEnabled() ) {
log.trace("deleting orphaned entity instance: " + entityName);
}
- eventSource.delete( entityName, orphan, false, null );
+ eventSource.delete( entityName, orphan, false, new HashSet() );
}
}
}
Modified: core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Address.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Address.java 2008-10-29 20:02:22 UTC (rev 15442)
+++ core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Address.java 2008-10-29 20:40:17 UTC (rev 15443)
@@ -1,5 +1,8 @@
package org.hibernate.test.deletetransient;
+import java.util.Set;
+import java.util.HashSet;
+
/**
* todo: describe Address
*
@@ -8,6 +11,7 @@
public class Address {
private Long id;
private String info;
+ private Set suites = new HashSet();
public Address() {
}
@@ -31,4 +35,12 @@
public void setInfo(String info) {
this.info = info;
}
+
+ public Set getSuites() {
+ return suites;
+ }
+
+ public void setSuites(Set suites) {
+ this.suites = suites;
+ }
}
Modified: core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2008-10-29 20:02:22 UTC (rev 15442)
+++ core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2008-10-29 20:40:17 UTC (rev 15443)
@@ -105,4 +105,70 @@
t.commit();
s.close();
}
+
+ public void testCascadeAllFromClearedPersistentAssnToTransientEntity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ p.getAddresses().add( address );
+ s.save( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Suite suite = new Suite();
+ address.getSuites().add( suite );
+ p.getAddresses().clear();
+ s.saveOrUpdate( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ p = ( Person ) s.get( p.getClass(), p.getId() );
+ assertEquals( "persistent collection not cleared", 0, p.getAddresses().size() );
+ Long count = ( Long ) s.createQuery( "select count(*) from Address" ).list().get( 0 );
+ assertEquals( 1, count.longValue() );
+ count = ( Long ) s.createQuery( "select count(*) from Suite" ).list().get( 0 );
+ assertEquals( 0, count.longValue() );
+ s.delete( p );
+ t.commit();
+ s.close();
+ }
+
+ public void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ Suite suite = new Suite();
+ address.getSuites().add( suite );
+ s.save( address );
+ t.commit();
+ s.close();
+
+
+ s = openSession();
+ t = s.beginTransaction();
+ Note note = new Note();
+ note.setDescription( "a description" );
+ suite.getNotes().add( note );
+ address.getSuites().clear();
+ s.saveOrUpdate( address );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Long count = ( Long ) s.createQuery( "select count(*) from Suite" ).list().get( 0 );
+ assertEquals( "all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue() );
+ count = ( Long ) s.createQuery( "select count(*) from Note" ).list().get( 0 );
+ assertEquals( 0, count.longValue() );
+ s.delete( address );
+ t.commit();
+ s.close();
+ }
}
Added: core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Note.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Note.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Note.java 2008-10-29 20:40:17 UTC (rev 15443)
@@ -0,0 +1,33 @@
+package org.hibernate.test.deletetransient;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class Note {
+ private Long id;
+ private String description;
+
+ public Note() {
+ }
+
+ public Note(String description) {
+ this.description = description;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
\ No newline at end of file
Modified: core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Person.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Person.hbm.xml 2008-10-29 20:02:22 UTC (rev 15442)
+++ core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Person.hbm.xml 2008-10-29 20:40:17 UTC (rev 15443)
@@ -29,6 +29,28 @@
<generator class="increment"/>
</id>
<property name="info" type="string"/>
+ <set name="suites" lazy="true" inverse="false" cascade="all-delete-orphan">
+ <key column="ADDRESS_ID"/>
+ <one-to-many class="Suite"/>
+ </set>
</class>
-
+
+ <class name="Suite" table="T_SUITE">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="location" type="string"/>
+ <set name="notes" lazy="true" inverse="false" cascade="all-delete-orphan">
+ <key column="SUITE_ID"/>
+ <one-to-many class="Note"/>
+ </set>
+ </class>
+
+ <class name="Note" table="T_NOTE">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="description" type="string"/>
+ </class>
+
</hibernate-mapping>
Added: core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Suite.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Suite.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/deletetransient/Suite.java 2008-10-29 20:40:17 UTC (rev 15443)
@@ -0,0 +1,47 @@
+package org.hibernate.test.deletetransient;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class Suite {
+ private Long id;
+ private String location;
+ private Set notes = new HashSet();
+
+ public Suite() {
+ }
+
+ public Suite(String location) {
+ this.location = location;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public Set getNotes() {
+ return notes;
+ }
+
+ public void setNotes(Set notes) {
+ this.notes = notes;
+ }
+}
\ No newline at end of file
16 years, 2 months
Hibernate SVN: r15442 - in core/branches/JBOSS_CACHE_3/cache-jbosscache2/src: test/resources and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-10-29 16:02:22 -0400 (Wed, 29 Oct 2008)
New Revision: 15442
Modified:
core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/main/resources/org/hibernate/cache/jbc2/builder/jbc2-configs.xml
core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/resources/treecache.xml
Log:
Use MVCC in place of PESSIMISTIC (for JBC3 testing only!!!)
Modified: core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/main/resources/org/hibernate/cache/jbc2/builder/jbc2-configs.xml
===================================================================
(Binary files differ)
Modified: core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/resources/treecache.xml
===================================================================
--- core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/resources/treecache.xml 2008-10-29 19:48:02 UTC (rev 15441)
+++ core/branches/JBOSS_CACHE_3/cache-jbosscache2/src/test/resources/treecache.xml 2008-10-29 20:02:22 UTC (rev 15442)
@@ -51,9 +51,9 @@
<!-- Node locking scheme:
OPTIMISTIC
- PESSIMISTIC (default)
+ MVCC (default)
-->
- <attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
+ <attribute name="NodeLockingScheme">MVCC</attribute>
<!--
READ_COMMITTED is as strong as necessary for most 2nd Level Cache usage.
@@ -108,6 +108,9 @@
<!-- Must match the value of "useRegionBasedMarshalling" -->
<attribute name="InactiveOnStartup">true</attribute>
+ <!-- For now. disable asynchronous RPC marshalling/sending -->
+ <attribute name="SerializationExecutorPoolSize">0</attribute>
+
<!-- Specific eviction policy configurations. This is LRU -->
<attribute name="EvictionPolicyConfig">
<config>
16 years, 2 months
Hibernate SVN: r15441 - core/branches/JBOSS_CACHE_3/cache-jbosscache2.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-10-29 15:48:02 -0400 (Wed, 29 Oct 2008)
New Revision: 15441
Modified:
core/branches/JBOSS_CACHE_3/cache-jbosscache2/pom.xml
Log:
Set up pom for JBC 3 testing
Modified: core/branches/JBOSS_CACHE_3/cache-jbosscache2/pom.xml
===================================================================
--- core/branches/JBOSS_CACHE_3/cache-jbosscache2/pom.xml 2008-10-29 19:35:10 UTC (rev 15440)
+++ core/branches/JBOSS_CACHE_3/cache-jbosscache2/pom.xml 2008-10-29 19:48:02 UTC (rev 15441)
@@ -12,27 +12,28 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jbosscache2</artifactId>
<packaging>jar</packaging>
+ <version>3.3.1.JBC3-SNAPSHOT</version>
- <name>Hibernate JBossCache2.x Integration</name>
- <description>Integration of Hibernate with JBossCache (based on JBossCache2.x APIs)</description>
+ <name>Hibernate JBossCache3.x Integration</name>
+ <description>Integration of Hibernate with JBossCache 3 (based on JBossCache2.x APIs)</description>
<dependencies>
<dependency>
<groupId>${groupId}</groupId>
<artifactId>hibernate-core</artifactId>
- <version>${version}</version>
+ <version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
- <version>2.1.1.GA</version>
+ <version>3.0.0-SNAPSHOT</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>${groupId}</groupId>
<artifactId>hibernate-testing</artifactId>
- <version>${version}</version>
+ <version>3.3.1.GA</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -48,6 +49,13 @@
<version>3.4.GA</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
16 years, 2 months
Hibernate SVN: r15440 - core/branches.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-10-29 15:35:10 -0400 (Wed, 29 Oct 2008)
New Revision: 15440
Added:
core/branches/JBOSS_CACHE_3/
Log:
Create dev branch for testing of JBC 3 and MVCC
Copied: core/branches/JBOSS_CACHE_3 (from rev 15439, core/tags/hibernate-3.3.1.GA)
16 years, 2 months
Hibernate SVN: r15439 - search/trunk/src/test/org/hibernate/search/test/worker/duplication.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-10-29 12:59:46 -0400 (Wed, 29 Oct 2008)
New Revision: 15439
Modified:
search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
Log:
Added test case for HSEARCH-257
Modified: search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java 2008-10-29 16:52:19 UTC (rev 15438)
+++ search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java 2008-10-29 16:59:46 UTC (rev 15439)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
package org.hibernate.search.test.worker.duplication;
import java.util.List;
@@ -23,7 +23,7 @@
public class WorkDuplicationTest extends SearchTestCase {
/**
- * This test assures that HSEARCH-257. Before the fix SEarch would issue another <code>AddLuceneWork</code> after
+ * This test assures that HSEARCH-257. Before the fix Search would issue another <code>AddLuceneWork</code> after
* the <code>DeleteLuceneWork</code>. This lead to the fact that after the deletion there was still a Lucene document
* in the index.
*
@@ -74,7 +74,8 @@
IndexSearcher searcher = new IndexSearcher( reader );
try {
- // we have to test using Lucene directly.
+ // we have to test using Lucene directly since query loaders will ignore hits for which there is no
+ // database entry
TopDocs topDocs = searcher.search( luceneQuery, null, 1 );
assertTrue( "We should have no hit", topDocs.totalHits == 0 );
}
16 years, 2 months
Hibernate SVN: r15438 - in search/trunk/src/test/org/hibernate/search/test/worker: duplication and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-10-29 12:52:19 -0400 (Wed, 29 Oct 2008)
New Revision: 15438
Added:
search/trunk/src/test/org/hibernate/search/test/worker/duplication/
search/trunk/src/test/org/hibernate/search/test/worker/duplication/EmailAddress.java
search/trunk/src/test/org/hibernate/search/test/worker/duplication/Person.java
search/trunk/src/test/org/hibernate/search/test/worker/duplication/SpecialPerson.java
search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
Log:
Added test case for HSEARCH-257
Added: search/trunk/src/test/org/hibernate/search/test/worker/duplication/EmailAddress.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/worker/duplication/EmailAddress.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/worker/duplication/EmailAddress.java 2008-10-29 16:52:19 UTC (rev 15438)
@@ -0,0 +1,57 @@
+// $Id:$
+package org.hibernate.search.test.worker.duplication;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Store;
+
+/**
+ * Test entity for HSEARCH-257.
+ *
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class EmailAddress implements Serializable {
+ @Id
+ @GeneratedValue
+ @DocumentId
+ private int id;
+
+ private boolean isDefaultAddress;
+
+ @Field(store = Store.YES, index = Index.NO)
+ private String address;
+
+ public EmailAddress() {
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public boolean isDefaultAddress() {
+ return isDefaultAddress;
+ }
+
+ public void setDefaultAddress(boolean isDefault) {
+ isDefaultAddress = isDefault;
+ }
+}
Added: search/trunk/src/test/org/hibernate/search/test/worker/duplication/Person.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/worker/duplication/Person.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/worker/duplication/Person.java 2008-10-29 16:52:19 UTC (rev 15438)
@@ -0,0 +1,82 @@
+// $Id:$
+package org.hibernate.search.test.worker.duplication;
+
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.persistence.OneToOne;
+import javax.persistence.JoinColumn;
+import javax.persistence.CascadeType;
+import javax.persistence.FetchType;
+
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+
+/**
+ * Test entity for HSEARCH-257.
+ *
+ * @author Marina Vatkina
+ * @author Hardy Ferentschik
+ */
+@Entity
+@Table
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@DiscriminatorColumn(name = "DISC", discriminatorType = DiscriminatorType.STRING)
+public class Person {
+
+ @Id
+ @GeneratedValue
+ @DocumentId
+ private int id;
+
+ @Field(index = Index.TOKENIZED, name = "Content")
+ private String name;
+
+ @OneToOne(fetch = FetchType.EAGER, cascade = {
+ CascadeType.MERGE,
+ CascadeType.PERSIST
+ })
+ @JoinColumn(name = "DEFAULT_EMAILADDRESS_FK")
+ private EmailAddress defaultEmailAddress;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * This function return the value of defaultEmailAddress.
+ *
+ * @return the defaultEmailAddress
+ */
+
+ public EmailAddress getDefaultEmailAddress() {
+ return defaultEmailAddress;
+ }
+
+ /**
+ * This function sets the value of the defaultEmailAddress.
+ *
+ * @param defaultEmailAddress the defaultEmailAddress to set
+ */
+ protected void setDefaultEmailAddress(EmailAddress defaultEmailAddress) {
+ this.defaultEmailAddress = defaultEmailAddress;
+ }
+}
Added: search/trunk/src/test/org/hibernate/search/test/worker/duplication/SpecialPerson.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/worker/duplication/SpecialPerson.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/worker/duplication/SpecialPerson.java 2008-10-29 16:52:19 UTC (rev 15438)
@@ -0,0 +1,127 @@
+// $Id:$
+package org.hibernate.search.test.worker.duplication;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.CascadeType;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.Cascade;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * Test entity for HSEARCH-257.
+ *
+ * @author Hardy Ferentschik
+ */
+@Entity
+@Indexed
+@DiscriminatorValue("SpecialPerson")
+public class SpecialPerson extends Person {
+
+ @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
+ @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
+ @JoinColumn(name = "SPECIALPERSON_FK")
+ @IndexedEmbedded
+ private Set<EmailAddress> emailAddressSet = new HashSet<EmailAddress>();
+
+ public Set<EmailAddress> getEmailAddressSet() {
+ return emailAddressSet;
+ }
+
+ public void setEmailAddressSet(Set<EmailAddress> emailAddresses) {
+ EmailAddress defaultVal = getDefaultEmailAddressFromList( emailAddresses );
+
+ super.setDefaultEmailAddress( defaultVal );
+
+ emailAddressSet = emailAddresses;
+ }
+
+ /**
+ * This function add the provided emailAddress to the existing set.
+ *
+ * @param emailAddress EmailAddress to add the the set
+ */
+ public void addEmailAddress(EmailAddress emailAddress) {
+ if ( emailAddress != null ) {
+ if ( emailAddressSet == null ) {
+ emailAddressSet = new HashSet<EmailAddress>();
+ }
+
+ // We cannot add another default address to the list. Check if
+ // default
+ // address has been set before.
+ if ( emailAddress.isDefaultAddress() ) {
+ // Replace old default address with new one.
+ processDefaultEmailAddress( emailAddress, emailAddressSet );
+
+ super.setDefaultEmailAddress( emailAddress );
+ }
+ else {
+ emailAddressSet.add( emailAddress );
+ }
+ }
+ }
+
+ private void processDefaultEmailAddress(EmailAddress defaultVal,
+ Set<EmailAddress> list) {
+ if ( defaultVal != null ) {
+ boolean addToList = true;
+
+ for ( EmailAddress aList : list ) {
+
+ if ( defaultVal.equals( aList ) ) {
+ aList.setDefaultAddress( true );
+ addToList = false;
+ }
+ else if ( aList.isDefaultAddress() ) {
+ // Reset default value.
+ aList.setDefaultAddress( false );
+ }
+ }
+
+ // Add Email Address to the list if list does not contain it.
+ if ( addToList ) {
+ list.add( defaultVal );
+ }
+ }
+ }
+
+ private EmailAddress getDefaultEmailAddressFromList(
+ Set<EmailAddress> list) {
+ EmailAddress address = null;
+ EmailAddress firstAddressInList = null;
+ boolean found = false;
+
+ if ( list != null ) {
+ for ( EmailAddress aList : list ) {
+ address = aList;
+
+ if ( address != null ) {
+ if ( firstAddressInList == null ) {
+ firstAddressInList = address;
+ }
+
+ if ( address.isDefaultAddress() ) {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if ( !found && firstAddressInList != null ) {
+ // If default address was not found we set the first one as
+ // default.
+ firstAddressInList.setDefaultAddress( true );
+ address = firstAddressInList;
+ }
+ }
+
+ return address;
+ }
+}
Added: search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java 2008-10-29 16:52:19 UTC (rev 15438)
@@ -0,0 +1,91 @@
+// $Id:$
+package org.hibernate.search.test.worker.duplication;
+
+import java.util.List;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.TopDocs;
+
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextQuery;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.reader.ReaderProvider;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.test.SearchTestCase;
+
+/**
+ * Testcase for HSEARCH-257.
+ */
+public class WorkDuplicationTest extends SearchTestCase {
+
+ /**
+ * This test assures that HSEARCH-257. Before the fix SEarch would issue another <code>AddLuceneWork</code> after
+ * the <code>DeleteLuceneWork</code>. This lead to the fact that after the deletion there was still a Lucene document
+ * in the index.
+ *
+ * @throws Exception in case the test fails.
+ */
+ public void testNoWorkDuplication() throws Exception {
+
+ FullTextSession s = org.hibernate.search.Search.getFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+
+ // create new customer
+ SpecialPerson person = new SpecialPerson();
+ person.setName( "Joe Smith" );
+
+ EmailAddress emailAddress = new EmailAddress();
+ emailAddress.setAddress( "foo(a)foobar.com" );
+ emailAddress.setDefaultAddress(true);
+
+ person.addEmailAddress( emailAddress );
+
+ // persist the customer
+ s.persist( person );
+ tx.commit();
+
+ // search if the record made it into the index
+ tx = s.beginTransaction();
+ String searchQuery = "Joe";
+ QueryParser parser = new QueryParser( "Content", new StandardAnalyzer() );
+ Query luceneQuery = parser.parse( searchQuery );
+ FullTextQuery query = s.createFullTextQuery( luceneQuery );
+ List results = query.list();
+ assertTrue( "We should have a hit", results.size() == 1 );
+ tx.commit();
+
+ // Now try to delete
+ tx = s.beginTransaction();
+ int id = person.getId();
+ person = ( SpecialPerson ) s.get( SpecialPerson.class, id );
+ s.delete( person );
+ tx.commit();
+
+ // Search and the record via Lucene directly
+ tx = s.beginTransaction();
+
+ DirectoryProvider directoryProvider = s.getSearchFactory().getDirectoryProviders( SpecialPerson.class )[0];
+ ReaderProvider readerProvider = s.getSearchFactory().getReaderProvider();
+ IndexReader reader = readerProvider.openReader( directoryProvider );
+ IndexSearcher searcher = new IndexSearcher( reader );
+
+ try {
+ // we have to test using Lucene directly.
+ TopDocs topDocs = searcher.search( luceneQuery, null, 1 );
+ assertTrue( "We should have no hit", topDocs.totalHits == 0 );
+ }
+ finally {
+ readerProvider.closeReader( reader );
+ }
+ tx.commit();
+ s.close();
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] { Person.class, EmailAddress.class, SpecialPerson.class };
+ }
+}
Property changes on: search/trunk/src/test/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
16 years, 2 months