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


Java Transaction.close方法代码示例

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


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

示例1: 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

示例2: checkReadThrough

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param cache Cache.
 * @param key Key.
 * @param concurrency Transaction concurrency.
 * @param isolation Transaction isolation.
 * @throws Exception If failed.
 */
private void checkReadThrough(IgniteCache<Object, Object> cache,
    Object key,
    @Nullable TransactionConcurrency concurrency,
    @Nullable TransactionIsolation isolation) throws Exception {
    putDataInStore(Collections.singletonMap(key, key), cache.getName());

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

    try {
        Object ret = cache.invoke(key, new TestEntryProcessor());

        assertEquals(key, ret);

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

    checkValue(cache.getName(), key, (Integer)key + 1);
}
 
开发者ID:apache,项目名称:ignite,代码行数:32,代码来源:IgniteCacheInvokeReadThroughAbstractTest.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: testSuspendPessimisticTx

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * Test for suspension on pessimistic transaction.
 *
 * @throws Exception If failed.
 */
public void testSuspendPessimisticTx() throws Exception {
    try (Ignite g = startGrid()) {
        IgniteCache<Integer, String> cache = jcache();

        IgniteTransactions txs = g.transactions();

        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            final Transaction tx = txs.txStart(TransactionConcurrency.PESSIMISTIC, isolation);

            cache.put(1, "1");

            GridTestUtils.assertThrowsWithCause(new Callable<Object>() {
                @Override public Object call() throws Exception {
                    tx.suspend();

                    return null;
                }
            }, UnsupportedOperationException.class);

            tx.close();

            assertNull(cache.get(1));
        }
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:31,代码来源:IgnitePessimisticTxSuspendResumeTest.java

示例5: 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

示例6: txClose

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param id Transaction ID.
 * @return Transaction state.
 */
private int txClose(long id) {
    Transaction tx = tx(id);

    try {
        tx.close();

        return tx.state().ordinal();
    }
    finally {
        unregisterTx(id);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:17,代码来源:PlatformTransactions.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: checkTransactionalRead

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * Tests sequential value write and read inside transaction.
 * @param concurrency Transaction concurrency.
 * @param isolation Transaction isolation.
 * @throws IgniteCheckedException If failed
 */
protected void checkTransactionalRead(TransactionConcurrency concurrency, TransactionIsolation isolation)
    throws IgniteCheckedException {
    IgniteCache<String, Integer> cache = jcache(0);

    cache.clear();

    Transaction tx = grid(0).transactions().txStart(concurrency, isolation);

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

        assertEquals("Invalid value after put", 1, cache.get("key").intValue());

        tx.commit();
    }
    finally {
        tx.close();
    }

    assertEquals("Invalid cache size after put", 1, cache.size());

    try {
        tx = grid(0).transactions().txStart(concurrency, isolation);

        assertEquals("Invalid value inside transactional read", Integer.valueOf(1), cache.get("key"));

        tx.commit();
    }
    finally {
        tx.close();
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:39,代码来源:GridCacheAbstractTxReadTest.java

示例10: 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

示例11: checkSinglePut

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param explicitTx Whether or not start implicit tx.
 * @param concurrency Tx concurrency.
 * @param isolation Tx isolation.
 * @throws Exception If failed.
 */
private void checkSinglePut(boolean explicitTx, TransactionConcurrency concurrency, TransactionIsolation isolation)
    throws Exception {
    startGrid();

    try {
        Transaction tx = explicitTx ? grid().transactions().txStart(concurrency, isolation) : null;

        try {
            IgniteCache<Object, Object> cache = jcache();

            cache.putAll(F.asMap(1, "Hello", 2, "World"));

            if (tx != null)
                tx.commit();

            System.out.println(cache.localMetrics());

            assertEquals("Hello", cache.get(1));
            assertEquals("World", cache.get(2));
            assertNull(cache.get(3));
        }
        finally {
            if (tx != null)
                tx.close();
        }
    }
    finally {
        stopAllGrids();
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:37,代码来源:GridCacheColocatedDebugTest.java

示例12: 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

示例13: 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

示例14: checkInvokeSequential0

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @param startVal Whether to put value.
 * @param concurrency Concurrency.
 * @throws Exception If failed.
 */
private void checkInvokeSequential0(boolean startVal, TransactionConcurrency concurrency)
    throws Exception {
    final Object val1 = value(1);
    final Object val2 = value(2);
    final Object val3 = value(3);

    IgniteCache<Object, Object> cache = jcache();

    final Object key = primaryTestObjectKeysForCache(cache, 1).get(0);

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

    try {
        if (startVal)
            cache.put(key, val2);
        else
            assertEquals(null, cache.get(key));

        Object expRes = startVal ? val2 : null;

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

        expRes = startVal ? val3 : val1;

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

        expRes = value(valueOf(expRes) + 1);

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

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

    Object exp = value((startVal ? 2 : 0) + 3);

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

    for (int i = 0; i < gridCount(); i++) {
        if (ignite(i).affinity(cacheName()).isPrimaryOrBackup(grid(i).localNode(), key))
            assertEquals(exp, jcache(i).localPeek(key));
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:53,代码来源:IgniteCacheConfigVariationsFullApiTest.java

示例15: testGetAndPutIfAbsentAsyncOld

import org.apache.ignite.transactions.Transaction; //导入方法依赖的package包/类
/**
 * @throws Exception If failed.
 */
public void testGetAndPutIfAbsentAsyncOld() throws Exception {
    Transaction tx = txShouldBeUsed() ? transactions().txStart() : null;

    IgniteCache<String, Integer> cache = jcache();

    IgniteCache<String, Integer> cacheAsync = cache.withAsync();

    try {
        cacheAsync.getAndPutIfAbsent("key", 1);

        IgniteFuture<Integer> fut1 = cacheAsync.future();

        assertNull(fut1.get());
        assertEquals((Integer)1, cache.get("key"));

        cacheAsync.getAndPutIfAbsent("key", 2);

        IgniteFuture<Integer> fut2 = cacheAsync.future();

        assertEquals((Integer)1, fut2.get());
        assertEquals((Integer)1, cache.get("key"));

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

    if (!storeEnabled())
        return;

    // Check swap.
    cache.put("key2", 1);

    cache.localEvict(Collections.singleton("key2"));

    if (!isLoadPreviousValue())
        cache.get("key2");

    cacheAsync.getAndPutIfAbsent("key2", 3);

    assertEquals((Integer)1, cacheAsync.<Integer>future().get());

    // Check db.
    if (storeEnabled() && isLoadPreviousValue() && !isMultiJvm()) {
        putToStore("key3", 3);

        cacheAsync.getAndPutIfAbsent("key3", 4);

        assertEquals((Integer)3, cacheAsync.<Integer>future().get());
    }

    cache.localEvict(Collections.singleton("key2"));

    if (!isLoadPreviousValue())
        cache.get("key2");

    // Same checks inside tx.
    tx = txShouldBeUsed() ? transactions().txStart() : null;

    try {
        cacheAsync.getAndPutIfAbsent("key2", 3);

        assertEquals(1, cacheAsync.future().get());

        if (tx != null)
            tx.commit();

        assertEquals((Integer)1, cache.get("key2"));
    }
    finally {
        if (tx != null)
            tx.close();
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:81,代码来源:IgniteCacheConfigVariationsFullApiTest.java


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