mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
Fix various problems with resources potentially not being freed, and other minor fixes suggested by FindBugs
git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@3036 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -98,59 +98,62 @@ public class HandleDispatcher implements BitstreamDispatcher
|
||||
* @throws SQLException
|
||||
* if database access fails.
|
||||
*/
|
||||
private void init()
|
||||
private synchronized void init()
|
||||
{
|
||||
Context context = null;
|
||||
int dsoType = -1;
|
||||
|
||||
int id = -1;
|
||||
try
|
||||
if (init == Boolean.FALSE)
|
||||
{
|
||||
context = new Context();
|
||||
DSpaceObject dso = HandleManager.resolveToObject(context, handle);
|
||||
id = dso.getID();
|
||||
dsoType = dso.getType();
|
||||
context.abort();
|
||||
Context context = null;
|
||||
int dsoType = -1;
|
||||
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOG.error("init error " + e.getMessage(), e);
|
||||
throw new RuntimeException("init error" + e.getMessage(), e);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Abort the context if it's still valid
|
||||
if ((context != null) && context.isValid())
|
||||
int id = -1;
|
||||
try
|
||||
{
|
||||
context = new Context();
|
||||
DSpaceObject dso = HandleManager.resolveToObject(context, handle);
|
||||
id = dso.getID();
|
||||
dsoType = dso.getType();
|
||||
context.abort();
|
||||
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LOG.error("init error " + e.getMessage(), e);
|
||||
throw new RuntimeException("init error" + e.getMessage(), e);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Abort the context if it's still valid
|
||||
if ((context != null) && context.isValid())
|
||||
{
|
||||
context.abort();
|
||||
}
|
||||
}
|
||||
|
||||
List ids = new ArrayList();
|
||||
|
||||
switch (dsoType)
|
||||
{
|
||||
case Constants.BITSTREAM:
|
||||
ids.add(new Integer(id));
|
||||
break;
|
||||
|
||||
case Constants.ITEM:
|
||||
ids = bitstreamInfoDAO.getItemBitstreams(id);
|
||||
break;
|
||||
|
||||
case Constants.COLLECTION:
|
||||
ids = bitstreamInfoDAO.getCollectionBitstreams(id);
|
||||
break;
|
||||
|
||||
case Constants.COMMUNITY:
|
||||
ids = bitstreamInfoDAO.getCommunityBitstreams(id);
|
||||
break;
|
||||
}
|
||||
|
||||
delegate = new ListDispatcher(ids);
|
||||
init = Boolean.TRUE;
|
||||
}
|
||||
|
||||
List ids = new ArrayList();
|
||||
|
||||
switch (dsoType)
|
||||
{
|
||||
case Constants.BITSTREAM:
|
||||
ids.add(new Integer(id));
|
||||
break;
|
||||
|
||||
case Constants.ITEM:
|
||||
ids = bitstreamInfoDAO.getItemBitstreams(id);
|
||||
break;
|
||||
|
||||
case Constants.COLLECTION:
|
||||
ids = bitstreamInfoDAO.getCollectionBitstreams(id);
|
||||
break;
|
||||
|
||||
case Constants.COMMUNITY:
|
||||
ids = bitstreamInfoDAO.getCommunityBitstreams(id);
|
||||
break;
|
||||
}
|
||||
|
||||
delegate = new ListDispatcher(ids);
|
||||
init = Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,12 +163,9 @@ public class HandleDispatcher implements BitstreamDispatcher
|
||||
*/
|
||||
public int next()
|
||||
{
|
||||
synchronized (init)
|
||||
if (init == Boolean.FALSE)
|
||||
{
|
||||
if (init == Boolean.FALSE)
|
||||
{
|
||||
init();
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
return delegate.next();
|
||||
|
Reference in New Issue
Block a user