Example usage for org.hibernate.tool.hbm2ddl SchemaExport execute

List of usage examples for org.hibernate.tool.hbm2ddl SchemaExport execute

Introduction

In this page you can find the example usage for org.hibernate.tool.hbm2ddl SchemaExport execute.

Prototype

@SuppressWarnings("unchecked")
    public void execute(EnumSet<TargetType> targetTypes, Action action, Metadata metadata,
            ServiceRegistry serviceRegistry) 

Source Link

Usage

From source file:com.github.gekoh.yagen.ddl.DDLGenerator.java

License:Apache License

public void writeDDL(Profile profile) {
    SchemaExport export = new SchemaExportFactory().createSchemaExport(profile);
    export.setDelimiter(";");
    export.setFormat(true);//from   ww w  . j a va2 s. c  om
    export.setOutputFile(profile.getOutputFile());
    export.execute(true, false, false, true);

    LOG.info("schema script written to file {}", profile.getOutputFile());
}

From source file:com.imos.sample.service.HibernateService.java

/**
 * Hibernate configuration.//  w w w  .j ava 2  s.com
 *
 * @throws RepositoryException
 */
public void config() throws RepositoryException {
    try {
        StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
        if (filePath == null || filePath.isEmpty()) {
            registryBuilder = registryBuilder.configure();
        } else {
            registryBuilder = registryBuilder.configure(filePath);
        }
        registry = registryBuilder.build();

        MetadataSources metaData = new MetadataSources(registry);
        sessionFactory = metaData.buildMetadata().buildSessionFactory();
        session = sessionFactory.openSession();

        SchemaExport schemaExport = new SchemaExport();
        schemaExport.setDelimiter(";");
        schemaExport.setFormat(true);
        schemaExport.setManageNamespaces(true);
        schemaExport.setOutputFile("./ddl_skilldb.sql");
        schemaExport.execute(EnumSet.of(TargetType.SCRIPT, TargetType.DATABASE, TargetType.STDOUT),
                SchemaExport.Action.CREATE, metaData.buildMetadata(registry), registry);

        log.info("Configuration succeed");
    } catch (HibernateException e) {
        StandardServiceRegistryBuilder.destroy(registry);
        log.error("Configuration failed : {}", e);
    }
}

From source file:com.jada.jpa.util.JpaSchemaExport.java

License:Open Source License

public void export() throws Exception {
    AnnotationConfiguration configuration = new AnnotationConfiguration();
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    PersistenceLoader persistenceLoader = PersistenceLoader.getInstance();
    Persistence persistence = persistenceLoader.getPersistence();
    for (String className : persistence.getPersistenceUnit().getClassNames()) {
        Class<?> c = Class.forName(className);
        configuration.addAnnotatedClass(c);
    }/*www .  java  2 s .  c o  m*/

    configuration.setProperty("hibernate.dialect", dialectName);
    SchemaExport exporter = new SchemaExport(configuration);
    exporter.setDelimiter(";");
    exporter.setOutputFile(fileName);

    boolean script = true;
    boolean export = false;
    boolean justDrop = false;
    boolean justCreate = false;
    exporter.execute(script, export, justDrop, justCreate);
}

From source file:com.okasamastarr.CreateDdlMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {//from w  w  w.j a  v a2 s.c  o  m
        Thread.currentThread().setContextClassLoader(createProjectClassLoader());
        Configuration cfg = createHibernateConfiguration(persistenceUnit);

        Properties props = new Properties();
        if (propFile != null) {
            props.load(new FileInputStream(propFile));
        }
        cfg.setProperties(props);
        if (dialect != null) {
            props.setProperty("hibernate.dialect", dialect);
        }
        if (importFile != null) {
            props.setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES, importFile);
        }

        SchemaExport schemaExport = new SchemaExport(cfg).setOutputFile(outputFile).setFormat(format)
                .setDelimiter(delimeter);
        schemaExport.execute(script, export, drop, create);
    } catch (Throwable ex) {
        throw new MojoExecutionException("Failed to create DDL schema", ex);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}

From source file:com.premiumminds.persistence.utils.HibernateEnversDDL.java

License:Open Source License

private static void createCommand(String[] args) {
    String unitName;//from  ww  w. j av  a2 s  . c  om
    String filename = null;
    if (args.length < 2)
        System.out.println("Expected unitName");
    else {
        unitName = args[1];
        if (args.length > 2)
            filename = args[2];

        EnversSchemaGenerator esg = new EnversSchemaGenerator(HibernateDDL.getConfiguration(unitName));
        org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export();
        se.setOutputFile(filename);
        se.setFormat(true);
        se.setDelimiter(";");
        se.execute(false, false, false, true);
    }
}

From source file:com.premiumminds.persistence.utils.HibernateEnversDDL.java

License:Open Source License

private static void createDropCommand(String[] args) {
    String unitName;//from  w w w.ja  v  a2 s .  c  o m
    String filename = null;
    if (args.length < 2)
        System.out.println("Expected unitName");
    else {
        unitName = args[1];
        if (args.length > 2)
            filename = args[2];

        EnversSchemaGenerator esg = new EnversSchemaGenerator(HibernateDDL.getConfiguration(unitName));
        org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export();
        se.setOutputFile(filename);
        se.setFormat(true);
        se.setDelimiter(";");
        se.execute(false, false, true, true);
    }
}

From source file:com.scopix.periscope.frameworksfoundation.hibernate.SchemaExportHelper.java

License:Open Source License

/**
 * This method deletes all tables and regenerates them. It produces total lost of information.
 *//*from   w  w w  .  j  av  a  2 s  . c  om*/
public void resetSchemaDB() {

    Connection connection = null;
    try {

        connection = DataSourceUtils.getConnection(this.dataSource);

        AnnotationConfiguration conf = HibernateConfigurationHolder.conf;
        SchemaExport export = new SchemaExport(conf, connection);
        export.execute(false, true, false, false);

    } catch (HibernateException e) {
        throw new UnexpectedRuntimeException(e);
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            throw new UnexpectedRuntimeException(e);
        }

    }
}

From source file:com.ttech.cordovabuild.infrastructure.DDLExport.java

License:Apache License

@Test
public void exportDDL() {

    Formatter formatter = FormatStyle.DDL.getFormatter();

    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure("cordova", null);
    Configuration hibernateConfiguration = jpaConfiguration.getHibernateConfiguration();
    SchemaExport export = new SchemaExport(hibernateConfiguration);
    export.setOutputFile("my-schema.sql");
    export.setDelimiter(";");
    export.execute(true, false, false, true);
}

From source file:com.userweave.config.MPSchemaExport.java

License:Open Source License

/**
 * @param args/*ww w.j  av  a2s.com*/
 */
public static void main(String[] args) {

    //      if (args.length != 1) {
    //         System.out.println("please specify output filename");
    //      }
    //      
    String filename = "schema.ddl";//args[0];

    final AnnotationConfiguration configuration = new AnnotationConfiguration();

    final Properties properties = new Properties();
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
    configuration.setProperties(properties);

    SchemaExport export = new SchemaExport(configuration);
    export.setDelimiter(";");
    export.setFormat(true);

    File outputFile = new File(filename);
    export.setOutputFile(outputFile.toString());
    export.execute(false, false, false, true);
}

From source file:com.vecna.maven.hibernate.HibernateSchemaExportMojo.java

License:Apache License

/**
 * Exports the schema./* w  ww. j  a v a 2  s.com*/
 * {@inheritDoc}
 */
@Override
protected void executeWithMappings(Configuration configuration)
        throws MojoExecutionException, MojoFailureException {
    SchemaExport schemaExport = new SchemaExport(configuration);
    schemaExport.setFormat(format);

    if (outputFile != null) {
        initializePath();
        schemaExport.setOutputFile(outputFile);
        schemaExport.setDelimiter(delimiter);
    }

    schemaExport.execute(print, export, false, !drop);
}