org.hibernate.search.indexes.impl.DynamicShardingIndexManagerSelector Maven / Gradle / Ivy
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.search.indexes.impl;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.apache.lucene.document.Document;
import org.hibernate.search.filter.FullTextFilterImplementor;
import org.hibernate.search.indexes.spi.IndexManager;
import org.hibernate.search.indexes.spi.IndexManagerSelector;
import org.hibernate.search.spi.IndexedTypeIdentifier;
import org.hibernate.search.store.ShardIdentifierProvider;
/**
* @author Hardy Ferentschik
* @author Emmanuel Bernard
*/
class DynamicShardingIndexManagerSelector implements IndexManagerSelector {
private final ShardIdentifierProvider shardIdentifierProvider;
private final IndexManagerGroupHolder indexManagerGroupHolder;
private final Properties indexProperties;
private final IndexedTypeIdentifier entityType;
public DynamicShardingIndexManagerSelector(ShardIdentifierProvider shardIdentifierProvider,
IndexManagerGroupHolder indexManagerGroupHolder, Properties indexProperties, IndexedTypeIdentifier entityType) {
this.shardIdentifierProvider = shardIdentifierProvider;
this.indexManagerGroupHolder = indexManagerGroupHolder;
this.indexProperties = indexProperties;
this.entityType = entityType;
}
@Override
public Set all() {
Set allShardIdentifiers = shardIdentifierProvider.getAllShardIdentifiers();
return getIndexManagersFromShards( allShardIdentifiers );
}
@Override
public IndexManager forNew(IndexedTypeIdentifier typeId, Serializable id, String idInString, Document document) {
String shardIdentifier = shardIdentifierProvider.getShardIdentifier( typeId.getPojoType(), id, idInString, document );
return indexManagerGroupHolder.getOrCreateIndexManager( shardIdentifier, indexProperties, entityType, null );
}
@Override
public Set forExisting(IndexedTypeIdentifier typeId, Serializable id, String idInString) {
Set shardIdentifiers = shardIdentifierProvider.getShardIdentifiersForDeletion( typeId.getPojoType(), id, idInString );
return getIndexManagersFromShards( shardIdentifiers );
}
@Override
public Set forFilters(FullTextFilterImplementor[] fullTextFilters) {
Set shards = shardIdentifierProvider.getShardIdentifiersForQuery( fullTextFilters );
return getIndexManagersFromShards( shards );
}
private Set getIndexManagersFromShards(Set shardIdentifiers) {
Set managers = new HashSet( shardIdentifiers.size() );
for ( String shardIdentifier : shardIdentifiers ) {
managers.add(
indexManagerGroupHolder.getOrCreateIndexManager(
shardIdentifier,
indexProperties,
entityType,
null
)
);
}
return managers;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy