Package org.springframework.transaction

Examples of org.springframework.transaction.TransactionStatus


    private DataSourceTransactionManager transactionManager;

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
        TransactionStatus transaction = transactionManager.getTransaction(transactionDefinition);

        try {
            Object result = invocation.proceed();

            try {
                if (transaction.isNewTransaction())
                    transactionManager.commit(transaction);
            }
            catch (UnexpectedRollbackException ignore) {}

            return result;
        }
        catch (Exception e) {
            if (transaction.isNewTransaction())
                transactionManager.rollback(transaction);

            throw e;
        }
    }
View Full Code Here


    PlatformTransactionManager txnManager =ctx.getBean(PlatformTransactionManager.class);
    DataSource dataSource = ctx.getBean(DataSource.class);
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    TransactionStatus status = txnManager.getTransaction(new DefaultTransactionDefinition());
    try {
      long id = 1;
      jdbcTemplate.execute("DELETE FROM COP_AUDIT_TRAIL_EVENT");
      System.out.println("wait #1");
      Thread.sleep(10000);
View Full Code Here

public abstract class SpringTransaction {
 
  protected abstract void execute(Connection con) throws Exception;
 
  public void run(PlatformTransactionManager transactionManager, DataSource dataSource, TransactionDefinition def) throws Exception {
    TransactionStatus txnStatus = transactionManager.getTransaction(def);
    try {
      Connection con = DataSourceUtils.getConnection(dataSource);
      try {
        execute(con);
      }
View Full Code Here

    return t[0];
  }

  @Override
  public <T> T run(Transaction<T> txn) throws Exception {
    final TransactionStatus txnStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
    T t = null;
    try {
      t = txn.run();
    }
    catch(Exception e) {
View Full Code Here

            //need to propagate any exceptions back to Spring container
            //so transactions can occur
            if (inMessage.getContent(Exception.class) != null && session != null) {
                PlatformTransactionManager m = jmsConfig.getTransactionManager();
                if (m != null) {
                    TransactionStatus status = m.getTransaction(null);
                    JmsResourceHolder resourceHolder =
                        (JmsResourceHolder) TransactionSynchronizationManager
                            .getResource(jmsConfig.getConnectionFactory());
                    boolean trans = resourceHolder == null
                        || !resourceHolder.containsSession(session);
                    if (status != null && !status.isCompleted() && trans) {
                        Exception ex = inMessage.getContent(Exception.class);
                        if (ex.getCause() instanceof RuntimeException) {
                            throw (RuntimeException)ex.getCause();
                        } else {
                            throw new RuntimeException(ex);
View Full Code Here

            case Supports:
                transactionDefinition.setPropagationBehavior(org.springframework.transaction.TransactionDefinition.PROPAGATION_SUPPORTS);
                break;
        }

        TransactionStatus transactionStatus = transactionManager.getTransaction(transactionDefinition);
        if (!(transactionManager instanceof DefaultTransactionStatus)) {
            throw new IllegalArgumentException("SpringTransactionPolicy only works with a PlatformTransactionManager that uses DefaultTransactionStatus");
        }
        this.transactionStatus = (DefaultTransactionStatus) transactionStatus;
    }
View Full Code Here

 
  /* (non-Javadoc)
   * @see com.apress.prospring.ch12.business.AccountManager#insert(com.apress.prospring.ch12.domain.Account)
   */
  public void insert(final Account account) {
    TransactionStatus status = transactionManager.getTransaction(getDefinition(TransactionDefinition.ISOLATION_READ_COMMITTED));
    try {
      doInsert(account);
      transactionManager.commit(status);
    } catch (Throwable t) {
      transactionManager.rollback(status);
View Full Code Here

  /* (non-Javadoc)
   * @see com.apress.prospring.ch12.business.AccountManager#deposit(int, java.math.BigDecimal)
   */
  public void deposit(final int accountId, final BigDecimal amount) {
    TransactionStatus status = transactionManager.getTransaction(getDefinition(TransactionDefinition.ISOLATION_READ_COMMITTED));
    try {
      doDeposit(accountId, amount);
      transactionManager.commit(status);
    } catch (Throwable t) {
      transactionManager.rollback(status);
View Full Code Here

  /* (non-Javadoc)
   * @see com.apress.prospring.ch12.business.AccountManager#transfer(int, int, java.math.BigDecimal)
   */
  public void transfer(final int sourceAccount, final int targetAccount, final BigDecimal amount) {
    TransactionStatus status = transactionManager.getTransaction(getDefinition(TransactionDefinition.ISOLATION_READ_COMMITTED));
    try {
      doTransfer(sourceAccount, targetAccount, amount);
      transactionManager.commit(status);
    } catch (Throwable t) {
      transactionManager.rollback(status);
View Full Code Here

  public Object execute(TransactionCallback action) throws TransactionException {
    if (this.transactionManager instanceof CallbackPreferringPlatformTransactionManager) {
      return ((CallbackPreferringPlatformTransactionManager) this.transactionManager).execute(this, action);
    }
    else {
      TransactionStatus status = this.transactionManager.getTransaction(this);
      Object result = null;
      try {
        result = action.doInTransaction(status);
      }
      catch (RuntimeException ex) {
View Full Code Here

TOP

Related Classes of org.springframework.transaction.TransactionStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.