File dbFile = getNewsSafePath();
try
{
SqlJetDb db = SqlJetDb.open(dbFile, true);
try
{
db.beginTransaction(SqlJetTransactionMode.WRITE);
try
{
ISqlJetTable table = db.getTable("articles");
ISqlJetCursor cursor = table.open();
try
{
//- - - - - - - - - - - - - - -
// For each entry in the
// "articles" table...
//- - - - - - - - - - - - - - -
do
{
// Remove the article if it has not
// been refreshed for too long
long refreshDateInMillis = cursor.getInteger("refreshed");
long diffTime = Math.abs(currentDateTimeInMillis - refreshDateInMillis);
if( diffTime > (1000*60*60) ) // not refreshed during the last 60 minutes
{
String entry = String.format("\tDelete old article \"%s (%s)\" \r\n",
cursor.getString("title"),
cursor.getString("front_page"));
System.out.println(entry);
cursor.delete();
}
else
{
// Remove registered image from the list
// of ".dat" files to erase from disk
String imageFileName = cursor.getString("image");
filesList.remove(imageFileName);
}
}while( cursor.next() == true);
db.commit();
}
finally
{
cursor.close();
}
for(String imageFileName : filesList )
{
System.out.format("\tDelete unused file %s\r\n", imageFileName);
File imageFile = new File(gfPath, imageFileName);
imageFile.delete();
}
}
catch(Exception ex)
{
db.rollback();
}
}
finally
{
db.close();
}
}
catch (Exception ex)
{
Logger.getLogger(NewsSafe.class.getName()).log(Level.SEVERE, null, ex);