use of org.adbcj.ResultSet in project adbcj by mheath.
the class SelectTest method testBrokenSelect.
public void testBrokenSelect() throws Exception {
Connection connection = connectionManager.connect().get();
DbSessionFuture<ResultSet> future = connection.executeQuery("SELECT broken_query");
try {
future.get(5, TimeUnit.SECONDS);
throw new AssertionError("Issues a bad query, future should have failed");
} catch (DbException e) {
// Pass
} finally {
connection.close(true).get();
}
}
use of org.adbcj.ResultSet in project adbcj by mheath.
the class SelectTest method testSimpleSelect.
public void testSimpleSelect() throws DbException, InterruptedException {
final boolean[] callbacks = { false };
final CountDownLatch latch = new CountDownLatch(callbacks.length);
Connection connection = connectionManager.connect().get();
try {
ResultSet resultSet = connection.executeQuery("SELECT int_val, str_val FROM simple_values ORDER BY int_val").addListener(new DbListener<ResultSet>() {
public void onCompletion(DbFuture<ResultSet> future) throws Exception {
System.out.println("In callback");
future.get().size();
callbacks[0] = true;
latch.countDown();
System.out.println("Finished callback");
}
}).get();
Assert.assertEquals(6, resultSet.size());
Iterator<Row> i = resultSet.iterator();
Row nullRow = null;
Row row = i.next();
if (row.get(0).isNull()) {
nullRow = row;
row = i.next();
}
Assert.assertEquals(row.get(0).getInt(), 0);
Assert.assertEquals(row.get(1).getValue(), "Zero");
row = i.next();
Assert.assertEquals(row.get(0).getInt(), 1);
Assert.assertEquals(row.get(1).getValue(), "One");
row = i.next();
Assert.assertEquals(row.get(0).getInt(), 2);
Assert.assertEquals(row.get(1).getValue(), "Two");
row = i.next();
Assert.assertEquals(row.get(0).getInt(), 3);
Assert.assertEquals(row.get(1).getValue(), "Three");
row = i.next();
Assert.assertEquals(row.get(0).getInt(), 4);
Assert.assertEquals(row.get(1).getValue(), "Four");
if (i.hasNext() && nullRow == null) {
nullRow = i.next();
}
Assert.assertEquals(nullRow.get(0).getValue(), null);
Assert.assertEquals(nullRow.get(1).getValue(), null);
Assert.assertTrue(!i.hasNext(), "There were too many rows in result set");
latch.await();
Assert.assertTrue(callbacks[0], "Result set callback was not invoked");
} finally {
connection.close(true);
}
}
Aggregations