Search in sources :

Example 1 with SchemaCreatorImpl

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

the class IndividuallySchemaValidatorImplTest method testMissingColumn.

@Test
public void testMissingColumn() throws Exception {
    MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(NoNameColumn.class);
    MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    Map<String, Object> settings = new HashMap<>();
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
    connectionProvider.configure(properties());
    final GenerationTargetToDatabase schemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcConnectionAccessImpl(connectionProvider)));
    try {
        new SchemaCreatorImpl(ssr).doCreation(metadata, serviceRegistry, settings, true, schemaGenerator);
        metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(NameColumn.class);
        metadata = (MetadataImplementor) metadataSources.buildMetadata();
        metadata.validate();
        try {
            getSchemaValidator(metadata);
            Assert.fail("SchemaManagementException expected");
        } catch (SchemaManagementException e) {
            assertEquals("Schema-validation: missing column [name] in table [SomeSchema.ColumnEntity]", e.getMessage());
        }
    } finally {
        new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
        serviceRegistry.destroy();
        connectionProvider.stop();
    }
}
Also used : JdbcConnectionAccessImpl(org.hibernate.testing.boot.JdbcConnectionAccessImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) Test(org.junit.Test)

Example 2 with SchemaCreatorImpl

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

the class JoinColumnOverrideTest method testBlownPrecision.

@Test
@TestForIssue(jiraKey = "ANN-748")
public void testBlownPrecision() throws Exception {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, "SQLServer").build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Bunny.class).addAnnotatedClass(PointyTooth.class).addAnnotatedClass(TwinkleToes.class).buildMetadata();
        boolean foundPointyToothCreate = false;
        boolean foundTwinkleToesCreate = false;
        List<String> commands = new SchemaCreatorImpl(ssr).generateCreationCommands(metadata, false);
        for (String command : commands) {
            log.debug(command);
            if (expectedSqlPointyTooth.equals(command)) {
                foundPointyToothCreate = true;
            } else if (expectedSqlTwinkleToes.equals(command)) {
                foundTwinkleToesCreate = true;
            }
        }
        assertTrue("Expected create table command for PointyTooth entity not found", foundPointyToothCreate);
        assertTrue("Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) TwinkleToes(org.hibernate.test.annotations.id.sequences.entities.TwinkleToes) Bunny(org.hibernate.test.annotations.id.sequences.entities.Bunny) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with SchemaCreatorImpl

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

the class NullablePrimaryKeyTest method testGeneratedSql.

@Test
@SuppressWarnings("unchecked")
public void testGeneratedSql() {
    Map settings = new HashMap();
    settings.putAll(Environment.getProperties());
    settings.put(AvailableSettings.DIALECT, SQLServerDialect.class.getName());
    ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(settings);
    try {
        MetadataSources ms = new MetadataSources(serviceRegistry);
        ms.addAnnotatedClass(Address.class);
        ms.addAnnotatedClass(Person.class);
        final Metadata metadata = ms.buildMetadata();
        final List<String> commands = new SchemaCreatorImpl(serviceRegistry).generateCreationCommands(metadata, false);
        for (String s : commands) {
            log.debug(s);
        }
        String expectedMappingTableSql = "create table personAddress (address_id numeric(19,0), " + "person_id numeric(19,0) not null, primary key (person_id))";
        Assert.assertEquals("Wrong SQL", expectedMappingTableSql, commands.get(2));
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    } finally {
        ServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : SQLServerDialect(org.hibernate.dialect.SQLServerDialect) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) ServiceRegistry(org.hibernate.service.ServiceRegistry) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with SchemaCreatorImpl

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

the class UniqueDelegateTest method testUniqueDelegateConsulted.

@Test
@TestForIssue(jiraKey = "HHH-10203")
public void testUniqueDelegateConsulted() {
    final Metadata metadata = new MetadataSources(ssr).addResource("org/hibernate/test/hbm/uk/person_unique.hbm.xml").buildMetadata();
    final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
    new SchemaCreatorImpl(ssr).doCreation(metadata, false, target);
    assertThat(getAlterTableToAddUniqueKeyCommandCallCount, equalTo(1));
    assertThat(getColumnDefinitionUniquenessFragmentCallCount, equalTo(1));
    assertThat(getTableCreationUniqueConstraintsFragmentCallCount, equalTo(1));
    new SchemaDropperImpl(ssr).doDrop(metadata, false, target);
    // unique keys are not dropped explicitly
    assertThat(getAlterTableToAddUniqueKeyCommandCallCount, equalTo(1));
    assertThat(getColumnDefinitionUniquenessFragmentCallCount, equalTo(1));
    assertThat(getTableCreationUniqueConstraintsFragmentCallCount, equalTo(1));
}
Also used : SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) JournalingSchemaToolingTarget(org.hibernate.test.hbm.index.JournalingSchemaToolingTarget) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with SchemaCreatorImpl

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

the class CollectionPkTest method verifyPkNameUsed.

private void verifyPkNameUsed(String mappingResource, String expectedName) {
    final Metadata metadata = new MetadataSources(ssr).addResource(mappingResource).buildMetadata();
    final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
    new SchemaCreatorImpl(ssr).doCreation(metadata, false, target);
    assertTrue("Expected foreign-key name [" + expectedName + "] not seen in schema creation output", target.containedText(expectedName));
}
Also used : SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) JournalingSchemaToolingTarget(org.hibernate.test.hbm.index.JournalingSchemaToolingTarget)

Aggregations

SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)18 MetadataSources (org.hibernate.boot.MetadataSources)14 Metadata (org.hibernate.boot.Metadata)11 Test (org.junit.Test)9 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)7 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)6 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)6 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)6 HashMap (java.util.HashMap)4 TestForIssue (org.hibernate.testing.TestForIssue)4 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)3 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)3 JournalingSchemaToolingTarget (org.hibernate.test.hbm.index.JournalingSchemaToolingTarget)3 Map (java.util.Map)2 SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)2 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)2 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)2 JdbcConnectionAccessImpl (org.hibernate.testing.boot.JdbcConnectionAccessImpl)2 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)2 SchemaManagementException (org.hibernate.tool.schema.spi.SchemaManagementException)2