Skip to content

Commit c3c143f

Browse files
committed
-fix resource leaks
1 parent db808db commit c3c143f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/com/leetcoders/token_registration/utils/PostgresHandler.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@ name varchar(255) PRIMARY KEY,
2121
access_key varchar(255),
2222
companies text ARRAY,
2323
solved_questions int,
24-
time_to_update timestamp
24+
time_to_update timestamp,
25+
being_processed BOOLEAN
2526
);
2627
END IF;
2728
END $$;
2829
""";
2930
private static final String UPDATE_USER_DETAILS = """
30-
INSERT INTO user_details (name, access_key, companies, solved_questions, time_to_update)
31+
INSERT INTO user_details (name, access_key, companies, solved_questions, time_to_update, being_processed)
3132
VALUES
3233
(
3334
?,
3435
?,
3536
?,
3637
0,
37-
now() AT TIME ZONE 'UTC'
38+
now() AT TIME ZONE 'UTC',
39+
FALSE
3840
)
3941
ON CONFLICT (name)
4042
DO
4143
UPDATE
42-
SET name=?, access_key=?, companies=?, time_to_update=now() AT TIME ZONE 'UTC';
44+
SET name=?, access_key=?, companies=?, time_to_update=now() AT TIME ZONE 'UTC', being_processed=FALSE;
4345
""";
4446
private static final Logger logger = LoggerFactory.getLogger(PostgresHandler.class);
4547
private static final String DB_NAME = "leetcode-rs";
@@ -71,8 +73,7 @@ protected void initializeUserTable() {
7173
}
7274

7375
public boolean updateUserDetails(UserDetails userDetails) {
74-
try (Connection connection = ds.getConnection()) {
75-
var statement = connection.prepareStatement(UPDATE_USER_DETAILS);
76+
try (Connection connection = ds.getConnection(); var statement = connection.prepareStatement(UPDATE_USER_DETAILS)) {
7677
statement.setString(1, userDetails.name());
7778
statement.setString(4, userDetails.name());
7879
statement.setString(2, userDetails.token());

0 commit comments

Comments
 (0)