A few improvements
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 5 Oct 2016 01:03:06 +0000 (03:03 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 5 Oct 2016 01:03:06 +0000 (03:03 +0200)
src/main/java/com/prueba/core/context/integration/database/impl/DataBaseAccessImpl.java
src/main/java/com/prueba/services/impl/LoginServiceImpl.java

index debe67a..2d85205 100644 (file)
@@ -42,8 +42,7 @@ public class DataBaseAccessImpl implements DataBaseAccess {
        protected List<Map<String, String>> executeQueryThrowable(
                        String query, ExecuteResultSet<ResultSet> 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();
                }
        }
        
index dd3a6f0..05b885a 100644 (file)
@@ -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);