Search in sources :

Example 11 with HintShardingValueHelper

use of io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper in project sharding-jdbc by shardingjdbc.

the class ShardingDatabaseOnlyWithHintForDMLTest method deleteWithoutAlias.

private void deleteWithoutAlias(final Map.Entry<DatabaseType, ShardingDataSource> dataSourceEntry) throws SQLException {
    for (int i = 10; i < 30; i++) {
        for (int j = 0; j < 2; j++) {
            try (HintShardingValueHelper helper = new HintShardingValueHelper(i, i * 100 + j);
                Connection connection = dataSourceEntry.getValue().getConnection()) {
                PreparedStatement preparedStatement = connection.prepareStatement(SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.DELETE_WITHOUT_ALIAS_SQL));
                preparedStatement.setInt(1, i * 100 + j);
                preparedStatement.setInt(2, i);
                preparedStatement.setString(3, "init");
                assertThat(preparedStatement.executeUpdate(), is(1));
            }
        }
    }
}
Also used : HintShardingValueHelper(io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper) Connection(java.sql.Connection) ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) PreparedStatement(java.sql.PreparedStatement)

Example 12 with HintShardingValueHelper

use of io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper 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 13 with HintShardingValueHelper

use of io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper 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 14 with HintShardingValueHelper

use of io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper 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)

Aggregations

HintShardingValueHelper (io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintShardingValueHelper)14 ShardingConnection (io.shardingjdbc.core.jdbc.core.connection.ShardingConnection)11 Connection (java.sql.Connection)11 PreparedStatement (java.sql.PreparedStatement)11 DatabaseType (io.shardingjdbc.core.constant.DatabaseType)8 ShardingDataSource (io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource)8 Map (java.util.Map)8 Test (org.junit.Test)8 AbstractShardingDatabaseOnlyWithHintTest (io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractShardingDatabaseOnlyWithHintTest)6 HintDatabaseShardingValueHelper (io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintDatabaseShardingValueHelper)5 AbstractRoutingDatabaseOnlyWithHintTest (io.shardingjdbc.core.integrate.type.sharding.hint.base.AbstractRoutingDatabaseOnlyWithHintTest)2