Example usage for javax.transaction.xa XAException addSuppressed

List of usage examples for javax.transaction.xa XAException addSuppressed

Introduction

In this page you can find the example usage for javax.transaction.xa XAException addSuppressed.

Prototype

public final synchronized void addSuppressed(Throwable exception) 

Source Link

Document

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Usage

From source file:org.everit.blobstore.jdbc.test.AbstractJdbcBlobstoreTest.java

@Before
public void before() {
    DatabaseAccessParametersDTO databaseAccessParameters = resolveDatabaseAccessParameters();

    skipped = databaseAccessParameters == null;
    Assume.assumeFalse("Tests are not enabled for database " + getDatabaseTestAttributes().dbName, skipped);

    try {/* ww w  . jav a2 s  .  c o  m*/
        transactionManager = new GeronimoTransactionManager(6000);
    } catch (XAException e) {
        throw new RuntimeException(e);
    }

    XADataSource xaDataSource = createXADataSource(databaseAccessParameters);

    managedDataSource = createManagedDataSource(transactionManager, xaDataSource);

    try (Connection connection = managedDataSource.getConnection()) {
        DatabaseConnection databaseConnection = new JdbcConnection(connection);

        Liquibase liquibase = new Liquibase("META-INF/liquibase/org.everit.blobstore.jdbc.changelog.xml",
                new ClassLoaderResourceAccessor(), databaseConnection);

        String sqlOutputFolder = System.getProperty("blobstore.sql.outputFolder");
        if (sqlOutputFolder != null) {
            File folder = new File(sqlOutputFolder);
            folder.mkdirs();

            File outputFile = new File(folder, "blobstore-" + getDatabaseTestAttributes().dbName + ".sql");

            try (FileWriter fw = new FileWriter(outputFile, true)) {

                liquibase.update((Contexts) null, fw);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        liquibase.update((Contexts) null);
    } catch (LiquibaseException | SQLException e) {
        try {
            managedDataSource.close();
        } catch (SQLException e1) {
            e.addSuppressed(e1);
        }
        throw new RuntimeException(e);
    }

    blobstore = new JdbcBlobstore(managedDataSource);

    transactionPropagator = new JTATransactionPropagator(transactionManager);

}

From source file:org.everit.email.store.ri.EmailStoreTest.java

@Before
public void before() {
    GeronimoTransactionManager transactionManager = null;
    try {//from  w w  w .  j  a  va 2  s . c  o  m
        transactionManager = new GeronimoTransactionManager(6000);
    } catch (XAException e) {
        throw new RuntimeException(e);
    }
    managedDataSource = createManagedDataSource(transactionManager, createXADatasource());

    try (Connection connection = managedDataSource.getConnection()) {
        DatabaseConnection databaseConnection = new JdbcConnection(connection);

        Liquibase liquibase = new Liquibase("META-INF/liquibase/email.store.ri.liquibase.xml",
                new ClassLoaderResourceAccessor(), databaseConnection);

        liquibase.update((Contexts) null);
    } catch (LiquibaseException | SQLException e) {
        try {
            managedDataSource.close();
        } catch (SQLException e1) {
            e.addSuppressed(e1);
        }
        throw new RuntimeException(e);
    }

    blobstore = new MemBlobstore(transactionManager);

    transactionPropagator = new JTATransactionPropagator(transactionManager);

    querydslSupport = new QuerydslSupportImpl(new Configuration(H2Templates.DEFAULT), managedDataSource);
    emailStore = new EmailStoreImpl(querydslSupport, transactionPropagator, blobstore);
}