use of java.sql.Connection in project crate by crate.
the class PostgresJobsLogsITest method testBatchOperationStatsTableSuccess.
@Test
public void testBatchOperationStatsTableSuccess() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_POSTGRESQL_URL)) {
conn.setAutoCommit(true);
conn.createStatement().executeUpdate("create table t (x string) with (number_of_replicas = 0)");
ensureGreen();
String uniqueId1 = UUID.randomUUID().toString();
String uniqueId2 = UUID.randomUUID().toString();
Statement statement = conn.createStatement();
final String stmtStr1 = "insert into t (x) values ('" + uniqueId1 + "')";
final String stmtStr1Where = "insert into t (x) values (''" + uniqueId1 + "'')";
final String stmtStr2 = "insert into t (x) values ('" + uniqueId2 + "')";
final String stmtStr2Where = "insert into t (x) values (''" + uniqueId2 + "'')";
statement.addBatch(stmtStr1);
statement.addBatch(stmtStr2);
int[] results = statement.executeBatch();
assertThat(results, is(new int[] { 1, 1 }));
assertJobLogContains(conn, new String[] { stmtStr1, stmtStr2 }, new String[] { stmtStr1Where, stmtStr2Where }, false);
}
}
use of java.sql.Connection in project crate by crate.
the class PostgresJobsLogsITest method testStatsTableFailure.
@Test
public void testStatsTableFailure() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_POSTGRESQL_URL)) {
conn.setAutoCommit(true);
conn.createStatement().executeUpdate("create table t (a integer not null, b string) " + "with (number_of_replicas = 0)");
ensureGreen();
String uniqueId = UUID.randomUUID().toString();
final String stmtStr = "insert into t(a,b) values(null, '" + uniqueId + "')";
final String stmtStrWhere = "insert into t(a,b) values(null, ''" + uniqueId + "'')";
try {
conn.prepareStatement(stmtStr).execute();
fail("NOT NULL constraint is not respected");
} catch (Exception e) {
assertJobLogContains(conn, new String[] { stmtStr }, new String[] { stmtStrWhere }, true);
}
}
}
use of java.sql.Connection in project sharding-jdbc by dangdangdotcom.
the class AbstractShardingBothForStatementWithDMLTest method assertUpdate.
@Test
public void assertUpdate() throws SQLException, DatabaseUnitException {
String sql = "UPDATE `t_order` SET `status` = '%s' WHERE `order_id` = %s AND `user_id` = %s";
for (int i = 10; i < 20; i++) {
for (int j = 0; j < 10; j++) {
try (Connection connection = shardingDataSource.getConnection()) {
Statement stmt = connection.createStatement();
assertThat(stmt.executeUpdate(String.format(sql, "updated", i * 100 + j, i)), is(1));
}
}
}
assertDataSet("update", "updated");
}
use of java.sql.Connection in project sharding-jdbc by dangdangdotcom.
the class AbstractShardingBothForStatementWithDMLTest method assertInsert.
@Test
public void assertInsert() throws SQLException, DatabaseUnitException {
String sql = "INSERT INTO `t_order` (`order_id`, `user_id`, `status`) VALUES (%s, %s, '%s')";
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
try (Connection connection = shardingDataSource.getConnection("", "")) {
Statement stmt = connection.createStatement();
stmt.executeUpdate(String.format(sql, i, j, "insert"));
}
}
}
assertDataSet("insert", "insert");
}
use of java.sql.Connection in project sharding-jdbc by dangdangdotcom.
the class DynamicShardingBothForPStatementWithDMLTest method assertDeleteWithoutShardingValue.
@Test(expected = IllegalStateException.class)
public void assertDeleteWithoutShardingValue() throws SQLException, DatabaseUnitException {
String sql = "DELETE `t_order` WHERE `status` = ?";
try (Connection connection = getShardingDataSource().getConnection()) {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, "init");
preparedStatement.executeUpdate();
}
}
Aggregations