Example usage for org.springframework.transaction.support DefaultTransactionDefinition DefaultTransactionDefinition

List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition DefaultTransactionDefinition

Introduction

In this page you can find the example usage for org.springframework.transaction.support DefaultTransactionDefinition DefaultTransactionDefinition.

Prototype

public DefaultTransactionDefinition() 

Source Link

Document

Create a new DefaultTransactionDefinition, with default settings.

Usage

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

/**
 * ArchDiff line.// www  .j a  va2  s .  c om
 *
 * @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.wlami.mibox.server.util.SpringTxHelper.java

/**
 * Start a spring transaction./*  w  w  w  .ja v  a  2  s  . c om*/
 * 
 * @param transactionName
 * @return
 */
public static TransactionStatus startTransaction(String transactionName,
        JpaTransactionManager jpaTransactionManager) {
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setName(transactionName);
    definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus transactionStatus = jpaTransactionManager.getTransaction(definition);
    return transactionStatus;
}

From source file:org.mybatis.spring.transaction.SpringTransactionManagerTest.java

@Test
public void shouldNoOpWithTx() throws Exception {
    DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
    txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
    TransactionStatus status = txManager.getTransaction(txDef);

    SpringManagedTransactionFactory transactionFactory = new SpringManagedTransactionFactory();
    SpringManagedTransaction transaction = (SpringManagedTransaction) transactionFactory
            .newTransaction(dataSource, null, false);
    transaction.getConnection();//from  ww  w  .j ava  2 s  .com
    transaction.commit();
    transaction.close();
    assertEquals("should not call commit on Connection", 0, connection.getNumberCommits());
    assertFalse("should not close the Connection", connection.isClosed());

    txManager.commit(status);
}

From source file:com.github.akiraly.db4j.CommonDbConfig.java

@Bean
public TransactionTemplate transactionTemplate(PlatformTransactionManager transactionManager) {
    DefaultTransactionDefinition td = new DefaultTransactionDefinition();
    td.setTimeout(30);//w w w.j  av a  2  s  .c  o  m
    return new TransactionTemplate(transactionManager, td);
}

From source file:com.logAnything.tvShows.service.TVShowServiceImpl.java

@Override
public int createNewShow(TVShow tvShow) {
    TransactionDefinition def = new DefaultTransactionDefinition();
    TransactionStatus status = transactionManager.getTransaction(def);
    int responseCode = 0;

    //check if show title already exists.
    if (showExists(tvShow.getTitle())) {
        return SHOW_EXISTS;
    }// w  w  w  .ja  v a 2 s.c om

    try {
        //This might cause data integrity issues, but in single user instance it should not be a problem.
        int newTvId = tvInfoDao.getNextId();
        tvShow.setId(newTvId);
        tvInfoDao.createNewShow(tvShow);
        Episode episode = createEpisode(tvShow);
        episodesDao.createNewEpisode(episode);
        transactionManager.commit(status);
    } catch (Exception ex) {
        responseCode = -1;
        transactionManager.rollback(status);
    }
    return responseCode;
}

From source file:org.molasdin.wbase.spring.transaction.SpringTransactionProvider.java

@Override
public Transaction<T> newTransaction(TransactionDescriptor descriptor) {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    if (descriptor.isolation() != null) {
        def.setIsolationLevel(descriptor.isolation().jdbcCode());
    }//from w  ww  . j av  a2 s . c  o  m
    TransactionStatus status = tx.getTransaction(def);

    return new SpringTransaction<T>(newEngine(), tx, status);
}

From source file:net.chrisrichardson.ormunit.hibernate.RollbackTransactionHibernatePersistenceTestsStrategy.java

public void onSetUp() {
    status = transactionManager.getTransaction(new DefaultTransactionDefinition());
}

From source file:com.thinkenterprise.domain.BoundedContextInitializer.java

@PostConstruct
public void init() {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("InitTx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    TransactionStatus status = txManager.getTransaction(def);
    try {/* w  ww  .  j a v  a 2s. c  o  m*/
        initRoutes();
    } catch (Exception ex) {
        txManager.rollback(status);
        throw ex;
    }
    txManager.commit(status);
}

From source file:com.googlecode.starflow.engine.transaction.SpringTransactionPolicy.java

@Override
public TransactionStatus begin() {
    if (transactionManager != null) {
        DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
        TransactionStatus txStatus = transactionManager.getTransaction(definition);
        return txStatus;
    } else {//from  w w  w.  ja v a 2  s  .c  om
        return null;
    }
}

From source file:es.urjc.mctwp.service.ServiceDelegate.java

private TransactionStatus getTxStatus(String action, boolean readOnly, String isolation, String propagation) {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();

    def.setName(action);/*  w  ww  .  j av a  2s.  c om*/

    //Set readOnly configuration
    def.setReadOnly(readOnly);

    //Set isolation configuration
    if (isolation.equals(Command.ISOLATION_DEFAULT)) {
        def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_DEFAULT);
    }

    //Set propagation configuration
    if (propagation.equals(Command.PROPAGATION_REQUIRED)) {
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRED);
    }

    return txManager.getTransaction(def);
}