Package org.hibernate.search.indexes.spi

Examples of org.hibernate.search.indexes.spi.IndexManager


    String indexName = indexBaseName;
    if ( shardName != null ) {
      indexName += INDEX_SHARD_ID_SEPARATOR + shardName;
    }

    IndexManager indexManager = indexManagersRegistry.get( indexName );
    if ( indexManager != null ) {
      indexManager.addContainedEntity( entityIndexBinding.getDocumentBuilder().getBeanClass() );
      return indexManager;
    }
    SearchFactoryImplementor searchFactory = entityIndexBinding.getSearchFactory();
    WorkerBuildContext context;
    //known implementations of SearchFactory passed are MutableSearchFactory and ImmutableSearchFactory
    if ( WorkerBuildContext.class.isAssignableFrom( searchFactory.getClass() ) ) {
      context = (WorkerBuildContext) searchFactory;
    }
    else {
      throw log.assertionFailureCannotCastToWorkerBuilderContext( searchFactory.getClass() );
    }

    Properties properties = entityIndexBinding.getProperties();
    if ( shardName != null ) {
      properties = new MaskedProperty( properties, shardName, properties );
    }

    indexManager = createIndexManager(
        indexName,
        entityIndexBinding.getDocumentBuilder().getBeanClass(),
        entityIndexBinding.getSimilarity(),
        properties,
        context
    );
    indexManager.setSearchFactory( searchFactory );
    return indexManager;
  }
View Full Code Here


    ServiceManager serviceManager = workerBuildContext.getServiceManager();
    IndexManagerFactory indexManagerFactory = serviceManager.requestService( IndexManagerFactory.class );

    // create IndexManager instance via the index manager factory
    String indexManagerImplementationName = properties.getProperty( Environment.INDEX_MANAGER_IMPL_NAME );
    final IndexManager manager;
    try {
      if ( StringHelper.isEmpty( indexManagerImplementationName ) ) {
        manager = indexManagerFactory.createDefaultIndexManager();
      }
      else {
        manager = indexManagerFactory.createIndexManagerByName( indexManagerImplementationName );
      }
    }
    finally {
      serviceManager.releaseService( IndexManagerFactory.class );
    }

    // init the IndexManager
    try {
      manager.initialize( indexName, properties, indexSimilarity, workerBuildContext );
      return manager;
    }
    catch (Exception e) {
      throw log.unableToInitializeIndexManager( indexName, e );
    }
View Full Code Here

    for ( int index = 0; index < nbrOfIndexManagers; index++ ) {
      String indexManagerName = nbrOfIndexManagers > 1 ?
          indexBaseName + INDEX_SHARD_ID_SEPARATOR + index :
          indexBaseName;
      Properties indexProp = indexProperties[index];
      IndexManager indexManager = indexManagersRegistry.get( indexManagerName );
      if ( indexManager == null ) {
        indexManager = createIndexManager(
            indexManagerName, mappedClass, similarity, indexProp, context
        );
      }
      else {
        if ( !indexManager.getSimilarity().getClass().equals( similarity.getClass() ) ) {
          throw log.getMultipleEntitiesShareIndexWithInconsistentSimilarityException(
              mappedClass.getName(),
              similarity.getClass().getName(),
              indexManager.getContainedTypes().iterator().next().getName(),
              indexManager.getSimilarity().getClass().getName()
          );
        }
        indexManager.addContainedEntity( mappedClass );
      }
      indexManagers[index] = indexManager;
    }
    return indexManagers;
  }
View Full Code Here

  private synchronized IndexManager createIndexManager(String indexManagerName,
      Class<?> mappedClass,
      Similarity similarity,
      Properties indexProperties,
      WorkerBuildContext context) {
    IndexManager indexManager = indexManagersRegistry.get( indexManagerName );
    if ( indexManager == null ) {
      indexManager = createIndexManager(
          indexManagerName,
          similarity,
          indexProperties,
          context
      );
      indexManagersRegistry.put( indexManagerName, indexManager );
    }
    indexManager.addContainedEntity( mappedClass );
    return indexManager;
  }
View Full Code Here

      sf.close();
    }
  }

  private Class<? extends IndexManager> extractDocumentIndexManagerClassName(SearchFactoryImplementor sf, String indexName) {
    IndexManager indexManager = sf.getIndexManagerHolder().getIndexManager( indexName );
    Assert.assertNotNull( indexManager );
    return indexManager.getClass();
  }
View Full Code Here

    shardingProperties.put( "hibernate.search.foo.snafu.indexBase", indexDir.getAbsolutePath() );

    MutableSearchFactory searchFactory = getSearchFactory( shardingProperties );

    EntityIndexBinding entityIndexBinding = searchFactory.getIndexBinding( Foo.class );
    IndexManager indexManagers[] = entityIndexBinding.getIndexManagers();

    assertTrue( "There should be two index managers", indexManagers.length == 1 );
    assertTrue( "Unexpected index manager type", indexManagers[0] instanceof DirectoryBasedIndexManager );

    DirectoryBasedIndexManager directoryBasedIndexManager = (DirectoryBasedIndexManager) indexManagers[0];
View Full Code Here

public class ClassLoaderHelperTest {

  @Test
  public void testInstanceFromClass() {
    //testing for interface implementation:
    IndexManager batchBackend = ClassLoaderHelper.instanceFromClass(
        IndexManager.class, DirectoryBasedIndexManager.class, "Lucene index manager"
    );
    assertNotNull( batchBackend );
    assertTrue( batchBackend.getClass().equals( DirectoryBasedIndexManager.class ) );

    //testing for subclasses:
    Similarity sim = ClassLoaderHelper.instanceFromClass(
        Similarity.class, DefaultSimilarity.class, "default similarity"
    );
View Full Code Here

      final byte[] rawBuffer = message.getRawBuffer();
      final int messageOffset = message.getOffset();
      final int bufferLength = message.getLength();
      String indexName = MessageSerializationHelper.extractIndexName( messageOffset, rawBuffer );
      byte[] serializedQueue = MessageSerializationHelper.extractSerializedQueue( messageOffset, bufferLength, rawBuffer );
      IndexManager indexManager = searchFactory.getIndexManagerHolder().getIndexManager( indexName );
      List<LuceneWork> queue = indexManager.getSerializer().toLuceneWorks( serializedQueue );
      queues++;
      works += queue.size();
    }
    catch (ClassCastException e) {
      throw new SearchException( e );
View Full Code Here

  @Test
  public void testErrorHandling() {
    MockErrorHandler mockErrorHandler = getErrorHandlerAndAssertCorrectTypeIsUsed();
    EntityIndexBinding mappingForEntity = getSearchFactoryImpl().getIndexBinding( Foo.class );
    IndexManager indexManager = mappingForEntity.getIndexManagers()[0];

    List<LuceneWork> queue = new ArrayList<LuceneWork>();
    queue.add( new HarmlessWork( "firstWork" ) );
    queue.add( new HarmlessWork( "secondWork" ) );
    WORK_COUNTER.set( 0 ); // reset work counter
    indexManager.performOperations( queue, null );
    Assert.assertEquals( 2, WORK_COUNTER.get() );

    WORK_COUNTER.set( 0 ); // reset work counter
    final FailingWork firstFailure = new FailingWork( "firstFailure" );
    queue.add( firstFailure );
    final HarmlessWork thirdWork = new HarmlessWork( "thirdWork" );
    queue.add( thirdWork );
    final HarmlessWork fourthWork = new HarmlessWork( "fourthWork" );
    queue.add( fourthWork );
    indexManager.performOperations( queue, null );
    Assert.assertEquals( 4, WORK_COUNTER.get() );

    String errorMessage = mockErrorHandler.getErrorMessage();
    Throwable exception = mockErrorHandler.getLastException();
View Full Code Here

    channel.connect( CHANNEL_NAME );
  }

  private void sendMessage(List<LuceneWork> queue) throws Exception {
    final String indexManagerName = "org.hibernate.search.test.jgroups.master.TShirt";
    IndexManager indexManager = getSearchFactoryImpl().getIndexManagerHolder().getIndexManager( indexManagerName );
    //send message to all listeners
    byte[] data = indexManager.getSerializer().toSerializedModel( queue );
    data = MessageSerializationHelper.prependString( indexManagerName, data );
    Message message = new Message( null, null, data );
    channel.send( message );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.indexes.spi.IndexManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.