View Javadoc
1   package org.andromda.maven.plugin.andromdapp;
2   
3   import java.lang.reflect.Method;
4   import java.sql.Connection;
5   import java.sql.Driver;
6   import java.sql.DriverPropertyInfo;
7   import java.sql.SQLException;
8   import java.sql.SQLFeatureNotSupportedException;
9   import java.util.Properties;
10  import java.util.logging.Logger;
11  
12  /**
13   * This just wraps a regular JDBC driver so that we can successfully load
14   * a JDBC driver without having to use the System class loader.
15   *
16   * @author Chad Brandon
17   */
18  public class JdbcDriverWrapper
19      implements Driver
20  {
21      private Driver driver;
22  
23      /**
24       * @param driver
25       */
26      public JdbcDriverWrapper(Driver driver)
27      {
28          this.driver = driver;
29      }
30  
31      /**
32       * @see java.sql.Driver#acceptsURL(String)
33       */
34      public boolean acceptsURL(String url)
35          throws SQLException
36      {
37          return this.driver.acceptsURL(url);
38      }
39  
40      /**
41       * @see java.sql.Driver#connect(String, java.util.Properties)
42       */
43      public Connection connect(
44          String url,
45          Properties properties)
46          throws SQLException
47      {
48          return this.driver.connect(
49              url,
50              properties);
51      }
52  
53      /**
54       * @see java.sql.Driver#getMajorVersion()
55       */
56      public int getMajorVersion()
57      {
58          return this.driver.getMajorVersion();
59      }
60  
61      /**
62       * @see java.sql.Driver#getMinorVersion()
63       */
64      public int getMinorVersion()
65      {
66          return this.driver.getMinorVersion();
67      }
68  
69      /**
70       * @see java.sql.Driver#getPropertyInfo(String, java.util.Properties)
71       */
72      public DriverPropertyInfo[] getPropertyInfo(
73          String url,
74          Properties properties)
75          throws SQLException
76      {
77          return this.driver.getPropertyInfo(
78              url,
79              properties);
80      }
81  
82      /**
83       * @see java.sql.Driver#jdbcCompliant()
84       */
85      public boolean jdbcCompliant()
86      {
87          return this.driver.jdbcCompliant();
88      }
89  
90      /**
91       * @see java.sql.Driver#getParentLogger()
92       */
93      // See http://stackoverflow.com/questions/8503338/new-method-added-in-javax-sql-commondatasource-in-1-7
94      // and https://forums.oracle.com/message/10089368
95      //@Override // This means it must be compiled with JDK7
96      public Logger getParentLogger() throws SQLFeatureNotSupportedException
97      {
98          Logger logger = null;
99          try
100         {
101             // Throws a runtime exception is this method is not in the runtime JDBC driver
102             // Use reflection to determine if the method exists at runtime
103             //logger = this.driver.getParentLogger(); // When JDK6 is no longer supported
104             Method method = this.driver.getClass().getMethod("getParentLogger");
105             logger = (Logger)method.invoke(this.driver);
106         }
107         catch (Exception e)
108         {
109             // Not using JDK7, method does not exist, ignore or return UnsupportedOperation.
110             // A better approach would be to use something other than java.util.Logger
111         }
112         return logger;
113     }
114 }