use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testGetSetAutoCommit.
/**
* @throws Exception If failed.
*/
@Test
public void testGetSetAutoCommit() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
boolean ac0 = conn.getAutoCommit();
conn.setAutoCommit(!ac0);
// assert no exception
conn.setAutoCommit(ac0);
// assert no exception
conn.close();
// Exception when called on closed connection
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.setAutoCommit(ac0);
}
});
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testPrepareStatement.
/**
* @throws Exception If failed.
*/
@Test
public void testPrepareStatement() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
// null query text
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return conn.prepareStatement(null);
}
}, SQLException.class, "SQL string cannot be null");
final String sqlText = "select * from test where param = ?";
try (PreparedStatement prepared = conn.prepareStatement(sqlText)) {
assertNotNull(prepared);
}
conn.close();
// Exception when called on closed connection
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.prepareStatement(sqlText);
}
});
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testNativeSql.
/**
* @throws Exception If failed.
*/
@Test
public void testNativeSql() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
// null query text
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return conn.nativeSQL(null);
}
}, SQLException.class, "SQL string cannot be null");
final String sqlText = "select * from test";
assertEquals(sqlText, conn.nativeSQL(sqlText));
conn.close();
// Exception when called on closed connection
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.nativeSQL(sqlText);
}
});
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testPrepareStatement4.
/**
* @throws Exception If failed.
*/
@Test
public void testPrepareStatement4() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
final String sqlText = "select * from test where param = ?";
int[] rsTypes = new int[] { TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE };
int[] rsConcurs = new int[] { CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE };
int[] rsHoldabilities = new int[] { HOLD_CURSORS_OVER_COMMIT, CLOSE_CURSORS_AT_COMMIT };
DatabaseMetaData meta = conn.getMetaData();
for (final int type : rsTypes) {
for (final int concur : rsConcurs) {
for (final int holdabililty : rsHoldabilities) {
if (meta.supportsResultSetConcurrency(type, concur)) {
assert type == TYPE_FORWARD_ONLY;
assert concur == CONCUR_READ_ONLY;
// null query text
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return conn.prepareStatement(null, type, concur, holdabililty);
}
}, SQLException.class, "SQL string cannot be null");
continue;
}
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return conn.prepareStatement(sqlText, type, concur, holdabililty);
}
}, SQLFeatureNotSupportedException.class, null);
}
}
}
conn.close();
// Exception when called on closed connection
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.prepareStatement(sqlText, TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT);
}
});
conn.close();
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testGetSetReadOnly.
/**
* @throws Exception If failed.
*/
@Test
public void testGetSetReadOnly() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
conn.close();
// Exception when called on closed connection
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.setReadOnly(true);
}
});
// Exception when called on closed connection
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.isReadOnly();
}
});
}
}
Aggregations