X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fplugins%2Fhibernate4%2FHbm2DdlMojo.java;h=a7eab4ce6718c4084025bdedf901cee227c5ed8a;hb=refs%2Fheads%2Fvtatai;hp=3b3a72b79137b1d7a46b4d19775e3f4c40ff838f;hpb=bf5e8c39287713b9eb236ca441473f723059357a;p=hibernate4-maven-plugin diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index 3b3a72b7..a7eab4ce 100644 --- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java @@ -53,6 +53,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.hibernate.cfg.Configuration; +import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.hbm2ddl.SchemaExport.Type; import org.hibernate.tool.hbm2ddl.Target; @@ -77,6 +78,7 @@ public class Hbm2DdlMojo extends AbstractMojo public final static String USERNAME = "hibernate.connection.username"; public final static String PASSWORD = "hibernate.connection.password"; public final static String DIALECT = "hibernate.dialect"; + public final static String ENVERS = "hibernate.export.envers"; private final static String MD5S = "schema.md5s"; @@ -197,6 +199,13 @@ public class Hbm2DdlMojo extends AbstractMojo */ private String hibernateDialect; + /** + * Generate envers schema for auditing tables. + * + * @parameter expression="${hibernate.export.envers}" default-value="false" + */ + private Boolean envers; + /** * Path to Hibernate configuration file. * @@ -484,6 +493,19 @@ public class Hbm2DdlMojo extends AbstractMojo getLog().debug("Using the value " + hibernateDialect); properties.setProperty(DIALECT, hibernateDialect); } + if (envers != null) + { + if (properties.containsKey(ENVERS)) + getLog().debug( + "Overwriting property " + + ENVERS + "=" + properties.getProperty(ENVERS) + + " with the value " + envers + ); + else + getLog().debug("Using the value " + envers); + properties.setProperty(ENVERS, envers.toString()); + } + /** The generated SQL varies with the dialect! */ if (md5s.containsKey(DIALECT)) @@ -504,6 +526,25 @@ public class Hbm2DdlMojo extends AbstractMojo md5s.put(DIALECT, properties.getProperty(DIALECT)); } + /** The generated SQL varies with the envers-configuration! */ + if (md5s.containsKey(ENVERS)) + { + String envers = properties.getProperty(ENVERS); + if (md5s.get(ENVERS).equals(envers)) + getLog().debug("Envers-configuration unchanged."); + else + { + getLog().debug("Envers-configuration changed: " + envers); + modified = true; + md5s.put(ENVERS, envers.toString()); + } + } + else + { + modified = true; + md5s.put(ENVERS, properties.getProperty(ENVERS)); + } + if (properties.isEmpty()) { getLog().error("No properties set!"); @@ -518,6 +559,13 @@ public class Hbm2DdlMojo extends AbstractMojo getLog().debug("Class " + annotatedClass); config.addAnnotatedClass(annotatedClass); } + if ("true".equals(properties.getProperty(ENVERS))) + { + config.buildMappings(); + getLog().debug("Using envers"); + AuditConfiguration.getFor(config); + } + Target target = null; try