Package ejava.utils.jpa
Class JPASchemaGenMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- ejava.utils.jpa.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.AbstractMojoThis 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 Summary
Fields Modifier and Type Field Description private StringcreatePathThe path to write the create script.private StringdelimiterStatement termination stringprivate StringdropPathThe path to write the drop script.private booleanformatprivate StringpersistenceUnitThe name of the persistence unit from within META-INF/persistence.xml.private org.apache.maven.project.MavenProjectprojectDescribes the entire project.private StringschemagenDriverJDBC driver for schemagen JDBC URL.private StringschemagenPasswordPassword for the alternateDB referenced by schemagenUrl.private StringschemagenUrlAlternate JDBC URL used only for schemagen plugin.private StringschemagenUserUsername for the alternate DB referenced by schemagenUrl.private StringscriptsAction
-
Constructor Summary
Constructors Constructor Description JPASchemaGenMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,Object>configure()voidexecute()protected StringfindPersistenceUnit(ClassLoader clsLoader)protected URLClassLoadergetClassLoader()protected voidloadBeforeClosing()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.protected StringresolvePath(String path)voidsetCreatePath(String createPath)voidsetDelimiter(String delimiter)voidsetDropPath(String dropPath)voidsetFormat(boolean format)voidsetPersistenceUnit(String puName)voidsetProject(org.apache.maven.project.MavenProject project)voidsetScriptsAction(String scriptsAction)
-
-
-
Field Detail
-
persistenceUnit
@Parameter(property="persistenceUnit", required=false) private String persistenceUnitThe 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 createPathThe path to write the create script.
-
dropPath
@Parameter(property="dropPath", required=false, defaultValue="target/classes/ddl/${persistenceUnit}-drop.ddl") private String dropPathThe path to write the drop script.
-
delimiter
@Parameter(property="delimiter", required=false, defaultValue=";") private String delimiterStatement 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 schemagenUrlAlternate 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 schemagenUserUsername for the alternate DB referenced by schemagenUrl.
-
schemagenPassword
@Parameter(property="schemagenPassword", required=false, defaultValue="") private String schemagenPasswordPassword for the alternateDB referenced by schemagenUrl.
-
schemagenDriver
@Parameter(property="schemagenDriver", required=false, defaultValue="org.h2.Driver") private String schemagenDriverJDBC 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 projectDescribes the entire project.
-
-
Method Detail
-
getClassLoader
protected URLClassLoader getClassLoader() throws org.apache.maven.artifact.DependencyResolutionRequiredException, MalformedURLException
- Throws:
org.apache.maven.artifact.DependencyResolutionRequiredExceptionMalformedURLException
-
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.MojoFailureExceptionkludge 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)
-
-