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;
}
}
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;
}
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);
}
}
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);
}
}
}
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;
}
}
Aggregations