All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.mvn.Hbm2DdlMojo Maven / Gradle / Ivy

Go to download

Maven plugin to provide hibernate-tools reverse engineering and code/schema generation abilities.

There is a newer version: 5.6.15.Final
Show newest version
package org.hibernate.mvn;

import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.hibernate.boot.Metadata;
import org.hibernate.tool.api.metadata.MetadataDescriptor;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;

import java.io.File;
import java.util.EnumSet;
import java.util.Set;

import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_RESOURCES;

/**
 * Mojo to generate DDL Scripts from an existing database.
 * 

* See https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4651 */ @Mojo(name = "hbm2ddl", defaultPhase = GENERATE_RESOURCES) public class Hbm2DdlMojo extends AbstractHbm2xMojo { /** The directory into which the DDLs will be generated. */ @Parameter(defaultValue = "${project.build.directory}/generated-resources/") private File outputDirectory; /** The default filename of the generated DDL script. */ @Parameter(defaultValue = "schema.ddl") private String outputFileName; /** The type of output to produce. *

    *
  • DATABASE: Export to the database.
  • *
  • SCRIPT (default): Write to a script file.
  • *
  • STDOUT: Write to {@link System#out}.
  • *
*/ @Parameter(defaultValue = "SCRIPT") private Set targetTypes; /** * The DDLs statements to create. *
    *
  • NONE: None - duh :P.
  • *
  • CREATE (default): Create only.
  • *
  • DROP: Drop only.
  • *
  • BOTH: Drop and then create.
  • *
*/ @Parameter(defaultValue = "CREATE") private SchemaExport.Action schemaExportAction; /** Set the end of statement delimiter. */ @Parameter(defaultValue = ";") private String delimiter; /** Should we format the sql strings? */ @Parameter(defaultValue = "true") private boolean format; /** Should we stop once an error occurs? */ @Parameter(defaultValue = "true") private boolean haltOnError; @Override protected void executeExporter(MetadataDescriptor metadataDescriptor) { Metadata metadata = metadataDescriptor.createMetadata(); SchemaExport export = new SchemaExport(); export.setOutputFile(new File(outputDirectory, outputFileName).toString()); export.setDelimiter(delimiter); export.setHaltOnError(haltOnError); export.setFormat(format); export.execute(EnumSet.copyOf(this.targetTypes), schemaExportAction, metadata); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy