Search in sources :

Example 16 with DatabaseType

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

the class ShardingDatabaseOnlyWithHintForSelectTest method assertSelectBetweenWithSingleTable.

@Test
public void assertSelectBetweenWithSingleTable() throws SQLException, DatabaseUnitException {
    String sql = SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.SELECT_BETWEEN_WITH_SINGLE_TABLE_SQL);
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        assertDataSet("integrate/dataset/sharding/db/expect/select/SelectBetweenWithSingleTable.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12), ShardingOperator.BETWEEN, Lists.newArrayList(1001, 1200), ShardingOperator.BETWEEN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 1001, 1200);
        assertDataSet("integrate/dataset/Empty.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12), ShardingOperator.BETWEEN, Lists.newArrayList(1309, 1408), ShardingOperator.BETWEEN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 1309, 1408);
    }
}
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) Map(java.util.Map) Test(org.junit.Test) AbstractShardingDatabaseOnlyWithHintTest(io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractShardingDatabaseOnlyWithHintTest)

Example 17 with DatabaseType

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

the class ShardingDatabaseOnlyWithHintForSelectTest method assertSelectEqualsWithSingleTable.

@Test
public void assertSelectEqualsWithSingleTable() throws SQLException, DatabaseUnitException {
    String sql = SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.SELECT_EQUALS_WITH_SINGLE_TABLE_SQL);
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        assertDataSet("integrate/dataset/sharding/db/expect/select/SelectEqualsWithSingleTable_0.xml", new HintShardingValueHelper(10, 1000), each.getValue().getConnection(), sql, each.getKey(), 10, 1000);
        assertDataSet("integrate/dataset/sharding/db/expect/select/SelectEqualsWithSingleTable_1.xml", new HintShardingValueHelper(12, 1201), each.getValue().getConnection(), sql, each.getKey(), 12, 1201);
        assertDataSet("integrate/dataset/Empty.xml", new HintShardingValueHelper(12, 1000), each.getValue().getConnection(), sql, each.getKey(), 12, 1000);
    }
}
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) Map(java.util.Map) Test(org.junit.Test) AbstractShardingDatabaseOnlyWithHintTest(io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractShardingDatabaseOnlyWithHintTest)

Example 18 with DatabaseType

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

the class ShardingDatabaseOnlyWithHintForSelectTest method assertSelectInWithSingleTable.

@Test
public void assertSelectInWithSingleTable() throws SQLException, DatabaseUnitException {
    String sql = SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.SELECT_IN_WITH_SINGLE_TABLE_SQL);
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        assertDataSet("integrate/dataset/sharding/db/expect/select/SelectInWithSingleTable_0.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12, 15), ShardingOperator.IN, Lists.newArrayList(1000, 1201), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1000, 1201);
        assertDataSet("integrate/dataset/sharding/db/expect/select/SelectInWithSingleTable_1.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12, 15), ShardingOperator.IN, Lists.newArrayList(1000, 1101), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1000, 1101);
        assertDataSet("integrate/dataset/Empty.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12, 15), ShardingOperator.IN, Lists.newArrayList(1309, 1408), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1309, 1408);
    }
}
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) Map(java.util.Map) Test(org.junit.Test) AbstractShardingDatabaseOnlyWithHintTest(io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractShardingDatabaseOnlyWithHintTest)

Example 19 with DatabaseType

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

the class SQLAssertJAXBHelper method dataParameters.

private static Collection<Object[]> dataParameters(final File file) {
    SQLAsserts asserts = loadSQLAsserts(file);
    List<Object[]> result = new ArrayList<>();
    for (int i = 0; i < asserts.getSqlAsserts().size(); i++) {
        SQLAssert assertObj = asserts.getSqlAsserts().get(i);
        for (DatabaseType each : getDatabaseTypes(SQLCasesLoader.getInstance().getDatabaseTypes(assertObj.getId()))) {
            result.add(getDataParameter(assertObj, each));
        }
    }
    return result;
}
Also used : DatabaseType(io.shardingjdbc.core.constant.DatabaseType) ArrayList(java.util.ArrayList) SQLAsserts(io.shardingjdbc.core.integrate.jaxb.SQLAsserts) SQLAssert(io.shardingjdbc.core.integrate.jaxb.SQLAssert)

Example 20 with DatabaseType

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

the class AbstractShardingDatabaseOnlyTest method getDataSources.

@Override
protected Map<DatabaseType, ShardingDataSource> getDataSources() throws SQLException {
    if (!getShardingDataSources().isEmpty()) {
        return getShardingDataSources();
    }
    Map<DatabaseType, Map<String, DataSource>> dataSourceMap = createDataSourceMap();
    for (Map.Entry<DatabaseType, Map<String, DataSource>> each : dataSourceMap.entrySet()) {
        final ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
        TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
        orderTableRuleConfig.setLogicTable("t_order");
        orderTableRuleConfig.setLogicIndex("t_order_index");
        orderTableRuleConfig.setKeyGeneratorColumnName("order_id");
        orderTableRuleConfig.setKeyGenerator(new IncrementKeyGenerator());
        shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig);
        TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
        orderItemTableRuleConfig.setLogicTable("t_order_item");
        TableRuleConfiguration logTableRuleConfig = new TableRuleConfiguration();
        logTableRuleConfig.setLogicIndex("t_log_index");
        logTableRuleConfig.setLogicTable("t_log");
        TableRuleConfiguration tempLogTableRuleConfig = new TableRuleConfiguration();
        tempLogTableRuleConfig.setLogicTable("t_temp_log");
        shardingRuleConfig.getTableRuleConfigs().add(logTableRuleConfig);
        shardingRuleConfig.getTableRuleConfigs().add(tempLogTableRuleConfig);
        shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
        shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
        shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new ComplexShardingStrategyConfiguration("user_id", new ComplexKeysModuloDatabaseShardingAlgorithm()));
        shardingRuleConfig.setDefaultTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
        getShardingDataSources().put(each.getKey(), new ShardingDataSource(each.getValue(), new ShardingRule(shardingRuleConfig, each.getValue().keySet())));
    }
    return getShardingDataSources();
}
Also used : DatabaseType(io.shardingjdbc.core.constant.DatabaseType) NoneShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.NoneShardingStrategyConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) ComplexShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration) ComplexKeysModuloDatabaseShardingAlgorithm(io.shardingjdbc.core.integrate.fixture.ComplexKeysModuloDatabaseShardingAlgorithm) SQLShardingRule(io.shardingjdbc.core.integrate.jaxb.SQLShardingRule) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) IncrementKeyGenerator(io.shardingjdbc.core.fixture.IncrementKeyGenerator) Map(java.util.Map) TableRuleConfiguration(io.shardingjdbc.core.api.config.TableRuleConfiguration)

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