Search in sources :

Example 1 with TargetType

use of org.hibernate.tool.schema.TargetType in project hibernate-orm by hibernate.

the class SchemaManagementToolCoordinator method buildScriptTargetDescriptor.

private static JpaTargetAndSourceDescriptor buildScriptTargetDescriptor(Map configurationValues, SettingSelector settingSelector, ServiceRegistry serviceRegistry) {
    final Object scriptSourceSetting = settingSelector.getScriptSourceSetting(configurationValues);
    final SourceType sourceType = SourceType.interpret(settingSelector.getSourceTypeSetting(configurationValues), scriptSourceSetting != null ? SourceType.SCRIPT : SourceType.METADATA);
    final boolean includesScripts = sourceType != SourceType.METADATA;
    if (includesScripts && scriptSourceSetting == null) {
        throw new SchemaManagementException("Schema generation configuration indicated to include CREATE scripts, but no script was specified");
    }
    String charsetName = (String) configurationValues.get(AvailableSettings.HBM2DDL_CHARSET_NAME);
    final ScriptSourceInput scriptSourceInput = includesScripts ? Helper.interpretScriptSourceSetting(scriptSourceSetting, serviceRegistry.getService(ClassLoaderService.class), charsetName) : null;
    final ScriptTargetOutput scriptTargetOutput = Helper.interpretScriptTargetSetting(settingSelector.getScriptTargetSetting(configurationValues), serviceRegistry.getService(ClassLoaderService.class), charsetName);
    return new JpaTargetAndSourceDescriptor() {

        @Override
        public EnumSet<TargetType> getTargetTypes() {
            return EnumSet.of(TargetType.SCRIPT);
        }

        @Override
        public ScriptTargetOutput getScriptTargetOutput() {
            return scriptTargetOutput;
        }

        @Override
        public SourceType getSourceType() {
            return sourceType;
        }

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return scriptSourceInput;
        }
    };
}
Also used : SourceType(org.hibernate.tool.schema.SourceType) TargetType(org.hibernate.tool.schema.TargetType) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 2 with TargetType

use of org.hibernate.tool.schema.TargetType in project hibernate-orm by hibernate.

the class SchemaManagementToolCoordinator method buildDatabaseTargetDescriptor.

private static JpaTargetAndSourceDescriptor buildDatabaseTargetDescriptor(Map configurationValues, SettingSelector settingSelector, ServiceRegistry serviceRegistry) {
    final Object scriptSourceSetting = settingSelector.getScriptSourceSetting(configurationValues);
    final SourceType sourceType = SourceType.interpret(settingSelector.getSourceTypeSetting(configurationValues), scriptSourceSetting != null ? SourceType.SCRIPT : SourceType.METADATA);
    final boolean includesScripts = sourceType != SourceType.METADATA;
    if (includesScripts && scriptSourceSetting == null) {
        throw new SchemaManagementException("Schema generation configuration indicated to include CREATE scripts, but no script was specified");
    }
    final ScriptSourceInput scriptSourceInput = includesScripts ? Helper.interpretScriptSourceSetting(scriptSourceSetting, serviceRegistry.getService(ClassLoaderService.class), (String) configurationValues.get(AvailableSettings.HBM2DDL_CHARSET_NAME)) : null;
    return new JpaTargetAndSourceDescriptor() {

        @Override
        public EnumSet<TargetType> getTargetTypes() {
            return EnumSet.of(TargetType.DATABASE);
        }

        @Override
        public ScriptTargetOutput getScriptTargetOutput() {
            return null;
        }

        @Override
        public SourceType getSourceType() {
            return sourceType;
        }

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return scriptSourceInput;
        }
    };
}
Also used : SourceType(org.hibernate.tool.schema.SourceType) TargetType(org.hibernate.tool.schema.TargetType)

Example 3 with TargetType

use of org.hibernate.tool.schema.TargetType in project bw-calendar-engine by Bedework.

the class SchemaBuilderImpl method execute.

@Override
public void execute(final Properties props, final String outputFile, final boolean export, final String delimiter) throws CalFacadeException {
    try {
        SchemaExport se = new SchemaExport();
        if (delimiter != null) {
            se.setDelimiter(delimiter);
        }
        se.setFormat(true);
        se.setHaltOnError(false);
        se.setOutputFile(outputFile);
        final EnumSet<TargetType> targets = EnumSet.noneOf(TargetType.class);
        if (export) {
            targets.add(TargetType.DATABASE);
        } else {
            targets.add(TargetType.SCRIPT);
        }
        Properties allProps = getConfiguration(props).getProperties();
        final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
        final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
        ssrBuilder.applySettings(allProps);
        se.execute(targets, SchemaExport.Action.BOTH, null, ssrBuilder.getBootstrapServiceRegistry());
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) TargetType(org.hibernate.tool.schema.TargetType) Properties(java.util.Properties) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Aggregations

TargetType (org.hibernate.tool.schema.TargetType)3 SourceType (org.hibernate.tool.schema.SourceType)2 Properties (java.util.Properties)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)1 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)1