net.tinyos.tinydb
Class DBLogger

java.lang.Object
  |
  +--net.tinyos.tinydb.DBLogger
All Implemented Interfaces:
QueryListener, ResultListener

public class DBLogger
extends java.lang.Object
implements ResultListener, QueryListener

DBLogger is repsonsible for logging query results to Postgres. When instantiated with a query, it creates a new table to hold the results of that query and registers itself as a listener to results from that query. The name of table that is logged to can be retrieved via the getTableName() method. It will be uniquely generated for each query. The schema of the results table is: +----------------------------------------------------------+ | time stamp | epoch no | field1 | .... | field n | +----------------------------------------------------------+ Additionally, each query is logged to a queries table (which must have been created before DBLogger is invoked. The command to insert the queries table is: create table queries (qname varchar(10), query_time timestamp, query_string varchar(500));


Constructor Summary
DBLogger(net.tinyos.tinydb.TinyDBQuery query, java.lang.String queryStr, net.tinyos.tinydb.TinyDBNetwork nw)
          Start logging the specified query
 
Method Summary
 void addQuery(net.tinyos.tinydb.TinyDBQuery q)
          QueryListener Method.
 void addResult(net.tinyos.tinydb.QueryResult qr)
          ResultListener Method.
 void close()
          Shut down the connection to Postgres.
 java.lang.String getTableName()
           
 void removeQuery(net.tinyos.tinydb.TinyDBQuery q)
          QueryListener Method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBLogger

public DBLogger(net.tinyos.tinydb.TinyDBQuery query,
                java.lang.String queryStr,
                net.tinyos.tinydb.TinyDBNetwork nw)
         throws java.sql.SQLException
Start logging the specified query

Parameters:
query - The query to log
queryStr - The SQL string corresponding to query (since not all TinyDB queries have a unique SQL representation)
nw - The TinyDBNetwork that will deliver results for this query
Method Detail

getTableName

public java.lang.String getTableName()
Returns:
The name of the table to which this queries results are being logged

addResult

public void addResult(net.tinyos.tinydb.QueryResult qr)
ResultListener Method. Log the specified query result to the table set up for this DBLogger.

Specified by:
addResult in interface ResultListener
Parameters:
qr - The result to log

removeQuery

public void removeQuery(net.tinyos.tinydb.TinyDBQuery q)
QueryListener Method. Stop logging for the specified query.

Specified by:
removeQuery in interface QueryListener
Parameters:
q - The query to stop logging for

addQuery

public void addQuery(net.tinyos.tinydb.TinyDBQuery q)
QueryListener Method. Does nothing.

Specified by:
addQuery in interface QueryListener

close

public void close()
Shut down the connection to Postgres.