Author: epbernard
Date: 2007-02-23 17:49:14 -0500 (Fri, 23 Feb 2007)
New Revision: 11235
Modified:
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/jms/JMSHibernateSearchController.java
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/util/ContextHelper.java
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/session/Email.java
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/session/MassIndexTest.java
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/worker/WorkerTestCase.java
Log:
More tests on session.index
Modified:
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java
===================================================================
---
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java 2007-02-23
21:47:34 UTC (rev 11234)
+++
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java 2007-02-23
22:49:14 UTC (rev 11235)
@@ -14,6 +14,7 @@
import org.hibernate.HibernateException;
import org.hibernate.search.Environment;
import org.hibernate.search.SearchFactory;
+import org.hibernate.search.SearchException;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.Work;
@@ -27,11 +28,14 @@
private Properties properties;
private Queue jmsQueue;
private QueueConnectionFactory factory;
+ public static final String JMS_CONNECTION_FACTORY = Environment.WORKER_PREFIX +
"jms.connection_factory";
+ public static final String JMS_QUEUE = Environment.WORKER_PREFIX +
"jms.queue";
public void initialize(Properties props, SearchFactory searchFactory) {
+ //TODO proper exception if jms queues and connecitons are not there
this.properties = props;
- this.jmsConnectionFactoryName = props.getProperty( Environment.WORKER_PREFIX +
"jms.connection_factory" );
- this.jmsQueueName = props.getProperty( Environment.WORKER_PREFIX +
"jms.queue" );
+ this.jmsConnectionFactoryName = props.getProperty( JMS_CONNECTION_FACTORY );
+ this.jmsQueueName = props.getProperty( JMS_QUEUE );
prepareJMSTools();
}
@@ -57,11 +61,12 @@
if (jmsQueue != null && factory != null) return;
try {
InitialContext initialContext = getInitialContext(properties);
+ factory = (QueueConnectionFactory) initialContext.lookup( jmsConnectionFactoryName );
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);
+ throw new SearchException("Unable to lookup Search queue and connection
factory", e);
}
}
Modified:
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/jms/JMSHibernateSearchController.java
===================================================================
---
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/jms/JMSHibernateSearchController.java 2007-02-23
21:47:34 UTC (rev 11234)
+++
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/jms/JMSHibernateSearchController.java 2007-02-23
22:49:14 UTC (rev 11235)
@@ -49,7 +49,7 @@
private Runnable getWorker(List<Work> queue) {
//FIXME casting sucks becasue we do not control what get session from
- SearchFactory factory = ContextHelper.getSearchFactory( (SessionImplementor)
getSession() );
+ SearchFactory factory = ContextHelper.getSearchFactoryBySFI( (SessionImplementor)
getSession() );
return factory.getBackendQueueProcessorFactory().getProcessor( queue );
}
Modified:
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
---
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-02-23
21:47:34 UTC (rev 11234)
+++
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-02-23
22:49:14 UTC (rev 11235)
@@ -27,6 +27,7 @@
import org.hibernate.Interceptor;
import org.hibernate.ScrollableResults;
import org.hibernate.ScrollMode;
+import org.hibernate.Hibernate;
import org.hibernate.event.EventListeners;
import org.hibernate.loader.custom.CustomQuery;
import org.hibernate.persister.entity.EntityPersister;
@@ -88,7 +89,7 @@
*/
public void index(Object entity) {
if (entity == null) return;
- Class clazz = entity.getClass();
+ Class clazz = Hibernate.getClass( entity );
SearchFactory searchFactory = ContextHelper.getSearchFactory( session );
DocumentBuilder<Object> builder = searchFactory.getDocumentBuilders().get( clazz
);
if ( builder != null ) {
Modified:
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
---
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-02-23
21:47:34 UTC (rev 11234)
+++
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-02-23
22:49:14 UTC (rev 11235)
@@ -72,7 +72,7 @@
//user stop using it
//scrollable is better in this area
- SearchFactory searchFactory = ContextHelper.getSearchFactory( session );
+ SearchFactory searchFactory = ContextHelper.getSearchFactoryBySFI( session );
//find the directories
Searcher searcher = buildSearcher( searchFactory );
try {
@@ -106,7 +106,7 @@
public ScrollableResults scroll() throws HibernateException {
//keep the searcher open until the resultset is closed
- SearchFactory searchFactory = ContextHelper.getSearchFactory( session );;
+ SearchFactory searchFactory = ContextHelper.getSearchFactoryBySFI( session );;
//find the directories
Searcher searcher = buildSearcher( searchFactory );
Hits hits;
@@ -135,7 +135,7 @@
}
public List list() throws HibernateException {
- SearchFactory searchFactory = ContextHelper.getSearchFactory( session );;
+ SearchFactory searchFactory = ContextHelper.getSearchFactoryBySFI( session );;
//find the directories
Searcher searcher = buildSearcher( searchFactory );
Hits hits;
Modified:
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/util/ContextHelper.java
===================================================================
---
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/util/ContextHelper.java 2007-02-23
21:47:34 UTC (rev 11234)
+++
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/util/ContextHelper.java 2007-02-23
22:49:14 UTC (rev 11235)
@@ -2,6 +2,7 @@
package org.hibernate.search.util;
import org.hibernate.HibernateException;
+import org.hibernate.Session;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.search.event.FullTextIndexEventListener;
@@ -12,7 +13,12 @@
*/
public abstract class ContextHelper {
- public static SearchFactory getSearchFactory(SessionImplementor session) {
+ public static SearchFactory getSearchFactory(Session session) {
+ return getSearchFactoryBySFI( (SessionImplementor) session );
+ }
+
+
+ public static SearchFactory getSearchFactoryBySFI(SessionImplementor session) {
PostInsertEventListener[] listeners =
session.getListeners().getPostInsertEventListeners();
FullTextIndexEventListener listener = null;
//FIXME this sucks since we mandante the event listener use
Modified:
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/session/Email.java
===================================================================
---
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/session/Email.java 2007-02-23
21:47:34 UTC (rev 11234)
+++
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/session/Email.java 2007-02-23
22:49:14 UTC (rev 11235)
@@ -17,7 +17,6 @@
@Indexed
public class Email {
@Id
- @GeneratedValue
@DocumentId
private Long id;
Modified:
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/session/MassIndexTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/session/MassIndexTest.java 2007-02-23
21:47:34 UTC (rev 11234)
+++
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/session/MassIndexTest.java 2007-02-23
22:49:14 UTC (rev 11235)
@@ -2,14 +2,21 @@
package org.hibernate.search.test.session;
import java.util.List;
+import java.sql.ResultSet;
import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.impl.FullTextSessionImpl;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
+import org.hibernate.search.util.ContextHelper;
import org.hibernate.Transaction;
+import org.hibernate.Session;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Hits;
/**
* @author Emmanuel Bernard
@@ -22,6 +29,7 @@
int loop = 4;
for (int i = 0 ; i < loop; i++) {
Email email = new Email();
+ email.setId( (long)i+1 );
email.setTitle( "JBoss World Berlin" );
email.setBody( "Meet the guys who wrote the software");
s.persist( email );
@@ -32,6 +40,9 @@
s = new FullTextSessionImpl( openSession() );
s.getTransaction().begin();
s.connection().createStatement().executeUpdate( "update Email set body='Meet
the guys who write the software'");
+ //insert an object never indexed
+ s.connection().createStatement().executeUpdate( "insert into Email(id, title,
body, header) values( + "
+ + (loop+1) + ", 'Bob Sponge', 'Meet the guys who create the
software', 'nope')");
s.getTransaction().commit();
s.close();
@@ -51,13 +62,22 @@
tx.commit(); //do the process
s.close();
+ s = Search.createFullTextSession( openSession() );
+ tx = s.beginTransaction();
+ //object never indexed
+ Email email = (Email) s.get(Email.class, new Long(loop + 1) );
+ s.index( email );
+ tx.commit();
+ s.close();
+
+ //check
s = new FullTextSessionImpl( openSession() );
tx = s.beginTransaction();
- result = s.createFullTextQuery( parser.parse( "body:write" ) ).list();
- assertEquals( loop, result.size() );
- for (Object o : result) s.delete( o );
+ result = s.createFullTextQuery( parser.parse( "body:create" ) ).list();
+ assertEquals( 1, result.size() );
tx.commit();
s.close();
+
}
protected Class[] getMappings() {
Modified:
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/worker/WorkerTestCase.java
===================================================================
---
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/worker/WorkerTestCase.java 2007-02-23
21:47:34 UTC (rev 11234)
+++
branches/Branch_3_2/HibernateExt/search/src/test/org/hibernate/search/test/worker/WorkerTestCase.java 2007-02-23
22:49:14 UTC (rev 11235)
@@ -130,6 +130,7 @@
throw new RuntimeException( e );
}
boolean results = fts.createFullTextQuery( query ).list().size() > 0;
+ //don't test because in case of async, it query happens before actual saving
//if ( !results ) throw new RuntimeException( "No results!" );
tx.commit();
s.close();