Search in sources :

Example 1 with AsyncQueryRunner

use of org.apache.commons.dbutils.AsyncQueryRunner in project tutorials by eugenp.

the class DbUtilsUnitTest method givenAsyncRunner_whenExecutingQuery_thenExpectedList.

@Test
public void givenAsyncRunner_whenExecutingQuery_thenExpectedList() throws Exception {
    AsyncQueryRunner runner = new AsyncQueryRunner(Executors.newCachedThreadPool());
    EmployeeHandler employeeHandler = new EmployeeHandler(connection);
    String query = "SELECT * FROM employee";
    Future<List<Employee>> future = runner.query(connection, query, employeeHandler);
    List<Employee> employeeList = future.get(10, TimeUnit.SECONDS);
    assertEquals(employeeList.size(), 5);
}
Also used : AsyncQueryRunner(org.apache.commons.dbutils.AsyncQueryRunner) List(java.util.List) Test(org.junit.Test)

Aggregations

List (java.util.List)1 AsyncQueryRunner (org.apache.commons.dbutils.AsyncQueryRunner)1 Test (org.junit.Test)1