-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-823 Make it possible to plug in custom IndexManager implement…
…ations
- Loading branch information
1 parent
1e52171
commit 17c7db7
Showing
6 changed files
with
157 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
hibernate-search/src/main/java/org/hibernate/search/indexes/impl/NRTIndexManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors | ||
* as indicated by the @authors tag. All rights reserved. | ||
* See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This copyrighted material is made available to anyone wishing to use, | ||
* modify, copy, or redistribute it subject to the terms and conditions | ||
* of the GNU Lesser General Public License, v. 2.1. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT A | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public License, | ||
* v.2.1 along with this distribution; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
package org.hibernate.search.indexes.impl; | ||
|
||
/** | ||
* IndexManager implementation taking advantage of the Near-Real-Time | ||
* features of Lucene. | ||
* When using this work mode the IndexWriter does not need a full | ||
* flush at the end of each operation: new IndexReaders are able to | ||
* inspect the unflushed changes still pending in the IndexWriter buffers. | ||
* | ||
* This improves write performance as the IndexWriter doesn't need | ||
* to commit as often, but has two limitations: | ||
* <ul> | ||
* <li>unsaved index data might be lost in case of crashes</li> | ||
* <li>is not useful for non-local (clustered) backends</li> | ||
* </ul> | ||
* | ||
* @since 4.0 | ||
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc. | ||
*/ | ||
public class NRTIndexManager extends DirectoryBasedIndexManager { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...earch/src/test/java/org/hibernate/search/test/configuration/IndexManagerOverrideTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors | ||
* as indicated by the @authors tag. All rights reserved. | ||
* See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* This copyrighted material is made available to anyone wishing to use, | ||
* modify, copy, or redistribute it subject to the terms and conditions | ||
* of the GNU Lesser General Public License, v. 2.1. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT A | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public License, | ||
* v.2.1 along with this distribution; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
package org.hibernate.search.test.configuration; | ||
|
||
import org.hibernate.search.FullTextSession; | ||
import org.hibernate.search.engine.spi.SearchFactoryImplementor; | ||
import org.hibernate.search.indexes.impl.IndexManagerHolder; | ||
import org.hibernate.search.indexes.spi.IndexManager; | ||
import org.hibernate.search.test.util.FullTextSessionBuilder; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Verifies the configured IndexManager implementation is used for each index | ||
* | ||
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc. | ||
*/ | ||
public class IndexManagerOverrideTest { | ||
|
||
@Test | ||
public void verifyIndexExclusivity() { | ||
FullTextSessionBuilder builder = new FullTextSessionBuilder(); | ||
FullTextSession ftSession = builder | ||
.setProperty( "hibernate.search.Book.indexmanager", "NRT" ) | ||
.setProperty( "hibernate.search.org.hibernate.search.test.perf.Boat.indexmanager", | ||
"org.hibernate.search.test.util.RamIndexManager" ) | ||
.addAnnotatedClass( BlogEntry.class ) | ||
.addAnnotatedClass( org.hibernate.search.test.perf.Boat.class ) | ||
.addAnnotatedClass( org.hibernate.search.test.query.Book.class ) | ||
.addAnnotatedClass( org.hibernate.search.test.query.Author.class ) | ||
.openFullTextSession(); | ||
SearchFactoryImplementor searchFactory = ( SearchFactoryImplementor ) ftSession.getSearchFactory(); | ||
ftSession.close(); | ||
IndexManagerHolder allIndexesManager = searchFactory.getAllIndexesManager(); | ||
|
||
//checks for the default implementation | ||
checkIndexManagerType( allIndexesManager, "org.hibernate.search.test.configuration.BlogEntry", | ||
org.hibernate.search.indexes.impl.DirectoryBasedIndexManager.class ); | ||
|
||
//Uses "NRT" taken from shortcut names | ||
checkIndexManagerType( allIndexesManager, "Book", | ||
org.hibernate.search.indexes.impl.NRTIndexManager.class ); | ||
|
||
//Uses a fully qualified name to load an implementation | ||
checkIndexManagerType( allIndexesManager, "org.hibernate.search.test.perf.Boat", | ||
org.hibernate.search.test.util.RamIndexManager.class ); | ||
|
||
builder.close(); | ||
} | ||
|
||
private void checkIndexManagerType(IndexManagerHolder allIndexesManager, String name, Class expectedType) { | ||
IndexManager indexManager = allIndexesManager.getIndexManager( name ); | ||
Assert.assertEquals( expectedType, indexManager.getClass() ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters