KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > pages > StatsPage


1 package org.ashkelon.pages;
2
3 import org.ashkelon.db.*;
4
5 import java.util.*;
6 import java.sql.*;
7
8 /**
9  * @author Eitan Suez
10  */

11 public class StatsPage extends Page
12 {
13    public StatsPage()
14    {
15       super();
16    }
17    
18    public String JavaDoc handleRequest() throws SQLException
19    {
20       if (app.getAttribute("api_count")==null)
21       {
22          int apis = DBUtils.getCount(conn, "API");
23          int packages = DBUtils.getCount(conn, "PACKAGE");
24          int classes = DBUtils.getCount(conn, "CLASSTYPE");
25          int members = DBUtils.getCount(conn, "MEMBER");
26
27          app.setAttribute("api_count", new Integer JavaDoc(apis));
28          app.setAttribute("package_count", new Integer JavaDoc(packages));
29          app.setAttribute("class_count", new Integer JavaDoc(classes));
30          app.setAttribute("member_count", new Integer JavaDoc(members));
31       }
32       
33       List apipkgcounts = getCountsFor("apistatspkg");
34       List apiclscounts = getCountsFor("apistatscls");
35       List apimmbcounts = getCountsFor("apistatsmmb");
36       
37       request.setAttribute("apipkgcounts", apipkgcounts);
38       request.setAttribute("apiclscounts", apiclscounts);
39       request.setAttribute("apimmbcounts", apimmbcounts);
40
41       return null;
42    }
43
44
45
46    private List getCountsFor(String JavaDoc stmt_key) throws SQLException
47    {
48       DBMgr dbmgr = DBMgr.getInstance();
49       String JavaDoc sql = dbmgr.getStatement(stmt_key);
50       Statement stmt = conn.createStatement();
51       ResultSet rset = stmt.executeQuery(sql);
52       
53       List counts = new ArrayList(20);
54       List pair;
55       
56       while (rset.next())
57       {
58          pair = new ArrayList(2);
59          pair.add(new Integer JavaDoc(rset.getInt(1)));
60          pair.add(rset.getString(2));
61          counts.add(pair);
62       }
63       
64       rset.close();
65       stmt.close();
66       
67       return counts;
68    }
69
70
71 }
72
73
Popular Tags