diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-12-22 19:33:23 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-12-22 19:33:23 +0100 |
commit | 78e7933c0af1d11d9476c5ee213c64ad87066f55 (patch) | |
tree | b7d7f908bf24c5ce000dac9b6ff0dfb63c30b5ee /src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java | |
parent | c8c863ce36f57954369a0b4a15e6c5e720f03f87 (diff) | |
download | esper-testing-78e7933c0af1d11d9476c5ee213c64ad87066f55.tar.gz esper-testing-78e7933c0af1d11d9476c5ee213c64ad87066f55.tar.bz2 esper-testing-78e7933c0af1d11d9476c5ee213c64ad87066f55.tar.xz esper-testing-78e7933c0af1d11d9476c5ee213c64ad87066f55.zip |
o First badge: UNBREAKABLE.
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java')
-rw-r--r-- | src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java new file mode 100644 index 0000000..24ecfd3 --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java @@ -0,0 +1,65 @@ +package io.trygvis.esper.testing.core.db; + +import io.trygvis.esper.testing.*; +import io.trygvis.esper.testing.util.sql.*; +import org.joda.time.*; + +import java.sql.*; +import java.util.*; + +import static io.trygvis.esper.testing.util.sql.ResultSetF.*; +import static java.lang.System.*; + +public class BuildDao { + private final Connection c; + + public static final String BUILD = "uuid, created_date, timestamp, success, reference_type, reference_uuid"; + + public static final SqlF<ResultSet, BuildDto> build = new SqlF<ResultSet, BuildDto>() { + public BuildDto apply(ResultSet rs) throws SQLException { + int i = 1; + return new BuildDto( + UUID.fromString(rs.getString(i++)), + new DateTime(rs.getTimestamp(i++).getTime()), + new DateTime(rs.getTimestamp(i++).getTime()), + rs.getBoolean(i++), + EntityRef.fromRs(rs, i)); + } + }; + + public BuildDao(Connection c) { + this.c = c; + } + + public UUID insertBuild(DateTime timestamp, boolean success, EntityRef ref) throws SQLException { + try (PreparedStatement s = c.prepareStatement("INSERT INTO build(" + BUILD + ") VALUES(?, ?, ?, ?, ?, ?)")) { + UUID uuid = UUID.randomUUID(); + int i = 1; + s.setString(i++, uuid.toString()); + s.setTimestamp(i++, new Timestamp(currentTimeMillis())); + s.setTimestamp(i++, new Timestamp(timestamp.getMillis())); + s.setBoolean(i++, success); + s.setString(i++, ref.type); + s.setString(i, ref.uuid.toString()); + s.executeUpdate(); + return uuid; + } + } + + public void insertBuildParticipant(UUID build, UUID person) throws SQLException { + try (PreparedStatement s = c.prepareStatement("INSERT INTO build_participant(build, person) VALUES(?, ?)")) { + int i = 1; + s.setString(i++, build.toString()); + s.setString(i, person.toString()); + s.executeUpdate(); + } + } + + public List<UUID> selectPersonsFromBuildParticipant(UUID build) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT person FROM build_participant WHERE build=?")) { + int i = 1; + s.setString(i, build.toString()); + return Util.toList(s, getUuid); + } + } +} |