for (Iterator<TableRow> iterator = storage.iterator(); iterator.hasNext();)
{
TableRow row = iterator.next();
int bid = row.getIntColumn("bitstream_id");
GeneralFile file = getFile(row);
// Make sure entries which do not exist are removed
if (file == null || !file.exists())
{
log.debug("file is null");
if (deleteDbRecords)
{
log.debug("deleting record");
if (verbose)
{
System.out.println(" - Deleting bitstream information (ID: " + bid + ")");
}
bitstreamInfoDAO.deleteBitstreamInfoWithHistory(bid);
if (verbose)
{
System.out.println(" - Deleting bitstream record from database (ID: " + bid + ")");
}
DatabaseManager.delete(context, "Bitstream", bid);
}
continue;
}
// This is a small chance that this is a file which is
// being stored -- get it next time.
if (isRecent(file))
{
log.debug("file is recent");
continue;
}
if (deleteDbRecords)
{
log.debug("deleting db record");
if (verbose)
{
System.out.println(" - Deleting bitstream information (ID: " + bid + ")");
}
bitstreamInfoDAO.deleteBitstreamInfoWithHistory(bid);
if (verbose)
{
System.out.println(" - Deleting bitstream record from database (ID: " + bid + ")");
}
DatabaseManager.delete(context, "Bitstream", bid);
}
if (isRegisteredBitstream(row.getStringColumn("internal_id"))) {
continue; // do not delete registered bitstreams
}
// Since versioning allows for multiple bitstreams, check if the internal identifier isn't used on another place
TableRow duplicateBitRow = DatabaseManager.querySingleTable(context, "Bitstream", "SELECT * FROM Bitstream WHERE internal_id = ? AND bitstream_id <> ?", row.getStringColumn("internal_id"), bid);
if(duplicateBitRow == null)
{
boolean success = file.delete();
String message = ("Deleted bitstream " + bid + " (file "
+ file.getAbsolutePath() + ") with result "
+ success);
if (log.isDebugEnabled())
{
log.debug(message);
}