mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-03 15:33:22 +01:00
46 lines
1.2 KiB
Java
46 lines
1.2 KiB
Java
package com.Acrobot.ChestShop.DB;
|
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
|
|
|
import javax.persistence.OptimisticLockException;
|
|
import java.util.List;
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class Queue implements Runnable {
|
|
private static final ConcurrentLinkedQueue<Transaction> queue = new ConcurrentLinkedQueue<Transaction>();
|
|
|
|
public static void addToQueue(Transaction t) {
|
|
queue.add(t);
|
|
}
|
|
|
|
public synchronized void run() {
|
|
if (Properties.RECORD_TIME_TO_LIVE != -1)
|
|
deleteOld();
|
|
|
|
ChestShop.getDB().save(queue);
|
|
queue.clear();
|
|
}
|
|
|
|
public synchronized 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) - Properties.RECORD_TIME_TO_LIVE)
|
|
.findList();
|
|
}
|
|
}
|