Search in sources :

Example 11 with DatabaseType

use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.

the class AbstractSQLTest method init.

private static synchronized void init() {
    try {
        Properties prop = new Properties();
        prop.load(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/env.properties"));
        boolean initialized = null == prop.getProperty("initialized") ? false : Boolean.valueOf(prop.getProperty("initialized"));
        String databases = prop.getProperty("databases");
        if (!Strings.isNullOrEmpty(databases)) {
            for (String each : databases.split(",")) {
                databaseTypes.add(findDatabaseType(each.trim()));
            }
        }
        if (initialized) {
            createSchema(DatabaseType.H2);
        } else {
            for (DatabaseType each : getDatabaseTypes()) {
                createSchema(each);
            }
        }
    } catch (final IOException ex) {
        ex.printStackTrace();
    }
}
Also used : DatabaseType(io.shardingjdbc.core.constant.DatabaseType) IOException(java.io.IOException) Properties(java.util.Properties)

Example 12 with DatabaseType

use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.

the class AbstractSQLTest method importDataSet.

protected final void importDataSet() throws Exception {
    for (DatabaseType databaseType : getDatabaseTypes()) {
        if (databaseType == getCurrentDatabaseType() || null == getCurrentDatabaseType()) {
            DatabaseEnvironment dbEnv = new DatabaseEnvironment(databaseType);
            for (String each : getInitDataSetFiles()) {
                InputStream is = AbstractSQLTest.class.getClassLoader().getResourceAsStream(each);
                IDataSet dataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(is));
                IDatabaseTester databaseTester = new ShardingJdbcDatabaseTester(dbEnv.getDriverClassName(), dbEnv.getURL(getDatabaseName(each)), dbEnv.getUsername(), dbEnv.getPassword(), dbEnv.getSchema(getDatabaseName(each)));
                databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
                databaseTester.setDataSet(dataSet);
                databaseTester.onSetup();
            }
        }
    }
}
Also used : DatabaseEnvironment(io.shardingjdbc.core.common.env.DatabaseEnvironment) DatabaseType(io.shardingjdbc.core.constant.DatabaseType) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IDatabaseTester(org.dbunit.IDatabaseTester) IDataSet(org.dbunit.dataset.IDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) ShardingJdbcDatabaseTester(io.shardingjdbc.core.common.env.ShardingJdbcDatabaseTester)

Example 13 with DatabaseType

use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.

the class AbstractHintTest method initShardingDataSources.

protected final Map<DatabaseType, ShardingDataSource> initShardingDataSources() throws SQLException {
    Map<DatabaseType, Map<String, DataSource>> dataSourceMap = createDataSourceMap();
    for (Map.Entry<DatabaseType, Map<String, DataSource>> each : dataSourceMap.entrySet()) {
        ShardingRule shardingRule = getShardingRule(each);
        getShardingDataSources().put(each.getKey(), new ShardingDataSource(each.getValue(), shardingRule));
    }
    return getShardingDataSources();
}
Also used : DatabaseType(io.shardingjdbc.core.constant.DatabaseType) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) Map(java.util.Map)

Example 14 with DatabaseType

use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.

the class RoutingDatabaseOnlyWithHintForDMLTest method assertInsertWithPartialPlaceholders.

@Test
public void assertInsertWithPartialPlaceholders() throws SQLException, DatabaseUnitException {
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        for (int i = 1; i <= 10; i++) {
            try (HintShardingValueHelper helper = new HintDatabaseShardingValueHelper(i);
                Connection connection = each.getValue().getConnection();
                PreparedStatement preparedStatement = connection.prepareStatement(String.format(DatabaseTestSQL.INSERT_WITH_PARTIAL_PLACEHOLDERS_SQL, i, i))) {
                preparedStatement.setString(1, "insert");
                preparedStatement.executeUpdate();
            }
        }
        assertDataSet(each.getValue().getConnection(), each.getKey(), "insert", "insert");
    }
}
Also used : HintShardingValueHelper(io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper) DatabaseType(io.shardingjdbc.core.constant.DatabaseType) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) Connection(java.sql.Connection) ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) PreparedStatement(java.sql.PreparedStatement) HintDatabaseShardingValueHelper(io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintDatabaseShardingValueHelper) Map(java.util.Map) AbstractRoutingDatabaseOnlyWithHintTest(io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractRoutingDatabaseOnlyWithHintTest) Test(org.junit.Test)

Example 15 with DatabaseType

use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.

the class ShardingDatabaseOnlyWithHintForDMLTest method assertInsertWithPartialPlaceholders.

@Test
public void assertInsertWithPartialPlaceholders() throws SQLException, DatabaseUnitException {
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        for (int i = 1; i <= 10; i++) {
            try (HintShardingValueHelper helper = new HintShardingValueHelper(i, i);
                Connection connection = each.getValue().getConnection()) {
                PreparedStatement preparedStatement = connection.prepareStatement(String.format(DatabaseTestSQL.INSERT_WITH_PARTIAL_PLACEHOLDERS_SQL, i, i));
                preparedStatement.setString(1, "insert");
                preparedStatement.executeUpdate();
            }
        }
        assertDataSet(each.getValue().getConnection(), each.getKey(), "insert", "insert");
    }
}
Also used : HintShardingValueHelper(io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper) DatabaseType(io.shardingjdbc.core.constant.DatabaseType) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) Connection(java.sql.Connection) ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) PreparedStatement(java.sql.PreparedStatement) Map(java.util.Map) Test(org.junit.Test) AbstractShardingDatabaseOnlyWithHintTest(io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractShardingDatabaseOnlyWithHintTest)

Aggregations

DatabaseType (io.shardingjdbc.core.constant.DatabaseType)21 ShardingDataSource (io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource)16 Map (java.util.Map)16 Test (org.junit.Test)9 HintShardingValueHelper (io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper)8 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)7 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)6 TableRuleConfiguration (io.shardingjdbc.core.api.config.TableRuleConfiguration)6 AbstractShardingDatabaseOnlyWithHintTest (io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractShardingDatabaseOnlyWithHintTest)6 SQLShardingRule (io.shardingjdbc.core.integrate.jaxb.SQLShardingRule)5 ShardingConnection (io.shardingjdbc.core.jdbc.core.connection.ShardingConnection)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)4 LinkedList (java.util.LinkedList)4 AbstractRoutingDatabaseOnlyWithHintTest (io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractRoutingDatabaseOnlyWithHintTest)3 HintDatabaseShardingValueHelper (io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintDatabaseShardingValueHelper)3 ComplexShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration)2 NoneShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration)2 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)2