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