Skip to content

Commit

Permalink
-fix resource leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ronen4822 committed Aug 6, 2024
1 parent db808db commit c3c143f
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@ name varchar(255) PRIMARY KEY,
access_key varchar(255),
companies text ARRAY,
solved_questions int,
time_to_update timestamp
time_to_update timestamp,
being_processed BOOLEAN
);
END IF;
END $$;
""";
private static final String UPDATE_USER_DETAILS = """
INSERT INTO user_details (name, access_key, companies, solved_questions, time_to_update)
INSERT INTO user_details (name, access_key, companies, solved_questions, time_to_update, being_processed)
VALUES
(
?,
?,
?,
0,
now() AT TIME ZONE 'UTC'
now() AT TIME ZONE 'UTC',
FALSE
)
ON CONFLICT (name)
DO
UPDATE
SET name=?, access_key=?, companies=?, time_to_update=now() AT TIME ZONE 'UTC';
SET name=?, access_key=?, companies=?, time_to_update=now() AT TIME ZONE 'UTC', being_processed=FALSE;
""";
private static final Logger logger = LoggerFactory.getLogger(PostgresHandler.class);
private static final String DB_NAME = "leetcode-rs";
Expand Down Expand Up @@ -71,8 +73,7 @@ protected void initializeUserTable() {
}

public boolean updateUserDetails(UserDetails userDetails) {
try (Connection connection = ds.getConnection()) {
var statement = connection.prepareStatement(UPDATE_USER_DETAILS);
try (Connection connection = ds.getConnection(); var statement = connection.prepareStatement(UPDATE_USER_DETAILS)) {
statement.setString(1, userDetails.name());
statement.setString(4, userDetails.name());
statement.setString(2, userDetails.token());
Expand Down

0 comments on commit c3c143f

Please # to comment.