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