Hibernate SVN: r11030 - branches/Branch_3_2/HibernateExt/tools
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-09 06:19:24 -0500 (Tue, 09 Jan 2007)
New Revision: 11030
Modified:
branches/Branch_3_2/HibernateExt/tools/build.xml
Log:
bump
Modified: branches/Branch_3_2/HibernateExt/tools/build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/build.xml 2007-01-09 11:19:09 UTC (rev 11029)
+++ branches/Branch_3_2/HibernateExt/tools/build.xml 2007-01-09 11:19:24 UTC (rev 11030)
@@ -7,7 +7,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Tools"/>
<property name="name" value="hibernate-tools"/>
- <property name="version" value="3.2.0snapshotb9"/>
+ <property name="version" value="3.2.0b9"/>
<property name="javadoc.packagenames" value="org.hibernate.tool"/>
17 years, 8 months
Hibernate SVN: r11029 - branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-09 06:19:09 -0500 (Tue, 09 Jan 2007)
New Revision: 11029
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/BasicMultiSchemaTest.java
Log:
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/BasicMultiSchemaTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/BasicMultiSchemaTest.java 2007-01-09 11:19:00 UTC (rev 11028)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/BasicMultiSchemaTest.java 2007-01-09 11:19:09 UTC (rev 11029)
@@ -41,7 +41,7 @@
"create table basic ( a int not null, name varchar(20), primary key (a) )",
"create table somecolumnsnopk ( pk varchar(25) not null, b char, c int not null, aBoolean boolean )",
"create table multikeyed ( orderid varchar(10), customerid varchar(10), name varchar(10), primary key(orderid, customerid) )",
- "create schema otherschema authorization sa",
+ "create schema otherschema authorization dba",
"create table otherschema.basic ( a int not null, name varchar(20), primary key (a) )",
};
}
17 years, 8 months
Hibernate SVN: r11028 - branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-09 06:19:00 -0500 (Tue, 09 Jan 2007)
New Revision: 11028
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DefaultSchemaCatalogTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/JdbcHbm2JavaEjb3Test.java
Log:
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DefaultSchemaCatalogTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DefaultSchemaCatalogTest.java 2007-01-09 11:17:39 UTC (rev 11027)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DefaultSchemaCatalogTest.java 2007-01-09 11:19:00 UTC (rev 11028)
@@ -121,7 +121,7 @@
protected String[] getCreateSQL() {
return new String[] {
- "create schema ovrtest AUTHORIZATION SA ",
+ "create schema ovrtest AUTHORIZATION DBA ",
"create table ovrtest.catmaster ( id char not null, name varchar(20), primary key (id) )",
"create table ovrtest.catchild ( childid char not null, masterref char, primary key (childid), foreign key (masterref) references catmaster(id) )",
"create table master ( id char not null, name varchar(20), primary key (id) )",
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java 2007-01-09 11:17:39 UTC (rev 11027)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java 2007-01-09 11:19:00 UTC (rev 11028)
@@ -5,6 +5,11 @@
package org.hibernate.tool.hbm2x;
import java.io.File;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Iterator;
import org.dom4j.Document;
@@ -57,7 +62,22 @@
cfg2configure.setReverseEngineeringStrategy(configurableNamingStrategy);
}
- public void testGenerateJava() {
+ public void testGenerateJava() throws SQLException, ClassNotFoundException {
+
+ Class.forName("org.h2.Driver");
+ Connection conn = DriverManager.getConnection("jdbc:h2:mem:", "sa", "");
+ conn.createStatement().execute("CREATE TABLE IF NOT EXISTS TEST(ID INT)");
+ DatabaseMetaData meta = conn.getMetaData();
+ ResultSet rs = meta.getTables(null, null, "TEST", null);
+ while(rs.next()) {
+ String cat = rs.getString("TABLE_CAT");
+ String schema = rs.getString("TABLE_SCHEM");
+ String table = rs.getString("TABLE_NAME");
+ ResultSet rs2 = meta.getColumns(cat, schema, table, null);
+ while(rs2.next()) {
+ System.out.println(table + "." + rs2.getString("COLUMN_NAME"));
+ }
+ }
POJOExporter exporter = new POJOExporter(cfg,getOutputDir());
exporter.start();
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java 2007-01-09 11:17:39 UTC (rev 11027)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java 2007-01-09 11:19:00 UTC (rev 11028)
@@ -220,13 +220,10 @@
}
- protected void tearDown() throws Exception {
-
- //super.tearDown();
- }
+
protected String getBaseForMappings() {
return "org/hibernate/tool/hbm2x/";
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/JdbcHbm2JavaEjb3Test.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/JdbcHbm2JavaEjb3Test.java 2007-01-09 11:17:39 UTC (rev 11027)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/JdbcHbm2JavaEjb3Test.java 2007-01-09 11:19:00 UTC (rev 11028)
@@ -53,10 +53,6 @@
}
- protected void tearDown() throws Exception {
-
- //super.tearDown();
- }
protected String getBaseForMappings() {
17 years, 8 months
Hibernate SVN: r11027 - tags/TOOLS_3_2_0_BETA9
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2007-01-09 06:17:39 -0500 (Tue, 09 Jan 2007)
New Revision: 11027
Removed:
tags/TOOLS_3_2_0_BETA9/HibernateExt/
Log:
bad tag
17 years, 8 months
Hibernate SVN: r11026 - in branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg: . annotations
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-08 18:22:41 -0500 (Mon, 08 Jan 2007)
New Revision: 11026
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/EntityBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
Log:
ANN-517
Default NodeName value not set in HAN leading to NPE in DOM4J mode (based on Daniel)
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-01-08 19:19:08 UTC (rev 11025)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-01-08 23:22:41 UTC (rev 11026)
@@ -1646,6 +1646,7 @@
else {
comp.setComponentClassName( comp.getOwner().getClassName() );
}
+ comp.setNodeName( inferredData.getPropertyName() );
String subpath = StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() );
log.debug( "Binding component with path: " + subpath );
PropertyHolder subHolder = PropertyHolderBuilder.buildPropertyHolder(
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java 2007-01-08 19:19:08 UTC (rev 11025)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java 2007-01-08 23:22:41 UTC (rev 11026)
@@ -65,6 +65,7 @@
clone.setInsertable( property.isInsertable() );
clone.setLazy( property.isLazy() );
clone.setName( property.getName() );
+ clone.setNodeName( property.getNodeName() );
clone.setNaturalIdentifier( property.isNaturalIdentifier() );
clone.setOptimisticLocked( property.isOptimisticLocked() );
clone.setOptional( property.isOptional() );
@@ -112,6 +113,7 @@
new Component( (PersistentClass) columnOwner ) :
new Component( (Join) columnOwner );
embeddedComp.setEmbedded( true );
+ embeddedComp.setNodeName( syntheticPropertyName );
embeddedComp.setComponentClassName( embeddedComp.getOwner().getClassName() );
for ( Property property : properties ) {
Property clone = BinderHelper.shallowCopy( property );
@@ -122,7 +124,7 @@
}
synthProp = new Property();
synthProp.setName( syntheticPropertyName );
- //synthProp.setNodeName(syntheticPropertyName);
+ synthProp.setNodeName(syntheticPropertyName);
synthProp.setPersistentClass( ownerEntity );
synthProp.setUpdateable( false );
synthProp.setInsertable( false );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-01-08 19:19:08 UTC (rev 11025)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-01-08 23:22:41 UTC (rev 11026)
@@ -283,6 +283,7 @@
this.collection = createCollection( propertyHolder.getPersistentClass() );
log.debug( "Collection role: " + StringHelper.qualify( propertyHolder.getPath(), propertyName ) );
collection.setRole( StringHelper.qualify( propertyHolder.getPath(), propertyName ) );
+ collection.setNodeName( propertyName );
if ( property.isAnnotationPresent( org.hibernate.annotations.MapKey.class ) && mapKeyPropertyName != null ) {
throw new AnnotationException(
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/EntityBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/EntityBinder.java 2007-01-08 19:19:08 UTC (rev 11025)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/EntityBinder.java 2007-01-08 23:22:41 UTC (rev 11026)
@@ -156,6 +156,7 @@
public void bindEntity() {
persistentClass.setAbstract( annotatedClass.isAbstract() );
persistentClass.setClassName( annotatedClass.getName() );
+ persistentClass.setNodeName( name );
//persistentClass.setDynamic(false); //no longer needed with the Entity name refactoring?
persistentClass.setEntityName( annotatedClass.getName() );
bindDiscriminatorValue();
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2007-01-08 19:19:08 UTC (rev 11025)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2007-01-08 23:22:41 UTC (rev 11026)
@@ -298,6 +298,8 @@
Iterator properties = component.getPropertyIterator();
Component indexComponent = new Component( collection );
indexComponent.setComponentClassName( component.getComponentClassName() );
+ //TODO I don't know if this is appropriate
+ indexComponent.setNodeName( "index" );
while ( properties.hasNext() ) {
Property current = (Property) properties.next();
Property newProperty = new Property();
@@ -307,6 +309,7 @@
newProperty.setUpdateable( false );
newProperty.setMetaAttributes( current.getMetaAttributes() );
newProperty.setName( current.getName() );
+ newProperty.setNodeName( current.getNodeName() );
newProperty.setNaturalIdentifier( false );
//newProperty.setOptimisticLocked( false );
newProperty.setOptional( false );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2007-01-08 19:19:08 UTC (rev 11025)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2007-01-08 23:22:41 UTC (rev 11026)
@@ -122,6 +122,7 @@
log.debug( "Building property " + name );
Property prop = new Property();
prop.setName( name );
+ prop.setNodeName( name );
prop.setValue( value );
prop.setInsertable( insertable );
prop.setUpdateable( updatable );
17 years, 8 months
Hibernate SVN: r11025 - in branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search: backend backend/impl backend/impl/jms engine
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-08 14:19:08 -0500 (Mon, 08 Jan 2007)
New Revision: 11025
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/QueueWorker.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkQueue.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedQueueWorker.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/jms/
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/jms/JMSQueueWorker.java
Removed:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkQueue.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Worker.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java
Log:
ANN-523 JMS Worker wo test
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/QueueWorker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/QueueWorker.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/QueueWorker.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -0,0 +1,26 @@
+//$Id: $
+package org.hibernate.search.backend;
+
+import java.util.Properties;
+import java.util.Map;
+import java.util.List;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.store.DirectoryProvider;
+
+/**
+ * Execute the work for a given queue
+ *
+ * @author Emmanuel Bernard
+ */
+public interface QueueWorker extends Runnable {
+ void run();
+
+ void initialize(Properties props, Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders);
+
+ void setQueue(List<Work> queue);
+
+}
Deleted: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkQueue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkQueue.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkQueue.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -1,24 +0,0 @@
-//$Id: $
-package org.hibernate.search.backend;
-
-/**
- * Set of work operations
- *
- * @author Emmanuel Bernard
- */
-public interface WorkQueue {
- /**
- * Add a work
- */
- void add(Work work);
-
- /**
- * Execute works
- */
- void performWork();
-
- /**
- * Rollback works
- */
- void cancelWork();
-}
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkQueue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkQueue.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/WorkQueue.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -0,0 +1,26 @@
+//$Id: $
+package org.hibernate.search.backend;
+
+import org.hibernate.search.backend.Work;
+
+/**
+ * Set of work operations
+ *
+ * @author Emmanuel Bernard
+ */
+public interface WorkQueue {
+ /**
+ * Add a work
+ */
+ void add(Work work);
+
+ /**
+ * Execute works
+ */
+ void performWork();
+
+ /**
+ * Rollback works
+ */
+ void cancelWork();
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Worker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Worker.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/Worker.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -15,7 +15,6 @@
* Perform work for a given session. This implementation has to be multi threaded
* @author Emmanuel Bernard
*/
-//TODO merge worker and workQueue to do a list of workers through work delegation
public interface Worker {
void performWork(Work work, EventSource session);
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedQueueWorker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedQueueWorker.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedQueueWorker.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -0,0 +1,77 @@
+//$Id: $
+package org.hibernate.search.backend.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.Workspace;
+import org.hibernate.search.backend.AddWork;
+import org.hibernate.search.backend.QueueWorker;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.engine.DocumentBuilder;
+
+/**
+ * @author Emmanuel Bernard
+*/
+class BatchedQueueWorker implements QueueWorker {
+ private List<Work> queue;
+ private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
+ private Map<Class, DocumentBuilder<Object>> documentBuilders;
+
+ public void run() {
+ Workspace workspace;
+ LuceneWorker worker;
+ workspace = new Workspace( documentBuilders, lockableDirectoryProviders );
+ worker = new LuceneWorker( workspace );
+ try {
+ deadlockFreeQueue(queue, workspace);
+ for ( Work work : queue ) {
+ worker.performWork( work );
+ }
+ }
+ finally {
+ workspace.clean();
+ queue.clear();
+ }
+ }
+
+ public void initialize(Properties props, Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ this.documentBuilders = documentBuilders;
+ this.lockableDirectoryProviders = lockableDirectoryProviders;
+ }
+
+ public void setQueue(List<Work> queue) {
+ this.queue = queue;
+ }
+
+ /**
+ * one must lock the directory providers in the exact same order to avoid
+ * dead lock between concurrent threads or processes
+ * To achieve that, the work will be done per directory provider
+ */
+ private void deadlockFreeQueue(List<Work> queue, final Workspace workspace) {
+ Collections.sort( queue, new Comparator<Work>() {
+ public int compare(Work o1, Work o2) {
+ long h1 = getWorkHashCode( o1, workspace );
+ long h2 = getWorkHashCode( o2, workspace );
+ return h1 < h2 ?
+ -1 :
+ h1 == h2 ?
+ 0 :
+ 1;
+ }
+ } );
+ }
+
+ private long getWorkHashCode(Work work, Workspace workspace) {
+ long h = workspace.getDocumentBuilder( work.getEntity() ).hashCode() * 2;
+ if (work instanceof AddWork ) h+=1; //addwork after deleteWork
+ return h;
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -4,11 +4,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.Properties;
import java.util.concurrent.locks.ReentrantLock;
-import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
@@ -16,14 +13,11 @@
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.store.DirectoryProvider;
-import org.hibernate.search.backend.impl.LuceneWorker;
import org.hibernate.search.backend.WorkQueue;
-import org.hibernate.search.backend.Workspace;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.UpdateWork;
import org.hibernate.search.backend.DeleteWork;
import org.hibernate.search.backend.AddWork;
-import org.hibernate.search.backend.Worker;
import org.hibernate.search.Environment;
/**
@@ -74,7 +68,9 @@
//TODO implements parallel batchWorkers (one per Directory)
public void performWork() {
- BatchWorker batchWorker = new BatchWorker( queue, documentBuilders, lockableDirectoryProviders, properties );
+ BatchedQueueWorker batchWorker = new BatchedQueueWorker();
+ batchWorker.initialize( properties, documentBuilders, lockableDirectoryProviders );
+ batchWorker.setQueue( queue );
if (sync) {
batchWorker.run();
}
@@ -87,59 +83,4 @@
queue.clear();
}
- private class BatchWorker implements Runnable {
- private List<Work> queue;
- private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
- private Map<Class, DocumentBuilder<Object>> documentBuilders;
-
-
- public BatchWorker(List<Work> queue, Map<Class, DocumentBuilder<Object>> documentBuilders,
- Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders, Properties properties) {
- this.queue = queue;
- this.documentBuilders = documentBuilders;
- this.lockableDirectoryProviders = lockableDirectoryProviders;
- }
-
- public void run() {
- Workspace workspace;
- LuceneWorker worker;
- workspace = new Workspace( documentBuilders, lockableDirectoryProviders );
- worker = new LuceneWorker( workspace );
- try {
- deadlockFreeQueue(queue, workspace);
- for ( Work work : queue ) {
- worker.performWork( work );
- }
- }
- finally {
- workspace.clean();
- queue.clear();
- }
- }
-
- /**
- * one must lock the directory providers in the exact same order to avoid
- * dead lock between concurrent threads or processes
- * To achieve that, the work will be done per directory provider
- */
- private void deadlockFreeQueue(List<Work> queue, final Workspace workspace) {
- Collections.sort( queue, new Comparator<Work>() {
- public int compare(Work o1, Work o2) {
- long h1 = getWorkHashCode( o1, workspace );
- long h2 = getWorkHashCode( o2, workspace );
- return h1 < h2 ?
- -1 :
- h1 == h2 ?
- 0 :
- 1;
- }
- } );
- }
-
- private long getWorkHashCode(Work work, Workspace workspace) {
- long h = workspace.getDocumentBuilder( work.getEntity() ).hashCode() * 2;
- if (work instanceof AddWork) h+=1; //addwork after deleteWork
- return h;
- }
- }
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -12,7 +12,6 @@
import org.hibernate.search.util.WeakIdentityHashMap;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.store.DirectoryProvider;
-import org.hibernate.search.Environment;
import org.hibernate.event.EventSource;
import org.hibernate.Transaction;
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/jms/JMSQueueWorker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/jms/JMSQueueWorker.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/jms/JMSQueueWorker.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -0,0 +1,133 @@
+//$Id: $
+package org.hibernate.search.backend.impl.jms;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.concurrent.locks.ReentrantLock;
+import java.io.Serializable;
+
+import javax.jms.QueueSender;
+import javax.jms.QueueConnection;
+import javax.jms.Queue;
+import javax.jms.QueueSession;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.ObjectMessage;
+import javax.jms.JMSException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.Context;
+
+import org.hibernate.search.backend.QueueWorker;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.Environment;
+import org.hibernate.HibernateException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class JMSQueueWorker implements QueueWorker {
+ private List<Work> queue;
+ private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
+ private Map<Class, DocumentBuilder<Object>> documentBuilders;
+ private String jmsQueueName;
+ private String jmsConnectionFactoryName;
+ private static final String JNDI_PREFIX = Environment.WORKER_PREFIX + "jndi.";
+ private Properties properties;
+ private Queue jmsQueue;
+ private QueueConnectionFactory factory;
+
+ public void run() {
+ resetJMSTools();
+ QueueConnection cnn = null;
+ QueueSender sender = null;
+ QueueSession session = null;
+ try {
+ cnn = factory.createQueueConnection();
+ //TODO make transacted parameterized
+ session = cnn.createQueueSession( false, QueueSession.AUTO_ACKNOWLEDGE );
+
+ ObjectMessage message = session.createObjectMessage( );
+ message.setObject( (Serializable) this.queue );
+
+ sender = session.createSender( jmsQueue );
+ sender.send( message );
+
+ session.close();
+ cnn.close();
+ }
+ catch( JMSException e ) {
+ throw new HibernateException("Unable to send Search work to JMS queue: " + jmsQueueName, e);
+ }
+ }
+
+ private InitialContext getInitialContext(Properties properties) throws NamingException {
+ Properties jndiProps = getJndiProperties( properties );
+ if (jndiProps.size() == 0) {
+ return new InitialContext( );
+ }
+ else {
+ return new InitialContext( jndiProps );
+ }
+ }
+
+ public void initialize(Properties props, Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ this.documentBuilders = documentBuilders;
+ this.lockableDirectoryProviders = lockableDirectoryProviders;
+ this.properties = props;
+ this.jmsConnectionFactoryName = props.getProperty( Environment.WORKER_PREFIX + "jms.connection_factory" );
+ this.jmsQueueName = props.getProperty( Environment.WORKER_PREFIX + "jms.queue" );
+ resetJMSTools();
+
+ }
+
+ private void resetJMSTools() {
+ if (jmsQueue != null && factory != null) return;
+ try {
+ InitialContext initialContext = getInitialContext(properties);
+ jmsQueue = (Queue) initialContext.lookup( jmsQueueName );
+ factory = (QueueConnectionFactory) initialContext.lookup( jmsConnectionFactoryName );
+ }
+ catch (NamingException e) {
+ throw new HibernateException("Unable to lookup Search queue and connection factory", e);
+ }
+ }
+
+ public void setQueue(List<Work> queue) {
+ this.queue = queue;
+ }
+
+ public static Properties getJndiProperties(Properties properties) {
+
+ HashSet specialProps = new HashSet();
+ specialProps.add( JNDI_PREFIX + "class" );
+ specialProps.add( JNDI_PREFIX + "url" );
+
+ Iterator iter = properties.keySet().iterator();
+ Properties result = new Properties();
+ while ( iter.hasNext() ) {
+ String prop = (String) iter.next();
+ if ( prop.indexOf(JNDI_PREFIX) > -1 && !specialProps.contains(prop) ) {
+ result.setProperty(
+ prop.substring( JNDI_PREFIX.length()+1 ),
+ properties.getProperty(prop)
+ );
+ }
+ }
+
+ String jndiClass = properties.getProperty(JNDI_PREFIX + "class");
+ String jndiURL = properties.getProperty(JNDI_PREFIX + "url");
+ // we want to be able to just use the defaults,
+ // if JNDI environment properties are not supplied
+ // so don't put null in anywhere
+ if (jndiClass != null) result.put( Context.INITIAL_CONTEXT_FACTORY, jndiClass);
+ if (jndiURL != null) result.put(Context.PROVIDER_URL, jndiURL);
+
+ return result;
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-01-08 19:13:17 UTC (rev 11024)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-01-08 19:19:08 UTC (rev 11025)
@@ -195,7 +195,7 @@
return Field.Index.NO_NORMS;
case TOKENIZED:
return Field.Index.TOKENIZED;
- case UN_TOKENISED:
+ case UN_TOKENIZED:
return Field.Index.UN_TOKENIZED;
default:
throw new AssertionFailure( "Unexpected Index: " + index );
17 years, 8 months
Hibernate SVN: r11024 - branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/annotations
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-08 14:13:17 -0500 (Mon, 08 Jan 2007)
New Revision: 11024
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/annotations/Index.java
Log:
ANN-512
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/annotations/Index.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/annotations/Index.java 2007-01-08 13:55:36 UTC (rev 11023)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/annotations/Index.java 2007-01-08 19:13:17 UTC (rev 11024)
@@ -22,7 +22,7 @@
* As no analyzer is used the value will be stored as a single term. This is
* useful for unique Ids like product numbers.
*/
- UN_TOKENISED,
+ UN_TOKENIZED,
/**
* Index the field's value without an Analyzer, and disable
* the storing of norms. No norms means that index-time boosting
17 years, 8 months
Hibernate SVN: r11023 - branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/util
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-08 08:55:36 -0500 (Mon, 08 Jan 2007)
New Revision: 11023
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/util/WeakIdentityHashMap.java
Log:
generic weakidentityhashmap
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/util/WeakIdentityHashMap.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/util/WeakIdentityHashMap.java 2007-01-08 12:23:31 UTC (rev 11022)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/util/WeakIdentityHashMap.java 2007-01-08 13:55:36 UTC (rev 11023)
@@ -58,7 +58,7 @@
* @see java.util.IdentityHashMap
* @see java.util.WeakHashMap
*/
-public class WeakIdentityHashMap /*extends AbstractMap*/ implements Map {
+public class WeakIdentityHashMap<K,V> /*extends AbstractMap*/ implements Map<K,V> {
/**
* The default initial capacity -- MUST be a power of two.
@@ -80,7 +80,7 @@
/**
* The table, resized as necessary. Length MUST Always be a power of two.
*/
- private Entry[] table;
+ private Entry<K,V>[] table;
/**
* The number of key-value mappings contained in this weak hash map.
@@ -195,16 +195,16 @@
/**
* Use NULL_KEY for key if it is null.
*/
- private static Object maskNull(Object key) {
+ private static <T> T maskNull(T key) {
return ( key == null ?
- NULL_KEY :
+ (T) NULL_KEY : //i don't think there is a better way
key );
}
/**
* Return internal representation of null key back to caller as null
*/
- private static Object unmaskNull(Object key) {
+ private static <T> T unmaskNull(T key) {
return ( key == NULL_KEY ?
null :
key );
@@ -258,7 +258,7 @@
/**
* Return the table after first expunging stale entries
*/
- private Entry[] getTable() {
+ private Entry<K,V>[] getTable() {
expungeStaleEntries();
return table;
}
@@ -300,12 +300,12 @@
* <tt>null</tt> if the map contains no mapping for this key.
* @see #put(Object,Object)
*/
- public Object get(Object key) {
+ public V get(Object key) {
Object k = maskNull( key );
int h = hash( k );
- Entry[] tab = getTable();
+ Entry<K,V>[] tab = getTable();
int index = indexFor( h, tab.length );
- Entry e = tab[index];
+ Entry<K,V> e = tab[index];
while ( e != null ) {
if ( e.hash == h && k == e.get() )
return e.value;
@@ -330,12 +330,12 @@
* Returns the entry associated with the specified key in the HashMap.
* Returns null if the HashMap contains no mapping for this key.
*/
- Entry getEntry(Object key) {
+ Entry<K,V> getEntry(Object key) {
Object k = maskNull( key );
int h = hash( k );
- Entry[] tab = getTable();
+ Entry<K,V>[] tab = getTable();
int index = indexFor( h, tab.length );
- Entry e = tab[index];
+ Entry<K,V> e = tab[index];
while ( e != null && !( e.hash == h && k == e.get() ) )
e = e.next;
return e;
@@ -353,15 +353,15 @@
* also indicate that the HashMap previously associated
* <tt>null</tt> with the specified key.
*/
- public Object put(Object key, Object value) {
- Object k = maskNull( key );
+ public V put(K key, V value) {
+ K k = maskNull( key );
int h = hash( k );
- Entry[] tab = getTable();
+ Entry<K,V>[] tab = getTable();
int i = indexFor( h, tab.length );
- for ( Entry e = tab[i]; e != null; e = e.next ) {
+ for ( Entry<K,V> e = tab[i]; e != null; e = e.next ) {
if ( h == e.hash && k == e.get() ) {
- Object oldValue = e.value;
+ V oldValue = e.value;
if ( value != oldValue )
e.value = value;
return oldValue;
@@ -369,7 +369,7 @@
}
modCount++;
- tab[i] = new Entry( k, value, queue, h, tab[i] );
+ tab[i] = new Entry<K,V>( k, value, queue, h, tab[i] );
if ( ++size >= threshold )
resize( tab.length * 2 );
return null;
@@ -388,14 +388,14 @@
void resize(int newCapacity) {
// assert (newCapacity & -newCapacity) == newCapacity; // power of 2
- Entry[] oldTable = getTable();
+ Entry<K,V>[] oldTable = getTable();
int oldCapacity = oldTable.length;
// check if needed
if ( size < threshold || oldCapacity > newCapacity )
return;
- Entry[] newTable = new Entry[newCapacity];
+ Entry<K,V>[] newTable = new Entry[newCapacity];
transfer( oldTable, newTable );
table = newTable;
@@ -418,13 +418,13 @@
/**
* Transfer all entries from src to dest tables
*/
- private void transfer(Entry[] src, Entry[] dest) {
+ private void transfer(Entry<K,V>[] src, Entry<K,V>[] dest) {
for ( int j = 0; j < src.length; ++j ) {
- Entry e = src[j];
+ Entry<K,V> e = src[j];
src[j] = null;
while ( e != null ) {
- Entry next = e.next;
- Object key = e.get();
+ Entry<K,V> next = e.next;
+ K key = e.get();
if ( key == null ) {
e.next = null; // Help GC
e.value = null; // " "
@@ -448,7 +448,7 @@
* @param t mappings to be stored in this map.
* @throws NullPointerException if the specified map is null.
*/
- public void putAll(Map t) {
+ public void putAll(Map<? extends K, ? extends V> t) {
// Expand enough to hold t's elements without resizing.
int n = t.size();
if ( n == 0 )
@@ -464,7 +464,7 @@
}
for ( Iterator i = t.entrySet().iterator(); i.hasNext(); ) {
- Map.Entry e = (Map.Entry) i.next();
+ Map.Entry<K,V> e = (Map.Entry<K,V>) i.next(); //FIXME should not have to cast
put( e.getKey(), e.getValue() );
}
}
@@ -478,16 +478,16 @@
* also indicate that the map previously associated <tt>null</tt>
* with the specified key.
*/
- public Object remove(Object key) {
+ public V remove(Object key) {
Object k = maskNull( key );
int h = hash( k );
- Entry[] tab = getTable();
+ Entry<K,V>[] tab = getTable();
int i = indexFor( h, tab.length );
- Entry prev = tab[i];
- Entry e = prev;
+ Entry<K,V> prev = tab[i];
+ Entry<K,V> e = prev;
while ( e != null ) {
- Entry next = e.next;
+ Entry<K,V> next = e.next;
if ( h == e.hash && k == e.get() ) {
modCount++;
size--;
@@ -632,32 +632,32 @@
* The entries in this hash table extend WeakReference, using its main ref
* field as the key.
*/
- private static class Entry extends WeakReference implements Map.Entry {
- private Object value;
+ private static class Entry<K,V> extends WeakReference<K> implements Map.Entry<K,V> {
+ private V value;
private final int hash;
- private Entry next;
+ private Entry<K,V> next;
/**
* Create new entry.
*/
- Entry(Object key, Object value, ReferenceQueue queue,
- int hash, Entry next) {
+ Entry(K key, V value, ReferenceQueue queue,
+ int hash, Entry<K,V> next) {
super( key, queue );
this.value = value;
this.hash = hash;
this.next = next;
}
- public Object getKey() {
- return unmaskNull( this.get() );
+ public K getKey() {
+ return WeakIdentityHashMap.unmaskNull( this.get() );
}
- public Object getValue() {
+ public V getValue() {
return value;
}
- public Object setValue(Object newValue) {
- Object oldValue = value;
+ public V setValue(V newValue) {
+ V oldValue = value;
value = newValue;
return oldValue;
}
@@ -693,10 +693,10 @@
}
}
- private abstract class HashIterator implements Iterator {
+ private abstract class HashIterator<E> implements Iterator<E> {
int index;
- Entry entry = null;
- Entry lastReturned = null;
+ Entry<K,V> entry = null;
+ Entry<K,V> lastReturned = null;
int expectedModCount = modCount;
/**
@@ -741,7 +741,7 @@
/**
* The common parts of next() across different types of iterators
*/
- protected Entry nextEntry() {
+ protected Entry<K,V> nextEntry() {
if ( modCount != expectedModCount )
throw new ConcurrentModificationException();
if ( nextKey == null && !hasNext() )
@@ -780,15 +780,15 @@
}
}
- private class EntryIterator extends HashIterator {
- public Object next() {
+ private class EntryIterator extends HashIterator<Map.Entry<K,V>> {
+ public Map.Entry<K,V> next() {
return nextEntry();
}
}
// Views
- private transient Set entrySet = null;
+ private transient Set<Map.Entry<K,V>> entrySet = null;
/**
* Returns a set view of the keys contained in this map. The set is
@@ -912,15 +912,15 @@
* @return a collection view of the mappings contained in this map.
* @see java.util.Map.Entry
*/
- public Set entrySet() {
- Set es = entrySet;
+ public Set<Map.Entry<K,V>> entrySet() {
+ Set<Map.Entry<K,V>> es = entrySet;
return ( es != null ?
es :
( entrySet = new EntrySet() ) );
}
- private class EntrySet extends AbstractSet {
- public Iterator iterator() {
+ private class EntrySet extends AbstractSet<Map.Entry<K,V>> {
+ public Iterator<Map.Entry<K,V>> iterator() {
return new EntryIterator();
}
17 years, 8 months
Hibernate SVN: r11022 - in branches/Branch_3_2/HibernateExt/metadata/src: java/org/hibernate/search/backend/impl java/org/hibernate/search/impl test/org/hibernate/search/test test/org/hibernate/search/test/worker
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-08 07:23:31 -0500 (Mon, 08 Jan 2007)
New Revision: 11022
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/AsyncWorkerTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/Employee.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/Employer.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/SyncWorkerTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/WorkerTestCase.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java
Log:
ANN-520 asynchronous worker queue
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/BatchedWorkQueue.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -6,7 +6,13 @@
import java.util.Map;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Properties;
import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ExecutorService;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.store.DirectoryProvider;
@@ -17,6 +23,8 @@
import org.hibernate.search.backend.UpdateWork;
import org.hibernate.search.backend.DeleteWork;
import org.hibernate.search.backend.AddWork;
+import org.hibernate.search.backend.Worker;
+import org.hibernate.search.Environment;
/**
* Batch work until #performWork is called.
@@ -27,14 +35,29 @@
public class BatchedWorkQueue implements WorkQueue {
private List<Work> queue = new ArrayList<Work>();
private boolean sync;
- Map<Class, DocumentBuilder<Object>> documentBuilders;
- Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
+ private Map<Class, DocumentBuilder<Object>> documentBuilders;
+ private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
+ private ExecutorService executorService;
+ private Properties properties;
public BatchedWorkQueue(Map<Class, DocumentBuilder<Object>> documentBuilders,
- Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders, boolean sync) {
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders,
+ Properties properties) {
this.documentBuilders = documentBuilders;
this.lockableDirectoryProviders = lockableDirectoryProviders;
- this.sync = sync;
+ this.properties = properties;
+ //default to sync if none defined
+ this.sync = ! "async".equalsIgnoreCase( properties.getProperty( Environment.WORKER_PREFIX + "type") );
+ int min = Integer.parseInt(
+ properties.getProperty( Environment.WORKER_PREFIX + "thread_pool.min", "0" )
+ );
+ int max = Integer.parseInt(
+ properties.getProperty( Environment.WORKER_PREFIX + "thread_pool.max", "0" ).trim()
+ );
+ if (max == 0) max = Integer.MAX_VALUE;
+ if ( ! sync) {
+ executorService = new ThreadPoolExecutor( min, max, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>() );
+ }
}
public void add(Work work) {
@@ -51,14 +74,12 @@
//TODO implements parallel batchWorkers (one per Directory)
public void performWork() {
- BatchWorker batchWorker = new BatchWorker( queue, documentBuilders, lockableDirectoryProviders );
+ BatchWorker batchWorker = new BatchWorker( queue, documentBuilders, lockableDirectoryProviders, properties );
if (sync) {
batchWorker.run();
}
else {
- //TODO pool threads?
- Thread thread = new Thread(batchWorker);
- thread.start();
+ executorService.execute( batchWorker );
}
}
@@ -73,7 +94,7 @@
public BatchWorker(List<Work> queue, Map<Class, DocumentBuilder<Object>> documentBuilders,
- Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders, Properties properties) {
this.queue = queue;
this.documentBuilders = documentBuilders;
this.lockableDirectoryProviders = lockableDirectoryProviders;
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -30,7 +30,7 @@
protected WeakIdentityHashMap queuePerTransaction = new WeakIdentityHashMap();
private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders;
private Map<Class, DocumentBuilder<Object>> documentBuilders;
- private boolean sync;
+ private Properties properties;
public void performWork(Work work, EventSource session) {
if ( session.isTransactionInProgress() ) {
@@ -38,7 +38,7 @@
PostTransactionWorkQueueSynchronization txSync = (PostTransactionWorkQueueSynchronization)
queuePerTransaction.get( transaction );
if ( txSync == null || txSync.isConsumed() ) {
- WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, sync );
+ WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, properties );
txSync = new PostTransactionWorkQueueSynchronization( workQueue, queuePerTransaction );
transaction.registerSynchronization( txSync );
queuePerTransaction.put(transaction, txSync);
@@ -46,7 +46,7 @@
txSync.add( work );
}
else {
- WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, sync );
+ WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, properties );
PostTransactionWorkQueueSynchronization sync = new PostTransactionWorkQueueSynchronization( workQueue );
sync.add( work );
sync.afterCompletion( Status.STATUS_COMMITTED );
@@ -57,7 +57,6 @@
Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
this.documentBuilders = documentBuilders;
this.lockableDirectoryProviders = lockableDirectoryProviders;
- //default to sync if none defined
- this.sync = ! "async".equalsIgnoreCase( props.getProperty( Environment.WORKER_PREFIX + "type") );
+ this.properties = props;
}
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -7,6 +7,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.locks.ReentrantLock;
import javax.transaction.Status;
@@ -113,7 +114,7 @@
Map<Class, DocumentBuilder<Object>> documentBuilders,
Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
//FIXME should be harmonized with the WorkerFactory?
- WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, true );
+ WorkQueue workQueue = new BatchedWorkQueue( documentBuilders, lockableDirectoryProviders, new Properties() );
return new PostTransactionWorkQueueSynchronization( workQueue );
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -158,7 +158,7 @@
assertEquals( "Hibernate in Action", hits.doc( 0 ).get( "title" ) );
}
finally {
- if ( searcher != null ) searcher.close();
+ searcher.close();
}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/AsyncWorkerTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/AsyncWorkerTest.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/AsyncWorkerTest.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -0,0 +1,38 @@
+//$Id: $
+package org.hibernate.search.test.worker;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutorService;
+
+import org.hibernate.search.test.TestCase;
+import org.hibernate.search.store.RAMDirectoryProvider;
+import org.hibernate.search.Environment;
+import org.hibernate.search.event.FullTextIndexEventListener;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.event.PostDeleteEventListener;
+import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.event.PostInsertEventListener;
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.apache.lucene.analysis.StopAnalyzer;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class AsyncWorkerTest extends WorkerTestCase {
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
+ cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+ cfg.setProperty( Environment.WORKER_IMPL, "transactional" );
+ cfg.setProperty( Environment.WORKER_PREFIX + "type", "async" );
+ cfg.setProperty( Environment.WORKER_PREFIX + "thread_pool.min", "1" );
+ cfg.setProperty( Environment.WORKER_PREFIX + "thread_pool.max", "10" );
+ FullTextIndexEventListener del = new FullTextIndexEventListener();
+ cfg.getEventListeners().setPostDeleteEventListeners( new PostDeleteEventListener[]{del} );
+ cfg.getEventListeners().setPostUpdateEventListeners( new PostUpdateEventListener[]{del} );
+ cfg.getEventListeners().setPostInsertEventListeners( new PostInsertEventListener[]{del} );
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/Employee.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/Employee.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/Employee.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -0,0 +1,43 @@
+//$Id: $
+package org.hibernate.search.test.worker;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Indexed(index="employee")
+public class Employee {
+ @Id
+ @GeneratedValue
+ @DocumentId
+ private long id;
+
+ @Field(index = Index.TOKENIZED )
+ private String name;
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/Employer.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/Employer.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/Employer.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -0,0 +1,43 @@
+//$Id: $
+package org.hibernate.search.test.worker;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.DocumentId;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Indexed(index="employer")
+public class Employer {
+ @Id
+ @GeneratedValue
+ @DocumentId
+ private long id;
+
+ @Field(index = Index.TOKENIZED )
+ private String name;
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/SyncWorkerTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/SyncWorkerTest.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/SyncWorkerTest.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -0,0 +1,28 @@
+//$Id: $
+package org.hibernate.search.test.worker;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.search.store.RAMDirectoryProvider;
+import org.hibernate.search.Environment;
+import org.hibernate.search.event.FullTextIndexEventListener;
+import org.hibernate.event.PostDeleteEventListener;
+import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.event.PostInsertEventListener;
+import org.apache.lucene.analysis.StopAnalyzer;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class SyncWorkerTest extends WorkerTestCase {
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
+ cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+ cfg.setProperty( Environment.WORKER_IMPL, "transactional" );
+ cfg.setProperty( Environment.WORKER_PREFIX + "type", "sync" );
+ FullTextIndexEventListener del = new FullTextIndexEventListener();
+ cfg.getEventListeners().setPostDeleteEventListeners( new PostDeleteEventListener[]{del} );
+ cfg.getEventListeners().setPostUpdateEventListeners( new PostUpdateEventListener[]{del} );
+ cfg.getEventListeners().setPostInsertEventListeners( new PostInsertEventListener[]{del} );
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/WorkerTestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/WorkerTestCase.java 2007-01-08 12:10:39 UTC (rev 11021)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/search/test/worker/WorkerTestCase.java 2007-01-08 12:23:31 UTC (rev 11022)
@@ -0,0 +1,124 @@
+//$Id: $
+package org.hibernate.search.test.worker;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.hibernate.search.test.TestCase;
+import org.hibernate.search.store.RAMDirectoryProvider;
+import org.hibernate.search.Environment;
+import org.hibernate.search.event.FullTextIndexEventListener;
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.event.PostDeleteEventListener;
+import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.event.PostInsertEventListener;
+import org.hibernate.cfg.Configuration;
+import org.apache.lucene.analysis.StopAnalyzer;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class WorkerTestCase extends TestCase {
+
+ public void testConcurrency() throws Exception {
+ ExecutorService es = Executors.newFixedThreadPool( 15 );
+ Work work = new Work( getSessions() );
+ ReverseWork reverseWork = new ReverseWork( getSessions() );
+ for (int i = 0 ; i < 200 ; i++) {
+ es.execute( work );
+ es.execute( reverseWork );
+ }
+ while(work.count < 199) {
+ Thread.sleep( 20 );
+ }
+ }
+
+ protected class Work implements Runnable {
+ private SessionFactory sf;
+ public volatile int count = 0;
+
+ public Work(SessionFactory sf) {
+ this.sf = sf;
+ }
+
+ public void run() {
+ Session s = sf.openSession( );
+ Transaction tx = s.beginTransaction();
+ Employee ee = new Employee();
+ ee.setName( "Emmanuel" );
+ s.persist( ee );
+ Employer er = new Employer();
+ er.setName( "RH" );
+ s.persist( er );
+ tx.commit();
+ s.close();
+
+ s = sf.openSession( );
+ tx = s.beginTransaction();
+ ee = (Employee) s.get( Employee.class, ee.getId() );
+ ee.setName( "Emmanuel2" );
+ er = (Employer) s.get( Employer.class, er.getId() );
+ er.setName( "RH2" );
+ tx.commit();
+ s.close();
+
+ s = sf.openSession( );
+ tx = s.beginTransaction();
+ ee = (Employee) s.get( Employee.class, ee.getId() );
+ s.delete( ee );
+ er = (Employer) s.get( Employer.class, er.getId() );
+ s.delete( er );
+ tx.commit();
+ s.close();
+ count++;
+ }
+ }
+
+ protected class ReverseWork implements Runnable {
+ private SessionFactory sf;
+
+ public ReverseWork(SessionFactory sf) {
+ this.sf = sf;
+ }
+
+ public void run() {
+ Session s = sf.openSession( );
+ Transaction tx = s.beginTransaction();
+ Employer er = new Employer();
+ er.setName( "RH" );
+ s.persist( er );
+ Employee ee = new Employee();
+ ee.setName( "Emmanuel" );
+ s.persist( ee );
+ tx.commit();
+ s.close();
+
+ s = sf.openSession( );
+ tx = s.beginTransaction();
+ er = (Employer) s.get( Employer.class, er.getId() );
+ er.setName( "RH2" );
+ ee = (Employee) s.get( Employee.class, ee.getId() );
+ ee.setName( "Emmanuel2" );
+ tx.commit();
+ s.close();
+
+ s = sf.openSession( );
+ tx = s.beginTransaction();
+ er = (Employer) s.get( Employer.class, er.getId() );
+ s.delete( er );
+ ee = (Employee) s.get( Employee.class, ee.getId() );
+ s.delete( ee );
+ tx.commit();
+ s.close();
+ }
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Employee.class,
+ Employer.class
+ };
+ }
+}
17 years, 8 months
Hibernate SVN: r11021 - branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-01-08 07:10:39 -0500 (Mon, 08 Jan 2007)
New Revision: 11021
Added:
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competition.java
Modified:
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competitor.java
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java
Log:
more tests (related to HHH-2292
Added: branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competition.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competition.java 2007-01-08 12:00:02 UTC (rev 11020)
+++ branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competition.java 2007-01-08 12:10:39 UTC (rev 11021)
@@ -0,0 +1,47 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.ManyToMany;
+import javax.persistence.CascadeType;
+import javax.persistence.FetchType;
+import javax.persistence.JoinTable;
+import javax.persistence.JoinColumn;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Competition {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE },
+ fetch = FetchType.LAZY)
+ @JoinTable(name="competition_competitor")
+ @JoinColumn
+ private List<Competitor> competitors = new ArrayList<Competitor>();
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public List<Competitor> getCompetitors() {
+ return competitors;
+ }
+
+ public void setCompetitors(List<Competitor> competitors) {
+ this.competitors = competitors;
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competitor.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competitor.java 2007-01-08 12:00:02 UTC (rev 11020)
+++ branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competitor.java 2007-01-08 12:10:39 UTC (rev 11021)
@@ -11,7 +11,16 @@
@Entity
public class Competitor {
@Id @GeneratedValue public Integer id;
+ private String name;
+
+ public Competitor() {
+ }
+
+ public Competitor(String name) {
+ this.name = name;
+ }
+
public Integer getId() {
return id;
}
@@ -19,4 +28,12 @@
public void setId(Integer id) {
this.id = id;
}
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
}
Modified: branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2007-01-08 12:00:02 UTC (rev 11020)
+++ branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2007-01-08 12:10:39 UTC (rev 11021)
@@ -1,6 +1,8 @@
//$Id: $
package org.hibernate.ejb.test.emops;
+import java.util.List;
+import java.util.ArrayList;
import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase;
@@ -11,9 +13,9 @@
public class MergeTest extends TestCase {
public void testMergeWithIndexColumn() {
Race race = new Race();
+ race.competitors.add( new Competitor("Name") );
race.competitors.add( new Competitor() );
race.competitors.add( new Competitor() );
- race.competitors.add( new Competitor() );
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
em.persist( race );
@@ -21,15 +23,67 @@
em.clear();
race.competitors.add( new Competitor() );
race.competitors.remove( 2 );
+ race.competitors.remove( 1 );
+ race.competitors.get( 0 ).setName( "Name2" );
race = em.merge( race );
em.flush();
em.clear();
race = em.find( Race.class, race.id );
- assertEquals( 3, race.competitors.size() );
+ assertEquals( 2, race.competitors.size() );
+ assertEquals( "Name2", race.competitors.get(0).getName() );
em.getTransaction().rollback();
em.close();
}
+ public void testMergeManyToMany() {
+ Competition competition = new Competition();
+ competition.getCompetitors().add( new Competitor("Name") );
+ competition.getCompetitors().add( new Competitor() );
+ competition.getCompetitors().add( new Competitor() );
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( competition );
+ em.flush();
+ em.clear();
+ competition.getCompetitors().add( new Competitor() );
+ competition.getCompetitors().remove( 2 );
+ competition.getCompetitors().remove( 1 );
+ competition.getCompetitors().get(0).setName( "Name2" );
+ competition = em.merge( competition );
+ em.flush();
+ em.clear();
+ competition = em.find( Competition.class, competition.getId() );
+ assertEquals( 2, competition.getCompetitors().size() );
+ assertEquals( "Name2", competition.getCompetitors().get(0).getName() );
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ public void testMergeManyToManyWithDeference() {
+ Competition competition = new Competition();
+ competition.getCompetitors().add( new Competitor("Name") );
+ competition.getCompetitors().add( new Competitor() );
+ competition.getCompetitors().add( new Competitor() );
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( competition );
+ em.flush();
+ em.clear();
+ List<Competitor> newComp = new ArrayList<Competitor>();
+ newComp.add( competition.getCompetitors().get(0) );
+ newComp.add( new Competitor() );
+ newComp.get(0).setName( "Name2" );
+ competition.setCompetitors( newComp );
+ competition = em.merge( competition );
+ em.flush();
+ em.clear();
+ competition = em.find( Competition.class, competition.getId() );
+ assertEquals( 2, competition.getCompetitors().size() );
+ assertEquals( "Name2", competition.getCompetitors().get(0).getName() );
+ em.getTransaction().rollback();
+ em.close();
+ }
+
public void testRemoveAndMerge() {
Race race = new Race();
EntityManager em = factory.createEntityManager();
@@ -89,7 +143,8 @@
public Class[] getAnnotatedClasses() {
return new Class[] {
Race.class,
- Competitor.class
+ Competitor.class,
+ Competition.class
};
}
}
17 years, 8 months