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);
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);
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 CacheJdbcPojoStoreTest method testWriteRetry.
/**
* @throws Exception If failed.
*/
public void testWriteRetry() throws Exception {
CacheJdbcPojoStore<Object, Object> store = store();
// Special dialect that will skip updates, to test write retry.
store.setDialect(new H2Dialect() {
/** {@inheritDoc} */
@Override
public boolean hasMerge() {
return false;
}
/** {@inheritDoc} */
@Override
public String updateQuery(String tblName, Collection<String> keyCols, Iterable<String> valCols) {
return super.updateQuery(tblName, keyCols, valCols) + " AND 1 = 0";
}
});
inject(store);
Connection conn = store.openConnection(false);
PreparedStatement orgStmt = conn.prepareStatement("INSERT INTO Organization(id, name, city) VALUES (?, ?, ?)");
orgStmt.setInt(1, 1);
orgStmt.setString(2, "name" + 1);
orgStmt.setString(3, "city" + 1);
orgStmt.executeUpdate();
U.closeQuiet(orgStmt);
conn.commit();
OrganizationKey k1 = new OrganizationKey(1);
Organization v1 = new Organization(1, "Name1", "City1");
ses.newSession(null);
try {
store.write(new CacheEntryImpl<>(wrap(k1), wrap(v1)));
fail("CacheWriterException wasn't thrown.");
} catch (CacheWriterException e) {
if (!e.getMessage().startsWith("Failed insert entry in database, violate a unique index or primary key") || e.getSuppressed().length != 2)
throw e;
}
}
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);
}
}
Aggregations