Search in sources :

Example 16 with CacheWriterException

use of javax.cache.integration.CacheWriterException in project ignite by apache.

the class GridCacheStoreManagerAdapter method putAll.

/** {@inheritDoc} */
@Override
public final boolean putAll(@Nullable IgniteInternalTx tx, Map<? extends KeyCacheObject, IgniteBiTuple<? extends CacheObject, GridCacheVersion>> map) throws IgniteCheckedException {
    if (F.isEmpty(map))
        return true;
    if (map.size() == 1) {
        Map.Entry<? extends KeyCacheObject, IgniteBiTuple<? extends CacheObject, GridCacheVersion>> e = ((Map<? extends KeyCacheObject, IgniteBiTuple<? extends CacheObject, GridCacheVersion>>) map).entrySet().iterator().next();
        return put(tx, e.getKey(), e.getValue().get1(), e.getValue().get2());
    } else {
        if (store != null) {
            EntriesView entries = new EntriesView(map);
            if (log.isDebugEnabled())
                log.debug("Storing values in cache store [entries=" + entries + ']');
            sessionInit0(tx);
            boolean threwEx = true;
            try {
                store.writeAll(entries);
                threwEx = false;
            } catch (ClassCastException e) {
                handleClassCastException(e);
            } catch (Exception e) {
                if (!(e instanceof CacheWriterException))
                    e = new CacheWriterException(e);
                if (!entries.isEmpty()) {
                    List<Object> keys = new ArrayList<>(entries.size());
                    for (Cache.Entry<?, ?> entry : entries) keys.add(entry.getKey());
                    throw new CacheStorePartialUpdateException(keys, e);
                }
                throw new IgniteCheckedException(e);
            } finally {
                sessionEnd0(tx, threwEx);
            }
            if (log.isDebugEnabled())
                log.debug("Stored value in cache store [entries=" + entries + ']');
            return true;
        }
        return false;
    }
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheWriterException(javax.cache.integration.CacheWriterException) CacheLoaderException(javax.cache.integration.CacheLoaderException) NoSuchElementException(java.util.NoSuchElementException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException) List(java.util.List) ArrayList(java.util.ArrayList) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 17 with CacheWriterException

use of javax.cache.integration.CacheWriterException in project ignite by apache.

the class GridCacheStoreManagerAdapter method put.

/** {@inheritDoc} */
@Override
public final boolean put(@Nullable IgniteInternalTx tx, KeyCacheObject key, CacheObject val, GridCacheVersion ver) throws IgniteCheckedException {
    if (store != null) {
        // Never persist internal keys.
        if (key instanceof GridCacheInternal)
            return true;
        Object key0 = cctx.unwrapBinaryIfNeeded(key, !convertBinary());
        Object val0 = cctx.unwrapBinaryIfNeeded(val, !convertBinary());
        if (log.isDebugEnabled()) {
            log.debug(S.toString("Storing value in cache store", "key", key0, true, "val", val0, true));
        }
        sessionInit0(tx);
        boolean threwEx = true;
        try {
            store.write(new CacheEntryImpl<>(key0, locStore ? F.t(val0, ver) : val0));
            threwEx = false;
        } catch (ClassCastException e) {
            handleClassCastException(e);
        } catch (CacheWriterException e) {
            throw new IgniteCheckedException(e);
        } catch (Exception e) {
            throw new IgniteCheckedException(new CacheWriterException(e));
        } finally {
            sessionEnd0(tx, threwEx);
        }
        if (log.isDebugEnabled()) {
            log.debug(S.toString("Stored value in cache store", "key", key0, true, "val", val0, true));
        }
        return true;
    }
    return false;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheInternal(org.apache.ignite.internal.processors.cache.GridCacheInternal) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheWriterException(javax.cache.integration.CacheWriterException) CacheLoaderException(javax.cache.integration.CacheLoaderException) NoSuchElementException(java.util.NoSuchElementException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 18 with CacheWriterException

use of javax.cache.integration.CacheWriterException in project ignite by apache.

the class CacheHibernateBlobStore method write.

/** {@inheritDoc} */
@Override
public void write(javax.cache.Cache.Entry<? extends K, ? extends V> entry) {
    init();
    Transaction tx = transaction();
    K key = entry.getKey();
    V val = entry.getValue();
    if (log.isDebugEnabled())
        log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']');
    if (val == null) {
        delete(key);
        return;
    }
    Session ses = session(tx);
    try {
        CacheHibernateBlobStoreEntry entry0 = new CacheHibernateBlobStoreEntry(toBytes(key), toBytes(val));
        ses.saveOrUpdate(entry0);
    } catch (IgniteCheckedException | HibernateException e) {
        rollback(ses, tx);
        throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e);
    } finally {
        end(ses, tx);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(org.apache.ignite.transactions.Transaction) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session) CacheStoreSession(org.apache.ignite.cache.store.CacheStoreSession) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 19 with CacheWriterException

use of javax.cache.integration.CacheWriterException in project ignite by apache.

the class CacheSpringStoreSessionListener method onSessionStart.

/** {@inheritDoc} */
@Override
public void onSessionStart(CacheStoreSession ses) {
    if (ses.isWithinTransaction() && ses.attachment() == null) {
        try {
            TransactionDefinition def = definition(ses.transaction(), ses.cacheName());
            ses.attach(txMgr.getTransaction(def));
        } catch (TransactionException e) {
            throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
        }
    }
}
Also used : TransactionDefinition(org.springframework.transaction.TransactionDefinition) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionException(org.springframework.transaction.TransactionException) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 20 with CacheWriterException

use of javax.cache.integration.CacheWriterException in project caffeine by ben-manes.

the class CacheProxy method removeAll.

@Override
public void removeAll(Set<? extends K> keys) {
    requireNotClosed();
    keys.forEach(Objects::requireNonNull);
    boolean statsEnabled = statistics.isEnabled();
    long start = statsEnabled ? ticker.read() : 0L;
    Set<K> keysToRemove = new HashSet<>(keys);
    CacheWriterException e = deleteAllToCacheWriter(keysToRemove);
    long removed = keysToRemove.stream().map(this::removeNoCopyOrAwait).filter(Objects::nonNull).count();
    dispatcher.awaitSynchronous();
    if (statsEnabled) {
        statistics.recordRemovals(removed);
        statistics.recordRemoveTime(ticker.read() - start);
    }
    if (e != null) {
        throw e;
    }
}
Also used : Objects(java.util.Objects) HashSet(java.util.HashSet) CacheWriterException(javax.cache.integration.CacheWriterException)

Aggregations

CacheWriterException (javax.cache.integration.CacheWriterException)44 CacheLoaderException (javax.cache.integration.CacheLoaderException)18 Connection (java.sql.Connection)14 SQLException (java.sql.SQLException)13 EntryProcessorException (javax.cache.processor.EntryProcessorException)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 RLock (org.redisson.api.RLock)10 PreparedStatement (java.sql.PreparedStatement)9 Transaction (org.apache.ignite.transactions.Transaction)8 IgniteException (org.apache.ignite.IgniteException)7 CacheStoreSession (org.apache.ignite.cache.store.CacheStoreSession)7 HashMap (java.util.HashMap)6 HibernateException (org.hibernate.HibernateException)6 Session (org.hibernate.Session)6 NoSuchElementException (java.util.NoSuchElementException)4 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)4 CacheStorePartialUpdateException (org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException)4 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)4 RedissonObject (org.redisson.RedissonObject)4 CacheNotExistsException (com.hazelcast.cache.CacheNotExistsException)3