[DS-445] New Bitstream.findAll() method

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@4657 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Stuart Lewis
2010-01-06 21:12:51 +00:00
parent 16acce7421
commit de65b78ca6

View File

@@ -170,6 +170,46 @@ public class Bitstream extends DSpaceObject
return new Bitstream(context, row);
}
public static Bitstream[] findAll(Context context) throws SQLException
{
TableRowIterator tri = DatabaseManager.queryTable(context, "bitstream",
"SELECT * FROM bitstream");
List<Bitstream> bitstreams = new ArrayList<Bitstream>();
try
{
while (tri.hasNext())
{
TableRow row = tri.next();
// First check the cache
Bitstream fromCache = (Bitstream) context.fromCache(
Bitstream.class, row.getIntColumn("bitstream_id"));
if (fromCache != null)
{
bitstreams.add(fromCache);
}
else
{
bitstreams.add(new Bitstream(context, row));
}
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
Bitstream[] bitstreamArray = new Bitstream[bitstreams.size()];
bitstreamArray = bitstreams.toArray(bitstreamArray);
return bitstreamArray;
}
/**
* Create a new bitstream, with a new ID. The checksum and file size are
* calculated. This method is not public, and does not check authorisation;