diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-03 15:09:43 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-03 15:09:43 +0100 |
commit | 35ba1a6f765f72a1d91a5456c7556e6274f8c3a9 (patch) | |
tree | 18d069a4512cec4fca1c93964adcb039b9ee6167 /src/main/java/io/trygvis/esper/testing/core/db | |
parent | 84fb49088a14cff8b453e0e32f6ad7007eb2184a (diff) | |
download | esper-testing-35ba1a6f765f72a1d91a5456c7556e6274f8c3a9.tar.gz esper-testing-35ba1a6f765f72a1d91a5456c7556e6274f8c3a9.tar.bz2 esper-testing-35ba1a6f765f72a1d91a5456c7556e6274f8c3a9.tar.xz esper-testing-35ba1a6f765f72a1d91a5456c7556e6274f8c3a9.zip |
o Moving Jenkins XML objects and parsing to it's own package.
o Removing fields from JenkinsBuild that's read from the XML later on.
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/core/db')
-rwxr-xr-x[-rw-r--r--] | src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java | 9 | ||||
-rwxr-xr-x[-rw-r--r--] | src/main/java/io/trygvis/esper/testing/core/db/FileDao.java | 14 | ||||
-rwxr-xr-x[-rw-r--r--] | src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java | 49 | ||||
-rwxr-xr-x[-rw-r--r--] | src/main/java/io/trygvis/esper/testing/core/db/PersonDto.java | 4 |
4 files changed, 73 insertions, 3 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 index 416faf6..c7923d0 100644..100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java @@ -81,6 +81,15 @@ public class BuildDao { } } + public SqlOption<UUID> findBuildByReference(EntityRef ref) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT uuid FROM build WHERE reference_type=? AND reference_uuid=?")) { + int i = 1; + s.setString(i++, ref.type); + s.setString(i, ref.uuid.toString()); + return fromRs(s.executeQuery()).map(getUuid); + } + } + public List<BuildDto> selectBuildsByPerson(UUID person, PageRequest page) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + BUILD + " FROM build b, build_participant bp WHERE bp.person=? AND b.uuid = bp.build ORDER BY created_date LIMIT ? OFFSET ?")) { int i = 1; diff --git a/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java b/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java index c418970..affe1c8 100644..100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java @@ -1,10 +1,13 @@ package io.trygvis.esper.testing.core.db; +import io.trygvis.esper.testing.util.sql.*; + import java.io.*; import java.net.*; import java.sql.*; import java.util.*; +import static io.trygvis.esper.testing.util.sql.SqlOption.*; import static java.lang.System.*; public class FileDao { @@ -27,4 +30,15 @@ public class FileDao { return uuid; } } + + public SqlOption<InputStream> load(UUID uuid) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT data FROM file WHERE uuid=?")) { + s.setString(1, uuid.toString()); + ResultSet rs = s.executeQuery(); + if(!rs.next()) { + return none(); + } + return some(rs.getBinaryStream(1)); + } + } } diff --git a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java index 62c4f2b..96569dd 100644..100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java @@ -14,7 +14,7 @@ import static java.lang.System.*; public class PersonDao { private final Connection c; - public static final String PERSON = "uuid, created_date, name"; + public static final String PERSON = "uuid, created_date, name, mail"; public static final SqlF<ResultSet, PersonDto> person = new SqlF<ResultSet, PersonDto>() { public PersonDto apply(ResultSet rs) throws SQLException { @@ -22,6 +22,7 @@ public class PersonDao { return new PersonDto( UUID.fromString(rs.getString(i++)), new DateTime(rs.getTimestamp(i++).getTime()), + rs.getString(i++), rs.getString(i)); } }; @@ -63,6 +64,19 @@ public class PersonDao { // Person // ----------------------------------------------------------------------- + public UUID insertPerson(String mail, String name) throws SQLException { + try (PreparedStatement s = c.prepareStatement("INSERT INTO person(" + PERSON + ") VALUES(?, ?, ?, ?)")) { + UUID uuid = UUID.randomUUID(); + int i = 1; + s.setString(i++, uuid.toString()); + s.setTimestamp(i++, new Timestamp(currentTimeMillis())); + s.setString(i++, name); + s.setString(i, mail); + s.executeUpdate(); + return uuid; + } + } + public SqlOption<PersonDto> selectPerson(UUID uuid) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person WHERE uuid=?")) { int i = 1; @@ -71,7 +85,15 @@ public class PersonDao { } } - public List<PersonDto> selectPerson(PageRequest pageRequest) throws SQLException { + public SqlOption<PersonDto> selectPersonByMail(String mail) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person WHERE mail=?")) { + int i = 1; + s.setString(i, mail); + return fromRs(s.executeQuery()).map(person); + } + } + + public List<PersonDto> selectPersons(PageRequest pageRequest) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person ORDER BY created_date, name LIMIT ? OFFSET ?")) { int i = 1; s.setInt(i++, pageRequest.count.orSome(10)); @@ -95,6 +117,29 @@ public class PersonDao { } // ----------------------------------------------------------------------- + // Person Jenkins User + // ----------------------------------------------------------------------- + + public void insertPersonJenkinsUser(UUID person, UUID jenkinsUser) throws SQLException { + try (PreparedStatement s = c.prepareStatement("INSERT INTO person_jenkins_user(person, jenkins_user) VALUES(?, ?)")) { + int i = 1; + s.setString(i++, person.toString()); + s.setString(i, jenkinsUser.toString()); + s.executeUpdate(); + } + } + + public boolean hasPersonJenkinsUser(UUID person, UUID jenkinsUser) throws SQLException { + try (PreparedStatement s = c.prepareStatement("SELECT 1 FROM person_jenkins_user WHERE person=? AND jenkins_user=?")) { + int i = 1; + s.setString(i++, person.toString()); + s.setString(i, jenkinsUser.toString()); + ResultSet rs = s.executeQuery(); + return rs.next(); + } + } + + // ----------------------------------------------------------------------- // Badge // ----------------------------------------------------------------------- diff --git a/src/main/java/io/trygvis/esper/testing/core/db/PersonDto.java b/src/main/java/io/trygvis/esper/testing/core/db/PersonDto.java index c643fc7..6dbea74 100644..100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/PersonDto.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonDto.java @@ -7,9 +7,11 @@ import java.util.*; public class PersonDto extends AbstractEntity { public final String name; + public final String mail; - public PersonDto(UUID uuid, DateTime createdDate, String name) { + public PersonDto(UUID uuid, DateTime createdDate, String name, String mail) { super(uuid, createdDate); this.name = name; + this.mail = mail; } } |