From ee65a2cf6055d107606e5114136ea5c5fde22402 Mon Sep 17 00:00:00 2001 From: Timo Schneider Date: Wed, 5 Jun 2024 11:53:30 +0200 Subject: [PATCH] removed all warnings --- .../de/anxietyprime/swajodel/JodelPost.java | 3 +- .../java/de/anxietyprime/swajodel/Routes.java | 162 +++++++++--------- 2 files changed, 82 insertions(+), 83 deletions(-) diff --git a/src/main/java/de/anxietyprime/swajodel/JodelPost.java b/src/main/java/de/anxietyprime/swajodel/JodelPost.java index 49498c3..f1c1c0e 100644 --- a/src/main/java/de/anxietyprime/swajodel/JodelPost.java +++ b/src/main/java/de/anxietyprime/swajodel/JodelPost.java @@ -120,7 +120,6 @@ public class JodelPost { @JsonIgnore public boolean isComment() { - if (parent.isEmpty()) return false; - return !Objects.equals(id, parent.get()); + return parent.filter(aLong -> !Objects.equals(id, aLong)).isPresent(); } } diff --git a/src/main/java/de/anxietyprime/swajodel/Routes.java b/src/main/java/de/anxietyprime/swajodel/Routes.java index d9247e0..ce3a854 100644 --- a/src/main/java/de/anxietyprime/swajodel/Routes.java +++ b/src/main/java/de/anxietyprime/swajodel/Routes.java @@ -18,8 +18,8 @@ public class Routes { Vector posts = new Vector<>(); // DB connection and statement - Connection c = null; - PreparedStatement stmt = null; + Connection c; + PreparedStatement stmt; // try to get data from db try { @@ -34,41 +34,42 @@ public class Routes { c.setAutoCommit(false); // create a new statement - stmt = c.prepareStatement("WITH RECURSIVE targets AS (\n" + - " SELECT\n" + - " posts.id,\n" + - " posts.id AS parent,\n" + - " posts.author,\n" + - " posts.title,\n" + - " posts.content,\n" + - " posts.postdate,\n" + - " posts.postlocation[0] AS longitude,\n" + - " posts.postlocation[1] AS latitude,\n" + - " (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = TRUE) AS positive,\n" + - " (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = FALSE) AS negative\n" + - " FROM\n" + - " posts\n" + - " WHERE\n" + - " deleted IS NULL\n" + - " AND sqrt(power(postlocation[0] - (?), 2) + power(postlocation[1] - (?), 2)) <= 10\n" + - " AND posts.id NOT IN (SELECT child FROM comments)\n" + - " UNION\n" + - " SELECT\n" + - " com.child,\n" + - " com.parent,\n" + - " com.author,\n" + - " com.title,\n" + - " com.content,\n" + - " com.postdate,\n" + - " com.postlocation[0],\n" + - " com.postlocation[1],\n" + - " (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = TRUE) AS positive,\n" + - " (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = FALSE) AS negative\n" + - " FROM\n" + - " (SELECT * FROM comments inner join posts ON comments.child = posts.id) com\n" + - " inner join targets ON targets.id = com.parent\n" + - ")\n" + - "SELECT * FROM targets;"); + stmt = c.prepareStatement(""" + WITH RECURSIVE targets AS ( + SELECT + posts.id, + posts.id AS parent, + posts.author, + posts.title, + posts.content, + posts.postdate, + posts.postlocation[0] AS longitude, + posts.postlocation[1] AS latitude, + (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = TRUE) AS positive, + (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = FALSE) AS negative + FROM + posts + WHERE + deleted IS NULL + AND sqrt(power(postlocation[0] - (?), 2) + power(postlocation[1] - (?), 2)) <= 10 + AND posts.id NOT IN (SELECT child FROM comments) + UNION + SELECT + com.child, + com.parent, + com.author, + com.title, + com.content, + com.postdate, + com.postlocation[0], + com.postlocation[1], + (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = TRUE) AS positive, + (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = FALSE) AS negative + FROM + (SELECT * FROM comments inner join posts ON comments.child = posts.id) com + inner join targets ON targets.id = com.parent + ) + SELECT * FROM targets;"""); stmt.setObject(1, longitude); stmt.setObject(2, latitude); @@ -110,9 +111,7 @@ public class Routes { } // calculate anonymous IDs for the posts - posts.forEach(post -> { - post.anonymize(Optional.empty()); - }); + posts.forEach(post -> post.anonymize(Optional.empty())); // return the posts return posts; } @@ -123,8 +122,8 @@ public class Routes { Optional root_post = Optional.empty(); // DB connection and statement - Connection c = null; - PreparedStatement stmt = null; + Connection c; + PreparedStatement stmt; // try to get data from db try { @@ -139,41 +138,42 @@ public class Routes { c.setAutoCommit(false); // create a new statement - stmt = c.prepareStatement("WITH RECURSIVE targets AS (\n" + - " SELECT\n" + - " posts.id,\n" + - " posts.id AS parent,\n" + - " posts.author,\n" + - " posts.title,\n" + - " posts.content,\n" + - " posts.postdate,\n" + - " posts.postlocation[0] AS longitude,\n" + - " posts.postlocation[1] AS latitude,\n" + - " (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = TRUE) AS positive,\n" + - " (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = FALSE) AS negative\n" + - " FROM\n" + - " posts\n" + - " WHERE\n" + - " deleted IS NULL\n" + - " AND posts.id = (?)\n" + - " AND posts.id NOT IN (SELECT child FROM comments)\n" + - " UNION\n" + - " SELECT\n" + - " com.child,\n" + - " com.parent,\n" + - " com.author,\n" + - " com.title,\n" + - " com.content,\n" + - " com.postdate,\n" + - " com.postlocation[0],\n" + - " com.postlocation[1],\n" + - " (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = TRUE) AS positive,\n" + - " (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = FALSE) AS negative\n" + - " FROM\n" + - " (SELECT * FROM comments inner join posts ON comments.child = posts.id) com\n" + - " inner join targets ON targets.id = com.parent\n" + - ")\n" + - "SELECT * FROM targets;"); + stmt = c.prepareStatement(""" + WITH RECURSIVE targets AS ( + SELECT + posts.id, + posts.id AS parent, + posts.author, + posts.title, + posts.content, + posts.postdate, + posts.postlocation[0] AS longitude, + posts.postlocation[1] AS latitude, + (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = TRUE) AS positive, + (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = FALSE) AS negative + FROM + posts + WHERE + deleted IS NULL + AND posts.id = (?) + AND posts.id NOT IN (SELECT child FROM comments) + UNION + SELECT + com.child, + com.parent, + com.author, + com.title, + com.content, + com.postdate, + com.postlocation[0], + com.postlocation[1], + (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = TRUE) AS positive, + (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = FALSE) AS negative + FROM + (SELECT * FROM comments inner join posts ON comments.child = posts.id) com + inner join targets ON targets.id = com.parent + ) + SELECT * FROM targets;"""); stmt.setObject(1, id); @@ -224,8 +224,8 @@ public class Routes { @PostMapping("/posts") public JodelPost postPost(@RequestBody JodelPost post) { // DB connection and statement - Connection c = null; - PreparedStatement stmt = null; + Connection c; + PreparedStatement stmt; // try to get data from db try { @@ -298,8 +298,8 @@ public class Routes { @DeleteMapping("/post/{id}") public void deletePost(@PathVariable long id) { // DB connection and statement - Connection c = null; - PreparedStatement stmt = null; + Connection c; + PreparedStatement stmt; // try to get data from db try {