Example usage for org.hibernate.tool.hbm2ddl Target EXPORT

List of usage examples for org.hibernate.tool.hbm2ddl Target EXPORT

Introduction

In this page you can find the example usage for org.hibernate.tool.hbm2ddl Target EXPORT.

Prototype

Target EXPORT

To view the source code for org.hibernate.tool.hbm2ddl Target EXPORT.

Click Source Link

Document

Export to the database.

Usage

From source file:org.bonitasoft.engine.business.data.impl.SchemaManager.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Exception> drop(final Set<String> managedClasses) {
    final SchemaExport export = new SchemaExport(buildConfiguration(managedClasses));
    export.drop(Target.EXPORT);
    return export.getExceptions();
}

From source file:org.bonitasoft.engine.business.data.impl.SchemaManager.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Exception> update(final Set<String> managedClasses) {
    final SchemaUpdate schemaUpdate = new SchemaUpdate(buildConfiguration(managedClasses));
    schemaUpdate.execute(Target.EXPORT);
    return schemaUpdate.getExceptions();
}

From source file:org.bonitasoft.engine.business.data.impl.SchemaManagerUpdate.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<Exception> drop(final Set<String> managedClasses) {
    final SchemaExport export = new SchemaExport(buildConfiguration(managedClasses));
    export.drop(Target.EXPORT);
    return export.getExceptions();
}

From source file:org.bonitasoft.engine.business.data.impl.SchemaManagerUpdate.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<Exception> update(final Set<String> managedClasses) {
    final SchemaUpdate schemaUpdate = new SchemaUpdate(buildConfiguration(managedClasses));
    schemaUpdate.execute(Target.EXPORT);
    return schemaUpdate.getExceptions();
}

From source file:org.web4thejob.module.JobletInstallerImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public <E extends Exception> List<E> install(List<Joblet> joblets) {
    List<E> exceptions = new ArrayList<E>();

    try {// ww w .  java 2 s  . co m

        final Configuration configuration = new Configuration();
        configuration.setProperty(AvailableSettings.DIALECT,
                connInfo.getProperty(DatasourceProperties.DIALECT));
        configuration.setProperty(AvailableSettings.DRIVER, connInfo.getProperty(DatasourceProperties.DRIVER));
        configuration.setProperty(AvailableSettings.URL, connInfo.getProperty(DatasourceProperties.URL));
        configuration.setProperty(AvailableSettings.USER, connInfo.getProperty(DatasourceProperties.USER));
        configuration.setProperty(AvailableSettings.PASS, connInfo.getProperty(DatasourceProperties.PASSWORD));

        final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();

        if (StringUtils.hasText(connInfo.getProperty(DatasourceProperties.SCHEMA_SYNTAX))) {
            String schemaSyntax = connInfo.getProperty(DatasourceProperties.SCHEMA_SYNTAX);
            Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();

            for (Joblet joblet : joblets) {
                for (String schema : joblet.getSchemas()) {
                    Statement statement = connection.createStatement();
                    statement.executeUpdate(schemaSyntax.replace("%s", schema));
                    statement.close();
                }
            }

            if (!connection.getAutoCommit()) {
                connection.commit();
            }
        }

        for (Joblet joblet : joblets) {
            for (Resource resource : joblet.getResources()) {
                configuration.addInputStream(resource.getInputStream());
            }
        }

        SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration);
        schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE);
        exceptions.addAll(schemaExport.getExceptions());

    } catch (Exception e) {
        exceptions.add((E) e);
    }

    return exceptions;

}

From source file:org.web4thejob.orm.CreateSchemaTest.java

License:Open Source License

@Test
public void schemaExportTest() throws IOException, SQLException {

    Log4jConfigurer.initLogging("classpath:org/web4thejob/conf/log4j.xml");

    Properties datasource = new Properties();
    datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream());

    final Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.DIALECT, datasource.getProperty(DatasourceProperties.DIALECT));
    configuration.setProperty(AvailableSettings.DRIVER, datasource.getProperty(DatasourceProperties.DRIVER));
    configuration.setProperty(AvailableSettings.URL, "jdbc:hsqldb:mem:mydb");
    configuration.setProperty(AvailableSettings.USER, datasource.getProperty(DatasourceProperties.USER));
    configuration.setProperty(AvailableSettings.PASS, datasource.getProperty(DatasourceProperties.PASSWORD));

    final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(configuration.getProperties()).build();

    Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();
    Statement statement = connection.createStatement();
    statement.executeUpdate("CREATE SCHEMA w4tj;");
    statement.close();/*from  w w w. ja  v  a 2 s. co m*/

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        for (Resource resource : resolver.getResources("classpath*:org/web4thejob/orm/**/*.hbm.xml")) {

            if (resource.getFile().getName().equals("AuxiliaryDatabaseObjects.hbm.xml"))
                continue;

            configuration.addFile(resource.getFile());
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

    SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration);
    schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE);

    if (!schemaExport.getExceptions().isEmpty()) {
        throw new RuntimeException((Throwable) schemaExport.getExceptions().get(0));
    }

}

From source file:persistence.DBUtility.java

public static void schemaExport() {
    Configuration config = new Configuration().configure("hibernate.cfg.xml");
    SchemaExport exporter = new SchemaExport(config);
    exporter.setDelimiter(";");
    exporter.setOutputFile("pentamatrix-2.sql");
    exporter.execute(Target.EXPORT, SchemaExport.Type.BOTH);
}