mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-24 19:15:48 +01:00
5908eb67fa
- Copied utilities from ChestShop-4 - Made code really, really nicer to read - Made every external plugin's wrapper a listener, so it listens to events instead of being hard-coded.
48 lines
1.3 KiB
Java
48 lines
1.3 KiB
Java
package com.Acrobot.ChestShop.DB;
|
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
|
import com.Acrobot.ChestShop.Config.Config;
|
|
import com.Acrobot.ChestShop.Config.Property;
|
|
|
|
import javax.persistence.OptimisticLockException;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class Queue implements Runnable {
|
|
private static final List<Transaction> queue = Collections.synchronizedList(new ArrayList<Transaction>());
|
|
|
|
public static void addToQueue(Transaction t) {
|
|
queue.add(t);
|
|
}
|
|
|
|
public synchronized void run() {
|
|
if (Config.getInteger(Property.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) - Config.getInteger(Property.RECORD_TIME_TO_LIVE))
|
|
.findList();
|
|
}
|
|
}
|