当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.commit方法代码示例

本文整理汇总了Java中org.apache.ignite.transactions.Transaction.commit方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.commit方法的具体用法?Java Transaction.commit怎么用?Java Transaction.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ignite.transactions.Transaction的用法示例。


在下文中一共展示了Transaction.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testLocalQuery

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @throws Exception If test failed.
 */
public void testLocalQuery() throws Exception {
    cache1.clear();

    Transaction tx = ignite1.transactions().txStart();

    try {
        cache1.put(new CacheKey(1), new CacheValue("1"));
        cache1.put(new CacheKey(2), new CacheValue("2"));
        cache1.put(new CacheKey(3), new CacheValue("3"));
        cache1.put(new CacheKey(4), new CacheValue("4"));

        tx.commit();

        info("Committed transaction: " + tx);
    }
    catch (IgniteException e) {
        tx.rollback();

        throw e;
    }

    checkQueryResults(cache1);
    checkQueryResults(cache2);
    checkQueryResults(cache3);
}
 
开发者ID:apache,项目名称:ignite,代码行数:29,代码来源:IgniteCacheReplicatedQuerySelfTest.java

示例2: checkVersion

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param key Key.
 * @param txMode Non null tx mode if explicit transaction should be started.
 * @throws Exception If failed.
 */
private void checkVersion(String key, @Nullable TransactionConcurrency txMode) throws Exception {
    IgniteCache<String, Integer> cache = jcache(0);

    Transaction tx = null;

    if (txMode != null)
        tx = cache.unwrap(Ignite.class).transactions().txStart(txMode, REPEATABLE_READ);

    try {
        cache.put(key, 1);

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    checkEntryVersion(key);
}
 
开发者ID:apache,项目名称:ignite,代码行数:27,代码来源:GridCacheVersionMultinodeTest.java

示例3: checkReadThrough

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param cache Cache.
 * @param c Cache operation Closure.
 * @param concurrency Transaction concurrency.
 * @param isolation Transaction isolation.
 * @param expLoadCnt Expected number of store 'load' calls.
 * @throws Exception If failed.
 */
private void checkReadThrough(IgniteCache<Object, Object> cache,
    IgniteRunnable c,
    @Nullable TransactionConcurrency concurrency,
    @Nullable TransactionIsolation isolation,
    int expLoadCnt) throws Exception {
    TestStore.loadCnt.set(0);

    Transaction tx = isolation != null ? cache.unwrap(Ignite.class).transactions().txStart(concurrency, isolation)
        : null;

    try {
        c.run();

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals(expLoadCnt, TestStore.loadCnt.get());
}
 
开发者ID:apache,项目名称:ignite,代码行数:32,代码来源:IgniteCacheReadThroughStoreCallTest.java

示例4: checkTransformAfterRemove

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param concurrency Concurrency.
 * @throws Exception If failed.
 */
private void checkTransformAfterRemove(TransactionConcurrency concurrency) throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    cache.put("key", 4);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, READ_COMMITTED) : null;

    try {
        cache.remove("key");

        cache.invoke("key", INCR_PROCESSOR);
        cache.invoke("key", INCR_PROCESSOR);
        cache.invoke("key", INCR_PROCESSOR);

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals((Integer)3, cache.get("key"));
}
 
开发者ID:apache,项目名称:ignite,代码行数:29,代码来源:GridCacheAbstractFullApiSelfTest.java

示例5: checkNormalTxFinish

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param tx Transaction.
 * @param commit Commit flag.
 */
private void checkNormalTxFinish(Transaction tx, boolean commit) {
    IgniteInternalTx tx0 = ((TransactionProxyImpl)tx).tx();

    if (commit) {
        tx.commit();

        assertNotNull(fieldValue(tx0, "prepFut"));
        assertNotNull(fieldValue(tx0, "finishFut"));
    }
    else {
        tx.rollback();

        assertNull(fieldValue(tx0, "prepFut"));
        assertNotNull(fieldValue(tx0, "finishFut"));
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:21,代码来源:CacheTxFastFinishTest.java

示例6: doCommit

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
    IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
    Transaction tx = txObj.getTransactionHolder().getTransaction();

    if (status.isDebug() && log.isDebugEnabled())
        log.debug("Committing Ignite transaction: " + tx);

    try {
        tx.commit();
    }
    catch (IgniteException e) {
        throw new TransactionSystemException("Could not commit Ignite transaction", e);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:16,代码来源:SpringTransactionManager.java

示例7: checkInvokeAfterRemove

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param concurrency Concurrency.
 * @throws Exception If failed.
 */
private void checkInvokeAfterRemove(TransactionConcurrency concurrency) throws Exception {
    IgniteCache<Object, Object> cache = jcache();

    Object key = key(1);

    cache.put(key, value(4));

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, READ_COMMITTED) : null;

    try {
        cache.remove(key);

        cache.invoke(key, INCR_PROCESSOR, dataMode);
        cache.invoke(key, INCR_PROCESSOR, dataMode);
        cache.invoke(key, INCR_PROCESSOR, dataMode);

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals(value(3), cache.get(key));
}
 
开发者ID:apache,项目名称:ignite,代码行数:31,代码来源:IgniteCacheConfigVariationsFullApiTest.java

示例8: checkInvokeReturnValue

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param put Whether to put value.
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 * @throws Exception If failed.
 */
private void checkInvokeReturnValue(boolean put,
    TransactionConcurrency concurrency,
    TransactionIsolation isolation)
    throws Exception {
    IgniteCache<Object, Object> cache = jcache();

    Object key = key(1);
    Object val1 = value(1);
    Object val2 = value(2);

    if (!put)
        cache.put(key, val1);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, isolation) : null;

    try {
        if (put)
            cache.put(key, val1);

        cache.invoke(key, INCR_PROCESSOR, dataMode);

        assertEquals(val2, cache.get(key));

        if (tx != null) {
            // Second get inside tx. Make sure read value is not transformed twice.
            assertEquals(val2, cache.get(key));

            tx.commit();
        }
    }
    finally {
        if (tx != null)
            tx.close();
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:42,代码来源:IgniteCacheConfigVariationsFullApiTest.java

示例9: checkTransformReturnValue

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param put Whether to put value.
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 * @throws Exception If failed.
 */
private void checkTransformReturnValue(boolean put,
    TransactionConcurrency concurrency,
    TransactionIsolation isolation)
    throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    if (!put)
        cache.put("key", 1);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, isolation) : null;

    try {
        if (put)
            cache.put("key", 1);

        cache.invoke("key", INCR_PROCESSOR);

        assertEquals((Integer)2, cache.get("key"));

        if (tx != null) {
            // Second get inside tx. Make sure read value is not transformed twice.
            assertEquals((Integer)2, cache.get("key"));

            tx.commit();
        }
    }
    finally {
        if (tx != null)
            tx.close();
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:38,代码来源:GridCacheAbstractFullApiSelfTest.java

示例10: syncOpAsyncCommitCallable

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * Crates callable for sync op with async commit test.
 *
 * @return Callable.
 * @throws Exception If failed.
 */
private Callable<Collection<WeakReference<Object>>> syncOpAsyncCommitCallable() throws Exception {
    return new Callable<Collection<WeakReference<Object>>>() {
        @Override public Collection<WeakReference<Object>> call() throws Exception {
            Collection<WeakReference<Object>> refs = new ArrayList<>();

            Ignite g = startGrid();

            try {
                IgniteCache<Integer, TestValue> cache = g.cache(DEFAULT_CACHE_NAME);

                refs.add(new WeakReference<Object>(cacheContext(cache)));

                Transaction tx = g.transactions().txStart();

                TestValue val = new TestValue(0);

                refs.add(new WeakReference<Object>(val));

                cache.put(0, val);

                tx.commit();
            }
            finally {
                G.stop(g.name(), cancel);
            }

            return refs;
        }
    };
}
 
开发者ID:apache,项目名称:ignite,代码行数:37,代码来源:GridCacheReferenceCleanupSelfTest.java

示例11: asyncOpsAsyncCommitCallable

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * Crates callable for async ops with async commit test.
 *
 * @return Callable.
 * @throws Exception If failed.
 */
private Callable<Collection<WeakReference<Object>>> asyncOpsAsyncCommitCallable() throws Exception {
    return new Callable<Collection<WeakReference<Object>>>() {
        @Override public Collection<WeakReference<Object>> call() throws Exception {
            Collection<WeakReference<Object>> refs = new ArrayList<>();

            Ignite g = startGrid();

            try {
                IgniteCache<Integer, TestValue> cache = g.cache(DEFAULT_CACHE_NAME);

                refs.add(new WeakReference<Object>(cacheContext(cache)));

                Transaction tx = g.transactions().txStart();

                for (int i = 0; i < 1000; i++) {
                    TestValue val = new TestValue(i);

                    refs.add(new WeakReference<Object>(val));

                    cache.putAsync(i, val).get();
                }

                tx.commit();
            }
            finally {
                G.stop(g.name(), cancel);
            }

            return refs;
        }
    };
}
 
开发者ID:apache,项目名称:ignite,代码行数:39,代码来源:GridCacheReferenceCleanupSelfTest.java

示例12: checkFastTxFinish

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param tx Transaction.
 * @param commit Commit flag.
 */
private void checkFastTxFinish(Transaction tx, boolean commit) {
    if (commit)
        tx.commit();
    else
        tx.rollback();

    IgniteInternalTx tx0 = ((TransactionProxyImpl)tx).tx();

    assertNull(fieldValue(tx0, "prepFut"));
    assertTrue(fieldValue(tx0, "finishFut") instanceof GridNearTxFastFinishFuture);
}
 
开发者ID:apache,项目名称:ignite,代码行数:16,代码来源:CacheTxFastFinishTest.java

示例13: execute

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * Perform mutation
 */
public Boolean execute() throws IgniteException {
    // TODO Auto-generated method stub

    IgniteCache<Long, Chromosome> populationCache = ignite.cache(GAGridConstants.POPULATION_CACHE);

    Chromosome chromosome = populationCache.localPeek(key);

    long[] geneKeys = chromosome.getGenes();

    for (int k = 0; k < this.mutatedGeneKeys.size(); k++) {
        {
            geneKeys[k] = this.mutatedGeneKeys.get(k);
        }
    }

    chromosome.setGenes(geneKeys);

    Transaction tx = ignite.transactions().txStart();

    populationCache.put(chromosome.id(), chromosome);

    tx.commit();

    return Boolean.TRUE;
}
 
开发者ID:techbysample,项目名称:gagrid,代码行数:29,代码来源:TruncateSelectionJob.java

示例14: checkIgniteTransform

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 * @throws Exception If failed.
 */
private void checkIgniteTransform(TransactionConcurrency concurrency, TransactionIsolation isolation)
    throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    cache.put("key2", 1);
    cache.put("key3", 3);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, isolation) : null;

    try {
        assertEquals("null", cache.invoke("key1", INCR_IGNITE_PROCESSOR));
        assertEquals("1", cache.invoke("key2", INCR_IGNITE_PROCESSOR));
        assertEquals("3", cache.invoke("key3", RMV_IGNITE_PROCESSOR));

        if (tx != null)
            tx.commit();
    }
    catch (Exception e) {
        e.printStackTrace();

        throw e;
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals((Integer)1, cache.get("key1"));
    assertEquals((Integer)2, cache.get("key2"));
    assertNull(cache.get("key3"));

    for (int i = 0; i < gridCount(); i++)
        assertNull("Failed for cache: " + i, jcache(i).localPeek("key3", ONHEAP));

    cache.remove("key1");
    cache.put("key2", 1);
    cache.put("key3", 3);

    assertEquals("null", cache.invoke("key1", INCR_IGNITE_PROCESSOR));
    assertEquals("1", cache.invoke("key2", INCR_IGNITE_PROCESSOR));
    assertEquals("3", cache.invoke("key3", RMV_IGNITE_PROCESSOR));

    assertEquals((Integer)1, cache.get("key1"));
    assertEquals((Integer)2, cache.get("key2"));
    assertNull(cache.get("key3"));

    for (int i = 0; i < gridCount(); i++)
        assertNull(jcache(i).localPeek("key3", ONHEAP));
}
 
开发者ID:apache,项目名称:ignite,代码行数:55,代码来源:GridCacheAbstractFullApiSelfTest.java

示例15: checkInvoke

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param concurrency Transaction concurrency.
 * @param isolation Transaction isolation.
 * @param incrProcessor Increment processor.
 * @param rmvProseccor Remove processor.
 */
private void checkInvoke(TransactionConcurrency concurrency, TransactionIsolation isolation,
    EntryProcessor<Object, Object, Object> incrProcessor,
    EntryProcessor<Object, Object, Object> rmvProseccor) {
    IgniteCache cache = jcache();

    final Object key1 = key(1);
    final Object key2 = key(2);
    final Object key3 = key(3);

    final Object val1 = value(1);
    final Object val2 = value(2);
    final Object val3 = value(3);

    cache.put(key2, val1);
    cache.put(key3, val3);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, isolation) : null;

    try {
        assertNull(cache.invoke(key1, incrProcessor, dataMode));
        assertEquals(val1, cache.invoke(key2, incrProcessor, dataMode));
        assertEquals(val3, cache.invoke(key3, rmvProseccor));

        if (tx != null)
            tx.commit();
    }
    catch (Exception e) {
        e.printStackTrace();

        throw e;
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals(val1, cache.get(key1));
    assertEquals(val2, cache.get(key2));
    assertNull(cache.get(key3));

    for (int i = 0; i < gridCount(); i++)
        assertNull("Failed for cache: " + i, jcache(i).localPeek(key3, ONHEAP));

    cache.remove(key1);
    cache.put(key2, val1);
    cache.put(key3, val3);

    assertNull(cache.invoke(key1, incrProcessor, dataMode));
    assertEquals(val1, cache.invoke(key2, incrProcessor, dataMode));
    assertEquals(val3, cache.invoke(key3, rmvProseccor));

    assertEquals(val1, cache.get(key1));
    assertEquals(val2, cache.get(key2));
    assertNull(cache.get(key3));

    for (int i = 0; i < gridCount(); i++)
        assertNull(jcache(i).localPeek(key3, ONHEAP));
}
 
开发者ID:apache,项目名称:ignite,代码行数:65,代码来源:IgniteCacheConfigVariationsFullApiTest.java


注:本文中的org.apache.ignite.transactions.Transaction.commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。