Package org.hibernate.search.engine.spi

Examples of org.hibernate.search.engine.spi.EntityIndexBinding


    bear.setType( "Mammal" );
  }

  @Test
  public void testDynamicCreationOfShards() throws Exception {
    EntityIndexBinding entityIndexBinding = getSearchFactoryImpl().getIndexBindings().get( Animal.class );
    assertThat( entityIndexBinding.getIndexManagers() ).hasSize( 0 );

    insertAnimals( elephant );
    assertThat( entityIndexBinding.getIndexManagers() ).hasSize( 1 );

    insertAnimals( spider );
    assertThat( entityIndexBinding.getIndexManagers() ).hasSize( 2 );

    insertAnimals( bear );
    assertThat( entityIndexBinding.getIndexManagers() ).hasSize( 2 );

    assertNumberOfEntitiesInIndex( "Animal.Mammal", 2 );
    assertNumberOfEntitiesInIndex( "Animal.Insect", 1 );
  }
View Full Code Here


    sendWorkToShards( work, false );
  }

  private void sendWorkToShards(LuceneWork work, boolean forceAsync) {
    final Class<?> entityType = work.getEntityClass();
    EntityIndexBinding entityIndexBinding = searchFactoryImplementor.getIndexBinding( entityType );
    IndexShardingStrategy shardingStrategy = entityIndexBinding.getSelectionStrategy();
    if ( forceAsync ) {
      work.getWorkDelegate( StreamingSelectionVisitor.INSTANCE )
          .performStreamOperation( work, shardingStrategy, progressMonitor, forceAsync );
    }
    else {
View Full Code Here

  }

  private Collection<IndexManager> uniqueIndexManagerForTypes(Collection<Class<?>> entityTypes) {
    HashMap<String,IndexManager> uniqueBackends = new HashMap<String, IndexManager>( entityTypes.size() );
    for ( Class<?> type : entityTypes ) {
      EntityIndexBinding indexBindingForEntity = searchFactoryImplementor.getIndexBinding( type );
      if ( indexBindingForEntity != null ) {
        IndexManager[] indexManagers = indexBindingForEntity.getIndexManagers();
        for ( IndexManager im : indexManagers ) {
          uniqueBackends.put( im.getIndexName(), im );
        }
      }
    }
View Full Code Here

      sf.close();
    }
  }

  private static AbstractWorkspaceImpl extractWorkspace(MutableSearchFactory sf, Class<?> type) {
    EntityIndexBinding indexBindingForEntity = sf.getIndexBinding( type );
    DirectoryBasedIndexManager indexManager = (DirectoryBasedIndexManager) indexBindingForEntity.getIndexManagers()[0];
    LuceneBackendQueueProcessor backend = (LuceneBackendQueueProcessor) indexManager.getBackendQueueProcessor();
    return backend.getIndexResources().getWorkspace();
  }
View Full Code Here

  @Test
  public void testNoShardingIsUsedPerDefault() {
    MutableSearchFactory searchFactory = getSearchFactory( Collections.<String, String>emptyMap() );

    EntityIndexBinding entityIndexBinding = searchFactory.getIndexBinding( Foo.class );

    assertEquals(
        "No sharding should be configured. Number of shards and sharding strategy are not set",
        NotShardedStrategy.class,
        entityIndexBinding.getSelectionStrategy().getClass()
    );
  }
View Full Code Here

    Map<String, String> shardingProperties = new HashMap<String, String>();
    shardingProperties.put( "hibernate.search.default.sharding_strategy.nbr_of_shards", "2" );

    MutableSearchFactory searchFactory = getSearchFactory( shardingProperties );

    EntityIndexBinding entityIndexBinding = searchFactory.getIndexBinding( Foo.class );

    assertEquals(
        "IdHashShardingStrategy should be selected due to number of shards being set",
        IdHashShardingStrategy.class,
        entityIndexBinding.getSelectionStrategy().getClass()
    );
  }
View Full Code Here

      name = "testSettingIdHashShardingStrategyWithoutNumberOfShards")
  public void testSettingIdHashShardingStrategyWithoutNumberOfShards() {
    Map<String, String> shardingProperties = new HashMap<String, String>();
    shardingProperties.put( "hibernate.search.default.sharding_strategy", IdHashShardingStrategy.class.getName() );

    EntityIndexBinding entityIndexBinding = getSearchFactory( shardingProperties ).getIndexBinding( Foo.class );

    // 1 is assumed for legacy reasons. IMO not setting the number of shards should throw an exception
    assertTrue(
        "Without specifying number of shards, 1 should be assumed",
        entityIndexBinding.getSelectionStrategy().getIndexManagersForAllShards().length == 1
    );

    Assert.assertEquals( "Wrong invocation count", 1, BytemanHelper.getAndResetInvocationCount() );
  }
View Full Code Here

    );
    shardingProperties.put( "hibernate.search.default.sharding_strategy.nbr_of_shards", "2" );

    MutableSearchFactory searchFactory = getSearchFactory( shardingProperties );

    EntityIndexBinding entityIndexBinding = searchFactory.getIndexBinding( Foo.class );

    assertEquals(
        "Explicitly set sharding strategy ignored",
        DummyIndexShardingStrategy.class,
        entityIndexBinding.getSelectionStrategy().getClass()
    );

    assertTrue(
        "Number of shards is explicitly set, but ignored",
        entityIndexBinding.getSelectionStrategy().getIndexManagersForAllShards().length == 2
    );
  }
View Full Code Here

        DummyShardIdentifierProvider.class.getName()
    );

    MutableSearchFactory searchFactory = getSearchFactory( shardingProperties );

    EntityIndexBinding entityIndexBinding = searchFactory.getIndexBinding( Foo.class );

    assertEquals(
        "Explicitly set shard id provider ignored",
        DummyShardIdentifierProvider.class,
        entityIndexBinding.getShardIdentifierProvider().getClass()
    );
  }
View Full Code Here

        DummyShardIdentifierProvider.class.getName()
    );

    MutableSearchFactory searchFactory = getSearchFactory( shardingProperties );

    EntityIndexBinding entityIndexBinding = searchFactory.getIndexBinding( Foo.class );

    assertEquals(
        "Explicitly set shard id provider ignored",
        DummyShardIdentifierProvider.class,
        entityIndexBinding.getShardIdentifierProvider().getClass()
    );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.engine.spi.EntityIndexBinding

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.