portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r992506 - in /portals/jetspeed-2/portal/trunk/components: jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/ jetspeed-statistics/src/main/java/org/apache/jetspeed/statistics/impl/
Date Fri, 03 Sep 2010 23:28:37 GMT
Author: woonsan
Date: Fri Sep  3 23:28:37 2010
New Revision: 992506

URL: http://svn.apache.org/viewvc?rev=992506&view=rev
Log:
JS2-1211: Closing properly on jdbc resources.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-statistics/src/main/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java?rev=992506&r1=992505&r2=992506&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLookupManagerAbstract.java
Fri Sep  3 23:28:37 2010
@@ -65,8 +65,11 @@ public abstract class JetspeedPrincipalL
 
 		int numberOfRecords = 0;
 		ArrayList<JetspeedPrincipal> results = new ArrayList<JetspeedPrincipal>();
+		
+        Connection conn = null;
 		PreparedStatement pstmt = null;
-		Connection conn = null;
+		ResultSet rs = null;
+		
 		try {
 			conn = PersistenceBrokerFactory.defaultPersistenceBroker().serviceConnectionManager().getConnection();
 
@@ -74,7 +77,7 @@ public abstract class JetspeedPrincipalL
 			// pstmt = conn.prepareStatement(sqlStr,
 			// ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
 			pstmt.setFetchSize((int) (queryContext.getOffset() + queryContext.getLength()));
-			ResultSet rs = pstmt.executeQuery();
+			rs = pstmt.executeQuery();
 			boolean hasRecords = rs.next();
 
 			if (hasRecords) {
@@ -97,7 +100,11 @@ public abstract class JetspeedPrincipalL
 						break;
 					}
 				}
+				
 				rs.close();
+                rs = null;
+                pstmt.close();
+                pstmt = null;
 
 				// get the total number of results effected by the query
 				int fromPos = baseSqlStr.toUpperCase().indexOf(" FROM ");
@@ -109,12 +116,12 @@ public abstract class JetspeedPrincipalL
 				if (orderPos >= 0) {
 					baseSqlStr = baseSqlStr.substring(0, orderPos);
 				}
+
 				pstmt = conn.prepareStatement(baseSqlStr);
 				rs = pstmt.executeQuery();
 				while (rs.next()) {
 					numberOfRecords += rs.getInt(1);
 				}
-				rs.close();
 			}
 		} catch (SQLException e) {
 			log.error("Error reading principal.", e);
@@ -123,13 +130,37 @@ public abstract class JetspeedPrincipalL
 		} catch (LookupException e) {
 			log.error("Error reading principal.", e);
 		} finally {
-			try {
-				if (conn != null && !conn.isClosed()) {
-					conn.close();
-				}
-			} catch (SQLException e) {
-				log.error("Error closing connection.", e);
-			}
+            if(rs != null) 
+            {
+                try 
+                {
+                    rs.close();
+                }
+                catch (Exception ignore) 
+                {
+                }
+            }
+            if(pstmt != null) 
+            {
+                try 
+                {
+                    pstmt.close();
+                }
+                catch (Exception ignore) 
+                {
+                }
+            }
+            if(conn != null) 
+            {
+                try 
+                {
+                    conn.close();
+                }
+                catch (Exception e) 
+                {
+                    log.error("error releasing the connection",e);
+                }
+            }
 		}
 		return new JetspeedPrincipalResultList(results, numberOfRecords);
 	}

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-statistics/src/main/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-statistics/src/main/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java?rev=992506&r1=992505&r2=992506&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-statistics/src/main/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-statistics/src/main/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
Fri Sep  3 23:28:37 2010
@@ -625,7 +625,7 @@ public class PortalStatisticsImpl extend
             throws InvalidCriteriaException
     {
         AggregateStatistics as = new AggregateStatisticsImpl();
-        String query;
+        String query1;
         String query2;
 
         String tableName;
@@ -660,7 +660,7 @@ public class PortalStatisticsImpl extend
 
         if (!PortalStatistics.QUERY_TYPE_USER.equals(queryType))
         {
-            query = "select count(*) as itemcount , MIN(ELAPSED_TIME) as amin ,AVG(ELAPSED_TIME)
as aavg ,MAX(ELAPSED_TIME) as amax from "
+            query1 = "select count(*) as itemcount , MIN(ELAPSED_TIME) as amin ,AVG(ELAPSED_TIME)
as aavg ,MAX(ELAPSED_TIME) as amax from "
                     + tableName + " where time_stamp > ? and time_stamp < ?";
             query2 = "select count(*) as itemcount ,"
                     + groupColumn
@@ -670,7 +670,7 @@ public class PortalStatisticsImpl extend
                     + groupColumn + "  order by " + orderColumn + " " + ascDesc;
         } else
         {
-            query = "select count(*) as itemcount , MIN(ELAPSED_TIME) as amin,AVG(ELAPSED_TIME)
as aavg ,MAX(ELAPSED_TIME) as amax from "
+            query1 = "select count(*) as itemcount , MIN(ELAPSED_TIME) as amin,AVG(ELAPSED_TIME)
as aavg ,MAX(ELAPSED_TIME) as amax from "
                     + tableName
                     + " where time_stamp > ? and time_stamp < ? and status = 2";
             query2 = "select count(*) as itemcount ,"
@@ -681,14 +681,20 @@ public class PortalStatisticsImpl extend
                     + " where time_stamp > ? and time_stamp < ? and status = 2 group
by "
                     + groupColumn + "  order by " + orderColumn + " " + ascDesc;
         }
+        
         Connection con = null;
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        
         try
         {
             con = ds.getConnection();
-            PreparedStatement pstmt = con.prepareStatement(query);
+            
+            // query 1
+            pstmt = con.prepareStatement(query1);
             pstmt.setTimestamp(1, new Timestamp(start.getTime()));
             pstmt.setTimestamp(2, new Timestamp(end.getTime()));
-            ResultSet rs = pstmt.executeQuery();
+            rs = pstmt.executeQuery();
             float denominator = 1.0f;
             if (PortalStatistics.QUERY_TYPE_USER.equals(queryType))
             {
@@ -702,12 +708,18 @@ public class PortalStatisticsImpl extend
                 as.setMinProcessingTime(rs.getFloat("amin") / denominator);
                 as.setAvgProcessingTime(rs.getFloat("aavg") / denominator);
                 as.setMaxProcessingTime(rs.getFloat("amax") / denominator);
-
             }
-            PreparedStatement pstmt2 = con.prepareStatement(query2);
-            pstmt2.setTimestamp(1, new Timestamp(start.getTime()));
-            pstmt2.setTimestamp(2, new Timestamp(end.getTime()));
-            ResultSet rs2 = pstmt2.executeQuery();
+            
+            rs.close();
+            rs = null;
+            pstmt.close();
+            pstmt = null;
+            
+            // query 2
+            pstmt = con.prepareStatement(query2);
+            pstmt.setTimestamp(1, new Timestamp(start.getTime()));
+            pstmt.setTimestamp(2, new Timestamp(end.getTime()));
+            rs = pstmt.executeQuery();
 
             int rowCount = 0;
             int totalRows = 5;
@@ -724,11 +736,11 @@ public class PortalStatisticsImpl extend
                 totalRows = temp;
             }
             
-            while ((rs2.next()) && (rowCount < totalRows))
+            while ((rs.next()) && (rowCount < totalRows))
             {
                 Map row = new HashMap();
-                row.put("count", "" + rs2.getInt("itemcount"));
-                String col = rs2.getString(groupColumn);
+                row.put("count", "" + rs.getInt("itemcount"));
+                String col = rs.getString(groupColumn);
                 int maxColLen = 35;
                 if (col != null)
                 {
@@ -741,11 +753,11 @@ public class PortalStatisticsImpl extend
 
                 row.put("groupColumn", col);
                 row.put("min", ""
-                        + floatFormatter(rs2.getFloat("amin") / denominator));
+                        + floatFormatter(rs.getFloat("amin") / denominator));
                 row.put("avg", ""
-                        + floatFormatter(rs2.getFloat("aavg") / denominator));
+                        + floatFormatter(rs.getFloat("aavg") / denominator));
                 row.put("max", ""
-                        + floatFormatter(rs2.getFloat("amax") / denominator));
+                        + floatFormatter(rs.getFloat("amax") / denominator));
                 as.addRow(row);
                 rowCount++;
             }
@@ -757,16 +769,36 @@ public class PortalStatisticsImpl extend
         }
         finally 
         {
-            try 
+            if(rs != null) 
             {
-                if(con != null) 
+                try 
                 {
-                    con.close();
+                    rs.close();
                 }
-            } 
-            catch (SQLException e) 
+                catch (Exception ignore) 
+                {
+                }
+            }
+            if(pstmt != null) 
+            {
+                try 
+                {
+                    pstmt.close();
+                }
+                catch (Exception ignore) 
+                {
+                }
+            }
+            if(con != null) 
             {
-                logger.error("error releasing the connection",e);
+                try 
+                {
+                    con.close();
+                }
+                catch (Exception e) 
+                {
+                    logger.error("error releasing the connection",e);
+                }
             }
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message