r8501@libaxis1 (orig r2366): grahamtriggs | 2007-11-26 06:03:40 -0500

Fixed connection / context leak in ItemCounter


git-svn-id: http://scm.dspace.org/svn/repo/trunk@2387 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Mark Diggory
2007-11-26 20:28:52 +00:00
parent 293b1f3538
commit a106e7b3ab
2 changed files with 15 additions and 58 deletions

View File

@@ -78,32 +78,12 @@ public class ItemCounter
* @param args
*/
public static void main(String[] args)
throws ItemCountException
throws ItemCountException, SQLException
{
ItemCounter ic = new ItemCounter();
Context context = new Context();
ItemCounter ic = new ItemCounter(context);
ic.buildItemCounts();
ic.completeContext();
}
/**
* Construct a new item counter which will create its own
* DSpace Context
*
* @throws ItemCountException
*/
public ItemCounter()
throws ItemCountException
{
try
{
this.context = new Context();
this.dao = ItemCountDAOFactory.getInstance(this.context);
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
context.complete();
}
/**
@@ -120,30 +100,6 @@ public class ItemCounter
this.dao = ItemCountDAOFactory.getInstance(this.context);
}
/**
* Complete the context being used by this class. This exists so that
* instances of this class which created their own instance of the
* DSpace Context can also terminate it. For Context object which were
* passed in by the constructor, the caller is responsible for
* either calling this method themselves or completing the context
* when they need to.
*
* @throws ItemCountException
*/
public void completeContext()
throws ItemCountException
{
try
{
this.context.complete();
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
}
/**
* This method does the grunt work of drilling through and iterating
* over all of the communities and collections in the system and

View File

@@ -55,16 +55,17 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page import="java.util.Map" %>
<%@ page import="org.dspace.app.webui.servlet.admin.EditCommunitiesServlet" %>
<%@ page import="org.dspace.app.webui.util.UIUtil" %>
<%@ page import="org.dspace.browse.ItemCountException" %>
<%@ page import="org.dspace.browse.ItemCounter" %>
<%@ page import="org.dspace.content.Collection" %>
<%@ page import="org.dspace.content.Community" %>
<%@ page import="org.dspace.core.ConfigurationManager" %>
<%@ page import="javax.servlet.jsp.jstl.fmt.LocaleSupport" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="javax.servlet.jsp.jstl.fmt.LocaleSupport" %>
<%@ page import="org.dspace.content.Community" %>
<%@ page import="org.dspace.content.Collection" %>
<%@ page import="org.dspace.app.webui.servlet.admin.EditCommunitiesServlet" %>
<%@ page import="org.dspace.core.ConfigurationManager" %>
<%@ page import="org.dspace.browse.ItemCounter" %>
<%@ page import="org.dspace.browse.ItemCountException" %>
<%@ page import="java.util.Map" %>
<%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %>
@@ -75,7 +76,7 @@
Boolean admin_b = (Boolean)request.getAttribute("admin_button");
boolean admin_button = (admin_b == null ? false : admin_b.booleanValue());
boolean showAll = true;
ItemCounter ic = new ItemCounter();
ItemCounter ic = new ItemCounter(UIUtil.obtainContext(request));
%>
<%!
@@ -90,7 +91,7 @@
void showCommunity(Community c) throws ItemCountException, IOException, SQLException
{
ItemCounter ic = new ItemCounter();
ItemCounter ic = new ItemCounter(UIUtil.obtainContext(request));
out.println( "<li class=\"communityLink\">" );
out.println( "<strong><a href=\"" + request.getContextPath() + "/handle/" + c.getHandle() + "\">" + c.getMetadata("name") + "</a></strong>");
if(ConfigurationManager.getBooleanProperty("webui.strengths.show"))