Refactoring in Zutil
Former-commit-id: fb96815cdc14141930bc026bff8272e241e05731
This commit is contained in:
parent
f3bf9d716d
commit
c1af8a1e17
3 changed files with 9 additions and 10 deletions
|
|
@ -1,11 +1,10 @@
|
||||||
package se.koc.hal;
|
package se.koc.hal;
|
||||||
|
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.handler.PropertiesSQLHandler;
|
import zutil.db.handler.PropertiesSQLResult;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
@ -52,12 +51,12 @@ public class HalContext {
|
||||||
|
|
||||||
// Read DB conf
|
// Read DB conf
|
||||||
dbConf =
|
dbConf =
|
||||||
db.exec("SELECT * FROM conf", new PropertiesSQLHandler());
|
db.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
||||||
|
|
||||||
// Upgrade DB needed?
|
// Upgrade DB needed?
|
||||||
DBConnection defaultDB = new DBConnection(DBConnection.DBMS.SQLite, DEFAULT_DB_FILE);
|
DBConnection defaultDB = new DBConnection(DBConnection.DBMS.SQLite, DEFAULT_DB_FILE);
|
||||||
Properties defaultDBConf =
|
Properties defaultDBConf =
|
||||||
db.exec("SELECT * FROM conf", new PropertiesSQLHandler());
|
db.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
||||||
if(defaultDBConf.getProperty("db_version") != null &&
|
if(defaultDBConf.getProperty("db_version") != null &&
|
||||||
defaultDBConf.getProperty("db_version").compareTo(dbConf.getProperty("db_version")) > 0) {
|
defaultDBConf.getProperty("db_version").compareTo(dbConf.getProperty("db_version")) > 0) {
|
||||||
logger.info("Upgrading DB (from: v"+dbConf.getProperty("db_version") +", to: v"+defaultDBConf.getProperty("db_version") +")...");
|
logger.info("Upgrading DB (from: v"+dbConf.getProperty("db_version") +", to: v"+defaultDBConf.getProperty("db_version") +")...");
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import se.koc.hal.HalContext;
|
||||||
import se.koc.hal.struct.Sensor;
|
import se.koc.hal.struct.Sensor;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.SQLResultHandler;
|
import zutil.db.SQLResultHandler;
|
||||||
import zutil.db.handler.SimpleSQLHandler;
|
import zutil.db.handler.SimpleSQLResult;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,7 +50,7 @@ public class DataAggregatorDaemon extends TimerTask implements HalDaemon {
|
||||||
public void aggregateSensor(long sensorId) {
|
public void aggregateSensor(long sensorId) {
|
||||||
DBConnection db = HalContext.getDB();
|
DBConnection db = HalContext.getDB();
|
||||||
try {
|
try {
|
||||||
Long maxDBTimestamp = db.exec("SELECT MAX(timestamp_end) FROM sensor_data_aggr WHERE sensor_id == "+sensorId, new SimpleSQLHandler<Long>());
|
Long maxDBTimestamp = db.exec("SELECT MAX(timestamp_end) FROM sensor_data_aggr WHERE sensor_id == "+sensorId, new SimpleSQLResult<Long>());
|
||||||
if(maxDBTimestamp == null)
|
if(maxDBTimestamp == null)
|
||||||
maxDBTimestamp = 0l;
|
maxDBTimestamp = 0l;
|
||||||
// 5 minute aggregation
|
// 5 minute aggregation
|
||||||
|
|
@ -62,7 +62,7 @@ public class DataAggregatorDaemon extends TimerTask implements HalDaemon {
|
||||||
new FiveMinuteAggregator());
|
new FiveMinuteAggregator());
|
||||||
|
|
||||||
// hour aggregation
|
// hour aggregation
|
||||||
maxDBTimestamp = db.exec("SELECT MAX(timestamp_end) FROM sensor_data_aggr WHERE sensor_id == "+sensorId+" AND timestamp_end-timestamp_start == " + (HOUR_IN_MS-1), new SimpleSQLHandler<Long>());
|
maxDBTimestamp = db.exec("SELECT MAX(timestamp_end) FROM sensor_data_aggr WHERE sensor_id == "+sensorId+" AND timestamp_end-timestamp_start == " + (HOUR_IN_MS-1), new SimpleSQLResult<Long>());
|
||||||
if(maxDBTimestamp == null)
|
if(maxDBTimestamp == null)
|
||||||
maxDBTimestamp = 0l;
|
maxDBTimestamp = 0l;
|
||||||
long hourPeriodTimestamp = getTimestampMinutePeriodStart(60, System.currentTimeMillis()-HOUR_AGGREGATION_OFFSET);
|
long hourPeriodTimestamp = getTimestampMinutePeriodStart(60, System.currentTimeMillis()-HOUR_AGGREGATION_OFFSET);
|
||||||
|
|
@ -73,7 +73,7 @@ public class DataAggregatorDaemon extends TimerTask implements HalDaemon {
|
||||||
new HourAggregator());
|
new HourAggregator());
|
||||||
|
|
||||||
// day aggregation
|
// day aggregation
|
||||||
maxDBTimestamp = db.exec("SELECT MAX(timestamp_end) FROM sensor_data_aggr WHERE sensor_id == "+sensorId+" AND timestamp_end-timestamp_start == " + (DAY_IN_MS-1), new SimpleSQLHandler<Long>());
|
maxDBTimestamp = db.exec("SELECT MAX(timestamp_end) FROM sensor_data_aggr WHERE sensor_id == "+sensorId+" AND timestamp_end-timestamp_start == " + (DAY_IN_MS-1), new SimpleSQLResult<Long>());
|
||||||
if(maxDBTimestamp == null)
|
if(maxDBTimestamp == null)
|
||||||
maxDBTimestamp = 0l;
|
maxDBTimestamp = 0l;
|
||||||
long dayPeriodTimestamp = getTimestampHourPeriodStart(24, System.currentTimeMillis()-DAY_AGGREGATION_OFFSET);
|
long dayPeriodTimestamp = getTimestampHourPeriodStart(24, System.currentTimeMillis()-DAY_AGGREGATION_OFFSET);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import se.koc.hal.HalContext;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.bean.DBBean;
|
import zutil.db.bean.DBBean;
|
||||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||||
import zutil.db.handler.SimpleSQLHandler;
|
import zutil.db.handler.SimpleSQLResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-03.
|
* Created by Ziver on 2015-12-03.
|
||||||
|
|
@ -39,7 +39,7 @@ public class Sensor extends DBBean{
|
||||||
|
|
||||||
|
|
||||||
public static long getHighestSequenceId(long sensorId) throws SQLException{
|
public static long getHighestSequenceId(long sensorId) throws SQLException{
|
||||||
Integer id = HalContext.getDB().exec("SELECT MAX(sequence_id) FROM sensor_data_aggr WHERE sensor_id == "+ sensorId, new SimpleSQLHandler<Integer>());
|
Integer id = HalContext.getDB().exec("SELECT MAX(sequence_id) FROM sensor_data_aggr WHERE sensor_id == "+ sensorId, new SimpleSQLResult<Integer>());
|
||||||
return (id != null ? id+1 : 1);
|
return (id != null ? id+1 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue