use of org.apache.commons.dbutils.QueryRunner in project atlasdb by palantir.
the class InDbTimestampBoundStore method readLimit.
private Long readLimit(Connection connection) throws SQLException {
String sql = "SELECT last_allocated FROM " + prefixedTimestampTableName() + " FOR UPDATE";
QueryRunner run = new QueryRunner();
return run.query(connection, sql, rs -> {
if (rs.next()) {
return rs.getLong("last_allocated");
} else {
return null;
}
});
}
use of org.apache.commons.dbutils.QueryRunner in project atlasdb by palantir.
the class InDbTimestampBoundStore method createLimit.
private void createLimit(Connection connection, long limit) throws SQLException {
QueryRunner run = new QueryRunner();
run.update(connection, String.format("INSERT INTO %s (last_allocated) VALUES (?)", prefixedTimestampTableName()), limit);
}
use of org.apache.commons.dbutils.QueryRunner in project tutorials by eugenp.
the class EmployeeHandler method handle.
@Override
public List<Employee> handle(ResultSet rs) throws SQLException {
List<Employee> employees = super.handle(rs);
QueryRunner runner = new QueryRunner();
BeanListHandler<Email> handler = new BeanListHandler<>(Email.class);
String query = "SELECT * FROM email WHERE employeeid = ?";
for (Employee employee : employees) {
List<Email> emails = runner.query(connection, query, handler, employee.getId());
employee.setEmails(emails);
}
return employees;
}
use of org.apache.commons.dbutils.QueryRunner in project tutorials by eugenp.
the class DbUtilsUnitTest method givenHandler_whenInserting_thenExpectedId.
@Test
public void givenHandler_whenInserting_thenExpectedId() throws SQLException {
ScalarHandler<Integer> scalarHandler = new ScalarHandler<>();
QueryRunner runner = new QueryRunner();
String insertSQL = "INSERT INTO employee (firstname,lastname,salary, hireddate) VALUES (?, ?, ?, ?)";
int newId = runner.insert(connection, insertSQL, scalarHandler, "Jenny", "Medici", 60000.60, new Date());
assertEquals(newId, 6);
}
use of org.apache.commons.dbutils.QueryRunner in project tutorials by eugenp.
the class DbUtilsUnitTest method givenResultHandler_whenExecutingQuery_thenAllPropertiesSetted.
@Test
public void givenResultHandler_whenExecutingQuery_thenAllPropertiesSetted() throws SQLException {
EmployeeHandler employeeHandler = new EmployeeHandler(connection);
QueryRunner runner = new QueryRunner();
String query = "SELECT * FROM employee_legacy";
List<Employee> employees = runner.query(connection, query, employeeHandler);
assertEquals((int) employees.get(0).getId(), 1);
assertEquals(employees.get(0).getFirstName(), "John");
}
Aggregations