Search in sources :

Example 11 with DatabaseConnection

use of org.dbunit.database.DatabaseConnection in project head by mifos.

the class DatabaseTestUtils method cleanAndInsertDataSet.

private void cleanAndInsertDataSet(DriverManagerDataSource dataSource, IDataSet dataSet) throws DatabaseUnitException, SQLException {
    Connection jdbcConnection = null;
    ReplacementDataSet replacementDataSet = getDataSetWithNullsReplaced(dataSet);
    try {
        jdbcConnection = DataSourceUtils.getConnection(dataSource);
        IDatabaseConnection databaseConnection = new DatabaseConnection(jdbcConnection);
        databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);
        DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, replacementDataSet);
    } finally {
        if (null != jdbcConnection) {
            jdbcConnection.close();
        }
        DataSourceUtils.releaseConnection(jdbcConnection, dataSource);
    }
}
Also used : ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection)

Example 12 with DatabaseConnection

use of org.dbunit.database.DatabaseConnection in project head by mifos.

the class DataSetUpgradeUtil method upgrade.

private void upgrade(String fileName, ApplicationContext applicationContext) throws Exception {
    System.out.println("Upgrading: " + fileName);
    dbUnitUtilities = new DbUnitUtilities();
    IDataSet dataSet = null;
    try {
        dataSet = dbUnitUtilities.getDataSetFromFile(fileName);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Class.forName("com.mysql.jdbc.Driver");
    Connection jdbcConnection = null;
    try {
        // TODO use same db cxn info that Mifos uses! (local.properties)
        jdbcConnection = DriverManager.getConnection(getUrl(databaseName, port, params), user, password);
        jdbcConnection.setAutoCommit(false);
        resetDatabase(databaseName, jdbcConnection);
        SqlExecutor.execute(new FileInputStream(schemaFileName), jdbcConnection);
        jdbcConnection.commit();
        jdbcConnection.setAutoCommit(true);
        IDatabaseConnection databaseConnection = new DatabaseConnection(jdbcConnection);
        databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.FALSE);
        DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
    System.setProperty(TestingService.TEST_MODE_SYSTEM_PROPERTY, "acceptance");
    ApplicationInitializer applicationInitializer = new ApplicationInitializer();
    applicationInitializer.dbUpgrade(applicationContext);
    applicationContext.getBean(DatabaseUpgradeSupport.class).contraction();
    applicationInitializer.setAttributesOnContext(null);
    StaticHibernateUtil.closeSession();
    System.out.println(" upgrade done!");
}
Also used : Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) ApplicationInitializer(org.mifos.framework.ApplicationInitializer) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) DatabaseUpgradeSupport(org.mifos.db.upgrade.DatabaseUpgradeSupport) IOException(java.io.IOException) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) FileInputStream(java.io.FileInputStream)

Aggregations

DatabaseConnection (org.dbunit.database.DatabaseConnection)12 Connection (java.sql.Connection)11 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)10 IDataSet (org.dbunit.dataset.IDataSet)8 FileOutputStream (java.io.FileOutputStream)4 File (java.io.File)3 DataSourceDatabaseTester (org.dbunit.DataSourceDatabaseTester)2 IDatabaseTester (org.dbunit.IDatabaseTester)2 FilteredDataSet (org.dbunit.dataset.FilteredDataSet)2 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)2 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ITable (org.dbunit.dataset.ITable)1 ReplacementDataSet (org.dbunit.dataset.ReplacementDataSet)1 DatabaseUpgradeSupport (org.mifos.db.upgrade.DatabaseUpgradeSupport)1 ApplicationInitializer (org.mifos.framework.ApplicationInitializer)1 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)1