net.tinyos.tinydb
Class TinyDBQuery

java.lang.Object
  |
  +--net.tinyos.tinydb.TinyDBQuery

public class TinyDBQuery
extends java.lang.Object

TinyDBQuery is a Java data structure representing a query running (or to be run) on a set of motes. Queries consist of: - a list of fields to select - a list of expressions over those fields, where an expression is - an filter that rejects some readings - an aggregate that combines local readings with readings from neighbors. In addition to allowing a query to be built, this class includes methods to generate radio messages so the query can be distributed over the network or to abort the query


Field Summary
 short epochDur
           
 byte from_qid
           
static short kEPOCH_DUR_ONE_SHOT
           
static byte NO_FROM_QUERY
           
 byte qid
           
 
Constructor Summary
TinyDBQuery(byte qid, short epochDur)
          Constructor
 
Method Summary
 net.tinyos.message.Message abortMessage()
          Return a byte array representing a radio message that will tell motes to abort this query
 boolean active()
           
 void addExpr(net.tinyos.tinydb.QueryExpr e)
          Add the specified expression to the query
 void addField(net.tinyos.tinydb.QueryField f)
          Add the specified field to the query
 boolean containsNonAggFields()
          Returns true iff the query contains a field that isn't contained in any aggregate.
 java.util.Vector getColumnHeadings()
           
 net.tinyos.tinydb.QueryExpr getExpr(int i)
           
 net.tinyos.tinydb.QueryField getField(int i)
          Return the ith field in this query
 byte getFieldType(int idx)
           
 byte getFromQid()
           
 net.tinyos.tinydb.AggExpr getGroupExpr()
           
 int getId()
          Return the id of the query
 java.lang.String getSQL()
          Return the text of the SQL for this query as set by setSQL (Note that TinyDBQuery does not include an interface for generating SQL from an arbitrary query.)
 java.lang.String groupColName()
          Return the name of the group by column
 boolean grouped()
          Return true if the query is grouped (e.g.
 boolean hasOutputAction()
           
 boolean isAgg()
          Return true if this query contains one or more aggregate expressions
 java.util.Iterator messageIterator()
          Return an Iterator over messages to be sent to start sensors running this query
 int numExprs()
           
 int numFields()
          Return the number of fields in this query
 void setActive(boolean active)
           
 void setEpoch(short epochDur)
           
 void setFromQid(byte qid)
          Set the id of the query this query reads results from
 void setGrouped(boolean isGrouped)
           
 void setGroupExpr(net.tinyos.tinydb.AggExpr ae)
           
 void setId(byte qid)
           
 void setOutputCommand(java.lang.String cmd)
           
 void setOutputCommand(java.lang.String cmd, short param)
           
 void setSQL(java.lang.String s)
          Set the SQL string associated with this query.
 java.lang.String toString()
           
 void useRamBuffer(short size)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

qid

public byte qid

from_qid

public byte from_qid

epochDur

public short epochDur

NO_FROM_QUERY

public static final byte NO_FROM_QUERY
See Also:
Constant Field Values

kEPOCH_DUR_ONE_SHOT

public static final short kEPOCH_DUR_ONE_SHOT
See Also:
Constant Field Values
Constructor Detail

TinyDBQuery

public TinyDBQuery(byte qid,
                   short epochDur)
Constructor

Parameters:
qid - The id of the query
epochDur - The rate at which results from the query should be generated
Method Detail

getId

public int getId()
Return the id of the query


setId

public void setId(byte qid)

setEpoch

public void setEpoch(short epochDur)

addField

public void addField(net.tinyos.tinydb.QueryField f)
Add the specified field to the query


addExpr

public void addExpr(net.tinyos.tinydb.QueryExpr e)
Add the specified expression to the query


grouped

public boolean grouped()
Return true if the query is grouped (e.g. contains one or more aggregates with a group by expression)


setGrouped

public void setGrouped(boolean isGrouped)

setGroupExpr

public void setGroupExpr(net.tinyos.tinydb.AggExpr ae)

getGroupExpr

public net.tinyos.tinydb.AggExpr getGroupExpr()

groupColName

public java.lang.String groupColName()
Return the name of the group by column


getSQL

public java.lang.String getSQL()
Return the text of the SQL for this query as set by setSQL (Note that TinyDBQuery does not include an interface for generating SQL from an arbitrary query.)


setSQL

public void setSQL(java.lang.String s)
Set the SQL string associated with this query. Note that this string doesn't not neccessarily have any relationship to the fields / expressions in this object


isAgg

public boolean isAgg()
Return true if this query contains one or more aggregate expressions


numExprs

public int numExprs()

getExpr

public net.tinyos.tinydb.QueryExpr getExpr(int i)
                                    throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

containsNonAggFields

public boolean containsNonAggFields()
Returns true iff the query contains a field that isn't contained in any aggregate. NOTE: Will return FALSE in this example "Select light, avg(light) from sensors" But, tinydb processes this query if it were "Select avg(light) from sensors"


setOutputCommand

public void setOutputCommand(java.lang.String cmd,
                             short param)

setOutputCommand

public void setOutputCommand(java.lang.String cmd)

hasOutputAction

public boolean hasOutputAction()

numFields

public int numFields()
Return the number of fields in this query


getField

public net.tinyos.tinydb.QueryField getField(int i)
                                      throws java.lang.ArrayIndexOutOfBoundsException
Return the ith field in this query

Throws:
java.lang.ArrayIndexOutOfBoundsException - if i < 0 or i >= numFields()

abortMessage

public net.tinyos.message.Message abortMessage()
Return a byte array representing a radio message that will tell motes to abort this query


getColumnHeadings

public java.util.Vector getColumnHeadings()

getFieldType

public byte getFieldType(int idx)
                  throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException

messageIterator

public java.util.Iterator messageIterator()
Return an Iterator over messages to be sent to start sensors running this query


getFromQid

public byte getFromQid()

setFromQid

public void setFromQid(byte qid)
Set the id of the query this query reads results from


useRamBuffer

public void useRamBuffer(short size)

active

public boolean active()

setActive

public void setActive(boolean active)