Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class DaoService {
- @Autowired
- private ConnectionPool pool;
- public void updateTimestamp(long id) {
- perform(conn -> {
- if (!conn.recordExists(id))
- create(id);
- conn.updateTimestamp(id, System.currentTimeMillis());
- });
- }
- private void create(long id) {
- try {
- perform(conn -> conn.createRecord(id));
- }
- catch (DuplicateKeyException ex) {
- // ignored
- }
- }
- private void perform(Consumer<Connection> c) {
- Connection conn = pool.borrowConnection();
- try {
- c.accept(conn);
- }
- finally {
- pool.returnConnection(conn);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement