@Component(service=UkelonnService.class, immediate=true) | |
public class UkelonnServiceProvider extends UkelonnServiceBase { | |
... | |
@Override | |
public Account getAccount(String username) { | |
try(Connection connection = database.getConnection()) { | |
try(PreparedStatement statement = connection.prepareStatement("select * from accounts_view where username=?")) { | |
statement.setString(1, username); | |
try(ResultSet resultset = statement.executeQuery()) { | |
if (resultset.next()) | |
{ | |
return mapAccount(resultset); | |
} | |
throw new UkelonnException(String.format("Got an empty ResultSet while fetching account from the database for user \\\"%s\\\"", username)); | |
} | |
} | |
} catch (SQLException e) { | |
throw new UkelonnException(String.format("Caught SQLException while fetching account from the database for user \"%s\"", username), e); | |
} | |
} | |
public Account mapAccount(ResultSet results) throws SQLException { | |
String username = results.getString(UkelonnServiceProvider.USERNAME); | |
no.priv.bang.osgiservice.users.User user = useradmin.getUser(username); | |
return new Account( | |
results.getInt("account_id"), | |
username, | |
user.getFirstname(), | |
user.getLastname(), | |
results.getDouble("balance")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment