use of javax.cache.integration.CacheWriterException in project ignite by apache.
the class CacheStoreSessionListenerAbstractSelfTest method testRollback.
/**
* @throws Exception If failed.
*/
public void testRollback() throws Exception {
write.set(true);
fail.set(true);
CacheConfiguration<Integer, Integer> cfg1 = cacheConfiguration("cache1", CacheAtomicityMode.TRANSACTIONAL);
CacheConfiguration<Integer, Integer> cfg2 = cacheConfiguration("cache2", CacheAtomicityMode.TRANSACTIONAL);
IgniteCache<Integer, Integer> cache1 = ignite(0).createCache(cfg1);
IgniteCache<Integer, Integer> cache2 = ignite(0).createCache(cfg2);
try (Transaction tx = ignite(0).transactions().txStart()) {
cache1.put(1, 1);
cache2.put(2, 2);
tx.commit();
assert false : "Exception was not thrown.";
} catch (IgniteException e) {
CacheWriterException we = X.cause(e, CacheWriterException.class);
assertNotNull(we);
assertEquals("Expected failure.", we.getMessage());
} finally {
cache1.destroy();
cache2.destroy();
}
try (Connection conn = DriverManager.getConnection(URL)) {
checkTable(conn, 1, true);
checkTable(conn, 2, true);
}
}
use of javax.cache.integration.CacheWriterException in project ignite by apache.
the class GridCacheUtils method convertToCacheException.
/**
* @param e Ignite checked exception.
* @return CacheException runtime exception, never null.
*/
@NotNull
public static RuntimeException convertToCacheException(IgniteCheckedException e) {
IgniteClientDisconnectedCheckedException disconnectedErr = e.getCause(IgniteClientDisconnectedCheckedException.class);
if (disconnectedErr != null) {
assert disconnectedErr.reconnectFuture() != null : disconnectedErr;
e = disconnectedErr;
}
if (e.hasCause(CacheWriterException.class))
return new CacheWriterException(U.convertExceptionNoWrap(e));
if (e instanceof CachePartialUpdateCheckedException)
return new CachePartialUpdateException((CachePartialUpdateCheckedException) e);
else if (e instanceof CacheAtomicUpdateTimeoutCheckedException)
return new CacheAtomicUpdateTimeoutException(e.getMessage(), e);
else if (e instanceof ClusterTopologyServerNotFoundException)
return new CacheServerNotFoundException(e.getMessage(), e);
else if (e instanceof SchemaOperationException)
return new CacheException(e.getMessage(), e);
if (e.getCause() instanceof CacheException)
return (CacheException) e.getCause();
if (e.getCause() instanceof NullPointerException)
return (NullPointerException) e.getCause();
C1<IgniteCheckedException, IgniteException> converter = U.getExceptionConverter(e.getClass());
return converter != null ? new CacheException(converter.apply(e)) : new CacheException(e);
}
use of javax.cache.integration.CacheWriterException in project ignite by apache.
the class GridCacheStoreManagerAdapter method removeAll.
/**
* {@inheritDoc}
*/
@Override
public final boolean removeAll(@Nullable IgniteInternalTx tx, Collection<? extends KeyCacheObject> keys) throws IgniteCheckedException {
if (F.isEmpty(keys))
return true;
if (keys.size() == 1) {
KeyCacheObject key = keys.iterator().next();
return remove(tx, key);
}
if (store != null) {
Collection<Object> keys0 = cctx.unwrapBinariesIfNeeded(keys, !convertBinary());
if (log.isDebugEnabled())
log.debug(S.toString("Removing values from cache store", "keys", keys0, true));
sessionInit0(tx, StoreOperation.WRITE, false);
boolean threwEx = true;
try {
store.deleteAll(keys0);
threwEx = false;
} catch (ClassCastException e) {
handleClassCastException(e);
} catch (Exception e) {
if (!(e instanceof CacheWriterException))
e = new CacheWriterException(e);
if (!keys0.isEmpty())
throw new CacheStorePartialUpdateException(keys0, e);
throw new IgniteCheckedException(e);
} finally {
sessionEnd0(tx, threwEx);
}
if (log.isDebugEnabled())
log.debug(S.toString("Removed values from cache store", "keys", keys0, true));
return true;
}
return false;
}
use of javax.cache.integration.CacheWriterException in project ignite by apache.
the class GridCacheStoreManagerAdapter method remove.
/**
* {@inheritDoc}
*/
@Override
public final boolean remove(@Nullable IgniteInternalTx tx, KeyCacheObject key) throws IgniteCheckedException {
if (store != null) {
// Never remove internal key from store as it is never persisted.
if (key instanceof GridCacheInternal)
return false;
Object key0 = cctx.unwrapBinaryIfNeeded(key, !convertBinary());
if (log.isDebugEnabled())
log.debug(S.toString("Removing value from cache store", "key", key0, true));
sessionInit0(tx, StoreOperation.WRITE, false);
boolean threwEx = true;
try {
store.delete(key0);
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("Removed value from cache store", "key", key0, true));
return true;
}
return false;
}
use of javax.cache.integration.CacheWriterException in project ignite by apache.
the class CacheHibernatePersonStore method write.
/**
* {@inheritDoc}
*/
@Override
public void write(javax.cache.Cache.Entry<? extends Long, ? extends Person> entry) {
Long key = entry.getKey();
Person val = entry.getValue();
System.out.println(">>> Store write [key=" + key + ", val=" + val + ']');
Session hibSes = ses.attachment();
try {
hibSes.saveOrUpdate(val);
} catch (HibernateException e) {
throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e);
}
}
Aggregations