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
public boolean isComment() {
if (parent.isEmpty()) return false;
return !Objects.equals(id, parent.get());
return parent.filter(aLong -> !Objects.equals(id, aLong)).isPresent();
}
}

View File

@@ -18,8 +18,8 @@ public class Routes {
Vector<JodelPost> 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<JodelPost> 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 {