Search in sources :

Example 16 with ShardingConnection

use of io.shardingjdbc.core.jdbc.core.connection.ShardingConnection in project sharding-jdbc by shardingjdbc.

the class ConnectionAdapterTest method assertCommit.

@Test
public // TODO 缺少断言,做柔性事务时补充
void assertCommit() throws SQLException {
    try (ShardingConnection actual = getShardingDataSource().getConnection()) {
        actual.setAutoCommit(false);
        actual.createStatement().executeQuery(sql);
        actual.commit();
    }
}
Also used : ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) Test(org.junit.Test) AbstractShardingJDBCDatabaseAndTableTest(io.shardingjdbc.core.common.base.AbstractShardingJDBCDatabaseAndTableTest)

Example 17 with ShardingConnection

use of io.shardingjdbc.core.jdbc.core.connection.ShardingConnection in project sharding-jdbc by shardingjdbc.

the class ConnectionAdapterTest method assertSetAutoCommit.

@Test
public void assertSetAutoCommit() throws SQLException {
    try (ShardingConnection actual = getShardingDataSource().getConnection()) {
        assertTrue(actual.getAutoCommit());
        actual.setAutoCommit(false);
        actual.createStatement().executeQuery(sql);
        assertAutoCommit(actual, false);
        actual.setAutoCommit(true);
        assertAutoCommit(actual, true);
    }
}
Also used : ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) Test(org.junit.Test) AbstractShardingJDBCDatabaseAndTableTest(io.shardingjdbc.core.common.base.AbstractShardingJDBCDatabaseAndTableTest)

Example 18 with ShardingConnection

use of io.shardingjdbc.core.jdbc.core.connection.ShardingConnection in project sharding-jdbc by shardingjdbc.

the class PreparedStatementAdapterTest method init.

@Before
public void init() {
    ShardingConnection shardingConnection = getShardingDataSource().getConnection();
    shardingConnections.add(shardingConnection);
    preparedStatements.add(shardingConnection.prepareStatement(JDBCTestSQL.SELECT_GROUP_BY_USER_ID_SQL));
}
Also used : ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) Before(org.junit.Before)

Example 19 with ShardingConnection

use of io.shardingjdbc.core.jdbc.core.connection.ShardingConnection in project sharding-jdbc by shardingjdbc.

the class ResultSetGetterAdapterTest method init.

@Before
public void init() throws SQLException {
    ShardingConnection shardingConnection = getShardingDataSource().getConnection();
    shardingConnections.add(shardingConnection);
    Statement statement = shardingConnection.createStatement();
    statements.add(statement);
    ResultSet resultSet = statement.executeQuery(JDBCTestSQL.SELECT_ORDER_BY_USER_ID_SQL);
    resultSet.next();
    resultSets.put(getCurrentDatabaseType(), resultSet);
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) Before(org.junit.Before)

Aggregations

ShardingConnection (io.shardingjdbc.core.jdbc.core.connection.ShardingConnection)19 Before (org.junit.Before)8 AbstractShardingJDBCDatabaseAndTableTest (io.shardingjdbc.core.common.base.AbstractShardingJDBCDatabaseAndTableTest)7 Test (org.junit.Test)7 Connection (java.sql.Connection)4 Statement (java.sql.Statement)4 ResultSet (java.sql.ResultSet)2 PreparedStatement (java.sql.PreparedStatement)1