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());
}
}
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);
}
}
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;
}
}
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;
}
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());
}
}
Aggregations