| 1 | /** |
| 2 | * Copyright (C) 2006 NetMind Consulting Bt. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
| 19 | package hu.netmind.beankeeper.transaction; |
| 20 | |
| 21 | /** |
| 22 | * Keeps statistics of database usage in the transaction.<br> |
| 23 | * Note: Operations are thread-safe. |
| 24 | * @author Brautigam Robert |
| 25 | * @version Revision: $Revision$ |
| 26 | */ |
| 27 | public class TransactionStatistics |
| 28 | { |
| 29 | private int updateCount; |
| 30 | private int insertCount; |
| 31 | private int selectCount; |
| 32 | private int deleteCount; |
| 33 | private int schemaCount; |
| 34 | |
| 35 | private long updateTime; |
| 36 | private long insertTime; |
| 37 | private long selectTime; |
| 38 | private long deleteTime; |
| 39 | private long schemaTime; |
| 40 | |
| 41 | public TransactionStatistics() |
| 42 | { |
| 43 | reset(); |
| 44 | } |
| 45 | |
| 46 | public TransactionStatistics(int updateCount, int insertCount, |
| 47 | int selectCount, int deleteCount, int schemaCount) |
| 48 | { |
| 49 | this.updateCount=updateCount; |
| 50 | this.insertCount=insertCount; |
| 51 | this.selectCount=selectCount; |
| 52 | this.deleteCount=deleteCount; |
| 53 | this.schemaCount=schemaCount; |
| 54 | } |
| 55 | |
| 56 | public synchronized void add(TransactionStatistics stats) |
| 57 | { |
| 58 | this.updateCount+=stats.updateCount; |
| 59 | this.insertCount+=stats.insertCount; |
| 60 | this.selectCount+=stats.selectCount; |
| 61 | this.deleteCount+=stats.deleteCount; |
| 62 | this.schemaCount+=stats.schemaCount; |
| 63 | this.updateTime+=stats.updateTime; |
| 64 | this.insertTime+=stats.insertTime; |
| 65 | this.selectTime+=stats.selectTime; |
| 66 | this.deleteTime+=stats.deleteTime; |
| 67 | this.schemaTime+=stats.schemaTime; |
| 68 | } |
| 69 | |
| 70 | public synchronized void substract(TransactionStatistics stats) |
| 71 | { |
| 72 | this.updateCount-=stats.updateCount; |
| 73 | this.insertCount-=stats.insertCount; |
| 74 | this.selectCount-=stats.selectCount; |
| 75 | this.deleteCount-=stats.deleteCount; |
| 76 | this.schemaCount-=stats.schemaCount; |
| 77 | this.updateTime-=stats.updateTime; |
| 78 | this.insertTime-=stats.insertTime; |
| 79 | this.selectTime-=stats.selectTime; |
| 80 | this.deleteTime-=stats.deleteTime; |
| 81 | this.schemaTime-=stats.schemaTime; |
| 82 | } |
| 83 | |
| 84 | public synchronized void reset() |
| 85 | { |
| 86 | updateCount=0; |
| 87 | insertCount=0; |
| 88 | selectCount=0; |
| 89 | deleteCount=0; |
| 90 | schemaCount=0; |
| 91 | } |
| 92 | |
| 93 | public int getTotalCount() |
| 94 | { |
| 95 | return getUpdateCount()+getInsertCount()+getSelectCount()+ |
| 96 | getDeleteCount()+getSchemaCount(); |
| 97 | } |
| 98 | |
| 99 | public int getUpdateCount() |
| 100 | { |
| 101 | return updateCount; |
| 102 | } |
| 103 | public void setUpdateCount(int updateCount) |
| 104 | { |
| 105 | this.updateCount=updateCount; |
| 106 | } |
| 107 | |
| 108 | public int getInsertCount() |
| 109 | { |
| 110 | return insertCount; |
| 111 | } |
| 112 | public void setInsertCount(int insertCount) |
| 113 | { |
| 114 | this.insertCount=insertCount; |
| 115 | } |
| 116 | |
| 117 | public int getSelectCount() |
| 118 | { |
| 119 | return selectCount; |
| 120 | } |
| 121 | public void setSelectCount(int selectCount) |
| 122 | { |
| 123 | this.selectCount=selectCount; |
| 124 | } |
| 125 | |
| 126 | public int getDeleteCount() |
| 127 | { |
| 128 | return deleteCount; |
| 129 | } |
| 130 | public void setDeleteCount(int deleteCount) |
| 131 | { |
| 132 | this.deleteCount=deleteCount; |
| 133 | } |
| 134 | |
| 135 | public int getSchemaCount() |
| 136 | { |
| 137 | return schemaCount; |
| 138 | } |
| 139 | public void setSchemaCount(int schemaCount) |
| 140 | { |
| 141 | this.schemaCount=schemaCount; |
| 142 | } |
| 143 | |
| 144 | public long getUpdateTime() |
| 145 | { |
| 146 | return updateTime; |
| 147 | } |
| 148 | public void setUpdateTime(long updateTime) |
| 149 | { |
| 150 | this.updateTime=updateTime; |
| 151 | } |
| 152 | |
| 153 | public long getInsertTime() |
| 154 | { |
| 155 | return insertTime; |
| 156 | } |
| 157 | public void setInsertTime(long insertTime) |
| 158 | { |
| 159 | this.insertTime=insertTime; |
| 160 | } |
| 161 | |
| 162 | public long getSelectTime() |
| 163 | { |
| 164 | return selectTime; |
| 165 | } |
| 166 | public void setSelectTime(long selectTime) |
| 167 | { |
| 168 | this.selectTime=selectTime; |
| 169 | } |
| 170 | |
| 171 | public long getDeleteTime() |
| 172 | { |
| 173 | return deleteTime; |
| 174 | } |
| 175 | public void setDeleteTime(long deleteTime) |
| 176 | { |
| 177 | this.deleteTime=deleteTime; |
| 178 | } |
| 179 | |
| 180 | public long getSchemaTime() |
| 181 | { |
| 182 | return schemaTime; |
| 183 | } |
| 184 | public void setSchemaTime(long schemaTime) |
| 185 | { |
| 186 | this.schemaTime=schemaTime; |
| 187 | } |
| 188 | |
| 189 | public String toString() |
| 190 | { |
| 191 | return "[Stats: U:"+updateCount+" I:"+insertCount+" D:"+deleteCount+" T:"+schemaCount+" S:"+selectCount+"]"; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | |