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

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

Introduction

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

Prototype

public SchemaExport setDelimiter(String delimiter) 

Source Link

Document

Set the end of statement delimiter

Usage

From source file:org.ambraproject.hibernate.SchemaGenerator.java

License:Apache License

/**
 * Run the schema creation script/*  w  ww. j a  va 2  s.c  om*/
 *
 * @param jdbcUrl  - the jdbc url for the database in which to run the script
 * @param dialect- the sql dialect for the database
 * @param username - the username for the database
 * @param password - the password to use
 */
public void createSchema(String jdbcUrl, Dialect dialect, String username, String password) {
    configuration.setProperty("connection.url", jdbcUrl);
    configuration.setProperty("connection.username", username);
    configuration.setProperty("connection.password", password);
    configuration.setProperty("dialect", dialect.getDialectClass());
    configuration.setProperty("connection.driver_class", dialect.getDriverClass());
    SchemaExport export = new SchemaExport(configuration);
    export.setDelimiter(";");
    export.execute(false, true, false, !updateSchema);
}

From source file:org.apache.juddi.ddl.generator.App.java

License:Apache License

/**
 * Method that actually creates the file.
 *
 * @param dbDialect to use/*from  w  ww. ja v a  2  s  . com*/
 */
private void generate(Dialect dialect) {
    cfg.setProperty("hibernate.dialect", dialect.getDialectClass());

    SchemaExport export = new SchemaExport(cfg);
    export.setDelimiter(";");
    export.setOutputFile(dialect.name().toLowerCase() + ".ddl");
    export.execute(true, false, false, true);
}

From source file:org.bedework.calcore.hibernate.SchemaBuilderImpl.java

License:Apache License

@Override
public void execute(final Properties props, final String outputFile, final boolean export,
        final String delimiter) throws CalFacadeException {
    try {//w  w w  . j a v a2  s . c  o m
        SchemaExport se = new SchemaExport(getConfiguration(props));

        if (delimiter != null) {
            se.setDelimiter(delimiter);
        }

        se.setFormat(true);
        se.setHaltOnError(false);
        se.setOutputFile(outputFile);

        se.execute(false, // script - causes write to System.out if true
                export, false, // drop
                true); // create
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}

From source file:org.bedework.synch.service.Synch.java

License:Apache License

@Override
public String schema() {
    String result = "Export complete: check logs";

    try {//from   w  w w  .  j a v  a  2 s. c o  m
        SchemaExport se = new SchemaExport(getConfiguration());

        if (getDelimiter() != null) {
            se.setDelimiter(getDelimiter());
        }

        se.setFormat(getFormat());
        se.setHaltOnError(getHaltOnError());
        se.setOutputFile(getSchemaOutFile());
        se.setImportFile(getSqlIn());

        se.execute(false, // script - causes write to System.out if true
                getExport(), getDrop(), getCreate());
    } catch (Throwable t) {
        error(t);
        result = "Exception: " + t.getLocalizedMessage();
    } finally {
        create = false;
        drop = false;
        export = false;
    }

    return result;
}

From source file:org.codehaus.mojo.hibernate3.exporter.Hbm2DDLExporterMojo.java

License:Apache License

/**
 * Overrides the default implementation of executing this goal.
 *
 * @throws MojoExecutionException if there is an error executing the goal
 *//*from  w  w  w. j  av a  2s  .c  o m*/
protected void doExecute() throws MojoExecutionException {
    boolean scriptToConsole = getComponentProperty("console", true);
    boolean exportToDatabase = getComponentProperty("export", true);
    boolean haltOnError = getComponentProperty("haltonerror", false);
    boolean drop = getComponentProperty("drop", false);
    boolean create = getComponentProperty("create", true);
    String implementation = getComponentProperty("implementation", getComponent().getImplementation());

    Configuration configuration = getComponentConfiguration(implementation).getConfiguration(this);

    if (getComponentProperty("update", false)) {
        SchemaUpdate update = new SchemaUpdate(configuration);
        update.execute(scriptToConsole, exportToDatabase);
    } else {
        SchemaExport export = new SchemaExport(configuration);
        export.setDelimiter(getComponentProperty("delimiter", ";"));
        export.setHaltOnError(haltOnError);
        export.setFormat(getComponentProperty("format", false));

        String outputFilename = getComponentProperty("outputfilename");
        if (outputFilename != null) {
            File outputFile = HibernateUtils.prepareFile(
                    new File(getProject().getBasedir(), getComponent().getOutputDirectory()), outputFilename,
                    "outputfilename");
            export.setOutputFile(outputFile.toString());
        }

        if (drop && create) {
            export.create(scriptToConsole, exportToDatabase);
        } else {
            export.execute(scriptToConsole, exportToDatabase, drop, create);
        }

        if (export.getExceptions().size() > 0) {
            Iterator iterator = export.getExceptions().iterator();
            int cnt = 1;
            getLog().warn(export.getExceptions().size() + " errors occurred while performing <hbm2ddl>.");
            while (iterator.hasNext()) {
                getLog().error("Error #" + cnt + ": " + iterator.next().toString());
            }
            if (haltOnError) {
                throw new MojoExecutionException("Errors while performing <hbm2ddl>");
            }
        }
    }
}

From source file:org.jahia.maven.hbm2ddl.JpaSchemaExportMojo.java

License:Open Source License

private void performExport() throws MojoExecutionException {
    final Configuration cfg = new Ejb3Configuration().configure(persistenceUnitName, getHibernateProperties())
            .getHibernateConfiguration();

    configureNamingStrategy(cfg);/* ww  w .ja  v a  2s  . com*/

    SchemaExport schemaExport = new SchemaExport(cfg);
    schemaExport.setDelimiter(";");
    schemaExport.setOutputFile(outputFile.getAbsolutePath());
    schemaExport.execute(Target.SCRIPT, statementType);
}

From source file:org.jboss.bpm.monitor.model.hibernate.SchemaGenerator.java

License:Apache License

/**
 * Method that actually creates the file.
 *///from w w w.  j av  a 2 s  . co  m
private void generate(Dialect dialect) {
    String s = output.getAbsolutePath() + "/ddl_" + dialect.name().toLowerCase() + ".sql";
    cfg.setProperty("hibernate.dialect", dialect.getDialectClass());

    SchemaExport export = new SchemaExport(cfg);
    export.setDelimiter(";");
    export.setOutputFile(s);
    export.setFormat(true);
    export.setHaltOnError(true);
    export.execute(true, false, false, false);

    System.out.println("==================");
    System.out.println("DDL: " + s);
    System.out.println("==================");
}

From source file:org.jbpm.ant.JbpmSchemaTask.java

License:Open Source License

public void execute() throws BuildException {
    if (actions == null) {
        // default action is create
        actions = "create";
    }//from ww w . j a v a 2  s  . co  m

    // we need a configuration
    Configuration configuration = null;

    // if there is no jbpm nor hibernate configuration specified
    if ((jbpmCfg == null) && (hibernateCfg == null)) {
        // search for the default jbpm.cfg.xml
        URL defaultJbpmCfgUrl = getClass().getClassLoader().getResource("jbpm.cfg.xml");
        if (defaultJbpmCfgUrl != null) {
            jbpmCfg = "jbpm.cfg.xml";
            // if still not found, search for the default hibernate.cfg.xml
        } else {
            URL defaultHibernateCfgUrl = getClass().getClassLoader().getResource("hibernate.cfg.xml");
            if (defaultHibernateCfgUrl != null) {
                hibernateCfg = "hibernate.cfg.xml";
            }
        }
    }

    // first see if the jbpm cfg is specified cause that implies a hibernate configuration
    if (jbpmCfg != null) {
        log("using jbpm configuration " + jbpmCfg);
        JbpmConfiguration jbpmConfiguration = AntHelper.getJbpmConfiguration(jbpmCfg);
        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
        try {
            DbPersistenceServiceFactory dbPersistenceServiceFactory = (DbPersistenceServiceFactory) jbpmConfiguration
                    .getServiceFactory(Services.SERVICENAME_PERSISTENCE);
            configuration = dbPersistenceServiceFactory.getConfiguration();
        } finally {
            jbpmContext.close();
        }

        // if there is no jbpm.cfg.xml specified, check if there is a hibernate.cfg.xml specified
    } else if (hibernateCfg != null) {
        log("using hibernate configuration " + hibernateCfg);
        configuration = AntHelper.getConfiguration(hibernateCfg, hibernateProperties);

        // no hibernate configuration specified
    } else {
        throw new BuildException("couldn't create schema.  no jbpm nor hibernate configuration specified.");
    }

    JbpmSchema jbpmSchema = new JbpmSchema(configuration);

    SchemaExport schemaExport = new SchemaExport(configuration);
    if (output != null)
        schemaExport.setOutputFile(output);
    if (delimiter != null)
        schemaExport.setDelimiter(delimiter);

    StringTokenizer tokenizer = new StringTokenizer(actions, ",");
    while (tokenizer.hasMoreTokens()) {
        String action = tokenizer.nextToken();

        if ("drop".equalsIgnoreCase(action)) {
            schemaExport.drop(!quiet, !text);

        } else if ("create".equalsIgnoreCase(action)) {
            schemaExport.create(!quiet, !text);

        } else if ("clean".equalsIgnoreCase(action)) {
            jbpmSchema.cleanSchema();
        }
    }
}

From source file:org.jpos.ee.DB.java

License:Open Source License

/**
 * Creates database schema/* w  w w.  j a  va2s .com*/
 *
 * @param outputFile optional output file (may be null)
 * @param create     true to actually issue the create statements
 */
public void createSchema(String outputFile, boolean create) throws HibernateException {
    SchemaExport export = new SchemaExport(getHibernateAccessService().getConfiguration());
    if (outputFile != null) {
        export.setOutputFile(outputFile);
        export.setDelimiter(";");
    }
    export.create(true, create);
}

From source file:org.kuali.mobility.shared.controllers.HomeController.java

License:Open Source License

/**
 * Controller method to download a ddl./*from   ww  w . ja  va 2s  .  c  o m*/
 */
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(value = "ddl", method = RequestMethod.GET)
public void exportDatabaseSchema(HttpServletRequest request, HttpServletResponse response, Model uiModel) {
    PersistenceUnitInfo persistenceUnitInfo = getEntityManagerFactory().getPersistenceUnitInfo();

    Map jpaPropertyMap = getEntityManagerFactory().getJpaPropertyMap();
    jpaPropertyMap.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
    Configuration configuration = new Ejb3Configuration().configure(persistenceUnitInfo, jpaPropertyMap)
            .getHibernateConfiguration();

    SchemaExport schema = new SchemaExport(configuration);
    schema.setFormat(true);
    schema.setDelimiter(";");
    schema.setOutputFile("/tmp/schema.sql");
    schema.create(false, false);
}