001: /**
002: * Copyright (C) 2006 NetMind Consulting Bt.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 3 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package hu.netmind.persistence;
018:
019: /**
020: * Keeps statistics of database usage.<br>
021: * Note: It is thread-safe.
022: * @author Brautigam Robert
023: * @version Revision: $Revision$
024: */
025: public class DatabaseStatistics {
026: private int updateCount;
027: private int insertCount;
028: private int selectCount;
029: private int deleteCount;
030: private int schemaCount;
031:
032: private long updateTime;
033: private long insertTime;
034: private long selectTime;
035: private long deleteTime;
036: private long schemaTime;
037:
038: public DatabaseStatistics() {
039: reset();
040: }
041:
042: public DatabaseStatistics(int updateCount, int insertCount,
043: int selectCount, int deleteCount, int schemaCount) {
044: this .updateCount = updateCount;
045: this .insertCount = insertCount;
046: this .selectCount = selectCount;
047: this .deleteCount = deleteCount;
048: this .schemaCount = schemaCount;
049: }
050:
051: public synchronized void add(DatabaseStatistics stats) {
052: this .updateCount += stats.updateCount;
053: this .insertCount += stats.insertCount;
054: this .selectCount += stats.selectCount;
055: this .deleteCount += stats.deleteCount;
056: this .schemaCount += stats.schemaCount;
057: this .updateTime += stats.updateTime;
058: this .insertTime += stats.insertTime;
059: this .selectTime += stats.selectTime;
060: this .deleteTime += stats.deleteTime;
061: this .schemaTime += stats.schemaTime;
062: }
063:
064: public synchronized void reset() {
065: updateCount = 0;
066: insertCount = 0;
067: selectCount = 0;
068: deleteCount = 0;
069: schemaCount = 0;
070: }
071:
072: public int getUpdateCount() {
073: return updateCount;
074: }
075:
076: public void setUpdateCount(int updateCount) {
077: this .updateCount = updateCount;
078: }
079:
080: public int getInsertCount() {
081: return insertCount;
082: }
083:
084: public void setInsertCount(int insertCount) {
085: this .insertCount = insertCount;
086: }
087:
088: public int getSelectCount() {
089: return selectCount;
090: }
091:
092: public void setSelectCount(int selectCount) {
093: this .selectCount = selectCount;
094: }
095:
096: public int getDeleteCount() {
097: return deleteCount;
098: }
099:
100: public void setDeleteCount(int deleteCount) {
101: this .deleteCount = deleteCount;
102: }
103:
104: public int getSchemaCount() {
105: return schemaCount;
106: }
107:
108: public void setSchemaCount(int schemaCount) {
109: this .schemaCount = schemaCount;
110: }
111:
112: public long getUpdateTime() {
113: return updateTime;
114: }
115:
116: public void setUpdateTime(long updateTime) {
117: this .updateTime = updateTime;
118: }
119:
120: public long getInsertTime() {
121: return insertTime;
122: }
123:
124: public void setInsertTime(long insertTime) {
125: this .insertTime = insertTime;
126: }
127:
128: public long getSelectTime() {
129: return selectTime;
130: }
131:
132: public void setSelectTime(long selectTime) {
133: this .selectTime = selectTime;
134: }
135:
136: public long getDeleteTime() {
137: return deleteTime;
138: }
139:
140: public void setDeleteTime(long deleteTime) {
141: this .deleteTime = deleteTime;
142: }
143:
144: public long getSchemaTime() {
145: return schemaTime;
146: }
147:
148: public void setSchemaTime(long schemaTime) {
149: this .schemaTime = schemaTime;
150: }
151:
152: public String toString() {
153: return "[Stats: U:" + updateCount + " I:" + insertCount + " D:"
154: + deleteCount + " T:" + schemaCount + " S:"
155: + selectCount + "]";
156: }
157: }
|