Java Code Examples for javax.cache.Cache#Entry

The following examples show how to use javax.cache.Cache#Entry . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 * @param entries Expected entries in the cache.
 */
private void checkIteratorCache(IgniteCache<String, Integer> cache, Map<String, Integer> entries) {
    Iterator<Cache.Entry<String, Integer>> iter = cache.iterator();

    int cnt = 0;

    while (iter.hasNext()) {
        Cache.Entry<String, Integer> cur = iter.next();

        assertTrue(entries.containsKey(cur.getKey()));
        assertEquals(entries.get(cur.getKey()), cur.getValue());

        cnt++;
    }

    assertEquals(entries.size(), cnt);
}
 
Example 2
Source File: IgniteCacheLocalQuerySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Test
@Override public void testLocalSqlQueryFromClient() throws Exception {
    try (Ignite g = startClientGrid("client")) {
        IgniteCache<Integer, Integer> c = jcache(g, Integer.class, Integer.class);

        for (int i = 0; i < 10; i++)
            c.put(i, i);

        SqlQuery<Integer, Integer> qry = new SqlQuery<>(Integer.class, "_key >= 5 order by _key");

        qry.setLocal(true);

        try (QueryCursor<Cache.Entry<Integer, Integer>> qryCursor = c.query(qry)) {
            assertNotNull(qryCursor);

            List<Cache.Entry<Integer, Integer>> res = qryCursor.getAll();

            assertNotNull(res);

            assertEquals(5, res.size());
        }
    }
}
 
Example 3
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testIterator() throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);

    final int KEYS = 1000;

    for (int i = 0; i < KEYS; i++)
        cache.put(i, i);

    // Try to initialize readers in case when near cache is enabled.
    for (int i = 0; i < gridCount(); i++) {
        cache = grid(i).cache(DEFAULT_CACHE_NAME);

        for (int k = 0; k < KEYS; k++)
            assertEquals((Object)k, cache.get(k));
    }

    int cnt = 0;

    for (Cache.Entry e : cache)
        cnt++;

    assertEquals(KEYS, cnt);
}
 
Example 4
Source File: GridCacheStoreManagerAdapter.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public boolean remove(Object o) {
    if (cleared || !(o instanceof Cache.Entry))
        return false;

    Cache.Entry<?, ?> e = (Cache.Entry<?, ?>)o;

    if (rmvd != null && rmvd.contains(e.getKey()))
        return false;

    if (mapContains(e)) {
        addRemoved(e);

        return true;
    }

    return false;
}
 
Example 5
Source File: IgniteCacheReplicatedQuerySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If test failed.
 */
@Test
public void testToString() throws Exception {
    int keyCnt = 4;

    for (int i = 1; i <= keyCnt; i++)
        cache1.put(new CacheKey(i), new CacheValue(String.valueOf(i)));

    // Create query with key filter.

    QueryCursor<Cache.Entry<CacheKey, CacheValue>> qry =
        cache1.query(new SqlQuery<CacheKey, CacheValue>(CacheValue.class, "val > 0"));

    assertEquals(keyCnt, qry.getAll().size());
}
 
Example 6
Source File: CacheSpringPersonStore.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void write(Cache.Entry<? extends Long, ? extends Person> entry) {
    Long key = entry.getKey();
    Person val = entry.getValue();

    System.out.println(">>> Store write [key=" + key + ", val=" + val + ']');

    int updated = jdbcTemplate.update("update PERSON set first_name = ?, last_name = ? where id = ?",
        val.firstName, val.lastName, val.id);

    if (updated == 0) {
        jdbcTemplate.update("insert into PERSON (id, first_name, last_name) values (?, ?, ?)",
            val.id, val.firstName, val.lastName);
    }
}
 
Example 7
Source File: BatchPartialSuccessRecordingClassWriter.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
/**
 * Some implementations may not call writeAll.  So this method fails every {@link #simulatedWriteFailure} times.
 * @param entry to write
 * @throws CacheException to simulate partial failure of write-through
 */
public void write(Cache.Entry<? extends K, ? extends V> entry) {
    if ((numWrite.getAndIncrement() % simulatedWriteFailure) == 0) {
        throw new CacheException("simulated failure of write entry=[" + entry.getKey() + "," + entry.getValue()
                                 + "]");
    } else {
        super.write(entry);
    }
}
 
Example 8
Source File: HibernateCacheProxy.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Iterator<Cache.Entry<Object,Object>> scanIterator(
    boolean keepBinary,
    @Nullable IgniteBiPredicate p
) throws IgniteCheckedException {
    return delegate.get().scanIterator(keepBinary, p);
}
 
Example 9
Source File: CacheQueryExample.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Example for TEXT queries using LUCENE-based indexing of people's resumes.
 */
private static void textQuery() {
    IgniteCache<Long, Person> cache = Ignition.ignite().cache(PERSON_CACHE);

    //  Query for all people with "Master Degree" in their resumes.
    QueryCursor<Cache.Entry<Long, Person>> masters =
        cache.query(new TextQuery<Long, Person>(Person.class, "Master"));

    // Query for all people with "Bachelor Degree" in their resumes.
    QueryCursor<Cache.Entry<Long, Person>> bachelors =
        cache.query(new TextQuery<Long, Person>(Person.class, "Bachelor"));

    print("Following people have 'Master Degree' in their resumes: ", masters.getAll());
    print("Following people have 'Bachelor Degree' in their resumes: ", bachelors.getAll());
}
 
Example 10
Source File: GridCacheIteratorPerformanceTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Empty filter.
 */
private IgniteInClosure<Cache.Entry<Integer, Integer>> emptyFilter() {
    return new CI1<Cache.Entry<Integer, Integer>>() {
        @Override public void apply(Cache.Entry<Integer, Integer> e) {
            // No-op
        }
    };
}
 
Example 11
Source File: CacheWriterClient.java    From cache2k with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void writeAll(Collection<Cache.Entry<? extends K, ? extends V>> entries) {
    if (isDirectCallable()) {
        shortCircuitServer.getCacheWriter().writeAll(entries);
        return;
    }
    getClient().invoke(new WriteAllOperation<>(entries));
}
 
Example 12
Source File: GridNearCacheAdapter.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@NotNull @Override public Iterator<Cache.Entry<K, V>> iterator() {
    return new EntryIterator(nearSet.iterator(),
        F.iterator0(dhtSet, false, new P1<Cache.Entry<K, V>>() {
            @Override public boolean apply(Cache.Entry<K, V> e) {
                try {
                    return GridNearCacheAdapter.super.localPeek(e.getKey(), NEAR_PEEK_MODE) == null;
                }
                catch (IgniteCheckedException ex) {
                    throw new IgniteException(ex);
                }
            }
        }));
}
 
Example 13
Source File: IgniteCacheQueryIndexSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache.
 * @throws Exception If failed.
 */
private void checkQuery(IgniteCache<Integer, CacheValue> cache) throws Exception {
    QueryCursor<Cache.Entry<Integer, CacheValue>> qry =
        cache.query(new SqlQuery(CacheValue.class, "val >= 5"));

    Collection<Cache.Entry<Integer, CacheValue>> queried = qry.getAll();

    assertEquals("Unexpected query result: " + queried, 5, queried.size());
}
 
Example 14
Source File: EvictionAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param c Collection.
 * @return String.
 */
protected static String string(Iterable<? extends Cache.Entry> c) {
    return "[" +
        F.fold(
            c,
            "",
            new C2<Cache.Entry, String, String>() {
                @Override public String apply(Cache.Entry e, String b) {
                    return b.isEmpty() ? e.getKey().toString() : b + ", " + e.getKey();
                }
            }) +
        "]]";
}
 
Example 15
Source File: CompositeCacheWriterTest.java    From commons-jcs with Apache License 2.0 4 votes vote down vote up
@Override
public void write(final Cache.Entry<? extends String, ? extends String> entry) throws CacheWriterException
{
    copy1.put(entry.getKey(), entry.getValue());
}
 
Example 16
Source File: ContinuousQuery.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public ContinuousQuery<K, V> setInitialQuery(Query<Cache.Entry<K, V>> initQry) {
    return (ContinuousQuery<K, V>)super.setInitialQuery(initQry);
}
 
Example 17
Source File: CacheDeploymentTestStoreFactory.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public void writeAll(Collection<Cache.Entry<? extends K, ? extends IgniteBiTuple<V, ?>>> entries)
    throws CacheWriterException {
    for (Cache.Entry<? extends K, ? extends IgniteBiTuple<V, ?>> e : entries)
        map.put(e.getKey(), e.getValue());
}
 
Example 18
Source File: GridCacheLifecycleAwareSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) {
    return newVal;
}
 
Example 19
Source File: GridCacheBinaryObjectsAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testIterator() throws Exception {
    IgniteCache<Integer, TestObject> c = jcache(0);

    Map<Integer, TestObject> entries = new HashMap<>();

    for (int i = 0; i < ENTRY_CNT; i++) {
        TestObject val = new TestObject(i);

        c.put(i, val);

        entries.put(i, val);
    }

    IgniteCache<Integer, BinaryObject> prj = ((IgniteCacheProxy)c).keepBinary();

    Iterator<Cache.Entry<Integer, BinaryObject>> it = prj.iterator();

    assertTrue(it.hasNext());

    while (it.hasNext()) {
        Cache.Entry<Integer, BinaryObject> entry = it.next();

        assertTrue(entries.containsKey(entry.getKey()));

        TestObject o = entries.get(entry.getKey());

        BinaryObject po = entry.getValue();

        assertEquals(o.val, (int)po.field("val"));

        entries.remove(entry.getKey());
    }

    assertEquals(0, entries.size());
}
 
Example 20
Source File: GridCacheEntryEx.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Wraps this map entry into cache entry.
 *
 * @return Wrapped entry.
 */
public <K, V> Cache.Entry<K, V> wrap();