Search in sources :

Example 41 with CacheWriterException

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;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException) 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) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 42 with CacheWriterException

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;
}
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 43 with CacheWriterException

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;
    }
}
Also used : Organization(org.apache.ignite.cache.store.jdbc.model.Organization) H2Dialect(org.apache.ignite.cache.store.jdbc.dialect.H2Dialect) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) OrganizationKey(org.apache.ignite.cache.store.jdbc.model.OrganizationKey) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 44 with CacheWriterException

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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) Connection(java.sql.Connection) 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