public class StatsDB
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected java.sql.Connection |
con
The db connection (if any).
|
protected java.sql.PreparedStatement |
deleteprops
The prepared delete properties statement.
|
protected java.sql.PreparedStatement |
getlatest
The prepared get latest entry query statement.
|
protected java.sql.PreparedStatement |
insert
The prepared insert statement for new platform entries (without dbid).
|
protected java.sql.PreparedStatement |
insert2
The prepared insert statement for remote platform entries (with dbid).
|
protected java.sql.PreparedStatement |
insertprops
The prepared insert properties statement.
|
protected java.util.Map<java.lang.String,java.lang.Integer> |
latest
The latest entries (cached for speed).
|
protected java.lang.String |
peerid
The peer id.
|
protected java.sql.PreparedStatement |
update
The prepared update statement for platform entries.
|
| Modifier | Constructor and Description |
|---|---|
protected |
StatsDB(java.lang.String peerid,
java.sql.Connection con)
Create the db object.
|
| Modifier and Type | Method and Description |
|---|---|
static StatsDB |
createDB(java.lang.String peerid)
Create the db object.
|
java.util.Iterator<PlatformInfo> |
getAllPlatformInfos(boolean properties)
Get all saved platform infos for direct data export (sorted by id, oldest first).
|
int |
getLatestEntry(java.lang.String peerid)
Get the latest id for a peer.
|
PlatformInfo[] |
getPlatformInfos(int limit)
Get cumulated platform infos per ip to use for display (sorted by recency, newest first).
|
PlatformInfo[] |
getPlatformInfosForSync(java.lang.String peerid,
int startid,
int cnt)
Get platform infos for history synchronization
|
protected static void |
logResultSet(java.sql.ResultSet rs)
Print out the contents of a result set.
|
static void |
main(java.lang.String[] args)
Test the stats db.
|
protected void |
migrateFrom(StatsDB old)
Migrate from one database to another.
|
protected static java.sql.Connection |
openDerbyDB()
Create a derby db connection.
|
protected static java.sql.Connection |
openH2DB(java.lang.String peerid)
Create a derby db connection.
|
protected static void |
printPlatformInfos(java.util.Iterator<PlatformInfo> infos)
Print out the contents of a result set.
|
protected static void |
printPlatformInfos(PlatformInfo[] infos)
Print out the contents of a result set.
|
protected static void |
printResultSet(java.sql.ResultSet rs)
Print out the contents of a result set.
|
void |
save(PlatformInfo pi)
Save (insert or update) a platform info object.
|
void |
shutdown()
Close the database connection on exit.
|
void |
writePlatformInfos(java.io.OutputStream out,
int limit)
Write platform infos as JSON to the provided output stream.
|
protected java.lang.String peerid
protected java.sql.Connection con
protected java.sql.PreparedStatement insert
protected java.sql.PreparedStatement insert2
protected java.sql.PreparedStatement update
protected java.sql.PreparedStatement getlatest
protected java.sql.PreparedStatement deleteprops
protected java.sql.PreparedStatement insertprops
protected java.util.Map<java.lang.String,java.lang.Integer> latest
protected StatsDB(java.lang.String peerid,
java.sql.Connection con)
public static StatsDB createDB(java.lang.String peerid)
protected static java.sql.Connection openDerbyDB()
throws java.lang.Exception
java.lang.Exceptionprotected static java.sql.Connection openH2DB(java.lang.String peerid)
throws java.lang.Exception
java.lang.Exceptionpublic void save(PlatformInfo pi)
pi - The platform info.public java.util.Iterator<PlatformInfo> getAllPlatformInfos(boolean properties)
public PlatformInfo[] getPlatformInfosForSync(java.lang.String peerid, int startid, int cnt)
peerid - The peer id;startid - Start id;cnt - The number of entries to retrieve;public PlatformInfo[] getPlatformInfos(int limit)
limit - Limit the number of results (-1 for no limit);public void writePlatformInfos(java.io.OutputStream out,
int limit)
limit - Limit the number of results (-1 for no limit);public int getLatestEntry(java.lang.String peerid)
public void shutdown()
protected void migrateFrom(StatsDB old)
public static void main(java.lang.String[] args)
throws java.lang.Exception
args - Ignored.java.lang.Exception - on database problems.protected static void printPlatformInfos(PlatformInfo[] infos)
protected static void printPlatformInfos(java.util.Iterator<PlatformInfo> infos)
protected static void printResultSet(java.sql.ResultSet rs)
throws java.lang.Exception
java.lang.Exceptionprotected static void logResultSet(java.sql.ResultSet rs)
throws java.lang.Exception
java.lang.Exception