Author: epbernard
Date: 2010-07-30 06:09:16 -0400 (Fri, 30 Jul 2010)
New Revision: 20085
Modified:
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
Log:
HSEARCH-562 Add JTA test with JBoss TS: Make use of Hibernate Search in test
indexing + search
Modified:
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 2010-07-30
10:08:42 UTC (rev 20084)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/JBossTSTest.java 2010-07-30
10:09:16 UTC (rev 20085)
@@ -7,25 +7,30 @@
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.arjuna.coordinator.TxControl;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
import com.arjuna.ats.jdbc.TransactionalDriver;
+import org.apache.lucene.search.Query;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.hibernate.ConnectionReleaseMode;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.ejb.HibernatePersistence;
+import org.hibernate.search.jpa.FullTextEntityManager;
+import org.hibernate.search.jpa.Search;
+import org.hibernate.search.query.dsl.v2.QueryBuilder;
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;
+import org.hibernate.search.util.FileHelper;
/**
* @author Emmanuel Bernard
@@ -68,6 +73,7 @@
.addProperty( "hibernate.dialect", H2Dialect.class.getName() )
.addProperty( Environment.HBM2DDL_AUTO, "create-drop" )
.addProperty( Environment.SHOW_SQL, "true" )
+ .addProperty( "hibernate.search.default.directory_provider",
"org.hibernate.search.store.RAMDirectoryProvider" )
.create();
final HibernatePersistence hp = new HibernatePersistence();
factory = hp.createContainerEntityManagerFactory( unitInfo, new HashMap( ) );
@@ -86,12 +92,20 @@
EntityManager em = factory.createEntityManager();
Tweet tweet = new Tweet( "Spice is the essence of life" );
em.persist( tweet );
- em.flush();
tm.commit();
em.close();
tm.begin();
em = factory.createEntityManager();
+ FullTextEntityManager ftem = Search.getFullTextEntityManager( em );
+ final QueryBuilder builder = ftem.getSearchFactory().buildQueryBuilder().forEntity(
Tweet.class ).get();
+ final Query query = builder
+ .keyword()
+ .onField( "text" )
+ .matching( "spice" )
+ .createQuery();
+
+ ftem.createFullTextQuery( query, Tweet.class ).getResultList();
final List resultList = em.createQuery( "from " + Tweet.class.getName()
).getResultList();
Assert.assertEquals( 1, resultList.size() );
for (Object o : resultList) {
Modified:
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 2010-07-30
10:08:42 UTC (rev 20084)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jbossjta/Tweet.java 2010-07-30
10:09:16 UTC (rev 20085)
@@ -7,11 +7,14 @@
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Indexed;
/**
* @author Emmanuel Bernard
*/
@Entity
+@Indexed
public class Tweet {
public Tweet() {};
@@ -27,6 +30,7 @@
private String id;
@Column(name="tweet_text")
+ @Field
public String getText() { return text; };
public void setText(String text) { this.text = text; }
private String text;
Show replies by date