2013-06-16 11:48:23 +02:00
|
|
|
package com.commafeed.backend;
|
|
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
2013-06-18 08:54:53 +02:00
|
|
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
2013-06-16 11:48:23 +02:00
|
|
|
|
|
|
|
|
public class DatabaseCleaner {
|
|
|
|
|
|
|
|
|
|
@Inject
|
2013-06-18 08:54:53 +02:00
|
|
|
FeedEntryStatusDAO feedEntryStatusDAO;
|
2013-06-16 11:48:23 +02:00
|
|
|
|
2013-06-18 13:00:03 +02:00
|
|
|
public long cleanOlderThan(long value, TimeUnit unit) {
|
2013-06-16 11:48:23 +02:00
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
cal.add(Calendar.MINUTE, -1 * (int) unit.toMinutes(value));
|
|
|
|
|
|
2013-06-18 13:00:03 +02:00
|
|
|
long total = 0;
|
|
|
|
|
int deleted = -1;
|
|
|
|
|
do {
|
|
|
|
|
deleted = feedEntryStatusDAO.delete(cal.getTime(), 100);
|
|
|
|
|
total += deleted;
|
|
|
|
|
} while (deleted != 0);
|
|
|
|
|
return total;
|
2013-06-16 11:48:23 +02:00
|
|
|
}
|
|
|
|
|
}
|