Author: navssurtani
Date: 2008-06-26 07:18:41 -0400 (Thu, 26 Jun 2008)
New Revision: 6052
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
Log:
Cleaned up CacheQueryImpl a bit
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-26
11:06:55 UTC (rev 6051)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-26
11:18:41 UTC (rev 6052)
@@ -14,7 +14,7 @@
{
List<Object> list();
- QueryResultIterator iterate();
+ QueryResultIterator iterator();
void setFirstResult(int index);
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-26
11:06:55 UTC (rev 6051)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-26
11:18:41 UTC (rev 6052)
@@ -7,10 +7,7 @@
import org.apache.lucene.search.*;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
-import org.hibernate.LockMode;
-import org.hibernate.ScrollableResults;
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.DocumentExtractor;
@@ -76,11 +73,6 @@
this.classes = classes;
}
- public FullTextQuery setResultTransformer(ResultTransformer transformer)
- {
- // TODO: Do we need to impl this? What does HS do?
- return null;
- }
/**
* @return The result size of the query.
@@ -130,28 +122,9 @@
sort = s;
}
- /**
- * This method is not supported in JBossCache Searchable and should not be called.
- */
- public FullTextQuery setCriteriaQuery(Criteria criteria)
- {
- 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
- */
- public FullTextQuery setProjection(String... strings)
- {
- throw new UnsupportedOperationException("Not supported in
SearchableCache!");
- }
-
private void closeSearcher(Searcher searcher, ReaderProvider readerProvider)
{
Set<IndexReader> indexReaders = getIndexReaders(searcher);
@@ -213,9 +186,9 @@
this.firstResult = firstResult;
}
- public QueryResultIterator iterate() throws HibernateException
+ public QueryResultIterator iterator() throws HibernateException
{
- List list;
+ List<CacheEntityId> ids = null;
IndexSearcher searcher = buildSearcher(searchFactory);
if (searcher == null)
{
@@ -228,7 +201,7 @@
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);
+ ids = new ArrayList<CacheEntityId>(size);
DocumentExtractor extractor = new DocumentExtractor(searchFactory,
indexProjection);
for (int index = first; index <= max; index++)
@@ -238,7 +211,6 @@
ids.add(id);
}
- list = entityLoader.load(ids);
}
catch (IOException e)
{
@@ -253,46 +225,9 @@
}
- return new QueryResultIteratorImpl(list, entityLoader);
+ return new QueryResultIteratorImpl(ids, entityLoader);
}
- public ScrollableResults scroll() throws HibernateException
- {
- IndexSearcher searcher = buildSearcher(searchFactory);
-
- Hits hits;
-
- try
- {
- hits = getHits(searcher);
- int first = first();
- int max = max(first, hits);
- int size = max - first + 1 < 0 ? 0 : max - first + 1;
-
- DocumentExtractor extractor = new DocumentExtractor(searchFactory,
indexProjection);
-
- List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
-
- for (int index = first; index <= max; index++)
- {
-
- String documentId = (String) extractor.extract(hits, index).id;
- CacheEntityId id = new CacheEntityId(documentId);
- ids.add(id);
- }
-
- List<Object> list = entityLoader.load(ids);
-
- }
-
- catch (IOException e)
- {
- throw new HibernateException("Unable to query Lucene index", e);
- }
-
- return null;
- }
-
/**
* Returns a the results from the query as a List object.
*
@@ -349,48 +284,6 @@
}
-// 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;
-// }
-// }
private int max(int first, Hits hits)
{
@@ -408,11 +301,6 @@
0;
}
- public int executeUpdate() throws HibernateException
- {
- throw new UnsupportedOperationException(" This method is not supported in
JBossCache Searchable");
- }
-
public void setMaxResults(int maxResults)
{
if (maxResults < 0)
@@ -431,16 +319,6 @@
this.fetchSize = fetchSize;
}
- public org.hibernate.Query setLockMode(String alias, LockMode lockMode)
- {
- throw new UnsupportedOperationException(" This method is not supported in
JBossCache Searchable");
- }
-
- protected Map getLockModes()
- {
- throw new UnsupportedOperationException(" This method is not supported in
JBossCache Searchable");
- }
-
private IndexSearcher buildSearcher(SearchFactoryImplementor
searchFactoryImplementor)
{
Map<Class, DocumentBuilder<Object>> builders =
searchFactoryImplementor.getDocumentBuilders();
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java 2008-06-26
11:06:55 UTC (rev 6051)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java 2008-06-26
11:18:41 UTC (rev 6052)
@@ -79,7 +79,7 @@
public Object next()
{
- if ( !hasNext() ) throw new NoSuchElementException( "Out of boundaries"
);
+ if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
index++;
return next;
}
@@ -106,15 +106,16 @@
public void remove()
{
+ throw new UnsupportedOperationException("Not supported as you are trying to
change something in the cache");
}
- public void set(Object o)
+ public void set(Object o) throws UnsupportedOperationException
{
- //TODO: Implement
+ throw new UnsupportedOperationException("Not supported as you are trying to
change something in the cache");
}
public void add(Object o)
{
- idList.add(o);
+ throw new UnsupportedOperationException("Not supported as you are trying to
change something in the cache");
}
}