Search in sources :

Example 1 with PostgresqlDataTypeFactory

use of org.dbunit.ext.postgresql.PostgresqlDataTypeFactory in project sharding-jdbc by shardingjdbc.

the class DBUnitUtil method getConnection.

/**
 * Get connection.
 * @param dbEnv Database environment
 * @param connection connection
 * @return database connection
 * @throws DatabaseUnitException DatabaseUnitException
 */
public static IDatabaseConnection getConnection(final DatabaseEnvironment dbEnv, final Connection connection) throws DatabaseUnitException {
    switch(dbEnv.getDatabaseType()) {
        case H2:
            return new H2Connection(connection, "PUBLIC");
        case MySQL:
            return new MySqlConnection(connection, null);
        case PostgreSQL:
            DatabaseConnection databaseConnection = new DatabaseConnection(connection);
            databaseConnection.getConfig().setProperty("http://www.dbunit.org/properties/datatypeFactory", new PostgresqlDataTypeFactory());
            return databaseConnection;
        case Oracle:
            return new OracleConnection(connection, "JDBC");
        case SQLServer:
            return new MsSqlConnection(connection);
        default:
            throw new UnsupportedOperationException(dbEnv.getDatabaseType().name());
    }
}
Also used : PostgresqlDataTypeFactory(org.dbunit.ext.postgresql.PostgresqlDataTypeFactory) MsSqlConnection(org.dbunit.ext.mssql.MsSqlConnection) MySqlConnection(org.dbunit.ext.mysql.MySqlConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) OracleConnection(org.dbunit.ext.oracle.OracleConnection) H2Connection(org.dbunit.ext.h2.H2Connection)

Example 2 with PostgresqlDataTypeFactory

use of org.dbunit.ext.postgresql.PostgresqlDataTypeFactory 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

IDatabaseConnection (org.dbunit.database.IDatabaseConnection)2 PostgresqlDataTypeFactory (org.dbunit.ext.postgresql.PostgresqlDataTypeFactory)2 ShardingJdbcException (io.shardingjdbc.core.exception.ShardingJdbcException)1 DatabaseConfig (org.dbunit.database.DatabaseConfig)1 DatabaseConnection (org.dbunit.database.DatabaseConnection)1 H2Connection (org.dbunit.ext.h2.H2Connection)1 H2DataTypeFactory (org.dbunit.ext.h2.H2DataTypeFactory)1 MsSqlConnection (org.dbunit.ext.mssql.MsSqlConnection)1 MsSqlDataTypeFactory (org.dbunit.ext.mssql.MsSqlDataTypeFactory)1 MySqlConnection (org.dbunit.ext.mysql.MySqlConnection)1 MySqlDataTypeFactory (org.dbunit.ext.mysql.MySqlDataTypeFactory)1 Oracle10DataTypeFactory (org.dbunit.ext.oracle.Oracle10DataTypeFactory)1 OracleConnection (org.dbunit.ext.oracle.OracleConnection)1