commit_counter++; if (commit_counter % 100 == 0) { context.commit(); }
    public static void cleanup(boolean deleteDbRecords) throws SQLException, IOException    {        Context context = null;        BitstreamInfoDAO bitstreamInfoDAO = new BitstreamInfoDAO();        try        {            context = new Context();            String myQuery = "select * from Bitstream where deleted = '1'";            List storage = DatabaseManager.queryTable(context, "Bitstream", myQuery)                    .toList();            for (Iterator iterator = storage.iterator(); iterator.hasNext();)            {                TableRow row = (TableRow) 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");                        bitstreamInfoDAO.deleteBitstreamInfoWithHistory(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");                    bitstreamInfoDAO.deleteBitstreamInfoWithHistory(bid);                    DatabaseManager.delete(context, "Bitstream", bid);                }				if (isRegisteredBitstream(row.getStringColumn("internal_id"))) {				    continue;			// do not delete registered bitstreams				}                boolean success = file.delete();                if (log.isDebugEnabled())                {                    log.debug("Deleted bitstream " + bid + " (file "                            + file.getAbsolutePath() + ") with result "                            + success);                }                // if the file was deleted then                // try deleting the parents                // Otherwise the cleanup script is set to                 // leave the db records then the file                // and directories have already been deleted                // if this is turned off then it still looks like the                // file exists                if( success )                {                    deleteParents(file);                }            }            context.complete();        }        // Aborting will leave the DB objects around, even if the        // bitstreams are deleted. This is OK; deleting them next        // time around will be a no-op.        catch (SQLException sqle)        {            context.abort();            throw sqle;        }        catch (IOException ioe)        {            context.abort();            throw ioe;        }    }