Search in sources :

Example 1 with ProgrammaticSearchMappingProvider

use of org.infinispan.search.mapper.mapping.ProgrammaticSearchMappingProvider 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;
}
Also used : GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) SearchMappingBuilder(org.infinispan.search.mapper.mapping.SearchMappingBuilder) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) ProgrammaticSearchMappingProvider(org.infinispan.search.mapper.mapping.ProgrammaticSearchMappingProvider) SearchMappingCommonBuilding(org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 ProgrammaticSearchMappingProvider (org.infinispan.search.mapper.mapping.ProgrammaticSearchMappingProvider)1 SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)1 SearchMappingBuilder (org.infinispan.search.mapper.mapping.SearchMappingBuilder)1 SearchMappingCommonBuilding (org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding)1