Search in sources :

Example 96 with Connection

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);
    }
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Example 97 with Connection

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);
        }
    }
}
Also used : Connection(java.sql.Connection) Test(org.junit.Test)

Example 98 with Connection

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");
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) AbstractShardingBothTest(com.dangdang.ddframe.rdb.integrate.dbtbl.common.AbstractShardingBothTest) Test(org.junit.Test)

Example 99 with Connection

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");
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) AbstractShardingBothTest(com.dangdang.ddframe.rdb.integrate.dbtbl.common.AbstractShardingBothTest) Test(org.junit.Test)

Example 100 with Connection

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();
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) AbstractShardingBothForPStatementWithDMLTest(com.dangdang.ddframe.rdb.integrate.dbtbl.common.pstatement.AbstractShardingBothForPStatementWithDMLTest) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)6326 PreparedStatement (java.sql.PreparedStatement)2793 ResultSet (java.sql.ResultSet)2657 Test (org.junit.Test)2455 SQLException (java.sql.SQLException)2267 Properties (java.util.Properties)1188 Statement (java.sql.Statement)1078 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)689 ArrayList (java.util.ArrayList)397 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)232 DataSource (javax.sql.DataSource)211 BaseTest (org.apache.phoenix.query.BaseTest)201 CallableStatement (java.sql.CallableStatement)192 IOException (java.io.IOException)158 Reader (java.io.Reader)144 DatabaseMetaData (java.sql.DatabaseMetaData)144 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)134 HashMap (java.util.HashMap)123 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)114 Timestamp (java.sql.Timestamp)113