本文整理汇总了Java中org.apache.ignite.cache.query.ScanQuery类的典型用法代码示例。如果您正苦于以下问题:Java ScanQuery类的具体用法?Java ScanQuery怎么用?Java ScanQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScanQuery类属于org.apache.ignite.cache.query包,在下文中一共展示了ScanQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testQuery
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testQuery() {
IgniteCache<String, String> cache = ignite().getOrCreateCache("testcache1");
Set<String> keys = new HashSet<>();
for (int i = 0; i < 100; i++) {
cache.put("k" + i, "v" + i);
keys.add("k" + i);
}
Query<Entry<String, String>> query = new ScanQuery<String, String>(new IgniteBiPredicate<String, String>() {
private static final long serialVersionUID = 1L;
@Override
public boolean apply(String key, String value) {
return Integer.parseInt(key.replace("k", "")) >= 50;
}
});
List results = template.requestBodyAndHeader("ignite:cache:testcache1?operation=QUERY", keys, IgniteConstants.IGNITE_CACHE_QUERY, query, List.class);
assert_().that(results.size()).isEqualTo(50);
}
示例2: main
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
try (Ignite ignite = Ignition.start("config/default-config.xml")) {
CacheConfiguration<String, LocalDateTime> cacheCfg = new CacheConfiguration<>("CacheQueriesScanQueryExample");
cacheCfg.setCacheMode(CacheMode.PARTITIONED).setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 3)));
try (IgniteCache<String, LocalDateTime> igniteCache = ignite.getOrCreateCache(cacheCfg)) {
LocalDateTime now = LocalDateTime.now();
igniteCache.put("doctor", now);
igniteCache.put("doctor who", now.plusHours(10L));
igniteCache.put("doctor who", now.minusYears(1L));
System.out.println("--------ScanQuery----------");
try (QueryCursor<Entry<Object, Object>> query = igniteCache.query(new ScanQuery<>((k, v) -> v.equals(now)))) {
for (Entry<Object, Object> entry : query) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
}
}
}
}
示例3: testScanQueryUsesDedicatedThreadPool
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* Tests that Scan queries are executed in dedicated pool
* @throws Exception If failed.
*/
public void testScanQueryUsesDedicatedThreadPool() throws Exception {
try (Ignite client = startGrid("client")) {
IgniteCache<Integer, Integer> cache = client.cache(CACHE_NAME);
cache.put(0, 0);
QueryCursor<Cache.Entry<Object, Object>> cursor = cache.query(
new ScanQuery<>(new IgniteBiPredicate<Object, Object>() {
@Override public boolean apply(Object o, Object o2) {
return F.eq(GridIoManager.currentPolicy(), GridIoPolicy.QUERY_POOL);
}
}));
assertEquals(1, cursor.getAll().size());
cursor.close();
}
}
示例4: testScanLocal
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* Scan should perform on the local node.
*
* @throws Exception If failed.
*/
public void testScanLocal() throws Exception {
cacheMode = CacheMode.PARTITIONED;
backups = 0;
commSpiFactory = new TestLocalCommunicationSpiFactory();
try {
Ignite ignite = startGrids(GRID_CNT);
IgniteCacheProxy<Integer, Integer> cache = fillCache(ignite);
int part = anyLocalPartition(cache.context());
QueryCursor<Cache.Entry<Integer, Integer>> qry =
cache.query(new ScanQuery<Integer, Integer>().setPartition(part));
doTestScanQuery(qry, part);
}
finally {
stopAllGrids();
}
}
示例5: testScanRemote
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* Scan should perform on the remote node.
*
* @throws Exception If failed.
*/
public void testScanRemote() throws Exception {
cacheMode = CacheMode.PARTITIONED;
backups = 0;
commSpiFactory = new TestRemoteCommunicationSpiFactory();
try {
Ignite ignite = startGrids(GRID_CNT);
IgniteCacheProxy<Integer, Integer> cache = fillCache(ignite);
IgniteBiTuple<Integer, UUID> tup = remotePartition(cache.context());
int part = tup.get1();
expNodeId = tup.get2();
QueryCursor<Cache.Entry<Integer, Integer>> qry =
cache.query(new ScanQuery<Integer, Integer>().setPartition(part));
doTestScanQuery(qry, part);
}
finally {
stopAllGrids();
}
}
示例6: testResponseMessageOnRequestUnmarshallingFailed
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* @throws Exception If failed.
*/
public void testResponseMessageOnRequestUnmarshallingFailed() throws Exception {
readCnt.set(Integer.MAX_VALUE);
try {
jcache().query(new ScanQuery<>(new IgniteBiPredicate<TestKey, String>() {
@Override public boolean apply(TestKey key, String val) {
return false;
}
private void readObject(ObjectInputStream is) throws IOException {
throw new IOException();
}
private void writeObject(ObjectOutputStream os) throws IOException {
// No-op.
}
})).getAll();
fail();
}
catch (Exception ignored) {
// No-op.
}
}
示例7: run
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void run() {
IgniteCache cache = node.cache(cacheName);
// Getting a list of the partitions owned by this node.
List<Integer> myPartitions = cachePart.get(node.cluster().localNode().id());
for (Integer part : myPartitions) {
ScanQuery scanQry = new ScanQuery();
scanQry.setPartition(part);
scanQry.setFilter(igniteBiPred);
try (QueryCursor cursor = cache.query(scanQry)) {
for (Object obj : cursor) {
// No-op.
}
}
}
}
示例8: query
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public <T, R> QueryCursor<R> query(Query<T> qry, IgniteClosure<T, R> transformer) {
A.notNull(qry, "qry");
A.notNull(transformer, "transformer");
if (!(qry instanceof ScanQuery))
throw new UnsupportedOperationException("Transformers are supported only for SCAN queries.");
try {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
validate(qry);
return query((ScanQuery<K, V>)qry, transformer, projection(qry.isLocal()));
}
catch (Exception e) {
if (e instanceof CacheException)
throw (CacheException)e;
throw new CacheException(e);
}
}
示例9: checkScan
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* @param total Expected total entries.
*/
private void checkScan(int total) {
for (int i = 0; i < gridCount(); i++) {
Set<DbKey> allKeys = new HashSet<>();
Ignite ignite0 = grid(i);
IgniteCache<DbKey, DbValue> cache0 = ignite0.cache("non-primitive");
ScanQuery<DbKey, DbValue> qry = new ScanQuery<>();
QueryCursor<Cache.Entry<DbKey, DbValue>> cur = cache0.query(qry);
for (Cache.Entry<DbKey, DbValue> e : cur) {
allKeys.add(e.getKey());
assertEquals(e.getKey().val, e.getValue().iVal);
}
assertEquals(total, allKeys.size());
}
}
示例10: testEntriesMovedFromOnHeap
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* @throws Exception If failed.
*/
public void testEntriesMovedFromOnHeap() throws Exception {
Ignite ignite0 = grid(0);
Ignite ignite1 = grid(1);
IgniteCache<Integer, Integer> cache0 = ignite0.cache(CACHE_NAME);
IgniteCache<Integer, Integer> cache1 = ignite1.cache(CACHE_NAME);
populateCache(cache0);
assertEquals(0, cache0.localSize(ONHEAP));
assertEquals(0, cache1.localSize(ONHEAP));
assertEquals(ENTRIES_CNT, cache0.localSize(OFFHEAP) + cache1.localSize(OFFHEAP));
cache0.query(new ScanQuery<>()).getAll();
cache1.query(new ScanQuery<>()).getAll();
assertEquals(0, cache0.localSize(ONHEAP));
assertEquals(0, cache1.localSize(ONHEAP));
assertEquals(ENTRIES_CNT, cache0.localSize(OFFHEAP) + cache1.localSize(OFFHEAP));
}
示例11: cacheQuery
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* @param cache Cache.
*/
private void cacheQuery(IgniteCache cache) {
int keys = 100;
Map<Integer, Integer> data = generateDataMap(keys);
cache.putAll(data);
ScanQuery<Integer, Integer> qry = new ScanQuery<>(new IgniteBiPredicate<Integer, Integer>() {
@Override public boolean apply(Integer key, Integer val) {
return key % 2 == 0;
}
});
List<Cache.Entry<Integer, Integer>> all = cache.query(qry).getAll();
assertEquals(all.size(), data.size() / 2);
for (Cache.Entry<Integer, Integer> entry : all) {
assertEquals(0, entry.getKey() % 2);
assertEquals(entry.getValue(), data.get(entry.getKey()));
}
tearDown(cache);
}
示例12: testDeployScanPredicate
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* @throws Exception In case of error.
*/
public void testDeployScanPredicate() throws Exception {
startGrids(4);
awaitPartitionMapExchange();
try {
IgniteCache<Object, Object> cache = grid(3).cache(DEFAULT_CACHE_NAME);
// It is important that there are no too many keys.
for (int i = 0; i < 1; i++)
cache.put(i, i);
Class predCls = grid(3).configuration().getClassLoader().loadClass(TEST_PREDICATE);
IgniteBiPredicate<Object, Object> pred = (IgniteBiPredicate<Object, Object>)predCls.newInstance();
List<Cache.Entry<Object, Object>> all = cache.query(new ScanQuery<>(pred)).getAll();
assertEquals(1, all.size());
}
finally {
stopAllGrids();
}
}
示例13: scanQuery
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
/**
* Example for scan query based on a predicate using binary objects.
*/
private static void scanQuery() {
IgniteCache<BinaryObject, BinaryObject> cache = Ignition.ignite()
.cache(PERSON_CACHE).withKeepBinary();
ScanQuery<BinaryObject, BinaryObject> scan = new ScanQuery<>(
new IgniteBiPredicate<BinaryObject, BinaryObject>() {
@Override public boolean apply(BinaryObject key, BinaryObject person) {
return person.<Double>field("salary") <= 1000;
}
}
);
// Execute queries for salary ranges.
print("People with salaries between 0 and 1000 (queried with SCAN query): ", cache.query(scan).getAll());
}
示例14: entries
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
@Override
public void entries(Handler<AsyncResult<Map<K, V>>> resultHandler) {
vertx.executeBlocking(fut -> {
List<Cache.Entry<K, V>> all = cache.query(new ScanQuery<K, V>()).getAll();
Map<K, V> map = new HashMap<>(all.size());
for (Cache.Entry<K, V> entry : all) {
map.put(unmarshal(entry.getKey()), unmarshal(entry.getValue()));
}
fut.complete(map);
}, resultHandler);
}
示例15: createRegistry
import org.apache.ignite.cache.query.ScanQuery; //导入依赖的package包/类
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry answer = super.createRegistry();
ScanQuery<Integer, Person> scanQuery1 = new ScanQuery<>(new IgniteBiPredicate<Integer, Person>() {
private static final long serialVersionUID = 1L;
@Override
public boolean apply(Integer key, Person person) {
return person.getId() > 50;
}
});
CacheEntryEventSerializableFilter<Integer, Person> remoteFilter = new CacheEntryEventSerializableFilter<Integer, IgniteCacheContinuousQueryTest.Person>() {
private static final long serialVersionUID = 5624973479995548199L;
@Override
public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Person> event) throws CacheEntryListenerException {
return event.getValue().getId() > 150;
}
};
answer.bind("query1", scanQuery1);
answer.bind("remoteFilter1", remoteFilter);
return answer;
}