diff options
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/AtomDao.java')
-rw-r--r-- | src/main/java/io/trygvis/esper/testing/AtomDao.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/AtomDao.java b/src/main/java/io/trygvis/esper/testing/AtomDao.java new file mode 100644 index 0000000..0215545 --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/AtomDao.java @@ -0,0 +1,37 @@ +package io.trygvis.esper.testing; + +import java.sql.*; + +public class AtomDao { + private final PreparedStatement selectLastUpdate; + private final PreparedStatement insertAtomFeed; + private final PreparedStatement updateAtomFeed; + + public AtomDao(Connection c) throws SQLException { + selectLastUpdate = c.prepareStatement("SELECT last_update FROM atom_feed WHERE url=?"); + insertAtomFeed = c.prepareStatement("INSERT INTO atom_feed(url, last_update) VALUES(?, ?)"); + updateAtomFeed = c.prepareStatement("UPDATE atom_feed SET last_update=? WHERE url=?"); + } + + public Timestamp getAtomFeed(String url) throws SQLException { + selectLastUpdate.setString(1, url); + ResultSet rs = selectLastUpdate.executeQuery(); + if (!rs.next()) { + return null; + } + + return rs.getTimestamp(1); + } + + public void insertAtomFeed(String url, Timestamp lastUpdate) throws SQLException { + insertAtomFeed.setString(1, url); + insertAtomFeed.setTimestamp(2, lastUpdate); + insertAtomFeed.executeUpdate(); + } + + public void updateAtomFeed(String url, Timestamp lastUpdate) throws SQLException { + updateAtomFeed.setTimestamp(1, lastUpdate); + updateAtomFeed.setString(2, url); + updateAtomFeed.executeUpdate(); + } +} |