Coverage report

  %line %branch
net.sf.infrared.web.util.PerformanceDataSnapshot
0% 
0% 

 1  
 /*
 2  
  *
 3  
  * Copyright 2005 Tavant Technologies and Contributors
 4  
  * 
 5  
  * Licensed under the Apache License, Version 2.0 (the "License")
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  *
 17  
  *
 18  
  *
 19  
  * Original Author:  prashant.nair (Tavant Technologies)
 20  
  * Contributor(s):   -;
 21  
  *
 22  
  */
 23  
 package net.sf.infrared.web.util;
 24  
 
 25  
 import java.util.HashMap;
 26  
 import java.util.Map;
 27  
 import java.util.Set;
 28  
 
 29  
 import net.sf.infrared.aspects.jdbc.SqlExecuteContext;
 30  
 import net.sf.infrared.aspects.jdbc.SqlPrepareContext;
 31  
 import net.sf.infrared.base.model.AggregateExecutionTime;
 32  
 import net.sf.infrared.base.model.ApplicationStatistics;
 33  
 import net.sf.infrared.base.model.ExecutionContext;
 34  
 import net.sf.infrared.base.model.StatisticsSnapshot;
 35  
 
 36  0
 public class PerformanceDataSnapshot {
 37  
     
 38  
     //[BINIL] private ApplicationStatistics stats;
 39  
     private StatisticsSnapshot stats;    
 40  
     private Set applicationNames;
 41  
     private Set instanceNames;
 42  
     
 43  
     public Set getApplicationNames() {
 44  0
         return applicationNames;
 45  
     }
 46  
     public void setApplicationNames(Set applicationNames) {
 47  0
         this.applicationNames = applicationNames;
 48  0
     }
 49  
     public Set getInstanceNames() {
 50  0
         return instanceNames;
 51  
     }
 52  
     public void setInstanceNames(Set instanceNames) {
 53  0
         this.instanceNames = instanceNames;
 54  0
     }
 55  
     //[BINIL] public ApplicationStatistics getStats() {
 56  
     public StatisticsSnapshot getStats() {
 57  0
         return stats;
 58  
     }
 59  
     
 60  
     public void setStats(StatisticsSnapshot stats) {
 61  0
         this.stats = stats;
 62  0
     }
 63  
     
 64  
     public SqlStatistics[] getSqlStatistics(){
 65  0
         Map sqlStatsMap = new HashMap();
 66  
         SqlStatistics sqlStats;
 67  0
         String[] layers = stats.getHierarchicalLayers();
 68  0
         for (int i = 0; i < layers.length; i++) {
 69  0
             String layer = layers[i];
 70  0
             if (! layer.endsWith("SQL")) {
 71  0
                 continue;    
 72  
             }
 73  0
             AggregateExecutionTime[] sqlTimes = stats.getExecutionsInHierarchicalLayer(layer);
 74  0
             for (int j = 0; j < sqlTimes.length; j++) {
 75  0
                 AggregateExecutionTime aet = (AggregateExecutionTime) sqlTimes[j];
 76  0
                 ExecutionContext ctx = aet.getContext();
 77  
             
 78  0
                 if (ctx instanceof SqlPrepareContext) {
 79  0
                     String sql = ctx.getName();
 80  0
                     sqlStats = getSqlStatsFromMap(sqlStatsMap, sql);
 81  0
                     sqlStats.mergePrepareTime(aet);
 82  0
                 } else if(ctx instanceof SqlExecuteContext) {
 83  0
                     String sql = ctx.getName();
 84  0
                     sqlStats = getSqlStatsFromMap(sqlStatsMap, sql);
 85  0
                     sqlStats.mergeExecuteTime(aet);
 86  
                 }
 87  
             }
 88  
         }
 89  0
         return (SqlStatistics[]) sqlStatsMap.values().toArray(new SqlStatistics[0]);
 90  
     }
 91  
     
 92  
     public SqlStatistics[] getSqlStatisticsForLayer(String layer, String layerType){
 93  
 
 94  0
         Map sqlStatsMap = new HashMap();
 95  
         SqlStatistics sqlStats;
 96  0
         AggregateExecutionTime[] sqlTimes = null;
 97  0
         if(layerType.equals("hier")){
 98  0
             sqlTimes = stats.getExecutionsInHierarchicalLayer(layer); 
 99  
         }
 100  0
         else if(layerType.equals("abs")){
 101  0
             sqlTimes = stats.getExecutionsInAbsoluteLayer(layer);
 102  
         }
 103  
 
 104  0
         for (int j = 0; j < sqlTimes.length; j++) {
 105  0
             AggregateExecutionTime aet = (AggregateExecutionTime) sqlTimes[j];
 106  0
             ExecutionContext ctx = aet.getContext();
 107  
         
 108  0
             if (ctx instanceof SqlPrepareContext) {
 109  0
                 String sql = ctx.getName();
 110  0
                 sqlStats = getSqlStatsFromMap(sqlStatsMap, sql);
 111  0
                 sqlStats.mergePrepareTime(aet);
 112  
             } 
 113  0
             else if(ctx instanceof SqlExecuteContext) {
 114  0
                 String sql = ctx.getName();
 115  0
                 sqlStats = getSqlStatsFromMap(sqlStatsMap, sql);
 116  0
                 sqlStats.mergeExecuteTime(aet);
 117  
             }
 118  
         }
 119  0
         return (SqlStatistics[]) sqlStatsMap.values().toArray(new SqlStatistics[0]);
 120  
     }
 121  
 
 122  
     public SqlStatistics getSqlStatsFromMap(Map sqlStatsMap, String sql){
 123  
         SqlStatistics stats;
 124  0
         if(sqlStatsMap.get(sql) == null){
 125  0
             stats = new SqlStatistics();
 126  0
             sqlStatsMap.put(sql, stats);
 127  
         }
 128  
         else{
 129  0
             stats = (SqlStatistics)sqlStatsMap.get(sql);
 130  
         }        
 131  0
         return stats;        
 132  
     }    
 133  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.