Author: epbernard
Date: 2010-07-30 06:08:05 -0400 (Fri, 30 Jul 2010)
New Revision: 20083
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/Tweet.java
Modified:
search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml
Log:
HSEARCH-562 Add JTA test with JBoss TS: Add unit test
Use a friendly id generator not involving several connections to the database
Make constructor public for entity
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java 2010-07-30
10:08:05 UTC (rev 20083)
@@ -0,0 +1,102 @@
+package org.hibernate.search.test.integration.jbossjta;
+
+import java.util.HashMap;
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.SharedCacheMode;
+import javax.persistence.ValidationMode;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
+import com.arjuna.ats.jdbc.TransactionalDriver;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.H2Dialect;
+import org.hibernate.ejb.HibernatePersistence;
+import org.hibernate.search.test.integration.jbossjta.infra.H2dataSourceProvider;
+import
org.hibernate.search.test.integration.jbossjta.infra.JBossTSStandaloneTransactionManagerLookup;
+import org.hibernate.search.test.integration.jbossjta.infra.PersistenceUnitInfoBuilder;
+import org.hibernate.search.test.integration.jbossjta.infra.ReadOnlyPersistenceUnitInfo;
+import org.hibernate.search.test.integration.jbossjta.infra.XADataSourceWrapper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+
+public class JBossTSTest {
+
+ private static EntityManagerFactory factory;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+
+ H2dataSourceProvider dsProvider = new H2dataSourceProvider();
+ final XADataSource h2DataSource = dsProvider.getDataSource(
dsProvider.getDataSourceName() );
+ XADataSourceWrapper dsw = new XADataSourceWrapper(
+ dsProvider.getDataSourceName(),
+ h2DataSource
+ );
+ dsw.setProperty( TransactionalDriver.dynamicClass, H2dataSourceProvider.class.getName()
);
+ dsw.setProperty( TransactionalDriver.userName, "sa" );
+ dsw.setProperty( TransactionalDriver.password, "" );
+
+ PersistenceUnitInfoBuilder pub = new PersistenceUnitInfoBuilder();
+ final ReadOnlyPersistenceUnitInfo unitInfo = pub
+ .setExcludeUnlistedClasses( true )
+ .setJtaDataSource( dsw )
+ //.setJtaDataSource( ( DataSource) h2DataSource )
+ .setPersistenceProviderClassName( HibernatePersistence.class.getName() )
+ .setPersistenceUnitName( "jbossjta" )
+ .setPersistenceXMLSchemaVersion( "2.0" )
+ .setSharedCacheMode( SharedCacheMode.NONE )
+ .setValidationMode( ValidationMode.NONE )
+ .setTransactionType( PersistenceUnitTransactionType.JTA )
+ .addManagedClassNames( Tweet.class.getName() )
+ //.addProperty( "hibernate.transaction.factory_class", null )
+ .addProperty(
+ "hibernate.transaction.manager_lookup_class",
+ JBossTSStandaloneTransactionManagerLookup.class.getName()
+ )
+ .addProperty( "hibernate.dialect", H2Dialect.class.getName() )
+ .addProperty( Environment.HBM2DDL_AUTO, "create-drop" )
+ .create();
+ final HibernatePersistence hp = new HibernatePersistence();
+ factory = hp.createContainerEntityManagerFactory( unitInfo, new HashMap( ) );
+
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ factory.close();
+ }
+
+ @Test
+ public void testJBossTS() throws Exception {
+ TransactionManagerImple transaction = new TransactionManagerImple();
+ transaction.begin();;
+ EntityManager em = factory.createEntityManager();
+ em.persist( new Tweet("Spice is the essence of life") );
+ em.flush();
+ transaction.commit();
+ em.close();
+
+
+ transaction.begin();
+ em = factory.createEntityManager();
+ final List resultList = em.createQuery( "from " + Tweet.class.getName()
).getResultList();
+ Assert.assertEquals( 1, resultList.size() );
+ for (Object o : resultList) {
+ em.remove( o );
+ }
+ transaction.commit();
+
+ em.close();
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/Tweet.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/Tweet.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/Tweet.java 2010-07-30
10:08:05 UTC (rev 20083)
@@ -0,0 +1,33 @@
+package org.hibernate.search.test.integration.jbossjta;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.GenericGenerator;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Tweet {
+ public Tweet() {};
+
+ public Tweet(String tweet) {
+ this.text = tweet;
+ }
+
+ @Id
+ @GeneratedValue(generator = "uuid")
+ @GenericGenerator( name = "uuid", strategy = "uuid")
+ public String getId() { return id; }
+ public void setId(String id) { this.id = id; }
+ private String id;
+
+ @Column(name="tweet_text")
+ public String getText() { return text; };
+ public void setText(String text) { this.text = text; }
+ private String text;
+}
Modified:
search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml 2010-07-30
10:07:26 UTC (rev 20082)
+++
search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml 2010-07-30
10:08:05 UTC (rev 20083)
@@ -7,4 +7,11 @@
<class>org.hibernate.search.test.integration.jtaspring.Doughnut</class>
<class>org.hibernate.search.test.integration.jtaspring.Muffin</class>
</persistence-unit>
+
+ <persistence-unit name="jbossjta" transaction-type="JTA">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <properties>
+ <property name="" value=""/>
+ </properties>
+ </persistence-unit>
</persistence>
Show replies by date