Example usage for org.springframework.transaction PlatformTransactionManager commit

List of usage examples for org.springframework.transaction PlatformTransactionManager commit

Introduction

In this page you can find the example usage for org.springframework.transaction PlatformTransactionManager commit.

Prototype

void commit(TransactionStatus status) throws TransactionException;

Source Link

Document

Commit the given transaction, with regard to its status.

Usage

From source file:org.openvpms.tools.archetype.loader.ArchetypeLoader.java

/**
 * ArchDiff line.//w  w  w  .j  a va 2  s .com
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    BasicConfigurator.configure();

    try {
        JSAP parser = createParser();
        JSAPResult config = parser.parse(args);
        if (!config.success()) {
            displayUsage(parser, config);
        } else {
            String contextPath = config.getString("context");

            ApplicationContext context;
            if (!new File(contextPath).exists()) {
                context = new ClassPathXmlApplicationContext(contextPath);
            } else {
                context = new FileSystemXmlApplicationContext(contextPath);
            }

            IArchetypeService service = (IArchetypeService) context.getBean("archetypeService");
            ArchetypeLoader loader = new ArchetypeLoader(service);
            String file = config.getString("file");
            String dir = config.getString("dir");
            boolean recurse = config.getBoolean("subdir");
            loader.setOverwrite(config.getBoolean("overwrite"));
            loader.setFailOnError(config.getBoolean("failOnError"));
            loader.setVerbose(config.getBoolean("verbose"));
            boolean clean = config.getBoolean("clean");
            String mappingFile = config.getString("mappingFile");
            int processed = 0;

            PlatformTransactionManager mgr;
            mgr = (PlatformTransactionManager) context.getBean("txnManager");
            TransactionStatus status = mgr.getTransaction(new DefaultTransactionDefinition());
            try {
                if (clean) {
                    loader.clean();
                    ++processed;
                }
                if (mappingFile != null) {
                    loader.loadAssertions(mappingFile);
                    ++processed;
                }
                if (file != null) {
                    loader.loadArchetypes(file);
                    ++processed;
                } else if (dir != null) {
                    loader.loadArchetypes(dir, recurse);
                    ++processed;
                }
                mgr.commit(status);
                if (processed == 0) {
                    displayUsage(parser, config);
                }
            } catch (Throwable throwable) {
                log.error(throwable, throwable);
                log.error("Rolling back changes");
                mgr.rollback(status);
            }
        }
    } catch (Throwable throwable) {
        log.error(throwable, throwable);
    }
}

From source file:com.googlecode.starflow.engine.support.TriggerProcessEventUtil.java

/**
 * ?/*from w w w . jav a  2 s. c  o m*/
 * 
 * @param processInstId
 * @param action
 * @return
 */
private static void executeLogicInNewTransaction(ProcessDefine processDefine, ProcessInstance processInstance,
        IAction action) {
    PlatformTransactionManager txManager = ApplicationContextHolder.getBean(PlatformTransactionManager.class);
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    TransactionStatus status = txManager.getTransaction(definition);
    try {
        action.execute(processDefine, processInstance);
        txManager.commit(status);
    } catch (Exception e) {
        txManager.rollback(status);
        throw new ProcessEngineException("?", e);
    }
}

From source file:com.googlecode.starflow.engine.support.TriggerActivityEventUtil.java

/**
 * ?//from w w  w .  ja  v  a2s.c om
 * 
 * @param activityXml
 * @param activityInst
 * @param action
 * @return
 */
private static void executeLogicInNewTransaction(ActivityElement activityXml, ActivityInst activityInst,
        IAction action) {
    PlatformTransactionManager txManager = ApplicationContextHolder.getBean(PlatformTransactionManager.class);
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    TransactionStatus status = txManager.getTransaction(definition);
    try {
        action.execute(activityXml, activityInst);
        txManager.commit(status);
    } catch (Exception e) {
        txManager.rollback(status);
        throw new ProcessEngineException("?", e);
    }
}

From source file:com.opensymphony.able.filter.TransactionOutcome.java

/**
 * Marks that a transaction should be committed. If this method is not
 * called then the transaction wil be rolled back to avoid accidental
 * updates./*from  w w  w.  ja v a 2s. c  o m*/
 */
public void enableCommit() {
    if (delayCommit) {
        shouldCommit = true;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Committing the transaction with rollback status: " + status.isRollbackOnly());
        }
        PlatformTransactionManager transactionManager = transactionTemplate.getTransactionManager();
        transactionManager.commit(status);
    }
}

From source file:org.dbflute.utflute.spring.SpringTransactionResource.java

public void commit() {
    if (_transactionManagerList.isEmpty()) {
        return;//from  w  w w  .j  av a  2s .c  o m
    }
    final OneTransactionElement mainTx = _transactionManagerList.get(0); // because of TransactionSynchronization
    try {
        final PlatformTransactionManager manager = mainTx.getTransactionManager();
        final TransactionStatus status = mainTx.getTransactionStatus();
        manager.commit(status);
    } catch (RuntimeException e) {
        throw new TransactionFailureException("Failed to commit the transaction.", e);
    }
}

From source file:bigbank.transaction.MultiTransactionStatus.java

void commit(PlatformTransactionManager transactionManager) {
    TransactionStatus transactionStatus = getTransactionStatus(transactionManager);
    transactionManager.commit(transactionStatus);
}

From source file:org.jboss.arquillian.transaction.spring.provider.AbstractSpringTransactionProvider.java

/**
 * {@inheritDoc}// ww w  .  j ava 2s. co  m
 */
@Override
public void commitTransaction(TransactionalTest transactionalTest) {

    PlatformTransactionManager transactionManager = transactionManagerInstance.get();
    TransactionStatus transactionStatus = transactionStatusInstance.get();

    // commits the transaction
    transactionManager.commit(transactionStatus);
}

From source file:com.becool.base.spring.tx.MultiTransactionStatus.java

public void commit(PlatformTransactionManager transactionManager) {
    TransactionStatus transactionStatus = getTransactionStatus(transactionManager);
    transactionManager.commit(transactionStatus);
}

From source file:com.alibaba.cobar.client.transaction.MultipleDataSourcesTransactionManager.java

@Override
protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
    @SuppressWarnings("unchecked")
    List<DefaultTransactionStatus> list = (List<DefaultTransactionStatus>) status.getTransaction();

    logger.info("prepare to commit transactions on multiple data sources.");
    Validate.isTrue(list.size() <= this.getTransactionManagers().size());

    TransactionException lastException = null;
    for (int i = list.size() - 1; i >= 0; i--) {
        PlatformTransactionManager transactionManager = this.getTransactionManagers().get(i);
        TransactionStatus localTransactionStatus = list.get(i);

        try {// w  w w  .j  a v a2s  . c o m
            transactionManager.commit(localTransactionStatus);
        } catch (TransactionException e) {
            lastException = e;
            logger.error("Error in commit", e);

        }
    }
    if (lastException != null) {
        throw lastException;
        // Rollback will ensue as long as rollbackOnCommitFailure=true
    }

}

From source file:com.zhengmo.data.transaction.MultiTransactionStatus.java

/**
 * ???./*  ww  w . jav a 2  s  . co  m*/
 * @param transactionManager ?
 */
public void commit(PlatformTransactionManager transactionManager) {
    TransactionStatus transactionStatus = getTransactionStatus(transactionManager);
    transactionManager.commit(transactionStatus);
}