Package com.lissenberg.blog.util

Source Code of com.lissenberg.blog.util.SchemaExporter

package com.lissenberg.blog.util;

import org.hibernate.cfg.Configuration;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;

/**
* Util class to export DDL schema from JPA persistence entities & configuration
*
* @author Harro Lissenberg
*/
public class SchemaExporter {


    public static void main(String[] args) {
        SchemaExporter exporter = new SchemaExporter();
        exporter.createDerbySchema();
        exporter.createMySqlSchema();
    }

  private void createDerbySchema() {
    Configuration cfg = new Ejb3Configuration().configure("in-memory-test-db", null).getHibernateConfiguration();
    new SchemaExport(cfg)
        .setOutputFile("schema-export-derby.sql")
        .setDelimiter(";")
        .setFormat(true)
        .create(false, true);
  }

  private void createMySqlSchema() {
    Configuration cfg = new Ejb3Configuration().configure("in-memory-test-db", null).getHibernateConfiguration();
    // override the Derby dialect used in tests
    cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
    new SchemaExport(cfg)
        .setOutputFile("schema-export-mysql.sql")
        .setDelimiter(";")
        .setFormat(true)
        .create(false, true);
  }

}
TOP

Related Classes of com.lissenberg.blog.util.SchemaExporter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.