Package com.facebook.openwifi.rrm.mysql
Class DatabaseManager
- java.lang.Object
-
- com.facebook.openwifi.rrm.mysql.DatabaseManager
-
public class DatabaseManager extends Object
Database connection manager.
-
-
Constructor Summary
Constructors Constructor Description DatabaseManager(String server, String user, String password, String dbName, int dataRetentionIntervalDays)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStateRecords(List<StateRecord> records)Insert state record(s) into the database.voidaddWifiScan(String serialNumber, long timestampSeconds, List<WifiScanEntry> entries)Insert wifi scan results into the database.voidclose()Close all database resources.Map<String,State>getLatestState()Return the latest state records for each unique device.Map<Long,List<WifiScanEntry>>getLatestWifiScans(String serialNumber, int count)Return up to the N latest wifiscan results for the given device as a map of timestamp to scan results.voidinit()Run database initialization.
-
-
-
Constructor Detail
-
DatabaseManager
public DatabaseManager(String server, String user, String password, String dbName, int dataRetentionIntervalDays)
Constructor.- Parameters:
server- the database host:port (ex. "localhost:3306")user- the database userpassword- the database passworddbName- the database namedataRetentionIntervalDays- the data retention interval in days (0 to disable)
-
-
Method Detail
-
init
public void init() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLExceptionRun database initialization.
-
close
public void close() throws SQLExceptionClose all database resources.- Throws:
SQLException
-
addStateRecords
public void addStateRecords(List<StateRecord> records) throws SQLException
Insert state record(s) into the database.- Throws:
SQLException
-
getLatestState
public Map<String,State> getLatestState() throws SQLException
Return the latest state records for each unique device.- Throws:
SQLException
-
addWifiScan
public void addWifiScan(String serialNumber, long timestampSeconds, List<WifiScanEntry> entries) throws SQLException
Insert wifi scan results into the database.- Parameters:
serialNumber- serial numbertimestampSeconds- timestamp (Unix time in seconds).entries- list of wifiscan entries- Throws:
SQLException
-
getLatestWifiScans
public Map<Long,List<WifiScanEntry>> getLatestWifiScans(String serialNumber, int count) throws SQLException
Return up to the N latest wifiscan results for the given device as a map of timestamp to scan results.- Throws:
SQLException
-
-