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


Java UnitOfWork.begin方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:MoodCat,项目名称:MoodCat.me-Core,代码行数:14,代码来源:CallableInUnitOfWork.java

示例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;
}
 
开发者ID:supercargo,项目名称:guice-persist-jooq,代码行数:64,代码来源:JdbcLocalTxnInterceptor.java


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