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

changeset 150
822b7e3d064d
parent 138
e2aa673dd473
child 154
3d10f2a390a1
equal deleted inserted replaced
149:30b840ed8c0e 150:822b7e3d064d
273 public List<IssueComment> listComments(Issue issue) throws SQLException { 273 public List<IssueComment> listComments(Issue issue) throws SQLException {
274 listComments.setInt(1, issue.getId()); 274 listComments.setInt(1, issue.getId());
275 List<IssueComment> comments = new ArrayList<>(); 275 List<IssueComment> comments = new ArrayList<>();
276 try (var result = listComments.executeQuery()) { 276 try (var result = listComments.executeQuery()) {
277 while (result.next()) { 277 while (result.next()) {
278 final var comment = new IssueComment(result.getInt("commentid"), issue); 278 final var comment = new IssueComment(result.getInt("commentid"));
279 comment.setCreated(result.getTimestamp("created")); 279 comment.setCreated(result.getTimestamp("created"));
280 comment.setUpdated(result.getTimestamp("updated")); 280 comment.setUpdated(result.getTimestamp("updated"));
281 comment.setUpdateCount(result.getInt("updatecount")); 281 comment.setUpdateCount(result.getInt("updatecount"));
282 comment.setComment(result.getString("comment")); 282 comment.setComment(result.getString("comment"));
283 comment.setAuthor(PGUserDao.mapColumns(result)); 283 comment.setAuthor(PGUserDao.mapColumns(result));
286 } 286 }
287 return comments; 287 return comments;
288 } 288 }
289 289
290 @Override 290 @Override
291 public void saveComment(IssueComment comment) throws SQLException { 291 public void saveComment(Issue issue, IssueComment comment) throws SQLException {
292 Objects.requireNonNull(comment.getComment());
293 Objects.requireNonNull(comment.getIssue());
294 if (comment.getId() >= 0) { 292 if (comment.getId() >= 0) {
295 updateComment.setString(1, comment.getComment()); 293 updateComment.setString(1, comment.getComment());
296 updateComment.setInt(2, comment.getId()); 294 updateComment.setInt(2, comment.getId());
297 updateComment.execute(); 295 updateComment.execute();
298 } else { 296 } else {
299 insertComment.setInt(1, comment.getIssue().getId()); 297 insertComment.setInt(1, issue.getId());
300 insertComment.setString(2, comment.getComment()); 298 insertComment.setString(2, comment.getComment());
301 setForeignKeyOrNull(insertComment, 3, comment.getAuthor(), User::getId); 299 setForeignKeyOrNull(insertComment, 3, comment.getAuthor(), User::getId);
302 insertComment.execute(); 300 insertComment.execute();
303 } 301 }
304 } 302 }

mercurial