KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > statistics > TableStatistics


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22 package org.enhydra.dods.statistics;
23
24 import java.util.Date JavaDoc;
25
26 /**
27  *
28  * This class provides information about table and its statistics.
29  *
30  * @author Tanja Jovanovic
31  * @author Nenad Vico
32  * @author Zorica Suvajdzin
33  * @version 2.0 15.06.2003.
34  */

35 public class TableStatistics implements Statistics {
36
37     /**
38      * Number of insert statements performed on the table.
39      */

40     protected int insertNum = 0;
41
42     /**
43      * Number of update statements performed on the table.
44      */

45     protected int updateNum = 0;
46
47     /**
48      * Number of delete statements performed on the table.
49      */

50     protected int deleteNum = 0;
51
52     /**
53      * Number of lazy loadings performed on the table.
54      */

55     protected int lazyLoadingNum = 0;
56
57     /**
58      * Time when the statistics was started.
59      */

60     protected Date JavaDoc startTime;
61
62     /**
63      * Time when the statistics was stopped.
64      */

65     protected Date JavaDoc stopTime;
66
67     /**
68      * Total number of non-oid queries performed on the table.
69      * Query by oid is query which "where" clause contains request for DO with
70      * specified oid. Non-oid query is any other query.
71      */

72     protected int queryNum = 0;
73     
74     /**
75      * Total number of queries by oid performed on the table.
76      * Query by oid is query which "where" clause contains request for DO with
77      * specified oid.
78      */

79     protected int queryByOIdNum = 0;
80
81     /**
82      * Average time for executing non-oid queries in milliseconds.
83      * Query by oid is query which "where" clause contains request for DO with
84      * specified oid. Non-oid query is any other query.
85      */

86     protected int averageQueryTime = 0;
87
88     /**
89      * Average time for executing queries by oid in milliseconds.
90      * Query by oid is query which "where" clause contains request for DO with
91      * specified oid.
92      */

93     protected int averageQueryByOIdTime = 0;
94
95     /**
96      * Constructor().
97      */

98     public TableStatistics() {
99         this.clears();
100     }
101
102     /**
103      * Returns type of the statistics. In this case, this is TABLE_STATISTICS.
104      *
105      * @return Type of the statistics: TABLE_STATISTICS.
106      */

107     public int getStatisticsType() {
108         return TABLE_STATISTICS;
109     }
110
111     /**
112      * Returns number of insert statements performed on the table.
113      *
114      * @return Number of insert statements performed on the table.
115      */

116     public int getInsertNum() {
117         return insertNum;
118     }
119
120     /**
121      * Sets number of insert statements performed on the table.
122      *
123      * @param newInsertNum New number of insert statements performed on the
124      * table.
125      */

126     public void setInsertNum(int newInsertNum) {
127         this.insertNum = newInsertNum;
128     }
129
130     /**
131      * Increases number of insert statemenst performed on the table.
132      */

133     public void incrementInsertNum() {
134         insertNum++;
135     }
136
137     /**
138      * Returns number of update statements performed on the table.
139      *
140      * @return Number of update statements performed on the table.
141      */

142     public int getUpdateNum() {
143         return updateNum;
144     }
145
146     /**
147      * Sets number of update statements performed on the table.
148      *
149      * @param newUpdateNum New number of update statements performed on the
150      * table.
151      */

152     public void setUpdateNum(int newUpdateNum) {
153         this.updateNum = newUpdateNum;
154     }
155
156     /**
157      * Increases number of update statements performed on the table.
158      */

159     public void incrementUpdateNum() {
160         updateNum++;
161     }
162
163     /**
164      * Returns number of delete statements performed on the table.
165      *
166      * @return Number of delete statements performed on the table.
167      */

168     public int getDeleteNum() {
169         return deleteNum;
170     }
171
172     /**
173      * Sets number of delete statements performed on the table.
174      *
175      * @param newDeleteNum New number of delete statements performed on the
176      * table.
177      */

178     public void setDeleteNum(int newDeleteNum) {
179         this.deleteNum = newDeleteNum;
180     }
181
182     /**
183      * Increases number of delete statements performed on table.
184      */

185     public void incrementDeleteNum() {
186         deleteNum++;
187     }
188
189     /**
190      * Returns number of DML operations (inserts, updates and deletes) performed
191      * on the table.
192      *
193      * @return Number of DML operations performed on the table.
194      */

195     public int getDMLNum() {
196         return insertNum + updateNum + deleteNum;
197     }
198
199     /**
200      * Returns number of lazy loadings performed on the table.
201      *
202      * @return Number of lazy loadings performed on the table.
203      */

204     public int getLazyLoadingNum() {
205         return lazyLoadingNum;
206     }
207
208     /**
209      * Sets number of lazy loadings performed on the table.
210      *
211      * @param newLazyLoadingNum New number of lazy loadings performed on the
212      * table.
213      */

214     public void setLazyLoadingNum(int newLazyLoadingNum) {
215         this.lazyLoadingNum = newLazyLoadingNum;
216     }
217
218     /**
219      * Increases number of lazy loadings performed on the table for one.
220      */

221     public void incrementLazyLoadingNum() {
222         lazyLoadingNum++;
223     }
224
225     /**
226      * Returns time when the statistics was started.
227      *
228      * @return Time when the statistics was started.
229      */

230     public Date JavaDoc getStartTime() {
231         return startTime;
232     }
233
234     /**
235      * Sets time when the statistics starts.
236      *
237      * @param startTime Time when the statistics starts.
238      */

239     public void setStartTime(Date JavaDoc startTime) {
240         this.startTime = startTime;
241     }
242
243     /**
244      * Returns time when the statistics was stopped.
245      *
246      * @return Time when the statistics was stopped.
247      */

248     public Date JavaDoc getStopTime() {
249         return stopTime;
250     }
251
252     /**
253      * Sets time when the statistics stops.
254      *
255      * @param stopTime time when the statistics was stops.
256      */

257     public void setStopTime(Date JavaDoc stopTime) {
258         this.stopTime = stopTime;
259     }
260
261     /**
262      * Sets stop time to current time.
263      */

264     public void stopTime() {
265         stopTime = new Date JavaDoc();
266     }
267
268     /**
269      * Returns total number of non-oid queries performed on the table.
270      * Query by oid is query which "where" clause contains request for DO with
271      * specified oid. Non-oid query is any other query.
272      *
273      * @return Total number of non-oid queries performed on the table.
274      */

275     public int getQueryNum() {
276         return queryNum;
277     }
278
279     /**
280      * Sets total number of non-oid queries performed on the table.
281      * Query by oid is query which "where" clause contains request for DO with
282      * specified oid. Non-oid query is any other query.
283      *
284      * @param newQueryNum New total number of non-oid queries performed on
285      * the table.
286      */

287     public void setQueryNum(int newQueryNum) {
288         this.queryNum = newQueryNum;
289     }
290
291     /**
292      * Increases total number of non-oid queries performed on the table.
293      * Query by oid is query which "where" clause contains request for DO with
294      * specified oid. Non-oid query is any other query.
295      */

296     public void incrementQueryNum() {
297         queryNum++;
298     }
299
300     /**
301      * Returns total number of queries by oid performed on the table.
302      * Query by oid is query which "where" clause contains request for DO with
303      * specified oid.
304      *
305      * @return Total number of queries by oid performed performed on the table.
306      */

307     public int getQueryByOIdNum() {
308         return queryByOIdNum;
309     }
310
311     /**
312      * Sets total number of queries by oid performed on the table.
313      * Query by oid is query which "where" clause contains request for DO with
314      * specified oid.
315      *
316      * @param newQueryByOIdNum New total number of queries by oid performed on
317      * the table.
318      */

319     public void setQueryByOIdNum(int newQueryByOIdNum) {
320         this.queryByOIdNum = newQueryByOIdNum;
321     }
322
323     /**
324      * Increases total number of queries by oid performed on the table for one.
325      * Query by oid is query which "where" clause contains request for DO with
326      * specified oid.
327      */

328     public void incrementQueryByOIdNum() {
329         queryByOIdNum++;
330     }
331
332     /**
333      * Returns average time needed for executing non-oid query.
334      * Query by oid is query which "where" clause contains request for DO with
335      * specified oid. Non-oid query is any other query.
336      *
337      * @return Average time needed for executing non-oid query.
338      */

339     public int getQueryAverageTime() {
340         return averageQueryTime;
341     }
342
343     /**
344      * Updates average time needed for executing non-oid queries.
345      * Query by oid is query which "where" clause contains request for DO with
346      * specified oid. Non-oid query is any other query.
347      *
348      * @param newTime New query time in miliseconds.
349      */

350     public void updateQueryAverageTime(int newTime) {
351         long sum = 0;
352
353         if (queryNum > 0) {
354             sum = (queryNum - 1) * averageQueryTime + newTime;
355             sum = sum / queryNum;
356             averageQueryTime = (new Long JavaDoc(sum)).intValue();
357         }
358     }
359
360     /**
361      * Returns average time needed for executing oid query.
362      * Query by oid is query which "where" clause contains request for DO with
363      * specified oid.
364      *
365      * @return Average time needed for executing oid query.
366      */

367     public int getQueryByOIdAverageTime() {
368         return averageQueryByOIdTime;
369     }
370
371     /**
372      * Updates average time for executing OId queries and increments number
373      * of them by paramether <code>no</code>.
374      * Query by oid is query which "where" clause contains request for DO with
375      * specified oid.
376      *
377      * @param newTime New query time in miliseconds for no queries by OId.
378      * @param no Number of queries by OId.
379      */

380     public void updateQueryByOIdAverageTime(int newTime, int no) {
381         if (no > 0) {
382             long sum = 0;
383
384             if (queryByOIdNum > 0) {
385                 sum = (queryByOIdNum) * averageQueryByOIdTime + newTime;
386                 queryByOIdNum += no;
387                 sum = sum / queryByOIdNum;
388                 averageQueryByOIdTime = (new Long JavaDoc(sum)).intValue();
389             } else {
390                 sum = newTime;
391                 queryByOIdNum += no;
392                 sum = sum / queryByOIdNum;
393                 averageQueryByOIdTime = (new Long JavaDoc(sum)).intValue();
394             }
395         }
396     }
397
398     /**
399      * Clears statistics.
400      */

401     public void clears() {
402         insertNum = 0;
403         updateNum = 0;
404         deleteNum = 0;
405         lazyLoadingNum = 0;
406         startTime = new Date JavaDoc();
407         stopTime = new Date JavaDoc();
408         queryNum = 0;
409         queryByOIdNum = 0;
410         averageQueryTime = 0;
411         averageQueryByOIdTime = 0;
412     }
413
414     /**
415      * Clears statistics.
416      */

417     public void clear() {
418         this.clears();
419     }
420
421     /**
422      * Returns query statistics for table without cache.
423      * Since this is table without cache parameter type has no meaning.
424      *
425      * @param type Value 0 (org.enhydra.dods.cache.CacheConstants.DATA_CACHE)
426      * for DO (data object) cache,
427      * value 1 (org.enhydra.dods.cache.CacheConstants.SIMPLE_QUERY_CACHE) for
428      * simple query cache and value 2
429      * (org.enhydra.dods.cache.CacheConstants.COMPLEX_QUERY_CACHE) for complex
430      * query cache.
431      * @return Query statistics table.
432      */

433     public CacheStatistics getCacheStatistics(int type) {
434         return null;
435     }
436 }
437
Popular Tags