Coverage report

  %line %branch
net.sf.infrared.aspects.jdbc.NonWrappingJdbcAspect
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:  binil.thomas (Tavant Technologies)
 19  
  * Contributor(s):   -;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.aspects.jdbc;
 23  
 
 24  
 import java.sql.Connection;
 25  
 import java.sql.PreparedStatement;
 26  
 import java.sql.ResultSet;
 27  
 
 28  
 import net.sf.infrared.agent.MonitorConfig;
 29  
 import net.sf.infrared.agent.MonitorFacade;
 30  
 import net.sf.infrared.agent.MonitorFactory;
 31  
 import net.sf.infrared.agent.StatisticsCollector;
 32  
 import net.sf.infrared.aspects.AbstractBaseAspect;
 33  
 import net.sf.infrared.aspects.api.ApiContext;
 34  
 import net.sf.infrared.aspects.jdbc.p6spy.InfraREDP6Factory;
 35  
 import net.sf.infrared.base.model.ExecutionTimer;
 36  
 import org.codehaus.aspectwerkz.joinpoint.StaticJoinPoint;
 37  
 
 38  
 /**
 39  
  * An aspect implementation which intercepts JDBC calls without wrapping using
 40  
  * a P6Spy decorator.
 41  
  * This was implemented as a solution for bug# 1423202 (casts to driver-specific
 42  
  * interfaces fail).
 43  
  *
 44  
  * @author binil.thomas
 45  
  */
 46  0
 public class NonWrappingJdbcAspect extends AbstractBaseAspect {
 47  0
     private static SqlContextManager ctxMgr = new SqlContextManager();
 48  
 
 49  0
     private static SqlMemory sqlMem = new SqlMemory();
 50  
     
 51  
     public Object aroundSimpleSqlExecution(StaticJoinPoint sjp, String sql) throws Throwable {      
 52  0
         MonitorFacade facade = MonitorFactory.getFacade();
 53  0
     	if(! isJDBCMonitoringEnabled(facade) ) {
 54  0
             return sjp.proceed();
 55  
     	}
 56  0
         SqlExecuteContext ctx = ctxMgr.getExecuteContext(sql);
 57  0
         return recordExecution(ctx, sjp, facade);    
 58  
     }
 59  
 
 60  
     public Object aroundFirstStatementOrCallPreparation(StaticJoinPoint sjp, String sql) throws Throwable {              
 61  0
         MonitorFacade facade = MonitorFactory.getFacade();
 62  0
         if(! isJDBCMonitoringEnabled(facade) ) {
 63  0
             Object ps = sjp.proceed();
 64  0
             sqlMem.memorizeSql(sql, ps);
 65  0
             return ps;
 66  
     	}
 67  
         
 68  0
         SqlPrepareContext ctx = ctxMgr.getPrepareContext(sql);
 69  0
         ExecutionTimer timer = new ExecutionTimer(ctx);
 70  0
         StatisticsCollector collector = facade.recordExecutionBegin(timer);
 71  0
         Object ps = null;
 72  
         try {
 73  0
             ps = sjp.proceed();            
 74  0
             return ps;
 75  
         } finally {
 76  0
             facade.recordExecutionEnd(timer, collector);
 77  0
             if (ps != null) {
 78  0
                 sqlMem.memorizeSql(sql, ps);
 79  
             }
 80  
         }  
 81  
     }
 82  
 
 83  
     public Object aroundStatementOrCallExecution(StaticJoinPoint sjp, PreparedStatement ps) throws Throwable {
 84  0
         MonitorFacade facade = MonitorFactory.getFacade();
 85  0
         if(! isJDBCMonitoringEnabled(facade) ) {
 86  0
             return sjp.proceed();
 87  
     	}
 88  
 
 89  0
         String sql = sqlMem.recollectSql(ps);
 90  0
         if (sql == null) {
 91  
             // we somehow missed recording the SQL; this is as good (or bad) as
 92  
             // having the JDBC monitoring turned off for this execution.
 93  0
             return sjp.proceed(); 
 94  
         }
 95  
         
 96  0
         SqlExecuteContext ctx = ctxMgr.getExecuteContext(sql);
 97  0
         ExecutionTimer timer = new ExecutionTimer(ctx);
 98  0
         StatisticsCollector collector = facade.recordExecutionBegin(timer);
 99  
         try {            
 100  0
             return sjp.proceed();
 101  
         } finally {
 102  0
             facade.recordExecutionEnd(timer, collector);
 103  
         }
 104  
     }
 105  
     
 106  
     public Object aroundCommit(StaticJoinPoint sjp) throws Throwable {        
 107  0
         MonitorFacade facade = MonitorFactory.getFacade();
 108  0
         if(! isJDBCMonitoringEnabled(facade) ) {
 109  0
             return sjp.proceed();            
 110  
     	}
 111  
         
 112  0
         ApiContext ctx = new ApiContext(Connection.class.getName(), "commit", "JDBC");
 113  0
         return recordExecution(ctx, sjp, facade);  
 114  
     }
 115  
     
 116  
     public Object aroundRollback(StaticJoinPoint sjp) throws Throwable {        
 117  0
         MonitorFacade facade = MonitorFactory.getFacade();
 118  0
         if(! isJDBCMonitoringEnabled(facade) ) {
 119  0
             return sjp.proceed();            
 120  
     	}
 121  
         
 122  0
         ApiContext ctx = new ApiContext(Connection.class.getName(), "rollback", "JDBC");
 123  0
         return recordExecution(ctx, sjp, facade);  
 124  
     }
 125  
     
 126  
     public Object aroundIterateOverResultSet(StaticJoinPoint sjp) throws Throwable {
 127  0
         MonitorFacade facade = MonitorFactory.getFacade();
 128  0
         if(! isJDBCMonitoringEnabled(facade) ) {
 129  0
             return sjp.proceed();            
 130  
     	}
 131  
         
 132  0
         ApiContext apiCtx = new ApiContext(ResultSet.class.getName(), "next", "JDBC");
 133  0
         return recordExecution(apiCtx, sjp, facade);    
 134  
     }
 135  
     
 136  
     boolean isJDBCMonitoringEnabled(MonitorFacade facade) {
 137  0
         MonitorConfig cfg = facade.getConfiguration();
 138  0
         return cfg.isMonitoringEnabled() 
 139  
             && cfg.getProperty(InfraREDP6Factory.KEY_JDBC_MONITORING_ENABLED, true);
 140  
     }
 141  
 }

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