Coverage Report - org.owasp.dependencycheck.data.nvdcve.DriverShim
 
Classes in this File Line Coverage Branch Coverage Complexity
DriverShim
25%
5/20
0%
0/12
1.636
 
 1  
 /*
 2  
  * This file is part of dependency-check-core.
 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  
  * Copyright (c) 2014 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.data.nvdcve;
 19  
 
 20  
 import java.sql.Connection;
 21  
 import java.sql.Driver;
 22  
 import java.sql.DriverPropertyInfo;
 23  
 import java.sql.SQLException;
 24  
 import java.sql.SQLFeatureNotSupportedException;
 25  
 import java.util.Properties;
 26  
 import java.util.logging.Logger;
 27  
 
 28  
 /**
 29  
  * <p>
 30  
  * Driver shim to get around the class loader issue with the DriverManager. The following code is a nearly identical
 31  
  * copy (with more comments and a few more methods implemented) of the DriverShim from:</p>
 32  
  * <blockquote>http://www.kfu.com/~nsayer/Java/dyn-jdbc.html</blockquote>
 33  
  *
 34  
  * @author Jeremy Long <jeremy.long@owasp.org>
 35  
  * @see java.sql.Driver
 36  
  */
 37  
 class DriverShim implements Driver {
 38  
 
 39  
     /**
 40  
      * The database driver being wrapped.
 41  
      */
 42  
     private final Driver driver;
 43  
 
 44  
     /**
 45  
      * Constructs a new wrapper around a Driver.
 46  
      *
 47  
      * @param driver the database driver to wrap
 48  
      */
 49  57
     DriverShim(Driver driver) {
 50  57
         this.driver = driver;
 51  57
     }
 52  
 
 53  
     /**
 54  
      * Wraps the underlying driver's call to acceptsURL. Returns whether or not the driver can open a connection to the
 55  
      * given URL.
 56  
      *
 57  
      * @param url the URL of the database
 58  
      * @return true if the wrapped driver can connect to the specified URL
 59  
      * @throws SQLException thrown if there is an error connecting to the database
 60  
      * @see java.sql.Driver#acceptsURL(java.lang.String)
 61  
      */
 62  
     @Override
 63  
     public boolean acceptsURL(String url) throws SQLException {
 64  48
         return this.driver.acceptsURL(url);
 65  
     }
 66  
 
 67  
     /**
 68  
      * Returns the wrapped driver's major version number.
 69  
      *
 70  
      * @return the wrapped driver's major version number
 71  
      * @see java.sql.Driver#getMajorVersion()
 72  
      */
 73  
     @Override
 74  
     public int getMajorVersion() {
 75  0
         return this.driver.getMajorVersion();
 76  
     }
 77  
 
 78  
     /**
 79  
      * Returns the wrapped driver's minor version number.
 80  
      *
 81  
      * @return the wrapped driver's minor version number
 82  
      * @see java.sql.Driver#getMinorVersion()
 83  
      */
 84  
     @Override
 85  
     public int getMinorVersion() {
 86  0
         return this.driver.getMinorVersion();
 87  
     }
 88  
 
 89  
     /**
 90  
      * Returns whether or not the wrapped driver is jdbcCompliant.
 91  
      *
 92  
      * @return true if the wrapped driver is JDBC compliant; otherwise false
 93  
      * @see java.sql.Driver#jdbcCompliant()
 94  
      */
 95  
     @Override
 96  
     public boolean jdbcCompliant() {
 97  0
         return this.driver.jdbcCompliant();
 98  
     }
 99  
 
 100  
     /**
 101  
      * Wraps the call to the underlying driver's connect method.
 102  
      *
 103  
      * @param url the URL of the database
 104  
      * @param info a collection of string/value pairs
 105  
      * @return a Connection object
 106  
      * @throws SQLException thrown if there is an error connecting to the database
 107  
      * @see java.sql.Driver#connect(java.lang.String, java.util.Properties)
 108  
      */
 109  
     @Override
 110  
     public Connection connect(String url, Properties info) throws SQLException {
 111  0
         return this.driver.connect(url, info);
 112  
     }
 113  
 
 114  
     /**
 115  
      * Wraps the call to the underlying driver's getPropertyInfo method.
 116  
      *
 117  
      * @param url the URL of the database
 118  
      * @param info a collection of string/value pairs
 119  
      * @return an array of DriverPropertyInfo objects
 120  
      * @throws SQLException thrown if there is an error accessing the database
 121  
      * @see java.sql.Driver#getPropertyInfo(java.lang.String, java.util.Properties)
 122  
      */
 123  
     @Override
 124  
     public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
 125  0
         return this.driver.getPropertyInfo(url, info);
 126  
     }
 127  
 
 128  
     /**
 129  
      * Wraps the call to the underlying driver's getParentLogger method.
 130  
      *
 131  
      * @return the parent's Logger
 132  
      * @throws SQLFeatureNotSupportedException thrown if the feature is not supported
 133  
      * @see java.sql.Driver#getParentLogger()
 134  
      */
 135  
     @Override
 136  
     public Logger getParentLogger() throws SQLFeatureNotSupportedException {
 137  0
         return this.driver.getParentLogger();
 138  
     }
 139  
 
 140  
     /**
 141  
      * Standard implementation of hashCode.
 142  
      *
 143  
      * @return the hashCode of the object
 144  
      */
 145  
     @Override
 146  
     public int hashCode() {
 147  0
         int hash = 7;
 148  0
         hash = 97 * hash + (this.driver != null ? this.driver.hashCode() : 0);
 149  0
         return hash;
 150  
     }
 151  
 
 152  
     /**
 153  
      * Standard implementation of equals.
 154  
      *
 155  
      * @param obj the object to compare
 156  
      * @return returns true if the objects are equal; otherwise false
 157  
      */
 158  
     @Override
 159  
     public boolean equals(Object obj) {
 160  0
         if (obj == null) {
 161  0
             return false;
 162  
         }
 163  0
         if (getClass() != obj.getClass()) {
 164  0
             return false;
 165  
         }
 166  0
         final DriverShim other = (DriverShim) obj;
 167  0
         return this.driver == other.driver || (this.driver != null && this.driver.equals(other.driver));
 168  
     }
 169  
 
 170  
     /**
 171  
      * Standard implementation of toString().
 172  
      *
 173  
      * @return the String representation of the object
 174  
      */
 175  
     @Override
 176  
     public String toString() {
 177  57
         return "DriverShim{" + "driver=" + driver + '}';
 178  
     }
 179  
 }