Class JPASchemaGenMojo

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

    @Mojo(name="generate",
          defaultPhase=PROCESS_TEST_CLASSES,
          requiresDependencyResolution=TEST,
          threadSafe=true)
    @Execute(phase=TEST_COMPILE)
    public class JPASchemaGenMojo
    extends org.apache.maven.plugin.AbstractMojo
    This plugin will generate SQL schema for a specified persistence unit. It is targeted/tuned to have the features desired for use with the ejava course examples. Thus it inserts hibernate-specific extensions to enable pretty-printing and line terminators. Use this as an example of how you could create something more general purpose if you would like.
    • Field Detail

      • persistenceUnit

        @Parameter(property="persistenceUnit",
                   required=false)
        private String persistenceUnit
        The name of the persistence unit from within META-INF/persistence.xml. Only required if there are multiple persistence units within the project. Otherwise, it will use the only one found in the path.
      • createPath

        @Parameter(property="createPath",
                   required=false,
                   defaultValue="target/classes/ddl/${persistenceUnit}-create.ddl")
        private String createPath
        The path to write the create script.
      • dropPath

        @Parameter(property="dropPath",
                   required=false,
                   defaultValue="target/classes/ddl/${persistenceUnit}-drop.ddl")
        private String dropPath
        The path to write the drop script.
      • delimiter

        @Parameter(property="delimiter",
                   required=false,
                   defaultValue=";")
        private String delimiter
        Statement termination string
      • format

        @Parameter(property="format",
                   required=false,
                   defaultValue="true")
        private boolean format
      • scriptsAction

        @Parameter(property="scriptsAction",
                   required=false,
                   defaultValue="drop-and-create")
        private String scriptsAction
      • schemagenUrl

        @Parameter(property="schemagenUrl",
                   required=false,
                   defaultValue="jdbc:h2:mem:")
        private String schemagenUrl
        Alternate JDBC URL used only for schemagen plugin. For whatever reason, Hibernate requires a database connection when generating database schema to file and unfortunately leaves a session hanging open and the database file locked when using a file-based database. This setting helps avoid DB locks for file-based, local databases. The default is to use the H2 in-memory database.
      • schemagenUser

        @Parameter(property="schemagenUser",
                   required=false,
                   defaultValue="")
        private String schemagenUser
        Username for the alternate DB referenced by schemagenUrl.
      • schemagenPassword

        @Parameter(property="schemagenPassword",
                   required=false,
                   defaultValue="")
        private String schemagenPassword
        Password for the alternateDB referenced by schemagenUrl.
      • schemagenDriver

        @Parameter(property="schemagenDriver",
                   required=false,
                   defaultValue="org.h2.Driver")
        private String schemagenDriver
        JDBC driver for schemagen JDBC URL. Used only if schemagenUrl is supplied and will default to the driver appropriate for the default value of schemagenUrl.
      • project

        @Parameter(property="project",
                   required=true,
                   defaultValue="${project}")
        private org.apache.maven.project.MavenProject project
        Describes the entire project.
    • Constructor Detail

      • JPASchemaGenMojo

        public JPASchemaGenMojo()
    • Method Detail

      • resolvePath

        protected String resolvePath​(String path)
      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoFailureException
      • findPersistenceUnit

        protected String findPersistenceUnit​(ClassLoader clsLoader)
                                      throws org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoFailureException
      • loadBeforeClosing

        protected void loadBeforeClosing()
                                  throws org.apache.maven.plugin.MojoFailureException
        kludge to try to avoid an ugly non-fatal stack trace of missing classes when plugin shuts down (closing the classloader) and the database attempts to load new classes to complete its thread shutdown.
        Throws:
        org.apache.maven.plugin.MojoFailureException
      • setPersistenceUnit

        public void setPersistenceUnit​(String puName)
      • setProject

        public void setProject​(org.apache.maven.project.MavenProject project)
      • setCreatePath

        public void setCreatePath​(String createPath)
      • setDropPath

        public void setDropPath​(String dropPath)
      • setDelimiter

        public void setDelimiter​(String delimiter)
      • setFormat

        public void setFormat​(boolean format)
      • setScriptsAction

        public void setScriptsAction​(String scriptsAction)