Coverage report

  %line %branch
net.sf.infrared.aspects.jdbc.p6spy.InfraREDP6Factory
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):   -;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.aspects.jdbc.p6spy;
 23  
 
 24  
 import java.sql.Array;
 25  
 import java.sql.CallableStatement;
 26  
 import java.sql.Connection;
 27  
 import java.sql.DatabaseMetaData;
 28  
 import java.sql.PreparedStatement;
 29  
 import java.sql.ResultSet;
 30  
 import java.sql.ResultSetMetaData;
 31  
 import java.sql.SQLException;
 32  
 import java.sql.Statement;
 33  
 import java.util.Map;
 34  
 import java.util.WeakHashMap;
 35  
 
 36  
 import net.sf.infrared.agent.MonitorConfig;
 37  
 import net.sf.infrared.agent.MonitorFactory;
 38  
 import net.sf.infrared.aspects.jdbc.SqlContext;
 39  
 import net.sf.infrared.aspects.jdbc.SqlContextManager;
 40  
 import net.sf.infrared.aspects.jdbc.SqlExecuteContext;
 41  
 import net.sf.infrared.aspects.jdbc.SqlPrepareContext;
 42  
 import net.sf.infrared.base.util.LoggingFactory;
 43  
 
 44  
 import com.p6spy.engine.spy.P6Connection;
 45  
 import com.p6spy.engine.spy.P6CoreFactory;
 46  
 import com.p6spy.engine.spy.P6Statement;
 47  
 
 48  
 import org.apache.log4j.Logger;
 49  
 
 50  
 
 51  
 
 52  
 /**
 53  
  * Provide an implementation of the Factory class to plug in our wrapper class
 54  
  * implementation inplace of P6Spy. For the classes in which we are not
 55  
  * interested return the real JDBC class instead of the P6 wrapper. This is to
 56  
  * minimize the performance overhead.
 57  
  *
 58  
  * @author kamal.govindraj
 59  
  * @author binil.thomas
 60  
  */
 61  0
 public class InfraREDP6Factory extends P6CoreFactory {
 62  
 
 63  0
     private static final Logger log = LoggingFactory.getLogger(InfraREDP6Factory.class);
 64  
 
 65  
     public static final String KEY_JDBC_MONITORING_ENABLED = "jdbc-monitoring-enable";
 66  
 
 67  
     public static final String KEY_JDBC_FETCH_STATISTICS_ENABLE = "jdbc-fetch-statistics";
 68  
 
 69  
 	public static final String KEY_PREPARED_STATEMENT_MONITORING_ENABLED = "prepared-statement-monitoring-enable";
 70  
 
 71  0
     private SqlContextManager ctxMgr = new SqlContextManager();
 72  
 
 73  
     static{
 74  0
 		log.debug("InfraREDP6Factory class is being used to wrap the database connection");
 75  0
 	}
 76  
 
 77  
     public Connection getConnection(Connection conn) throws SQLException {
 78  
 
 79  0
         log.debug("InfraRED returning the wrapped InfraREDP6Connection");
 80  0
         return new InfraREDP6Connection(this, conn);
 81  
     }
 82  
 
 83  
     public PreparedStatement getPreparedStatement(PreparedStatement real, P6Connection conn,
 84  
             String sql) throws SQLException {
 85  0
         if (isJDBCMonitoringEnabled()) {
 86  0
         	if (isPreparedStatementMonitoringEnabled()){
 87  0
 	            return new InfraREDP6PreparedStatementWithVariables(this, real, conn, sql);
 88  
 			 } else {
 89  0
 				 return new InfraREDP6PreparedStatement(this, real, conn, sql);
 90  
 			 }
 91  
         } else {
 92  0
             return real;
 93  
         }
 94  
     }
 95  
 
 96  
     public Statement getStatement(Statement statement, P6Connection conn) throws SQLException {
 97  0
         if (isJDBCMonitoringEnabled()) {
 98  0
             return new InfraREDP6Statement(this, statement, conn);
 99  
         } else {
 100  0
             return statement;
 101  
         }
 102  
     }
 103  
 
 104  
     public ResultSet getResultSet(ResultSet real, P6Statement statement, String preparedQuery,
 105  
             String query) throws SQLException {
 106  0
         if (isJDBCMonitoringEnabled() && isCollectFetchDataEnabled()) {
 107  0
             return (real == null) ? class="keyword">null : new InfraREDP6ResultSet(this, real, statement,
 108  
                     preparedQuery, query);
 109  
         } else {
 110  0
             return real;
 111  
         }
 112  
     }
 113  
 
 114  
     public Array getArray(Array real, P6Statement statement, String preparedQuery, String query)
 115  
             throws SQLException {
 116  0
         return real;
 117  
     }
 118  
 
 119  
     public ResultSetMetaData getResultSetMetaData(ResultSetMetaData real) throws SQLException {
 120  0
         return real;
 121  
     }
 122  
 
 123  
     public CallableStatement getCallableStatement(CallableStatement real, P6Connection conn,
 124  
             String p0) throws SQLException {
 125  0
         if (isJDBCMonitoringEnabled()) {
 126  0
             return new InfraREDP6CallableStatement(this, real, conn, p0);
 127  
         } else {
 128  0
             return real;
 129  
         }
 130  
     }
 131  
 
 132  
     public DatabaseMetaData getDatabaseMetaData(DatabaseMetaData real, P6Connection conn)
 133  
             throws SQLException {
 134  0
         return new InfraREDP6DatabaseMetaData(this, real, conn);
 135  
     }
 136  
 
 137  
     public SqlContext getSqlContext(String sql) {
 138  0
         return ctxMgr.getSqlContext(sql);
 139  
     }
 140  
 
 141  
     public SqlExecuteContext getExecuteContext(String sql) {
 142  0
         return ctxMgr.getExecuteContext(sql);
 143  
     }
 144  
 
 145  
     public SqlPrepareContext getPrepareContext(String sql) {
 146  0
         return ctxMgr.getPrepareContext(sql);
 147  
     }
 148  
 
 149  
     boolean isJDBCMonitoringEnabled() {
 150  0
         MonitorConfig cfg = MonitorFactory.getFacade().getConfiguration();
 151  0
         return cfg.isMonitoringEnabled() && cfg.getProperty(KEY_JDBC_MONITORING_ENABLED, true);
 152  
     }
 153  
 
 154  
     boolean isCollectFetchDataEnabled() {
 155  0
         MonitorConfig cfg = MonitorFactory.getFacade().getConfiguration();
 156  0
         return cfg.isMonitoringEnabled() && cfg.getProperty(KEY_JDBC_FETCH_STATISTICS_ENABLE, true);
 157  
     }
 158  
 
 159  
     boolean isPreparedStatementMonitoringEnabled() {
 160  0
         MonitorConfig cfg = MonitorFactory.getFacade().getConfiguration();
 161  0
         return cfg.isMonitoringEnabled() && cfg.getProperty(KEY_PREPARED_STATEMENT_MONITORING_ENABLED, false);
 162  
     }
 163  
 }

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