Coverage report

  %line %branch
net.sf.infrared.aspects.jdbc.p6spy.InfraREDP6Connection
0% 
0% 

 1  
 /* 
 2  
  * Copyright 2005 Tavant Technologies and Contributors
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License")
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  * 
 16  
  *
 17  
  *
 18  
  * Original Author:  kamal.govindraj (Tavant Technologies)
 19  
  * Contributor(s):   prashant.nair, binil.thomas;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.aspects.jdbc.p6spy;
 23  
 
 24  
 import java.sql.CallableStatement;
 25  
 import java.sql.Connection;
 26  
 import java.sql.PreparedStatement;
 27  
 import java.sql.SQLException;
 28  
 
 29  
 import net.sf.infrared.agent.MonitorFactory;
 30  
 import net.sf.infrared.agent.StatisticsCollector;
 31  
 import net.sf.infrared.aspects.api.ApiContext;
 32  
 import net.sf.infrared.aspects.jdbc.SqlPrepareContext;
 33  
 import net.sf.infrared.base.model.ExecutionTimer;
 34  
 
 35  
 import com.p6spy.engine.spy.P6Connection;
 36  
 
 37  
 /**
 38  
  * Wrapper over {@link com.p6spy.engine.spy.P6Connection}. Intercepts
 39  
  * com.p6spy.engine.spy.P6Connection methods for monitoring.
 40  
  * 
 41  
  * @author kamal.govindraj
 42  
  * @author prashant.nair
 43  
  * @author binil.thomas
 44  
  */
 45  
 public class InfraREDP6Connection extends P6Connection {
 46  
     private InfraREDP6Factory factory;
 47  
 
 48  
     public InfraREDP6Connection(InfraREDP6Factory infraP6Factory, Connection conn)
 49  
             throws SQLException {
 50  0
         super(infraP6Factory, conn);
 51  0
         this.factory = infraP6Factory;
 52  0
     }
 53  
 
 54  
     public PreparedStatement prepareStatement(String sql) throws SQLException {
 55  0
         PreparedStatement pstmt = null;
 56  0
         if (factory.isJDBCMonitoringEnabled()) {
 57  0
             SqlPrepareContext ctx = getPrepareContext(sql);
 58  0
             ExecutionTimer timer = new ExecutionTimer(ctx);
 59  0
             StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer);
 60  
             try {                
 61  0
                 pstmt = super.prepareStatement(sql);
 62  
             } finally {
 63  0
                 MonitorFactory.getFacade().recordExecutionEnd(timer, col);
 64  0
             }
 65  
         } else {
 66  0
             pstmt = super.prepareStatement(sql);
 67  
         }
 68  0
         return pstmt;
 69  
     }
 70  
 
 71  
     public PreparedStatement prepareStatement(String sql, int p1, class="keyword">int p2) throws SQLException {
 72  0
         PreparedStatement pstmt = null;
 73  0
         if (factory.isJDBCMonitoringEnabled()) {
 74  0
             SqlPrepareContext ctx = getPrepareContext(sql);
 75  0
             ExecutionTimer timer = new ExecutionTimer(ctx);
 76  0
             StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer);
 77  
             try {
 78  0
                 pstmt = super.prepareStatement(sql, p1, p2);
 79  
             } finally {
 80  0
                 MonitorFactory.getFacade().recordExecutionEnd(timer, col);
 81  0
             }
 82  
         } else {
 83  0
             pstmt = super.prepareStatement(sql, p1, p2);
 84  
         }
 85  0
         return pstmt;
 86  
     }
 87  
 
 88  
     public CallableStatement prepareCall(String sql) throws SQLException {
 89  0
         CallableStatement cstmt = null;
 90  0
         if (factory.isJDBCMonitoringEnabled()) {
 91  0
             SqlPrepareContext ctx = getPrepareContext(sql);
 92  0
             ExecutionTimer timer = new ExecutionTimer(ctx);
 93  0
             StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer);
 94  
             try {
 95  0
                 cstmt = super.prepareCall(sql);
 96  
             } finally {
 97  0
                 MonitorFactory.getFacade().recordExecutionEnd(timer, col);
 98  0
             }
 99  
         } else {
 100  0
             cstmt = super.prepareCall(sql);
 101  
         }
 102  
 
 103  0
         return cstmt;
 104  
     }
 105  
 
 106  
     public CallableStatement prepareCall(String sql, int p1, class="keyword">int p2) throws SQLException {
 107  0
         CallableStatement cstmt = null;
 108  0
         if (factory.isJDBCMonitoringEnabled()) {
 109  0
             SqlPrepareContext ctx = getPrepareContext(sql);
 110  0
             ExecutionTimer timer = new ExecutionTimer(ctx);
 111  0
             StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer);
 112  
             try {
 113  0
                 cstmt = super.prepareCall(sql);
 114  
             } finally {
 115  0
                 MonitorFactory.getFacade().recordExecutionEnd(timer, col);
 116  0
             }
 117  
         } else {
 118  0
             cstmt = super.prepareCall(sql);
 119  
         }
 120  0
         return cstmt;
 121  
     }
 122  
 
 123  
     public void commit() throws SQLException {
 124  0
         if (factory.isJDBCMonitoringEnabled()) {
 125  0
             final String methodName = "commit";
 126  0
             ApiContext ctx = new ApiContext(Connection.class.getName(), methodName, "JDBC");
 127  0
             ExecutionTimer timer = new ExecutionTimer(ctx);
 128  0
             StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer);
 129  
             try {
 130  0
                 super.commit();
 131  
             } finally {
 132  0
                 MonitorFactory.getFacade().recordExecutionEnd(timer, col);
 133  0
             }
 134  
         } else {
 135  0
             super.commit();
 136  
         }
 137  0
     }
 138  
 
 139  
     public void rollback() throws SQLException {
 140  0
         if (factory.isJDBCMonitoringEnabled()) {
 141  0
             final String methodName = "rollback";
 142  0
             ApiContext ctx = new ApiContext(Connection.class.getName(), methodName, "JDBC");
 143  0
             ExecutionTimer timer = new ExecutionTimer(ctx);
 144  0
             StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer);
 145  
             try {
 146  0
                 super.rollback();
 147  
             } finally {
 148  0
                 MonitorFactory.getFacade().recordExecutionEnd(timer, col);
 149  0
             }
 150  
         } else {
 151  0
             super.rollback();
 152  
         }
 153  0
     }
 154  
 
 155  
     public void close() throws SQLException {
 156  0
         if (factory.isJDBCMonitoringEnabled()) {
 157  0
             final String methodName = "close";
 158  0
             ApiContext ctx = new ApiContext(Connection.class.getName(), methodName, "JDBC");
 159  0
             ExecutionTimer timer = new ExecutionTimer(ctx);
 160  0
             StatisticsCollector col = MonitorFactory.getFacade().recordExecutionBegin(timer);
 161  
             try {
 162  0
                 super.close();
 163  
             } finally {
 164  0
                 MonitorFactory.getFacade().recordExecutionEnd(timer, col);
 165  0
             }
 166  
         } else {
 167  0
             super.close();
 168  
         }
 169  0
     }
 170  
     
 171  
     private SqlPrepareContext getPrepareContext(String sql) {
 172  0
         return factory.getPrepareContext(sql);
 173  
     }
 174  
 }

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