From eaf04f18001159cf5aaa3c9747a300b48e8d3f2f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 18 Dec 2022 11:16:03 +0300 Subject: Correct unwrapped DataSource connection usage --- src/main/java/com/juick/service/PostgreGINService.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/juick') diff --git a/src/main/java/com/juick/service/PostgreGINService.java b/src/main/java/com/juick/service/PostgreGINService.java index ca326bd5..583836a7 100644 --- a/src/main/java/com/juick/service/PostgreGINService.java +++ b/src/main/java/com/juick/service/PostgreGINService.java @@ -49,11 +49,9 @@ public class PostgreGINService extends BaseJdbcService implements SearchService DataSource dataSource; private String escapeQuery(String searchString) { - try { - if (dataSource.getConnection().isWrapperFor(PGConnection.class)) { - PGConnection connection = dataSource.getConnection().unwrap(PGConnection.class); - return connection.escapeLiteral(searchString); - } + try (var connection = dataSource.getConnection()) { + var pg = connection.unwrap(PGConnection.class); + return pg.escapeLiteral(searchString); } catch (SQLException e) { e.printStackTrace(); } -- cgit v1.2.3