Search in sources :

Example 1 with TableStructure

use of org.hibernate.id.enhanced.TableStructure 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(), 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();
    assertEquals(1, table.getInitCommands().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;
        }
    }, 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) 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) 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)

Aggregations

EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 Database (org.hibernate.boot.model.relational.Database)1 QualifiedTableName (org.hibernate.boot.model.relational.QualifiedTableName)1 TableStructure (org.hibernate.id.enhanced.TableStructure)1 Table (org.hibernate.mapping.Table)1 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)1 ExceptionHandler (org.hibernate.tool.schema.spi.ExceptionHandler)1 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)1 ScriptTargetOutput (org.hibernate.tool.schema.spi.ScriptTargetOutput)1 TargetDescriptor (org.hibernate.tool.schema.spi.TargetDescriptor)1 Test (org.junit.Test)1