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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:org.glite.security.voms.admin.persistence.deployer.SchemaDeployer.java

License:Apache License

private void doDeploy() {

    checkVoExistence();/*from w w  w .j a  v  a2  s .  co m*/

    int existingDb = checkDatabaseExistence();

    if (existingDb > 0) {
        final String adminDbVersion = VOMSVersionDAO.instance().getVersion().getAdminVersion().trim();

        log.warn("Existing voms database found. Will not overwrite " + "the database! (admin db version: {})",
                adminDbVersion);
        System.exit(0);
    }

    checkDatabaseWritable();

    SchemaExport exporter = new SchemaExport();

    EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.DATABASE);
    exporter.createOnly(targetTypes, HibernateFactory.getMetadata());

    log.info("Deploying voms database...");

    @SuppressWarnings("rawtypes")
    List l = exporter.getExceptions();

    if (!l.isEmpty()) {
        log.error("Error deploying voms database!");
        printExceptions(l);
        System.exit(2);

    }

    // This is needed as the version of hibernate we are using
    // does not support defining indexes on join table columns
    // See: https://hibernate.atlassian.net/browse/HHH-4263
    CreateAuditEventDataIndexes createIndexTask = new CreateAuditEventDataIndexes(
            HibernateFactory.getSession());

    HibernateFactory.beginTransaction();

    createIndexTask.run();

    CreateAttributeValueIndex avIndexTask = new CreateAttributeValueIndex(HibernateFactory.getSession());

    avIndexTask.run();

    UpdateCATask caTask = new UpdateCATask();
    caTask.run();

    DatabaseSetupTask task = DatabaseSetupTask.instance();
    task.run();

    HibernateFactory.commitTransaction();
    log.info("Database deployed correctly!");

}