- Common ways to obtain DBI
private void myMethod () {DBI d =
DataSource dataSource;new DBI(dataSource)
ConnectionFactory connectionFactory;new DBI(connectionFactory)
String url;String username;String password;new DBI(url, username, password)
- Smart code suggestions by Codota
}
@JsonRequest @ApiOperation(value = "Get dashboard users") @Path("/users/set") public SuccessMessage setUsers(@Named("user_id") Project project, @ApiParam("dashboard") int id, @ApiParam("user_ids") int[] users) { TransactionHandler transactionHandler = dbi.getTransactionHandler(); try (Handle handle = dbi.open()) { transactionHandler.begin(handle); Integer userId = handle.createQuery("SELECT user_id FROM dashboard where id = :id") .bind("id", id).map(IntegerMapper.FIRST).first(); if (project.userId != userId) { throw new RakamException(FORBIDDEN); } handle.createStatement("DELETE FROM dashboard_permission WHERE dashboard = :dashboard") .bind("dashboard", id).execute(); handle.createStatement("UPDATE dashboard SET shared_everyone = :sharedEveryone" + " WHERE id = :id AND project_id = :project") .bind("id", id) .bind("sharedEveryone", false) .bind("project", project.project) .execute(); for (int user : users) { handle.createStatement("INSERT INTO dashboard_permission (dashboard, user_id) VALUES (:dashboard, :user_id) ") .bind("dashboard", id) .bind("user_id", user) .execute(); } transactionHandler.commit(handle); return SuccessMessage.success(); } }