Search in sources :

Example 11 with ShardingConnection

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

the class ConnectionAdapterTest method assertSetReadOnly.

@Test
public void assertSetReadOnly() throws SQLException {
    try (ShardingConnection actual = getShardingDataSource().getConnection()) {
        assertTrue(actual.isReadOnly());
        actual.setReadOnly(false);
        actual.createStatement().executeQuery(sql);
        assertReadOnly(actual, false);
        if (DatabaseType.SQLServer != getCurrentDatabaseType()) {
            actual.setReadOnly(true);
            assertReadOnly(actual, true);
        }
    }
}
Also used : ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) Test(org.junit.Test) AbstractShardingJDBCDatabaseAndTableTest(io.shardingjdbc.core.common.base.AbstractShardingJDBCDatabaseAndTableTest)

Example 12 with ShardingConnection

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

the class ConnectionAdapterTest method assertTransactionIsolation.

private void assertTransactionIsolation(final ShardingConnection actual, final int transactionIsolation) throws SQLException {
    assertThat(actual.getTransactionIsolation(), is(transactionIsolation));
    assertThat(actual.getCachedConnections().size(), is(2));
    for (Connection each : actual.getCachedConnections().values()) {
        assertThat(each.getTransactionIsolation(), is(transactionIsolation));
    }
}
Also used : Connection(java.sql.Connection) ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection)

Example 13 with ShardingConnection

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

the class ConnectionAdapterTest method assertAutoCommit.

private void assertAutoCommit(final ShardingConnection actual, final boolean autoCommit) throws SQLException {
    assertThat(actual.getAutoCommit(), is(autoCommit));
    assertThat(actual.getCachedConnections().size(), is(2));
    for (Connection each : actual.getCachedConnections().values()) {
        assertThat(each.getAutoCommit(), is(autoCommit));
    }
}
Also used : Connection(java.sql.Connection) ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection)

Example 14 with ShardingConnection

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

the class ConnectionAdapterTest method assertRollback.

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

Example 15 with ShardingConnection

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

the class ConnectionAdapterTest method assertReadOnly.

private void assertReadOnly(final ShardingConnection actual, final boolean readOnly) throws SQLException {
    assertThat(actual.isReadOnly(), is(readOnly));
    assertThat(actual.getCachedConnections().size(), is(2));
    for (Connection each : actual.getCachedConnections().values()) {
        assertThat(each.isReadOnly(), is(readOnly));
    }
}
Also used : Connection(java.sql.Connection) ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection)

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