net.java.ao
Class IndexingEntityManager

java.lang.Object
  extended by net.java.ao.EntityManager
      extended by net.java.ao.IndexingEntityManager

public class IndexingEntityManager
extends EntityManager

Author:
Daniel Spiewak

Constructor Summary
IndexingEntityManager(DatabaseProvider provider, org.apache.lucene.store.Directory indexDir)
           
IndexingEntityManager(DatabaseProvider provider, org.apache.lucene.store.Directory indexDir, boolean weaklyCache)
           
IndexingEntityManager(java.lang.String uri, java.lang.String username, java.lang.String password, org.apache.lucene.store.Directory indexDir)
           
 
Method Summary
 void addToIndex(Entity entity)
           
 void delete(Entity... entities)
          Deletes the specified entities from the database.
 org.apache.lucene.analysis.Analyzer getAnalyzer()
           
protected
<T extends Entity>
T
getAndInstantiate(java.lang.Class<T> type, int id)
           
 org.apache.lucene.store.Directory getIndexDir()
           
 void optimize()
           
 void removeFromIndex(Entity entity)
           
<T extends Entity>
T[]
search(java.lang.Class<T> type, java.lang.String strQuery)
           
 
Methods inherited from class net.java.ao.EntityManager
count, count, count, create, find, find, find, find, findWithSQL, flush, flushAll, get, get, getFieldNameConverter, getProvider, getProxyForEntity, getRSCachingStrategy, getTableNameConverter, migrate, setFieldNameConverter, setRSCachingStrategy, setTableNameConverter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexingEntityManager

public IndexingEntityManager(DatabaseProvider provider,
                             org.apache.lucene.store.Directory indexDir)
                      throws java.io.IOException
Throws:
java.io.IOException

IndexingEntityManager

public IndexingEntityManager(DatabaseProvider provider,
                             org.apache.lucene.store.Directory indexDir,
                             boolean weaklyCache)
                      throws java.io.IOException
Throws:
java.io.IOException

IndexingEntityManager

public IndexingEntityManager(java.lang.String uri,
                             java.lang.String username,
                             java.lang.String password,
                             org.apache.lucene.store.Directory indexDir)
                      throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getAndInstantiate

protected <T extends Entity> T getAndInstantiate(java.lang.Class<T> type,
                                                 int id)
Overrides:
getAndInstantiate in class EntityManager

search

public <T extends Entity> T[] search(java.lang.Class<T> type,
                                     java.lang.String strQuery)
                          throws java.io.IOException,
                                 org.apache.lucene.queryParser.ParseException
Throws:
java.io.IOException
org.apache.lucene.queryParser.ParseException

delete

public void delete(Entity... entities)
            throws java.sql.SQLException
Description copied from class: EntityManager

Deletes the specified entities from the database. DELETE statements are called on the rows in the corresponding tables and the entities are removed from the instance cache. The entity instances themselves are not invalidated, but it doesn't even make sense to continue using the instance without a row with which it is paired.

This method does attempt to group the DELETE statements on a per-type basis. Thus, if you pass 5 instances of EntityA and two instances of EntityB, the following prepared statement SQL will be invoked:

DELETE FROM entityA WHERE id IN (?,?,?,?,?);
 DELETE FROM entityB WHERE id IN (?,?);

Thus, this method scales very well for large numbers of entities grouped into types. However, the execution time scales linearly for each entity of unique type.

Overrides:
delete in class EntityManager
Throws:
java.sql.SQLException

addToIndex

public void addToIndex(Entity entity)
                throws java.io.IOException
Throws:
java.io.IOException

removeFromIndex

public void removeFromIndex(Entity entity)
                     throws java.io.IOException
Throws:
java.io.IOException

optimize

public void optimize()
              throws java.io.IOException
Throws:
java.io.IOException

getIndexDir

public org.apache.lucene.store.Directory getIndexDir()

getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer()