@Mojo(name="gen-ddl",
defaultPhase=PROCESS_CLASSES,
requiresDependencyResolution=COMPILE_PLUS_RUNTIME,
threadSafe=true)
public class GenerateDdlMojo
extends org.apache.maven.plugin.AbstractMojo
| Modifier and Type | Class and Description |
|---|---|
private class |
GenerateDdlMojo.PersistenceXmlHandler |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
createDropStatments
Set this to
true to include drop statements into the generated
DDL file. |
private String[] |
dialects
Database dialects for which create scripts shall be generated.
|
private File |
outputDirectory
Location of the output file.
|
private String[] |
packages
Packages containing the entity files for which the SQL DDL scripts shall
be generated.
|
private File |
persistenceXml
The
persistence.xml file to use to read properties etc. |
private org.apache.maven.project.MavenProject |
project |
private boolean |
useEnvers
Set this to
true if you use the Envers feature of Hibernate. |
| Constructor and Description |
|---|
GenerateDdlMojo() |
| Modifier and Type | Method and Description |
|---|---|
private void |
convertDialect(String dialect,
Set<Dialect> dialectsList)
Helper method for converting the dialects from
String to
instances of the Dialect enumeration. |
private void |
createOutputDir()
Helper for creating the output directory if it does not exist.
|
private Path |
createOutputFilePath(Dialect dialect) |
void |
execute()
The Mojo's execute method.
|
private void |
generateDdl(Dialect dialect,
Set<Class<?>> entityClasses)
Helper method for generating the DDL classes for a specific dialect.
|
String[] |
getDialects() |
File |
getOutputDirectory() |
String[] |
getPackages() |
File |
getPersistenceXml() |
boolean |
isCreateDropStatments() |
boolean |
isUseEnvers() |
private void |
processPersistenceXml(Configuration configuration) |
void |
setCreateDropStatements(boolean createDropStatments) |
void |
setDialects(String... dialects) |
void |
setOutputDirectory(File outputDirectory) |
void |
setPackages(String... packages) |
void |
setPersistenceXml(File persistenceXml) |
void |
setUseEnvers(boolean useEnvers) |
private void |
writeOutputFile(Dialect dialect,
Path tmpDir)
Helper method for writing the output files if necessary.
|
@Parameter(defaultValue="${project.build.directory}/generated-resources/sql/ddl/auto",
property="outputDir",
required=true)
private File outputDirectory
@Parameter(required=true) private String[] packages
@Parameter(required=true) private String[] dialects
Dialect
enumeration.@Parameter(required=false) private boolean useEnvers
true if you use the Envers feature of Hibernate.
When set to true the SchemaExport implementation for
Envers is used. This is necessary to create the additional tables
required by Envers. Default value is false.@Parameter(required=false) private boolean createDropStatments
true to include drop statements into the generated
DDL file.@Parameter(defaultValue="${basedir}/src/main/resources/META-INF/persistence.xml",
required=false)
private File persistenceXml
persistence.xml file to use to read properties etc. Default
value is src/main/resources/META-INF/persistence.xml. If the file
is not present it is ignored. If the file is present all properties set
using a <property> element are set on the Hibernate
configuration.@Component private transient org.apache.maven.project.MavenProject project
public void execute()
throws org.apache.maven.plugin.MojoExecutionException,
org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException - if the Mojo can't be executed.org.apache.maven.plugin.MojoFailureException - if something goes wrong while to Mojo is
executed.public File getOutputDirectory()
public void setOutputDirectory(File outputDirectory)
public String[] getPackages()
public void setPackages(String... packages)
public String[] getDialects()
public void setDialects(String... dialects)
public boolean isUseEnvers()
public void setUseEnvers(boolean useEnvers)
public boolean isCreateDropStatments()
public void setCreateDropStatements(boolean createDropStatments)
public File getPersistenceXml()
public void setPersistenceXml(File persistenceXml)
private void convertDialect(String dialect, Set<Dialect> dialectsList) throws org.apache.maven.plugin.MojoFailureException
String to
instances of the Dialect enumeration.dialect - The dialect to convert.dialectsList - The lists of dialects where the converted dialect is
stored.org.apache.maven.plugin.MojoFailureException - If the dialect string could not be
converted, for example if it is misspelled.
This will cause a Build Failureprivate void generateDdl(Dialect dialect, Set<Class<?>> entityClasses) throws org.apache.maven.plugin.MojoFailureException
Configuration class from Hibernate an puts the appropriate
values into it. It then creates an instance of the SchemaExport
class from the Hibernate API, configured this class, for example by
setting format to true so that the generated SQL files
are formatted nicely. After that it calls the
SchemaExport.execute(boolean, boolean, boolean, boolean) method
which will create the SQL script file. The method is called in a way
which requires no database connection.dialect - The dialect for which the DDL files is generated.entityClasses - The entity classes for which the DDL file is
generated.org.apache.maven.plugin.MojoFailureException - if something goes wrong.private void processPersistenceXml(Configuration configuration)
private void writeOutputFile(Dialect dialect, Path tmpDir) throws org.apache.maven.plugin.MojoFailureException
generateDdl(Dialect, Set) method writes the output to temporary
files. This method checks of the output files have changed and copies the
files if necessary.org.apache.maven.plugin.MojoFailureExceptionprivate void createOutputDir()
throws org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoFailureException - If The creation of the output directory
fails.Copyright © 2014–2016 Jens Pelzetter. All rights reserved.