本文整理了Java中com.googlecode.objectify.Objectify.transactNew()
方法的一些代码示例,展示了Objectify.transactNew()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Objectify.transactNew()
方法的具体详情如下:
包路径:com.googlecode.objectify.Objectify
类名称:Objectify
方法名:transactNew
[英]Executes the work in a new transaction, repeating up to limitTries times when a ConcurrentModificationException is thrown. This requires your Work to be idempotent; otherwise limit tries to 1.
Within Work.run(), obtain the new transactional Objectify instance by calling ObjectifyService.ofy()
[中]在新事务中执行工作,在抛出ConcurrentModificationException时最多重复有限次。这要求你的工作是幂等的;否则,限制将尝试1。
在工作中。run(),通过调用ObjectifyService获取新的事务Objectify实例。ofy()
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
/**
* Delete the segment specified.
* @param name The name of the segment
*/
protected void deleteSegment(final String name) {
ofy().transactNew(4, new Work<Void>() {
@Override
public Void run() {
deleteSegment(ofy(), name);
return null;
}
});
}
/**
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
/**
* Delete this directory.
* @throws IOException If an error occurs
*/
public void delete() throws IOException {
ofy().transactNew(3, new Work<Void>() {
@Override
public Void run() {
Objectify objectify = ofy();
for(String name : listAll())
deleteSegment(objectify, name);
objectify.delete().key(indexKey);
objectify.delete().entities(((GaeLockFactory)lockFactory).getLocks(GaeDirectory.this));
return null;
}
});
}
/**
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(new VoidWork()
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
@Override
public void close() throws LockReleaseFailedException {
try {
ofy().transactNew(3, new Work<Void>() {
@Override
public Void run() {
final GaeLock gaeLock = ofy().load().key(Key.create(indexKey, GaeLock.class, lockName)).now();
if (gaeLock != null && gaeLock.locked) {
log.debug("Unlocking Lock '{}'.", lockName);
gaeLock.locked = false;
ofy().save().entity(gaeLock).now();
} else {
log.warn("Trying to release a non locked Lock '{}'.", lockName);
}
return null;
}
});
} catch (RuntimeException e) {
log.error("Error closing lock:{} error:{}", lockName, e.getMessage(), e);
throw new LockReleaseFailedException("Error closing lock:" + lockName, e);
} finally {
closed = true;
}
}
/*
代码示例来源:origin: instacount/appengine-counter
final Integer numCounterShards = ObjectifyService.ofy().transactNew(new Work<Integer>()
ObjectifyService.ofy().transactNew(new VoidWork()
ObjectifyService.ofy().transactNew(new VoidWork()
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
boolean obtainedLock;
try {
obtainedLock = ofy().transactNew(new Work<Boolean>() {
@Override
public Boolean run() {
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
public static <T> T getOrCreate(final Key<T> key, final ObjectifyBuilder<T> builder) {
final Objectify objectify = ofy();
T t = objectify.load().key(key).now();
if(t == null) {
t = objectify.transactNew(4, new Work<T>() {
@Override
public T run() {
T t = ofy().load().key(key).now();
if(t == null) {
t = builder.newInstance(key);
ofy().save().entity(t).now();
}
return t;
}
});
}
return t;
}
代码示例来源:origin: instacount/appengine-counter
/**
* Test an increment where there is an active parent transaction, but the counter does not exist (ExistingTx: T;
* ExistingCounter: F)
*/
@Test
public void increment_TransactionActive_NoExistingCounter_CounterNotCached()
{
final String counterName = UUID.randomUUID().toString();
// Perform another increment in a Work, but abort it before it can commit.
ObjectifyService.ofy().transactNew(new VoidWork()
{
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
final CounterShardData counterShardData = new CounterShardData(counterShardDataKey);
ObjectifyService.ofy().save().entity(counterShardData);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
}
});
assertThat(this.singleShardShardedCounterService.getCounter(counterName).get().getCount(),
is(BigInteger.valueOf(10L)));
this.assertCounterShardValue(counterName, 10L);
}
代码示例来源:origin: instacount/appengine-counter
/**
* Test an increment where there is an active transaction, but the counter does not exist (ExistingTx: T;
* ExistingCounter: F), and then the transaction aborts after the call to increment.
*/
@Test
public void decrement_Abort_TransactionActive_NoExistingCounter_CounterNotCached()
{
final String counterName = UUID.randomUUID().toString();
try
{
// Perform another increment in a Work, but abort it before it can commit.
ObjectifyService.ofy().transactNew(new VoidWork()
{
@Override
public void vrun()
{
// The actual test.
CounterOperation decrementAmount = singleShardShardedCounterService.decrement(counterName, 10L);
assertThat(decrementAmount.getAppliedAmount(), is(10L));
throw new RuntimeException("Abort the Transaction!");
}
});
}
catch (Exception e)
{
// Eat the Exception.
}
assertThat(this.singleShardShardedCounterService.getCounter(counterName).isPresent(), is(false));
this.assertCounterShardValue(counterName, null);
}
代码示例来源:origin: instacount/appengine-counter
/**
* Test an increment where there is an active parent transaction, but the counter does not exist (ExistingTx: T;
* ExistingCounter: F)
*/
@Test
public void decrement_TransactionActive_NoExistingCounter_CounterNotCached()
{
final String counterName = UUID.randomUUID().toString();
// Perform another increment in a Work, but abort it before it can commit.
ObjectifyService.ofy().transactNew(new VoidWork()
{
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
final CounterShardData counterShardData = new CounterShardData(counterShardDataKey);
ObjectifyService.ofy().save().entity(counterShardData);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
}
});
assertThat(this.singleShardShardedCounterService.getCounter(counterName).get().getCount(), is(BigInteger.TEN));
this.assertCounterShardValue(counterName, 10L);
}
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(new VoidWork()
代码示例来源:origin: instacount/appengine-counter
/**
* Test an increment where there is an active parent transaction, but the counter does not exist (ExistingTx: T;
* ExistingCounter: T)
*/
@Test
public void increment_TransactionActive_ExistingCounter_CounterCached()
{
final String counterName = UUID.randomUUID().toString();
singleShardShardedCounterService.increment(counterName, 1L);
assertThat(this.singleShardShardedCounterService.getCounter(counterName).get().getCount(),
is(BigInteger.valueOf(1L)));
// Perform another increment in a Work, but abort it before it can commit.
ObjectifyService.ofy().transactNew(new VoidWork()
{
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
final CounterShardData counterShardData = new CounterShardData(counterShardDataKey);
ObjectifyService.ofy().save().entity(counterShardData);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
}
});
assertThat(this.singleShardShardedCounterService.getCounter(counterName).get().getCount(),
is(BigInteger.valueOf(11L)));
this.assertCounterShardValue(counterName, 11L);
}
代码示例来源:origin: instacount/appengine-counter
/**
* Test an increment where there is an active parent transaction, but the counter does not exist (ExistingTx: T;
* ExistingCounter: T)
*/
@Test
public void decrement_TransactionActive_ExistingCounter_CounterCached()
{
final String counterName = UUID.randomUUID().toString();
singleShardShardedCounterService.increment(counterName, 10L);
assertThat(this.singleShardShardedCounterService.getCounter(counterName).get().getCount(), is(BigInteger.TEN));
this.assertCounterShardValue(counterName, 10L);
// Perform another increment in a Work, but abort it before it can commit.
ObjectifyService.ofy().transactNew(new VoidWork()
{
@Override
public void vrun()
{
// The actual test.
singleShardShardedCounterService.decrement(counterName, 1L);
}
});
assertThat(this.singleShardShardedCounterService.getCounter(counterName).get().getCount(),
is(BigInteger.valueOf(9L)));
this.assertCounterShardValue(counterName, 9L);
}
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(new VoidWork()
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(1, new VoidWork()
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(new VoidWork()
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(new VoidWork()
ObjectifyService.ofy().transactNew(new VoidWork()
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(new VoidWork()
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(new VoidWork()
代码示例来源:origin: instacount/appengine-counter
ObjectifyService.ofy().transactNew(new VoidWork()
内容来源于网络,如有侵权,请联系作者删除!