javax.transaction.Transactional类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(364)

本文整理了Java中javax.transaction.Transactional类的一些代码示例,展示了Transactional类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transactional类的具体详情如下:
包路径:javax.transaction.Transactional
类名称:Transactional

Transactional介绍

暂无

代码示例

代码示例来源:origin: netgloo/spring-boot-samples

@Repository
@Transactional
public class UserDao {
 @Autowired
 private SessionFactory _sessionFactory;

代码示例来源:origin: jersey/jersey

@Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199)
@Interceptor
@Transactional
@JerseyVetoed
public final class WebAppExceptionInterceptor implements Serializable {

代码示例来源:origin: netgloo/spring-boot-samples

/**
 * Repository for the entity Person.
 * 
 * @see netgloo.models.UserBaseRepository
 */
@Transactional
public interface PersonRepository extends UserBaseRepository<Person> { }

代码示例来源:origin: com.expanset.hk2/hk2-persistence

protected boolean needRollback(Transactional ann, Throwable e) 
    throws Exception {
  assert ann != null;
  assert e != null;
  
  if(transactionManager.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
    return true;
  }
  
  if(ann.dontRollbackOn() != null) {
    for(Class<?> dontRollback : ann.dontRollbackOn()) {
      if(dontRollback.isAssignableFrom(e.getClass())) {
        return false;
      }
    }
  }
  if(ann.rollbackOn() != null) {
    for(Class<?> rollback : ann.rollbackOn()) {
      if(rollback.isAssignableFrom(e.getClass())) {
        return true;
      }
    }
  }
  if(ann.rollbackOn() == null || ann.rollbackOn().length == 0) {
    return true;
  }
  
  return false;
}

代码示例来源:origin: org.seedstack.seed/seed-core

private TransactionMetadata readTransactionMetadata(MethodInvocation methodInvocation) {
  Method method = methodInvocation.getMethod();
  TransactionMetadata defaults = defaultTransactionMetadata();
  TransactionMetadata target = defaultTransactionMetadata();
  for (TransactionMetadataResolver transactionMetadataResolver : transactionMetadataResolvers) {
    target.mergeFrom(transactionMetadataResolver.resolve(methodInvocation, defaults));
  }
  Optional<Transactional> nativeTransactional = TransactionalResolver.INSTANCE.apply(method);
  if (nativeTransactional.isPresent()) {
    target.mergeFrom(nativeTransactional.get());
  } else if (TransactionPlugin.JTA_12_OPTIONAL.isPresent()) {
    Optional<javax.transaction.Transactional> transactionalOptional = JtaTransactionalResolver.INSTANCE
        .apply(method);
    if (transactionalOptional.isPresent()) {
      javax.transaction.Transactional transactional = transactionalOptional.get();
      target.setPropagation(Propagation.valueOf(transactional.value().name()));
      if (transactional.rollbackOn().length > 0) {
        target.setRollbackOn(asExceptions(transactional.rollbackOn()));
      }
      if (transactional.dontRollbackOn().length > 0) {
        target.setNoRollbackFor(asExceptions(transactional.dontRollbackOn()));
      }
    }
  }
  return target;
}

代码示例来源:origin: org.apache.aries.transaction/org.apache.aries.transaction.blueprint

private static TxType getType(Transactional jtaT) {
  return (jtaT != null) ? jtaT.value() : null;
}

代码示例来源:origin: org.apache.tomee/openejb-core

@Interceptor
@Transactional(Transactional.TxType.MANDATORY)
@Priority(Interceptor.Priority.PLATFORM_BEFORE + 200)
public class MandatoryInterceptor extends InterceptorBase {
  @AroundInvoke
  public Object intercept(final InvocationContext ic) throws Exception {
    return super.intercept(ic);
  }

  @Override
  protected TransactionPolicy getPolicy() throws SystemException, ApplicationException {
    return new TxMandatory(getTransactionManager());
  }
}

代码示例来源:origin: netgloo/spring-boot-samples

/**
 * Repository for the entity Company.
 * 
 * @see netgloo.models.UserBaseRepository
 */
@Transactional
public interface CompanyRepository extends UserBaseRepository<Company> { }

代码示例来源:origin: org.jboss.narayana.jts/narayana-jts-idlj

protected void handleException(InvocationContext ic, Exception e, Transaction tx) throws Exception {
  Transactional transactional = getTransactional(ic);
  for (Class<?> dontRollbackOnClass : transactional.dontRollbackOn()) {
    if (dontRollbackOnClass.isAssignableFrom(e.getClass())) {
      throw e;
    }
  }
  for (Class<?> rollbackOnClass : transactional.rollbackOn()) {
    if (rollbackOnClass.isAssignableFrom(e.getClass())) {
      tx.setRollbackOnly();
      throw e;
    }
  }
  if (e instanceof RuntimeException) {
    tx.setRollbackOnly();
    throw e;
  }
  throw e;
}

代码示例来源:origin: net.unit8.enkan/enkan-component-doma2

private Transactional.TxType getTransactionType(Method m) {
  Transactional transactional = m.getDeclaredAnnotation(Transactional.class);
  return transactional != null ? transactional.value() : null;
}

代码示例来源:origin: spring-projects/spring-security

@Transactional
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {ApplicationConfig.class, SecurityConfig.class})
public class Issue50Tests {
  @Autowired
  private AuthenticationManager authenticationManager;
  @Autowired
  private UserRepository userRepo;

代码示例来源:origin: org.apache.tomee/openejb-core

@Interceptor
@Transactional(Transactional.TxType.REQUIRES_NEW)
@Priority(Interceptor.Priority.PLATFORM_BEFORE + 200)
public class RequiredNewInterceptor extends InterceptorBase {
  @AroundInvoke
  public Object intercept(final InvocationContext ic) throws Exception {
    return super.intercept(ic);
  }

  @Override
  protected TransactionPolicy getPolicy() throws SystemException, ApplicationException {
    return new TxRequiresNew(getTransactionManager());
  }
}

代码示例来源:origin: netgloo/spring-boot-samples

/**
 * Repository for the entity User.
 * 
 * @see netgloo.models.UserBaseRepository
 */
@Transactional
public interface UserRepository extends UserBaseRepository<User> { }

代码示例来源:origin: org.jboss.narayana.jta/cdi

protected void handleException(InvocationContext ic, Exception e, Transaction tx) throws Exception {
  Transactional transactional = getTransactional(ic);
  for (Class<?> dontRollbackOnClass : transactional.dontRollbackOn()) {
    if (dontRollbackOnClass.isAssignableFrom(e.getClass())) {
      throw e;
    }
  }
  for (Class<?> rollbackOnClass : transactional.rollbackOn()) {
    if (rollbackOnClass.isAssignableFrom(e.getClass())) {
      tx.setRollbackOnly();
      throw e;
    }
  }
  if (e instanceof RuntimeException) {
    tx.setRollbackOnly();
    throw e;
  }
  throw e;
}

代码示例来源:origin: net.unit8.enkan/kotowari

private Transactional.TxType getTransactionType(Method m) {
  Transactional transactional = m.getDeclaredAnnotation(Transactional.class);
  return transactional != null ? transactional.value() : null;
}

代码示例来源:origin: kaaproject/kaa

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/common-dao-test-context.xml")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Transactional
public class HibernateNotificationSchemaDaoTest extends HibernateAbstractTest {
 @Autowired
 private NotificationSchemaDao<NotificationSchema> notificationSchemaDao;

代码示例来源:origin: org.apache.tomee/openejb-core

@Interceptor
@Transactional(Transactional.TxType.REQUIRED)
@Priority(Interceptor.Priority.PLATFORM_BEFORE + 200)
public class RequiredInterceptor extends InterceptorBase {
  @AroundInvoke
  public Object intercept(final InvocationContext ic) throws Exception {
    return super.intercept(ic);
  }

  @Override
  protected TransactionPolicy getPolicy() throws SystemException {
    return new TxRequired(getTransactionManager());
  }
}

代码示例来源:origin: spring-projects/spring-framework

@javax.transaction.Transactional(javax.transaction.Transactional.TxType.SUPPORTS)
interface ITestJta {
  @javax.transaction.Transactional
  int getAge();
  void setAge(int age);
  String getName();
  void setName(String name);
}

代码示例来源:origin: jbosstm/narayana

protected void handleException(InvocationContext ic, Exception e, Transaction tx) throws Exception {
  Transactional transactional = getTransactional(ic);
  for (Class<?> dontRollbackOnClass : transactional.dontRollbackOn()) {
    if (dontRollbackOnClass.isAssignableFrom(e.getClass())) {
      throw e;
    }
  }
  for (Class<?> rollbackOnClass : transactional.rollbackOn()) {
    if (rollbackOnClass.isAssignableFrom(e.getClass())) {
      tx.setRollbackOnly();
      throw e;
    }
  }
  if (e instanceof RuntimeException) {
    tx.setRollbackOnly();
    throw e;
  }
  throw e;
}

代码示例来源:origin: kawasima/enkan

private Transactional.TxType getTransactionType(Method m) {
  Transactional transactional = m.getDeclaredAnnotation(Transactional.class);
  return transactional != null ? transactional.value() : null;
}

相关文章