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

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

Introduction

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

Prototype

public void create(EnumSet<TargetType> targetTypes, Metadata metadata) 

Source Link

Usage

From source file:conexao.GeraTabelas.java

public static void main(String[] args) {

    Configuration conf = new AnnotationConfiguration();
    conf.configure();/*from  ww  w. ja  v  a 2 s  .  c  o  m*/
    SchemaExport se = new SchemaExport(conf);
    se.create(true, true);
}

From source file:connectster.server.HibernateUtility.java

License:Apache License

public static void createDatabase() {
    SchemaExport schema = new SchemaExport(configuration);
    schema.create(true, true);
}

From source file:dao.conexao.GerarBanco.java

public static void main(String[] args) {
    Configuration conf = new AnnotationConfiguration();
    conf.configure();//from w ww.j a v a2  s  .c o  m
    SchemaExport se = new SchemaExport(conf);
    se.create(true, true);
}

From source file:de.evjnw.jlk.work.impl.DaoFactoryImpl.java

License:Apache License

/**
 * @param user//from ww  w  . ja v a  2  s  .co  m
 *            technischer Benutzer an der Datenbank
 * @param password
 *            Passwort des technischen Benutzers an der Datenbank
 * @throws DaoConfigurationException 
 *          wenn bei der Verarbeitung der Hibernate Configuration ein Fehler auftritt
 */
public DaoFactoryImpl(String user, String password) throws DaoConfigurationException {
    // TODO: user und password merken?
    try {
        // frhzeitig die Konfiguration laden und so Fehler bemerken
        Configuration configuration = loadConfiguration();
        if (exportSchemaForTests) {
            SchemaExport export = new SchemaExport(configuration);
            export.setOutputFile("create_jlk.sql");
            boolean writeScript = true;
            boolean executeDdl = true;
            export.create(writeScript, executeDdl);
        }
    } catch (HibernateException he) {
        throw new DaoConfigurationException(he.getMessage(), he);
    }
}

From source file:de.tudarmstadt.ukp.lmf.transform.LMFDBUtils.java

License:Apache License

/**
 * Create all LMF Tables in the database based on the hibernate mapping
 * @param dbConfig/*from  ww  w  .j  a  v a2  s.c  o  m*/
 * @throws FileNotFoundException
 */
public static void createTables(DBConfig dbConfig) throws FileNotFoundException {
    // public static  void createTables(DBConfig dbConfig/*, boolean constraints*/) 
    System.out.println("CREATE TABLES");
    Configuration cfg = HibernateConnect.getConfiguration(dbConfig);
    cfg.setProperty("hibernate.hbm2ddl.auto", "none");
    SchemaExport se = new SchemaExport(cfg);
    se.create(true, true);

    /*if (constraints) {
       turnOnConstraints(dbConfig);
    }*/
}

From source file:de.xwic.sandbox.server.installer.InstallationManager.java

License:Apache License

/**
 * Export the database schema based on the hibernate configuration to the database. This drops the database.
 *//* w  w w.  jav  a  2  s.  c  o m*/
public void schemaExport() throws IOException {

    log.info("Initialize database requested.");

    Configuration cfg = createHibernateConfiguration();

    SchemaExport export = new SchemaExport(cfg);
    export.create(true, true);

    log.info("The schema export has been finished successfully.");

}

From source file:edu.udo.scaffoldhunter.model.db.DbManagerHibernate.java

License:Open Source License

@Override
public void createAndExportSchema() throws DatabaseException {
    Connection dbConnection = getNativeDbConnection();

    // drop and recreate schema
    try {//from  w  w w . j  ava 2  s. co m
        Statement setupStatement = dbConnection.createStatement();
        if (hibernateDialect.equals(MySQL5InnoDBDialect.class.getCanonicalName())) {
            setupStatement.execute("DROP SCHEMA IF EXISTS " + connectionSchema + ";");
            setupStatement.execute("CREATE SCHEMA " + connectionSchema + ";");
        } else if (hibernateDialect.equals(HSQLDialectValid.class.getCanonicalName())) {
            setupStatement.execute("DROP SCHEMA IF EXISTS " + connectionSchema + " CASCADE;");
            setupStatement.execute("CREATE SCHEMA " + connectionSchema + ";");
        } else {
            throw new AssertionError("Unsupported Dialect");
        }
    } catch (SQLException e) {
        throw new DatabaseException("Could not excecute recreation of database schema", e);
    } finally {
        try {
            dbConnection.close();
        } catch (SQLException e) {
            throw new DatabaseException("Failed to close database connection.");
        }
    }

    // export hibernate schema
    SchemaExport schemaTool = new SchemaExport(hibernateConfiguration);
    schemaTool.create(false, true);
}

From source file:eu.hydrologis.jgrass.database.core.h2.H2DatabaseConnection.java

License:Open Source License

public void createSchemas(boolean doUpdate) throws Exception {
    getSessionFactory();/*w ww .  j a va 2 s .  c o m*/
    if (doUpdate) {
        SchemaUpdate schemaUpdate = new SchemaUpdate(getAnnotationConfiguration());
        schemaUpdate.execute(true, true);
    } else {
        SchemaExport schemaExport = new SchemaExport(getAnnotationConfiguration());
        schemaExport.create(true, true);
    }
}

From source file:eu.hydrologis.jgrass.database.core.postgres.PostgresDatabaseConnection.java

License:Open Source License

public void createSchemas(boolean doUpdate) throws Exception {
    getSessionFactory();//from   w  w w . j a v a  2  s .  c o m
    if (doUpdate) {
        SchemaUpdate schemaUpdate = new SchemaUpdate(getAnnotationConfiguration());
        schemaUpdate.execute(false, true);
    } else {
        SchemaExport schemaExport = new SchemaExport(getAnnotationConfiguration());
        schemaExport.create(false, true);
    }
}

From source file:example.HHH9788Test.java

License:Apache License

/**
 * @see HHH-9788//w ww.  ja v a2s.  com
 */
@Test
public void updatesSchemaCorrectly() {

    SchemaExport schemaExport = new SchemaExport(serviceRegistry, metadata);
    schemaExport.create(true, true);

    SchemaUpdate schemaUpdate = new SchemaUpdate(serviceRegistry, metadata);
    schemaUpdate.execute(true, true);
}