3 import java
.sql
.ResultSet
;
6 /** Service class for getting mote data.
8 * The mote data can be anything from availability information, mote
9 * attributes such as MAC and net address, as well as site attributes
12 public class MoteData
{
14 /** Get status information about all motes in the testbed.
16 * Builds a query to extract all info about the testbed motes
17 * including mote and site attributes into a single table.
19 * @param session_id The client session.
20 * @return A serialized SimpleTable with mote data.
23 public SimpleTable
getMoteData(String session_id
) throws Exception
28 SimpleTable result
= null;
29 Object
[] param
= { session_id
};
32 sql
= new SQLHelper();
34 query
= "select m.id mote_id, m.site_id site_id,s.sitename site, " +
35 "case when m.curr_session_id=? then 'controlled' " +
36 "when isnull(m.curr_session_id) then 'available' else 'occupied' end mote_usage ";
38 select
= "select id, name from moteattrtype order by sortseq";
39 rs
= sql
.retrieve(select
);
41 query
+=getMoteAttrSubquery(rs
.getString("name"),rs
.getString("id"));
43 select
= "select id, name from siteattrtype order by sortseq";
44 rs
= sql
.retrieve(select
);
46 query
+=getSiteAttrSubquery(rs
.getString("name"),rs
.getString("id"));
48 query
+=" from mote m, site s " +
49 " where s.id=m.site_id";
50 rs
= sql
.retrieve(query
, param
);
52 int rows
= rs
.getRow();
53 int cols
= rs
.getMetaData().getColumnCount();
54 result
= new SimpleTable(rows
,cols
);
57 for (int i
=0;i
<cols
;i
++){
58 String title
= rs
.getMetaData().getColumnLabel(i
+1);
59 String name
= rs
.getMetaData().getColumnName(i
+1);
60 String classname
= rs
.getMetaData().getColumnClassName(i
+1);
61 result
.getColumnHeaders()[i
] = new ColumnHeader(title
,name
,true,classname
);
66 for (int j
=0;j
<cols
;j
++)
68 result
.getData()[i
][j
] = rs
.getObject(j
+1);
80 private String
getMoteAttrSubquery(String colname
,String type_id
)
82 return ", (select ma.val from moteattr ma, mote_moteattr mma" +
83 " where ma.moteattrtype_id="+type_id
+
84 " and ma.id = mma.moteattr_id" +
85 " and mma.mote_id=m.id) "+colname
+" ";
88 private String
getSiteAttrSubquery(String colname
,String type_id
)
90 return ", (select sa.val from siteattr sa, site_siteattr ssa" +
91 " where sa.siteattrtype_id="+type_id
+
92 " and sa.id = ssa.siteattr_id" +
93 " and ssa.site_id=s.id) "+colname
+" ";