Search in sources :

Example 6 with DriverManagerConnectionProviderImpl

use of org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl in project hibernate-orm by hibernate.

the class IndividuallySchemaValidatorImplTest method testMismatchColumnType.

@Test
public void testMismatchColumnType() throws Exception {
    MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(NameColumn.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(IntegerNameColumn.class);
        metadata = (MetadataImplementor) metadataSources.buildMetadata();
        metadata.validate();
        try {
            getSchemaValidator(metadata);
            Assert.fail("SchemaManagementException expected");
        } catch (SchemaManagementException e) {
            assertEquals("Schema-validation: wrong column type encountered in column [name] in table [SomeSchema.ColumnEntity]; found [varchar (Types#VARCHAR)], but expecting [integer (Types#INTEGER)]", 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 7 with DriverManagerConnectionProviderImpl

use of org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl in project tutorials by eugenp.

the class MapMultiTenantConnectionProvider method initConnectionProviderForTenant.

private void initConnectionProviderForTenant(String tenantId) throws IOException {
    Properties properties = new Properties();
    properties.load(getClass().getResourceAsStream(String.format("/hibernate-database-%s.properties", tenantId)));
    DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
    connectionProvider.configure(properties);
    this.connectionProviderMap.put(tenantId, connectionProvider);
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) Properties(java.util.Properties)

Example 8 with DriverManagerConnectionProviderImpl

use of org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl 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(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);
        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.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 9 with DriverManagerConnectionProviderImpl

use of org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl in project hibernate-orm by hibernate.

the class IndividuallySchemaValidatorImplConnectionTest method setUp.

@Before
public void setUp() throws Exception {
    connectionProvider = new DriverManagerConnectionProviderImpl();
    connectionProvider.configure(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;
        }
    };
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Map(java.util.Map) HashMap(java.util.HashMap) Before(org.junit.Before)

Aggregations

DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)9 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)4 MetadataSources (org.hibernate.boot.MetadataSources)3 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)3 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)3 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)3 JdbcConnectionAccessImpl (org.hibernate.testing.boot.JdbcConnectionAccessImpl)3 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)3 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)3 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)3 Test (org.junit.Test)3 SchemaManagementException (org.hibernate.tool.schema.spi.SchemaManagementException)2 Map (java.util.Map)1 IndividuallySchemaValidatorImpl (org.hibernate.tool.schema.internal.IndividuallySchemaValidatorImpl)1 ExceptionHandler (org.hibernate.tool.schema.spi.ExceptionHandler)1 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)1 SchemaValidator (org.hibernate.tool.schema.spi.SchemaValidator)1 Before (org.junit.Before)1