[jbosscache-commits] JBoss Cache SVN: r7569 - in searchable/trunk: src/main/java/org/jboss/cache/search and 1 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Thu Jan 22 06:31:35 EST 2009
Author: navssurtani
Date: 2009-01-22 06:31:35 -0500 (Thu, 22 Jan 2009)
New Revision: 7569
Modified:
searchable/trunk/pom.xml
searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
Log:
Playing with pojo
Modified: searchable/trunk/pom.xml
===================================================================
--- searchable/trunk/pom.xml 2009-01-22 10:31:05 UTC (rev 7568)
+++ searchable/trunk/pom.xml 2009-01-22 11:31:35 UTC (rev 7569)
@@ -25,7 +25,7 @@
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
- <version>3.0.1.GA</version>
+ <version>3.0.2.GA</version>
</dependency>
<dependency>
@@ -40,14 +40,13 @@
<version>1.1.1</version>
</dependency>
-<!--
- Temporarily commented out until the searchable cache is compatible with pojo cache
-
+
+
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-pojo</artifactId>
<version>3.0.0.GA</version>
- </dependency> -->
+ </dependency>
<!-- Test dependencies -->
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java 2009-01-22 10:31:05 UTC (rev 7568)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java 2009-01-22 11:31:35 UTC (rev 7569)
@@ -1,72 +1,72 @@
-///*
-// * JBoss, Home of Professional Open Source
-// * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
-// * by the @authors tag. See the copyright.txt in the distribution for a
-// * full listing of individual contributors.
-// *
-// * This is free software; you can redistribute it and/or modify it
-// * under the terms of the GNU Lesser General Public License as
-// * published by the Free Software Foundation; either version 2.1 of
-// * the License, or (at your option) any later version.
-// *
-// * This software is distributed in the hope that it will be useful,
-// * but WITHOUT ANY WARRANTY; without even the implied warranty of
-// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// * Lesser General Public License for more details.
-// *
-// * You should have received a copy of the GNU Lesser General Public
-// * License along with this software; if not, write to the Free
-// * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-// * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-// */
-//
-//package org.jboss.cache.search;
-//
-//import org.hibernate.search.backend.TransactionContext;
-//import org.jboss.cache.pojo.notification.event.Event;
-//
-//import javax.transaction.Synchronization;
-//import javax.transaction.Transaction;
-//
-///**
-// * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
-// */
-//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 isTransactionInProgress()
-// {
-// 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);
-// }
-// }
-// }
-//}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.search;
+
+import org.hibernate.search.backend.TransactionContext;
+import org.jboss.cache.pojo.notification.event.Event;
+
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+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 isTransactionInProgress()
+ {
+ 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 2009-01-22 10:31:05 UTC (rev 7568)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2009-01-22 11:31:35 UTC (rev 7569)
@@ -27,6 +27,7 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
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;
@@ -105,64 +106,64 @@
}
-// /**
-// * This method creates a searchable cache as well but requires the properties object.
-// *
-// * @param pojo - the pojoCache
-// * @param properties - java.util.properties
-// * @param classes - a class array
-// * @return a SearchableCache
-// */
+ /**
+ * This method creates a searchable cache as well but requires the properties object.
+ *
+ * @param pojo - the pojoCache
+ * @param properties - java.util.properties
+ * @param classes - a class array
+ * @return a SearchableCache
+ */
-// public SearchableCache createSearchableCache(PojoCache pojo, Properties properties, Class... classes)
-// {
-//
-// System.out.println("create searchable cache called with pojo cache");
-// //TODO: Ask Manik and/or Jason if there is a way to directly check if the pojo cache is started or not
-// validateClasses(classes);
-//
-// Cache coreCache = pojo.getCache();
-//
-// if (coreCache.getCacheStatus() != CacheStatus.STARTED)
-// {
-// if (log.isInfoEnabled()) log.info("Cache not started. Starting cache first.");
-// pojo.start();
-// }
-//
-// if (classes.length == 0)
-// {
-// if (log.isWarnEnabled()) log.warn("You haven't passed in any classes to index. Is this an error?");
-// }
-//
-// // step 1: create hibernate search searchFactory
-// SearchConfiguration cfg = new SearchableCacheConfiguration(classes, properties);
-// // set classes in the cfg
-//
-// SearchFactoryImplementor searchFactory = new SearchFactoryImpl(cfg);
-//
-// //Now create the pojoListener
-// SearchablePojoListener pojoListener = new SearchablePojoListener(searchFactory);
-// pojo.addListener(pojoListener);
-// pojo.getCache().addCacheListener(pojoListener);
-//
-// SearchableCache sc = new SearchableCacheImpl(coreCache, searchFactory);
-// return sc;
-// }
+ public SearchableCache createSearchableCache(PojoCache pojo, Properties properties, Class... classes)
+ {
-// /**
-// * Creates a searchable cache from a cache object and a class array, without the properties object.
-// *
-// * @param pojo - the pojoCache
-// * @param classes - Class array to be added
-// * @return a SearchableCache
-// */
-//
-//
-// public SearchableCache createSearchableCache(PojoCache pojo, Class... classes)
-// {
-// return createSearchableCache(pojo, null, classes);
-// }
+ System.out.println("create searchable cache called with pojo cache");
+ //TODO: Ask Manik and/or Jason if there is a way to directly check if the pojo cache is started or not
+ validateClasses(classes);
+ Cache coreCache = pojo.getCache();
+
+ if (coreCache.getCacheStatus() != CacheStatus.STARTED)
+ {
+ if (log.isInfoEnabled()) log.info("Cache not started. Starting cache first.");
+ pojo.start();
+ }
+
+ if (classes.length == 0)
+ {
+ if (log.isWarnEnabled()) log.warn("You haven't passed in any classes to index. Is this an error?");
+ }
+
+ // step 1: create hibernate search searchFactory
+ SearchConfiguration cfg = new SearchableCacheConfiguration(classes, properties);
+ // set classes in the cfg
+
+ SearchFactoryImplementor searchFactory = new SearchFactoryImpl(cfg);
+
+ //Now create the pojoListener
+ SearchablePojoListener pojoListener = new SearchablePojoListener(searchFactory);
+ pojo.addListener(pojoListener);
+ pojo.getCache().addCacheListener(pojoListener);
+
+ SearchableCache sc = new SearchableCacheImpl(coreCache, searchFactory);
+ return sc;
+ }
+
+ /**
+ * Creates a searchable cache from a cache object and a class array, without the properties object.
+ *
+ * @param pojo - the pojoCache
+ * @param classes - Class array to be added
+ * @return a SearchableCache
+ */
+
+
+ public SearchableCache createSearchableCache(PojoCache pojo, Class... classes)
+ {
+ return createSearchableCache(pojo, null, classes);
+ }
+
//This is to check that both the @ProvidedId is present and the the @DocumentId is not present. This is because
// don't want both of these 2 annotations used at the same time.
private void validateClasses(Class... classes)
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java 2009-01-22 10:31:05 UTC (rev 7568)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java 2009-01-22 11:31:35 UTC (rev 7569)
@@ -1,156 +1,156 @@
-///*
-// * JBoss, Home of Professional Open Source
-// * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
-// * by the @authors tag. See the copyright.txt in the distribution for a
-// * full listing of individual contributors.
-// *
-// * This is free software; you can redistribute it and/or modify it
-// * under the terms of the GNU Lesser General Public License as
-// * published by the Free Software Foundation; either version 2.1 of
-// * the License, or (at your option) any later version.
-// *
-// * This software is distributed in the hope that it will be useful,
-// * but WITHOUT ANY WARRANTY; without even the implied warranty of
-// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// * Lesser General Public License for more details.
-// *
-// * You should have received a copy of the GNU Lesser General Public
-// * License along with this software; if not, write to the Free
-// * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-// * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-// */
-//
-//package org.jboss.cache.search;
-//
-//import org.hibernate.search.impl.SearchFactoryImpl;
-//import org.hibernate.search.backend.TransactionContext;
-//import org.hibernate.search.backend.Work;
-//import org.hibernate.search.backend.WorkType;
-//import org.hibernate.search.engine.SearchFactoryImplementor;
-//import org.jboss.cache.notifications.event.NodeModifiedEvent;
-//import org.jboss.cache.notifications.event.NodeCreatedEvent;
-//import org.jboss.cache.notifications.annotation.NodeModified;
-//import org.jboss.cache.notifications.annotation.CacheListener;
-//import org.jboss.cache.notifications.annotation.NodeCreated;
-//import org.jboss.cache.pojo.notification.annotation.*;
-//import org.jboss.cache.pojo.notification.event.AttachedEvent;
-//import org.jboss.cache.pojo.notification.event.DetachedEvent;
-//import org.jboss.cache.pojo.notification.event.Event;
-//import org.jboss.cache.pojo.notification.NotificationContext;
-//import org.jboss.cache.pojo.PojoCache;
-//import org.jboss.cache.pojo.impl.InternalHelper;
-//import org.jboss.cache.Fqn;
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
-//
-//import javax.transaction.Transaction;
-//
-///**
-// * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
-// */
-//
-//@PojoCacheListener
-//@CacheListener
-//public class SearchablePojoListener
-//{
-// private SearchFactoryImplementor searchFactory;
-// private static final Log log = LogFactory.getLog(SearchablePojoListener.class);
-// private String pojoKey = "pojoKey";
-//
-// private ThreadLocal<Fqn> savedFqn = new ThreadLocal<Fqn>();
-//
-// public SearchablePojoListener(SearchFactoryImplementor searchFactory)
-// {
-// this.searchFactory = searchFactory;
-// }
-//
-// @NodeModified
-// public void handleNodeModified(NodeModifiedEvent nme)
-// {
-// if (!nme.isPre()) return;
-// Fqn f = nme.getFqn();
-// if(log.isDebugEnabled()) log.debug("Node modified called for Fqn " + f);
-// if (InternalHelper.isInternalNode(f))
-// {
-// if(log.isDebugEnabled()) log.debug("Is internal and I dont care");
-// }
-// else
-// {
-// savedFqn.set(f);
-// if(log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal.");
-// }
-// }
-//
-// @NodeCreated
-// public void handleNodeKreated(NodeCreatedEvent nce)
-// {
-// if (!nce.isPre()) return;
-// Fqn f = nce.getFqn();
-// if(log.isDebugEnabled()) log.debug("Node kreated called for Fqn " + f);
-// if (InternalHelper.isInternalNode(f))
-// {
-// if(log.isDebugEnabled()) log.debug("Is internal and I dont care");
-// }
-// else
-// {
-// savedFqn.set(f);
-// if(log.isDebugEnabled()) log.debug("savedFqn.set() called");
-// }
-// }
-//
-// /**
-// * 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) throws InvalidKeyException
-// {
-// System.out.println("Pojocache.attach() called");
-// Object added = event.getSource();
-//
-// System.out.println("the object is " + event.toString());
-//
-// NotificationContext notificationContext = event.getContext();
-// System.out.println("notificationContext is " + notificationContext);
-//
-// PojoCache pojo = notificationContext.getPojoCache();
-// System.out.println("pojo is " + pojo);
-//
-//// Fqn fqn = pojo.getInternalFqn(added);
-// Fqn fqn = savedFqn.get();
-// savedFqn.remove();
-// System.out.println("Fqn is " + fqn);
-//
-//
-// CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
-// System.out.println("new CEI created" + cacheEntityId);
-//
-// TransactionContext ctx = new PojoTransactionContext(event);
-// System.out.println("new ctx created" + ctx);
-//
-// searchFactory.getWorker().performWork(new Work(added, cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
-// }
-//
-// @Detached
-// public void handleDetach(DetachedEvent event) throws InvalidKeyException
-// {
-// Object deleted = event.getSource();
-// Fqn fqn = event.getContext().getPojoCache().getInternalFqn(deleted);
-//
-// CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
-//
-// TransactionContext ctx = new PojoTransactionContext(event);
-//
-// searchFactory.getWorker().performWork(new Work(deleted, cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
-// }
-//
-// //TODO: Sort out updating Lucene for the following annotations: -
-//// @FieldModified
-//// @ListModified
-//// @ArrayModified
-//// @SetModified
-//
-//}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.search;
+
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.backend.TransactionContext;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.notifications.event.NodeCreatedEvent;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeCreated;
+import org.jboss.cache.pojo.notification.annotation.*;
+import org.jboss.cache.pojo.notification.event.AttachedEvent;
+import org.jboss.cache.pojo.notification.event.DetachedEvent;
+import org.jboss.cache.pojo.notification.event.Event;
+import org.jboss.cache.pojo.notification.NotificationContext;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.impl.InternalHelper;
+import org.jboss.cache.Fqn;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.transaction.Transaction;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at PojoCacheListener
+ at CacheListener
+public class SearchablePojoListener
+{
+ private SearchFactoryImplementor searchFactory;
+ private static final Log log = LogFactory.getLog(SearchablePojoListener.class);
+ private String pojoKey = "pojoKey";
+
+ private ThreadLocal<Fqn> savedFqn = new ThreadLocal<Fqn>();
+
+ public SearchablePojoListener(SearchFactoryImplementor searchFactory)
+ {
+ this.searchFactory = searchFactory;
+ }
+
+ @NodeModified
+ public void handleNodeModified(NodeModifiedEvent nme)
+ {
+ if (!nme.isPre()) return;
+ Fqn f = nme.getFqn();
+ if(log.isDebugEnabled()) log.debug("Node modified called for Fqn " + f);
+ if (InternalHelper.isInternalNode(f))
+ {
+ if(log.isDebugEnabled()) log.debug("Is internal and I dont care");
+ }
+ else
+ {
+ savedFqn.set(f);
+ if(log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal.");
+ }
+ }
+
+ @NodeCreated
+ public void handleNodeKreated(NodeCreatedEvent nce)
+ {
+ if (!nce.isPre()) return;
+ Fqn f = nce.getFqn();
+ if(log.isDebugEnabled()) log.debug("Node kreated called for Fqn " + f);
+ if (InternalHelper.isInternalNode(f))
+ {
+ if(log.isDebugEnabled()) log.debug("Is internal and I dont care");
+ }
+ else
+ {
+ savedFqn.set(f);
+ if(log.isDebugEnabled()) log.debug("savedFqn.set() called");
+ }
+ }
+
+ /**
+ * 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) throws InvalidKeyException
+ {
+ System.out.println("Pojocache.attach() called");
+ Object added = event.getSource();
+
+ System.out.println("the object is " + event.toString());
+
+ NotificationContext notificationContext = event.getContext();
+ System.out.println("notificationContext is " + notificationContext);
+
+ PojoCache pojo = notificationContext.getPojoCache();
+ System.out.println("pojo is " + pojo);
+
+// Fqn fqn = pojo.getInternalFqn(added);
+ Fqn fqn = savedFqn.get();
+ savedFqn.remove();
+ System.out.println("Fqn is " + fqn);
+
+
+ CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
+ System.out.println("new CEI created " + cacheEntityId);
+
+ TransactionContext ctx = new PojoTransactionContext(event);
+ System.out.println("new ctx created " + ctx);
+
+ searchFactory.getWorker().performWork(new Work(added, cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
+ }
+
+ @Detached
+ public void handleDetach(DetachedEvent event) throws InvalidKeyException
+ {
+ Object deleted = event.getSource();
+ Fqn fqn = event.getContext().getPojoCache().getInternalFqn(deleted);
+
+ CacheEntityId cacheEntityId = new CacheEntityId(fqn, pojoKey);
+
+ TransactionContext ctx = new PojoTransactionContext(event);
+
+ searchFactory.getWorker().performWork(new Work(deleted, cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
+ }
+
+ //TODO: Sort out updating Lucene for the following annotations: -
+// @FieldModified
+// @ListModified
+// @ArrayModified
+// @SetModified
+
+}
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 2009-01-22 10:31:05 UTC (rev 7568)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java 2009-01-22 11:31:35 UTC (rev 7569)
@@ -1,193 +1,195 @@
-//package org.jboss.cache.search.blackbox;
-//
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
-//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.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.QueryResultIterator;
-//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;
-//
-///**
-// * 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 (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
-// */
-//
-//@Test(groups = "functional", enabled = false)
-//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, 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("/a/b/c", person1);
-// pojo.attach("/a/b/d", person2);
-// pojo.attach("/c/a/t", 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);
-//
-// QueryResultIterator found = cacheQuery.iterator();
-// found.first();
-// System.out.println("First object is " + found.next());
-// }
-//
-// public void testMultipleResults() throws ParseException
-// {
-// queryParser = new QueryParser("blurb", new StandardAnalyzer());
-// luceneQuery = queryParser.parse("Eats");
-// cacheQuery = searchableCache.createQuery(luceneQuery);
-// found = cacheQuery.list();
-//
-// System.out.println("size is " + found.size());
-// assert found.size() == 2;
-//
-// System.out.println("object 0 is " + found.get(0));
-// System.out.println("object 1 is " + found.get(1));
-// 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";
-//
-//
-// }
-//
-//}
-//
-//
-//
+package org.jboss.cache.search.blackbox;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.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.QueryResultIterator;
+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;
+
+/**
+ * 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 (<a href="mailto:nsurtani at redhat.com">nsurtani at redhat.com</a>)
+ */
+
+ at Test(groups = "functional", enabled = true)
+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, 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("/a/b/c", person1);
+ pojo.attach("/a/b/d", person2);
+ pojo.attach("/c/a/t", 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("eats");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ System.out.println("Size of list is " + found.size());
+ System.out.println("Object 1 is " + found.get(0));
+ System.out.println("Object 2 is " + found.get(1));
+ }
+
+ public void testMultipleResults() throws ParseException
+ {
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("Eats");
+ cacheQuery = searchableCache.createQuery(luceneQuery);
+ found = cacheQuery.list();
+
+ System.out.println("size is " + found.size());
+ assert found.size() == 2;
+
+ System.out.println("object 0 is " + found.get(0));
+ System.out.println("object 1 is " + found.get(1));
+ 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";
+
+
+ }
+
+}
+
+
+
More information about the jbosscache-commits
mailing list