001/*
002 * $Id: ProxyDriver.java,v 1.10 2016/12/18 20:19:38 oboehm Exp $
003 *
004 * Copyright (c) 2014 by Oliver Boehm
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 *
018 * (c)reated 27.03.2014 by oliver (ob@oasd.de)
019 */
020
021package patterntesting.runtime.monitor.db;
022
023import java.sql.Driver;
024import java.sql.DriverManager;
025import java.sql.SQLException;
026
027/**
028 * This JDBC driver acts like a proxy between PatternTesting and the real JDBC
029 * driver to be able to monitor JDBC access. It was inspired by the JAMonDriver
030 * of the JAMon framework.
031 * <p>
032 * This driver is registered for JDBC URLs beginning with "<em>jdbc:proxy:</em>
033 * ...". This prefix must follow the real driver path. E.g. if you want to use
034 * HSQL as database your URL make look like
035 * "<em>jdbc:proxy:hsqldb:file:/tmp/oli</em>".
036 * </p>
037 *
038 * @author oliver
039 * @version $Revision: 1.10 $
040 * @since 1.4.1 (27.03.2014)
041 * @deprecated since 2.0, use {@link clazzfish.jdbc.ProxyDriver}
042 */
043@Deprecated
044public class ProxyDriver extends clazzfish.jdbc.ProxyDriver implements Driver {
045
046        /**
047         * Registers the driver as JDBC driver.
048         * <p>
049         * Because the implementation how the {@link DriverManager} finds the
050         * corresponding driver for a given JDBC-URL is a little stupid - it tries
051         * out all drivers if it can work with the URL. In case of problems (e.g. if
052         * the network is down) it throws the first {@link SQLException} it got and
053         * rethrow it - but this may be not the reason for the error message that
054         * the protocoll "jdbc:proxy:..." can not be understood.
055         * </p>
056         * <p>
057         * This is the reason why first all registered drivers are first
058         * deregistered and the registered again. This guarantees that the
059         * ProxyDriver is the first registered driver.
060         * </p>
061         */
062        public static void register() {
063                clazzfish.jdbc.ProxyDriver.register();
064        }
065
066        /**
067         * Gets the real JDBC URL of the underlying driver.
068         *
069         * @param jdbcURL
070         *            the jdbc url, e.g. "jdbc:proxy:hsqldb:mem:testdb"
071         * @return the real driver name
072         */
073        public static String getRealURL(final String jdbcURL) {
074                return clazzfish.jdbc.ProxyDriver.getRealURL(jdbcURL);
075        }
076
077        /**
078         * Gets the real driver name of the underlying driver.
079         *
080         * @param jdbcURL
081         *            the jdbc url, e.g. "jdbc:proxy:hsqldb:mem:testdb"
082         * @return the real driver name
083         */
084        public static String getRealDriverName(final String jdbcURL) {
085                return clazzfish.jdbc.ProxyDriver.getRealDriverName(jdbcURL);
086        }
087
088        /**
089         * Gets the real driver.
090         *
091         * @param jdbcURL
092         *            the jdbc url, e.g. "jdbc:proxy:hsqldb:mem:testdb"
093         * @return the real driver
094         */
095        public static Driver getRealDriver(final String jdbcURL) {
096                return clazzfish.jdbc.ProxyDriver.getRealDriver(jdbcURL);
097        }
098
099}