Lucene workspace for a DirectoryProvider.
| Method from org.hibernate.search.backend.Workspace Detail: |
public synchronized void closeIndexReader() {
assertOwnLock();
IndexReader toClose = reader;
reader = null;
if ( toClose != null ) {
try {
toClose.close();
log.trace( "IndexReader closed" );
}
catch ( IOException e ) {
throw new SearchException( "Exception while closing IndexReader", e );
}
}
else {
throw new AssertionFailure( "No IndexReader open to close." );
}
}
Closes a previously opened IndexReader. |
public synchronized void closeIndexWriter() {
assertOwnLock();
IndexWriter toClose = writer;
writer = null;
if ( toClose != null ) {
try {
toClose.close();
log.trace( "IndexWriter closed" );
}
catch ( IOException e ) {
throw new SearchException( "Exception while closing IndexWriter", e );
}
}
else {
throw new AssertionFailure( "No open IndexWriter to close" );
}
}
Closes a previously opened IndexWriter. |
public DocumentBuilder getDocumentBuilder(Class entity) {
return searchFactoryImplementor.getDocumentBuilder( entity );
}
|
public Set getEntitiesInDirectory() {
return entitiesInDirectory;
}
|
public synchronized IndexReader getIndexReader() {
assertOwnLock();
// one cannot access a reader for update while a writer is in use
if ( writer != null )
throw new AssertionFailure( "Tries to read for update an index while a writer is in use." );
if ( reader != null )
return reader;
Directory directory = directoryProvider.getDirectory();
try {
reader = IndexReader.open( directory, false );
log.trace( "IndexReader opened" );
}
catch ( IOException e ) {
reader = null;
throw new SearchException( "Unable to open IndexReader on directory " + directory, e );
}
return reader;
}
Gets an IndexReader to alter the index, opening one if needed.
The caller needs to own the lock relevant to this DirectoryProvider. |
public synchronized IndexWriter getIndexWriter(boolean batchmode) {
assertOwnLock();
// one has to close a reader for update before a writer is accessed
if ( reader != null )
throw new AssertionFailure( "Tries to open an IndexWriter while an IndexReader is open in update mode." );
if ( writer != null )
return writer;
try {
// don't care about the Analyzer as it will be selected during usage of IndexWriter.
//FIXME use the non deprecated constructor = > requires to call #Commit()
writer = new IndexWriter( directoryProvider.getDirectory(), SIMPLE_ANALYZER, false ); // has been created at init time
indexingParams.applyToWriter( writer, batchmode );
log.trace( "IndexWriter opened" );
}
catch ( IOException e ) {
writer = null;
throw new SearchException( "Unable to open IndexWriter", e );
}
return writer;
}
Gets the IndexWriter, opening one if needed. |
public void incrementModificationCounter(int modCount) {
operations.addAndGet( modCount );
}
Increment the counter of modification operations done on the index.
Used (currently only) by the OptimizerStrategy. |
public void lock() {
lock.lock();
}
Acquires a lock on the DirectoryProvider backing this Workspace;
this is required to use getIndexWriter(boolean), closeIndexWriter(),
getIndexReader(), closeIndexReader(). |
public void optimize() {
assertOwnLock(); // the DP is not affected, but needs to ensure the optimizerStrategy is accesses in threadsafe way
optimizerStrategy.optimizationForced();
}
Used by OptimizeLuceneWork after index optimization to flag that
optimization has been forced. |
public void optimizerPhase() {
assertOwnLock();
// used getAndSet(0) because Workspace is going to be reused by next transaction.
optimizerStrategy.addTransaction( operations.getAndSet( 0L ) );
optimizerStrategy.optimize( this );
}
If optimization has not been forced give a change to configured OptimizerStrategy
to optimize the index. |
public synchronized void unlock() {
try {
if ( this.reader != null ) {
throw new AssertionFailure( "Unlocking Workspace without having closed the IndexReader" );
}
if ( this.writer != null ) {
throw new AssertionFailure( "Unlocking Workspace without having closed the IndexWriter" );
}
}
finally {
lock.unlock();
}
}
Releases the lock obtained by calling lock() |