Author: navssurtani
Date: 2009-02-06 05:03:13 -0500 (Fri, 06 Feb 2009)
New Revision: 7656
Added:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/EntityId.java
searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java
searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCachePojoImpl.java
Modified:
searchable/trunk/
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/QueryResultIteratorImpl.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/SearchablePojoListener.java
Log:
Property changes on: searchable/trunk
___________________________________________________________________
Name: svn:ignore
+ jbosscache-searchable.iws
jbosscache-searchable.iml
jbosscache-searchable.ipr
test-output
out
org.jboss.cache.search.test.Person
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2009-02-05
17:34:33 UTC (rev 7655)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -30,48 +30,23 @@
* <p/>
* @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
*/
-public class CacheEntityId
+public class CacheEntityId extends PojoEntityId
{
- Fqn fqn;
String key;
- String documentId;
public CacheEntityId(String documentId)
{
- if(documentId == null) throw new NullPointerException("documentId is
null");
- this.documentId = documentId;
+ super(documentId);
}
public CacheEntityId(Fqn fqn, String key)
{
- if(fqn == null) throw new NullPointerException("Fqn is null");
+ super(fqn);
if(key == null) throw new NullPointerException("Key is null");
- this.fqn = fqn;
this.key = key;
}
/**
- * Gets the Fqn from the instance of CacheEntityId.
- *
- * @return Fqn from the instance of CacheEntityId.
- */
-
- public Fqn getFqn()
- {
- if (fqn != null) return fqn;
- if (documentId != null)
- {
- fqn = Transformer.getFqn(documentId);
- return fqn;
- }
-
- if(documentId == null)
- throw new IllegalArgumentException("docId is null");
-
- throw new IllegalArgumentException("Fqn is null");
- }
-
- /**
* Gets the key from the instance of CacheEntityId.
*
* @return Key from the instance of CacheEntityId.
@@ -105,4 +80,9 @@
return Transformer.generateId(fqn, key);
}
+
+ public Fqn getFqn()
+ {
+ throw new RuntimeException("implement me");
+ }
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2009-02-05
17:34:33 UTC (rev 7655)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -50,29 +50,35 @@
* @return List of objects loaded from the cache. The list returned will be exactly
the same size as the ids list passed in.
* @throws NullPointerException if ids is null.
*/
- public List<Object> load(List<CacheEntityId> ids)
+ public List<Object> load(List<EntityId> ids)
{
if (ids == null) throw new NullPointerException("ids are null");
List<Object> retVal = new ArrayList<Object>(ids.size());
- for (CacheEntityId id: ids)
+ for (EntityId id: ids)
{
- retVal.add( cache.get(id.getFqn(), id.getKey()) );
+ retVal.add( loadFromCache(id) );
if(log.isTraceEnabled()) log.trace("Created list of return values. Size is
" + retVal.size() );
}
return retVal;
}
+ protected Object loadFromCache(EntityId id)
+ {
+ CacheEntityId cei = (CacheEntityId) id;
+ return cache.get(cei.getFqn(), cei.getKey());
+ }
+
/**
* Takes a list of entity ids and gets them from the cache.
* @param id cache entity id to look up in the cache.
* @return the object from the cache, or null if one cannot be found.
* @throws NullPointerException if ids is null.
*/
- public Object load(CacheEntityId id)
+ public Object load(EntityId id)
{
if (id == null) throw new NullPointerException("id is null");
- return cache.get(id.getFqn(), id.getKey());
+ return loadFromCache(id);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2009-02-05
17:34:33 UTC (rev 7655)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -43,6 +43,7 @@
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.transform.ResultTransformer;
import org.jboss.cache.Cache;
+import org.jboss.cache.pojo.PojoCache;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@@ -63,36 +64,43 @@
public class CacheQueryImpl implements CacheQuery
{
// private Cache cache; - Removed on 11/07/2008, cache is assigned but never used.
Hence removed.
- private Class[] classes;
private Sort sort;
private Filter filter;
private Map<String, FullTextFilterImpl> filterDefinitions;
- private SearchFactoryImplementor searchFactory;
private Integer firstResult;
private Integer resultSize;
private Integer maxResults;
private static final Log log = LogFactory.getLog(CacheQueryImpl.class);
private boolean needClassFilterClause;
- private Query luceneQuery;
private String[] indexProjection;
private ResultTransformer resultTransformer;
CacheEntityLoader entityLoader;
- private Set<Class<?>> targetedEntities;
private Set<Class<?>> classesAndSubclasses;
private Set<String> idFieldNames;
private boolean allowFieldSelectionInProjection = true;
+ // Protected fields for CacheQueryPojoImpl to see.
+ protected Query luceneQuery;
+ protected SearchFactoryImplementor searchFactory;
+ protected Set<Class<?>> targetedEntities;
+ protected Cache cache;
+ protected Class[] classes;
+
+
+
+
public CacheQueryImpl(Query luceneQuery, SearchFactoryImplementor searchFactory, Cache
cache, Class... classes)
{
this.luceneQuery = luceneQuery;
-// this.cache = cache;
+ this.cache = cache;
entityLoader = new CacheEntityLoader(cache);
this.searchFactory = searchFactory;
- this.targetedEntities = this.searchFactory.getIndexedTypesPolymorphic( classes );
+ this.targetedEntities = this.searchFactory.getIndexedTypesPolymorphic(classes);
this.classes = classes;
}
+
/**
* Takes in a lucene filter and sets it to the filter field in the class.
*
@@ -224,7 +232,7 @@
public QueryResultIterator iterator(int fetchSize) throws HibernateException
{
- List<CacheEntityId> ids = null;
+ List<EntityId> ids = null;
IndexSearcher searcher = buildSearcher(searchFactory);
if (searcher == null)
{
@@ -237,13 +245,13 @@
int first = first();
int max = max(first, queryHits.totalHits);
int size = max - first + 1 < 0 ? 0 : max - first + 1;
- ids = new ArrayList<CacheEntityId>(size);
+ ids = new ArrayList<EntityId>(size);
DocumentExtractor extractor = new DocumentExtractor(queryHits, searchFactory,
indexProjection, idFieldNames, allowFieldSelectionInProjection);
for (int index = first; index <= max; index++)
{
String documentId = (String) extractor.extract(index).id;
- CacheEntityId id = new CacheEntityId(documentId);
+ EntityId id = createCacheEntityId(documentId);
ids.add(id);
}
@@ -315,13 +323,13 @@
int size = max - first + 1 < 0 ? 0 : max - first + 1;
- List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
DocumentExtractor extractor = new DocumentExtractor(queryHits, searchFactory,
indexProjection, idFieldNames, allowFieldSelectionInProjection);
+ List<EntityId> ids = new ArrayList<EntityId>(size);
for (int index = first; index <= max; index++)
{
String documentId = (String) extractor.extract(index).id;
- CacheEntityId id = new CacheEntityId(documentId);
+ EntityId id = createCacheEntityId(documentId);
ids.add(id);
}
@@ -350,7 +358,12 @@
}
+ protected EntityId createCacheEntityId(String docId)
+ {
+ return new CacheEntityId(docId);
+ }
+
private int max(int first, int totalHits)
{
if (maxResults == null)
@@ -544,7 +557,6 @@
}
-
private org.apache.lucene.search.Query
filterQueryByClasses(org.apache.lucene.search.Query luceneQuery)
{
if (!needClassFilterClause)
Added: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryPojoImpl.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -0,0 +1,33 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.Cache;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.apache.lucene.search.Query;
+
+/**
+ * @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
+ */
+public class CacheQueryPojoImpl extends CacheQueryImpl
+{
+
+ private PojoCache pojo;
+
+ public CacheQueryPojoImpl(Query luceneQuery, SearchFactoryImplementor searchFactory,
PojoCache pojo, Class... classes)
+ {
+ super (luceneQuery, searchFactory, pojo.getCache(), classes);
+
+ this.pojo = pojo;
+
+ // Create a pojo entity loader instead of a cache entity loader since we are
dealing with a pojo cache
+ entityLoader = new PojoEntityLoader(pojo);
+
+ }
+
+ protected EntityId createCacheEntityId(String docId)
+ {
+ return new PojoEntityId(docId);
+ }
+
+
+}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/EntityId.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/EntityId.java
(rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/EntityId.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -0,0 +1,13 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Fqn;
+
+/**
+ * @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
+ */
+public interface EntityId
+{
+ Fqn getFqn();
+
+ String getDocumentId() throws InvalidKeyException;
+}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java
(rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityId.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -0,0 +1,65 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Fqn;
+
+/**
+ * This class is used to get fqns, keys and documentId's by calling methods on
{@link org.jboss.cache.search.Transformer}
+ * <p/>
+ *
+ * @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
+ */
+public class PojoEntityId implements EntityId
+{
+ // Contains documentId and fqn fields. Subclassed by CacheEntityId.
+ protected String documentId;
+ protected Fqn fqn;
+
+ public PojoEntityId (Fqn fqn)
+ {
+ if (fqn == null) throw new NullPointerException("Fqn is null.");
+ this.fqn = fqn;
+ documentId = fqn.toString();
+
+ }
+
+ public PojoEntityId (String documentId)
+ {
+ if (documentId == null) throw new NullPointerException("doc ID is
null.");
+ this.documentId = documentId;
+ }
+
+ /**
+ * Gets the Fqn from the instance of CacheEntityId.
+ *
+ * @return Fqn from the instance of CacheEntityId.
+ */
+
+ public Fqn getFqn()
+ {
+ if (fqn != null) return fqn;
+ if (documentId != null)
+ {
+ fqn = Fqn.fromString(documentId);
+ return fqn;
+ }
+ throw new IllegalArgumentException("docId is null");
+ }
+
+ /**
+ * Gets a documentId String from an Fqn and key combination.
+ *
+ * @return documentId String.
+ */
+
+
+ public String getDocumentId() throws InvalidKeyException
+ {
+ if (fqn == null)
+ {
+ throw new IllegalArgumentException("Either your key or fqn is null. Please
check again.");
+ }
+
+ return fqn.toString();
+ }
+
+}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.java
(rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoEntityLoader.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -0,0 +1,23 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.pojo.PojoCache;
+
+/**
+ * @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
+ */
+public class PojoEntityLoader extends CacheEntityLoader
+{
+ PojoCache pojoCache;
+
+ public PojoEntityLoader(PojoCache pojoCache)
+ {
+ super(pojoCache.getCache());
+ this.pojoCache = pojoCache;
+ }
+
+ protected Object loadFromCache(CacheEntityId id)
+ {
+ return pojoCache.find(id.getFqn());
+ }
+}
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java 2009-02-05
17:34:33 UTC (rev 7655)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -42,7 +42,7 @@
{
private int index = 0;
//private final int size;
- private List<CacheEntityId> idList;
+ private List<EntityId> idList;
private CacheEntityLoader entityLoader;
private int lowerLimit = 0;
private int upperLimit = 0;
@@ -52,7 +52,7 @@
private static final Log log = LogFactory.getLog(QueryResultIteratorImpl.class);
- public QueryResultIteratorImpl(List<CacheEntityId> idList, CacheEntityLoader
entityLoader, int fetchSize)
+ public QueryResultIteratorImpl(List<EntityId> idList, CacheEntityLoader
entityLoader, int fetchSize)
{
if (fetchSize < 1)
{
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2009-02-05
17:34:33 UTC (rev 7655)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -119,11 +119,9 @@
{
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.");
@@ -146,7 +144,7 @@
pojo.addListener(pojoListener);
pojo.getCache().addCacheListener(pojoListener);
- SearchableCache sc = new SearchableCacheImpl(coreCache, searchFactory);
+ SearchableCache sc = new SearchableCachePojoImpl(pojo, 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 2009-02-05
17:34:33 UTC (rev 7655)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -32,6 +32,7 @@
import org.jboss.cache.Node;
import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.Region;
+import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.config.Configuration;
import org.jgroups.Address;
@@ -49,11 +50,12 @@
public class SearchableCacheImpl<K, V> implements SearchableCache<K, V>
{
// this is the ACTUAL cache. that does all the work.
- private Cache<K, V> cache;
+ // protected fields for Pojo subclass
+ protected Cache<K, V> cache;
+ protected SearchFactoryImplementor searchFactory;
- private SearchFactoryImplementor searchFactory;
-
+
public SearchableCacheImpl(Cache<K, V> cache, SearchFactoryImplementor
searchFactory)
{
if (cache == null) throw new NullPointerException("Cache is null");
@@ -62,6 +64,8 @@
this.searchFactory = searchFactory;
}
+
+
/**
* Creates a CacheQuery object from a Lucene Query and a class array.
*
Added: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCachePojoImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCachePojoImpl.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCachePojoImpl.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -0,0 +1,34 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.Cache;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.apache.lucene.search.Query;
+
+/**
+ * @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
+ */
+public class SearchableCachePojoImpl extends SearchableCacheImpl
+{
+
+ private PojoCache pojo;
+
+ /**
+ * Pojo cache implementation constructor.
+ *
+ * @param pojo
+ * @param searchFactory
+ */
+
+ public SearchableCachePojoImpl(PojoCache pojo, SearchFactoryImplementor
searchFactory)
+ {
+ super(pojo.getCache(), searchFactory);
+ if (pojo == null) throw new NullPointerException("pojo is null");
+ this.pojo = pojo;
+ }
+
+ public CacheQuery createQuery(Query luceneQuery, Class... classes)
+ {
+ return new CacheQueryPojoImpl(luceneQuery, searchFactory, pojo, 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-02-05
17:34:33 UTC (rev 7655)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java 2009-02-06
10:03:13 UTC (rev 7656)
@@ -69,15 +69,15 @@
{
if (!nme.isPre()) return;
Fqn f = nme.getFqn();
- if(log.isDebugEnabled()) log.debug("Node modified called for Fqn " + f);
+ System.out.println("Node modified called for Fqn " + f);
if (InternalHelper.isInternalNode(f))
{
- if(log.isDebugEnabled()) log.debug("Is internal and I dont care");
+ System.out.println("Is internal and I dont care");
}
else
{
savedFqn.set(f);
- if(log.isDebugEnabled()) log.debug("Saved Fqn to ThreadLocal.");
+ System.out.println("Saved Fqn to ThreadLocal.");
}
}
@@ -86,15 +86,15 @@
{
if (!nce.isPre()) return;
Fqn f = nce.getFqn();
- if(log.isDebugEnabled()) log.debug("Node kreated called for Fqn " + f);
+ System.out.println("Node kreated called for Fqn " + f);
if (InternalHelper.isInternalNode(f))
{
- if(log.isDebugEnabled()) log.debug("Is internal and I dont care");
+ System.out.println("Is internal and I dont care");
}
else
{
savedFqn.set(f);
- if(log.isDebugEnabled()) log.debug("savedFqn.set() called");
+ System.out.println("savedFqn.set() called");
}
}