Coverage Report - net.admin4j.jdbc.driver.SqlStatementTimerFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
SqlStatementTimerFactory
82%
14/17
100%
2/2
1.4
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.jdbc.driver;
 15  
 
 16  
 import java.util.ArrayList;
 17  
 import java.util.List;
 18  
 import java.util.Map;
 19  
 import java.util.Set;
 20  
 
 21  
 import net.admin4j.entity.ExecutionStack;
 22  
 import net.admin4j.timer.DataMeasure;
 23  
 import net.admin4j.timer.TaskTimer;
 24  
 import net.admin4j.vo.DataMeasurementSummaryVO;
 25  
 
 26  
 /**
 27  
  * Tracks SQL Statement timers that have been issued.
 28  
  * @author D. Ashmore
 29  
  * @since 1.0.1
 30  
  */
 31  0
 public class SqlStatementTimerFactory {
 32  
     
 33  
     public static TaskTimer start(String sqlText, DriverContext driverContext, StackTraceElement[] executionStack) {
 34  180138
         return start(sqlText, driverContext, new ExecutionStack(executionStack));
 35  
     }
 36  
     
 37  
     public static TaskTimer start(String sqlText, DriverContext driverContext, ExecutionStack executionStack) {
 38  180138
         String key = deriveKey(sqlText, driverContext);
 39  180138
         SqlTaskTimer timer = SqlStatementTimerRegistry.findTaskTimer(key);
 40  180138
         if (timer != null)  {
 41  180102
             timer.start();
 42  180102
             return timer;
 43  
         }
 44  
         
 45  36
         List<DataMeasure> list = new ArrayList<DataMeasure>();
 46  36
         list.add(new SqlStatementSummaryDataMeasure(System.currentTimeMillis(), executionStack));
 47  36
         timer = new SqlTaskTimer(key, list, driverContext, executionStack);
 48  36
         SqlStatementTimerRegistry.register(timer);
 49  
         
 50  36
         timer.start();
 51  36
         return timer;
 52  
     }
 53  
     
 54  
     public static Map<String,Set<DataMeasurementSummaryVO>> getDataSummaryMap() {
 55  12
         return SqlStatementTimerRegistry.getDataSummaryMap();
 56  
     }
 57  
     
 58  
     public void clearAll() {
 59  0
         SqlStatementTimerRegistry.clearAll();
 60  0
     }
 61  
     
 62  
     private static String deriveKey(String sqlText, DriverContext driverContext) {
 63  180138
         return driverContext + "-" + sqlText;
 64  
     }
 65  
 
 66  
 }