本文整理汇总了Java中org.apache.ignite.cache.query.ScanQuery.setPartition方法的典型用法代码示例。如果您正苦于以下问题:Java ScanQuery.setPartition方法的具体用法?Java ScanQuery.setPartition怎么用?Java ScanQuery.setPartition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ignite.cache.query.ScanQuery
的用法示例。
在下文中一共展示了ScanQuery.setPartition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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.
}
}
}
}
示例2: run
import org.apache.ignite.cache.query.ScanQuery; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public void run() {
try {
IgniteCache traders = node.cache(TRADER_CACHE).withKeepBinary();
IgniteCache<String, BinaryObject> depositCache = node.cache(DEPOSIT_CACHE).withKeepBinary();
// 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);
try (QueryCursor<Cache.Entry<String, BinaryObject>> cursor = traders.query(scanQry)) {
for (Cache.Entry<String, BinaryObject> entry : cursor) {
String traderId = entry.getKey();
SqlFieldsQuery findDepositQry = new SqlFieldsQuery(FIND_DEPOSIT_SQL).setLocal(true);
try (QueryCursor cursor1 = depositCache.query(findDepositQry.setArgs(traderId))) {
for (Object obj : cursor1) {
List<String> depositIds = (List<String>)obj;
for (String depositId : depositIds) {
updateDeposit(depositCache, depositId);
checkDeposit(depositCache, depositId);
}
}
}
}
}
}
}
catch (Exception e) {
throw new IgniteException(e);
}
}
示例3: checkScanPartition
import org.apache.ignite.cache.query.ScanQuery; //导入方法依赖的package包/类
/**
* @param partCntrs Expected per-partition entries count.
*/
private void checkScanPartition(Ignite ignite,
IgniteCache<DbKey, DbValue> cache,
Map<Integer, Integer> partCntrs,
boolean loc) {
Affinity<Object> aff = ignite.affinity(cache.getName());
int parts = aff.partitions();
for (int p = 0; p < parts; p++) {
ScanQuery<DbKey, DbValue> qry = new ScanQuery<>();
qry.setPartition(p);
qry.setLocal(loc);
if (loc && !ignite.cluster().localNode().equals(aff.mapPartitionToNode(p)))
continue;
QueryCursor<Cache.Entry<DbKey, DbValue>> cur = cache.query(qry);
Set<DbKey> allKeys = new HashSet<>();
for (Cache.Entry<DbKey, DbValue> e : cur) {
allKeys.add(e.getKey());
assertEquals(e.getKey().val, e.getValue().iVal);
}
Integer exp = partCntrs.get(p);
if (exp == null)
exp = 0;
assertEquals(exp, (Integer)allKeys.size());
}
}
示例4: call
import org.apache.ignite.cache.query.ScanQuery; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public Object call() throws Exception {
cache = node.cache(PERSON_CACHE_NAME);
// Getting a list of the partitions owned by this node.
List<Integer> myPartitions = nodesToPart.get(node.cluster().localNode().id());
// Iterating over every partition and increasing salary for every person.
for (Integer part : myPartitions) {
ScanQuery scanQuery = new ScanQuery();
scanQuery.setPartition(part);
// Execute the query.
Iterator<Cache.Entry<PersonKey, Person>> iterator = node.cache(PERSON_CACHE_NAME).
query(scanQuery).iterator();
while (iterator.hasNext()) {
PersonKey key = iterator.next().getKey();
// Performing update in a transaction.
try (Transaction tr = node.transactions().txStart(
TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
// Locking the entry.
Person person = cache.get(key);
person.setSalary(person.getSalary() + person.getSalary() / 10);
cache.put(key, person);
tr.commit();
System.out.println("Increased salary for person: " + person);
}
}
}
return null;
}
示例5: scanQueryReconnectInProgress
import org.apache.ignite.cache.query.ScanQuery; //导入方法依赖的package包/类
/**
* @param setPart If {@code true} sets partition for scan query.
* @throws Exception If failed.
*/
private void scanQueryReconnectInProgress(boolean setPart) throws Exception {
Ignite cln = grid(serverCount());
assertTrue(cln.cluster().localNode().isClient());
final Ignite srv = clientRouter(cln);
final IgniteCache<Integer, Person> clnCache = cln.getOrCreateCache(QUERY_CACHE);
clnCache.put(1, new Person(1, "name1", "surname1"));
clnCache.put(2, new Person(2, "name2", "surname2"));
clnCache.put(3, new Person(3, "name3", "surname3"));
final ScanQuery<Integer, Person> scanQry = new ScanQuery<>();
scanQry.setPageSize(1);
scanQry.setFilter(new IgniteBiPredicate<Integer, Person>() {
@Override public boolean apply(Integer integer, Person person) {
return true;
}
});
if (setPart)
scanQry.setPartition(1);
blockMessage(GridCacheQueryResponse.class);
final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override public Object call() throws Exception {
try {
QueryCursor<Cache.Entry<Integer, Person>> qryCursor = clnCache.query(scanQry);
qryCursor.getAll();
}
catch (CacheException e) {
checkAndWait(e);
return true;
}
return false;
}
});
// Check that client waiting operation.
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
return fut.get(200);
}
}, IgniteFutureTimeoutCheckedException.class, null);
assertNotDone(fut);
unblockMessage();
reconnectClientNode(cln, srv, null);
assertTrue((Boolean)fut.get(2, SECONDS));
QueryCursor<Cache.Entry<Integer, Person>> qryCursor2 = clnCache.query(scanQry);
List<Cache.Entry<Integer, Person>> entries = qryCursor2.getAll();
assertEquals(setPart ? 1 : 3, entries.size());
for (Cache.Entry<Integer, Person> entry : entries) {
assertEquals(Integer.class, entry.getKey().getClass());
assertEquals(Person.class, entry.getValue().getClass());
}
}
示例6: readScanQuery
import org.apache.ignite.cache.query.ScanQuery; //导入方法依赖的package包/类
/**
* Reads scan query.
*
* @param reader Binary reader.
* @return Query.
*/
private Query readScanQuery(BinaryRawReaderEx reader) {
boolean loc = reader.readBoolean();
final int pageSize = reader.readInt();
boolean hasPart = reader.readBoolean();
Integer part = hasPart ? reader.readInt() : null;
ScanQuery qry = new ScanQuery().setPageSize(pageSize);
qry.setPartition(part);
Object pred = reader.readObjectDetached();
if (pred != null)
qry.setFilter(platformCtx.createCacheEntryFilter(pred, 0));
qry.setLocal(loc);
return qry;
}