Coverage Report - net.admin4j.jdbc.driver.SqlTaskTimer
 
Classes in this File Line Coverage Branch Coverage Complexity
SqlTaskTimer
92%
12/13
75%
3/4
2
 
 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.Collection;
 17  
 
 18  
 import net.admin4j.deps.commons.lang3.Validate;
 19  
 import net.admin4j.entity.ExecutionStack;
 20  
 import net.admin4j.timer.BasicTaskTimer;
 21  
 import net.admin4j.timer.DataMeasure;
 22  
 import net.admin4j.util.Admin4jRuntimeException;
 23  
 
 24  
 /**
 25  
  * Times SQL Statement executions.
 26  
  * @author D. Ashmore
 27  
  * @since 1.0.1
 28  
  */
 29  
 public class SqlTaskTimer extends BasicTaskTimer {
 30  
     
 31  
     private static final long serialVersionUID = -1731339518240664632L;
 32  36
     private ThreadLocal<ExecutionStack> executionStack = new ThreadLocal<ExecutionStack>();
 33  
     private DriverContext driverContext;
 34  
 
 35  
     public SqlTaskTimer(String sqlText
 36  
             , Collection<DataMeasure> dataMeasures
 37  
             , DriverContext driverContext
 38  
             , ExecutionStack executionStack) {
 39  36
         super(sqlText, dataMeasures);
 40  
         Validate.notNull(executionStack, "Null executionstack not allowed.");
 41  
         Validate.notNull(driverContext, "Null driverContext not allowed.");
 42  36
         this.executionStack.set(executionStack);
 43  36
         this.driverContext = driverContext;
 44  36
     }
 45  
 
 46  
     /* (non-Javadoc)
 47  
      * @see net.admin4j.timer.BasicTaskTimer#stop()
 48  
      */
 49  
     @Override
 50  
     public void stop() {
 51  180138
         Long bTime = this.getBeginTime();
 52  180138
         if (bTime == null) {
 53  0
             throw new Admin4jRuntimeException("Can't call stop() on a timer that hasn't been started.");            
 54  
         }
 55  
         
 56  180138
         Long timing = System.currentTimeMillis() - bTime;
 57  180138
         for (DataMeasure measure: this.getDataMeasures()) {
 58  180138
             ((SqlStatementSummaryDataMeasure)measure).addNumber(timing, executionStack.get());
 59  
         }
 60  180138
     }
 61  
 
 62  
     public DriverContext getDriverContext() {
 63  49
         return driverContext;
 64  
     }
 65  
 
 66  
 }