Class GenerateDdlMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="gen-ddl",
          defaultPhase=PROCESS_CLASSES,
          requiresDependencyResolution=COMPILE_PLUS_RUNTIME,
          threadSafe=true)
    public class GenerateDdlMojo
    extends org.apache.maven.plugin.AbstractMojo
    Base class the the Mojo class providing the gen-ddl goal. In the plugins it should be enough to create an empty class which extends this class and is annotated with the Mojo annotation.
    Author:
    Jens Pelzetter
    • Field Detail

      • DEFAULT_PROPERTIES_TO_USE

        private static final String[] DEFAULT_PROPERTIES_TO_USE
      • outputDirectory

        @Parameter(defaultValue="${project.build.directory}/generated-resources/sql/ddl/auto",
                   property="outputDir",
                   required=true)
        private File outputDirectory
        Location of the output file.
      • outputFileNamePrefix

        @Parameter(required=false,
                   defaultValue="")
        private String outputFileNamePrefix
        If set each name of an output file will be prefixed with the value of this parameter.
      • outputFileNameSuffix

        @Parameter(required=false,
                   defaultValue="")
        private String outputFileNameSuffix
        If set the value of this parameter will be appended to the name of each output file.
      • omitDialectFromFileName

        @Parameter(required=false)
        private boolean omitDialectFromFileName
        If set to true and if only one dialect is configured and either outputFileNamePrefix or outputFileNameSuffix are set the dialect name will be omitted from the name of the DDL file.
      • packages

        @Parameter(required=false)
        private String[] packages
        Packages containing the entity files for which the SQL DDL scripts shall be generated.
      • includeTestClasses

        @Parameter(required=false)
        private boolean includeTestClasses
        Set to true to include classes in src/test.
      • dialects

        @Parameter(required=false)
        private String[] dialects
        Database dialects for which create scripts shall be generated. For available dialects refer to the documentation the Dialect enumeration.
      • customDialects

        @Parameter(required=false)
        private String[] customDialects
      • createDropStatements

        @Parameter(required=false)
        private boolean createDropStatements
        Set this to true to include drop statements into the generated DDL file.
      • persistenceXml

        @Parameter(defaultValue="${basedir}/src/main/resources/META-INF/persistence.xml",
                   required=false)
        private File persistenceXml
        The 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.
      • persistencePropertiesToUse

        @Parameter(required=false)
        private String[] persistencePropertiesToUse
      • persistenceProperties

        @Parameter(required=false)
        private Map<String,​String> persistenceProperties
      • project

        @Parameter(defaultValue="${project}",
                   readonly=true)
        private transient org.apache.maven.project.MavenProject project
    • Constructor Detail

      • GenerateDdlMojo

        public GenerateDdlMojo()
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        The Mojo's execute method.
        Throws:
        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.
      • getOutputDirectory

        public File getOutputDirectory()
      • setOutputDirectory

        public void setOutputDirectory​(File outputDirectory)
      • getOutputFileNamePrefix

        public String getOutputFileNamePrefix()
      • setOutputFileNamePrefix

        public void setOutputFileNamePrefix​(String outputFileNamePrefix)
      • getOutputFileNameSuffix

        public String getOutputFileNameSuffix()
      • setOutputFileNameSuffix

        public void setOutputFileNameSuffix​(String outputFileNameSuffix)
      • isOmitDialectFromFileName

        public boolean isOmitDialectFromFileName()
      • setOmitDialectFromFileName

        public void setOmitDialectFromFileName​(boolean omitDialectFromFileName)
      • getPackages

        public String[] getPackages()
      • setPackages

        public void setPackages​(String... packages)
      • getDialects

        public String[] getDialects()
      • setDialects

        public void setDialects​(String... dialects)
      • getCustomDialects

        public String[] getCustomDialects()
      • setCustomDialects

        public void setCustomDialects​(String... customDialects)
      • isCreateDropStatements

        public boolean isCreateDropStatements()
      • setCreateDropStatements

        public void setCreateDropStatements​(boolean createDropStatments)
      • getPersistenceXml

        public File getPersistenceXml()
      • setPersistenceXml

        public void setPersistenceXml​(File persistenceXml)
      • getPersistencePropertiesToUse

        public String[] getPersistencePropertiesToUse()
      • setPersistencePropertiesToUse

        public void setPersistencePropertiesToUse​(String... persistencePropertiesToUse)
      • getPersistenceProperties

        public Map<String,​String> getPersistenceProperties()
      • setPersistenceProperties

        public void setPersistenceProperties​(Map<String,​String> persistenceProperties)
      • getProject

        protected org.apache.maven.project.MavenProject getProject()
      • setProject

        protected void setProject​(org.apache.maven.project.MavenProject project)
      • isIncludeTestClasses

        public boolean isIncludeTestClasses()
      • setIncludeTestClasses

        public void setIncludeTestClasses​(boolean includeTestClasses)
      • convertDialects

        private Set<Dialect> convertDialects()
                                      throws org.apache.maven.plugin.MojoFailureException
        Helper method which reads the dialects from the parameter and converts them into instances of the Dialect enumeration.
        Returns:
        A list of all dialects to use
        Throws:
        org.apache.maven.plugin.MojoFailureException - If an error occurs.
      • convertDialect

        private void convertDialect​(String dialect,
                                    Set<Dialect> dialectsList)
                             throws org.apache.maven.plugin.MojoFailureException
        Helper method for converting the dialects from String to instances of the Dialect enumeration.
        Parameters:
        dialect - The dialect to convert.
        dialectsList - The lists of dialects where the converted dialect is stored.
        Throws:
        org.apache.maven.plugin.MojoFailureException - If the dialect string could not be converted, for example if it is misspelled. This will cause a Build Failure
      • writeOutputFile

        protected void writeOutputFile​(String dialectClassName,
                                       Path tmpDir)
                                throws org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoFailureException
      • getDialectNameFromClassName

        public String getDialectNameFromClassName​(String dialectClassName)