mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-24 16:21:57 +01:00
Task registration to ReactHook, Table cleaning
This commit is contained in:
parent
2a06c57c71
commit
19068d8f81
@ -9,6 +9,7 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.Table;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.volmit.react.api.SampledType;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -43,6 +44,17 @@ public class ReactDataTable extends Table {
|
||||
.toString());
|
||||
}
|
||||
|
||||
public void clean() throws SQLException {
|
||||
String sql = "DELETE FROM " + tableName + " WHERE " + Col.DATE + "<?";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, System.currentTimeMillis() - TimeAmount.MONTH.ms());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addData(ReactValue value) throws SQLException {
|
||||
String sql = "INSERT INTO " + tableName + " (" +
|
||||
Col.SAMPLED_TYPE + ", " +
|
||||
|
@ -2,6 +2,11 @@ package com.djrapitops.pluginbridge.plan.react;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.task.ITask;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
|
||||
/**
|
||||
@ -11,13 +16,39 @@ import com.djrapitops.pluginbridge.plan.Hook;
|
||||
*/
|
||||
public class ReactHook extends Hook {
|
||||
|
||||
private static ITask TASK;
|
||||
|
||||
public ReactHook(HookHandler hookHandler) {
|
||||
super("com.volmit.react.ReactPlugin", hookHandler);
|
||||
}
|
||||
|
||||
private static void setTask(ITask task) {
|
||||
if (TASK != null) {
|
||||
try {
|
||||
TASK.cancel();
|
||||
} catch (Exception ignored) {
|
||||
/* Possible "Task not registered" exception is ignored. */
|
||||
}
|
||||
}
|
||||
ReactHook.TASK = task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hook() throws NoClassDefFoundError {
|
||||
Plan plan = Plan.getInstance();
|
||||
try {
|
||||
if (enabled) {
|
||||
Plan plan = Plan.getInstance();
|
||||
|
||||
ReactDataTable table = new ReactDataTable((SQLDB) plan.getSystem().getDatabaseSystem().getActiveDatabase());
|
||||
table.createTable();
|
||||
table.clean();
|
||||
|
||||
ITask task = RunnableFactory.createNew(new DataCollectionTask(table))
|
||||
.runTaskTimerAsynchronously(TimeAmount.SECOND.ticks() * 10L, TimeAmount.SECOND.ticks() * 10L);
|
||||
setTask(task);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user