From e6f720cc799c3e5537c49ffa2db1874be93cc931 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Wed, 5 Oct 2016 03:03:06 +0200 Subject: [PATCH] A few improvements --- .../context/integration/database/impl/DataBaseAccessImpl.java | 10 ++-------- src/main/java/com/prueba/services/impl/LoginServiceImpl.java | 3 ++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/prueba/core/context/integration/database/impl/DataBaseAccessImpl.java b/src/main/java/com/prueba/core/context/integration/database/impl/DataBaseAccessImpl.java index debe67a..2d85205 100644 --- a/src/main/java/com/prueba/core/context/integration/database/impl/DataBaseAccessImpl.java +++ b/src/main/java/com/prueba/core/context/integration/database/impl/DataBaseAccessImpl.java @@ -42,8 +42,7 @@ public class DataBaseAccessImpl implements DataBaseAccess { protected List> executeQueryThrowable( String query, ExecuteResultSet executeResultSet, FillPreparedStatement fillStatement) throws SQLException { - final Connection connection = this.dataSource.getConnection(); - try { + try (final Connection connection = this.dataSource.getConnection()) { return this.doExecuteQuery( query, connection, @@ -54,8 +53,6 @@ public class DataBaseAccessImpl implements DataBaseAccess { return preparedStatement.executeQuery(); }, executeResultSet); - } finally { - connection.close(); } } @@ -88,8 +85,7 @@ public class DataBaseAccessImpl implements DataBaseAccess { protected void executeUpdateThrowable( String query, FillPreparedStatement fillStatement) throws SQLException { - final Connection connection = this.dataSource.getConnection(); - try { + try (final Connection connection = this.dataSource.getConnection()) { this.doExecuteUpdate( query, connection, @@ -99,8 +95,6 @@ public class DataBaseAccessImpl implements DataBaseAccess { preparedStatement.executeUpdate(); }); - } finally { - connection.close(); } } diff --git a/src/main/java/com/prueba/services/impl/LoginServiceImpl.java b/src/main/java/com/prueba/services/impl/LoginServiceImpl.java index dd3a6f0..05b885a 100644 --- a/src/main/java/com/prueba/services/impl/LoginServiceImpl.java +++ b/src/main/java/com/prueba/services/impl/LoginServiceImpl.java @@ -31,7 +31,8 @@ public class LoginServiceImpl { public void processLogoutGet(HttpExchange httpExchange) throws IOException { final Headers headers = httpExchange.getRequestHeaders(); - final String cookieValue = headers.getFirst(COOKIE_HEADER); + final String cookieValue = headers.getFirst(COOKIE_HEADER); + if (cookieValue != null) { final UUID uuid = UUID.fromString(cookieValue); Sessions.getInstance().removeSession(uuid); -- 2.1.4