Search in sources :

Example 16 with MutableEntry

use of javax.cache.processor.MutableEntry in project ignite by apache.

the class DmlUtils method doDelete.

/**
 * Perform DELETE operation on top of results of SELECT.
 *
 * @param cctx Cache context.
 * @param cursor SELECT results.
 * @param pageSize Batch size for streaming, anything <= 0 for single page operations.
 * @return Results of DELETE (number of items affected AND keys that failed to be updated).
 */
private static UpdateResult doDelete(GridCacheContext cctx, Iterable<List<?>> cursor, int pageSize) throws IgniteCheckedException {
    DmlBatchSender sender = new DmlBatchSender(cctx, pageSize, 1);
    for (List<?> row : cursor) {
        if (row.size() != 2)
            continue;
        Object key = row.get(0);
        ClusterNode node = sender.primaryNodeByKey(key);
        IgniteInClosure<MutableEntry<Object, Object>> rmvC = DmlStatementsProcessor.getRemoveClosure(node, key);
        sender.add(key, new DmlStatementsProcessor.ModifyingEntryProcessor(row.get(1), rmvC), 0);
    }
    sender.flush();
    SQLException resEx = sender.error();
    if (resEx != null) {
        if (!F.isEmpty(sender.failedKeys())) {
            // Don't go for a re-run if processing of some keys yielded exceptions and report keys that
            // had been modified concurrently right away.
            String msg = "Failed to DELETE some keys because they had been modified concurrently " + "[keys=" + sender.failedKeys() + ']';
            SQLException conEx = createJdbcSqlException(msg, IgniteQueryErrorCode.CONCURRENT_UPDATE);
            conEx.setNextException(resEx);
            resEx = conEx;
        }
        throw new IgniteSQLException(resEx);
    }
    return new UpdateResult(sender.updateCount(), sender.failedKeys().toArray(), cursor instanceof QueryCursorImpl ? ((QueryCursorImpl) cursor).partitionResult() : null);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) MutableEntry(javax.cache.processor.MutableEntry) DmlStatementsProcessor(org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor) UpdateResult(org.apache.ignite.internal.processors.query.h2.UpdateResult)

Example 17 with MutableEntry

use of javax.cache.processor.MutableEntry in project ignite by apache.

the class DmlStatementsProcessorTest method checkRemoveEntryClassName.

/**
 * Checks remove-closure class name.
 *
 * @param ver The version of the remote node.
 * @param expClsName Expected class name.
 */
private void checkRemoveEntryClassName(final String ver, String expClsName) {
    ClusterNode node = new GridTestNode() {

        @Override
        public IgniteProductVersion version() {
            return IgniteProductVersion.fromString(ver);
        }
    };
    IgniteInClosure<MutableEntry<Object, Object>> rmvC = DmlStatementsProcessor.getRemoveClosure(node, 0);
    Assert.assertNotNull("Check remove-closure", rmvC);
    Assert.assertEquals("Check remove-closure class name for version " + ver, expClsName, rmvC.getClass().getName());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) MutableEntry(javax.cache.processor.MutableEntry) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Aggregations

MutableEntry (javax.cache.processor.MutableEntry)17 Ignite (org.apache.ignite.Ignite)9 CacheEntryProcessor (org.apache.ignite.cache.CacheEntryProcessor)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 EntryProcessorException (javax.cache.processor.EntryProcessorException)7 IgniteCache (org.apache.ignite.IgniteCache)7 EntryProcessor (javax.cache.processor.EntryProcessor)6 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)4 QueryCursor (org.apache.ignite.cache.query.QueryCursor)4 Transaction (org.apache.ignite.transactions.Transaction)4 Map (java.util.Map)3 CacheEntryEvent (javax.cache.event.CacheEntryEvent)3 IgniteException (org.apache.ignite.IgniteException)3 BinaryObject (org.apache.ignite.binary.BinaryObject)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2