Search in sources :

Example 1 with DatabaseConfig

use of org.dbunit.database.DatabaseConfig in project openmrs-core by openmrs.

the class BaseContextSensitiveTest method setupDatabaseConnection.

private IDatabaseConnection setupDatabaseConnection(Connection connection) throws DatabaseUnitException {
    IDatabaseConnection dbUnitConn = new DatabaseConnection(connection);
    if (useInMemoryDatabase()) {
        // Setup the db connection to use H2 config.
        DatabaseConfig config = dbUnitConn.getConfig();
        config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory());
    }
    return dbUnitConn;
}
Also used : IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) H2DataTypeFactory(org.dbunit.ext.h2.H2DataTypeFactory) DatabaseConfig(org.dbunit.database.DatabaseConfig)

Example 2 with DatabaseConfig

use of org.dbunit.database.DatabaseConfig in project openmrs-core by openmrs.

the class CreateConceptDictionaryDataSet method createConceptDictionaryDataSet.

@Test
@SkipBaseSetup
public void createConceptDictionaryDataSet() throws Exception {
    IDatabaseConnection connection = new DatabaseConnection(getConnection());
    DatabaseConfig config = connection.getConfig();
    config.setProperty(DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY, new ForwardOnlyResultSetTableFactory());
    String[] tableNames = new String[] { "concept_class", "concept_datatype", "concept_map_type", "concept_reference_source", "concept", "concept_numeric", "concept_description", "concept_name", "concept_reference_term", "concept_reference_map", "concept_reference_term_map", "concept_set", "concept_complex", "concept_answer", "concept_stop_word" };
    IDataSet dataSet = connection.createDataSet(tableNames);
    FlatXmlDataSet.write(dataSet, new FileOutputStream("target/conceptDictionaryDataSet.xml"));
}
Also used : FileOutputStream(java.io.FileOutputStream) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) ForwardOnlyResultSetTableFactory(org.dbunit.database.ForwardOnlyResultSetTableFactory) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) DatabaseConfig(org.dbunit.database.DatabaseConfig) Test(org.junit.Test)

Example 3 with DatabaseConfig

use of org.dbunit.database.DatabaseConfig in project openmrs-core by openmrs.

the class TestUtil method printOutTableContents.

/**
 * Print the contents of the given tableName to system.out<br>
 * <br>
 * Call this from any {@link BaseContextSensitiveTest} child by:
 * TestUtil.printOutTableContents(getConnection(), "encounter");
 *
 * @param sqlConnection the connection to use
 * @param tableNames the name(s) of the table(s) to print out
 * @throws Exception
 */
public static void printOutTableContents(Connection sqlConnection, String... tableNames) throws Exception {
    for (String tableName : tableNames) {
        System.out.println("The contents of table: " + tableName);
        IDatabaseConnection connection = new DatabaseConnection(sqlConnection);
        DatabaseConfig config = connection.getConfig();
        config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
        QueryDataSet outputSet = new QueryDataSet(connection);
        outputSet.addTable(tableName);
        FlatXmlDataSet.write(outputSet, System.out);
    }
}
Also used : HsqldbDataTypeFactory(org.dbunit.ext.hsqldb.HsqldbDataTypeFactory) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) QueryDataSet(org.dbunit.database.QueryDataSet) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConfig(org.dbunit.database.DatabaseConfig)

Example 4 with DatabaseConfig

use of org.dbunit.database.DatabaseConfig in project sharding-jdbc by shardingjdbc.

the class ShardingJdbcDatabaseTester method getConnection.

@Override
public IDatabaseConnection getConnection() throws Exception {
    IDatabaseConnection result = super.getConnection();
    DatabaseConfig dbConfig = result.getConfig();
    dbConfig.setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, false);
    dbConfig.setProperty(DatabaseConfig.FEATURE_DATATYPE_WARNING, false);
    switch(driverClass) {
        case "org.h2.Driver":
            dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory());
            break;
        case "com.mysql.jdbc.Driver":
            dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
            break;
        case "org.postgresql.Driver":
            dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory());
            break;
        case "oracle.jdbc.driver.OracleDriver":
            dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new Oracle10DataTypeFactory());
            break;
        case "com.microsoft.sqlserver.jdbc.SQLServerDriver":
            dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MsSqlDataTypeFactory());
            break;
        default:
            throw new ShardingJdbcException("Unsupported JDBC driver '%s'", driverClass);
    }
    return result;
}
Also used : PostgresqlDataTypeFactory(org.dbunit.ext.postgresql.PostgresqlDataTypeFactory) MySqlDataTypeFactory(org.dbunit.ext.mysql.MySqlDataTypeFactory) Oracle10DataTypeFactory(org.dbunit.ext.oracle.Oracle10DataTypeFactory) ShardingJdbcException(io.shardingjdbc.core.exception.ShardingJdbcException) MsSqlDataTypeFactory(org.dbunit.ext.mssql.MsSqlDataTypeFactory) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) H2DataTypeFactory(org.dbunit.ext.h2.H2DataTypeFactory) DatabaseConfig(org.dbunit.database.DatabaseConfig)

Aggregations

DatabaseConfig (org.dbunit.database.DatabaseConfig)4 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)4 DatabaseConnection (org.dbunit.database.DatabaseConnection)3 H2DataTypeFactory (org.dbunit.ext.h2.H2DataTypeFactory)2 ShardingJdbcException (io.shardingjdbc.core.exception.ShardingJdbcException)1 FileOutputStream (java.io.FileOutputStream)1 ForwardOnlyResultSetTableFactory (org.dbunit.database.ForwardOnlyResultSetTableFactory)1 QueryDataSet (org.dbunit.database.QueryDataSet)1 IDataSet (org.dbunit.dataset.IDataSet)1 HsqldbDataTypeFactory (org.dbunit.ext.hsqldb.HsqldbDataTypeFactory)1 MsSqlDataTypeFactory (org.dbunit.ext.mssql.MsSqlDataTypeFactory)1 MySqlDataTypeFactory (org.dbunit.ext.mysql.MySqlDataTypeFactory)1 Oracle10DataTypeFactory (org.dbunit.ext.oracle.Oracle10DataTypeFactory)1 PostgresqlDataTypeFactory (org.dbunit.ext.postgresql.PostgresqlDataTypeFactory)1 Test (org.junit.Test)1