org.hibernate.search.backend
Class Workspace

java.lang.Object
  extended by org.hibernate.search.backend.Workspace

public class Workspace
extends Object

Lucene workspace for a DirectoryProvider.

Before using getIndexWriter(boolean, org.hibernate.search.exception.impl.ErrorContextBuilder) the lock must be acquired, and resources must be closed before releasing the lock.

Author:
Emmanuel Bernard, Hardy Ferentschik, Sanne Grinovero

Constructor Summary
Workspace(WorkerBuildContext context, DirectoryProvider<?> provider, ErrorHandler errorHandler)
           
 
Method Summary
 void closeIndexWriter()
          Closes a previously opened IndexWriter.
 void commitIndexWriter()
           
 void commitIndexWriter(ErrorContextBuilder errorContextBuilder)
          Commits changes to a previously opened IndexWriter.
 void forceLockRelease()
          Forces release of Directory lock.
 Analyzer getAnalyzer(String name)
           
<T> DocumentBuilderIndexedEntity<T>
getDocumentBuilder(Class<T> entity)
           
 Set<Class<?>> getEntitiesInDirectory()
           
 IndexWriter getIndexWriter(boolean batchmode)
           
 IndexWriter getIndexWriter(boolean batchmode, ErrorContextBuilder errorContextBuilder)
          Gets the IndexWriter, opening one if needed.
 void incrementModificationCounter(int modCount)
          Increment the counter of modification operations done on the index.
 void optimize()
          Used by OptimizeLuceneWork after index optimization to flag that optimization has been forced.
 void optimizerPhase()
          If optimization has not been forced give a chance to configured OptimizerStrategy to optimize the index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Workspace

public Workspace(WorkerBuildContext context,
                 DirectoryProvider<?> provider,
                 ErrorHandler errorHandler)
Method Detail

getDocumentBuilder

public <T> DocumentBuilderIndexedEntity<T> getDocumentBuilder(Class<T> entity)

getAnalyzer

public Analyzer getAnalyzer(String name)

optimizerPhase

public void optimizerPhase()
If optimization has not been forced give a chance to configured OptimizerStrategy to optimize the index.


optimize

public void optimize()
Used by OptimizeLuceneWork after index optimization to flag that optimization has been forced.

See Also:
OptimizeLuceneWork, SearchFactory.optimize(), SearchFactory.optimize(Class)

getIndexWriter

public IndexWriter getIndexWriter(boolean batchmode,
                                  ErrorContextBuilder errorContextBuilder)
Gets the IndexWriter, opening one if needed.

Parameters:
batchmode - when true the indexWriter settings for batch mode will be applied. Ignored if IndexWriter is open already.
errorContextBuilder - might contain some context useful to provide when handling IOExceptions
Returns:
a new IndexWriter or one already open.

getIndexWriter

public IndexWriter getIndexWriter(boolean batchmode)
See Also:
getIndexWriter(boolean, ErrorContextBuilder)

commitIndexWriter

public void commitIndexWriter(ErrorContextBuilder errorContextBuilder)
Commits changes to a previously opened IndexWriter.

Parameters:
errorContextBuilder - use it to handle exceptions, as it might contain a reference to the work performed before the commit

commitIndexWriter

public void commitIndexWriter()
See Also:
commitIndexWriter(ErrorContextBuilder)

closeIndexWriter

public void closeIndexWriter()
Closes a previously opened IndexWriter.


incrementModificationCounter

public void incrementModificationCounter(int modCount)
Increment the counter of modification operations done on the index. Used (currently only) by the OptimizerStrategy.

Parameters:
modCount - the increment to add to the counter.

getEntitiesInDirectory

public Set<Class<?>> getEntitiesInDirectory()
Returns:
The unmodifiable set of entity types being indexed in the underlying Lucene Directory backing this Workspace.

forceLockRelease

public void forceLockRelease()
Forces release of Directory lock. Should be used only to cleanup as error recovery.



Copyright © 2006-2010 Red Hat Middleware, LLC. All Rights Reserved