Author: indika
Date: Sun Dec 2 20:42:39 2007
New Revision: 10384
Modified:
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/statistics/persistence/StatisticsDBUtils.java
Log:
fixed ESBJAVA-364
Modified:
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/statistics/persistence/StatisticsDBUtils.java
==============================================================================
---
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/statistics/persistence/StatisticsDBUtils.java
(original)
+++
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/statistics/persistence/StatisticsDBUtils.java
Sun Dec 2 20:42:39 2007
@@ -36,8 +36,8 @@
private static final String DIRECTION_ = "direction";
private static StatisticsDO createStatisticsRecord(
- String serverId, int statisticsCategory,
- String key, int direction, Statistics statistics) {
+ String serverId, int statisticsCategory,
+ String key, int direction, Statistics statistics) {
StatisticsDO statisticsDO = new StatisticsDO();
statisticsDO.setName(key);
@@ -48,7 +48,8 @@
statisticsDO.setMinTime(statistics.getMinProcessingTime());
statisticsDO.setFaultCount(statistics.getFaultCount());
statisticsDO.setTotalCount(statistics.getCount());
- statisticsDO.setAvgTime(statistics.getAvgProcessingTime());
+ statisticsDO.setAvgTime((
+ Math.round(statistics.getAvgProcessingTime() * 100.0) / 100.0));
return statisticsDO;
}
@@ -67,11 +68,11 @@
int statisticsCategory = statisticsHolder.getStatisticsCategory();
if (statisticsHolder.getInFlowStatistics() != null) {
pm.addStatisticsRecord(createStatisticsRecord(
- serverId, statisticsCategory, key, 0,
statisticsHolder.getInFlowStatistics()));
+ serverId, statisticsCategory, key, 0,
statisticsHolder.getInFlowStatistics()));
}
if (statisticsHolder.getOutFlowStatistics() != null) {
pm.addStatisticsRecord(createStatisticsRecord(
- serverId, statisticsCategory, key, 1,
statisticsHolder.getOutFlowStatistics()));
+ serverId, statisticsCategory, key, 1,
statisticsHolder.getOutFlowStatistics()));
}
}
@@ -90,11 +91,11 @@
int statisticsCategory = statisticsHolder.getStatisticsCategory();
if (statisticsHolder.getInFlowStatistics() != null) {
updateRecord(pm, serverId, statisticsCategory,
- key, 0, statisticsHolder.getInFlowStatistics());
+ key, 0, statisticsHolder.getInFlowStatistics());
}
if (statisticsHolder.getOutFlowStatistics() != null) {
updateRecord(pm, serverId, statisticsCategory,
- key, 1, statisticsHolder.getOutFlowStatistics());
+ key, 1, statisticsHolder.getOutFlowStatistics());
}
}
@@ -114,9 +115,9 @@
int direction, Statistics statistics) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
- " where " + SERVER_ID_ + "= '" + serverId + "' and " +
- CATEGORY_ + "=" + statisticsCategory + " and " + NAME_ + "= '"
+ key +
- "' and " + DIRECTION_ + " = " + direction + "";
+ " where " + SERVER_ID_ + "= '" + serverId + "' and " +
+ CATEGORY_ + "=" + statisticsCategory + " and " + NAME_ + "= '" +
key +
+ "' and " + DIRECTION_ + " = " + direction + "";
int currentTotalCount = statistics.getCount();
int currentFaultCount = statistics.getFaultCount();
@@ -146,7 +147,7 @@
if (updatedTotalCount != 0) {
updatedFaultCount = currentFaultCount + previousFaultCount;
updatedAvgTime = (currentAvgTime * currentTotalCount +
- previousAvgTime * previousTotalCount) /
updatedTotalCount;
+ previousAvgTime * previousTotalCount) / updatedTotalCount;
if (currentMaxTime > previousMaxTime) {
updatedMaxTime = currentMaxTime;
} else {
@@ -161,13 +162,13 @@
previousDO.setTotalCount(updatedTotalCount);
previousDO.setMaxTime(updatedMaxTime);
previousDO.setMinTime(updatedMinTime);
- previousDO.setAvgTime(updatedAvgTime);
+ previousDO.setAvgTime(Math.round(updatedAvgTime * 100.0) /
100.0);
pm.updateStatisticsRecord(previousDO);
}
} else if (resultSet == null || resultSet.length == 0) {
previousDO = createStatisticsRecord(
- serverId, statisticsCategory, key, direction, statistics);
+ serverId, statisticsCategory, key, direction, statistics);
pm.addStatisticsRecord(previousDO);
}
}
@@ -176,16 +177,16 @@
public static StatisticsDO[] getStatistics(PersistenceManager pm, String
serverid) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO +
- " where " + SERVER_ID_ + " = '" + serverid + "'";
+ " where " + SERVER_ID_ + " = '" + serverid + "'";
return pm.selectStatisticsRecords(queryString);
}
public static StatisticsDO[] getStatistics(
- PersistenceManager pm, String serverid, int direction) {
+ PersistenceManager pm, String serverid, int direction) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO +
- " where " + SERVER_ID_ + " = '" + serverid +
- "' and " + DIRECTION_ + " = " + direction + "";
+ " where " + SERVER_ID_ + " = '" + serverid +
+ "' and " + DIRECTION_ + " = " + direction + "";
return pm.selectStatisticsRecords(queryString);
}
@@ -193,16 +194,16 @@
int direction, int category) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " + " where " +
- SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + "= " +
category + " and " +
- DIRECTION_ + " = " + direction + "";
+ SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + "= " +
category + " and " +
+ DIRECTION_ + " = " + direction + "";
return pm.selectStatisticsRecords(queryString);
}
public static StatisticsDO[] getTotalStatisticsForServer(
- PersistenceManager pm, String serverid) {
+ PersistenceManager pm, String serverid) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
- " where " + SERVER_ID_ + " = '" + serverid + "'";
+ " where " + SERVER_ID_ + " = '" + serverid + "'";
return pm.selectStatisticsRecords(queryString);
}
@@ -211,8 +212,8 @@
int category, String name) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " + " where " +
- SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + "= " +
category + " and " +
- NAME_ + " = '" + name + "'";
+ SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + "= " +
category + " and " +
+ NAME_ + " = '" + name + "'";
return pm.selectStatisticsRecords(queryString);
}
@@ -220,28 +221,28 @@
int direction, String name) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " + " where " +
- SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + "= " +
category + " and " +
- NAME_ + " = '" + name + "'" + " and " + DIRECTION_ + " = " +
direction + "";
+ SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + "= " +
category + " and " +
+ NAME_ + " = '" + name + "'" + " and " + DIRECTION_ + " = " +
direction + "";
return (StatisticsDO) pm.createAnewObjectFromStatistics(queryString);
}
public static StatisticsDO[] getStatistics(PersistenceManager pm, int
category, String name) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
- " where " + CATEGORY_ + "= " + category +
- " and " + NAME_ + " = '" + name + "'";
+ " where " + CATEGORY_ + "= " + category +
+ " and " + NAME_ + " = '" + name + "'";
return pm.selectStatisticsRecords(queryString);
}
public static StatisticsDO[] getStatistics(PersistenceManager pm, int
category) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
- " where " + CATEGORY_ + "= " + category +
- "";
+ " where " + CATEGORY_ + "= " + category +
+ "";
return pm.selectStatisticsRecords(queryString);
}
public static StatisticsDO[] getStatistics(PersistenceManager pm, int
category, int direction) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " + " where " +
- CATEGORY_ + "= " + category + " and " + DIRECTION_ + " = " +
direction + " ";
+ CATEGORY_ + "= " + category + " and " + DIRECTION_ + " = " +
direction + " ";
return pm.selectStatisticsRecords(queryString);
}
@@ -249,7 +250,7 @@
int category) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " + " where " +
- SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + " = "
+ category + "";
+ SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + " = " +
category + "";
return pm.selectStatisticsRecords(queryString);
}
@@ -257,8 +258,8 @@
int direction, int
category) {
String queryString = "from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " + " where " +
- SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + "= " +
category + " and " +
- DIRECTION_ + " = " + direction + "";
+ SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_ + "= " +
category + " and " +
+ DIRECTION_ + " = " + direction + "";
return pm.selectStatisticsRecords(queryString);
}
@@ -266,41 +267,41 @@
int direction, int
category) {
String queryString = "select sum(totalCount), sum(faultCount),
avg(maxTime), " +
- "avg(minTime), avg(avgTime) from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
- " where " + SERVER_ID_ + " = '" + serverid + "' and " +
CATEGORY_ + "= " +
- category + " and " + DIRECTION_ + " = " + direction + "";
+ "avg(minTime), avg(avgTime) from " +
ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
+ " where " + SERVER_ID_ + " = '" + serverid + "' and " + CATEGORY_
+ "= " +
+ category + " and " + DIRECTION_ + " = " + direction + "";
return pm.createAnewObjectFromStatistics(queryString);
}
public static List getTotalCountForServerS(PersistenceManager pm, int
category) {
String queryString = "select " + SERVER_ID_ + " ,sum(totalCount) from
" +
- ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
- " where " + CATEGORY_ + "= " + category + " group by " +
SERVER_ID_ + " ";
+ ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
+ " where " + CATEGORY_ + "= " + category + " group by " +
SERVER_ID_ + " ";
return pm.selectCustomObjectList(queryString);
}
public static Object getServersIds(PersistenceManager pm) {
String queryString = "select distinct " + SERVER_ID_ + " from " +
- ServiceBusConstants.DBAccess.STATISTICS_DO + " ";
+ ServiceBusConstants.DBAccess.STATISTICS_DO + " ";
return pm.selectCustomObjectList(queryString);
}
public static Object getUniqueNames(PersistenceManager pm, int category) {
String queryString = "select distinct " + NAME_ + " from " +
- ServiceBusConstants.DBAccess.STATISTICS_DO + " where " +
CATEGORY_ + "= " + category + " ";
+ ServiceBusConstants.DBAccess.STATISTICS_DO + " where " + CATEGORY_
+ "= " + category + " ";
return pm.selectCustomObjectList(queryString);
}
public static List getTotalCountForCategory(PersistenceManager pm, int
category) {
String queryString = "select " + NAME_ + ",sum(totalCount) from " +
- ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
- " where " + CATEGORY_ + "= " + category + " group by " + NAME_
+ " ";
+ ServiceBusConstants.DBAccess.STATISTICS_DO + " " +
+ " where " + CATEGORY_ + "= " + category + " group by " + NAME_ + "
";
return pm.selectCustomObjectList(queryString);
}
- public static int clearAll(PersistenceManager pm){
- String queryString = "DELETE " +
ServiceBusConstants.DBAccess.STATISTICS_DO;
- return pm.clearAll(queryString);
- }
+ public static int clearAll(PersistenceManager pm) {
+ String queryString = "DELETE " +
ServiceBusConstants.DBAccess.STATISTICS_DO;
+ return pm.clearAll(queryString);
+ }
}
_______________________________________________
Esb-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev