Fixed problem with NamingStrategy (contribution from Lorenzo Nicora)
[hibernate4-maven-plugin] / src / main / java / de / juplo / plugins / hibernate4 / Hbm2DdlMojo.java
1 package de.juplo.plugins.hibernate4;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 import com.pyx4j.log4j.MavenLogAppender;
20 import java.io.File;
21 import java.io.FileInputStream;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.ObjectInputStream;
26 import java.io.ObjectOutputStream;
27 import java.math.BigInteger;
28 import java.net.URL;
29 import java.net.URLClassLoader;
30 import java.security.MessageDigest;
31 import java.sql.Connection;
32 import java.sql.Driver;
33 import java.sql.DriverManager;
34 import java.sql.DriverPropertyInfo;
35 import java.sql.SQLException;
36 import java.sql.SQLFeatureNotSupportedException;
37 import java.util.Comparator;
38 import java.util.Enumeration;
39 import java.util.HashMap;
40 import java.util.HashSet;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Map.Entry;
44 import java.util.Properties;
45 import java.util.Set;
46 import java.util.TreeSet;
47 import java.util.logging.Logger;
48 import javax.persistence.Embeddable;
49 import javax.persistence.Entity;
50 import javax.persistence.MappedSuperclass;
51 import org.apache.maven.plugin.AbstractMojo;
52 import org.apache.maven.plugin.MojoExecutionException;
53 import org.apache.maven.plugin.MojoFailureException;
54 import org.apache.maven.project.MavenProject;
55 import org.hibernate.cfg.Configuration;
56 import org.hibernate.cfg.NamingStrategy;
57 import org.hibernate.tool.hbm2ddl.SchemaExport;
58 import org.hibernate.tool.hbm2ddl.SchemaExport.Type;
59 import org.hibernate.tool.hbm2ddl.Target;
60 import org.scannotation.AnnotationDB;
61
62
63 /**
64  * Goal which extracts the hibernate-mapping-configuration and
65  * exports an according SQL-database-schema.
66  *
67  * @goal export
68  * @phase process-classes
69  * @threadSafe
70  * @requiresDependencyResolution runtime
71  */
72 public class Hbm2DdlMojo extends AbstractMojo
73 {
74   public final static String EXPORT_SKIPPED_PROPERTY = "hibernate.export.skipped";
75
76   public final static String DRIVER_CLASS = "hibernate.connection.driver_class";
77   public final static String URL = "hibernate.connection.url";
78   public final static String USERNAME = "hibernate.connection.username";
79   public final static String PASSWORD = "hibernate.connection.password";
80   public final static String DIALECT = "hibernate.dialect";
81   public final static String NAMING_STRATEGY="hibernate.ejb.naming_strategy";
82
83   private final static String MD5S = "schema.md5s";
84
85   /**
86    * The maven project.
87    * <p>
88    * Only needed internally.
89    *
90    * @parameter property="project"
91    * @required
92    * @readonly
93    */
94   private MavenProject project;
95
96   /**
97    * Build-directory.
98    * <p>
99    * Only needed internally.
100    *
101    * @parameter property="project.build.directory"
102    * @required
103    * @readonly
104    */
105   private String buildDirectory;
106
107   /**
108    * Classes-Directory to scan.
109    * <p>
110    * This parameter defaults to the maven build-output-directory for classes.
111    * Additonally, all dependencies are scanned for annotated classes.
112    *
113    * @parameter property="project.build.outputDirectory"
114    */
115   private String outputDirectory;
116
117   /**
118    * Wether to scan test-classes too, or not.
119    * <p>
120    * If this parameter is set to <code>true</code> the test-classes of the
121    * artifact will be scanned for hibernate-annotated classes additionally.
122    *
123    * @parameter property="hibernate.export.scan_testclasses" default-value="false"
124    */
125   private boolean scanTestClasses;
126
127   /**
128    * Test-Classes-Directory to scan.
129    * <p>
130    * This parameter defaults to the maven build-output-directory for
131    * test-classes.
132    * <p>
133    * This parameter is only used, when <code>scanTestClasses</code> is set
134    * to <code>true</code>!
135    *
136    * @parameter property="project.build.testOutputDirectory"
137    */
138   private String testOutputDirectory;
139
140   /**
141    * Skip execution
142    * <p>
143    * If set to <code>true</code>, the execution is skipped.
144    * <p>
145    * A skipped excecution is signaled via the maven-property
146    * <code>${hibernate.export.skipped}</code>.
147    * <p>
148    * The excecution is skipped automatically, if no modified or newly added
149    * annotated classes are found and the dialect was not changed.
150    *
151    * @parameter property="maven.test.skip" default-value="false"
152    */
153   private boolean skip;
154
155   /**
156    * Force execution
157    * <p>
158    * Force execution, even if no modified or newly added annotated classes
159    * where found and the dialect was not changed.
160    * <p>
161    * <code>skip</code> takes precedence over <code>force</code>.
162    *
163    * @parameter property="hibernate.export.force" default-value="false"
164    */
165   private boolean force;
166
167   /**
168    * SQL-Driver name.
169    *
170    * @parameter property="hibernate.connection.driver_class"
171    */
172   private String driverClassName;
173
174   /**
175    * Database URL.
176    *
177    * @parameter property="hibernate.connection.url"
178    */
179   private String url;
180
181   /**
182    * Database username
183    *
184    * @parameter property="hibernate.connection.username"
185    */
186   private String username;
187
188   /**
189    * Database password
190    *
191    * @parameter property="hibernate.connection.password"
192    */
193   private String password;
194
195   /**
196    * Hibernate dialect.
197    *
198    * @parameter property="hibernate.dialect"
199    */
200   private String hibernateDialect;
201
202   /**
203    * Hibernate Naming Strategy
204    * @parameter property="hibernate.ejb.naming_strategy"
205    * @author nicus
206    */
207   private String hibernateNamingStrategy;
208
209   /**
210    * Path to Hibernate configuration file.
211    *
212    * @parameter default-value="${project.build.outputDirectory}/hibernate.properties"
213    */
214   private String hibernateProperties;
215
216   /**
217    * Target of execution:
218    * <ul>
219    *   <li><strong>NONE</strong> do nothing - just validate the configuration (forces excecution, signals skip)</li>
220    *   <li><strong>EXPORT</strong> create database (<strong>DEFAULT!</strong>. forces excecution, signals skip)</li>
221    *   <li><strong>SCRIPT</strong> export schema to SQL-script</li>
222    *   <li><strong>BOTH</strong></li>
223    * </ul>
224    *
225    * @parameter property="hibernate.export.target" default-value="EXPORT"
226    */
227   private String target;
228
229   /**
230    * Type of execution.
231    * <ul>
232    *   <li><strong>NONE</strong> do nothing - just validate the configuration</li>
233    *   <li><strong>CREATE</strong> create database-schema</li>
234    *   <li><strong>DROP</strong> drop database-schema</li>
235    *   <li><strong>BOTH</strong> (<strong>DEFAULT!</strong>)</li>
236    * </ul>
237    *
238    * @parameter property="hibernate.export.type" default-value="BOTH"
239    */
240   private String type;
241
242   /**
243    * Output file.
244    *
245    * @parameter property="hibernate.export.schema.filename" default-value="${project.build.directory}/schema.sql"
246    */
247   private String outputFile;
248
249   /**
250    * Delimiter in output-file.
251    *
252    * @parameter property="hibernate.export.schema.delimiter" default-value=";"
253    */
254   private String delimiter;
255
256   /**
257    * Format output-file.
258    *
259    * @parameter property="hibernate.export.schema.format" default-value="true"
260    */
261   private boolean format;
262
263
264   @Override
265   public void execute()
266     throws
267       MojoFailureException,
268       MojoExecutionException
269   {
270     if (skip)
271     {
272       getLog().info("Exectuion of hibernate4-maven-plugin:export was skipped!");
273       project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
274       return;
275     }
276
277     File dir = new File(outputDirectory);
278     if (!dir.exists())
279       throw new MojoExecutionException("Cannot scan for annotated classes in " + outputDirectory + ": directory does not exist!");
280
281     Map<String,String> md5s;
282     boolean modified = false;
283     File saved = new File(buildDirectory + File.separator + MD5S);
284
285     if (saved.exists())
286     {
287       try
288       {
289         FileInputStream fis = new FileInputStream(saved);
290         ObjectInputStream ois = new ObjectInputStream(fis);
291         md5s = (HashMap<String,String>)ois.readObject();
292         ois.close();
293       }
294       catch (Exception e)
295       {
296         md5s = new HashMap<String,String>();
297         getLog().warn("Cannot read timestamps from saved: " + e);
298       }
299     }
300     else
301     {
302       md5s = new HashMap<String,String>();
303       try
304       {
305         saved.createNewFile();
306       }
307       catch (IOException e)
308       {
309         getLog().warn("Cannot create saved for timestamps: " + e);
310       }
311     }
312
313     ClassLoader classLoader = null;
314     try
315     {
316       getLog().debug("Creating ClassLoader for project-dependencies...");
317       List<String> classpathFiles = project.getCompileClasspathElements();
318       if (scanTestClasses)
319         classpathFiles.addAll(project.getTestClasspathElements());
320       URL[] urls = new URL[classpathFiles.size()];
321       for (int i = 0; i < classpathFiles.size(); ++i)
322       {
323         getLog().debug("Dependency: " + classpathFiles.get(i));
324         urls[i] = new File(classpathFiles.get(i)).toURI().toURL();
325       }
326       classLoader = new URLClassLoader(urls, getClass().getClassLoader());
327     }
328     catch (Exception e)
329     {
330       getLog().error("Error while creating ClassLoader!", e);
331       throw new MojoExecutionException(e.getMessage());
332     }
333
334     Set<Class<?>> classes =
335         new TreeSet<Class<?>>(
336             new Comparator<Class<?>>() {
337               @Override
338               public int compare(Class<?> a, Class<?> b)
339               {
340                 return a.getName().compareTo(b.getName());
341               }
342             }
343           );
344
345     try
346     {
347       AnnotationDB db = new AnnotationDB();
348       getLog().info("Scanning directory " + outputDirectory + " for annotated classes...");
349       URL dirUrl = dir.toURI().toURL();
350       db.scanArchives(dirUrl);
351       if (scanTestClasses)
352       {
353         dir = new File(testOutputDirectory);
354         if (!dir.exists())
355           throw new MojoExecutionException("Cannot scan for annotated test-classes in " + testOutputDirectory + ": directory does not exist!");
356         getLog().info("Scanning directory " + testOutputDirectory + " for annotated classes...");
357         dirUrl = dir.toURI().toURL();
358         db.scanArchives(dirUrl);
359       }
360
361       Set<String> classNames = new HashSet<String>();
362       if (db.getAnnotationIndex().containsKey(Entity.class.getName()))
363         classNames.addAll(db.getAnnotationIndex().get(Entity.class.getName()));
364       if (db.getAnnotationIndex().containsKey(MappedSuperclass.class.getName()))
365         classNames.addAll(db.getAnnotationIndex().get(MappedSuperclass.class.getName()));
366       if (db.getAnnotationIndex().containsKey(Embeddable.class.getName()))
367         classNames.addAll(db.getAnnotationIndex().get(Embeddable.class.getName()));
368
369       MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
370       for (String name : classNames)
371       {
372         Class<?> annotatedClass = classLoader.loadClass(name);
373         classes.add(annotatedClass);
374         InputStream is =
375             annotatedClass
376                 .getResourceAsStream(annotatedClass.getSimpleName() + ".class");
377         byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks
378         int i;
379         while((i = is.read(buffer)) > -1)
380           digest.update(buffer, 0, i);
381         is.close();
382         byte[] bytes = digest.digest();
383         BigInteger bi = new BigInteger(1, bytes);
384         String newMd5 = String.format("%0" + (bytes.length << 1) + "x", bi);
385         String oldMd5 = !md5s.containsKey(name) ? "" : md5s.get(name);
386         if (!newMd5.equals(oldMd5))
387         {
388           getLog().debug("Found new or modified annotated class: " + name);
389           modified = true;
390           md5s.put(name, newMd5);
391         }
392         else
393         {
394           getLog().debug(oldMd5 + " -> class unchanged: " + name);
395         }
396       }
397     }
398     catch (ClassNotFoundException e)
399     {
400       getLog().error("Error while adding annotated classes!", e);
401       throw new MojoExecutionException(e.getMessage());
402     }
403     catch (Exception e)
404     {
405       getLog().error("Error while scanning!", e);
406       throw new MojoFailureException(e.getMessage());
407     }
408
409     if (classes.isEmpty())
410       throw new MojoFailureException("No annotated classes found in directory " + outputDirectory);
411
412     getLog().debug("Detected classes with mapping-annotations:");
413     for (Class<?> annotatedClass : classes)
414       getLog().debug("  " + annotatedClass.getName());
415
416
417     Properties properties = new Properties();
418
419     /** Try to read configuration from properties-file */
420     try
421     {
422       File file = new File(hibernateProperties);
423       if (file.exists())
424       {
425         getLog().info("Reading properties from file " + hibernateProperties + "...");
426         properties.load(new FileInputStream(file));
427       }
428       else
429         getLog().info("No hibernate-properties-file found! (Checked path: " + hibernateProperties + ")");
430     }
431     catch (IOException e)
432     {
433       getLog().error("Error while reading properties!", e);
434       throw new MojoExecutionException(e.getMessage());
435     }
436
437     /** Overwrite values from propertie-file or set, if given */
438     if (driverClassName != null)
439     {
440       if (properties.containsKey(DRIVER_CLASS))
441         getLog().debug(
442             "Overwriting property " +
443             DRIVER_CLASS + "=" + properties.getProperty(DRIVER_CLASS) +
444             " with the value " + driverClassName
445           );
446       else
447         getLog().debug("Using the value " + driverClassName);
448       properties.setProperty(DRIVER_CLASS, driverClassName);
449     }
450     if (url != null)
451     {
452       if (properties.containsKey(URL))
453         getLog().debug(
454             "Overwriting property " +
455             URL + "=" + properties.getProperty(URL) +
456             " with the value " + url
457           );
458       else
459         getLog().debug("Using the value " + url);
460       properties.setProperty(URL, url);
461     }
462     if (username != null)
463     {
464       if (properties.containsKey(USERNAME))
465         getLog().debug(
466             "Overwriting property " +
467             USERNAME + "=" + properties.getProperty(USERNAME) +
468             " with the value " + username
469           );
470       else
471         getLog().debug("Using the value " + username);
472       properties.setProperty(USERNAME, username);
473     }
474     if (password != null)
475     {
476       if (properties.containsKey(PASSWORD))
477         getLog().debug(
478             "Overwriting property " +
479             PASSWORD + "=" + properties.getProperty(PASSWORD) +
480             " with the value " + password
481           );
482       else
483         getLog().debug("Using the value " + password);
484       properties.setProperty(PASSWORD, password);
485     }
486     if (hibernateDialect != null)
487     {
488       if (properties.containsKey(DIALECT))
489         getLog().debug(
490             "Overwriting property " +
491             DIALECT + "=" + properties.getProperty(DIALECT) +
492             " with the value " + hibernateDialect
493           );
494       else
495         getLog().debug("Using the value " + hibernateDialect);
496       properties.setProperty(DIALECT, hibernateDialect);
497     }
498     if ( hibernateNamingStrategy != null )
499     {
500       if ( properties.contains(NAMING_STRATEGY))
501         getLog().debug(
502             "Overwriting property " +
503             NAMING_STRATEGY + "=" + properties.getProperty(NAMING_STRATEGY) +
504             " with the value " + hibernateNamingStrategy
505            );
506       else
507         getLog().debug("Using the value " + hibernateNamingStrategy);
508       properties.setProperty(NAMING_STRATEGY, hibernateNamingStrategy);
509     }
510
511     /** The generated SQL varies with the dialect! */
512     if (md5s.containsKey(DIALECT))
513     {
514       String dialect = properties.getProperty(DIALECT);
515       if (md5s.get(DIALECT).equals(dialect))
516         getLog().debug("SQL-dialect unchanged.");
517       else
518       {
519         getLog().debug("SQL-dialect changed: " + dialect);
520         modified = true;
521         md5s.put(DIALECT, dialect);
522       }
523     }
524     else
525     {
526       modified = true;
527       md5s.put(DIALECT, properties.getProperty(DIALECT));
528     }
529
530     if (properties.isEmpty())
531     {
532       getLog().error("No properties set!");
533       throw new MojoFailureException("Hibernate-Configuration is missing!");
534     }
535
536     Configuration config = new Configuration();
537     config.setProperties(properties);
538
539     if ( properties.containsKey(NAMING_STRATEGY))
540     {
541       String namingStrategy = properties.getProperty(NAMING_STRATEGY);
542       getLog().debug("Explicitly set NamingStrategy: " + namingStrategy);
543       try
544       {
545         @SuppressWarnings("unchecked")
546         Class<NamingStrategy> namingStrategyClass = (Class<NamingStrategy>) Class.forName(namingStrategy);
547         config.setNamingStrategy(namingStrategyClass.newInstance());
548       }
549       catch (Exception e)
550       {
551         getLog().error("Error setting NamingStrategy", e);
552         throw new MojoExecutionException(e.getMessage());
553       }
554     }
555
556     getLog().debug("Adding annotated classes to hibernate-mapping-configuration...");
557     for (Class<?> annotatedClass : classes)
558     {
559       getLog().debug("Class " + annotatedClass);
560       config.addAnnotatedClass(annotatedClass);
561     }
562
563     Target target = null;
564     try
565     {
566       target = Target.valueOf(this.target.toUpperCase());
567     }
568     catch (IllegalArgumentException e)
569     {
570       getLog().error("Invalid value for configuration-option \"target\": " + this.target);
571       getLog().error("Valid values are: NONE, SCRIPT, EXPORT, BOTH");
572       throw new MojoExecutionException("Invalid value for configuration-option \"target\"");
573     }
574     Type type = null;
575     try
576     {
577       type = Type.valueOf(this.type.toUpperCase());
578     }
579     catch (IllegalArgumentException e)
580     {
581       getLog().error("Invalid value for configuration-option \"type\": " + this.type);
582       getLog().error("Valid values are: NONE, CREATE, DROP, BOTH");
583       throw new MojoExecutionException("Invalid value for configuration-option \"type\"");
584     }
585
586     if (target.equals(Target.SCRIPT) || target.equals(Target.NONE))
587     {
588       project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
589     }
590     if (
591         !modified
592         && !target.equals(Target.SCRIPT)
593         && !target.equals(Target.NONE)
594         && !force
595       )
596     {
597       getLog().info("No modified annotated classes found and dialect unchanged.");
598       getLog().info("Skipping schema generation!");
599       project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
600       return;
601     }
602
603     getLog().info("Gathered hibernate-configuration (turn on debugging for details):");
604     for (Entry<Object,Object> entry : properties.entrySet())
605       getLog().info("  " + entry.getKey() + " = " + entry.getValue());
606
607     Connection connection = null;
608     try
609     {
610       /**
611        * The connection must be established outside of hibernate, because
612        * hibernate does not use the context-classloader of the current
613        * thread and, hence, would not be able to resolve the driver-class!
614        */
615       switch (target)
616       {
617         case EXPORT:
618         case BOTH:
619           switch (type)
620           {
621             case CREATE:
622             case DROP:
623             case BOTH:
624               Class driverClass = classLoader.loadClass(properties.getProperty(DRIVER_CLASS));
625               getLog().debug("Registering JDBC-driver " + driverClass.getName());
626               DriverManager.registerDriver(new DriverProxy((Driver)driverClass.newInstance()));
627               getLog().debug(
628                   "Opening JDBC-connection to "
629                   + properties.getProperty(URL)
630                   + " as "
631                   + properties.getProperty(USERNAME)
632                   + " with password "
633                   + properties.getProperty(PASSWORD)
634                   );
635               connection = DriverManager.getConnection(
636                   properties.getProperty(URL),
637                   properties.getProperty(USERNAME),
638                   properties.getProperty(PASSWORD)
639                   );
640           }
641       }
642     }
643     catch (ClassNotFoundException e)
644     {
645       getLog().error("Dependency for driver-class " + properties.getProperty(DRIVER_CLASS) + " is missing!");
646       throw new MojoExecutionException(e.getMessage());
647     }
648     catch (Exception e)
649     {
650       getLog().error("Cannot establish connection to database!");
651       Enumeration<Driver> drivers = DriverManager.getDrivers();
652       if (!drivers.hasMoreElements())
653         getLog().error("No drivers registered!");
654       while (drivers.hasMoreElements())
655         getLog().debug("Driver: " + drivers.nextElement());
656       throw new MojoExecutionException(e.getMessage());
657     }
658
659     ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
660     MavenLogAppender.startPluginLog(this);
661     try
662     {
663       /**
664        * Change class-loader of current thread, so that hibernate can
665        * see all dependencies!
666        */
667       Thread.currentThread().setContextClassLoader(classLoader);
668
669       SchemaExport export = new SchemaExport(config, connection);
670       export.setOutputFile(outputFile);
671       export.setDelimiter(delimiter);
672       export.setFormat(format);
673       export.execute(target, type);
674
675       for (Object exception : export.getExceptions())
676         getLog().debug(exception.toString());
677     }
678     finally
679     {
680       /** Stop Log-Capturing */
681       MavenLogAppender.endPluginLog(this);
682
683       /** Restore the old class-loader (TODO: is this really necessary?) */
684       Thread.currentThread().setContextClassLoader(contextClassLoader);
685
686       /** Close the connection */
687       try
688       {
689         if (connection != null)
690           connection.close();
691       }
692       catch (SQLException e)
693       {
694         getLog().error("Error while closing connection: " + e.getMessage());
695       }
696     }
697
698     /** Write md5-sums for annotated classes to file */
699     try
700     {
701       FileOutputStream fos = new FileOutputStream(saved);
702       ObjectOutputStream oos = new ObjectOutputStream(fos);
703       oos.writeObject(md5s);
704       oos.close();
705       fos.close();
706     }
707     catch (Exception e)
708     {
709       getLog().error("Cannot write md5-sums to file: " + e);
710     }
711   }
712
713   /**
714    * Needed, because DriverManager won't pick up drivers, that were not
715    * loaded by the system-classloader!
716    * See:
717    * http://stackoverflow.com/questions/288828/how-to-use-a-jdbc-driver-fromodifiedm-an-arbitrary-location
718    */
719   static final class DriverProxy implements Driver
720   {
721     private final Driver target;
722
723     DriverProxy(Driver target)
724     {
725       if (target == null)
726         throw new NullPointerException();
727       this.target = target;
728     }
729
730     public java.sql.Driver getTarget()
731     {
732       return target;
733     }
734
735     @Override
736     public boolean acceptsURL(String url) throws SQLException
737     {
738       return target.acceptsURL(url);
739     }
740
741     @Override
742     public java.sql.Connection connect(
743         String url,
744         java.util.Properties info
745       )
746       throws
747         SQLException
748     {
749       return target.connect(url, info);
750     }
751
752     @Override
753     public int getMajorVersion()
754     {
755       return target.getMajorVersion();
756     }
757
758     @Override
759     public int getMinorVersion()
760     {
761       return target.getMinorVersion();
762     }
763
764     @Override
765     public DriverPropertyInfo[] getPropertyInfo(
766         String url,
767         Properties info
768       )
769       throws
770         SQLException
771     {
772       return target.getPropertyInfo(url, info);
773     }
774
775     @Override
776     public boolean jdbcCompliant()
777     {
778       return target.jdbcCompliant();
779     }
780
781     /**
782      * This Method cannot be annotated with @Override, becaus the plugin
783      * will not compile then under Java 1.6!
784      */
785     public Logger getParentLogger() throws SQLFeatureNotSupportedException
786     {
787       throw new SQLFeatureNotSupportedException("Not supported, for backward-compatibility with Java 1.6");
788     }
789
790     @Override
791     public String toString()
792     {
793       return "Proxy: " + target;
794     }
795
796     @Override
797     public int hashCode()
798     {
799       return target.hashCode();
800     }
801
802     @Override
803     public boolean equals(Object obj)
804     {
805       if (!(obj instanceof DriverProxy))
806         return false;
807       DriverProxy other = (DriverProxy) obj;
808       return this.target.equals(other.target);
809     }
810   }
811 }