Search in sources :

Example 1 with SchemaValidator

use of org.hibernate.tool.hbm2ddl.SchemaValidator in project hibernate-orm by hibernate.

the class JoinTableWithDefaultSchemaTest method testGetTableDataForJoinTableWithDefaultSchema.

@Test
@TestForIssue(jiraKey = "HHH-10978")
@RequiresDialect(SQLServerDialect.class)
public void testGetTableDataForJoinTableWithDefaultSchema() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DEFAULT_CATALOG, "hibernate_orm_test").applySetting(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false").build();
    try {
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Task.class).addAnnotatedClass(Project.class).buildMetadata();
        metadata.validate();
        // first create the schema...
        new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
        try {
            // validate the schema
            new SchemaValidator().validate(metadata);
        } finally {
            // cleanup
            new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 2 with SchemaValidator

use of org.hibernate.tool.hbm2ddl.SchemaValidator in project hibernate-orm by hibernate.

the class SynonymValidationTest method testSynonymUsingIndividuallySchemaValidator.

@Test
public void testSynonymUsingIndividuallySchemaValidator() {
    ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.ENABLE_SYNONYMS, "true").applySetting(AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, JdbcMetadaAccessStrategy.INDIVIDUALLY).build();
    try {
        final MetadataSources metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(TestEntityWithSynonym.class);
        metadataSources.addAnnotatedClass(TestEntity.class);
        new SchemaValidator().validate(metadataSources.buildMetadata());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) Test(org.junit.Test)

Example 3 with SchemaValidator

use of org.hibernate.tool.hbm2ddl.SchemaValidator in project hibernate-orm by hibernate.

the class ConnectionsReleaseTest method testSchemaValidatorReleasesAllConnections.

@Test
public void testSchemaValidatorReleasesAllConnections() throws SQLException {
    new SchemaValidator().validate(metadata);
    assertThat(connectionProvider.getOpenConnection(), is(0));
}
Also used : SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) Test(org.junit.Test)

Example 4 with SchemaValidator

use of org.hibernate.tool.hbm2ddl.SchemaValidator in project hibernate-orm by hibernate.

the class SynonymValidationTest method testSynonymUsingGroupedSchemaValidator.

@Test
@TestForIssue(jiraKey = "HHH-12406")
public void testSynonymUsingGroupedSchemaValidator() {
    // Hibernate should use JdbcMetadaAccessStrategy.INDIVIDUALLY when
    // AvailableSettings.ENABLE_SYNONYMS is true,
    // even if JdbcMetadaAccessStrategy.GROUPED is specified.
    ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.ENABLE_SYNONYMS, "true").applySetting(AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, JdbcMetadaAccessStrategy.GROUPED).build();
    try {
        final MetadataSources metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(TestEntityWithSynonym.class);
        metadataSources.addAnnotatedClass(TestEntity.class);
        new SchemaValidator().validate(metadataSources.buildMetadata());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with SchemaValidator

use of org.hibernate.tool.hbm2ddl.SchemaValidator in project hibernate-orm by hibernate.

the class TableGeneratorQuotingTest method testTableGeneratorQuoting.

@Test
@TestForIssue(jiraKey = "HHH-7927")
public void testTableGeneratorQuoting() {
    final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(TestEntity.class).buildMetadata();
    final ConnectionProvider connectionProvider = serviceRegistry.getService(ConnectionProvider.class);
    final GenerationTarget target = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess(connectionProvider)));
    new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, false, target);
    try {
        new SchemaValidator().validate(metadata);
    } catch (HibernateException e) {
        fail("The identifier generator table should have validated.  " + e.getMessage());
    } finally {
        new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, target);
    }
}
Also used : DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) HibernateException(org.hibernate.HibernateException) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) GenerationTarget(org.hibernate.tool.schema.internal.exec.GenerationTarget) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

SchemaValidator (org.hibernate.tool.hbm2ddl.SchemaValidator)11 Test (org.junit.Test)10 MetadataSources (org.hibernate.boot.MetadataSources)7 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)6 TestForIssue (org.hibernate.testing.TestForIssue)4 Metadata (org.hibernate.boot.Metadata)2 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)2 RGlobalMetadata (com.evolveum.midpoint.repo.sql.data.common.RGlobalMetadata)1 HibernateException (org.hibernate.HibernateException)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)1 SQLServerDialect (org.hibernate.dialect.SQLServerDialect)1 ConnectionProvider (org.hibernate.engine.jdbc.connections.spi.ConnectionProvider)1 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)1 RequiresDialect (org.hibernate.testing.RequiresDialect)1 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)1 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)1 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)1 GenerationTarget (org.hibernate.tool.schema.internal.exec.GenerationTarget)1 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)1