本文整理汇总了Java中com.google.inject.persist.UnitOfWork.begin方法的典型用法代码示例。如果您正苦于以下问题:Java UnitOfWork.begin方法的具体用法?Java UnitOfWork.begin怎么用?Java UnitOfWork.begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.persist.UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.begin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import com.google.inject.persist.UnitOfWork; //导入方法依赖的package包/类
@Override
public V call() throws Exception {
final UnitOfWork work = workProvider.get();
try {
work.begin();
return callable.call();
} catch (final Throwable t) {
log.error(t.getMessage(), t);
throw t;
} finally {
work.end();
}
}
示例2: invoke
import com.google.inject.persist.UnitOfWork; //导入方法依赖的package包/类
public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
UnitOfWork unitOfWork = unitOfWorkProvider.get();
JooqPersistService jooqProvider = jooqPersistServiceProvider.get();
// Should we start a unit of work?
if (!jooqProvider.isWorking()) {
unitOfWork.begin();
didWeStartWork.set(true);
}
Transactional transactional = readTransactionMetadata(methodInvocation);
DefaultConnectionProvider conn = jooqProvider.getConnectionWrapper();
// Allow 'joining' of transactions if there is an enclosing @Transactional method.
if (!conn.getAutoCommit()) {
return methodInvocation.proceed();
}
logger.debug("Disabling JDBC auto commit for this thread");
conn.setAutoCommit(false);
Object result;
try {
result = methodInvocation.proceed();
} catch (Exception e) {
//commit transaction only if rollback didn't occur
if (rollbackIfNecessary(transactional, e, conn)) {
logger.debug("Committing JDBC transaction");
conn.commit();
}
logger.debug("Enabling auto commit for this thread");
conn.setAutoCommit(true);
//propagate whatever exception is thrown anyway
throw e;
} finally {
// Close the em if necessary (guarded so this code doesn't run unless catch fired).
if (null != didWeStartWork.get() && conn.getAutoCommit()) {
didWeStartWork.remove();
unitOfWork.end();
}
}
// everything was normal so commit the txn (do not move into try block above as it
// interferes with the advised method's throwing semantics)
try {
logger.debug("Committing JDBC transaction");
conn.commit();
logger.debug("Enabling auto commit for this thread");
conn.setAutoCommit(true);
} finally {
//close the em if necessary
if (null != didWeStartWork.get()) {
didWeStartWork.remove();
unitOfWork.end();
}
}
//or return result
return result;
}