Author: navssurtani
Date: 2008-06-24 06:51:36 -0400 (Tue, 24 Jun 2008)
New Revision: 6011
Added:
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/SearchResultIterator.java
Removed:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
Modified:
searchable/trunk/pom.xml
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.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/test/java/org/jboss/cache/search/BlackBoxTest.java
Log:
Created more classes
Modified: searchable/trunk/pom.xml
===================================================================
--- searchable/trunk/pom.xml 2008-06-23 17:38:03 UTC (rev 6010)
+++ searchable/trunk/pom.xml 2008-06-24 10:51:36 UTC (rev 6011)
@@ -27,13 +27,13 @@
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
- <version>2.2.0.CR1</version>
+ <version>2.2.0.CR4</version>
</dependency>
<dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-search</artifactId>
- <version>3.0.1.GA</version>
+ <groupId>org.hibernate.sandbox</groupId>
+ <artifactId>hibernate-search-gsoc</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
@@ -41,6 +41,13 @@
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.2</version>
+ </dependency>
+
</dependencies>
<build>
<plugins>
Added: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
(rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -0,0 +1,58 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Fqn;
+
+/**
+ @author Navin Surtani - navin(a)surtani.org
+ */
+public class CacheEntityId
+{
+ Fqn fqn;
+ String key;
+ String documentId;
+
+ public CacheEntityId(String documentId)
+ {
+ this.documentId = documentId;
+ }
+
+ public CacheEntityId(Fqn fqn, String key)
+ {
+ this.fqn = fqn;
+ this.key = key;
+ }
+
+ public Fqn getFqn()
+ {
+ if (fqn != null) return fqn;
+ if (documentId != null)
+ {
+ fqn = Transformer.getFqn(documentId);
+ return fqn;
+ }
+ throw new IllegalArgumentException("At least fqn or documentId must be set to
call this method");
+ }
+
+ public String getKey()
+ {
+ if (key != null) return key;
+ if (documentId != null)
+ {
+ key = Transformer.getKey(documentId);
+ return key;
+ }
+
+ throw new IllegalArgumentException("At least key or documentId must be set to
call this method");
+ }
+
+ public String getDocumentId()
+ {
+ if (key != null || fqn != null)
+ {
+
+ throw new IllegalArgumentException("Either your key or fqn is null. Please
check again.");
+ }
+
+ return Transformer.generateId(fqn, key);
+ }
+}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -0,0 +1,47 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Cache;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class CacheEntityLoader
+{
+ Cache cache;
+
+ public CacheEntityLoader(Cache cache)
+ {
+ this.cache = cache;
+ }
+
+ /**
+ * Takes a list of entity ids and gets them from the cache.
+ * @param ids
+ * @return
+ */
+ public List<Object> load(List<CacheEntityId> ids)
+ {
+ List<Object> retVal = new ArrayList<Object>(ids.size());
+
+ for (CacheEntityId id: ids)
+ {
+ retVal.add( cache.get(id.getFqn(), id.getKey()) );
+ }
+ return retVal;
+ }
+
+ /**
+ * Takes a list of entity ids and gets them from the cache.
+ * @param id
+ * @return
+ */
+ public Object load(CacheEntityId id)
+ {
+ return cache.get(id.getFqn(), id.getKey());
+ }
+
+
+}
Deleted: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-23
17:38:03 UTC (rev 6010)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -1,70 +0,0 @@
-package org.jboss.cache.search;
-
-import org.apache.lucene.search.Filter;
-import org.apache.lucene.search.Sort;
-import org.hibernate.search.FullTextFilter;
-
-/**
-@author Navin Surtani - navin(a)surtani.org
-
-
-*/
-// TODO: Can we remove this?
-public interface CacheQuery
-{
- /**
- * Allows to let lucene sort the results. This is useful when you have
- * additional sort requirements on top of the default lucene ranking.
- * Without lucene sorting you would have to retrieve the full result set and
- * order the hibernate objects.
- *
- * @param sort The lucene sort object.
- * @return this for method chaining
- */
- CacheQuery setSort(Sort sort);
-
- /**
- * Allows to use lucene filters.
- * A preferred way is to use the @FullTextFilterDef approach
- *
- * @param filter The lucene filter.
- * @return this for method chaining
- */
- CacheQuery setFilter(Filter filter);
-
- /**
- * Returns the number of hits for this search
- * <p/>
- * Caution:
- * The number of results might be slightly different from
- * <code>list().size()</code> because list() if the index is
- * not in sync with the database at the time of query.
- */
- int getResultSize();
-
- /**
- * Enable a given filter by its name. Returns a FullTextFilter object that allows
filter parameter injection
- */
- FullTextFilter enableFullTextFilter(String name);
-
- /**
- * Disable a given filter by its name
- */
- void disableFullTextFilter(String name);
-
- /**
- * {link:Query#setFirstResult}
- */
- CacheQuery setFirstResult(int firstResult);
-
- /**
- * {link:Query#setMaxResults}
- */
- CacheQuery setMaxResults(int maxResults);
-
- /**
- * Defines scrollable result fetch size as well as the JDBC fetch size
- */
- CacheQuery setFetchSize(int i);
-
-}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-23
17:38:03 UTC (rev 6010)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -8,18 +8,20 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Filter;
import org.hibernate.*;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.impl.AbstractQueryImpl;
+import org.hibernate.impl.CriteriaImpl;
import org.hibernate.type.Type;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.search.FullTextFilter;
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.SearchException;
-import org.hibernate.search.engine.DocumentBuilder;
-import org.hibernate.search.engine.FilterDef;
-import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.engine.*;
import org.hibernate.search.filter.ChainedFilter;
import org.hibernate.search.filter.FilterKey;
import org.hibernate.search.impl.SearchFactoryImpl;
import org.hibernate.search.query.FullTextFilterImpl;
+import org.hibernate.search.query.IteratorImpl;
import org.hibernate.search.reader.ReaderProvider;
import static org.hibernate.search.reader.ReaderProviderHelper.getIndexReaders;
import org.hibernate.search.store.DirectoryProvider;
@@ -34,10 +36,10 @@
/**
* @author Navin Surtani - navin(a)surtani.org
- *
- * Implementation class of the FullTextQuery interface in Hibernate Search.
+ * <p/>
+ * Implementation class of the FullTextQuery interface in Hibernate Search.
*/
-public class CacheQueryImpl implements FullTextQuery
+public class CacheQueryImpl extends AbstractQueryImpl implements FullTextQuery
{
private Cache cache;
private Class[] classes;
@@ -53,27 +55,36 @@
private boolean needClassFilterClause;
private Query luceneQuery;
private int fetchSize;
+ private String[] indexProjection;
+ private ResultTransformer resultTransformer;
+ private Criteria criteria;
+ CacheEntityLoader entityLoader;
public CacheQueryImpl(Query luceneQuery, SearchFactoryImpl searchFactory, Cache
cache)
{
+ super(luceneQuery.toString(), null, null, null);
this.luceneQuery = luceneQuery;
this.cache = cache;
+ entityLoader = new CacheEntityLoader(cache);
this.searchFactory = searchFactory;
}
public CacheQueryImpl(Query luceneQuery, SearchFactoryImpl searchFactory, Cache cache,
Class... classes)
{
- this.luceneQuery = luceneQuery;
- this.cache = cache;
+ this(luceneQuery, searchFactory, cache);
this.classes = classes;
- this.searchFactory = searchFactory;
+ }
+ public FullTextQuery setResultTransformer(ResultTransformer transformer)
+ {
+ // TODO: Do we need to impl this? What does HS do?
+ return null;
}
+
/**
- *Allows to let lucene sort the results.
+ * Allows to let lucene sort the results.
*
- *
* @param sort
* @return
*/
@@ -96,41 +107,32 @@
}
/**
- *
* @return The result size of the query.
*/
public int getResultSize()
{
- if (resultSize == null)
- {
+ if (resultSize == null) {
//get result size without object initialization
IndexSearcher searcher = buildSearcher(searchFactory);
- if (searcher == null)
- {
+ if (searcher == null) {
resultSize = 0;
}
- else
- {
+ else {
Hits hits;
- try
- {
+ try {
hits = getHits(searcher);
resultSize = hits.length();
}
- catch (IOException e)
- {
+ catch (IOException e) {
throw new HibernateException("Unable to query Lucene index",
e);
}
- finally
- {
+ finally {
//searcher cannot be null
- try
- {
+ try {
closeSearcher(searcher, searchFactory.getReaderProvider());
//searchFactoryImplementor.getReaderProvider().closeReader(
searcher.getIndexReader() );
}
- catch (SearchException e)
- {
+ catch (SearchException e) {
log.warn("Unable to properly close searcher during lucene query:
" + e);
}
}
@@ -140,19 +142,18 @@
}
/**
- * Defines the Database Query used to load the Lucene results
- *
- * @param criteria
- * @return
+ * This method is not supported in JBossCache Searchable and should not be called.
*/
+
public FullTextQuery setCriteriaQuery(Criteria criteria)
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ throw new UnsupportedOperationException("This method is not supported in
JBossCache Searchable");
}
/**
* Defines the Lucene field names projected and returned in a query result Each field
is converted back to it's object representation,
* an Object[] being returned for each "row" (similar to an HQL or a
Criteria API projection).
+ *
* @param strings
* @return
*/
@@ -166,8 +167,7 @@
{
Set<IndexReader> indexReaders = getIndexReaders(searcher);
- for (IndexReader indexReader : indexReaders)
- {
+ for (IndexReader indexReader : indexReaders) {
readerProvider.closeReader(indexReader);
}
}
@@ -175,13 +175,12 @@
/**
* Enable a given filter by its name.
*
- * @param name
+ * @param name
* @return
*/
public FullTextFilter enableFullTextFilter(String name)
{
- if (filterDefinitions == null)
- {
+ if (filterDefinitions == null) {
filterDefinitions = new HashMap<String, FullTextFilterImpl>();
}
FullTextFilterImpl filterDefinition = filterDefinitions.get(name);
@@ -190,8 +189,7 @@
filterDefinition = new FullTextFilterImpl();
filterDefinition.setName(name);
FilterDef filterDef = searchFactory.getFilterDefinition(name);
- if (filterDef == null)
- {
+ if (filterDef == null) {
throw new SearchException("Unkown @FullTextFilter: " + name);
}
filterDefinitions.put(name, filterDefinition);
@@ -209,727 +207,248 @@
}
/**
- *
+ * Sets the the result of the given integer value to the first result.
+ *
* @param firstResult
* @return
*/
public FullTextQuery setFirstResult(int firstResult)
{
- if (firstResult < 0)
- {
+ if (firstResult < 0) {
throw new IllegalArgumentException("'first' pagination parameter
less than 0");
}
this.firstResult = firstResult;
return this;
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setReadOnly(boolean b)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setCacheable(boolean b)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setCacheRegion(String s)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setTimeout(int i)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public String getQueryString()
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public Type[] getReturnTypes() throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public String[] getReturnAliases() throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public String[] getNamedParameters() throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
public Iterator iterate() throws HibernateException
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ List list;
+ IndexSearcher searcher = buildSearcher(searchFactory);
+ if (searcher == null) {
+ throw new NullPointerException("IndexSearcher instance is null.");
+ }
- public ScrollableResults scroll() throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ try {
+ Hits hits = getHits(searcher);
+ 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);
- public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ DocumentExtractor extractor = new DocumentExtractor(searchFactory,
indexProjection);
+ for (int index = first; index <= max; index++) {
+ String documentId = (String) extractor.extract(hits, index).id;
+ CacheEntityId id = new CacheEntityId(documentId);
+ ids.add(id);
+ }
- public List list() throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ list = entityLoader.load(ids);
+ }
+ catch (IOException e) {
+ throw new HibernateException("Unable to query Lucene index", e);
- public Object uniqueResult() throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public int executeUpdate() throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- public FullTextQuery setMaxResults(int maxResults)
- {
- if (maxResults < 0)
- {
- throw new IllegalArgumentException("'max' pagination parameter less
than 0");
}
- this.maxResults = maxResults;
- return this;
- }
- public FullTextQuery setFetchSize(int fetchSize)
- {
- if (fetchSize <= 0)
- {
- throw new IllegalArgumentException("'fetch size' parameter less
than or equals to 0");
+ finally {
+ try {
+ closeSearcher(searcher, searchFactory.getReaderProvider());
+ }
+ catch (SearchException e) {
+ log.warn("Unable to properly close searcher during lucene query: "
+ getQueryString(), e);
+ }
}
- this.fetchSize = fetchSize;
- return this;
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setLockMode(String s, LockMode lockMode)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ return new SearchResultIterator(list, entityLoader);
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setComment(String s)
+ public ScrollableResults scroll() throws HibernateException
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ IndexSearcher searcher = buildSearcher(searchFactory);
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ Hits hits;
- public org.hibernate.Query setFlushMode(FlushMode flushMode)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ try {
+ hits = getHits(searcher);
+ int first = first();
+ int max = max(first, hits);
+ int size = max - first + 1 < 0 ? 0 : max - first + 1;
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ DocumentExtractor extractor = new DocumentExtractor(searchFactory,
indexProjection);
- public org.hibernate.Query setCacheMode(CacheMode cacheMode)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ for (int index = first; index <= max; index++) {
- public org.hibernate.Query setParameter(int i, Object o, Type type)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ String documentId = (String) extractor.extract(hits, index).id;
+ CacheEntityId id = new CacheEntityId(documentId);
+ ids.add(id);
+ }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ List<Object> list = entityLoader.load(ids);
+
+ }
- public org.hibernate.Query setParameter(String s, Object o, Type type)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ catch (IOException e) {
+ throw new HibernateException("Unable to query Lucene index", e);
+ }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setParameter(int i, Object o) throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ return null;
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setParameter(String s, Object o) throws HibernateException
+ public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ return null; // TODO: Implement me!!!
}
/**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
+ * Returns a the results from the query as a List object.
*
+ * @return List of results.
+ * @throws HibernateException
*/
-
- public org.hibernate.Query setParameters(Object[] objects, Type[] types) throws
HibernateException
+ public List<Object> list() throws HibernateException
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ IndexSearcher searcher = buildSearcher(searchFactory);
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ if (searcher == null) return new ArrayList(0);
- public org.hibernate.Query setParameterList(String s, Collection collection, Type
type) throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ Hits hits;
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ try {
+ hits = getHits(searcher);
+ int first = first();
+ int max = max(first, hits);
- public org.hibernate.Query setParameterList(String s, Collection collection) throws
HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ int size = max - first + 1 < 0 ? 0 : max - first + 1;
+ List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
+ DocumentExtractor extractor = new DocumentExtractor(searchFactory,
indexProjection);
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ for (int index = first; index <= max; index++) {
+ String documentId = (String) extractor.extract(hits, index).id;
+ CacheEntityId id = new CacheEntityId(documentId);
+ ids.add(id);
+ }
- public org.hibernate.Query setParameterList(String s, Object[] objects, Type type)
throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ List<Object> list = entityLoader.load(ids);
+ if (resultTransformer == null) {
+ return list;
+ }
+ else {
+ return resultTransformer.transformList(list);
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ }
- public org.hibernate.Query setParameterList(String s, Object[] objects) throws
HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
+ }
+ catch (IOException e) {
+ throw new HibernateException("Unable to query Lucene index", e);
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+ }
+ finally {
+ try {
+ closeSearcher(searcher, searchFactory.getReaderProvider());
+ }
+ catch (SearchException e) {
+ log.warn("Unable to properly close searcher during lucene query: "
+ getQueryString(), e);
+ }
+ }
- public org.hibernate.Query setProperties(Object o) throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
+// private Loader getLoader(Session session)
+// {
+// if (indexProjection != null) {
+// ProjectionLoader loader = new ProjectionLoader();
+// loader.init(session, searchFactory, resultTransformer, indexProjection);
+// return loader;
+// }
+// if (criteria != null) {
+// if (classes.length > 1) throw new SearchException("Cannot mix criteria
and multiple entity types");
+// if (criteria instanceof CriteriaImpl) {
+// String targetEntity = ((CriteriaImpl) criteria).getEntityOrClassName();
+// if (classes.length == 1 &&
!classes[0].getName().equals(targetEntity)) {
+// throw new SearchException("Criteria query entity should match query
entity");
+// }
+// else {
+// try {
+// Class entityType = ReflectHelper.classForName(targetEntity);
+// classes = new Class[]{entityType};
+// }
+// catch (ClassNotFoundException e) {
+// throw new SearchException("Unable to load entity class from
criteria: " + targetEntity, e);
+// }
+// }
+// }
+// QueryLoader loader = new QueryLoader();
+// loader.init(session, searchFactory);
+// loader.setEntityType(classes[0]);
+// loader.setCriteria(criteria);
+// return loader;
+// }
+// else if (classes.length == 1) {
+// QueryLoader loader = new QueryLoader();
+// loader.init(session, searchFactory);
+// loader.setEntityType(classes[0]);
+// return loader;
+// }
+// else {
+// final ObjectLoader objectLoader = new ObjectLoader();
+// objectLoader.init(session, searchFactory);
+// return objectLoader;
+// }
+// }
- public org.hibernate.Query setProperties(Map map) throws HibernateException
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setString(int i, String s)
+ private int max(int first, Hits hits)
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ return maxResults == null ?
+ hits.length() - 1 :
+ maxResults + first < hits.length() ?
+ first + maxResults - 1 :
+ hits.length() - 1;
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setCharacter(int i, char c)
+ private int first()
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ return firstResult != null ?
+ firstResult :
+ 0;
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setBoolean(int i, boolean b)
+ public int executeUpdate() throws HibernateException
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ throw new UnsupportedOperationException(" This method is not supported in
JBossCache Searchable");
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setByte(int i, byte b)
+ public FullTextQuery setMaxResults(int maxResults)
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ if (maxResults < 0) {
+ throw new IllegalArgumentException("'max' pagination parameter less
than 0");
+ }
+ this.maxResults = maxResults;
+ return this;
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setShort(int i, short i1)
+ public FullTextQuery setFetchSize(int fetchSize)
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ if (fetchSize <= 0) {
+ throw new IllegalArgumentException("'fetch size' parameter less
than or equals to 0");
+ }
+ this.fetchSize = fetchSize;
+ return this;
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setInteger(int i, int i1)
+ public org.hibernate.Query setLockMode(String alias, LockMode lockMode)
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ throw new UnsupportedOperationException(" This method is not supported in
JBossCache Searchable");
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setLong(int i, long l)
+ protected Map getLockModes()
{
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
+ throw new UnsupportedOperationException(" This method is not supported in
JBossCache Searchable");
}
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setFloat(int i, float v)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setDouble(int i, double v)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setBinary(int i, byte[] bytes)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setText(int i, String s)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setSerializable(int i, Serializable serializable)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setLocale(int i, Locale locale)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setBigDecimal(int i, BigDecimal bigDecimal)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setBigInteger(int i, BigInteger bigInteger)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setDate(int i, Date date)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setTime(int i, Date date)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setTimestamp(int i, Date date)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setCalendar(int i, Calendar calendar)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setCalendarDate(int i, Calendar calendar)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setString(String s, String s1)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setCharacter(String s, char c)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setBoolean(String s, boolean b)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setByte(String s, byte b)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
-
- public org.hibernate.Query setShort(String s, short i)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setInteger(String s, int i)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setLong(String s, long l)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- public org.hibernate.Query setFloat(String s, float v)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setDouble(String s, double v)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setBinary(String s, byte[] bytes)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setText(String s, String s1)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setSerializable(String s, Serializable serializable)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setLocale(String s, Locale locale)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setBigDecimal(String s, BigDecimal bigDecimal)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setBigInteger(String s, BigInteger bigInteger)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setDate(String s, Date date)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setTime(String s, Date date)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setTimestamp(String s, Date date)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setCalendar(String s, Calendar calendar)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setCalendarDate(String s, Calendar calendar)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setEntity(int i, Object o)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public org.hibernate.Query setEntity(String s, Object o)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
- /**
- * This method is not supported in JBossCache Searchable and hence should not be
called.
- *
- */
- public FullTextQuery setResultTransformer(ResultTransformer resultTransformer)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
private IndexSearcher buildSearcher(SearchFactoryImplementor
searchFactoryImplementor)
{
Map<Class, DocumentBuilder<Object>> builders =
searchFactoryImplementor.getDocumentBuilders();
@@ -937,29 +456,24 @@
Similarity searcherSimilarity = null;
- if (classes == null || classes.length == 0)
- {
+ if (classes == null || classes.length == 0) {
//no class means all classes
- for (DocumentBuilder builder : builders.values())
- {
+ for (DocumentBuilder builder : builders.values()) {
searcherSimilarity = checkSimilarity(searcherSimilarity, builder);
final DirectoryProvider[] directoryProviders =
builder.getDirectoryProviderSelectionStrategy().getDirectoryProvidersForAllShards();
populateDirectories(directories, directoryProviders,
searchFactoryImplementor);
}
classesAndSubclasses = null;
}
- else
- {
+ else {
Set<Class> involvedClasses = new HashSet<Class>(classes.length);
Collections.addAll(involvedClasses, classes);
- for (Class clazz : classes)
- {
+ for (Class clazz : classes) {
DocumentBuilder builder = builders.get(clazz);
if (builder != null) involvedClasses.addAll(builder.getMappedSubclasses());
}
- for (Class clazz : involvedClasses)
- {
+ for (Class clazz : involvedClasses) {
DocumentBuilder builder = builders.get(clazz);
if (builder == null)
throw new HibernateException("Not a mapped entity (don't forget
to add @Indexed): " + clazz);
@@ -973,19 +487,14 @@
//compute optimization needClassFilterClause
//if at least one DP contains one class that is not part of the targeted
classesAndSubclasses we can't optimize
- if (classesAndSubclasses != null)
- {
- for (DirectoryProvider dp : directories)
- {
+ if (classesAndSubclasses != null) {
+ for (DirectoryProvider dp : directories) {
final Set<Class> classesInDirectoryProvider =
searchFactoryImplementor.getClassesInDirectoryProvider(dp);
// if a DP contains only one class, we know for sure it's part of
classesAndSubclasses
- if (classesInDirectoryProvider.size() > 1)
- {
+ if (classesInDirectoryProvider.size() > 1) {
//risk of needClassFilterClause
- for (Class clazz : classesInDirectoryProvider)
- {
- if (!classesAndSubclasses.contains(clazz))
- {
+ for (Class clazz : classesInDirectoryProvider) {
+ if (!classesAndSubclasses.contains(clazz)) {
this.needClassFilterClause = true;
break;
}
@@ -1004,12 +513,10 @@
private Similarity checkSimilarity(Similarity similarity, DocumentBuilder builder)
{
- if (similarity == null)
- {
+ if (similarity == null) {
similarity = builder.getSimilarity();
}
- else if (!similarity.getClass().equals(builder.getSimilarity().getClass()))
- {
+ else if (!similarity.getClass().equals(builder.getSimilarity().getClass())) {
throw new HibernateException("Cannot perform search on two entities with
differing Similarity implementations (" + similarity.getClass().getName() + "
& " + builder.getSimilarity().getClass().getName() + ")");
}
@@ -1019,10 +526,8 @@
private void populateDirectories(List<DirectoryProvider> directories,
DirectoryProvider[] directoryProviders,
SearchFactoryImplementor searchFactoryImplementor)
{
- for (DirectoryProvider provider : directoryProviders)
- {
- if (!directories.contains(provider))
- {
+ for (DirectoryProvider provider : directoryProviders) {
+ if (!directories.contains(provider)) {
directories.add(provider);
}
}
@@ -1045,19 +550,16 @@
private org.apache.lucene.search.Query
filterQueryByClasses(org.apache.lucene.search.Query luceneQuery)
{
- if (!needClassFilterClause)
- {
+ if (!needClassFilterClause) {
return luceneQuery;
}
- else
- {
+ else {
//A query filter is more practical than a manual class filtering post query (esp
on scrollable resultsets)
//it also probably minimise the memory footprint
BooleanQuery classFilter = new BooleanQuery();
//annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
classFilter.setBoost(0);
- for (Class clazz : classesAndSubclasses)
- {
+ for (Class clazz : classesAndSubclasses) {
Term t = new Term(DocumentBuilder.CLASS_FIELDNAME, clazz.getName());
TermQuery termQuery = new TermQuery(t);
classFilter.add(termQuery, BooleanClause.Occur.SHOULD);
@@ -1071,35 +573,27 @@
private void buildFilters()
{
- if (filterDefinitions != null && filterDefinitions.size() > 0)
- {
+ if (filterDefinitions != null && filterDefinitions.size() > 0) {
ChainedFilter chainedFilter = new ChainedFilter();
- for (FullTextFilterImpl filterDefinition : filterDefinitions.values())
- {
+ for (FullTextFilterImpl filterDefinition : filterDefinitions.values()) {
FilterDef def =
searchFactory.getFilterDefinition(filterDefinition.getName());
Class implClass = def.getImpl();
Object instance;
- try
- {
+ try {
instance = implClass.newInstance();
}
- catch (Exception e)
- {
+ catch (Exception e) {
throw new SearchException("Unable to create @FullTextFilterDef:
" + def.getImpl(), e);
}
- for (Map.Entry<String, Object> entry :
filterDefinition.getParameters().entrySet())
- {
+ for (Map.Entry<String, Object> entry :
filterDefinition.getParameters().entrySet()) {
def.invoke(entry.getKey(), instance, entry.getValue());
}
- if (def.isCache() && def.getKeyMethod() == null &&
filterDefinition.getParameters().size() > 0)
- {
+ if (def.isCache() && def.getKeyMethod() == null &&
filterDefinition.getParameters().size() > 0) {
throw new SearchException("Filter with parameters and no @Key method:
" + filterDefinition.getName());
}
FilterKey key = null;
- if (def.isCache())
- {
- if (def.getKeyMethod() == null)
- {
+ if (def.isCache()) {
+ if (def.getKeyMethod() == null) {
key = new FilterKey()
{
public int hashCode()
@@ -1115,68 +609,54 @@
}
};
}
- else
- {
- try
- {
+ else {
+ try {
key = (FilterKey) def.getKeyMethod().invoke(instance);
}
- catch (IllegalAccessException e)
- {
+ 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)
- {
+ 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)
- {
+ 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;
- if (filter == null)
- {
- if (def.getFactoryMethod() != null)
- {
- try
- {
+ searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
+ null;
+ if (filter == null) {
+ if (def.getFactoryMethod() != null) {
+ try {
filter = (Filter) def.getFactoryMethod().invoke(instance);
}
- catch (IllegalAccessException e)
- {
+ 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)
- {
+ 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)
- {
+ 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
- {
- try
- {
+ else {
+ try {
filter = (Filter) instance;
}
- catch (ClassCastException e)
- {
+ 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())
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java 2008-06-23
17:38:03 UTC (rev 6010)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -3,9 +3,11 @@
import org.jboss.cache.CacheException;
/**
- * @author Navin Surtani - navin(a)surtani.org
*
* Thrown when an invalid Fqn is passed into the generateId method in Transformer
+ * <p />
+ *
+ * @author Navin Surtani - navin(a)surtani.org
*/
public class InvalidFqnException extends CacheException
{
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-23
17:38:03 UTC (rev 6010)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -7,12 +7,12 @@
import javax.transaction.Transaction;
/**
+ * This class implements the TransactionContext interface in the
org.hibernate.search.transaction package. It
+ * retrieves transaction context information from the NodeModifiedEvent that gets passed
in.
+ * <p />
+ * It is used by the SearchableListener to pass in transaction information to a Hibernate
Search Work object.
+ * <p />
* @author Navin Surtani - navin(a)surtani.org
-
- This class implements the TransactionContext interface in
org.hibernate.search.transaction.
-
- It is used by the SearchableListener so that a TransactionContext instance can be
created.
-
*/
public class NodeModifiedTransactionContext implements TransactionContext
{
@@ -27,7 +27,7 @@
/**
* Returns a boolean value whether or not a transaction is in progress (JTA
transaction and in this case *not*
* an org.hibernate transaction).
- * @return
+ * @return true if a transaction is in progress, false otherwise.
*/
public boolean isTxInProgress()
{
@@ -35,8 +35,9 @@
}
/**
- * Returns a JTA transaction as an object.
- * @return
+ * Returns a JTA transaction.
+ * @return a JTA transaction if one is available, or a null otherwise.
+ * @see org.jboss.cache.notifications.event.NodeModifiedEvent#getTransaction()
*/
public Object getTransactionIdentifier()
Added: searchable/trunk/src/main/java/org/jboss/cache/search/SearchResultIterator.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchResultIterator.java
(rev 0)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchResultIterator.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -0,0 +1,61 @@
+package org.jboss.cache.search;
+
+import org.hibernate.search.engine.EntityInfo;
+import org.hibernate.search.engine.Loader;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class SearchResultIterator implements Iterator
+{
+ protected final List<CacheEntityId> entityIds;
+ protected int index = 0;
+ protected final int size;
+ protected Object next;
+ protected int nextObjectIndex = -1;
+ protected final CacheEntityLoader loader;
+
+ public SearchResultIterator(List<CacheEntityId> entityIds, CacheEntityLoader
loader) {
+ this.entityIds = entityIds;
+ this.size = entityIds.size();
+ this.loader = loader;
+ }
+
+ //side effect is to set up next
+ public boolean hasNext() {
+ if ( nextObjectIndex == index ) return next != null;
+ next = null;
+ nextObjectIndex = -1;
+ do {
+ if ( index >= size ) {
+ nextObjectIndex = index;
+ next = null;
+ return false;
+ }
+ next = loader.load( entityIds.get( index ) );
+ if ( next == null ) {
+ index++;
+ }
+ else {
+ nextObjectIndex = index;
+ }
+ }
+ while ( next == null );
+ return true;
+ }
+
+ public Object next() {
+ //hasNext() has side effect
+ if ( !hasNext() ) throw new NoSuchElementException( "Out of boundaries" );
+ index++;
+ return next;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException( "Cannot remove from a lucene query
iterator" );
+ }
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-23
17:38:03 UTC (rev 6010)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -19,9 +19,9 @@
import java.util.Set;
/**
-@author Navin Surtani - navin(a)surtani.org
-
- Implementation class for the SearchableCache interface.
+ * @author Navin Surtani - navin(a)surtani.org
+ * <p/>
+ * Implementation class for the SearchableCache interface.
*/
public class SearchableCacheImpl implements SearchableCache
{
@@ -29,8 +29,7 @@
private Cache cache;
private SearchFactoryImpl searchFactory;
- //TODO: Does the impl class have to be javadocced?
-
+ //TODO: javadoc!!
public SearchableCacheImpl(Cache cache, SearchFactoryImpl searchFactory)
{
this.cache = cache;
@@ -243,19 +242,4 @@
{
return cache.put(fqn, key, value);
}
-
- public Set getCacheListeners(Fqn region)
- {
- return cache.getCacheListeners(region);
- }
-
- public void removeCacheListener(Fqn region, Object listener)
- {
- cache.removeCacheListener(region, listener);
- }
-
- public void addCacheListener(Fqn region, Object listener)
- {
- cache.addCacheListener(region, listener);
- }
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-23
17:38:03 UTC (rev 6010)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -61,11 +61,10 @@
for (Object key : dataMap.keySet())
{
- String keyString = (String) key;
- String docId = Transformer.generateId(event.getFqn(), keyString);
+ CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId,
WorkType.DELETE), ctx);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId,
WorkType.ADD), ctx);
+ 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);
}
}
@@ -84,10 +83,9 @@
for (Object key : dataMap.keySet())
{
- String keyString = (String) key;
- String docId = Transformer.generateId(event.getFqn(), keyString);
+ CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), docId,
WorkType.DELETE), ctx);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key),
cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
}
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java 2008-06-23
17:38:03 UTC (rev 6010)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java 2008-06-24
10:51:36 UTC (rev 6011)
@@ -5,22 +5,36 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.search.test.Person;
import org.testng.annotations.Test;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.search.Query;
+import org.hibernate.search.FullTextQuery;
+import java.util.List;
+
/**
* @author Navin Surtani - navin(a)surtani.org
*/
@Test
public class BlackBoxTest
{
- public void doTest()
- {
+ public void doTest() throws ParseException {
Cache cache = new DefaultCacheFactory().createCache();
SearchableCache sc = new SearchableCacheFactory().createSearchableCache(cache,
Person.class);
Person p1 = new Person();
p1.setName("Navin Surtani");
p1.setBlurb("Likes playing WoW");
sc.put(Fqn.fromString("/a/b/c"), "Navin", p1);
+ QueryParser qp = new QueryParser("field", new
StandardAnalyzer());
+ Query luceneQuery = qp.parse("playing");
+ FullTextQuery query = sc.createQuery(luceneQuery);
+ List found = query.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(p1);
+
// try and search for navin
// TODO: Create a dummy lucene query
//sc.createQuery(new Query);