Search in sources :

Example 31 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)

Example 32 with CacheWriterException

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);
}
Also used : CacheAtomicUpdateTimeoutException(org.apache.ignite.cache.CacheAtomicUpdateTimeoutException) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) CacheException(javax.cache.CacheException) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) CacheWriterException(javax.cache.integration.CacheWriterException) NotNull(org.jetbrains.annotations.NotNull)

Example 33 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, 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;
}
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 34 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, 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;
}
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 35 with CacheWriterException

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);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) Person(org.apache.ignite.examples.model.Person) CacheStoreSession(org.apache.ignite.cache.store.CacheStoreSession) Session(org.hibernate.Session) CacheWriterException(javax.cache.integration.CacheWriterException)

Aggregations

CacheWriterException (javax.cache.integration.CacheWriterException)45 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