Search in sources :

Example 6 with HintDatabaseShardingValueHelper

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

the class RoutingDatabaseOnlyWithHintForDMLTest method deleteWithoutAlias.

private void deleteWithoutAlias(final Map.Entry<DatabaseType, ShardingDataSource> dataSourceEntry) throws SQLException, DatabaseUnitException {
    for (int i = 10; i < 30; i++) {
        for (int j = 0; j < 2; j++) {
            try (HintShardingValueHelper helper = new HintDatabaseShardingValueHelper(i);
                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));
            }
        }
    }
    assertDataSet(dataSourceEntry.getValue().getConnection(), dataSourceEntry.getKey(), "delete", "init");
}
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) HintDatabaseShardingValueHelper(io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintDatabaseShardingValueHelper)

Aggregations

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