javax.cache.integration.CacheLoaderException Java Examples

The following examples show how to use javax.cache.integration.CacheLoaderException. 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: CacheJdbcPojoStoreAbstractSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testLoadNotRegisteredType() throws Exception {
    startTestGrid(false, false, false, false, 512);

    IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME);

    try {
        checkFetchSize = true;

        c1.loadCache(null, "PersonKeyWrong", "SELECT * FROM Person");
    }
    catch (CacheLoaderException e) {
        String msg = e.getMessage();

        assertTrue("Unexpected exception: " + msg,
            ("Provided key type is not found in store or cache configuration " +
                "[cache=" + CACHE_NAME + ", key=PersonKeyWrong]").equals(msg));
    } finally {
        checkFetchSize = false;
    }
}
 
Example #2
Source File: PlatformDotNetCacheStore.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public void loadCache(final IgniteBiInClosure<K, V> clo, @Nullable final Object... args) {
    try {
        doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
            @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
                writer.writeByte(OP_LOAD_CACHE);
                writer.writeLong(session());
                writer.writeString(ses.cacheName());
                writer.writeObjectArray(args);
            }
        }, new IgniteInClosureX<BinaryRawReaderEx>() {
            @Override public void applyx(BinaryRawReaderEx reader) {
                int cnt = reader.readInt();

                for (int i = 0; i < cnt; i++)
                    clo.apply((K) reader.readObjectDetached(), (V) reader.readObjectDetached());
            }
        });
    }
    catch (IgniteCheckedException e) {
        throw new CacheLoaderException(e);
    }
}
 
Example #3
Source File: CacheSpringPersonStore.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public void loadCache(final IgniteBiInClosure<Long, Person> clo, Object... args) {
    if (args == null || args.length == 0 || args[0] == null)
        throw new CacheLoaderException("Expected entry count parameter is not provided.");

    int entryCnt = (Integer)args[0];

    final AtomicInteger cnt = new AtomicInteger();

    jdbcTemplate.query("select * from PERSON limit ?", new RowCallbackHandler() {
        @Override public void processRow(ResultSet rs) throws SQLException {
            Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));

            clo.apply(person.id, person);

            cnt.incrementAndGet();
        }
    }, entryCnt);

    System.out.println(">>> Loaded " + cnt + " values into cache.");
}
 
Example #4
Source File: GridCacheLoadOnlyStoreAdapterSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected Iterator<String> inputIterator(@Nullable Object... args) throws CacheLoaderException {
    return new Iterator<String>() {
        private int i;

        @Override public boolean hasNext() {
            return i < inputSize;
        }

        @Override public String next() {
            if (!hasNext())
                throw new NoSuchElementException();

            String res = i + "=str" + i;

            i++;

            return res;
        }

        @Override public void remove() {
            // No-op.
        }
    };
}
 
Example #5
Source File: CacheJdbcPojoStore.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Construct binary object from query result.
 *
 * @param typeName Type name.
 * @param fields Fields descriptors.
 * @param loadColIdxs Select query columns index.
 * @param rs ResultSet.
 * @return Constructed binary object.
 * @throws CacheLoaderException If failed to construct binary object.
 */
protected Object buildBinaryObject(String typeName, JdbcTypeField[] fields, Map<String, Integer> loadColIdxs, ResultSet rs) throws CacheLoaderException {
    try {
        BinaryObjectBuilder builder = ignite.binary().builder(typeName);

        for (JdbcTypeField field : fields) {
            Integer colIdx = columnIndex(loadColIdxs, field.getDatabaseFieldName());

            Object colVal = transformer.getColumnValue(rs, colIdx, field.getJavaFieldType());

            builder.setField(field.getJavaFieldName(), colVal, (Class<Object>)field.getJavaFieldType());
        }

        return builder.build();
    }
    catch (SQLException e) {
        throw new CacheException("Failed to read binary object: " + typeName, e);
    }
}
 
Example #6
Source File: DataStreamerStopCacheTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override public Integer load(Integer key) throws CacheLoaderException {
    // Block loading the key on the second node (non-coordinator).
    if (((IgniteEx)ignite).localNode().order() != 2)
        return key;

    // It is guaranteed that at this point cache gate is already acquired.
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite);

    spi.blockMessages((node, msg) -> msg instanceof GridDhtPartitionsSingleMessage);

    GridTestUtils.runAsync(() -> ignite.destroyCache(DEFAULT_CACHE_NAME));

    try {
        spi.waitForBlocked(1, TIMEOUT);
    }
    catch (InterruptedException e) {
        throw new CacheLoaderException("Failed to wait partition map exchange in " + TIMEOUT + " millis", e);
    }
    finally {
        spi.stopBlock();
    }

    return key;
}
 
Example #7
Source File: GridCacheGetStoreErrorSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param nearEnabled Near cache flag.
 * @param cacheMode Cache mode.
 * @throws Exception If failed.
 */
private void checkGetError(boolean nearEnabled, CacheMode cacheMode) throws Exception {
    this.nearEnabled = nearEnabled;
    this.cacheMode = cacheMode;

    startGridsMultiThreaded(3);

    try {
        GridTestUtils.assertThrows(log, new Callable<Object>() {
            @Override public Object call() throws Exception {
                grid(0).cache(DEFAULT_CACHE_NAME).get(nearKey());

                return null;
            }
        }, CacheLoaderException.class, null);
    }
    finally {
        stopAllGrids();
    }
}
 
Example #8
Source File: GridGeneratingTestStore.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public void loadCache(IgniteBiInClosure<String, String> clo, @Nullable Object... args) {
    if (args.length > 0) {
        try {
            int cnt = ((Number)args[0]).intValue();
            int postfix = ((Number)args[1]).intValue();

            for (int i = 0; i < cnt; i++)
                clo.apply("key" + i, "val." + cacheName + "." + postfix);
        }
        catch (Exception e) {
            X.println("Unexpected exception in loadAll: " + e);

            throw new CacheLoaderException(e);
        }
    }
    else {
        for (int i = 0; i < DFLT_GEN_CNT; i++)
            clo.apply("key" + i, "val." + cacheName + "." + i);
    }
}
 
Example #9
Source File: IgniteCacheLoadRebalanceEvictionSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void loadCache(IgniteBiInClosure<Integer, byte[]> clo,
    @Nullable Object... args) throws CacheLoaderException {

    for (int i = 0; i < ENTRIES_CNT; i++)
        clo.apply(i, data);
}
 
Example #10
Source File: CacheSpringStoreSessionListenerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer load(Integer key) throws CacheLoaderException {
    loadCnt.incrementAndGet();

    checkTransaction();
    checkConnection();

    return null;
}
 
Example #11
Source File: CacheDeploymentTestStoreFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Map<K, IgniteBiTuple<V, ?>> loadAll(Iterable<? extends K> keys) throws CacheLoaderException {
    Map<K, IgniteBiTuple<V, ?>> res = new HashMap<>();

    for (K key : keys) {
        IgniteBiTuple<V, ?> val = map.get(key);

        if (val != null)
            res.put(key, val);
    }

    return res;
}
 
Example #12
Source File: CacheStoreSessionListenerWriteBehindEnabledTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Object load(Object key) throws CacheLoaderException {
    entryCnt.getAndIncrement();

    if (ses.attachment() == null)
        uninitializedListenerCnt.incrementAndGet();

    return null;
}
 
Example #13
Source File: CacheLoader.java    From triava with Apache License 2.0 5 votes vote down vote up
@Override
public Map<K, V> loadAll(Iterable<? extends K> keys) throws CacheLoaderException
{
	Map<K, V> entries = new HashMap<>();
	for (K key : keys)
	{
		entries.put(key, load(key));
	}
	
	return entries;
}
 
Example #14
Source File: CacheHibernatePersonStore.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void loadCache(IgniteBiInClosure<Long, Person> clo, Object... args) {
    if (args == null || args.length == 0 || args[0] == null)
        throw new CacheLoaderException("Expected entry count parameter is not provided.");

    final int entryCnt = (Integer)args[0];

    Session hibSes = ses.attachment();

    try {
        int cnt = 0;

        List list = hibSes.createCriteria(Person.class).
            setMaxResults(entryCnt).
            list();

        if (list != null) {
            for (Object obj : list) {
                Person person = (Person)obj;

                clo.apply(person.id, person);

                cnt++;
            }
        }

        System.out.println(">>> Loaded " + cnt + " values into cache.");
    }
    catch (HibernateException e) {
        throw new CacheLoaderException("Failed to load values from cache store.", e);
    }
}
 
Example #15
Source File: CacheHibernateStoreSessionListenerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer load(Integer key) throws CacheLoaderException {
    loadCnt.incrementAndGet();

    checkSession();

    return null;
}
 
Example #16
Source File: CacheHibernateStoreSessionListenerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer load(Integer key) throws CacheLoaderException {
    loadCnt.incrementAndGet();

    checkSession();

    return null;
}
 
Example #17
Source File: CacheHibernateStoreSessionListenerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer load(Integer key) throws CacheLoaderException {
    loadCnt.incrementAndGet();

    checkSession();

    return null;
}
 
Example #18
Source File: PlatformDotNetCacheStore.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Map<K, V> loadAll(final Iterable<? extends K> keys) {
    try {
        final Map<K, V> loaded = new HashMap<>();

        final Collection keys0 = (Collection)keys;

        doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
            @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
                writer.writeByte(OP_LOAD_ALL);
                writer.writeLong(session());
                writer.writeString(ses.cacheName());

                writer.writeInt(keys0.size());

                for (Object o : keys0)
                    writer.writeObject(o);
            }
        }, new IgniteInClosureX<BinaryRawReaderEx>() {
            @Override public void applyx(BinaryRawReaderEx reader) {
                int cnt = reader.readInt();

                for (int i = 0; i < cnt; i++)
                    loaded.put((K) reader.readObjectDetached(), (V) reader.readObjectDetached());
            }
        });

        return loaded;
    }
    catch (IgniteCheckedException e) {
        throw new CacheLoaderException(e);
    }
}
 
Example #19
Source File: PostgresDBStore.java    From ignite-book-code-samples with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Post load(String key) throws CacheLoaderException {
    Map<String, Object> inputParam = new HashMap<>();
    inputParam.put("id", key);
    return jdbcTemplate.queryForObject("SELECT * FROM POSTS WHERE id=?", inputParam, new RowMapper<Post>() {
        @Override
        public Post mapRow(ResultSet rs, int i) throws SQLException {
            return new Post(rs.getString(1), rs.getString(2), rs.getString(3), rs.getDate(4).toLocalDate(), rs.getString(5));
        }
    });

}
 
Example #20
Source File: IgniteCacheLoadRebalanceEvictionSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Map<Integer, byte[]> loadAll(Iterable<? extends Integer> keys) throws CacheLoaderException {
    Map<Integer, byte[]> res = new HashMap<>();

    for (Integer key : keys)
        res.put(key, data);

    return res;
}
 
Example #21
Source File: IgniteGetNonPlainKeyReadThroughSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Object load(Object key) throws CacheLoaderException {
    if (nullVal)
        return null;
    else
        return key;
}
 
Example #22
Source File: CacheJdbcPojoStore.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected <R> R buildObject(@Nullable String cacheName, String typeName, TypeKind typeKind,
    JdbcTypeField[] flds, Map<String, Integer> loadColIdxs, ResultSet rs)
    throws CacheLoaderException {
    switch (typeKind) {
        case BUILT_IN:
            return (R)buildBuiltinObject(typeName, flds, loadColIdxs, rs);
        case POJO:
            return (R)buildPojoObject(cacheName, typeName, flds, loadColIdxs, rs);
        default:
            return (R)buildBinaryObject(typeName, flds, loadColIdxs, rs);
    }
}
 
Example #23
Source File: CacheJdbcPojoStore.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Construct Java built in object from query result.
 *
 * @param typeName Type name.
 * @param fields Fields descriptors.
 * @param loadColIdxs Select query columns indexes.
 * @param rs ResultSet to take data from.
 * @return Constructed object.
 * @throws CacheLoaderException If failed to construct POJO.
 */
private Object buildBuiltinObject(String typeName, JdbcTypeField[] fields, Map<String, Integer> loadColIdxs,
    ResultSet rs) throws CacheLoaderException {
    JdbcTypeField field = fields[0];

    try {
        Integer colIdx = columnIndex(loadColIdxs, field.getDatabaseFieldName());

        return transformer.getColumnValue(rs, colIdx, field.getJavaFieldType());
    }
    catch (SQLException e) {
        throw new CacheLoaderException("Failed to read object: [cls=" + typeName + ", prop=" + field + "]", e);
    }
}
 
Example #24
Source File: CacheAbstractJdbcStore.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Nullable @Override public V load(K key) throws CacheLoaderException {
    assert key != null;

    EntryMapping em = entryMapping(session().cacheName(), typeIdForObject(key));

    if (log.isDebugEnabled())
        log.debug("Load value from db [table= " + em.fullTableName() + ", key=" + key + ']');

    Connection conn = null;

    PreparedStatement stmt = null;

    try {
        conn = connection();

        stmt = conn.prepareStatement(em.loadQrySingle);

        fillKeyParameters(stmt, em, key);

        ResultSet rs = stmt.executeQuery();

        if (rs.next())
            return buildObject(em.cacheName, em.valueType(), em.valueKind(), em.valueColumns(), em.loadColIdxs, rs);
    }
    catch (SQLException e) {
        throw new CacheLoaderException("Failed to load object [table=" + em.fullTableName() +
            ", key=" + key + "]", e);
    }
    finally {
        end(conn, stmt);
    }

    return null;
}
 
Example #25
Source File: PageEvictionReadThroughTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Object load(Object key) throws CacheLoaderException {
    ThreadLocalRandom r = ThreadLocalRandom.current();

    if (r.nextInt() % 5 == 0)
        return new TestObject(PAGE_SIZE / 4 - 50 + r.nextInt(5000)); // Fragmented object.
    else
        return new TestObject(r.nextInt(PAGE_SIZE / 4 - 50)); // Fits in one page.
}
 
Example #26
Source File: CacheJdbcBlobStore.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public V load(K key) {
    init();

    Transaction tx = transaction();

    if (log.isDebugEnabled())
        log.debug("Store load [key=" + key + ", tx=" + tx + ']');

    Connection conn = null;

    PreparedStatement stmt = null;

    try {
        conn = connection(tx);

        stmt = conn.prepareStatement(loadQry);

        stmt.setObject(1, toBytes(key));

        ResultSet rs = stmt.executeQuery();

        if (rs.next())
            return fromBytes(rs.getBytes(2));
    }
    catch (IgniteCheckedException | SQLException e) {
        throw new CacheLoaderException("Failed to load object: " + key, e);
    }
    finally {
        end(tx, conn, stmt);
    }

    return null;
}
 
Example #27
Source File: CacheGetRemoveSkipStoreTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer load(Integer s) throws CacheLoaderException {
    try {
        if (readSemaphore != null)
            readSemaphore.acquire();
        else
            U.sleep(1000);
    }
    catch (Exception e) {
        throw new CacheLoaderException(e);
    }

    return CONSTANT_VALUE;
}
 
Example #28
Source File: GridCacheAbstractLocalStoreSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Map<K, IgniteBiTuple<V, ?>> loadAll(Iterable<? extends K> keys) throws CacheLoaderException {
    Map<K, IgniteBiTuple<V, ?>> res = new TreeMap<>();

    for (K key : keys) {
        IgniteBiTuple<V, ?> val = map.get(key);

        if (val != null)
            res.put(key, val);
    }

    return res;
}
 
Example #29
Source File: H2CacheStoreStrategy.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Object load(Object key) throws CacheLoaderException {
    try {
        Connection conn = ses.attachment();
        Object res = getFromDb(conn, key);
        updateStats("reads");
        return res;
    }
    catch (SQLException e) {
        throw new CacheLoaderException("Failed to load object [key=" + key + ']', e);
    }
}
 
Example #30
Source File: CacheConcurrentReadThroughTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Integer load(Integer key) throws CacheLoaderException {
    loadCnt.incrementAndGet();

    try {
        Thread.sleep(1000);
    }
    catch (InterruptedException e) {
        e.printStackTrace();
    }

    return key;
}