27 * |
27 * |
28 */ |
28 */ |
29 package de.uapcore.lightpit.dao.postgres; |
29 package de.uapcore.lightpit.dao.postgres; |
30 |
30 |
31 import de.uapcore.lightpit.dao.VersionDao; |
31 import de.uapcore.lightpit.dao.VersionDao; |
32 import de.uapcore.lightpit.entities.*; |
32 import de.uapcore.lightpit.entities.Project; |
|
33 import de.uapcore.lightpit.entities.Version; |
|
34 import de.uapcore.lightpit.entities.VersionStatus; |
33 |
35 |
34 import java.sql.Connection; |
36 import java.sql.Connection; |
35 import java.sql.PreparedStatement; |
37 import java.sql.PreparedStatement; |
36 import java.sql.ResultSet; |
38 import java.sql.ResultSet; |
37 import java.sql.SQLException; |
39 import java.sql.SQLException; |
40 import java.util.Objects; |
42 import java.util.Objects; |
41 |
43 |
42 public final class PGVersionDao implements VersionDao { |
44 public final class PGVersionDao implements VersionDao { |
43 |
45 |
44 private final PreparedStatement insert, update, list, find; |
46 private final PreparedStatement insert, update, list, find; |
45 private final PreparedStatement issuesAffected, issuesScheduled, issuesResolved; |
|
46 |
47 |
47 public PGVersionDao(Connection connection) throws SQLException { |
48 public PGVersionDao(Connection connection) throws SQLException { |
48 list = connection.prepareStatement( |
49 list = connection.prepareStatement( |
49 "select versionid, project, p.name as projectname, v.name, ordinal, status " + |
50 "select versionid, project, p.name as projectname, v.name, ordinal, status " + |
50 "from lpit_version v " + |
51 "from lpit_version v " + |
62 "insert into lpit_version (project, name, ordinal, status) values (?, ?, ?, ?::version_status)" |
63 "insert into lpit_version (project, name, ordinal, status) values (?, ?, ?, ?::version_status)" |
63 ); |
64 ); |
64 update = connection.prepareStatement( |
65 update = connection.prepareStatement( |
65 "update lpit_version set name = ?, ordinal = ?, status = ?::version_status where versionid = ?" |
66 "update lpit_version set name = ?, ordinal = ?, status = ?::version_status where versionid = ?" |
66 ); |
67 ); |
67 |
|
68 issuesAffected = connection.prepareStatement( |
|
69 "select category, status, count(*) as issuecount " + |
|
70 "from lpit_issue_affected_version " + |
|
71 "join lpit_issue using (issueid) " + |
|
72 "where versionid = ? " + |
|
73 "group by category, status" |
|
74 ); |
|
75 issuesScheduled = connection.prepareStatement( |
|
76 "select category, status, count(*) as issuecount " + |
|
77 "from lpit_issue_scheduled_version " + |
|
78 "join lpit_issue using (issueid) " + |
|
79 "where versionid = ? " + |
|
80 "group by category, status" |
|
81 ); |
|
82 issuesResolved = connection.prepareStatement( |
|
83 "select category, status, count(*) as issuecount " + |
|
84 "from lpit_issue_resolved_version " + |
|
85 "join lpit_issue using (issueid) " + |
|
86 "where versionid = ? " + |
|
87 "group by category, status" |
|
88 ); |
|
89 } |
68 } |
90 |
69 |
91 private Version mapColumns(ResultSet result) throws SQLException { |
70 private Version mapColumns(ResultSet result) throws SQLException { |
92 final var project = new Project(result.getInt("project")); |
71 final var project = new Project(result.getInt("project")); |
93 project.setName(result.getString("projectname")); |
72 project.setName(result.getString("projectname")); |
94 final var version = new Version(result.getInt("versionid"), project); |
73 final var version = new Version(result.getInt("versionid")); |
|
74 version.setProject(project); |
95 version.setName(result.getString("name")); |
75 version.setName(result.getString("name")); |
96 version.setOrdinal(result.getInt("ordinal")); |
76 version.setOrdinal(result.getInt("ordinal")); |
97 version.setStatus(VersionStatus.valueOf(result.getString("status"))); |
77 version.setStatus(VersionStatus.valueOf(result.getString("status"))); |
98 return version; |
78 return version; |
99 } |
|
100 |
|
101 private VersionStatistics versionStatistics(Version version, PreparedStatement stmt) throws SQLException { |
|
102 stmt.setInt(1, version.getId()); |
|
103 final var result = stmt.executeQuery(); |
|
104 final var stats = new VersionStatistics(version); |
|
105 while (result.next()) { |
|
106 stats.setIssueCount( |
|
107 IssueCategory.valueOf(result.getString("category")), |
|
108 IssueStatus.valueOf(result.getString("status")), |
|
109 result.getInt("issuecount") |
|
110 ); |
|
111 } |
|
112 return stats; |
|
113 } |
79 } |
114 |
80 |
115 @Override |
81 @Override |
116 public void save(Version instance) throws SQLException { |
82 public void save(Version instance) throws SQLException { |
117 Objects.requireNonNull(instance.getName()); |
83 Objects.requireNonNull(instance.getName()); |