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:
Graham Triggs
2008-08-06 15:52:30 +00:00
parent 44cdd859a8
commit 9ae95a94e7
42 changed files with 1972 additions and 1190 deletions

View File

@@ -242,10 +242,19 @@ public class METSExport
+ File.separator + "config" + File.separator + "dc2mods.cfg";
// Read it in
InputStream is = new FileInputStream(configFile);
InputStream is = null;
try
{
is = new FileInputStream(configFile);
dcToMODS = new Properties();
dcToMODS.load(is);
}
finally
{
if (is != null)
try { is.close(); } catch (IOException ioe) { }
}
}
/**
* Write out the AIP for the given item to the given directory. A new

View File

@@ -563,6 +563,8 @@ public class ReportGenerator
FileReader fr = null;
BufferedReader br = null;
try
{
// read in the map file, printing a warning if none is found
String record = null;
try
@@ -588,6 +590,15 @@ public class ReportGenerator
}
}
}
finally
{
if (br != null)
try { br.close(); } catch (IOException ioe) { }
if (fr != null)
try { fr.close(); } catch (IOException ioe) { }
}
}
/**

View File

@@ -140,12 +140,13 @@ public class X509Authentication
// First look for keystore full of trusted certs.
if (keystorePath != null)
{
FileInputStream fis = null;
if (keystorePassword == null)
keystorePassword = "";
try {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(keystorePath),
keystorePassword.toCharArray());
fis = new FileInputStream(keystorePath);
ks.load(fis, keystorePassword.toCharArray());
caCertKeyStore = ks;
}
catch (IOException e)
@@ -158,14 +159,22 @@ public class X509Authentication
log.error("X509Authentication: Failed to extract CA keystore, file="+
keystorePath+", error="+e.toString());
}
finally
{
if (fis != null)
try { fis.close(); } catch (IOException ioe) { }
}
}
// Second, try getting public key out of CA cert, if that's configured.
if (caCertPath != null)
{
InputStream is = null;
FileInputStream fis = null;
try
{
InputStream is = new BufferedInputStream(new FileInputStream(caCertPath));
fis = new FileInputStream(caCertPath);
is = new BufferedInputStream(fis);
X509Certificate cert = (X509Certificate) CertificateFactory
.getInstance("X.509").generateCertificate(is);
if (cert != null)
@@ -181,6 +190,14 @@ public class X509Authentication
log.error("X509Authentication: Failed to extract CA cert, file="+
caCertPath+", error="+e.toString());
}
finally
{
if (is != null)
try { is.close(); } catch (IOException ioe) { }
if (fis != null)
try { fis.close(); } catch (IOException ioe) { }
}
}
}

View File

@@ -424,6 +424,8 @@ public class AuthorizeManager
List<ResourcePolicy> policies = new ArrayList();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -441,7 +443,12 @@ public class AuthorizeManager
policies.add(new ResourcePolicy(c, row));
}
}
}
finally
{
if (tri != null)
tri.close();
}
return policies;
}
@@ -463,6 +470,8 @@ public class AuthorizeManager
List<ResourcePolicy> policies = new ArrayList<ResourcePolicy>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -480,7 +489,12 @@ public class AuthorizeManager
policies.add(new ResourcePolicy(c, row));
}
}
}
finally
{
if (tri != null)
tri.close();
}
return policies;
}
@@ -507,6 +521,8 @@ public class AuthorizeManager
List<ResourcePolicy> policies = new ArrayList<ResourcePolicy>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -524,7 +540,12 @@ public class AuthorizeManager
policies.add(new ResourcePolicy(c, row));
}
}
}
finally
{
if (tri != null)
tri.close();
}
return policies;
}
@@ -699,6 +720,8 @@ public class AuthorizeManager
"AND resource_id= ? AND action_id= ? ",o.getType(),o.getID(),actionID);
List<Group> groups = new ArrayList<Group>();
try
{
while (tri.hasNext())
{
@@ -727,7 +750,12 @@ public class AuthorizeManager
groups.add(myGroup);
}
}
}
finally
{
if (tri != null)
tri.close();
}
Group[] groupArray = new Group[groups.size()];
groupArray = groups.toArray(groupArray);

View File

@@ -96,11 +96,12 @@ public class ItemCountDAOOracle implements ItemCountDAO
public void collectionCount(Collection collection, int count)
throws ItemCountException
{
TableRowIterator tri = null;
try
{
// first find out if we have a record
Object[] sparams = { new Integer(collection.getID()) };
TableRowIterator tri = DatabaseManager.query(context, collectionSelect, sparams);
tri = DatabaseManager.query(context, collectionSelect, sparams);
if (tri.hasNext())
{
@@ -112,14 +113,17 @@ public class ItemCountDAOOracle implements ItemCountDAO
Object[] params = { new Integer(collection.getID()), new Integer(count) };
DatabaseManager.updateQuery(context, collectionInsert, params);
}
tri.close();
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
finally
{
if (tri != null)
tri.close();
}
}
/**
@@ -132,11 +136,12 @@ public class ItemCountDAOOracle implements ItemCountDAO
public void communityCount(Community community, int count)
throws ItemCountException
{
TableRowIterator tri = null;
try
{
// first find out if we have a record
Object[] sparams = { new Integer(community.getID()) };
TableRowIterator tri = DatabaseManager.query(context, communitySelect, sparams);
tri = DatabaseManager.query(context, communitySelect, sparams);
if (tri.hasNext())
{
@@ -148,14 +153,17 @@ public class ItemCountDAOOracle implements ItemCountDAO
Object[] params = { new Integer(community.getID()), new Integer(count) };
DatabaseManager.updateQuery(context, communityInsert, params);
}
tri.close();
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
finally
{
if (tri != null)
tri.close();
}
}
/**
@@ -268,10 +276,11 @@ public class ItemCountDAOOracle implements ItemCountDAO
private int getCollectionCount(Collection collection)
throws ItemCountException
{
TableRowIterator tri = null;
try
{
Object[] params = { new Integer(collection.getID()) };
TableRowIterator tri = DatabaseManager.query(context, collectionSelect, params);
tri = DatabaseManager.query(context, collectionSelect, params);
if (!tri.hasNext())
{
@@ -285,8 +294,6 @@ public class ItemCountDAOOracle implements ItemCountDAO
throw new ItemCountException("More than one count row in the database");
}
tri.close();
return tr.getIntColumn("count");
}
catch (SQLException e)
@@ -294,6 +301,11 @@ public class ItemCountDAOOracle implements ItemCountDAO
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
finally
{
if (tri != null)
tri.close();
}
}
/**
@@ -306,10 +318,11 @@ public class ItemCountDAOOracle implements ItemCountDAO
private int getCommunityCount(Community community)
throws ItemCountException
{
TableRowIterator tri = null;
try
{
Object[] params = { new Integer(community.getID()) };
TableRowIterator tri = DatabaseManager.query(context, communitySelect, params);
tri = DatabaseManager.query(context, communitySelect, params);
if (!tri.hasNext())
{
@@ -323,8 +336,6 @@ public class ItemCountDAOOracle implements ItemCountDAO
throw new ItemCountException("More than one count row in the database");
}
tri.close();
return tr.getIntColumn("count");
}
catch (SQLException e)
@@ -332,5 +343,10 @@ public class ItemCountDAOOracle implements ItemCountDAO
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
finally
{
if (tri != null)
tri.close();
}
}
}

View File

@@ -96,11 +96,12 @@ public class ItemCountDAOPostgres implements ItemCountDAO
public void collectionCount(Collection collection, int count)
throws ItemCountException
{
TableRowIterator tri = null;
try
{
// first find out if we have a record
Object[] sparams = { new Integer(collection.getID()) };
TableRowIterator tri = DatabaseManager.query(context, collectionSelect, sparams);
tri = DatabaseManager.query(context, collectionSelect, sparams);
if (tri.hasNext())
{
@@ -112,14 +113,17 @@ public class ItemCountDAOPostgres implements ItemCountDAO
Object[] params = { new Integer(collection.getID()), new Integer(count) };
DatabaseManager.updateQuery(context, collectionInsert, params);
}
tri.close();
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
finally
{
if (tri != null)
tri.close();
}
}
/**
@@ -132,11 +136,12 @@ public class ItemCountDAOPostgres implements ItemCountDAO
public void communityCount(Community community, int count)
throws ItemCountException
{
TableRowIterator tri = null;
try
{
// first find out if we have a record
Object[] sparams = { new Integer(community.getID()) };
TableRowIterator tri = DatabaseManager.query(context, communitySelect, sparams);
tri = DatabaseManager.query(context, communitySelect, sparams);
if (tri.hasNext())
{
@@ -148,14 +153,17 @@ public class ItemCountDAOPostgres implements ItemCountDAO
Object[] params = { new Integer(community.getID()), new Integer(count) };
DatabaseManager.updateQuery(context, communityInsert, params);
}
tri.close();
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
finally
{
if (tri != null)
tri.close();
}
}
/**
@@ -268,10 +276,11 @@ public class ItemCountDAOPostgres implements ItemCountDAO
private int getCollectionCount(Collection collection)
throws ItemCountException
{
TableRowIterator tri = null;
try
{
Object[] params = { new Integer(collection.getID()) };
TableRowIterator tri = DatabaseManager.query(context, collectionSelect, params);
tri = DatabaseManager.query(context, collectionSelect, params);
if (!tri.hasNext())
{
@@ -285,8 +294,6 @@ public class ItemCountDAOPostgres implements ItemCountDAO
throw new ItemCountException("More than one count row in the database");
}
tri.close();
return tr.getIntColumn("count");
}
catch (SQLException e)
@@ -294,6 +301,11 @@ public class ItemCountDAOPostgres implements ItemCountDAO
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
finally
{
if (tri != null)
tri.close();
}
}
/**
@@ -306,10 +318,11 @@ public class ItemCountDAOPostgres implements ItemCountDAO
private int getCommunityCount(Community community)
throws ItemCountException
{
TableRowIterator tri = null;
try
{
Object[] params = { new Integer(community.getID()) };
TableRowIterator tri = DatabaseManager.query(context, communitySelect, params);
tri = DatabaseManager.query(context, communitySelect, params);
if (!tri.hasNext())
{
@@ -323,8 +336,6 @@ public class ItemCountDAOPostgres implements ItemCountDAO
throw new ItemCountException("More than one count row in the database");
}
tri.close();
return tr.getIntColumn("count");
}
catch (SQLException e)
@@ -332,5 +343,10 @@ public class ItemCountDAOPostgres implements ItemCountDAO
log.error("caught exception: ", e);
throw new ItemCountException(e);
}
finally
{
if (tri != null)
tri.close();
}
}
}

View File

@@ -98,7 +98,9 @@ public class HandleDispatcher implements BitstreamDispatcher
* @throws SQLException
* if database access fails.
*/
private void init()
private synchronized void init()
{
if (init == Boolean.FALSE)
{
Context context = null;
int dsoType = -1;
@@ -152,6 +154,7 @@ public class HandleDispatcher implements BitstreamDispatcher
delegate = new ListDispatcher(ids);
init = Boolean.TRUE;
}
}
/**
* Initializes this dispatcher on first execution.
@@ -159,14 +162,11 @@ public class HandleDispatcher implements BitstreamDispatcher
* @see org.dspace.checker.BitstreamDispatcher#next()
*/
public int next()
{
synchronized (init)
{
if (init == Boolean.FALSE)
{
init();
}
}
return delegate.next();
}

View File

@@ -581,7 +581,8 @@ public class Bitstream extends DSpaceObject
// Build a list of Bundle objects
List<Bundle> bundles = new ArrayList<Bundle>();
try
{
while (tri.hasNext())
{
TableRow r = tri.next();
@@ -599,9 +600,13 @@ public class Bitstream extends DSpaceObject
bundles.add(new Bundle(bContext, r));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Bundle[] bundleArray = new Bundle[bundles.size()];
bundleArray = (Bundle[]) bundles.toArray(bundleArray);

View File

@@ -114,12 +114,19 @@ public class BitstreamFormat
"SELECT * FROM fileextension WHERE bitstream_format_id= ? ",
getID());
try
{
while (tri.hasNext())
{
extensions.add(tri.next().getStringColumn("extension"));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Cache ourselves
context.cache(this, row.getIntColumn("bitstream_format_id"));
@@ -298,6 +305,8 @@ public class BitstreamFormat
TableRowIterator tri = DatabaseManager.queryTable(context, "bitstreamformatregistry",
"SELECT * FROM bitstreamformatregistry ORDER BY bitstream_format_id");
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -316,8 +325,13 @@ public class BitstreamFormat
formats.add(new BitstreamFormat(context, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Return the formats as an array
BitstreamFormat[] formatArray = new BitstreamFormat[formats.size()];
@@ -349,6 +363,8 @@ public class BitstreamFormat
TableRowIterator tri = DatabaseManager.queryTable(context,
"bitstreamformatregistry", myQuery);
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -367,8 +383,13 @@ public class BitstreamFormat
formats.add(new BitstreamFormat(context, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Return the formats as an array
BitstreamFormat[] formatArray = new BitstreamFormat[formats.size()];

View File

@@ -111,6 +111,8 @@ public class Bundle extends DSpaceObject
+ "bundle2bitstream.bundle_id= ? ",
bundleRow.getIntColumn("bundle_id"));
try
{
while (tri.hasNext())
{
TableRow r = (TableRow) tri.next();
@@ -128,8 +130,13 @@ public class Bundle extends DSpaceObject
bitstreams.add(new Bitstream(ourContext, r));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Cache ourselves
context.cache(this, row.getIntColumn("bundle_id"));
@@ -332,6 +339,8 @@ public class Bundle extends DSpaceObject
"item2bundle.bundle_id= ? ",
bundleRow.getIntColumn("bundle_id"));
try
{
while (tri.hasNext())
{
TableRow r = (TableRow) tri.next();
@@ -349,8 +358,13 @@ public class Bundle extends DSpaceObject
items.add(new Item(ourContext, r));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Item[] itemArray = new Item[items.size()];
itemArray = (Item[]) items.toArray(itemArray);
@@ -503,14 +517,21 @@ public class Bundle extends DSpaceObject
"SELECT * FROM bundle2bitstream WHERE bitstream_id= ? ",
b.getID());
try
{
if (!tri.hasNext())
{
// The bitstream is an orphan, delete it
b.delete();
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
/**
* Update the bundle metadata

View File

@@ -289,6 +289,8 @@ public class Collection extends DSpaceObject
List<Collection> collections = new ArrayList<Collection>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -306,8 +308,13 @@ public class Collection extends DSpaceObject
collections.add(new Collection(context, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Collection[] collectionArray = new Collection[collections.size()];
collectionArray = (Collection[]) collections.toArray(collectionArray);
@@ -924,6 +931,8 @@ public class Collection extends DSpaceObject
"SELECT * FROM collection2item WHERE item_id= ? ",
item.getID());
try
{
if (!tri.hasNext())
{
//make the right to remove the item explicit because the implicit
@@ -940,9 +949,14 @@ public class Collection extends DSpaceObject
// Orphan; delete it
item.delete();
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
/**
* Update the collection metadata (including logo, and workflow groups) to
@@ -1181,6 +1195,8 @@ public class Collection extends DSpaceObject
// Build a list of Community objects
List<Community> communities = new ArrayList<Community>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -1204,8 +1220,13 @@ public class Collection extends DSpaceObject
communities.add(parents[i]);
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Community[] communityArray = new Community[communities.size()];
communityArray = (Community[]) communities.toArray(communityArray);
@@ -1315,21 +1336,40 @@ public class Collection extends DSpaceObject
*/
public int countItems()
throws SQLException
{
int itemcount = 0;
PreparedStatement statement = null;
ResultSet rs = null;
try
{
String query = "SELECT count(*) FROM collection2item, item WHERE "
+ "collection2item.collection_id = ? "
+ "AND collection2item.item_id = item.item_id "
+ "AND in_archive ='1' AND item.withdrawn='0' ";
PreparedStatement statement = ourContext.getDBConnection().prepareStatement(query);
statement = ourContext.getDBConnection().prepareStatement(query);
statement.setInt(1,getID());
ResultSet rs = statement.executeQuery();
rs = statement.executeQuery();
if (rs != null)
{
rs.next();
int itemcount = rs.getInt(1);
itemcount = rs.getInt(1);
}
}
finally
{
if (rs != null)
{
try { rs.close(); } catch (SQLException sqle) { }
}
statement.close();
if (statement != null)
{
try { statement.close(); } catch (SQLException sqle) { }
}
}
return itemcount;
}

View File

@@ -237,6 +237,8 @@ public class Community extends DSpaceObject
List<Community> communities = new ArrayList<Community>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -254,8 +256,13 @@ public class Community extends DSpaceObject
communities.add(new Community(context, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Community[] communityArray = new Community[communities.size()];
communityArray = (Community[]) communities.toArray(communityArray);
@@ -283,6 +290,8 @@ public class Community extends DSpaceObject
List<Community> topCommunities = new ArrayList<Community>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -300,8 +309,13 @@ public class Community extends DSpaceObject
topCommunities.add(new Community(context, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Community[] communityArray = new Community[topCommunities.size()];
communityArray = (Community[]) topCommunities.toArray(communityArray);
@@ -514,6 +528,8 @@ public class Community extends DSpaceObject
getID());
// Make Collection objects
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -531,8 +547,13 @@ public class Community extends DSpaceObject
collections.add(new Collection(ourContext, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Put them in an array
Collection[] collectionArray = new Collection[collections.size()];
@@ -562,6 +583,8 @@ public class Community extends DSpaceObject
// Make Community objects
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -579,8 +602,13 @@ public class Community extends DSpaceObject
subcommunities.add(new Community(ourContext, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Put them in an array
Community[] communityArray = new Community[subcommunities.size()];
@@ -608,6 +636,8 @@ public class Community extends DSpaceObject
getID());
// Make Community object
try
{
if (tri.hasNext())
{
TableRow row = tri.next();
@@ -625,8 +655,13 @@ public class Community extends DSpaceObject
parentCommunity = new Community(ourContext, row);
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
return parentCommunity;
}
@@ -694,6 +729,8 @@ public class Community extends DSpaceObject
"SELECT * FROM community2collection WHERE " +
"community_id= ? AND collection_id= ? ",getID(),c.getID());
try
{
if (!tri.hasNext())
{
// No existing mapping, so add one
@@ -707,9 +744,14 @@ public class Community extends DSpaceObject
DatabaseManager.update(ourContext, mappingRow);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
/**
* Create a new sub-community within this community.
@@ -749,6 +791,8 @@ public class Community extends DSpaceObject
"SELECT * FROM community2community WHERE parent_comm_id= ? "+
"AND child_comm_id= ? ",getID(), c.getID());
try
{
if (!tri.hasNext())
{
// No existing mapping, so add one
@@ -762,9 +806,14 @@ public class Community extends DSpaceObject
DatabaseManager.update(ourContext, mappingRow);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
/**
* Remove a collection. Any items then orphaned are deleted.
@@ -793,6 +842,8 @@ public class Community extends DSpaceObject
"SELECT * FROM community2collection WHERE collection_id= ? ",
c.getID());
try
{
if (!tri.hasNext())
{
//make the right to remove the collection explicit because the
@@ -810,9 +861,14 @@ public class Community extends DSpaceObject
// Orphan; delete it
c.delete();
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
/**
* Remove a subcommunity. Any substructure then orphaned is deleted.
@@ -841,6 +897,8 @@ public class Community extends DSpaceObject
"SELECT * FROM community2community WHERE child_comm_id= ? ",
c.getID());
try
{
if (!tri.hasNext())
{
//make the right to remove the sub explicit because the implicit
@@ -858,9 +916,14 @@ public class Community extends DSpaceObject
// Orphan; delete it
c.delete();
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
/**
* Delete the community, including the metadata and logo. Collections and

View File

@@ -105,6 +105,8 @@ public class FormatIdentifier
extension);
BitstreamFormat retFormat = null;
try
{
if (tri.hasNext())
{
// Return first match
@@ -114,8 +116,13 @@ public class FormatIdentifier
{
retFormat = null;
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
return retFormat;
}
}

View File

@@ -143,6 +143,8 @@ public class Item extends DSpaceObject
// Get Dublin Core metadata
TableRowIterator tri = retrieveMetadata();
try
{
while (tri.hasNext())
{
TableRow resultRow = tri.next();
@@ -174,8 +176,13 @@ public class Item extends DSpaceObject
dublinCore.add(dcv);
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Get our Handle if any
handle = HandleManager.findHandle(context, this);
@@ -918,6 +925,8 @@ public class Item extends DSpaceObject
"collection2item.item_id= ? ",
itemRow.getIntColumn("item_id"));
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -935,8 +944,13 @@ public class Item extends DSpaceObject
collections.add(new Collection(ourContext, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Collection[] collectionArray = new Collection[collections.size()];
collectionArray = (Collection[]) collections.toArray(collectionArray);
@@ -963,6 +977,8 @@ public class Item extends DSpaceObject
"AND community2item.item_id= ? ",
itemRow.getIntColumn("item_id"));
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -986,8 +1002,13 @@ public class Item extends DSpaceObject
communities.add(parents[i]);
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Community[] communityArray = new Community[communities.size()];
communityArray = (Community[]) communities.toArray(communityArray);
@@ -1012,6 +1033,8 @@ public class Item extends DSpaceObject
"item2bundle.item_id= ? ",
itemRow.getIntColumn("item_id"));
try
{
while (tri.hasNext())
{
TableRow r = tri.next();
@@ -1029,9 +1052,14 @@ public class Item extends DSpaceObject
bundles.add(new Bundle(ourContext, r));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
Bundle[] bundleArray = new Bundle[bundles.size()];
bundleArray = (Bundle[]) bundles.toArray(bundleArray);
@@ -1184,6 +1212,8 @@ public class Item extends DSpaceObject
"SELECT * FROM item2bundle WHERE bundle_id= ? ",
b.getID());
try
{
if (!tri.hasNext())
{
//make the right to remove the bundle explicit because the implicit
@@ -1201,9 +1231,14 @@ public class Item extends DSpaceObject
// The bundle is an orphan, delete it
b.delete();
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
/**
* Create a single bitstream in a new bundle. Provided as a convenience

View File

@@ -320,15 +320,20 @@ public class MetadataField
schemaID, element, qualifier);
}
TableRow row = null;
try
{
if (tri.hasNext())
{
row = tri.next();
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
if (row == null)
{
@@ -355,13 +360,20 @@ public class MetadataField
TableRowIterator tri = DatabaseManager.queryTable(context, "MetadataFieldRegistry",
"SELECT mfr.* FROM MetadataFieldRegistry mfr, MetadataSchemaRegistry msr where mfr.metadata_schema_id= msr.metadata_schema_id ORDER BY msr.short_id, mfr.element, mfr.qualifier");
try
{
// Make into DC Type objects
while (tri.hasNext())
{
fields.add(new MetadataField(tri.next()));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Convert list into an array
MetadataField[] typeArray = new MetadataField[fields.size()];
@@ -386,13 +398,20 @@ public class MetadataField
"SELECT * FROM MetadataFieldRegistry WHERE metadata_schema_id= ? " +
" ORDER BY element, qualifier", schemaID);
try
{
// Make into DC Type objects
while (tri.hasNext())
{
fields.add(new MetadataField(tri.next()));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Convert list into an array
MetadataField[] typeArray = new MetadataField[fields.size()];
@@ -509,7 +528,14 @@ public class MetadataField
String qualifier) throws IOException, SQLException,
AuthorizeException
{
Connection con = context.getDBConnection();
int count = 0;
Connection con = null;
PreparedStatement statement = null;
ResultSet rs = null;
try
{
con = context.getDBConnection();
TableRow reg = DatabaseManager.row("MetadataFieldRegistry");
String qualifierClause = "";
@@ -528,7 +554,7 @@ public class MetadataField
+ " and metadata_field_id != ? "
+ " and element= ? " + qualifierClause;
PreparedStatement statement = con.prepareStatement(query);
statement = con.prepareStatement(query);
statement.setInt(1,schemaID);
statement.setInt(2,fieldID);
statement.setString(3,element);
@@ -538,13 +564,25 @@ public class MetadataField
statement.setString(4,qualifier);
}
ResultSet rs = statement.executeQuery();
rs = statement.executeQuery();
int count = 0;
if (rs.next())
{
count = rs.getInt(1);
}
}
finally
{
if (rs != null)
{
try { rs.close(); } catch (SQLException sqle) { }
}
if (statement != null)
{
try { statement.close(); } catch (SQLException sqle) { }
}
}
return (count == 0);
}
@@ -604,21 +642,36 @@ public class MetadataField
{
if (id2field != null)
return;
id2field = new HashMap();
synchronized (MetadataField.class)
{
if (id2field == null)
{
HashMap new_id2field = new HashMap();
log.info("Loading MetadataField elements into cache.");
// Grab rows from DB
TableRowIterator tri = DatabaseManager.queryTable(context,"MetadataFieldRegistry",
"SELECT * from MetadataFieldRegistry");
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
int fieldID = row.getIntColumn("metadata_field_id");
id2field.put(new Integer(fieldID), new MetadataField(row));
new_id2field.put(new Integer(fieldID), new MetadataField(row));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
id2field = new_id2field;
}
}
}
}

View File

@@ -262,13 +262,19 @@ public class MetadataSchema
namespace);
TableRow row = null;
try
{
if (tri.hasNext())
{
row = tri.next();
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
if (row == null)
{
@@ -360,13 +366,20 @@ public class MetadataSchema
TableRowIterator tri = DatabaseManager.queryTable(context, "MetadataSchemaRegistry",
"SELECT * FROM MetadataSchemaRegistry ORDER BY metadata_schema_id");
try
{
// Make into DC Type objects
while (tri.hasNext())
{
schemas.add(new MetadataSchema(tri.next()));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Convert list into an array
MetadataSchema[] typeArray = new MetadataSchema[schemas.size()];
@@ -385,23 +398,42 @@ public class MetadataSchema
private boolean uniqueNamespace(Context context, String namespace)
throws SQLException
{
int count = 0;
Connection con = context.getDBConnection();
PreparedStatement statement = null;
ResultSet rs = null;
try
{
TableRow reg = DatabaseManager.row("MetadataSchemaRegistry");
String query = "SELECT COUNT(*) FROM " + reg.getTable() + " " +
"WHERE metadata_schema_id != ? " +
"AND namespace= ? ";
PreparedStatement statement = con.prepareStatement(query);
statement = con.prepareStatement(query);
statement.setInt(1,schemaID);
statement.setString(2,namespace);
ResultSet rs = statement.executeQuery();
rs = statement.executeQuery();
int count = 0;
if (rs.next())
{
count = rs.getInt(1);
}
}
finally
{
if (rs != null)
{
try { rs.close(); } catch (SQLException sqle) { }
}
if (statement != null)
{
try { statement.close(); } catch (SQLException sqle) { }
}
}
return (count == 0);
}
@@ -417,24 +449,42 @@ public class MetadataSchema
private boolean uniqueShortName(Context context, String name)
throws SQLException
{
int count = 0;
Connection con = context.getDBConnection();
PreparedStatement statement = null;
ResultSet rs = null;
try
{
TableRow reg = DatabaseManager.row("MetadataSchemaRegistry");
String query = "SELECT COUNT(*) FROM " + reg.getTable() + " " +
"WHERE metadata_schema_id != ? " +
"AND short_id = ? ";
PreparedStatement statement = con.prepareStatement(query);
statement = con.prepareStatement(query);
statement.setInt(1,schemaID);
statement.setString(2,name);
ResultSet rs = statement.executeQuery();
rs = statement.executeQuery();
int count = 0;
if (rs.next())
{
count = rs.getInt(1);
}
}
finally
{
if (rs != null)
{
try { rs.close(); } catch (SQLException sqle) { }
}
if (statement != null)
{
try { statement.close(); } catch (SQLException sqle) { }
}
}
return (count == 0);
}
@@ -501,21 +551,38 @@ public class MetadataSchema
if (id2schema != null && name2schema != null)
return;
synchronized (MetadataSchema.class)
{
if (id2schema == null && name2schema == null)
{
log.info("Loading schema cache for fast finds");
id2schema = new HashMap();
name2schema = new HashMap();
HashMap new_id2schema = new HashMap();
HashMap new_name2schema = new HashMap();
TableRowIterator tri = DatabaseManager.queryTable(context,"MetadataSchemaRegistry",
"SELECT * from MetadataSchemaRegistry");
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
MetadataSchema s = new MetadataSchema(row);
id2schema.put(new Integer(s.schemaID), s);
name2schema.put(s.name, s);
new_id2schema.put(new Integer(s.schemaID), s);
new_name2schema.put(s.name, s);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
id2schema = new_id2schema;
name2schema = new_name2schema;
}
}
}
}

View File

@@ -278,13 +278,19 @@ public class MetadataValue
valueId);
TableRow row = null;
try
{
if (tri.hasNext())
{
row = tri.next();
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
if (row == null)
{
@@ -316,14 +322,20 @@ public class MetadataValue
TableRow row = null;
java.util.Collection ret = new ArrayList();
try
{
while (tri.hasNext())
{
row = tri.next();
ret.add(new MetadataValue(row));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
return ret;
}

View File

@@ -122,6 +122,8 @@ public class SupervisedItem extends WorkspaceItem
"workspaceitem",
query);
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -129,8 +131,13 @@ public class SupervisedItem extends WorkspaceItem
sItems.add(si);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
SupervisedItem[] siArray = new SupervisedItem[sItems.size()];
siArray = (SupervisedItem[]) sItems.toArray(siArray);
@@ -160,6 +167,8 @@ public class SupervisedItem extends WorkspaceItem
TableRowIterator tri = DatabaseManager.queryTable(c,"epersongroup",query, wi);
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -167,8 +176,13 @@ public class SupervisedItem extends WorkspaceItem
groupList.add(group);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Group[] groupArray = new Group[groupList.size()];
groupArray = (Group[]) groupList.toArray(groupArray);
@@ -202,6 +216,8 @@ public class SupervisedItem extends WorkspaceItem
"epersongroup",
query, this.getID());
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -210,8 +226,13 @@ public class SupervisedItem extends WorkspaceItem
groupList.add(group);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Group[] groupArray = new Group[groupList.size()];
groupArray = (Group[]) groupList.toArray(groupArray);
@@ -245,14 +266,21 @@ public class SupervisedItem extends WorkspaceItem
"workspaceitem",
query,ep.getID());
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
SupervisedItem si = new SupervisedItem(context, row);
sItems.add(si);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
SupervisedItem[] siArray = new SupervisedItem[sItems.size()];
siArray = (SupervisedItem[]) sItems.toArray(siArray);

View File

@@ -312,6 +312,8 @@ public class WorkspaceItem implements InProgressSubmission
"ORDER BY workspaceitem.workspace_item_id",
ep.getID());
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -327,8 +329,13 @@ public class WorkspaceItem implements InProgressSubmission
wsItems.add(wi);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
WorkspaceItem[] wsArray = new WorkspaceItem[wsItems.size()];
wsArray = (WorkspaceItem[]) wsItems.toArray(wsArray);
@@ -356,6 +363,8 @@ public class WorkspaceItem implements InProgressSubmission
"workspaceitem.collection_id= ? ",
c.getID());
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -372,8 +381,13 @@ public class WorkspaceItem implements InProgressSubmission
wsItems.add(wi);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
WorkspaceItem[] wsArray = new WorkspaceItem[wsItems.size()];
wsArray = (WorkspaceItem[]) wsItems.toArray(wsArray);
@@ -397,6 +411,8 @@ public class WorkspaceItem implements InProgressSubmission
"workspaceitem",
query);
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -413,8 +429,13 @@ public class WorkspaceItem implements InProgressSubmission
wsItems.add(wi);
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
WorkspaceItem[] wsArray = new WorkspaceItem[wsItems.size()];
wsArray = (WorkspaceItem[]) wsItems.toArray(wsArray);

View File

@@ -260,9 +260,11 @@ public class MODSDisseminationCrosswalk extends SelfNamedPlugin
File.separator + "config" + File.separator;
File propsFile = new File(parent, propsFilename);
Properties modsConfig = new Properties();
FileInputStream pfs = null;
try
{
modsConfig.load(new FileInputStream(propsFile));
pfs = new FileInputStream(propsFile);
modsConfig.load(pfs);
}
catch (IOException e)
{
@@ -270,6 +272,12 @@ public class MODSDisseminationCrosswalk extends SelfNamedPlugin
throw new CrosswalkInternalException("MODS crosswalk cannot "+
"open config file: "+e.toString());
}
finally
{
if (pfs != null)
try { pfs.close(); } catch (IOException ioe) { }
}
modsMap = new HashMap();
Enumeration pe = modsConfig.propertyNames();
while (pe.hasMoreElements())

View File

@@ -280,7 +280,17 @@ public class QDCCrosswalk extends SelfNamedPlugin
File.separator + "config" + File.separator;
File propsFile = new File(parent, propsFilename);
Properties qdcProps = new Properties();
qdcProps.load(new FileInputStream(propsFile));
FileInputStream pfs = null;
try
{
pfs = new FileInputStream(propsFile);
qdcProps.load(pfs);
}
finally
{
if (pfs != null)
try { pfs.close(); } catch (IOException ioe) { }
}
// grovel properties to initialize qdc->element and element->qdc maps.
// evaluate the XML fragment with a wrapper including namespaces.

View File

@@ -120,7 +120,16 @@ public class XHTMLHeadDisseminationCrosswalk extends SelfNamedPlugin implements
// Read in configuration
Properties crosswalkProps = new Properties();
crosswalkProps.load(new FileInputStream(config));
FileInputStream fis = new FileInputStream(config);
try
{
crosswalkProps.load(fis);
}
finally
{
if (fis != null)
try { fis.close(); } catch (IOException ioe) { }
}
Enumeration e = crosswalkProps.keys();
while (e.hasMoreElements())

View File

@@ -177,9 +177,12 @@ public class ConfigurationManager
{
// Load in default license
FileReader fr = null;
BufferedReader br = null;
try
{
BufferedReader br = new BufferedReader(new FileReader(licenseFile));
fr = new FileReader(licenseFile);
br = new BufferedReader(fr);
String lineIn;
license = "";
while ((lineIn = br.readLine()) != null)
@@ -195,6 +198,15 @@ public class ConfigurationManager
// configuration we can't do anything
System.exit(1);
}
finally
{
if (br != null)
try { br.close(); } catch (IOException ioe) { }
if (fr != null)
try { fr.close(); } catch (IOException ioe) { }
}
return license;
}
@@ -480,6 +492,7 @@ public class ConfigurationManager
protected static File getConfigurationFile()
{
// in case it hasn't been done yet.
if (loadedFile == null)
loadConfig(null);
return loadedFile;
@@ -494,7 +507,7 @@ public class ConfigurationManager
* The <code>dspace.cfg</code> configuration file to use, or
* <code>null</code> to try default locations
*/
public static void loadConfig(String configFile)
public static synchronized void loadConfig(String configFile)
{
if (properties != null)
@@ -505,6 +518,7 @@ public class ConfigurationManager
URL url = null;
InputStream is = null;
try
{
String configProperty = null;
@@ -556,7 +570,8 @@ public class ConfigurationManager
else
{
properties = new Properties();
properties.load(url.openStream());
is = url.openStream();
properties.load(is);
// walk values, interpolating any embedded references.
for (Enumeration pe = properties.propertyNames(); pe.hasMoreElements(); )
@@ -577,16 +592,25 @@ public class ConfigurationManager
// configuration we can't do anything
throw new RuntimeException("Cannot load configuration: " + url, e);
}
finally
{
if (is != null)
try { is.close(); } catch (IOException ioe) { }
}
// Load in default license
File licenseFile = new File(getProperty("dspace.dir") + File.separator
+ "config" + File.separator + "default.license");
FileInputStream fir = null;
InputStreamReader ir = null;
BufferedReader br = null;
try
{
FileInputStream fir = new FileInputStream(licenseFile);
InputStreamReader ir = new InputStreamReader(fir, "UTF-8");
BufferedReader br = new BufferedReader(ir);
fir = new FileInputStream(licenseFile);
ir = new InputStreamReader(fir, "UTF-8");
br = new BufferedReader(ir);
String lineIn;
license = "";
@@ -606,6 +630,17 @@ public class ConfigurationManager
// configuration we can't do anything
throw new RuntimeException("Cannot load license: " + licenseFile.toString(),e);
}
finally
{
if (br != null)
try { br.close(); } catch (IOException ioe) { }
if (ir != null)
try { ir.close(); } catch (IOException ioe) { }
if (fir != null)
try { fir.close(); } catch (IOException ioe) { }
}

View File

@@ -84,9 +84,8 @@ public class LogManager
contextExtraInfo = "no_context";
}
String result = new String(email + ":" + contextExtraInfo + ":"
+ action + ":" + extrainfo);
return result;
StringBuilder result = new StringBuilder();
result.append(email).append(":").append(contextExtraInfo).append(":").append(action).append(":").append(extrainfo);
return result.toString();
}
}

View File

@@ -564,6 +564,9 @@ public class PluginManager
public static void checkConfiguration()
throws IOException
{
FileReader fr = null;
BufferedReader cr = null;
/* XXX TODO: (maybe) test that implementation class is really a
* subclass or impl of the plugin "interface"
*/
@@ -574,15 +577,18 @@ public class PluginManager
Map namedKey = new HashMap();
Map selfnamedKey = new HashMap();
Map reusableKey = new HashMap();
HashMap keyMap = new HashMap();
// 1. First pass -- grovel the actual config file to check for
// duplicate keys, since Properties class hides them from us.
// Also build lists of each type of key, check for misspellings.
File config = ConfigurationManager.getConfigurationFile();
BufferedReader cr = new BufferedReader(new FileReader(config));
try
{
fr = new FileReader(config);
cr = new BufferedReader(fr);
String line = null;
boolean continued = false;
HashMap keyMap = new HashMap();
Pattern keyPattern = Pattern.compile("([^\\s\\=\\:]+)");
while ((line = cr.readLine()) != null)
{
@@ -619,6 +625,15 @@ public class PluginManager
continued = line.length() > 0 && line.charAt(line.length()-1) == '\\';
}
}
}
finally
{
if (cr != null)
try { cr.close(); } catch (IOException ioe) { }
if (fr != null)
try { fr.close(); } catch (IOException ioe) { }
}
// 1.1 Sanity check, make sure keyMap == set of keys from Configuration
Enumeration pne = ConfigurationManager.propertyNames();

View File

@@ -908,36 +908,57 @@ public class EPerson extends DSpaceObject
"SELECT * from item where submitter_id= ? ",
getID());
try
{
if (tri.hasNext())
{
tableList.add("item");
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// check for eperson in workflowitem table
tri = DatabaseManager.query(myContext,
"SELECT * from workflowitem where owner= ? ",
getID());
try
{
if (tri.hasNext())
{
tableList.add("workflowitem");
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// check for eperson in tasklistitem table
tri = DatabaseManager.query(myContext,
"SELECT * from tasklistitem where eperson_id= ? ",
getID());
try
{
if (tri.hasNext())
{
tableList.add("tasklistitem");
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// the list of tables can be used to construct an error message
// explaining to the user why the eperson cannot be deleted.

View File

@@ -141,6 +141,8 @@ public class Group extends DSpaceObject
"epersongroup2eperson.eperson_group_id= ?",
myRow.getIntColumn("eperson_group_id"));
try
{
while (tri.hasNext())
{
TableRow r = (TableRow) tri.next();
@@ -158,8 +160,13 @@ public class Group extends DSpaceObject
epeople.add(new EPerson(myContext, r));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// now get Group objects
tri = DatabaseManager.queryTable(myContext,"epersongroup",
@@ -168,6 +175,8 @@ public class Group extends DSpaceObject
"group2group.parent_id= ? ",
myRow.getIntColumn("eperson_group_id"));
try
{
while (tri.hasNext())
{
TableRow r = (TableRow) tri.next();
@@ -185,8 +194,13 @@ public class Group extends DSpaceObject
groups.add(new Group(myContext, r));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
}
catch (Exception e)
@@ -449,6 +463,8 @@ public class Group extends DSpaceObject
Set<Integer> groupIDs = new HashSet<Integer>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -457,8 +473,13 @@ public class Group extends DSpaceObject
groupIDs.add(new Integer(childID));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Also need to get all "Special Groups" user is a member of!
// Otherwise, you're ignoring the user's membership to these groups!
@@ -501,6 +522,8 @@ public class Group extends DSpaceObject
"SELECT * FROM group2groupcache WHERE " + groupQuery,
parameters);
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -509,8 +532,13 @@ public class Group extends DSpaceObject
groupIDs.add(new Integer(parentID));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
return groupIDs;
}
@@ -570,6 +598,8 @@ public class Group extends DSpaceObject
Set<Integer> groupIDs = new HashSet<Integer>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -578,8 +608,13 @@ public class Group extends DSpaceObject
groupIDs.add(new Integer(childID));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// now we have all the groups (including this one)
// it is time to find all the EPeople who belong to those groups
@@ -612,6 +647,8 @@ public class Group extends DSpaceObject
"SELECT * FROM epersongroup2eperson WHERE " + epersonQuery,
parameters);
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -620,8 +657,13 @@ public class Group extends DSpaceObject
epeopleIDs.add(new Integer(epersonID));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
return epeopleIDs;
}
@@ -1135,6 +1177,8 @@ public class Group extends DSpaceObject
Map<Integer,Set<Integer>> parents = new HashMap<Integer,Set<Integer>>();
try
{
while (tri.hasNext())
{
TableRow row = (TableRow) tri.next();
@@ -1159,8 +1203,13 @@ public class Group extends DSpaceObject
children.add(childID);
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// now parents is a hash of all of the IDs of groups that are parents
// and each hash entry is a hash of all of the IDs of children of those

View File

@@ -112,6 +112,8 @@ public class Subscribe
" AND collection_id= ? ",
eperson.getID(),collection.getID());
try
{
if (!r.hasNext())
{
// Not subscribed, so add them
@@ -124,9 +126,14 @@ public class Subscribe
"eperson_id=" + eperson.getID() + ",collection_id="
+ collection.getID()));
}
}
finally
{
// close the TableRowIterator to free up resources
if (r != null)
r.close();
}
}
else
{
throw new AuthorizeException(
@@ -198,6 +205,8 @@ public class Subscribe
List collections = new ArrayList();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -205,8 +214,13 @@ public class Subscribe
collections.add(Collection.find(context, row
.getIntColumn("collection_id")));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Collection[] collArray = new Collection[collections.size()];
@@ -232,10 +246,16 @@ public class Subscribe
"AND collection_id= ? ",
eperson.getID(),collection.getID());
boolean result = tri.hasNext();
try
{
return tri.hasNext();
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
return result;
}
}
/**
@@ -265,6 +285,8 @@ public class Subscribe
EPerson currentEPerson = null;
List collections = null; // List of Collections
try
{
// Go through the list collating subscriptions for each e-person
while (tri.hasNext())
{
@@ -299,8 +321,13 @@ public class Subscribe
collections.add(Collection.find(context, row
.getIntColumn("collection_id")));
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
// Process the last person
if (currentEPerson != null)

View File

@@ -109,9 +109,16 @@ public class Supervisor {
"epersongroup2workspaceitem",
query,groupID,wsItemID);
boolean result = tri.hasNext();
try
{
return tri.hasNext();
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
return result;
}
}
/**

View File

@@ -327,13 +327,20 @@ public class HandleManager
TableRowIterator iterator = DatabaseManager.queryTable(context, null, sql, prefix+"%");
List results = new ArrayList();
try
{
while (iterator.hasNext())
{
TableRow row = (TableRow) iterator.next();
results.add(row.getStringColumn("handle"));
}
}
finally
{
// close the TableRowIterator to free up resources
if (iterator != null)
iterator.close();
}
return results;
}

View File

@@ -228,6 +228,8 @@ public class Harvest
List infoObjects = new LinkedList();
int index = 0;
try
{
// Process results of query into HarvestedItemInfo objects
while (tri.hasNext())
{
@@ -264,7 +266,13 @@ public class Harvest
index++;
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
return infoObjects;
}

View File

@@ -107,7 +107,6 @@ public class OrderFormat
{
return delegate.makeSortString(value, language);
}
}
// No delegates found, so apply defaults
if (type.equalsIgnoreCase(OrderFormat.AUTHOR) && authorDelegate != null)
@@ -124,6 +123,7 @@ public class OrderFormat
{
return textDelegate.makeSortString(value, language);
}
}
return value;
}

View File

@@ -305,12 +305,17 @@ public class SortOption
if (SortOption.sortOptionsMap != null)
return SortOption.sortOptionsMap;
SortOption.sortOptionsMap = new HashMap<Integer, SortOption>();
synchronized (SortOption.sortOptionsMap)
synchronized (SortOption.class)
{
if (SortOption.sortOptionsMap == null)
{
Map<Integer, SortOption> newSortOptionsMap = new HashMap<Integer, SortOption>();
for (SortOption so : SortOption.getSortOptions())
{
SortOption.sortOptionsMap.put(new Integer(so.getNumber()), so);
newSortOptionsMap.put(new Integer(so.getNumber()), so);
}
SortOption.sortOptionsMap = newSortOptionsMap;
}
}
@@ -327,18 +332,23 @@ public class SortOption
if (SortOption.sortOptionsSet != null)
return SortOption.sortOptionsSet;
SortOption.sortOptionsSet = new HashSet<SortOption>();
synchronized (SortOption.sortOptionsSet)
synchronized (SortOption.class)
{
if (SortOption.sortOptionsSet == null)
{
Set<SortOption> newSortOptionsSet = new HashSet<SortOption>();
int idx = 1;
String option;
while ( ((option = ConfigurationManager.getProperty("webui.itemlist.sort-option." + idx))) != null)
{
SortOption so = new SortOption(idx, option);
SortOption.sortOptionsSet.add(so);
newSortOptionsSet.add(so);
idx++;
}
SortOption.sortOptionsSet = newSortOptionsSet;
}
}
return SortOption.sortOptionsSet;

View File

@@ -352,9 +352,13 @@ public class BitstreamStorageManager
bitstream.setColumn("size_bytes", file.length());
if (dis != null)
{
bitstream.setColumn("checksum", Utils.toHex(dis.getMessageDigest()
.digest()));
bitstream.setColumn("checksum_algorithm", "MD5");
}
bitstream.setColumn("deleted", false);
DatabaseManager.update(context, bitstream);

View File

@@ -276,10 +276,19 @@ public class DatabaseManager
public static TableRow querySingle(Context context, String query,
Object... parameters) throws SQLException
{
TableRowIterator iterator = query(context, query, parameters);
TableRow retRow = (!iterator.hasNext()) ? null : iterator.next();
TableRow retRow = null;
TableRowIterator iterator = null;
try
{
iterator = query(context, query, parameters);
retRow = (!iterator.hasNext()) ? null : iterator.next();
}
finally
{
if (iterator != null)
iterator.close();
}
return (retRow);
}
@@ -304,10 +313,18 @@ public class DatabaseManager
public static TableRow querySingleTable(Context context, String table,
String query, Object... parameters) throws SQLException
{
TableRow retRow = null;
TableRowIterator iterator = queryTable(context, canonicalize(table), query, parameters);
TableRow retRow = (!iterator.hasNext()) ? null : iterator.next();
try
{
retRow = (!iterator.hasNext()) ? null : iterator.next();
}
finally
{
if (iterator != null)
iterator.close();
}
return (retRow);
}
@@ -564,8 +581,13 @@ public class DatabaseManager
public static void insert(Context context, TableRow row)
throws SQLException
{
int newID = -1;
String table = canonicalize(row.getTable());
Statement statement = null;
ResultSet rs = null;
try
{
// Get an ID (primary key) for this row by using the "getnextid"
// SQL function in Postgres, or directly with sequences in Oracle
String myQuery = "SELECT getnextid('" + table + "') AS result";
@@ -575,15 +597,28 @@ public class DatabaseManager
myQuery = "SELECT " + table + "_seq" + ".nextval FROM dual";
}
Statement statement = context.getDBConnection().createStatement();
ResultSet rs = statement.executeQuery(myQuery);
statement = context.getDBConnection().createStatement();
rs = statement.executeQuery(myQuery);
rs.next();
int newID = rs.getInt(1);
rs.close();
newID = rs.getInt(1);
}
finally
{
if (rs != null)
{
try { rs.close(); } catch (SQLException sqle) { }
}
statement.close();
if (statement != null)
{
try { statement.close(); } catch (SQLException sqle) { }
}
}
if (newID < 0)
throw new SQLException("Unable to retrieve sequence ID");
// Set the ID in the table row object
row.setColumn(getPrimaryKeyColumn(table), newID);
@@ -1354,6 +1389,8 @@ public class DatabaseManager
private static Map retrieveColumnInfo(String table) throws SQLException
{
Connection connection = null;
ResultSet pkcolumns = null;
ResultSet columns = null;
try
{
@@ -1367,13 +1404,13 @@ public class DatabaseManager
String tname = (table.length() >= max) ? table
.substring(0, max - 1) : table;
ResultSet pkcolumns = metadata.getPrimaryKeys(null, schema, tname);
pkcolumns = metadata.getPrimaryKeys(null, schema, tname);
Set pks = new HashSet();
while (pkcolumns.next())
pks.add(pkcolumns.getString(4));
ResultSet columns = metadata.getColumns(null, schema, tname, null);
columns = metadata.getColumns(null, schema, tname, null);
while (columns.next())
{
@@ -1394,9 +1431,19 @@ public class DatabaseManager
}
finally
{
if (pkcolumns != null)
{
try { pkcolumns.close(); } catch (SQLException sqle) { }
}
if (columns != null)
{
try { columns.close(); } catch (SQLException sqle) { }
}
if (connection != null)
{
connection.close();
try { connection.close(); } catch (SQLException sqle) { }
}
}
}

View File

@@ -108,7 +108,7 @@ public class TableRowIterator
/**
* Finalize -- this method is called when this object is GC-ed.
*/
public void finalize()
protected void finalize()
{
close();
}

View File

@@ -171,6 +171,8 @@ public class WorkflowItem implements InProgressSubmission
TableRowIterator tri = DatabaseManager.queryTable(c, "workflowitem",
"SELECT * FROM workflowitem");
try
{
// make a list of workflow items
while (tri.hasNext())
{
@@ -178,8 +180,12 @@ public class WorkflowItem implements InProgressSubmission
WorkflowItem wi = new WorkflowItem(c, row);
wfItems.add(wi);
}
}
finally
{
if (tri != null)
tri.close();
}
WorkflowItem[] wfArray = new WorkflowItem[wfItems.size()];
wfArray = (WorkflowItem[]) wfItems.toArray(wfArray);
@@ -211,6 +217,8 @@ public class WorkflowItem implements InProgressSubmission
"ORDER BY workflowitem.workflow_id",
ep.getID());
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -226,8 +234,12 @@ public class WorkflowItem implements InProgressSubmission
wfItems.add(wi);
}
}
finally
{
if (tri != null)
tri.close();
}
WorkflowItem[] wfArray = new WorkflowItem[wfItems.size()];
wfArray = (WorkflowItem[]) wfItems.toArray(wfArray);
@@ -255,6 +267,8 @@ public class WorkflowItem implements InProgressSubmission
"workflowitem.collection_id= ? ",
c.getID());
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
@@ -271,8 +285,12 @@ public class WorkflowItem implements InProgressSubmission
wsItems.add(wi);
}
}
finally
{
if (tri != null)
tri.close();
}
WorkflowItem[] wsArray = new WorkflowItem[wsItems.size()];
wsArray = (WorkflowItem[]) wsItems.toArray(wsArray);

View File

@@ -237,12 +237,18 @@ public class WorkflowManager
TableRowIterator tri = DatabaseManager.queryTable(c,
"workflowitem", myquery,e.getID());
try
{
while (tri.hasNext())
{
mylist.add(new WorkflowItem(c, tri.next()));
}
}
finally
{
if (tri != null)
tri.close();
}
return mylist;
}
@@ -265,12 +271,18 @@ public class WorkflowManager
TableRowIterator tri = DatabaseManager
.queryTable(c, "workflowitem", myquery, e.getID());
try
{
while (tri.hasNext())
{
mylist.add(new WorkflowItem(c, tri.next()));
}
}
finally
{
if (tri != null)
tri.close();
}
return mylist;
}

View File

@@ -190,7 +190,7 @@ public class FeedServlet extends DSpaceServlet
//as long as this is not a site wide feed,
//attempt to retrieve the Collection or Community object
if(!handle.equals(SITE_FEED_KEY))
if(handle != null && !handle.equals(SITE_FEED_KEY))
{
// Determine if handle is a valid reference
dso = HandleManager.resolveToObject(context, handle);
@@ -371,7 +371,7 @@ public class FeedServlet extends DSpaceServlet
: HandleManager.getCanonicalForm(dso.getHandle());
// put in container-level data
channel.setDescription(description.replaceAll("\\p{Cntrl}", ""));
channel.setDescription(description == null ? "" : description.replaceAll("\\p{Cntrl}", ""));
channel.setLink(objectUrl);
//build channel title by passing in type and title
String channelTitle = MessageFormat.format(labels.getString(clazz + ".feed.title"),

View File

@@ -122,6 +122,7 @@ public class StatisticsServlet extends org.dspace.app.webui.servlet.DSpaceServle
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException, AuthorizeException
{
StringBuffer report = new StringBuffer();
String date = (String) request.getParameter("date");
request.setAttribute("date", date);
@@ -136,6 +137,8 @@ public class StatisticsServlet extends org.dspace.app.webui.servlet.DSpaceServle
InputStreamReader ir = null;
BufferedReader br = null;
try
{
List monthsList = new ArrayList();
Pattern monthly = Pattern.compile("report-([0-9][0-9][0-9][0-9]-[0-9]+)\\.html");
@@ -175,7 +178,7 @@ public class StatisticsServlet extends org.dspace.app.webui.servlet.DSpaceServle
reportFile = reports[i];
}
if (parsedDate.compareTo(mostRecentDate) > 0)
if (parsedDate != null && parsedDate.compareTo(mostRecentDate) > 0)
{
mostRecentDate = parsedDate;
reportFile = reports[i];
@@ -245,13 +248,23 @@ public class StatisticsServlet extends org.dspace.app.webui.servlet.DSpaceServle
}
// FIXME: there's got to be a better way of doing this
StringBuffer report = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null)
{
report.append(line);
}
}
finally
{
if (br != null)
try { br.close(); } catch (IOException ioe) { }
if (ir != null)
try { ir.close(); } catch (IOException ioe) { }
if (fir != null)
try { fir.close(); } catch (IOException ioe) { }
}
// set the report to be displayed
request.setAttribute("report", report.toString());

View File

@@ -93,7 +93,7 @@ public class SuggestServlet extends DSpaceServlet
if (item != null)
{
DCValue[] titleDC = item.getDC("title", null, Item.ANY);
if (titleDC != null || titleDC.length > 0)
if (titleDC != null && titleDC.length > 0)
{
title = titleDC[0].value;
}

View File

@@ -231,8 +231,21 @@ public class DIDLCrosswalk extends Crosswalk
byte[] buffer = new byte[intSize];
Context contextl= new Context();
BufferedInputStream bis=new BufferedInputStream(BitstreamStorageManager.retrieve(contextl,bitstreams[k].getID()));
InputStream is = BitstreamStorageManager.retrieve(contextl,bitstreams[k].getID());
BufferedInputStream bis = new BufferedInputStream(is);
try
{
int size=bis.read(buffer);
}
finally
{
if (bis != null)
try { bis.close(); } catch (IOException ioe) { }
if (is != null)
try { is.close(); } catch (IOException ioe) { }
}
contextl.complete();
String encoding = new String(Base64.encodeBase64(buffer), "ASCII");