Map itemMap = (Map) report.getStats().get(TxReport.SqlStats.NAME);
if(itemMap != null)
{
for(Iterator items = itemMap.values().iterator(); items.hasNext();)
{
StatisticalItem item = (StatisticalItem) items.next();
String sql = item.getValue().toLowerCase();
SqlStats sqlStats = (SqlStats)sqls.get(sql);
if(sqlStats == null)
{
sqlStats = new SqlStats(sql);
sqls.put(sql, sqlStats);
}
sqlStats.total += item.getCount();
if(sql.startsWith("select "))
{
int fromStart = sql.indexOf("from ");
if(fromStart == -1)
{
throw new IllegalStateException("FROM not found in: " + sql);
}
String table = sql.substring(fromStart + "from ".length());
int tableEnd = table.indexOf(' ');
if(tableEnd != -1)
{
table = table.substring(0, tableEnd);
}
TableStats tableStats = (TableStats) tables.get(table);
if(tableStats == null)
{
tableStats = new TableStats(table);
tables.put(table, tableStats);
}
tableStats.selects += item.getCount();
}
else if(sql.startsWith("update "))
{
String table = sql.substring("update ".length());
int tableEnd = table.indexOf(' ');
if(tableEnd == -1)
{
throw new IllegalStateException("Could not find end of the table name: " + sql);
}
table = table.substring(0, tableEnd);
TableStats tableStats = (TableStats) tables.get(table);
if(tableStats == null)
{
tableStats = new TableStats(table);
tables.put(table, tableStats);
}
tableStats.updates += item.getCount();
}
else if(sql.startsWith("insert into "))
{
String table = sql.substring("insert into ".length());
int tableEnd = table.indexOf('(');
if(tableEnd == -1)
{
throw new IllegalStateException("Could not find end of the table name: " + sql);
}
table = table.substring(0, tableEnd).trim();
TableStats tableStats = (TableStats) tables.get(table);
if(tableStats == null)
{
tableStats = new TableStats(table);
tables.put(table, tableStats);
}
tableStats.inserts += item.getCount();
}
else if(sql.startsWith("delete from "))
{
String table = sql.substring("delete from ".length());
int tableEnd = table.indexOf(' ');
if(tableEnd == -1)
{
throw new IllegalStateException("Could not find end of the table name: " + sql);
}
table = table.substring(0, tableEnd);
TableStats tableStats = (TableStats) tables.get(table);
if(tableStats == null)
{
tableStats = new TableStats(table);
tables.put(table, tableStats);
}
tableStats.deletes += item.getCount();
}
else
{
throw new IllegalStateException("Unrecognized sql statement: " + sql);
}