[exo-jcr-commits] exo-jcr SVN: r4959 - core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/jdbc.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Sep 23 05:51:52 EDT 2011


Author: tolusha
Date: 2011-09-23 05:51:52 -0400 (Fri, 23 Sep 2011)
New Revision: 4959

Modified:
   core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/jdbc/JDBCListAccess.java
Log:
EXOJCR-1492: close resultSet on finally block

Modified: core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/jdbc/JDBCListAccess.java
===================================================================
--- core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/jdbc/JDBCListAccess.java	2011-09-23 09:48:50 UTC (rev 4958)
+++ core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/jdbc/JDBCListAccess.java	2011-09-23 09:51:52 UTC (rev 4959)
@@ -106,11 +106,12 @@
     */
    public E[] load(int index, int length) throws Exception, IllegalArgumentException
    {
-      Connection connection = null;
+      Statement statement = null;
+      ResultSet resultSet = null;
+
+      Connection connection = dao.getExoDatasource().getConnection();
       try
       {
-         connection = dao.getExoDatasource().getConnection();
-
          if (index < 0)
          {
             throw new IllegalArgumentException("Illegal index: index must be a positive number");
@@ -123,13 +124,12 @@
 
          List<E> entities = new ArrayList<E>(length);
 
-         Statement statement =
-            connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
-         ResultSet resultSet = statement.executeQuery(findQuery);
+         statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+         resultSet = statement.executeQuery(findQuery);
 
          for (int p = 0, counter = 0; counter < length; p++)
          {
-            if (resultSet.isAfterLast())
+            if (!resultSet.next())
                throw new IllegalArgumentException(
                   "Illegal index or length: sum of the index and the length cannot be greater than the list size");
 
@@ -145,13 +145,20 @@
             }
          }
 
-         resultSet.close();
-         statement.close();
-
          return (E[])entities.toArray();
       }
       finally
       {
+         if (resultSet != null)
+         {
+            resultSet.close();
+         }
+
+         if (statement != null)
+         {
+            statement.close();
+         }
+
          dao.getExoDatasource().closeConnection(connection);
       }
    }



More information about the exo-jcr-commits mailing list