Search in sources :

Example 1 with HintDatabaseShardingValueHelper

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

the class RoutingDatabaseOnlyWithHintForDMLTest method assertInsertWithAllPlaceholders.

@Test
public void assertInsertWithAllPlaceholders() 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(DatabaseTestSQL.INSERT_ORDER_WITH_ALL_PLACEHOLDERS_SQL)) {
                preparedStatement.setInt(1, i);
                preparedStatement.setInt(2, i);
                preparedStatement.setString(3, "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 2 with HintDatabaseShardingValueHelper

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

the class RoutingDatabaseOnlyWithHintForDMLTest method updateWithAlias.

private void updateWithAlias(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(DatabaseTestSQL.UPDATE_WITH_ALIAS_SQL)) {
                preparedStatement.setString(1, "updated");
                preparedStatement.setInt(2, i * 100 + j);
                preparedStatement.setInt(3, i);
                assertThat(preparedStatement.executeUpdate(), is(1));
            }
        }
    }
    assertDataSet(dataSourceEntry.getValue().getConnection(), dataSourceEntry.getKey(), "update", "updated");
}
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)

Example 3 with HintDatabaseShardingValueHelper

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

the class RoutingDatabaseOnlyWithHintForDMLTest method updateWithoutAlias.

private void updateWithoutAlias(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 HintDatabaseShardingValueHelper(i);
                Connection connection = dataSourceEntry.getValue().getConnection();
                PreparedStatement preparedStatement = connection.prepareStatement(SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.UPDATE_WITHOUT_ALIAS_SQL))) {
                preparedStatement.setString(1, "updated");
                preparedStatement.setInt(2, i * 100 + j);
                preparedStatement.setInt(3, i);
                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) HintDatabaseShardingValueHelper(io.shardingjdbc.core.integrate.type.sharding.hint.helper.HintDatabaseShardingValueHelper)

Example 4 with HintDatabaseShardingValueHelper

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

the class RoutingDatabaseOnlyWithHintForSelectTest method assertSelectEqualsWithSingleTable.

@Test
public void assertSelectEqualsWithSingleTable() throws SQLException, DatabaseUnitException {
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        String sql = SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.SELECT_EQUALS_WITH_SINGLE_TABLE_SQL);
        assertDataSet("integrate/dataset/sharding/db/expect/select/SelectEqualsWithSingleTable_0.xml", new HintDatabaseShardingValueHelper(10), each.getValue().getConnection(), sql, each.getKey(), 10, 1000);
        assertDataSet("integrate/dataset/sharding/db/expect/select/SelectEqualsWithSingleTable_1.xml", new HintDatabaseShardingValueHelper(12), each.getValue().getConnection(), sql, each.getKey(), 12, 1201);
        assertDataSet("integrate/dataset/Empty.xml", new HintDatabaseShardingValueHelper(12), each.getValue().getConnection(), sql, each.getKey(), 12, 1000);
    }
}
Also used : DatabaseType(io.shardingjdbc.core.constant.DatabaseType) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) 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 5 with HintDatabaseShardingValueHelper

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

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