本文整理汇总了Java中org.apache.ignite.transactions.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于org.apache.ignite.transactions包,在下文中一共展示了Transaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: sessionEnd
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void sessionEnd(boolean commit) throws CacheWriterException {
Transaction transaction = session.transaction();
if (transaction == null) {
return;
}
Map<Object, Object> properties = session.properties();
if (!commit) {
Map bigBuffer = (Map) properties.get(BUFFER_PROPERTY_NAME);
if (bigBuffer != null) {
bigBuffer.remove(cacheName);
}
}
Set<String> caches = (Set<String>) properties.get(CACHES_PROPERTY_NAME);
if (caches != null && caches.remove(cacheName) && caches.isEmpty()) {
Map<String, Collection<Cache.Entry<?, ?>>> buffer =
(Map<String, Collection<Cache.Entry<?, ?>>>) properties.get(BUFFER_PROPERTY_NAME);
notifyListeners(nextTransactionId(), buffer);
}
}
开发者ID:epam,项目名称:Lagerta,代码行数:24,代码来源:DataCapturerBus.java
示例2: sessionEnd
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void sessionEnd(boolean commit) throws CacheWriterException {
Transaction transaction = session.transaction();
if (transaction == null) {
return;
}
Map<Object, Object> properties = session.properties();
if (!commit) {
Map bigBuffer = (Map)properties.get(BUFFER_PROPERTY_NAME);
if (bigBuffer != null) {
bigBuffer.remove(cacheName);
}
}
Set<String> caches = (Set<String>)properties.get(CACHES_PROPERTY_NAME);
if (caches != null && caches.remove(cacheName) && caches.isEmpty()) {
Map<String, Collection<Cache.Entry<?, ?>>> buffer =
(Map<String, Collection<Cache.Entry<?, ?>>>)properties.get(BUFFER_PROPERTY_NAME);
notifyListeners(nextTransactionId(), buffer);
}
}
开发者ID:epam,项目名称:Lagerta,代码行数:21,代码来源:ActiveCacheStore.java
示例3: commit
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
@Override public void commit(List<Long> txIds,
IgniteClosure<Long, Map.Entry<List<IgniteBiTuple<String, ?>>, List<Object>>> txSupplier,
IgniteInClosure<Long> onSingleCommit) {
for (final Long txId : txIds) {
Map.Entry<List<IgniteBiTuple<String, ?>>, List<Object>> currentTx = txSupplier.apply(txId);
List<IgniteBiTuple<String, ?>> keys = currentTx.getKey();
List<Object> values = currentTx.getValue();
try (Transaction tx = ignite.transactions().txStart()) {
for (int i = 0; i < keys.size(); i++) {
IgniteBiTuple<String, ?> compositeKey = keys.get(i);
ignite.cache(compositeKey.getKey()).put(compositeKey.getValue(), values.get(i));
tx.commit();
}
}
onSingleCommit.apply(txId);
}
}
开发者ID:epam,项目名称:Lagerta,代码行数:18,代码来源:IgniteCommitter.java
示例4: process
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void process(final Map<?, ?> entries) {
long processingStartTime = System.currentTimeMillis();
ignite.compute().run(new IgniteRunnable() {
@IgniteInstanceResource
private Ignite localIgnite;
@Override public void run() {
IgniteCache cache = localIgnite.cache(cacheName);
if (transactional) {
try (Transaction tx = localIgnite.transactions().txStart()) {
process(cache, entries);
}
}
else {
process(cache, entries);
}
}
});
Statistics.recordOperation(System.currentTimeMillis() - processingStartTime);
}
开发者ID:epam,项目名称:Lagerta,代码行数:23,代码来源:ServerSideEntryProcessor.java
示例5: putAll
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* Performs preparation for or actual write to persistence storage.
*
* @param entries changed in cache.
*/
private void putAll(Collection<Cache.Entry<?, ?>> entries) {
if (isOnDRCluster()) {
return;
}
Transaction transaction = session.transaction();
if (transaction == null) {
notifyListeners(nextTransactionId(), Collections.singletonMap(cacheName, entries));
}
else {
Collection<Cache.Entry<?, ?>> cacheBuffer = getBuffer();
for (Cache.Entry<?, ?> entry : entries) {
cacheBuffer.add(entry);
}
}
}
开发者ID:epam,项目名称:Lagerta,代码行数:21,代码来源:ActiveCacheStore.java
示例6: sessionEnd
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void sessionEnd(boolean commit) throws CacheWriterException {
Transaction transaction = session.transaction();
if (transaction == null) {
return;
}
Map<Object, Object> properties = session.properties();
if (!commit) {
Map bigBuffer = (Map)properties.get(BUFFER_PROPERTY_NAME);
if (bigBuffer != null) {
bigBuffer.remove(cacheName);
}
}
Set<String> caches = (Set<String>)properties.get(CACHES_PROPERTY_NAME);
if (caches != null && caches.remove(cacheName) && caches.isEmpty() && !isOnDRCluster()) {
Map<String, Collection<Cache.Entry<?, ?>>> buffer =
(Map<String, Collection<Cache.Entry<?, ?>>>)properties.get(BUFFER_PROPERTY_NAME);
notifyListeners(nextTransactionId(), buffer);
}
}
开发者ID:epam,项目名称:Lagerta,代码行数:21,代码来源:ActiveCacheStore.java
示例7: singleCommit
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
protected void singleCommit(TransactionSupplier txSupplier, IgniteInClosure<Long> onSingleCommit, long txId) {
TransactionDataIterator it = txSupplier.dataIterator(txId);
try (Transaction tx = ignite.transactions().txStart()) {
while (it.hasNextCache()) {
IgniteCache<Object, Object> cache = ignite.cache(it.nextCache());
while (it.hasNextEntry()) {
it.advance();
Object value = it.getValue();
if (ActiveCacheStore.TOMBSTONE.equals(value)) {
cache.remove(it.getKey());
} else {
cache.put(it.getKey(), value);
}
}
}
tx.commit();
}
onSingleCommit.apply(txId);
}
开发者ID:epam,项目名称:Lagerta,代码行数:22,代码来源:AbstractIgniteCommitter.java
示例8: deposit
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* Make deposit into specified account number.
*
* @param accountNumber Bank account number.
* @param amount Amount to deposit.+
* @throws IgniteException If failed.
*/
private static void deposit(IgniteCache<Integer, BankAccount> cache, int accountNumber,
double amount) throws IgniteException {
try (Transaction tx = Ignition.ignite().transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
BankAccount bankAccount = cache.get(accountNumber);
// Deposit into account.
bankAccount.deposit(amount);
// Store updated account in cache.
cache.put(accountNumber, bankAccount);
tx.commit();
}
logger.info("");
logger.info("|--Deposit amount: $" + amount + "--|");
}
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:25,代码来源:SimpleTransactions.java
示例9: withdraw
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* Make withdraw from specified account number.
*
* @param accountNumber Bank Account number.
* @param amount Amount to withdraw.-
* @throws IgniteException If failed.
*/
private static void withdraw(IgniteCache<Integer, BankAccount> cache, int accountNumber,
double amount) throws IgniteException {
try (Transaction tx = Ignition.ignite().transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
BankAccount bankAccount = cache.get(accountNumber);
// Deposit into account.
bankAccount.withdraw(amount);
// Store updated account in cache.
cache.put(accountNumber, bankAccount);
tx.commit();
}
logger.info("");
logger.info("|--Withdraw amount: $" + amount + "--|");
}
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:25,代码来源:SimpleTransactions.java
示例10: 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
示例11: txAsync
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* @param cache Cache.
* @param concurrency Transaction concurrency.
* @param isolation Transaction isolcation.
* @param c Closure to run in transaction.
* @throws Exception If failed.
*/
private void txAsync(final IgniteCache<Integer, Integer> cache,
final TransactionConcurrency concurrency,
final TransactionIsolation isolation,
final IgniteClosure<IgniteCache<Integer, Integer>, Void> c) throws Exception {
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override public Void call() throws Exception {
IgniteTransactions txs = cache.unwrap(Ignite.class).transactions();
try (Transaction tx = txs.txStart(concurrency, isolation)) {
c.apply(cache);
tx.commit();
}
return null;
}
}, "async-thread");
fut.get();
}
开发者ID:apache,项目名称:ignite,代码行数:28,代码来源:CacheSerializableTransactionsTest.java
示例12: testTransactionalRemove
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* @param concurrency Transaction concurrency level.
* @param isolation Transaction isolation level.
*/
private void testTransactionalRemove(TransactionConcurrency concurrency, TransactionIsolation isolation) {
IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME);
Random r = new Random();
try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) {
for (int i = 0; i < CNT; ++i) {
int key = r.nextInt();
cache.put(key, "test-value");
cache.remove(key, "test-value");
}
tx.commit();
}
}
开发者ID:apache,项目名称:ignite,代码行数:22,代码来源:CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java
示例13: putAndCheckEntrySet
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* @param cache Cache.
* @throws Exception If failed.
*/
private void putAndCheckEntrySet(IgniteCache<Object, Object> cache) throws Exception {
try (Transaction tx = cache.unwrap(Ignite.class).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
Integer total = (Integer) cache.get(TX_KEY);
if (total == null)
total = 0;
int cntr = 0;
for (Cache.Entry e : cache) {
if (e.getKey() instanceof Integer)
cntr++;
}
assertEquals(total, (Integer)cntr);
cache.put(cntr + 1, cntr + 1);
cache.put(TX_KEY, cntr + 1);
tx.commit();
}
}
开发者ID:apache,项目名称:ignite,代码行数:28,代码来源:GridCacheEntrySetAbstractSelfTest.java
示例14: testTxPutUpdate
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/** */
public void testTxPutUpdate() throws Exception {
executeWithAllTxCaches(new TestClosure() {
@Override public void run() throws Exception {
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
cache.put(key1, okValue);
cache.put(key2, okValue);
cache.put(key2, badValue);
tx.commit();
}
assertEquals(0, cache.size());
return null;
}
}, CacheException.class, ERR_MSG);
}
});
}
开发者ID:apache,项目名称:ignite,代码行数:23,代码来源:IgniteSqlNotNullConstraintTest.java
示例15: testTxPutIfAbsent
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/** */
public void testTxPutIfAbsent() throws Exception {
executeWithAllTxCaches(new TestClosure() {
@Override public void run() throws Exception {
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
cache.putIfAbsent(key1, badValue);
tx.commit();
}
assertEquals(0, cache.size());
return null;
}
}, CacheException.class, ERR_MSG);
}
});
}
开发者ID:apache,项目名称:ignite,代码行数:21,代码来源:IgniteSqlNotNullConstraintTest.java
示例16: testTxGetAndPut
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/** */
public void testTxGetAndPut() throws Exception {
executeWithAllTxCaches(new TestClosure() {
@Override public void run() throws Exception {
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
cache.getAndPut(key1, badValue);
tx.commit();
}
assertEquals(0, cache.size());
return null;
}
}, CacheException.class, ERR_MSG);
}
});
}
开发者ID:apache,项目名称:ignite,代码行数:21,代码来源:IgniteSqlNotNullConstraintTest.java
示例17: checkPeekTxRemove
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* @param concurrency Concurrency.
* @throws Exception If failed.
*/
private void checkPeekTxRemove(TransactionConcurrency concurrency) throws Exception {
if (txShouldBeUsed()) {
Ignite ignite = primaryIgnite("key");
IgniteCache<String, Integer> cache = ignite.cache(cacheName());
cache.put("key", 1);
try (Transaction tx = ignite.transactions().txStart(concurrency, READ_COMMITTED)) {
cache.remove("key");
assertNull(cache.get("key")); // localPeek ignores transactions.
assertNotNull(cache.localPeek("key")); // localPeek ignores transactions.
tx.commit();
}
}
}
开发者ID:apache,项目名称:ignite,代码行数:22,代码来源:IgniteCacheConfigVariationsFullApiTest.java
示例18: testTxInvoke
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/** */
public void testTxInvoke() throws Exception {
executeWithAllTxCaches(new TestClosure() {
@Override public void run() throws Exception {
cache.put(key1, okValue);
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception {
try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
cache.invoke(key1, new TestEntryProcessor(badValue));
tx.commit();
}
return null;
}
}, EntryProcessorException.class, ERR_MSG);
assertEquals(1, cache.size());
assertEquals(okValue, cache.get(key1));
}
});
}
开发者ID:apache,项目名称:ignite,代码行数:24,代码来源:IgniteSqlNotNullConstraintTest.java
示例19: testPutGet
import org.apache.ignite.transactions.Transaction; //导入依赖的package包/类
/**
* @throws Exception If failed.
*/
public void testPutGet() throws Exception {
IgniteCache<Object, Object> cache = jcache(grid(0), cacheConfiguration(), Object.class, Object.class);
Map map = new HashMap();
try (Transaction tx = grid(0).transactions().txStart(TransactionConcurrency.PESSIMISTIC,
TransactionIsolation.REPEATABLE_READ, 100000, 1000)) {
for (int i = 4; i < 400; i++) {
map.put("key" + i, new TestEntity("value"));
map.put(i, "value");
}
cache.putAll(map);
tx.commit();
}
for (int i = 0; i < 100; i++) {
cache.get("key" + i);
cache.get(i);
}
}
开发者ID:apache,项目名称:ignite,代码行数:27,代码来源:GridCacheOffheapIndexGetSelfTest.java
示例20: 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
注:本文中的org.apache.ignite.transactions.Transaction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论