use of org.infinispan.search.mapper.mapping.SearchMappingBuilder in project infinispan by infinispan.
the class LazySearchMapping method createMapping.
private SearchMapping createMapping() {
IndexingConfiguration indexingConfiguration = cache.getCacheConfiguration().indexing();
Set<String> indexedEntityTypes = indexingConfiguration.indexedEntityTypes();
DataConversion valueDataConversion = cache.getAdvancedCache().getValueDataConversion();
SearchMapping searchMapping = null;
if (commonBuilding != null) {
SearchMappingBuilder builder = SerializationContextSearchMapping.createBuilder(commonBuilding, entityLoader, indexedEntityTypes, serCtx);
searchMapping = builder != null ? builder.build() : null;
}
if (indexingConfiguration.enabled()) {
if (valueDataConversion.getStorageMediaType().match(APPLICATION_PROTOSTREAM)) {
// Try to resolve the indexed type names to protobuf type names.
Set<String> knownTypes = protobufMetadataManager.getSerializationContext().getGenericDescriptors().keySet();
for (String typeName : indexedEntityTypes) {
if (!knownTypes.contains(typeName)) {
if (searchMapping != null)
searchMapping.close();
throw log.unknownType(typeName);
}
if (searchMapping == null || searchMapping.indexedEntity(typeName) == null) {
if (searchMapping != null)
searchMapping.close();
throw log.typeNotIndexed(typeName);
}
}
}
}
return searchMapping;
}
use of org.infinispan.search.mapper.mapping.SearchMappingBuilder in project infinispan by infinispan.
the class LifecycleManager method createSearchMapping.
private SearchMapping createSearchMapping(LocalQueryStatistics queryStatistics, IndexingConfiguration indexingConfiguration, Map<String, Class<?>> indexedClasses, ComponentRegistry cr, AdvancedCache<?, ?> cache, KeyTransformationHandler keyTransformationHandler, ClassLoader aggregatedClassLoader) {
SearchMapping searchMapping = cr.getComponent(SearchMapping.class);
if (searchMapping != null && !searchMapping.isClose()) {
// a paranoid check against an unlikely failure
throw new IllegalStateException("SearchIntegrator already initialized!");
}
GlobalConfiguration globalConfiguration = cr.getGlobalComponentRegistry().getGlobalConfiguration();
// load ProgrammaticSearchMappingProviders from classpath
Collection<ProgrammaticSearchMappingProvider> mappingProviders = ServiceFinder.load(ProgrammaticSearchMappingProvider.class, aggregatedClassLoader);
SearchMappingCommonBuilding commonBuilding = new SearchMappingCommonBuilding(KeyTransformationHandlerIdentifierBridge.createReference(keyTransformationHandler), extractProperties(globalConfiguration, indexingConfiguration, aggregatedClassLoader), aggregatedClassLoader, mappingProviders);
Set<Class<?>> types = new HashSet<>(indexedClasses.values());
if (!types.isEmpty()) {
// use the common builder to create the mapping now
SearchMappingBuilder builder = commonBuilding.builder(SearchMappingBuilder.introspector(MethodHandles.lookup()));
builder.setEntityLoader(new EntityLoader<>(queryStatistics, cache, keyTransformationHandler));
builder.addEntityTypes(types);
searchMapping = builder.build();
cr.registerComponent(searchMapping, SearchMapping.class);
}
if (searchMapping == null) {
// register the common builder to create the mapping at a later time
cr.registerComponent(commonBuilding, SearchMappingCommonBuilding.class);
}
return searchMapping;
}
use of org.infinispan.search.mapper.mapping.SearchMappingBuilder in project infinispan by infinispan.
the class SerializationContextSearchMapping method createBuilder.
public static SearchMappingBuilder createBuilder(SearchMappingCommonBuilding commonBuilding, EntityLoader<EntityReference, ?> entityLoader, Set<String> indexedEntityTypes, SerializationContext serializationContext) {
GlobalReferenceHolder globalReferenceHolder = new GlobalReferenceHolder(serializationContext.getGenericDescriptors());
ProtobufBootstrapIntrospector introspector = new ProtobufBootstrapIntrospector();
SearchMappingBuilder builder = commonBuilding.builder(introspector);
builder.setEntityLoader(entityLoader);
builder.setEntityConverter(new ProtobufEntityConverter(serializationContext, globalReferenceHolder.getRootMessages()));
ProgrammaticMappingConfigurationContext programmaticMapping = builder.programmaticMapping();
boolean existIndexedEntities = false;
for (GlobalReferenceHolder.RootMessageInfo rootMessage : globalReferenceHolder.getRootMessages()) {
String fullName = rootMessage.getFullName();
if (!indexedEntityTypes.contains(fullName)) {
continue;
}
existIndexedEntities = true;
programmaticMapping.type(fullName).binder(new ProtobufMessageBinder(globalReferenceHolder, fullName)).indexed().index(rootMessage.getIndexName());
builder.addEntityType(byte[].class, fullName);
}
return existIndexedEntities ? builder : null;
}
Aggregations