Author: navssurtani
Date: 2008-07-03 10:05:31 -0400 (Thu, 03 Jul 2008)
New Revision: 6160
Added:
searchable/trunk/TODO.txt
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidKeyException.java
searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCoreListener.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
searchable/trunk/src/test/java/org/jboss/cache/search/helper/
searchable/trunk/src/test/java/org/jboss/cache/search/helper/IndexCleanUp.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java
searchable/trunk/src/test/resources/log4j.xml
Log:
Tried writing up POJO listener. Needs to be able to take out Fqn and Key from an Object
when event.getSource() is called.
Added: searchable/trunk/TODO.txt
===================================================================
--- searchable/trunk/TODO.txt (rev 0)
+++ searchable/trunk/TODO.txt 2008-07-03 14:05:31 UTC (rev 6160)
@@ -0,0 +1,13 @@
+1 - Fix POJO cache listener.
+
+The class needs to be able to get the Fqn and Key from the object so that Lucene can be
updated.
+
+2 - Lazy iterator.
+
+So that when a large amount of hits are there, they can be loaded when required.
+
+3 - Deal with Lucene Filters and Sorting.
+
+4 - Non-string keys.
+
+Think.
\ No newline at end of file
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2008-07-03
13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -74,7 +74,7 @@
*/
- public String getDocumentId()
+ public String getDocumentId() throws InvalidKeyException
{
if (key == null || fqn == null)
{
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2008-07-03
13:20:58 UTC (rev 6159)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -1,6 +1,8 @@
package org.jboss.cache.search;
import org.jboss.cache.Cache;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.List;
import java.util.ArrayList;
@@ -12,7 +14,8 @@
*/
public class CacheEntityLoader
{
- Cache cache;
+ Cache cache;
+ private static final Log log = LogFactory.getLog(CacheEntityLoader.class);
public CacheEntityLoader(Cache cache)
{
@@ -32,6 +35,7 @@
for (CacheEntityId id: ids)
{
retVal.add( cache.get(id.getFqn(), id.getKey()) );
+ if(log.isTraceEnabled()) log.trace("Created list of return values. Size is
" + retVal.size() );
}
return retVal;
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-07-03
13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -35,7 +35,8 @@
/**
* Implementation class of the CacheQuery interface.
- * <p />
+ * <p/>
+ *
* @author Navin Surtani - navin(a)surtani.org
*/
public class CacheQueryImpl implements CacheQuery
@@ -123,8 +124,6 @@
}
-
-
private void closeSearcher(Searcher searcher, ReaderProvider readerProvider)
{
Set<IndexReader> indexReaders = getIndexReaders(searcher);
@@ -188,7 +187,7 @@
//TODO How do we deal with this if the parameter is too high.
}
-
+
public QueryResultIterator iterator() throws HibernateException
{
List<CacheEntityId> ids = null;
@@ -248,10 +247,12 @@
try
{
hits = getHits(searcher);
+ if(log.isTraceEnabled()) log.trace("Number of hits are " +
hits.length());
int first = first();
int max = max(first, hits);
int size = max - first + 1 < 0 ? 0 : max - first + 1;
+
List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
DocumentExtractor extractor = new DocumentExtractor(searchFactory,
indexProjection);
@@ -291,17 +292,17 @@
private int max(int first, Hits hits)
{
return maxResults == null ?
- hits.length() - 1 :
- maxResults + first < hits.length() ?
- first + maxResults - 1 :
- hits.length() - 1;
+ hits.length() - 1 :
+ maxResults + first < hits.length() ?
+ first + maxResults - 1 :
+ hits.length() - 1;
}
private int first()
{
return firstResult != null ?
- firstResult :
- 0;
+ firstResult :
+ 0;
}
public void setMaxResults(int maxResults)
@@ -354,7 +355,9 @@
{
DocumentBuilder builder = builders.get(clazz);
if (builder == null)
+ {
throw new HibernateException("Not a mapped entity (don't forget
to add @Indexed): " + clazz);
+ }
final DirectoryProvider[] directoryProviders =
builder.getDirectoryProviderSelectionStrategy().getDirectoryProvidersForAllShards();
searcherSimilarity = checkSimilarity(searcherSimilarity, builder);
@@ -516,25 +519,25 @@
catch (IllegalAccessException e)
{
throw new SearchException("Unable to access @Key method:
"
- + def.getImpl().getName() + "." +
def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." +
def.getKeyMethod().getName());
}
catch (InvocationTargetException e)
{
throw new SearchException("Unable to access @Key method:
"
- + def.getImpl().getName() + "." +
def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." +
def.getKeyMethod().getName());
}
catch (ClassCastException e)
{
throw new SearchException("@Key method does not return
FilterKey: "
- + def.getImpl().getName() + "." +
def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." +
def.getKeyMethod().getName());
}
}
key.setImpl(def.getImpl());
}
Filter filter = def.isCache() ?
- searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
- null;
+ searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
+ null;
if (filter == null)
{
if (def.getFactoryMethod() != null)
@@ -546,17 +549,17 @@
catch (IllegalAccessException e)
{
throw new SearchException("Unable to access @Factory method:
"
- + def.getImpl().getName() + "." +
def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." +
def.getFactoryMethod().getName());
}
catch (InvocationTargetException e)
{
throw new SearchException("Unable to access @Factory method:
"
- + def.getImpl().getName() + "." +
def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." +
def.getFactoryMethod().getName());
}
catch (ClassCastException e)
{
throw new SearchException("@Key method does not return a
org.apache.lucene.search.Filter class: "
- + def.getImpl().getName() + "." +
def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." +
def.getFactoryMethod().getName());
}
}
else
@@ -568,11 +571,13 @@
catch (ClassCastException e)
{
throw new SearchException("@Key method does not return a
org.apache.lucene.search.Filter class: "
- + def.getImpl().getName() + "." +
def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." +
def.getFactoryMethod().getName());
}
}
if (def.isCache())
+ {
searchFactory.getFilterCachingStrategy().addCachedFilter(key, filter);
+ }
}
chainedFilter.addFilter(filter);
}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/InvalidKeyException.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/InvalidKeyException.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidKeyException.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -0,0 +1,28 @@
+package org.jboss.cache.search;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class InvalidKeyException extends Exception
+{
+
+ public InvalidKeyException()
+ {
+ }
+
+ public InvalidKeyException(String s)
+ {
+ super(s);
+ }
+
+ public InvalidKeyException(String s, Throwable throwable)
+ {
+ super(s, throwable);
+ }
+
+ public InvalidKeyException(Throwable throwable)
+ {
+ super(throwable);
+ }
+
+}
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-07-03
13:20:58 UTC (rev 6159)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -63,10 +63,11 @@
*/
public void registerSynchronization(Synchronization synchronization)
{
+ if (synchronization == null) throw new NullPointerException("Synchronization
passed in is null!");
+
Transaction transaction = event.getTransaction();
if (transaction != null)
{
- if (synchronization == null) throw new
NullPointerException("Synchronization passed in is null!");
try
{
transaction.registerSynchronization(synchronization);
Added: searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -0,0 +1,50 @@
+//package org.jboss.cache.search;
+//
+//import org.hibernate.search.transaction.TransactionContext;
+//import org.jboss.cache.pojo.notification.event.Event;
+//
+//import javax.transaction.Synchronization;
+//import javax.transaction.Transaction;
+//
+///**
+// * @author Navin Surtani - navin(a)surtani.org
+// */
+//public class PojoTransactionContext implements TransactionContext
+//{
+// Event event;
+//
+// public PojoTransactionContext(Event event)
+// {
+// if (event == null) throw new NullPointerException("event cannot be
null");
+// this.event = event;
+//
+// }
+// public boolean isTxInProgress()
+// {
+// return (event.getContext().getTransaction() != null);
+//
+// }
+//
+// public Object getTransactionIdentifier()
+// {
+// return event.getContext().getTransaction();
+// }
+//
+// public void registerSynchronization(Synchronization synchronization)
+// {
+// Transaction transaction = event.getContext().getTransaction();
+//
+// if (transaction != null)
+// {
+//
+// try
+// {
+// transaction.registerSynchronization(synchronization);
+// }
+// catch (Exception e)
+// {
+// throw new RuntimeException(e);
+// }
+// }
+// }
+//}
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-07-03
13:20:58 UTC (rev 6159)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -1,10 +1,10 @@
package org.jboss.cache.search;
-import org.hibernate.cfg.Configuration;
import org.hibernate.search.impl.SearchFactoryImpl;
import org.hibernate.search.cfg.Cfg;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheStatus;
+import org.jboss.cache.pojo.PojoCache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -51,20 +51,20 @@
if (log.isWarnEnabled()) log.warn("You haven't passed in any classes to
index. Is this an error?");
}
- // step 1: create hibernate search searchImpl
+ // step 1: create hibernate search searchFactory
Cfg cfg = new SearchableCacheCfgImpl(classes, properties);
// set classes in the cfg
- SearchFactoryImpl searchImpl = new SearchFactoryImpl(cfg);
+ SearchFactoryImpl searchFactory = new SearchFactoryImpl(cfg);
+ boolean isPojoCache = c instanceof PojoCache;
-
// Step 2: Add cache listener to listen for events happening in the cache.
- SearchableListener listener = new SearchableListener(searchImpl);
+ SearchableListener listener = isPojoCache ? new
SearchablePojoListener(searchFactory) : new SearchableCoreListener(searchFactory);
c.addCacheListener(listener);
// step 3: create the searchable cache delegate.
- SearchableCache sc = new SearchableCacheImpl(c, searchImpl);
+ SearchableCache sc = new SearchableCacheImpl(c, searchFactory);
return sc;
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-07-03
13:20:58 UTC (rev 6159)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -27,11 +27,9 @@
// this is the ACTUAL cache. that does all the work.
private Cache<K, V> cache;
- //TODO: Will this barf because of searchFactory being null or does it not matter to
us?
private SearchFactoryImpl searchFactory;
- //TODO: javadoc!!
public SearchableCacheImpl(Cache<K, V> cache, SearchFactoryImpl searchFactory)
{
if (cache == null) throw new NullPointerException("Blah");
@@ -43,7 +41,7 @@
/**
* Creates a CacheQuery object from a given Lucene Query.
*
- * @param luceneQuery
+ * @param luceneQuery - for lucene
* @return CacheQuery object
*/
@@ -55,8 +53,8 @@
/**
* Creates a CacheQuery object from a Lucene Query and a class array.
*
- * @param luceneQuery
- * @param classes
+ * @param luceneQuery - for lucene
+ * @param classes array
* @return CacheQuery object.
*/
Added: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCoreListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCoreListener.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCoreListener.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -0,0 +1,134 @@
+package org.jboss.cache.search;
+
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.transaction.TransactionContext;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkType;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ *
+ * Listener class for changes made to the cache. This listener makes changes if it is a
org.jboss.cache being used.
+ */
+@CacheListener
+public class SearchableCoreListener extends SearchableListener
+{
+ private SearchFactoryImpl searchFactory;
+ private static final Log log = LogFactory.getLog(SearchableCoreListener.class);
+
+ public SearchableCoreListener(SearchFactoryImpl searchFactory)
+ {
+
+ this.searchFactory = searchFactory;
+ }
+
+ /**
+ * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the
NodeModifiedEvent class.
+ *
+ * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
+ * @throws InvalidKeyException if an invalid key is passed in.
+ */
+
+ @NodeModified
+ public void updateLuceneIndexes(NodeModifiedEvent event) throws InvalidKeyException
+ {
+
+ if (log.isTraceEnabled()) log.trace("You have entered the
SearchableListener");
+ if (!event.isPre())
+ {
+ if (log.isTraceEnabled()) log.trace("event.isPre is false. Going to start
updating indexes");
+ switch (event.getModificationType())
+ {
+ case PUT_MAP:
+ case PUT_DATA:
+ if (log.isTraceEnabled()) log.trace("put() has been called on cache.
Going to handle the data.");
+ handlePutData(event, searchFactory);
+ break;
+ case REMOVE_DATA:
+ handleDeleteData(event, searchFactory);
+ break;
+ }
+ }
+ }
+
+ /**
+ * If the modification type is PUT_MAP or PUT_DATA then this method will be called.
+ * Takes in the event as a parameter
+ *
+ * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
+ * @param searchFactory - a SearchFactoryImpl instance.
+ * @throws InvalidKeyException
+ */
+
+
+ protected void handlePutData(NodeModifiedEvent event, SearchFactoryImpl searchFactory)
throws InvalidKeyException
+ {
+ Map dataMap = event.getData();
+ if (log.isTraceEnabled()) log.trace("Called event.getData() and saved to a
Map");
+
+
+ TransactionContext ctx = new NodeModifiedTransactionContext(event);
+
+ for (Object key : dataMap.keySet())
+ {
+ CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
+ if (log.isTraceEnabled()) log.trace("Created new CacheEntityId");
+
+ String fqnString = cacheEntityId.getFqn().toString(); // Vars for logging
+ String keyString = (String) key;
+
+
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key),
cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key),
cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
+
+
+ if (log.isTraceEnabled())
+ {
+ log.debug("Added your object into Lucene with Fqn " + fqnString +
" and key " + keyString);
+ }
+
+
+ }
+
+ }
+
+
+
+ /**
+ * If the modification type is DELETE_DATA then this method will be called.
+ * Takes in the event as a parameter
+ *
+ * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
+ * @param searchFactory - a SearchFactoryImpl instance.
+ * @throws InvalidKeyException
+ */
+ protected void handleDeleteData(NodeModifiedEvent event, SearchFactoryImpl
searchFactory) throws InvalidKeyException
+ {
+ Map dataMap = event.getData();
+
+ TransactionContext ctx = new NodeModifiedTransactionContext(event);
+
+ for (Object key : dataMap.keySet())
+ {
+ CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
+
+ String fqnString = cacheEntityId.getFqn().toString();
+ String keyString = (String) key;
+
+
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key),
cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
+ if (log.isTraceEnabled()) log.trace("Deleted your object from Lucene with
Fqn " + fqnString + " and key " + keyString);
+
+
+ }
+
+ }
+
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-07-03
13:20:58 UTC (rev 6159)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -7,92 +7,23 @@
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeModified;
import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.Fqn;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.Map;
/**
* @author Navin Surtani - navin(a)surtani.org
* <p/>
- * Class that listens for changes made to the cache so that the Lucene indexes
can be updated.
+ * Abstract class that listens for changes made to the cache so that the Lucene
indexes can be updated.
*/
@CacheListener
-public class SearchableListener
+public abstract class SearchableListener
{
- private SearchFactoryImpl searchFactory;
+ private static final Log log = LogFactory.getLog(SearchableListener.class);
- public SearchableListener(SearchFactoryImpl searchFactory)
- {
- this.searchFactory = searchFactory;
- }
+
- /**
- * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the
NodeModifiedEvent class.
- *
- * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
- */
-
-
- @NodeModified
- public void updateLuceneIndexes(NodeModifiedEvent event)
- {
- if (!event.isPre())
- {
- switch (event.getModificationType())
- {
- case PUT_MAP:
- case PUT_DATA:
- handlePutData(event);
- break;
- case REMOVE_DATA:
- handleDeleteData(event);
- break;
- }
- }
- }
-
- /**
- * If the modification type is PUT_MAP or PUT_DATA then this method will be called.
- * Takes in the event as a parameter
- *
- * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
- */
- void handlePutData(NodeModifiedEvent event)
- {
- Map dataMap = event.getData();
-
- TransactionContext ctx = new NodeModifiedTransactionContext(event);
-
- for (Object key : dataMap.keySet())
- {
- CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
-
- searchFactory.getWorker().performWork(new Work(dataMap.get(key),
cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key),
cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
- }
-
- }
-
- /**
- * If the modification type is DELETE_DATA then this method will be called.
- * Takes in the event as a parameter
- *
- * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
- */
- void handleDeleteData(NodeModifiedEvent event)
- {
- Map dataMap = event.getData();
-
- TransactionContext ctx = new NodeModifiedTransactionContext(event);
-
- for (Object key : dataMap.keySet())
- {
- CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
-
- searchFactory.getWorker().performWork(new Work(dataMap.get(key),
cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
-
- }
-
- }
-
}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -0,0 +1,72 @@
+//package org.jboss.cache.search;
+//
+//import org.hibernate.search.impl.SearchFactoryImpl;
+//import org.jboss.cache.notifications.event.NodeModifiedEvent;
+//import org.jboss.cache.pojo.notification.annotation.*;
+//import org.jboss.cache.pojo.notification.event.AttachedEvent;
+//import org.apache.commons.logging.Log;
+//import org.apache.commons.logging.LogFactory;
+//
+//import javax.transaction.Transaction;
+//
+///**
+// * @author Navin Surtani - navin(a)surtani.org
+// */
+//
+//@PojoCacheListener
+//public class SearchablePojoListener extends SearchableListener
+//{
+// private SearchFactoryImpl searchFactory;
+// private static final Log log = LogFactory.getLog(SearchablePojoListener.class);
+//
+// public SearchablePojoListener(SearchFactoryImpl searchFactory)
+// {
+// this.searchFactory = searchFactory;
+// }
+//
+// /**
+// * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the
NodeModifiedEvent class.
+// *
+// * @param event that has occured - or a node that has been changed. {@link
org.jboss.cache.notifications.event.NodeModifiedEvent}
+// * @throws InvalidKeyException if an invalid key is given.
+// */
+//
+// @Attached
+// public void handleAttach(AttachedEvent event)
+// {
+// Object added = event.getSource();
+//
+//
+//
+// }
+//
+//
+// @Detached
+// @FieldModified
+// @ListModified
+// @ArrayModified
+// @SetModified
+// @MapModified
+// public void updateLuceneIndexes(NodeModifiedEvent event) throws InvalidKeyException
+// {
+//
+// if (log.isTraceEnabled()) log.trace("You have entered the
SearchableListener");
+// if (!event.isPre())
+// {
+// if (log.isTraceEnabled()) log.trace("event.isPre is false. Going to start
updating indexes");
+// switch (event.getModificationType())
+// {
+// case PUT_MAP:
+// case PUT_DATA:
+// if (log.isTraceEnabled()) log.trace("put() has been called on
cache. Going to handle the data.");
+// handlePutData(event, searchFactory);
+// break;
+// case REMOVE_DATA:
+// handleDeleteData(event, searchFactory);
+// break;
+// }
+// }
+// }
+//
+//
+//}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-07-03
13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -72,15 +72,23 @@
* Generates the documentId from an Fqn, key combination.
*
*
- * @param fqn
- * @param key
+ * @param fqn - standard call Fqn.fromString()
+ * @param key - cannot be an object.
* @return documentId String to be given to Lucene.
* @throws InvalidFqnException
*/
- public static String generateId(Fqn fqn, String key) throws InvalidFqnException
+ public static String generateId(Fqn fqn, String key) throws InvalidFqnException,
InvalidKeyException
{
- if (key == null) throw new InvalidFqnException("Key passed in cannot be
null!");
+ if (key == null) throw new NullPointerException("Key passed in cannot be
null!");
+
+ if (key.startsWith("Fqn")) throw new InvalidKeyException("Invalid
key passed in - 'Fqn[' is not allowed");
+ if (key.startsWith("]Key=[")) throw new InvalidKeyException("Invalid
key passed in - ']Key=[' is not allowed");
+
+ if (fqn == null) throw new NullPointerException("Fqn cannot be null");
+
+ if(fqn.toString().startsWith("/Fqn")) throw new
InvalidFqnException("Invalid Fqn passed in.");
+ if (fqn.toString().startsWith("/]Key")) throw new
InvalidFqnException("Invalid Fqn passed in.");
StringBuilder sb = new StringBuilder();
sb.append("Fqn=[");
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java 2008-07-03
13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -17,7 +17,7 @@
* Tests the generateId method.
*/
- public void testGenerateId()
+ public void testGenerateId() throws InvalidKeyException
{
Fqn fqn = Fqn.fromString("/a/b/c");
@@ -67,43 +67,43 @@
}
@Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedString()
+ public void testGenerateIdWithHackedString() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/Fqn=[/a/b/c"), "x");
}
@Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedFqn()
+ public void testGenerateIdWithHackedFqn() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/Fqn=[/a/b/c"), "x");
}
@Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedFqn2()
+ public void testGenerateIdWithHackedFqn2() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/]Key=[/a/b/c"), "x");
}
- @Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedKey()
+ @Test(expectedExceptions = InvalidKeyException.class)
+ public void testGenerateIdWithHackedKey() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/a/b/c"), "]Key=[");
}
- @Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedKey2()
+ @Test(expectedExceptions = InvalidKeyException.class)
+ public void testGenerateIdWithHackedKey2() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/a/b/c"), "Fqn=[");
}
- @Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithNullKey()
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testGenerateIdWithNullKey() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/a/b/c"), null);
}
- @Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithNullFqn()
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testGenerateIdWithNullFqn() throws InvalidKeyException
{
Transformer.generateId(null, "x");
}
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java
===================================================================
---
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java 2008-07-03
13:20:58 UTC (rev 6159)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -4,12 +4,16 @@
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.search.CacheQuery;
import org.jboss.cache.search.SearchableCache;
import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.helper.IndexCleanUp;
import org.jboss.cache.search.test.Person;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -33,34 +37,66 @@
Query luceneQuery;
CacheQuery cacheQuery;
List found;
+ String key1 = "Navin";
+ String key2 = "BigGoat";
+ String key3 = "MiniGoat";
+ private static final Log log = LogFactory.getLog(Person.class);
+
@BeforeMethod
- public void setUp()
+ public void setUp() throws CloneNotSupportedException
{
- cache1 = new DefaultCacheFactory().createCache();
+ Configuration cacheCfg = new Configuration();
+ cacheCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ cacheCfg.setFetchInMemoryState(false);
+ cache1 = new DefaultCacheFactory().createCache(cacheCfg.clone());
searchableCache1 = new SearchableCacheFactory().createSearchableCache(cache1,
Person.class);
- cache2 = new DefaultCacheFactory().createCache();
+ cache2 = new DefaultCacheFactory().createCache(cacheCfg.clone());
searchableCache2 = new SearchableCacheFactory().createSearchableCache(cache2,
Person.class);
+ // wait until both caches are started and can see each other on the network.
+ long giveUpTime = System.currentTimeMillis() + (60 * 1000); // give up after 1
minute of waiting
+ boolean wait = true;
+ while (wait && System.currentTimeMillis() < giveUpTime)
+ {
+ wait = !((cache1.getMembers().size() == 2) &&
(cache2.getMembers().size() == 2));
+ // spin-lock
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException e)
+ {
+ // do nothing
+ }
+ }
+
+ if (wait)
+ {
+ // we still haven't got the cache views we want!!
+ throw new RuntimeException("Unable to initialise cluster!");
+ }
+
+
person1 = new Person();
person1.setName("Navin Surtani");
person1.setBlurb("Likes playing WoW");
person2 = new Person();
person2.setName("BigGoat");
- person2.setName("Eats grass");
+ person2.setBlurb("Eats grass");
person3 = new Person();
person3.setName("MiniGoat");
- person3.setBlurb("Makes cheese");
+ person3.setBlurb("Eats cheese");
//Put the 3 created objects in the searchableCache1.
- searchableCache1.put(Fqn.fromString("/a/b/c"), "Navin",
person1);
- searchableCache1.put(Fqn.fromString("/a/b/d"), "BigGoat",
person2);
- searchableCache1.put(Fqn.fromString("/a/b/c"), "MiniGoat",
person3);
+ searchableCache1.put(Fqn.fromString("/a/b/c"), key1, person1);
+ searchableCache1.put(Fqn.fromString("/a/b/d"), key2, person2);
+ searchableCache1.put(Fqn.fromString("/a/b/c"), key3, person3);
}
@@ -71,24 +107,45 @@
if (searchableCache1 != null) searchableCache1.stop();
if (searchableCache2 != null) searchableCache2.stop();
+ IndexCleanUp.cleanUpIndexes();
+
}
public void testSimple() throws ParseException
{
- queryParser = new QueryParser("field", new StandardAnalyzer());
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
luceneQuery = queryParser.parse("playing");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
assert found.size() == 1;
+
+ if(found.get(0) == null)
+ {
+ if(log.isTraceEnabled()) log.warn("found.get(0) is null");
+ Person p1 = (Person) searchableCache2.get("/a/b/c", key1);
+
http://wiki.jboss.org/wiki/JBossCacheSearchable
+ if(p1 == null)
+ {
+ if(log.isTraceEnabled()) log.warn("Person p1 is null in sc2 and cannot
actually see the data of person1 in sc1");
+ }
+
+ else
+ {
+ if(log.isTraceEnabled()) log.trace("p1 name is " + p1.getName());
+
+ }
+ }
+
+
assert found.get(0).equals(person1);
}
public void testModified() throws ParseException
{
- queryParser = new QueryParser("field", new StandardAnalyzer());
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
luceneQuery = queryParser.parse("playing");
cacheQuery = searchableCache2.createQuery(luceneQuery);
@@ -101,8 +158,8 @@
searchableCache1.put(Fqn.fromString("/a/b/c/"), "Navin",
person1);
- queryParser = new QueryParser("field", new StandardAnalyzer());
- luceneQuery = queryParser.parse("playing");
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("pizza");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
@@ -113,21 +170,26 @@
public void testAdded() throws ParseException
{
- luceneQuery = queryParser.parse("Goat");
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+
+ luceneQuery = queryParser.parse("eats");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
+ System.out.println("found.size() is " + found.size());
+
assert found.size() == 2 : "Size of list should be 2";
assert found.contains(person2);
assert found.contains(person3);
assert !found.contains(person4) : "This should not contain object
person4";
- person4.setName("MightyGoat");
+ person4 = new Person();
+ person4.setName("Mighty Goat");
person4.setBlurb("Also eats grass");
searchableCache1.put(Fqn.fromString("/r/a/m/"), "Ram",
person4);
- luceneQuery = queryParser.parse("Goat");
+ luceneQuery = queryParser.parse("eats");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
@@ -139,7 +201,8 @@
public void testRemoved() throws ParseException
{
- luceneQuery = queryParser.parse("Goat");
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("eats");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
@@ -147,9 +210,10 @@
assert found.contains(person2);
assert found.contains(person3) : "This should still contain object
person3";
- searchableCache1.remove(Fqn.fromString("/a/b/c/"), person3);
+ searchableCache1.remove(Fqn.fromString("/a/b/c/"), key3);
- luceneQuery = queryParser.parse("Goat");
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("eats");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java
===================================================================
---
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java 2008-07-03
13:20:58 UTC (rev 6159)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -4,6 +4,8 @@
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -11,12 +13,15 @@
import org.jboss.cache.search.QueryResultIterator;
import org.jboss.cache.search.SearchableCache;
import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.helper.IndexCleanUp;
import org.jboss.cache.search.test.Person;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.List;
+import java.util.Iterator;
+import java.io.File;
/**
* @author Navin Surtani - navin(a)surtani.org
@@ -30,10 +35,14 @@
Person person2;
Person person3;
Person person4;
+ Person person5;
QueryParser queryParser;
Query luceneQuery;
CacheQuery cacheQuery;
List found;
+ String key1 = "Navin";
+ String key2 = "BigGoat";
+ String key3 = "MiniGoat";
@BeforeMethod
public void setUp()
@@ -46,25 +55,29 @@
person1.setBlurb("Likes playing WoW");
person2 = new Person();
- person2.setName("BigGoat");
- person2.setName("Eats grass");
+ person2.setName("Big Goat");
+ person2.setBlurb("Eats grass");
person3 = new Person();
- person3.setName("MiniGoat");
- person3.setBlurb("Makes cheese");
+ person3.setName("Mini Goat");
+ person3.setBlurb("Eats cheese");
+ person5 = new Person();
+ person5.setName("Smelly Cat");
+ person5.setBlurb("Eats fish");
+
//Put the 3 created objects in the searchableCache.
+ searchableCache.put(Fqn.fromString("/a/b/c"), key1, person1);
+ searchableCache.put(Fqn.fromString("/a/b/d"), key2, person2);
+ searchableCache.put(Fqn.fromString("/a/b/c"), key3, person3);
- searchableCache.put(Fqn.fromString("/a/b/c"), "Navin",
person1);
- searchableCache.put(Fqn.fromString("/a/b/d"), "BigGoat",
person2);
- searchableCache.put(Fqn.fromString("/a/b/c"), "MiniGoat",
person3);
-
}
@AfterMethod
public void tearDown()
{
if (searchableCache != null) searchableCache.stop();
+ IndexCleanUp.cleanUpIndexes();
}
public void testSimple() throws ParseException
@@ -87,21 +100,23 @@
QueryResultIterator found = cacheQuery.iterator();
- assert found.equals(person1);
+ assert found.isFirst();
+ assert found.isLast();
}
public void testMultipleResults() throws ParseException
{
+
queryParser = new QueryParser("name", new StandardAnalyzer());
- luceneQuery = queryParser.parse("Goat");
+ luceneQuery = queryParser.parse("goat");
cacheQuery = searchableCache.createQuery(luceneQuery);
found = cacheQuery.list();
assert found.size() == 2;
- assert !found.get(1).equals(person2);
- assert !found.get(0).equals(person3);
+ assert found.get(0) == person2;
+ assert found.get(1) == person3;
}
@@ -117,9 +132,9 @@
assert found.get(0).equals(person1);
person1.setBlurb("Likes pizza");
- searchableCache.put(Fqn.fromString("/a/b/c/"), "Navin",
person1);
+ searchableCache.put(Fqn.fromString("/a/b/c/"), key1, person1);
- queryParser = new QueryParser("field", new StandardAnalyzer());
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
luceneQuery = queryParser.parse("pizza");
cacheQuery = searchableCache.createQuery(luceneQuery);
@@ -142,7 +157,8 @@
assert found.contains(person3);
assert !found.contains(person4) : "This should not contain object
person4";
- person4.setName("MightyGoat");
+ person4 = new Person();
+ person4.setName("Mighty Goat");
person4.setBlurb("Also eats grass");
searchableCache.put(Fqn.fromString("/r/a/m/"), "Ram",
person4);
@@ -169,7 +185,7 @@
assert found.contains(person2);
assert found.contains(person3) : "This should still contain object
person3";
- searchableCache.remove(Fqn.fromString("/a/b/c/"), person3);
+ searchableCache.remove(Fqn.fromString("/a/b/c/"), key3);
luceneQuery = queryParser.parse("Goat");
cacheQuery = searchableCache.createQuery(luceneQuery);
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
===================================================================
---
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java 2008-07-03
13:20:58 UTC (rev 6159)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -1,182 +1,202 @@
-package org.jboss.cache.search.blackbox;
-
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Query;
-import org.jboss.cache.Cache;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.search.CacheQuery;
-import org.jboss.cache.search.SearchableCache;
-import org.jboss.cache.search.SearchableCacheFactory;
-import org.jboss.cache.search.test.Person;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-/**
- * Same as LocalCacheTest except that you will use a POJO Cache instead and use
pojoCache.attach() ad pojoCache.detach()
- * instead of cache.put() and cache.remove().
- * <p/>
- *
- * @author Navin Surtani - navin(a)surtani.org
- */
-
-@Test(groups = "functional")
-public class LocalPOJOCacheTest
-{
- SearchableCache searchableCache;
- PojoCache pojo;
- Person person1;
- Person person2;
- Person person3;
- Person person4;
- QueryParser queryParser;
- Query luceneQuery;
- CacheQuery cacheQuery;
- List found;
-
-
- @BeforeMethod
- public void setUp()
- {
- Configuration config = new Configuration();
- PojoCache pojo = PojoCacheFactory.createCache(config, true);
- Cache coreCache = new DefaultCacheFactory().createCache();
- searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache,
Person.class);
-
- person1 = new Person();
- person1.setName("Navin Surtani");
- person1.setBlurb("Likes playing WoW");
-
- person2 = new Person();
- person2.setName("BigGoat");
- person2.setName("Eats grass");
-
- person3 = new Person();
- person3.setName("MiniGoat");
- person3.setBlurb("Makes cheese");
-
- pojo.attach(Fqn.fromString("/a/b/c"), person1);
- pojo.attach(Fqn.fromString("/a/b/d"), person2);
- pojo.attach(Fqn.fromString("/a/b/c"), person3);
-
-
- }
-
- @AfterMethod
- public void tearDown()
- {
-
- if (pojo != null) pojo.stop();
- if (searchableCache != null) searchableCache.stop();
- }
-
- public void testSimple() throws ParseException
- {
- queryParser = new QueryParser("field", new StandardAnalyzer());
- luceneQuery = queryParser.parse("playing");
- cacheQuery = searchableCache.createQuery(luceneQuery);
-
- found = cacheQuery.list();
-
- assert found.size() == 1;
- assert found.get(0).equals(person1);
- }
-
- public void testMultipleResults() throws ParseException
- {
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 2;
- assert !found.get(1).equals(person2);
- assert !found.get(0).equals(person3);
-
- }
-
- public void testModified() throws ParseException
- {
- queryParser = new QueryParser("field", new StandardAnalyzer());
- luceneQuery = queryParser.parse("playing");
- cacheQuery = searchableCache.createQuery(luceneQuery);
-
- found = cacheQuery.list();
-
- assert found.size() == 1;
- assert found.get(0).equals(person1);
-
- person1.setBlurb("Likes pizza");
-
- pojo.attach(Fqn.fromString("/a/b/c/"), person1);
-
- queryParser = new QueryParser("field", new StandardAnalyzer());
- luceneQuery = queryParser.parse("pizza");
- cacheQuery = searchableCache.createQuery(luceneQuery);
-
- found = cacheQuery.list();
-
- assert found.size() == 1;
- assert found.get(0).equals(person1);
- }
-
- public void testAdded() throws ParseException
- {
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 2 : "Size of list should be 2";
- assert found.contains(person2);
- assert found.contains(person3);
- assert !found.contains(person4) : "This should not contain object
person4";
-
- person4.setName("MightyGoat");
- person4.setBlurb("Also eats grass");
-
- pojo.attach(Fqn.fromString("/r/a/m/"), person4);
-
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 3 : "Size of list should be 3";
- assert found.contains(person2);
- assert found.contains(person3);
- assert found.contains(person4) : "This should now contain object
person4";
- }
-
- public void testRemoved() throws ParseException
- {
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 2;
- assert found.contains(person2);
- assert found.contains(person3) : "This should still contain object
person3";
-
- pojo.detach(Fqn.fromString("/a/b/c/"));
-
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 1;
- assert found.contains(person2);
- assert !found.contains(person3) : "The search should not return
person3";
-
-
- }
-
-}
-
-
-
+//package org.jboss.cache.search.blackbox;
+//
+//import org.apache.lucene.analysis.standard.StandardAnalyzer;
+//import org.apache.lucene.queryParser.ParseException;
+//import org.apache.lucene.queryParser.QueryParser;
+//import org.apache.lucene.search.Query;
+//import org.apache.commons.logging.Log;
+//import org.apache.commons.logging.LogFactory;
+//import org.jboss.cache.Cache;
+//import org.jboss.cache.DefaultCacheFactory;
+//import org.jboss.cache.Fqn;
+//import org.jboss.cache.config.Configuration;
+//import org.jboss.cache.pojo.PojoCache;
+//import org.jboss.cache.pojo.PojoCacheFactory;
+//import org.jboss.cache.search.CacheQuery;
+//import org.jboss.cache.search.SearchableCache;
+//import org.jboss.cache.search.SearchableCacheFactory;
+//import org.jboss.cache.search.helper.IndexCleanUp;
+//import org.jboss.cache.search.test.Person;
+//import org.testng.annotations.AfterMethod;
+//import org.testng.annotations.BeforeMethod;
+//import org.testng.annotations.Test;
+//
+//import java.util.List;
+//
+///**
+// * Same as LocalCacheTest except that you will use a POJO Cache instead and use
pojoCache.attach() ad pojoCache.detach()
+// * instead of cache.put() and cache.remove().
+// * <p/>
+// *
+// * @author Navin Surtani - navin(a)surtani.org
+// */
+//
+//@Test(groups = "functional")
+//public class LocalPOJOCacheTest
+//{
+// SearchableCache searchableCache;
+// PojoCache pojo;
+// Person person1;
+// Person person2;
+// Person person3;
+// Person person4;
+// QueryParser queryParser;
+// Query luceneQuery;
+// CacheQuery cacheQuery;
+// List found;
+// private static final Log log = LogFactory.getLog(LocalPOJOCacheTest.class);
+//
+//
+// @BeforeMethod
+// public void setUp()
+// {
+// boolean toStart = false;
+// pojo = PojoCacheFactory.createCache(new Configuration(), toStart);
+// pojo.start(); // if toStart above is true, it will starts the cache
automatically.
+// searchableCache = new
SearchableCacheFactory().createSearchableCache(pojo.getCache(), Person.class);
+//
+// person1 = new Person();
+// person1.setName("Navin Surtani");
+// person1.setBlurb("Likes playing WoW");
+//
+// person2 = new Person();
+// person2.setName("BigGoat");
+// person2.setBlurb("Eats grass");
+//
+// person3 = new Person();
+// person3.setName("MiniGoat");
+// person3.setBlurb("Eats cheese");
+//
+// pojo.attach(Fqn.fromString("/a/b/c"), person1);
+// pojo.attach(Fqn.fromString("/a/b/d"), person2);
+// pojo.attach(Fqn.fromString("/a/b/c"), person3);
+//
+//
+// }
+//
+// @AfterMethod
+// public void tearDown()
+// {
+// if (pojo != null) pojo.stop();
+// if (searchableCache != null) searchableCache.stop();
+// IndexCleanUp.cleanUpIndexes();
+// }
+//
+// public void testSimple() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("playing");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+//
+// found = cacheQuery.list();
+//
+// assert found.size() == 1;
+//
+// if (found.get(0) == null)
+// {
+// if (log.isTraceEnabled()) log.warn("found.get(0) is null");
+//
+// }
+//
+// if (person1 == null)
+// {
+// if (log.isTraceEnabled()) log.warn("person1 is null");
+// }
+//
+// // assert person1.equals(found.get(0));
+// }
+//
+// public void testMultipleResults() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("Eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 2;
+// assert !found.get(1).equals(person2);
+// assert !found.get(0).equals(person3);
+//
+// }
+//
+// public void testModified() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("playing");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+//
+// found = cacheQuery.list();
+//
+// assert found.size() == 1;
+//// assert found.get(0).equals(person1);
+//
+// person1.setBlurb("Likes pizza");
+//
+// pojo.attach(Fqn.fromString("/a/b/c/"), person1);
+//
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("pizza");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+//
+// found = cacheQuery.list();
+//
+// assert found.size() == 1;
+//// assert found.get(0).equals(person1);
+// }
+//
+// public void testAdded() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 2 : "Size of list should be 2";
+// assert found.contains(person2);
+// assert found.contains(person3);
+// assert !found.contains(person4) : "This should not contain object
person4";
+//
+// person4 = new Person();
+// person4.setName("MightyGoat");
+// person4.setBlurb("Also eats grass");
+//
+// pojo.attach(Fqn.fromString("/r/a/m/"), person4);
+//
+// luceneQuery = queryParser.parse("eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 3 : "Size of list should be 3";
+// assert found.contains(person2);
+// assert found.contains(person3);
+// assert found.contains(person4) : "This should now contain object
person4";
+// }
+//
+// public void testRemoved() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 2;
+// assert found.contains(person2);
+// assert found.contains(person3) : "This should still contain object
person3";
+//
+// pojo.detach("/a/b/d");
+//
+// luceneQuery = queryParser.parse("eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 1;
+// assert found.contains(person2);
+// assert !found.contains(person3) : "The search should not return
person3";
+//
+//
+// }
+//
+//}
+//
+//
+//
Added: searchable/trunk/src/test/java/org/jboss/cache/search/helper/IndexCleanUp.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/helper/IndexCleanUp.java
(rev 0)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/helper/IndexCleanUp.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -0,0 +1,41 @@
+package org.jboss.cache.search.helper;
+
+import org.jboss.cache.search.test.Person;
+
+import java.io.File;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class IndexCleanUp
+{
+
+ public static void cleanUpIndexes()
+ {
+ Class[] knownClasses = {Person.class};
+ for (Class c : knownClasses)
+ {
+ String dirName = c.getName();
+ File file = new File(dirName);
+ if (file.exists())
+ {
+ recursiveDelete(file);
+ }
+ }
+ }
+
+ private static void recursiveDelete(File f)
+ {
+ if (f.isDirectory())
+ {
+ File[] files = f.listFiles();
+ for (File file : files) recursiveDelete(file);
+ }
+ else
+ {
+ f.delete();
+ }
+ }
+
+}
+
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java 2008-07-03
13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java 2008-07-03
14:05:31 UTC (rev 6160)
@@ -1,19 +1,29 @@
package org.jboss.cache.search.test;
+
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Store;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.pojo.annotation.Replicable;
+import java.io.Serializable;
+
/**
* @author Navin Surtani - navin(a)surtani.org
*/
@ProvidedId
@Indexed
-public class Person
+public class Person implements Serializable
{
- @Field
+ private static final Log log = LogFactory.getLog(Person.class);
+
+
+ @Field (store = Store.YES)
private String name;
- @Field
+ @Field (store = Store.YES)
private String blurb;
public String getName()
@@ -35,4 +45,34 @@
{
this.blurb = blurb;
}
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Person person = (Person) o;
+
+ if (blurb != null ? !blurb.equals(person.blurb) : person.blurb != null) return
false;
+ if (name != null ? !name.equals(person.name) : person.name != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (name != null ? name.hashCode() : 0);
+ result = 31 * result + (blurb != null ? blurb.hashCode() : 0);
+ return result;
+ }
+
+
+ public String toString()
+ {
+ return "Person{" +
+ "name='" + name + '\'' +
+ ", blurb='" + blurb + '\'' +
+ '}';
+ }
}
Modified: searchable/trunk/src/test/resources/log4j.xml
===================================================================
--- searchable/trunk/src/test/resources/log4j.xml 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/resources/log4j.xml 2008-07-03 14:05:31 UTC (rev 6160)
@@ -63,11 +63,15 @@
<!-- ================ -->
<category name="org.jboss.cache.search">
- <priority value="WARN"/>
+ <priority value="TRACE"/>
</category>
+ <category name="org.hibernate.search">
+ <priority value="TRACE"/>
+ </category>
+
<category name="org.jboss.cache">
- <priority value="WARN"/>
+ <priority value="INFO"/>
</category>
<category name="org.jboss.cache.factories">
@@ -87,8 +91,8 @@
<!-- ======================= -->
<root>
- <!--<appender-ref ref="CONSOLE"/>-->
- <appender-ref ref="FILE"/>
+ <appender-ref ref="CONSOLE"/>
+ <!--<appender-ref ref="FILE"/>-->
</root>
</log4j:configuration>