Search in sources :

Example 1 with SchemaFilter

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

the class SchemaDropperImpl method doDrop.

/**
 * For tests
 */
public void doDrop(Metadata metadata, final ServiceRegistry serviceRegistry, final Map<String, Object> settings, final boolean manageNamespaces, GenerationTarget... targets) {
    if (targets == null || targets.length == 0) {
        final JdbcContext jdbcContext = tool.resolveJdbcContext(settings);
        targets = new GenerationTarget[] { new GenerationTargetToDatabase(serviceRegistry.getService(TransactionCoordinatorBuilder.class).buildDdlTransactionIsolator(jdbcContext), true) };
    }
    doDrop(metadata, new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return manageNamespaces;
        }

        @Override
        public Map<String, Object> getConfigurationValues() {
            return settings;
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }

        @Override
        public SchemaFilter getSchemaFilter() {
            return schemaFilter;
        }
    }, (contributed) -> true, serviceRegistry.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {

        @Override
        public SourceType getSourceType() {
            return SourceType.METADATA;
        }

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return null;
        }
    }, targets);
}
Also used : ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) SchemaFilter(org.hibernate.tool.schema.spi.SchemaFilter) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) SourceDescriptor(org.hibernate.tool.schema.spi.SourceDescriptor) ScriptSourceInput(org.hibernate.tool.schema.spi.ScriptSourceInput) JdbcContext(org.hibernate.tool.schema.internal.exec.JdbcContext) SourceType(org.hibernate.tool.schema.SourceType) TransactionCoordinatorBuilder(org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) Map(java.util.Map)

Example 2 with SchemaFilter

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

the class IndividuallySchemaValidatorImplConnectionTest method setUp.

@Before
public void setUp() throws Exception {
    connectionProvider = new DriverManagerConnectionProviderImpl();
    connectionProvider.configure(PropertiesHelper.map(properties()));
    connection = connectionProvider.getConnection();
    ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_CONNECTION, connection).build();
    tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
    configurationValues = ssr.getService(ConfigurationService.class).getSettings();
    executionOptions = new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return configurationValues;
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }

        @Override
        public SchemaFilter getSchemaFilter() {
            return SchemaFilter.ALL;
        }
    };
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) DefaultSchemaFilter(org.hibernate.tool.schema.internal.DefaultSchemaFilter) SchemaFilter(org.hibernate.tool.schema.spi.SchemaFilter) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 3 with SchemaFilter

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

the class SchemaUpdateTableBackedSequenceTest method testCreateTableOnUpdate.

@Test
public void testCreateTableOnUpdate() throws SQLException {
    Metadata metadata = new MetadataSources(ssr).buildMetadata();
    Database database = metadata.getDatabase();
    TableStructure tableStructure = new TableStructure(database.getJdbcEnvironment(), "orm", new QualifiedTableName(null, null, Identifier.toIdentifier("test_seq")), Identifier.toIdentifier("nextval"), 20, 30, Long.class);
    tableStructure.registerExportables(database);
    // lets make sure the InitCommand is there
    assertEquals(1, database.getDefaultNamespace().getTables().size());
    Table table = database.getDefaultNamespace().getTables().iterator().next();
    SqlStringGenerationContext context = SqlStringGenerationContextImpl.forTests(database.getJdbcEnvironment(), null, null);
    assertEquals(1, table.getInitCommands(context).size());
    final TargetImpl target = new TargetImpl();
    ssr.getService(SchemaManagementTool.class).getSchemaMigrator(Collections.emptyMap()).doMigration(metadata, new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return ssr.getService(ConfigurationService.class).getSettings();
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }

        @Override
        public SchemaFilter getSchemaFilter() {
            return SchemaFilter.ALL;
        }
    }, ContributableMatcher.ALL, new TargetDescriptor() {

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

        @Override
        public ScriptTargetOutput getScriptTargetOutput() {
            return target;
        }
    });
    assertTrue(target.found);
    new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
Also used : QualifiedTableName(org.hibernate.boot.model.relational.QualifiedTableName) Table(org.hibernate.mapping.Table) SqlStringGenerationContext(org.hibernate.boot.model.relational.SqlStringGenerationContext) EnumSet(java.util.EnumSet) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) TargetDescriptor(org.hibernate.tool.schema.spi.TargetDescriptor) ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) SchemaFilter(org.hibernate.tool.schema.spi.SchemaFilter) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) TableStructure(org.hibernate.id.enhanced.TableStructure) Database(org.hibernate.boot.model.relational.Database) ScriptTargetOutput(org.hibernate.tool.schema.spi.ScriptTargetOutput) Map(java.util.Map) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 4 with SchemaFilter

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

the class UniqueConstraintDropTest method setUp.

@Before
public void setUp() throws Exception {
    output = File.createTempFile("update_script", ".sql");
    output.deleteOnExit();
    ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").applySetting(Environment.FORMAT_SQL, "false").applySetting(Environment.SHOW_SQL, "true").build();
    metadata = (MetadataImplementor) new MetadataSources(ssr).addResource("org/hibernate/orm/test/schemaupdate/uniqueconstraint/TestEntity.hbm.xml").buildMetadata();
    metadata.validate();
    tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
    final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
    options = new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return configurationValues;
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }

        @Override
        public SchemaFilter getSchemaFilter() {
            return SchemaFilter.ALL;
        }
    };
}
Also used : ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) DefaultSchemaFilter(org.hibernate.tool.schema.internal.DefaultSchemaFilter) SchemaFilter(org.hibernate.tool.schema.spi.SchemaFilter) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Map(java.util.Map) Before(org.junit.Before)

Example 5 with SchemaFilter

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

the class IndividuallySchemaValidatorImplTest method setUp.

@Before
public void setUp() throws IOException {
    ssr = new StandardServiceRegistryBuilder().build();
    tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
    configurationValues = ssr.getService(ConfigurationService.class).getSettings();
    executionOptions = new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return configurationValues;
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }

        @Override
        public SchemaFilter getSchemaFilter() {
            return SchemaFilter.ALL;
        }
    };
}
Also used : ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) DefaultSchemaFilter(org.hibernate.tool.schema.internal.DefaultSchemaFilter) SchemaFilter(org.hibernate.tool.schema.spi.SchemaFilter) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Aggregations

Map (java.util.Map)5 ExceptionHandler (org.hibernate.tool.schema.spi.ExceptionHandler)5 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)5 SchemaFilter (org.hibernate.tool.schema.spi.SchemaFilter)5 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 DefaultSchemaFilter (org.hibernate.tool.schema.internal.DefaultSchemaFilter)3 Before (org.junit.Before)3 HashMap (java.util.HashMap)2 MetadataSources (org.hibernate.boot.MetadataSources)2 EnumSet (java.util.EnumSet)1 Metadata (org.hibernate.boot.Metadata)1 Database (org.hibernate.boot.model.relational.Database)1 QualifiedTableName (org.hibernate.boot.model.relational.QualifiedTableName)1 SqlStringGenerationContext (org.hibernate.boot.model.relational.SqlStringGenerationContext)1 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)1 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)1 TableStructure (org.hibernate.id.enhanced.TableStructure)1 Table (org.hibernate.mapping.Table)1 TransactionCoordinatorBuilder (org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder)1 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)1