removed all warnings

This commit is contained in:
2024-06-05 11:53:30 +02:00
parent 49254f3d87
commit ee65a2cf60
2 changed files with 82 additions and 83 deletions

View File

@@ -120,7 +120,6 @@ public class JodelPost {
@JsonIgnore @JsonIgnore
public boolean isComment() { public boolean isComment() {
if (parent.isEmpty()) return false; return parent.filter(aLong -> !Objects.equals(id, aLong)).isPresent();
return !Objects.equals(id, parent.get());
} }
} }

View File

@@ -18,8 +18,8 @@ public class Routes {
Vector<JodelPost> posts = new Vector<>(); Vector<JodelPost> posts = new Vector<>();
// DB connection and statement // DB connection and statement
Connection c = null; Connection c;
PreparedStatement stmt = null; PreparedStatement stmt;
// try to get data from db // try to get data from db
try { try {
@@ -34,41 +34,42 @@ public class Routes {
c.setAutoCommit(false); c.setAutoCommit(false);
// create a new statement // create a new statement
stmt = c.prepareStatement("WITH RECURSIVE targets AS (\n" + stmt = c.prepareStatement("""
" SELECT\n" + WITH RECURSIVE targets AS (
" posts.id,\n" + SELECT
" posts.id AS parent,\n" + posts.id,
" posts.author,\n" + posts.id AS parent,
" posts.title,\n" + posts.author,
" posts.content,\n" + posts.title,
" posts.postdate,\n" + posts.content,
" posts.postlocation[0] AS longitude,\n" + posts.postdate,
" posts.postlocation[1] AS latitude,\n" + posts.postlocation[0] AS longitude,
" (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = TRUE) AS positive,\n" + posts.postlocation[1] AS latitude,
" (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = FALSE) AS negative\n" + (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = TRUE) AS positive,
" FROM\n" + (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = FALSE) AS negative
" posts\n" + FROM
" WHERE\n" + posts
" deleted IS NULL\n" + WHERE
" AND sqrt(power(postlocation[0] - (?), 2) + power(postlocation[1] - (?), 2)) <= 10\n" + deleted IS NULL
" AND posts.id NOT IN (SELECT child FROM comments)\n" + AND sqrt(power(postlocation[0] - (?), 2) + power(postlocation[1] - (?), 2)) <= 10
" UNION\n" + AND posts.id NOT IN (SELECT child FROM comments)
" SELECT\n" + UNION
" com.child,\n" + SELECT
" com.parent,\n" + com.child,
" com.author,\n" + com.parent,
" com.title,\n" + com.author,
" com.content,\n" + com.title,
" com.postdate,\n" + com.content,
" com.postlocation[0],\n" + com.postdate,
" com.postlocation[1],\n" + com.postlocation[0],
" (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = TRUE) AS positive,\n" + com.postlocation[1],
" (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = FALSE) AS negative\n" + (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = TRUE) AS positive,
" FROM\n" + (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = FALSE) AS negative
" (SELECT * FROM comments inner join posts ON comments.child = posts.id) com\n" + FROM
" inner join targets ON targets.id = com.parent\n" + (SELECT * FROM comments inner join posts ON comments.child = posts.id) com
")\n" + inner join targets ON targets.id = com.parent
"SELECT * FROM targets;"); )
SELECT * FROM targets;""");
stmt.setObject(1, longitude); stmt.setObject(1, longitude);
stmt.setObject(2, latitude); stmt.setObject(2, latitude);
@@ -110,9 +111,7 @@ public class Routes {
} }
// calculate anonymous IDs for the posts // calculate anonymous IDs for the posts
posts.forEach(post -> { posts.forEach(post -> post.anonymize(Optional.empty()));
post.anonymize(Optional.empty());
});
// return the posts // return the posts
return posts; return posts;
} }
@@ -123,8 +122,8 @@ public class Routes {
Optional<JodelPost> root_post = Optional.empty(); Optional<JodelPost> root_post = Optional.empty();
// DB connection and statement // DB connection and statement
Connection c = null; Connection c;
PreparedStatement stmt = null; PreparedStatement stmt;
// try to get data from db // try to get data from db
try { try {
@@ -139,41 +138,42 @@ public class Routes {
c.setAutoCommit(false); c.setAutoCommit(false);
// create a new statement // create a new statement
stmt = c.prepareStatement("WITH RECURSIVE targets AS (\n" + stmt = c.prepareStatement("""
" SELECT\n" + WITH RECURSIVE targets AS (
" posts.id,\n" + SELECT
" posts.id AS parent,\n" + posts.id,
" posts.author,\n" + posts.id AS parent,
" posts.title,\n" + posts.author,
" posts.content,\n" + posts.title,
" posts.postdate,\n" + posts.content,
" posts.postlocation[0] AS longitude,\n" + posts.postdate,
" posts.postlocation[1] AS latitude,\n" + posts.postlocation[0] AS longitude,
" (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = TRUE) AS positive,\n" + posts.postlocation[1] AS latitude,
" (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = FALSE) AS negative\n" + (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = TRUE) AS positive,
" FROM\n" + (SELECT count(*) FROM reaction WHERE reaction.post = posts.id AND positive = FALSE) AS negative
" posts\n" + FROM
" WHERE\n" + posts
" deleted IS NULL\n" + WHERE
" AND posts.id = (?)\n" + deleted IS NULL
" AND posts.id NOT IN (SELECT child FROM comments)\n" + AND posts.id = (?)
" UNION\n" + AND posts.id NOT IN (SELECT child FROM comments)
" SELECT\n" + UNION
" com.child,\n" + SELECT
" com.parent,\n" + com.child,
" com.author,\n" + com.parent,
" com.title,\n" + com.author,
" com.content,\n" + com.title,
" com.postdate,\n" + com.content,
" com.postlocation[0],\n" + com.postdate,
" com.postlocation[1],\n" + com.postlocation[0],
" (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = TRUE) AS positive,\n" + com.postlocation[1],
" (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = FALSE) AS negative\n" + (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = TRUE) AS positive,
" FROM\n" + (SELECT count(*) FROM reaction WHERE reaction.post = com.child AND positive = FALSE) AS negative
" (SELECT * FROM comments inner join posts ON comments.child = posts.id) com\n" + FROM
" inner join targets ON targets.id = com.parent\n" + (SELECT * FROM comments inner join posts ON comments.child = posts.id) com
")\n" + inner join targets ON targets.id = com.parent
"SELECT * FROM targets;"); )
SELECT * FROM targets;""");
stmt.setObject(1, id); stmt.setObject(1, id);
@@ -224,8 +224,8 @@ public class Routes {
@PostMapping("/posts") @PostMapping("/posts")
public JodelPost postPost(@RequestBody JodelPost post) { public JodelPost postPost(@RequestBody JodelPost post) {
// DB connection and statement // DB connection and statement
Connection c = null; Connection c;
PreparedStatement stmt = null; PreparedStatement stmt;
// try to get data from db // try to get data from db
try { try {
@@ -298,8 +298,8 @@ public class Routes {
@DeleteMapping("/post/{id}") @DeleteMapping("/post/{id}")
public void deletePost(@PathVariable long id) { public void deletePost(@PathVariable long id) {
// DB connection and statement // DB connection and statement
Connection c = null; Connection c;
PreparedStatement stmt = null; PreparedStatement stmt;
// try to get data from db // try to get data from db
try { try {