001 /*
002 @license.text@
003 */
004 package biz.hammurapi.sql;
005
006 import java.sql.SQLException;
007
008 import biz.hammurapi.metrics.MeasurementCategory;
009 import biz.hammurapi.metrics.MeasurementCategoryFactory;
010 import biz.hammurapi.metrics.TimeIntervalCategory;
011
012 /**
013 * Collects operation metrics for load, insert, update, delete.
014 * @author Pavel Vlasov
015 * @revision $Revision$
016 */
017 public class MeasuringDatabaseObject extends DatabaseObject {
018 protected TimeIntervalCategory timeIntervalCategory=MeasurementCategoryFactory.getTimeIntervalCategory(getClass());
019 protected MeasurementCategory measurementCategory=MeasurementCategoryFactory.getCategory(getClass());
020
021 public int delete(SQLProcessor processor, String tableName) throws SQLException {
022 long start=timeIntervalCategory.getTime();
023 try {
024 return super.delete(processor, tableName);
025 } finally {
026 timeIntervalCategory.addInterval("delete", start);
027 }
028 }
029
030 public int insert(SQLProcessor processor, String tableName) throws SQLException {
031 long start=timeIntervalCategory.getTime();
032 try {
033 return super.insert(processor, tableName);
034 } finally {
035 timeIntervalCategory.addInterval("insert", start);
036 }
037 }
038
039 public int update(SQLProcessor processor, String tableName) throws SQLException {
040 long start=timeIntervalCategory.getTime();
041 try {
042 return super.update(processor, tableName);
043 } finally {
044 timeIntervalCategory.addInterval("update", start);
045 }
046 }
047
048 public MeasuringDatabaseObject() {
049 super();
050 measurementCategory.addMeasurement("new", 0, 0);
051 }
052
053 public MeasuringDatabaseObject(boolean force) {
054 super(force);
055 measurementCategory.addMeasurement("new", 0, 0);
056 }
057 }