KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > model > TrafficDataBean


1 /*
2  * TrafficDataBean.java
3  *
4  * Created on May 8, 2003, 9:37 PM
5  */

6
7 package com.quikj.application.communicator.applications.webtalk.model;
8
9 import java.sql.*;
10 import java.util.*;
11 /**
12  *
13  * @author Vinod Batra
14  */

15 public class TrafficDataBean
16 {
17     
18     private java.sql.Date JavaDoc startDate;
19     
20     private java.sql.Date JavaDoc endDate;
21     
22     private String JavaDoc groupid;
23     
24     private ArrayList result;
25     
26     /** Holds value of property height. */
27     private int height;
28     
29     /** Holds value of property width. */
30     private int width;
31     
32     public TrafficDataBean()
33     {
34     }
35     
36     public static java.sql.Date JavaDoc convertDate(String JavaDoc date)
37     {
38         StringTokenizer tokens = new StringTokenizer(date, "/");
39         if (tokens.countTokens() != 3)
40         {
41             return null;
42         }
43         
44         int m = 0;
45         int d = 0;
46         int y = 0;
47         
48         try
49         {
50             m = Integer.parseInt(tokens.nextToken()) - 1;
51             d = Integer.parseInt(tokens.nextToken());
52             y = Integer.parseInt(tokens.nextToken());
53             
54             Calendar cal = Calendar.getInstance();
55             cal.setLenient(false);
56             
57             try
58             {
59                 cal.set(y, m, d, 0, 0, 0);
60             }
61             catch (Exception JavaDoc ex)
62             {
63                 return null;
64             }
65             
66             return new java.sql.Date JavaDoc(cal.getTime().getTime());
67         }
68         catch (NumberFormatException JavaDoc ex)
69         {
70             return null;
71         }
72     }
73     
74     /** Getter for property groupid.
75      * @return Value of property groupid.
76      *
77      */

78     public String JavaDoc getGroupid()
79     {
80         return groupid;
81     }
82     
83     /** Setter for property groupid.
84      * @param groupid New value of property groupid.
85      *
86      */

87     public void setGroupid(String JavaDoc groupid)
88     {
89         this.groupid = groupid;
90     }
91     
92     /** Getter for property reDate.
93      * @return Value of property reDate.
94      *
95      */

96     public java.sql.Date JavaDoc getEndDate()
97     {
98         return endDate;
99     }
100     
101     /** Setter for property reDate.
102      * @param reDate New value of property reDate.
103      *
104      */

105     public void setEndDate(java.sql.Date JavaDoc endDate)
106     {
107         this.endDate = endDate;
108     }
109     
110     /** Getter for property rsDate.
111      * @return Value of property rsDate.
112      *
113      */

114     public java.sql.Date JavaDoc getStartDate()
115     {
116         return startDate;
117     }
118     
119     /** Setter for property rsDate.
120      * @param rsDate New value of property rsDate.
121      *
122      */

123     public void setStartDate(java.sql.Date JavaDoc startDate)
124     {
125         this.startDate = startDate;
126     }
127     
128     public void setResult(ArrayList result)
129     {
130         this.result = result;
131     }
132     
133     public ArrayList getResult()
134     {
135         return result;
136     }
137     
138     public void searchDatabase(Connection c)
139     {
140         try
141         {
142             List temp_list1 = new ArrayList();
143             List temp_list2 = new ArrayList();
144             List temp_list3 = new ArrayList();
145             List temp_list4 = new ArrayList();
146             
147             String JavaDoc select = "Select time_stamp, opm_name, opm_value from opm_operator_tbl where groupid = ?"
148             + " AND (time_stamp BETWEEN ? AND ?)"
149             + " AND ((opm_name='users_waiting') or (opm_name='users_talking') or (opm_name='actv_ops'))"
150             + " order by time_stamp";
151             
152             Statement st = c.createStatement();
153             st.execute("use webtalk ;");
154             
155             PreparedStatement ps = c.prepareStatement(select);
156             ps.setString(1, getGroupid());
157             ps.setDate(2, getStartDate());
158             ps.setDate(3, getEndDate());
159             ResultSet rs = ps.executeQuery();
160             
161             if (rs == null)
162             {
163                 result = null;
164             }
165             else
166             {
167                 Timestamp last = new Timestamp(0L);
168                 while (rs.next())
169                 {
170                     Timestamp ts = rs.getTimestamp(1);
171                     String JavaDoc opm_name = rs.getString(2);
172                     int count = rs.getInt(3);
173                     
174                     if (ts.equals(last) == false)
175                     {
176                         temp_list1.add(ts);
177                         last = ts;
178                     }
179                     
180                     if (opm_name.equals("actv_ops") == true)
181                     {
182                         temp_list2.add(new Integer JavaDoc(count));
183                     }
184                     else if (opm_name.equals("users_waiting") == true)
185                     {
186                         temp_list3.add(new Integer JavaDoc(count));
187                     }
188                     else if (opm_name.equals("users_talking") == true)
189                     {
190                         temp_list4.add(new Integer JavaDoc(count));
191                     }
192                 }
193                 
194                 result = new ArrayList();
195                 result.add(temp_list1);
196                 result.add(temp_list2);
197                 result.add(temp_list3);
198                 result.add(temp_list4);
199                 rs.close();
200             }
201         }
202         catch (Exception JavaDoc e)
203         {
204             // suppress
205
}
206     }
207     
208     /** Getter for property height.
209      * @return Value of property height.
210      *
211      */

212     public int getHeight()
213     {
214         return this.height;
215     }
216     
217     /** Setter for property height.
218      * @param height New value of property height.
219      *
220      */

221     public void setHeight(int height)
222     {
223         this.height = height;
224     }
225     
226     /** Getter for property width.
227      * @return Value of property width.
228      *
229      */

230     public int getWidth()
231     {
232         return this.width;
233     }
234     
235     /** Setter for property width.
236      * @param width New value of property width.
237      *
238      */

239     public void setWidth(int width)
240     {
241         this.width = width;
242     }
243     
244 }
Popular Tags