From jbosscache-commits at lists.jboss.org Fri Feb 20 10:15:28 2009 Content-Type: multipart/mixed; boundary="===============6006359105392420352==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r7742 - in searchable/trunk/src: test/java/org/jboss/cache/search and 2 other directories. Date: Fri, 20 Feb 2009 10:15:26 -0500 Message-ID: --===============6006359105392420352== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: navssurtani Date: 2009-02-20 10:15:26 -0500 (Fri, 20 Feb 2009) New Revision: 7742 Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl= .java searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.j= ava searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoList= ener.java searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIterato= rImplTest.java searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJO= CacheTest.java searchable/trunk/src/test/resources/log4j.xml Log: More stuff coming in Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryI= mpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.ja= va 2009-02-20 10:56:49 UTC (rev 7741) +++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.ja= va 2009-02-20 15:15:26 UTC (rev 7742) @@ -332,7 +332,10 @@ EntityId id =3D createCacheEntityId(documentId); ids.add(id); } - + if (entityLoader instanceof PojoEntityLoader) + { + System.out.println("entityLoader is a PEL"); + } List list =3D entityLoader.load(ids); if (resultTransformer =3D=3D null) { Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryP= ojoImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImp= l.java 2009-02-20 10:56:49 UTC (rev 7741) +++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImp= l.java 2009-02-20 15:15:26 UTC (rev 7742) @@ -21,7 +21,7 @@ = // Create a pojo entity loader instead of a cache entity loader sinc= e we are dealing with a pojo cache entityLoader =3D new PojoEntityLoader(pojo); - + System.out.println("Created a new CacheQueryPojoImpl"); } = protected EntityId createCacheEntityId(String docId) Modified: searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityI= d.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java= 2009-02-20 10:56:49 UTC (rev 7741) +++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java= 2009-02-20 15:15:26 UTC (rev 7742) @@ -3,7 +3,7 @@ import org.jboss.cache.Fqn; = /** - * This class is used to get fqns, keys and documentId's by calling meth= ods on {@link org.jboss.cache.search.Transformer} + * This class is used to get fqns, keys and documentId's by calling method= s on {@link org.jboss.cache.search.Transformer} *

* * @author Navin Surtani (nsurtan= i(a)redhat.com) @@ -14,7 +14,7 @@ protected String documentId; protected Fqn fqn; = - public PojoEntityId (Fqn fqn) + public PojoEntityId(Fqn fqn) { if (fqn =3D=3D null) throw new NullPointerException("Fqn is null."); this.fqn =3D fqn; @@ -22,7 +22,7 @@ = } = - public PojoEntityId (String documentId) + public PojoEntityId(String documentId) { if (documentId =3D=3D null) throw new NullPointerException("doc ID i= s null."); this.documentId =3D documentId; @@ -54,7 +54,7 @@ = public String getDocumentId() throws InvalidKeyException { - if (fqn =3D=3D null) + if (fqn =3D=3D null) { throw new IllegalArgumentException("Either your key or fqn is nul= l. Please check again."); } Modified: searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityL= oader.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.= java 2009-02-20 10:56:49 UTC (rev 7741) +++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.= java 2009-02-20 15:15:26 UTC (rev 7742) @@ -14,9 +14,11 @@ { super(pojoCache.getCache()); this.pojoCache =3D pojoCache; + System.out.println("Created new PojoEntityLoader"); } = - protected Object loadFromCache(CacheEntityId id) + @Override + protected Object loadFromCache(EntityId id) { return pojoCache.find(id.getFqn()); } Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableP= ojoListener.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoLis= tener.java 2009-02-20 10:56:49 UTC (rev 7741) +++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoLis= tener.java 2009-02-20 15:15:26 UTC (rev 7742) @@ -29,13 +29,14 @@ 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.event.NodeRemovedEvent; +import org.jboss.cache.notifications.event.NodeEvent; 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.notifications.annotation.NodeRemoved; 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.event.*; import org.jboss.cache.pojo.notification.NotificationContext; import org.jboss.cache.pojo.PojoCache; import org.jboss.cache.pojo.impl.InternalHelper; @@ -44,6 +45,9 @@ import org.apache.commons.logging.LogFactory; = import javax.transaction.Transaction; +import java.util.List; +import java.util.ArrayList; +import java.util.Collection; = /** * @author Navin Surtani (nsurtan= i(a)redhat.com) @@ -55,10 +59,11 @@ { private SearchFactoryImplementor searchFactory; private static final Log log =3D LogFactory.getLog(SearchablePojoListen= er.class); - private String pojoKey =3D "pojoKey"; = private ThreadLocal savedFqn =3D new ThreadLocal(); = + private List> fqnCollection =3D new ArrayList>(); + public SearchablePojoListener(SearchFactoryImplementor searchFactory) { this.searchFactory =3D searchFactory; @@ -69,35 +74,51 @@ { if (!nme.isPre()) return; Fqn f =3D nme.getFqn(); - System.out.println("Node modified called for Fqn " + f); if (InternalHelper.isInternalNode(f)) { - System.out.println("Is internal and I dont care"); + // do nothing because I don't want anything to do with the intern= al nodes } else { savedFqn.set(f); - System.out.println("Saved Fqn to ThreadLocal."); +// if (log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal f= or fqn " + f); } } = @NodeCreated - public void handleNodeKreated(NodeCreatedEvent nce) + public void handleNodeCreated(NodeCreatedEvent nce) { if (!nce.isPre()) return; - Fqn f =3D nce.getFqn(); - System.out.println("Node kreated called for Fqn " + f); - if (InternalHelper.isInternalNode(f)) + Fqn fqn =3D nce.getFqn(); + if (InternalHelper.isInternalNode(fqn)) { - System.out.println("Is internal and I dont care"); + // do nothing because I don't want anything to do with the intern= al nodes } else { - savedFqn.set(f); - System.out.println("savedFqn.set() called"); + savedFqn.set(fqn); +// if (log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal f= or fqn " + fqn); } } = + @NodeRemoved + public void handleNodeRemoved(NodeRemovedEvent nre) + { + if (!nre.isPre()) return; + Fqn fqn =3D nre.getFqn(); + if (InternalHelper.isInternalNode((fqn))) + { + // do nothing because I don't want anything to do with the intern= al nodes + + } + else + { + savedFqn.set(fqn); +// if (log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal f= or fqn " + fqn); + + } + } + /** * Takes in a NodeModifiedEvent and updates the Lucene indexes using me= thods on the NodeModifiedEvent class. * @@ -108,49 +129,123 @@ @Attached public void handleAttach(AttachedEvent event) throws InvalidKeyException { - System.out.println("Pojocache.attach() called"); + if (log.isDebugEnabled()) log.debug("@Attached annotation found."); + Object added =3D event.getSource(); = - System.out.println("the object is " + event.toString()); + if (log.isDebugEnabled()) log.debug("Added object is:- " + added); = - NotificationContext notificationContext =3D event.getContext(); - System.out.println("notificationContext is " + notificationContext); + Fqn fqn =3D savedFqn.get(); = - PojoCache pojo =3D notificationContext.getPojoCache(); - System.out.println("pojo is " + pojo); + if (fqn =3D=3D null) + { + //look through the collection of threadLocals. = -// Fqn fqn =3D pojo.getInternalFqn(added); - Fqn fqn =3D savedFqn.get(); - savedFqn.remove(); - System.out.println("Fqn is " + fqn); + if (fqn =3D=3D null) + { + throw new NullPointerException("Your fqn still null"); + } = + } = - CacheEntityId cacheEntityId =3D new CacheEntityId(fqn, pojoKey); - System.out.println("new CEI created " + cacheEntityId); +// savedFqn.remove(); = + if (log.isDebugEnabled()) log.debug("Fqn is " + fqn); = + + EntityId pojoEntityId =3D new PojoEntityId(fqn); + TransactionContext ctx =3D new PojoTransactionContext(event); - System.out.println("new ctx created " + ctx); = - searchFactory.getWorker().performWork(new Work(added, cacheEntityId.= getDocumentId(), WorkType.ADD), ctx); + searchFactory.getWorker().performWork(new Work(added, pojoEntityId.g= etDocumentId(), WorkType.ADD), ctx); } = @Detached public void handleDetach(DetachedEvent event) throws InvalidKeyException { + if (log.isDebugEnabled()) log.debug("@Detached annotation found."); Object deleted =3D event.getSource(); - Fqn fqn =3D event.getContext().getPojoCache().getInternalFqn(deleted= ); = - CacheEntityId cacheEntityId =3D new CacheEntityId(fqn, pojoKey); + Fqn fqn =3D savedFqn.get(); + savedFqn.remove(); = + if (log.isDebugEnabled()) log.debug("Fqn is " + fqn); + + EntityId pojoEntityId =3D new PojoEntityId(fqn); + TransactionContext ctx =3D new PojoTransactionContext(event); = - searchFactory.getWorker().performWork(new Work(deleted, cacheEntityI= d.getDocumentId(), WorkType.DELETE), ctx); + searchFactory.getWorker().performWork(new Work(deleted, pojoEntityId= .getDocumentId(), WorkType.DELETE), ctx); } = //TODO: Sort out updating Lucene for the following annotations: - -// @FieldModified -// @ListModified -// @ArrayModified -// @SetModified + @FieldModified + public void handleFieldModified(Event event) throws InvalidKeyException + { + if (log.isDebugEnabled()) log.debug("@FieldModified annotation found= ."); + Object modified =3D event.getSource(); + Fqn fqn =3D savedFqn.get(); + savedFqn.remove(); = + if (log.isDebugEnabled()) log.debug("Fqn is " + fqn); + + EntityId pojoEntityId =3D new PojoEntityId(fqn); + + TransactionContext ctx =3D new PojoTransactionContext(event); + + searchFactory.getWorker().performWork(new Work(modified, pojoEntityI= d.getDocumentId(), WorkType.DELETE), ctx); + searchFactory.getWorker().performWork(new Work(modified, pojoEntityI= d.getDocumentId(), WorkType.ADD), ctx); + + } + + + @ListModified + public void handleListModified(ListModifiedEvent event) throws InvalidK= eyException + { + if (log.isDebugEnabled()) log.debug("@ListModified annotation found.= "); + + if (log.isDebugEnabled()) log.debug("List size is " + event.getSourc= e().size()); + + + } + + @ArrayModified + public void handleArrayModified(ArrayModifiedEvent event) throws Invali= dKeyException + { + if (log.isDebugEnabled()) log.debug("@ArrayModified annotation found= ."); + + if (log.isDebugEnabled()) log.debug("Object array is " + event.getSo= urce().getClass()); + + + } + + @SetModified + public void handleSetModified(SetModifiedEvent event) throws InvalidKey= Exception + { + if (log.isDebugEnabled()) log.debug("@SetModified annotation found."= ); + + if (log.isDebugEnabled()) log.debug("Set size is " + event.getSource= ().size()); = + + } + + @MapModified + public void handleMapModified(MapModifiedEvent event) throws InvalidKey= Exception + { + if (log.isDebugEnabled()) log.debug("@MapModified annotation found."= ); + + if (log.isDebugEnabled()) log.debug("Set size is " + event.getSource= ().size()); + + if (log.isDebugEnabled()) log.debug("Where is the end of the thread?= "); + + + + } + + + @NodeCreated + @NodeRemoved + @NodeModified + public void logEvent(NodeEvent e) + { + if (log.isDebugEnabled()) log.debug("Detected event of type " + e.ge= tType() + " with Fqn " + e.getFqn()); + } } Modified: searchable/trunk/src/test/java/org/jboss/cache/search/QueryResult= IteratorImplTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIterat= orImplTest.java 2009-02-20 10:56:49 UTC (rev 7741) +++ searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIterat= orImplTest.java 2009-02-20 15:15:26 UTC (rev 7742) @@ -19,8 +19,8 @@ @Test(groups =3D "functional") public class QueryResultIteratorImplTest { - List ids; - Map dummyResults; + List ids; + Map dummyResults; QueryResultIterator iterator; int fetchSize =3D 1; = @@ -41,10 +41,10 @@ ids.add(new CacheEntityId(Fqn.fromString("/j"), "key10")); = // create some dummy data - dummyResults =3D new HashMap(); + dummyResults =3D new HashMap(); int counter =3D 0; = - for (CacheEntityId id : ids) + for (EntityId id : ids) { // for each cache entity ID, create a dummy result that will be r= eturned when loading it. dummyResults.put(id, "Result number " + counter++); @@ -191,7 +191,7 @@ iterator.first(); for (int i =3D 0; i < ids.size(); i++) { - System.out.println("Loop number count: - " + (i+1)); + System.out.println("Loop number count: - " + (i + 1)); Object expectedValue =3D dummyResults.get(ids.get(i)); assert iterator.hasNext(); // should have next as long as we are = less than the number of elements. assert expectedValue =3D=3D iterator.next(); // tests next() @@ -233,10 +233,10 @@ = public static class DummyEntityLoader extends CacheEntityLoader { - private List allKnownIds; - private Map dummyValues; + private List allKnownIds; + private Map dummyValues; = - public DummyEntityLoader(List allKnownIds, Map dummyValues) + public DummyEntityLoader(List allKnownIds, Map dummyValues) { // use a null as a cache since we won't ever need to refer to the= cache super(null); @@ -246,11 +246,11 @@ } = @Override - public List load(List ids) + public List load(List ids) { List resultsToReturn =3D new ArrayList(ids.size()= ); // iterate through the list of ids we are looking for - for (CacheEntityId id : ids) + for (EntityId id : ids) { resultsToReturn.add(dummyValues.get(id)); } @@ -259,7 +259,7 @@ } = @Override - public Object load(CacheEntityId id) + public Object load(EntityId id) { return dummyValues.get(id); } Modified: searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/Lo= calPOJOCacheTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJ= OCacheTest.java 2009-02-20 10:56:49 UTC (rev 7741) +++ searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJ= OCacheTest.java 2009-02-20 15:15:26 UTC (rev 7742) @@ -20,8 +20,7 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; = -import java.util.List; -import java.util.Iterator; +import java.util.*; = /** * Same as LocalCacheTest except that you will use a POJO Cache instead an= d use pojoCache.attach() ad pojoCache.detach() @@ -67,9 +66,9 @@ 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); +// pojo.attach("/a", person1); +// pojo.attach("/b", person2); +// pojo.attach("/c", person3); = = } @@ -90,9 +89,7 @@ = found =3D 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)); + assert found.size() =3D=3D 2; } = public void testMultipleResults() throws ParseException @@ -153,7 +150,7 @@ person4.setName("MightyGoat"); person4.setBlurb("Also eats grass"); = - pojo.attach(Fqn.fromString("/r/a/m/"), person4); + pojo.attach(Fqn.fromString("/d/"), person4); = luceneQuery =3D queryParser.parse("eats"); cacheQuery =3D searchableCache.createQuery(luceneQuery); @@ -173,22 +170,43 @@ found =3D cacheQuery.list(); = assert found.size() =3D=3D 2; - assert found.contains(person2); - assert found.contains(person3) : "This should still contain object p= erson3"; + assert found.contains(person3); + assert found.contains(person2) : "This should still contain object p= erson2"; = - pojo.detach("/a/b/d"); + pojo.detach("/b"); = luceneQuery =3D queryParser.parse("eats"); cacheQuery =3D searchableCache.createQuery(luceneQuery); found =3D cacheQuery.list(); = assert found.size() =3D=3D 1; - assert found.contains(person2); - assert !found.contains(person3) : "The search should not return pers= on3"; + assert found.contains(person3); + assert !found.contains(person2) : "The search should not return pers= on2"; = = } = + public void testListAdded() throws ParseException + { + List objectsToAdd =3D new ArrayList(); + + objectsToAdd.add(person1); + objectsToAdd.add(person2); + objectsToAdd.add(person3); + + pojo.attach(Fqn.fromString("/d"), objectsToAdd); + + queryParser =3D new QueryParser("blurb", new StandardAnalyzer()); + luceneQuery =3D queryParser.parse("eats"); + cacheQuery =3D searchableCache.createQuery(luceneQuery); + + found =3D cacheQuery.list(); + + System.out.println("Size of found is " + found.size()); + + System.out.println(pojo.find(Fqn.fromString("/d"))); + } + } = = Modified: searchable/trunk/src/test/resources/log4j.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- searchable/trunk/src/test/resources/log4j.xml 2009-02-20 10:56:49 UTC (= rev 7741) +++ searchable/trunk/src/test/resources/log4j.xml 2009-02-20 15:15:26 UTC (= rev 7742) @@ -63,7 +63,7 @@ = - + = --===============6006359105392420352==--