Search in sources :

Example 1 with DdlTransactionIsolatorTestingImpl

use of org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl 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 DdlTransactionIsolatorTestingImpl ddlTransactionIsolator = new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess(connectionProvider));
    try {
        final GenerationTarget target = new GenerationTargetToDatabase(ddlTransactionIsolator, false);
        try {
            new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, false, target);
            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);
        }
    } finally {
        ddlTransactionIsolator.release();
    }
}
Also used : JdbcEnvironmentInitiator(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator) HibernateException(org.hibernate.HibernateException) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SchemaValidator(org.hibernate.tool.hbm2ddl.SchemaValidator) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) DdlTransactionIsolatorTestingImpl(org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) GenerationTarget(org.hibernate.tool.schema.internal.exec.GenerationTarget) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) BaseUnitTest(org.hibernate.testing.orm.junit.BaseUnitTest) Test(org.junit.jupiter.api.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with DdlTransactionIsolatorTestingImpl

use of org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl in project hibernate-orm by hibernate.

the class IndividuallySchemaValidatorImplConnectionTest method testMissingEntityContainsUnqualifiedEntityName.

@Test
public void testMissingEntityContainsUnqualifiedEntityName() throws Exception {
    MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(UnqualifiedMissingEntity.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(PropertiesHelper.map(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(UnqualifiedMissingEntity.class);
        metadata = (MetadataImplementor) metadataSources.buildMetadata();
        metadata.validate();
        SchemaValidator schemaValidator = new IndividuallySchemaValidatorImpl(tool, DefaultSchemaFilter.INSTANCE);
        assertFalse(connection.getAutoCommit());
        schemaValidator.doValidation(metadata, executionOptions, ContributableMatcher.ALL);
        assertFalse(connection.getAutoCommit());
    } 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) SchemaValidator(org.hibernate.tool.schema.spi.SchemaValidator) IndividuallySchemaValidatorImpl(org.hibernate.tool.schema.internal.IndividuallySchemaValidatorImpl) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) DdlTransactionIsolatorTestingImpl(org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) Test(org.junit.Test)

Example 3 with DdlTransactionIsolatorTestingImpl

use of org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl in project hibernate-orm by hibernate.

the class SuppliedConnectionTest method cleanupTest.

@Override
protected void cleanupTest() throws Exception {
    try {
        Connection conn = cp.getConnection();
        try {
            final GenerationTargetToDatabase target = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry(), conn), true);
            new SchemaDropperImpl(serviceRegistry()).doDrop(metadata(), false, target);
        } finally {
            cp.closeConnection(conn);
        }
    } catch (Throwable ignore) {
    }
    super.cleanupTest();
}
Also used : DdlTransactionIsolatorTestingImpl(org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) Connection(java.sql.Connection) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)

Example 4 with DdlTransactionIsolatorTestingImpl

use of org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl in project hibernate-orm by hibernate.

the class AbstractMultiTenancyTest method sessionFactory.

protected SessionFactory sessionFactory(Map<String, Object> settings) {
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    for (Class annotatedClasses : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(annotatedClasses);
    }
    Metadata metadata = metadataSources.buildMetadata();
    HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
    tool.injectServices(serviceRegistry);
    final GenerationTargetToDatabase frontEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(FRONT_END_TENANT)));
    final GenerationTargetToDatabase backEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(BACK_END_TENANT)));
    new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
    new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
    final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
    return sessionFactoryBuilder.build();
}
Also used : DdlTransactionIsolatorTestingImpl(org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)

Example 5 with DdlTransactionIsolatorTestingImpl

use of org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl in project hibernate-orm by hibernate.

the class DatabaseTimeZoneMultiTenancyTest method sessionFactory.

protected SessionFactory sessionFactory(Map<String, Object> settings) {
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    for (Class annotatedClasses : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(annotatedClasses);
    }
    Metadata metadata = metadataSources.buildMetadata();
    HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
    tool.injectServices(serviceRegistry);
    final GenerationTargetToDatabase frontEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(FRONT_END_TENANT)));
    final GenerationTargetToDatabase backEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(BACK_END_TENANT)));
    new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
    new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
    final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
    return sessionFactoryBuilder.build();
}
Also used : DdlTransactionIsolatorTestingImpl(org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)

Aggregations

DdlTransactionIsolatorTestingImpl (org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl)11 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)10 MetadataSources (org.hibernate.boot.MetadataSources)9 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)9 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)9 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)8 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)6 HashMap (java.util.HashMap)5 Metadata (org.hibernate.boot.Metadata)5 SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)4 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)4 Test (org.junit.Test)4 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)3 JdbcConnectionAccessImpl (org.hibernate.testing.boot.JdbcConnectionAccessImpl)3 Connection (java.sql.Connection)2 ConnectionProvider (org.hibernate.engine.jdbc.connections.spi.ConnectionProvider)2 JdbcEnvironmentInitiator (org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 RootClass (org.hibernate.mapping.RootClass)2