Search in sources :

Example 1 with QueryInterceptor

use of org.infinispan.query.backend.QueryInterceptor in project infinispan by infinispan.

the class DefaultCacheInheritancePreventedTest method assertIndexingEnabled.

/**
 * Verifies that the SearchIntegrator is or is not registered as expected
 * @param expected true if you expect indexing to be enabled
 * @param cache the cache to extract indexing from
 */
private void assertIndexingEnabled(Cache<Object, Object> cache, boolean expected) {
    SearchMapping searchMapping = null;
    try {
        searchMapping = ComponentRegistryUtils.getSearchMapping(cache);
    } catch (IllegalStateException e) {
    // ignored here, we deal with it later
    }
    if (expected && searchMapping == null) {
        Assert.fail("SearchIntegrator not found but expected for cache " + cache.getName());
    }
    if (!expected && searchMapping != null) {
        Assert.fail("SearchIntegrator not expected but found for cache " + cache.getName());
    }
    // verify as well that the indexing interceptor is (not) there:
    QueryInterceptor queryInterceptor = null;
    try {
        queryInterceptor = ComponentRegistryUtils.getQueryInterceptor(cache);
    } catch (IllegalStateException e) {
    // ignored here, we deal with it later
    }
    if (expected && queryInterceptor == null) {
        Assert.fail("QueryInterceptor not found but expected for cache " + cache.getName());
    }
    if (!expected && queryInterceptor != null) {
        Assert.fail("QueryInterceptor not expected but found for cache " + cache.getName());
    }
}
Also used : SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor)

Example 2 with QueryInterceptor

use of org.infinispan.query.backend.QueryInterceptor in project infinispan by infinispan.

the class CacheModeTest method doTest.

private void doTest(CacheMode m) {
    CacheContainer cc = null;
    try {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.clustering().cacheMode(m).indexing().enable().addIndexedEntities(Person.class);
        cc = TestCacheManagerFactory.createClusteredCacheManager(TestDataSCI.INSTANCE, builder);
        QueryInterceptor queryInterceptor = TestingUtil.findInterceptor(cc.getCache(), QueryInterceptor.class);
        assertNotNull("Didn't find a query interceptor in the chain!!", queryInterceptor);
    } finally {
        TestingUtil.killCacheManagers(cc);
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor) CacheContainer(org.infinispan.manager.CacheContainer)

Example 3 with QueryInterceptor

use of org.infinispan.query.backend.QueryInterceptor in project infinispan by infinispan.

the class ObjectRemoteQueryManager method createEntityNamesResolver.

private EntityNameResolver<Class<?>> createEntityNamesResolver(MediaType mediaType) {
    if (mediaType.match(APPLICATION_PROTOSTREAM)) {
        return new ProtobufEntityNameResolver(serCtx);
    } else {
        ClassLoader classLoader = cr.getGlobalComponentRegistry().getComponent(ClassLoader.class);
        ReflectionEntityNamesResolver reflectionEntityNamesResolver = new ReflectionEntityNamesResolver(classLoader);
        if (searchMapping != null) {
            // If indexing is enabled then use the declared set of indexed classes for lookup but fallback to global classloader.
            QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class);
            Map<String, Class<?>> indexedEntities = queryInterceptor.indexedEntities();
            return name -> {
                Class<?> c = indexedEntities.get(name);
                if (c == null) {
                    c = reflectionEntityNamesResolver.resolve(name);
                }
                return c;
            };
        }
        return reflectionEntityNamesResolver;
    }
}
Also used : ReflectionEntityNamesResolver(org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) APPLICATION_PROTOSTREAM(org.infinispan.commons.dataconversion.MediaType.APPLICATION_PROTOSTREAM) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ReflectionMatcher(org.infinispan.objectfilter.impl.ReflectionMatcher) ComponentRegistry(org.infinispan.factories.ComponentRegistry) EntityNameResolver(org.infinispan.objectfilter.impl.syntax.parser.EntityNameResolver) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) MediaType(org.infinispan.commons.dataconversion.MediaType) AdvancedCache(org.infinispan.AdvancedCache) Matcher(org.infinispan.objectfilter.Matcher) APPLICATION_OBJECT(org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT) Map(java.util.Map) ReflectionEntityNamesResolver(org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver) ObjectReflectionMatcher(org.infinispan.query.dsl.embedded.impl.ObjectReflectionMatcher) SerializationContext(org.infinispan.protostream.SerializationContext) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor)

Example 4 with QueryInterceptor

use of org.infinispan.query.backend.QueryInterceptor in project infinispan by infinispan.

the class CQWorker method initialize.

void initialize(AdvancedCache<?, ?> cache, QueryDefinition queryDefinition, UUID queryId, int docIndex) {
    this.cache = cache;
    QueryInterceptor queryInterceptor = ComponentRegistryUtils.getQueryInterceptor(cache);
    this.queryStatistics = ComponentRegistryUtils.getLocalQueryStatistics(cache);
    if (queryDefinition != null) {
        this.queryDefinition = queryDefinition;
        this.queryDefinition.initialize(cache);
    }
    this.blockingManager = queryInterceptor.getBlockingManager();
    this.queryId = queryId;
    this.docIndex = docIndex;
}
Also used : QueryInterceptor(org.infinispan.query.backend.QueryInterceptor)

Example 5 with QueryInterceptor

use of org.infinispan.query.backend.QueryInterceptor in project infinispan by infinispan.

the class LifecycleManager method createQueryInterceptorIfNeeded.

private void createQueryInterceptorIfNeeded(ComponentRegistry cr, Configuration cfg, AdvancedCache<?, ?> cache, Map<String, Class<?>> indexedClasses) {
    CONTAINER.registeringQueryInterceptor(cache.getName());
    BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
    ComponentRef<QueryInterceptor> queryInterceptorRef = bcr.getComponent(QueryInterceptor.class);
    if (queryInterceptorRef != null) {
        // could be already present when two caches share a config
        return;
    }
    ConcurrentMap<GlobalTransaction, Map<Object, Object>> txOldValues = new ConcurrentHashMap<>();
    boolean manualIndexing = HS5_CONF_STRATEGY_MANUAL.equals(cfg.indexing().properties().get(HS5_CONF_STRATEGY_PROPERTY));
    QueryInterceptor queryInterceptor = new QueryInterceptor(manualIndexing, txOldValues, cache, indexedClasses);
    AsyncInterceptorChain ic = bcr.getComponent(AsyncInterceptorChain.class).wired();
    EntryWrappingInterceptor wrappingInterceptor = ic.findInterceptorExtending(EntryWrappingInterceptor.class);
    ic.addInterceptorBefore(queryInterceptor, wrappingInterceptor.getClass());
    bcr.registerComponent(QueryInterceptor.class, queryInterceptor, true);
    bcr.addDynamicDependency(AsyncInterceptorChain.class.getName(), QueryInterceptor.class.getName());
    if (cfg.transaction().transactionMode().isTransactional()) {
        TxQueryInterceptor txQueryInterceptor = new TxQueryInterceptor(txOldValues, queryInterceptor);
        ic.addInterceptorBefore(txQueryInterceptor, wrappingInterceptor.getClass());
        bcr.registerComponent(TxQueryInterceptor.class, txQueryInterceptor, true);
        bcr.addDynamicDependency(AsyncInterceptorChain.class.getName(), TxQueryInterceptor.class.getName());
    }
}
Also used : BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) TxQueryInterceptor(org.infinispan.query.backend.TxQueryInterceptor) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) EntryWrappingInterceptor(org.infinispan.interceptors.impl.EntryWrappingInterceptor) TxQueryInterceptor(org.infinispan.query.backend.TxQueryInterceptor) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

QueryInterceptor (org.infinispan.query.backend.QueryInterceptor)6 SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)2 TxQueryInterceptor (org.infinispan.query.backend.TxQueryInterceptor)2 HashMap (java.util.HashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AdvancedCache (org.infinispan.AdvancedCache)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 APPLICATION_OBJECT (org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT)1 APPLICATION_PROTOSTREAM (org.infinispan.commons.dataconversion.MediaType.APPLICATION_PROTOSTREAM)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 ComponentRegistry (org.infinispan.factories.ComponentRegistry)1 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)1 EntryWrappingInterceptor (org.infinispan.interceptors.impl.EntryWrappingInterceptor)1 CacheContainer (org.infinispan.manager.CacheContainer)1 Matcher (org.infinispan.objectfilter.Matcher)1 ReflectionMatcher (org.infinispan.objectfilter.impl.ReflectionMatcher)1 EntityNameResolver (org.infinispan.objectfilter.impl.syntax.parser.EntityNameResolver)1