src/main/java/de/uapcore/lightpit/dao/postgres/PGProjectDao.java

changeset 86
0a658e53177c
parent 81
1a2e7b5d48f7
child 128
947d0f6a6a83
equal deleted inserted replaced
85:3d16ad54b3dc 86:0a658e53177c
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.ProjectDao; 31 import de.uapcore.lightpit.dao.ProjectDao;
32 import de.uapcore.lightpit.entities.IssueSummary;
32 import de.uapcore.lightpit.entities.Project; 33 import de.uapcore.lightpit.entities.Project;
33 import de.uapcore.lightpit.entities.User; 34 import de.uapcore.lightpit.entities.User;
34 35
35 import java.sql.Connection; 36 import java.sql.Connection;
36 import java.sql.PreparedStatement; 37 import java.sql.PreparedStatement;
96 } 97 }
97 98
98 return proj; 99 return proj;
99 } 100 }
100 101
101 private void mapIssueSummary(Project proj) throws SQLException { 102 public IssueSummary getIssueSummary(Project project) throws SQLException {
102 issue_summary.setInt(1, proj.getId()); 103 issue_summary.setInt(1, project.getId());
103 final var result = issue_summary.executeQuery(); 104 final var result = issue_summary.executeQuery();
105 final var summary = new IssueSummary();
104 while (result.next()) { 106 while (result.next()) {
105 final var phase = result.getInt("phase"); 107 final var phase = result.getInt("phase");
106 final var total = result.getInt("total"); 108 final var total = result.getInt("total");
107 switch(phase) { 109 switch(phase) {
108 case 0: 110 case 0:
109 proj.setOpenIssues(total); 111 summary.setOpen(total);
110 break; 112 break;
111 case 1: 113 case 1:
112 proj.setActiveIssues(total); 114 summary.setActive(total);
113 break; 115 break;
114 case 2: 116 case 2:
115 proj.setDoneIssues(total); 117 summary.setDone(total);
116 break; 118 break;
117 } 119 }
118 } 120 }
121 return summary;
119 } 122 }
120 123
121 @Override 124 @Override
122 public void save(Project instance) throws SQLException { 125 public void save(Project instance) throws SQLException {
123 Objects.requireNonNull(instance.getName()); 126 Objects.requireNonNull(instance.getName());
144 public List<Project> list() throws SQLException { 147 public List<Project> list() throws SQLException {
145 List<Project> projects = new ArrayList<>(); 148 List<Project> projects = new ArrayList<>();
146 try (var result = list.executeQuery()) { 149 try (var result = list.executeQuery()) {
147 while (result.next()) { 150 while (result.next()) {
148 final var project = mapColumns(result); 151 final var project = mapColumns(result);
149 mapIssueSummary(project);
150 projects.add(project); 152 projects.add(project);
151 } 153 }
152 } 154 }
153 return projects; 155 return projects;
154 } 156 }
157 public Project find(int id) throws SQLException { 159 public Project find(int id) throws SQLException {
158 find.setInt(1, id); 160 find.setInt(1, id);
159 try (var result = find.executeQuery()) { 161 try (var result = find.executeQuery()) {
160 if (result.next()) { 162 if (result.next()) {
161 final var project = mapColumns(result); 163 final var project = mapColumns(result);
162 mapIssueSummary(project);
163 return project; 164 return project;
164 } else { 165 } else {
165 return null; 166 return null;
166 } 167 }
167 } 168 }

mercurial