public DirectoryProviderFactory.DirectoryProviders createDirectoryProviders(XClass entity,
SearchConfiguration cfg,
SearchFactoryImplementor searchFactoryImplementor,
ReflectionManager reflectionManager) {
//get properties
String directoryProviderName = getDirectoryProviderName( entity, cfg );
Properties[] indexProps = getDirectoryProperties( cfg, directoryProviderName );
//set up the directories
int nbrOfProviders = indexProps.length;
DirectoryProvider[] providers = new DirectoryProvider[nbrOfProviders];
for (int index = 0; index < nbrOfProviders; index++) {
String providerName = nbrOfProviders > 1 ?
directoryProviderName + "." + index :
directoryProviderName;
providers[index] = createDirectoryProvider( providerName, indexProps[index],
reflectionManager.toClass( entity ), searchFactoryImplementor );
}
//define sharding strategy
IndexShardingStrategy shardingStrategy;
//any indexProperty will do, the indexProps[0] surely exists.
String shardingStrategyName = indexProps[0].getProperty( SHARDING_STRATEGY );
if ( shardingStrategyName == null ) {
if ( indexProps.length == 1 ) {
shardingStrategy = new NotShardedStrategy();
}
else {
shardingStrategy = new IdHashShardingStrategy();
}
}
else {
try {
Class shardigStrategyClass = ReflectHelper.classForName( shardingStrategyName, this.getClass() );
shardingStrategy = (IndexShardingStrategy) shardigStrategyClass.newInstance();
}
catch (ClassNotFoundException e) {
throw new SearchException( "Unable to find ShardingStrategy class " + shardingStrategyName + " for " + directoryProviderName, e );
}
catch (IllegalAccessException e) {
throw new SearchException( "Unable to create instance of ShardingStrategy class " + shardingStrategyName
+ " Be sure to have a no-arg constructor", e );
}
catch (InstantiationException e) {
throw new SearchException( "Unable to create instance of ShardingStrategy class " + shardingStrategyName
+ " Be sure to have a no-arg constructor", e );
}
catch (ClassCastException e) {
throw new SearchException( "ShardingStrategy class does not implements DirecotryProviderShardingStrategy: "
+ shardingStrategyName, e );
}
}
shardingStrategy.initialize(
new MaskedProperty( indexProps[0], SHARDING_STRATEGY ), providers );
return new DirectoryProviders( shardingStrategy, providers );
}
|