Cleaned up code (formatting and logical code-order)
[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.envers.configuration.AuditConfiguration;
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 ENVERS = "hibernate.export.envers";
82
83   private final static String MD5S = "schema.md5s";
84
85   /**
86    * The maven project.
87    * <p>
88    * Only needed internally.
89    *
90    * @parameter expression="${project}"
91    * @required
92    * @readonly
93    */
94   private MavenProject project;
95
96   /**
97    * Build-directory.
98    * <p>
99    * Only needed internally.
100    *
101    * @parameter expression="${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 expression="${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 expression="${hibernate.export.scann_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 expression="${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 expression="${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 expression="${hibernate.export.force}" default-value="false"
164    */
165   private boolean force;
166
167   /**
168    * SQL-Driver name.
169    *
170    * @parameter expression="${hibernate.connection.driver_class}
171    */
172   private String driverClassName;
173
174   /**
175    * Database URL.
176    *
177    * @parameter expression="${hibernate.connection.url}"
178    */
179   private String url;
180
181   /**
182    * Database username
183    *
184    * @parameter expression="${hibernate.connection.username}"
185    */
186   private String username;
187
188   /**
189    * Database password
190    *
191    * @parameter expression="${hibernate.connection.password}"
192    */
193   private String password;
194
195   /**
196    * Hibernate dialect.
197    *
198    * @parameter expression="${hibernate.dialect}"
199    */
200   private String hibernateDialect;
201
202   /**
203    * Generate envers schema for auditing tables.
204    *
205    * @parameter expression="${hibernate.export.envers}" default-value="false"
206    */
207   private Boolean envers;
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    * @parameter expression="${hibernate.export.target}" default-value="EXPORT"
225    */
226   private String target;
227
228   /**
229    * Type of execution.
230    * <ul>
231    *   <li><strong>NONE</strong> do nothing - just validate the configuration</li>
232    *   <li><strong>CREATE</strong> create database-schema</li>
233    *   <li><strong>DROP</strong> drop database-schema</li>
234    *   <li><strong>BOTH</strong> (<strong>DEFAULT!</strong>)</li>
235    * </ul>
236    * @parameter expression="${hibernate.export.type}" default-value="BOTH"
237    */
238   private String type;
239
240   /**
241    * Output file.
242    *
243    * @parameter expression="${hibernate.export.schema.filename}" default-value="${project.build.directory}/schema.sql"
244    */
245   private String outputFile;
246
247   /**
248    * Delimiter in output-file.
249    *
250    * @parameter expression="${hibernate.export.schema.delimiter}" default-value=";"
251    */
252   private String delimiter;
253
254   /**
255    * Format output-file.
256    *
257    * @parameter expression="${hibernate.export.schema.format}" default-value="true"
258    */
259   private boolean format;
260
261
262   @Override
263   public void execute()
264     throws
265       MojoFailureException,
266       MojoExecutionException
267   {
268     if (skip)
269     {
270       getLog().info("Exectuion of hibernate4-maven-plugin:export was skipped!");
271       project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
272       return;
273     }
274
275     File dir = new File(outputDirectory);
276     if (!dir.exists())
277       throw new MojoExecutionException("Cannot scan for annotated classes in " + outputDirectory + ": directory does not exist!");
278
279     Map<String,String> md5s;
280     boolean modified = false;
281     File saved = new File(buildDirectory + File.separator + MD5S);
282
283     if (saved.exists())
284     {
285       try
286       {
287         FileInputStream fis = new FileInputStream(saved);
288         ObjectInputStream ois = new ObjectInputStream(fis);
289         md5s = (HashMap<String,String>)ois.readObject();
290         ois.close();
291       }
292       catch (Exception e)
293       {
294         md5s = new HashMap<String,String>();
295         getLog().warn("Cannot read timestamps from saved: " + e);
296       }
297     }
298     else
299     {
300       md5s = new HashMap<String,String>();
301       try
302       {
303         saved.createNewFile();
304       }
305       catch (IOException e)
306       {
307         getLog().warn("Cannot create saved for timestamps: " + e);
308       }
309     }
310
311     ClassLoader classLoader = null;
312     try
313     {
314       getLog().debug("Creating ClassLoader for project-dependencies...");
315       List<String> classpathFiles = project.getCompileClasspathElements();
316       if (scanTestClasses)
317         classpathFiles.addAll(project.getTestClasspathElements());
318       URL[] urls = new URL[classpathFiles.size()];
319       for (int i = 0; i < classpathFiles.size(); ++i)
320       {
321         getLog().debug("Dependency: " + classpathFiles.get(i));
322         urls[i] = new File(classpathFiles.get(i)).toURI().toURL();
323       }
324       classLoader = new URLClassLoader(urls, getClass().getClassLoader());
325     }
326     catch (Exception e)
327     {
328       getLog().error("Error while creating ClassLoader!", e);
329       throw new MojoExecutionException(e.getMessage());
330     }
331
332     Set<Class<?>> classes =
333         new TreeSet<Class<?>>(
334             new Comparator<Class<?>>() {
335               @Override
336               public int compare(Class<?> a, Class<?> b)
337               {
338                 return a.getName().compareTo(b.getName());
339               }
340             }
341           );
342
343     try
344     {
345       AnnotationDB db = new AnnotationDB();
346       getLog().info("Scanning directory " + outputDirectory + " for annotated classes...");
347       URL dirUrl = dir.toURI().toURL();
348       db.scanArchives(dirUrl);
349       if (scanTestClasses)
350       {
351         dir = new File(testOutputDirectory);
352         if (!dir.exists())
353           throw new MojoExecutionException("Cannot scan for annotated test-classes in " + testOutputDirectory + ": directory does not exist!");
354         getLog().info("Scanning directory " + testOutputDirectory + " for annotated classes...");
355         dirUrl = dir.toURI().toURL();
356         db.scanArchives(dirUrl);
357       }
358
359       Set<String> classNames = new HashSet<String>();
360       if (db.getAnnotationIndex().containsKey(Entity.class.getName()))
361         classNames.addAll(db.getAnnotationIndex().get(Entity.class.getName()));
362       if (db.getAnnotationIndex().containsKey(MappedSuperclass.class.getName()))
363         classNames.addAll(db.getAnnotationIndex().get(MappedSuperclass.class.getName()));
364       if (db.getAnnotationIndex().containsKey(Embeddable.class.getName()))
365         classNames.addAll(db.getAnnotationIndex().get(Embeddable.class.getName()));
366
367       MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
368       for (String name : classNames)
369       {
370         Class<?> annotatedClass = classLoader.loadClass(name);
371         classes.add(annotatedClass);
372         InputStream is =
373             annotatedClass
374                 .getResourceAsStream(annotatedClass.getSimpleName() + ".class");
375         byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks
376         int i;
377         while((i = is.read(buffer)) > -1)
378           digest.update(buffer, 0, i);
379         is.close();
380         byte[] bytes = digest.digest();
381         BigInteger bi = new BigInteger(1, bytes);
382         String newMd5 = String.format("%0" + (bytes.length << 1) + "x", bi);
383         String oldMd5 = !md5s.containsKey(name) ? "" : md5s.get(name);
384         if (!newMd5.equals(oldMd5))
385         {
386           getLog().debug("Found new or modified annotated class: " + name);
387           modified = true;
388           md5s.put(name, newMd5);
389         }
390         else
391         {
392           getLog().debug(oldMd5 + " -> class unchanged: " + name);
393         }
394       }
395     }
396     catch (ClassNotFoundException e)
397     {
398       getLog().error("Error while adding annotated classes!", e);
399       throw new MojoExecutionException(e.getMessage());
400     }
401     catch (Exception e)
402     {
403       getLog().error("Error while scanning!", e);
404       throw new MojoFailureException(e.getMessage());
405     }
406
407     if (classes.isEmpty())
408       throw new MojoFailureException("No annotated classes found in directory " + outputDirectory);
409
410     getLog().debug("Detected classes with mapping-annotations:");
411     for (Class<?> annotatedClass : classes)
412       getLog().debug("  " + annotatedClass.getName());
413
414
415     Properties properties = new Properties();
416
417     /** Try to read configuration from properties-file */
418     try
419     {
420       File file = new File(hibernateProperties);
421       if (file.exists())
422       {
423         getLog().info("Reading properties from file " + hibernateProperties + "...");
424         properties.load(new FileInputStream(file));
425       }
426       else
427         getLog().info("No hibernate-properties-file found! (Checked path: " + hibernateProperties + ")");
428     }
429     catch (IOException e)
430     {
431       getLog().error("Error while reading properties!", e);
432       throw new MojoExecutionException(e.getMessage());
433     }
434
435     /** Overwrite values from propertie-file or set, if given */
436     if (driverClassName != null)
437     {
438       if (properties.containsKey(DRIVER_CLASS))
439         getLog().debug(
440             "Overwriting property " +
441             DRIVER_CLASS + "=" + properties.getProperty(DRIVER_CLASS) +
442             " with the value " + driverClassName
443           );
444       else
445         getLog().debug("Using the value " + driverClassName);
446       properties.setProperty(DRIVER_CLASS, driverClassName);
447     }
448     if (url != null)
449     {
450       if (properties.containsKey(URL))
451         getLog().debug(
452             "Overwriting property " +
453             URL + "=" + properties.getProperty(URL) +
454             " with the value " + url
455           );
456       else
457         getLog().debug("Using the value " + url);
458       properties.setProperty(URL, url);
459     }
460     if (username != null)
461     {
462       if (properties.containsKey(USERNAME))
463         getLog().debug(
464             "Overwriting property " +
465             USERNAME + "=" + properties.getProperty(USERNAME) +
466             " with the value " + username
467           );
468       else
469         getLog().debug("Using the value " + username);
470       properties.setProperty(USERNAME, username);
471     }
472     if (password != null)
473     {
474       if (properties.containsKey(PASSWORD))
475         getLog().debug(
476             "Overwriting property " +
477             PASSWORD + "=" + properties.getProperty(PASSWORD) +
478             " with the value " + password 
479           );
480       else
481         getLog().debug("Using the value " + password);
482       properties.setProperty(PASSWORD, password);
483     }
484     if (hibernateDialect != null)
485     {
486       if (properties.containsKey(DIALECT))
487         getLog().debug(
488             "Overwriting property " +
489             DIALECT + "=" + properties.getProperty(DIALECT) +
490             " with the value " + hibernateDialect
491           );
492       else
493         getLog().debug("Using the value " + hibernateDialect);
494       properties.setProperty(DIALECT, hibernateDialect);
495     }
496     if (envers != null)
497     {
498       if (properties.containsKey(ENVERS))
499         getLog().debug(
500             "Overwriting property " +
501             ENVERS + "=" + properties.getProperty(ENVERS) +
502             " with the value " + envers
503           );
504       else
505         getLog().debug("Using the value " + envers);
506       properties.setProperty(ENVERS, envers.toString());
507     }
508
509
510     /** The generated SQL varies with the dialect! */
511     if (md5s.containsKey(DIALECT))
512     {
513       String dialect = properties.getProperty(DIALECT);
514       if (md5s.get(DIALECT).equals(dialect))
515         getLog().debug("SQL-dialect unchanged.");
516       else
517       {
518         getLog().debug("SQL-dialect changed: " + dialect);
519         modified = true;
520         md5s.put(DIALECT, dialect);
521       }
522     }
523     else
524     {
525       modified = true;
526       md5s.put(DIALECT, properties.getProperty(DIALECT));
527     }
528
529     /** The generated SQL varies with the envers-configuration! */
530     if (md5s.containsKey(ENVERS))
531     {
532       String envers = properties.getProperty(ENVERS);
533       if (md5s.get(ENVERS).equals(envers))
534         getLog().debug("Envers-configuration unchanged.");
535       else
536       {
537         getLog().debug("Envers-configuration changed: " + envers);
538         modified = true;
539         md5s.put(ENVERS, envers.toString());
540       }
541     }
542     else
543     {
544       modified = true;
545       md5s.put(ENVERS, properties.getProperty(ENVERS));
546     }
547
548     if (properties.isEmpty())
549     {
550       getLog().error("No properties set!");
551       throw new MojoFailureException("Hibernate-Configuration is missing!");
552     }
553
554     Configuration config = new Configuration();
555     config.setProperties(properties);
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     if ("true".equals(properties.getProperty(ENVERS)))
563     {
564       config.buildMappings();
565       getLog().debug("Using envers");
566       AuditConfiguration.getFor(config);
567     }
568
569
570     Target target = null;
571     try
572     {
573       target = Target.valueOf(this.target.toUpperCase());
574     }
575     catch (IllegalArgumentException e)
576     {
577       getLog().error("Invalid value for configuration-option \"target\": " + this.target);
578       getLog().error("Valid values are: NONE, SCRIPT, EXPORT, BOTH");
579       throw new MojoExecutionException("Invalid value for configuration-option \"target\"");
580     }
581     Type type = null;
582     try
583     {
584       type = Type.valueOf(this.type.toUpperCase());
585     }
586     catch (IllegalArgumentException e)
587     {
588       getLog().error("Invalid value for configuration-option \"type\": " + this.type);
589       getLog().error("Valid values are: NONE, CREATE, DROP, BOTH");
590       throw new MojoExecutionException("Invalid value for configuration-option \"type\"");
591     }
592
593     if (target.equals(Target.SCRIPT) || target.equals(Target.NONE))
594     {
595       project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
596     }
597     if (
598         !modified
599         && !target.equals(Target.SCRIPT)
600         && !target.equals(Target.NONE)
601         && !force
602       )
603     {
604       getLog().info("No modified annotated classes found and dialect unchanged.");
605       getLog().info("Skipping schema generation!");
606       project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
607       return;
608     }
609
610     getLog().info("Gathered hibernate-configuration (turn on debugging for details):");
611     for (Entry<Object,Object> entry : properties.entrySet())
612       getLog().info("  " + entry.getKey() + " = " + entry.getValue());
613
614     Connection connection = null;
615     try
616     {
617       /**
618        * The connection must be established outside of hibernate, because
619        * hibernate does not use the context-classloader of the current
620        * thread and, hence, would not be able to resolve the driver-class!
621        */
622       switch (target)
623       {
624         case EXPORT:
625         case BOTH:
626           switch (type)
627           {
628             case CREATE:
629             case DROP:
630             case BOTH:
631               Class driverClass = classLoader.loadClass(properties.getProperty(DRIVER_CLASS));
632               getLog().debug("Registering JDBC-driver " + driverClass.getName());
633               DriverManager.registerDriver(new DriverProxy((Driver)driverClass.newInstance()));
634               getLog().debug(
635                   "Opening JDBC-connection to "
636                   + properties.getProperty(URL)
637                   + " as "
638                   + properties.getProperty(USERNAME)
639                   + " with password "
640                   + properties.getProperty(PASSWORD)
641                   );
642               connection = DriverManager.getConnection(
643                   properties.getProperty(URL),
644                   properties.getProperty(USERNAME),
645                   properties.getProperty(PASSWORD)
646                   );
647           }
648       }
649     }
650     catch (ClassNotFoundException e)
651     {
652       getLog().error("Dependency for driver-class " + properties.getProperty(DRIVER_CLASS) + " is missing!");
653       throw new MojoExecutionException(e.getMessage());
654     }
655     catch (Exception e)
656     {
657       getLog().error("Cannot establish connection to database!");
658       Enumeration<Driver> drivers = DriverManager.getDrivers();
659       if (!drivers.hasMoreElements())
660         getLog().error("No drivers registered!");
661       while (drivers.hasMoreElements())
662         getLog().debug("Driver: " + drivers.nextElement());
663       throw new MojoExecutionException(e.getMessage());
664     }
665
666     ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
667     MavenLogAppender.startPluginLog(this);
668     try
669     {
670       /**
671        * Change class-loader of current thread, so that hibernate can
672        * see all dependencies!
673        */
674       Thread.currentThread().setContextClassLoader(classLoader);
675
676       SchemaExport export = new SchemaExport(config, connection);
677       export.setOutputFile(outputFile);
678       export.setDelimiter(delimiter);
679       export.setFormat(format);
680       export.execute(target, type);
681
682       for (Object exception : export.getExceptions())
683         getLog().debug(exception.toString());
684     }
685     finally
686     {
687       /** Stop Log-Capturing */
688       MavenLogAppender.endPluginLog(this);
689
690       /** Restore the old class-loader (TODO: is this really necessary?) */
691       Thread.currentThread().setContextClassLoader(contextClassLoader);
692
693       /** Close the connection */
694       try
695       {
696         if (connection != null)
697           connection.close();
698       }
699       catch (SQLException e)
700       {
701         getLog().error("Error while closing connection: " + e.getMessage());
702       }
703     }
704
705     /** Write md5-sums for annotated classes to file */
706     try
707     {
708       FileOutputStream fos = new FileOutputStream(saved);
709       ObjectOutputStream oos = new ObjectOutputStream(fos);
710       oos.writeObject(md5s);
711       oos.close();
712       fos.close();
713     }
714     catch (Exception e)
715     {
716       getLog().error("Cannot write md5-sums to file: " + e);
717     }
718   }
719
720   /**
721    * Needed, because DriverManager won't pick up drivers, that were not
722    * loaded by the system-classloader!
723    * See:
724    * http://stackoverflow.com/questions/288828/how-to-use-a-jdbc-driver-fromodifiedm-an-arbitrary-location
725    */
726   static final class DriverProxy implements Driver
727   {
728     private final Driver target;
729
730     DriverProxy(Driver target)
731     {
732       if (target == null)
733         throw new NullPointerException();
734       this.target = target;
735     }
736
737     public java.sql.Driver getTarget()
738     {
739       return target;
740     }
741
742     @Override
743     public boolean acceptsURL(String url) throws SQLException
744     {
745       return target.acceptsURL(url);
746     }
747
748     @Override
749     public java.sql.Connection connect(
750         String url,
751         java.util.Properties info
752       )
753       throws
754         SQLException
755     {
756       return target.connect(url, info);
757     }
758
759     @Override
760     public int getMajorVersion()
761     {
762       return target.getMajorVersion();
763     }
764
765     @Override
766     public int getMinorVersion()
767     {
768       return target.getMinorVersion();
769     }
770
771     @Override
772     public DriverPropertyInfo[] getPropertyInfo(
773         String url,
774         Properties info
775       )
776       throws
777         SQLException
778     {
779       return target.getPropertyInfo(url, info);
780     }
781
782     @Override
783     public boolean jdbcCompliant()
784     {
785       return target.jdbcCompliant();
786     }
787
788     /**
789      * This Method cannot be annotated with @Override, becaus the plugin
790      * will not compile then under Java 1.6!
791      */
792     public Logger getParentLogger() throws SQLFeatureNotSupportedException
793     {
794       throw new SQLFeatureNotSupportedException("Not supported, for backward-compatibility with Java 1.6");
795     }
796
797     @Override
798     public String toString()
799     {
800       return "Proxy: " + target;
801     }
802
803     @Override
804     public int hashCode()
805     {
806       return target.hashCode();
807     }
808
809     @Override
810     public boolean equals(Object obj)
811     {
812       if (!(obj instanceof DriverProxy))
813         return false;
814       DriverProxy other = (DriverProxy) obj;
815       return this.target.equals(other.target);
816     }
817   }
818 }