{
tableName = "PAGE_STATISTICS";
groupColumn = "PAGE";
} else
{
throw new InvalidCriteriaException(
" invalid queryType passed to queryStatistics");
}
String orderColumn = "itemcount";
String ascDesc = "DESC";
if (!PortalStatistics.QUERY_TYPE_USER.equals(queryType))
{
query1 = "select count(*) as itemcount , MIN(ELAPSED_TIME) as amin ,AVG(ELAPSED_TIME) as aavg ,MAX(ELAPSED_TIME) as amax from "
+ tableName + " where time_stamp > ? and time_stamp < ?";
query2 = "select count(*) as itemcount ,"
+ groupColumn
+ ", MIN(ELAPSED_TIME) as amin ,AVG(ELAPSED_TIME) as aavg ,MAX(ELAPSED_TIME) as amax "
+ "from " + tableName
+ " where time_stamp > ? and time_stamp < ? group by "
+ groupColumn + " order by " + orderColumn + " " + ascDesc;
} else
{
query1 = "select count(*) as itemcount , MIN(ELAPSED_TIME) as amin,AVG(ELAPSED_TIME) as aavg ,MAX(ELAPSED_TIME) as amax from "
+ tableName
+ " where time_stamp > ? and time_stamp < ? and status = 2";
query2 = "select count(*) as itemcount ,"
+ groupColumn
+ ", MIN(ELAPSED_TIME) as amin ,AVG(ELAPSED_TIME) as aavg ,MAX(ELAPSED_TIME) as amax "
+ "from "
+ tableName
+ " where time_stamp > ? and time_stamp < ? and status = 2 group by "
+ groupColumn + " order by " + orderColumn + " " + ascDesc;
}
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
con = ds.getConnection();
// query 1
pstmt = con.prepareStatement(query1);
pstmt.setTimestamp(1, new Timestamp(start.getTime()));
pstmt.setTimestamp(2, new Timestamp(end.getTime()));
rs = pstmt.executeQuery();
float denominator = 1.0f;
if (PortalStatistics.QUERY_TYPE_USER.equals(queryType))
{
denominator = 1000f * 60f; // this should convert from mS to
// minutes
}
if (rs.next())
{
as.setHitCount(rs.getInt("itemcount"));
as.setMinProcessingTime(rs.getFloat("amin") / denominator);
as.setAvgProcessingTime(rs.getFloat("aavg") / denominator);
as.setMaxProcessingTime(rs.getFloat("amax") / denominator);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
// query 2
pstmt = con.prepareStatement(query2);
pstmt.setTimestamp(1, new Timestamp(start.getTime()));
pstmt.setTimestamp(2, new Timestamp(end.getTime()));
rs = pstmt.executeQuery();
int rowCount = 0;
int totalRows = 5;
String listsizeStr = criteria.getListsize();
int temp = -1;
try
{
temp = Integer.parseInt(listsizeStr);
}
catch (NumberFormatException e)
{
}
if(temp != -1) {
totalRows = temp;
}
while ((rs.next()) && (rowCount < totalRows))
{
Map row = new HashMap();
row.put("count", "" + rs.getInt("itemcount"));
String col = rs.getString(groupColumn);
int maxColLen = 35;
if (col != null)
{
if (col.length() > maxColLen)
{
col = col.substring(0, maxColLen);
}
}
row.put("groupColumn", col);
row.put("min", ""
+ floatFormatter(rs.getFloat("amin") / denominator));
row.put("avg", ""
+ floatFormatter(rs.getFloat("aavg") / denominator));
row.put("max", ""
+ floatFormatter(rs.getFloat("amax") / denominator));
as.addRow(row);
rowCount++;
}
}
catch (SQLException e)
{
throw new InvalidCriteriaException(e.toString());
}
finally
{
if(rs != null)
{