ChestShop-3/com/Acrobot/ChestShop/DB/Queue.java

47 lines
1.2 KiB
Java
Raw Normal View History

2011-05-29 13:25:25 +02:00
package com.Acrobot.ChestShop.DB;
import com.Acrobot.ChestShop.ChestShop;
2011-06-09 22:54:01 +02:00
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
2011-05-29 13:25:25 +02:00
import javax.persistence.OptimisticLockException;
import java.util.ArrayList;
import java.util.List;
2011-05-29 13:25:25 +02:00
/**
* @author Acrobot
*/
public class Queue implements Runnable {
private static final ArrayList<Transaction> queue = new ArrayList<Transaction>();
2011-05-29 13:25:25 +02:00
2011-06-09 22:54:01 +02:00
public static void addToQueue(Transaction t) {
2011-05-29 13:25:25 +02:00
queue.add(t);
}
public synchronized void run() {
if (Config.getInteger(Property.RECORD_TIME_TO_LIVE) != -1)
deleteOld();
ChestShop.getDB().save(queue);
2011-05-29 13:25:25 +02:00
queue.clear();
}
public static boolean deleteOld() {
try {
ChestShop.getDB().delete(getOld());
return true;
} catch (OptimisticLockException ex) {
return false;
}
}
public static List getOld() throws OptimisticLockException {
return ChestShop
.getDB()
.find(Transaction.class)
.where()
.lt("sec", (System.currentTimeMillis() / 1000L) - Config.getInteger(Property.RECORD_TIME_TO_LIVE))
.findList();
}
2011-05-29 13:25:25 +02:00
}