Search in sources :

Example 1 with DriverManagerConnectionProviderImpl

use of org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl 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 DriverManagerConnectionProviderImpl

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

the class ConnectionProviderBuilder method buildConnectionProvider.

private static DriverManagerConnectionProviderImpl buildConnectionProvider(Properties props, final boolean allowAggressiveRelease) {
    DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl() {

        public boolean supportsAggressiveRelease() {
            return allowAggressiveRelease;
        }
    };
    connectionProvider.configure(props);
    return connectionProvider;
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)

Example 3 with DriverManagerConnectionProviderImpl

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

the class JtaAwareConnectionProviderImpl method configure.

@Override
public void configure(Map configurationValues) {
    Properties connectionSettings = new Properties();
    transferSetting(Environment.DRIVER, configurationValues, connectionSettings);
    transferSetting(Environment.URL, configurationValues, connectionSettings);
    transferSetting(Environment.USER, configurationValues, connectionSettings);
    transferSetting(Environment.PASS, configurationValues, connectionSettings);
    transferSetting(Environment.ISOLATION, configurationValues, connectionSettings);
    Properties passThroughSettings = ConnectionProviderInitiator.getConnectionProperties(configurationValues);
    if (passThroughSettings != null) {
        for (String setting : passThroughSettings.stringPropertyNames()) {
            transferSetting(Environment.CONNECTION_PREFIX + '.' + setting, configurationValues, connectionSettings);
        }
    }
    connectionSettings.setProperty(Environment.AUTOCOMMIT, "false");
    delegate = new DriverManagerConnectionProviderImpl();
    delegate.configure(connectionSettings);
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) Properties(java.util.Properties)

Example 4 with DriverManagerConnectionProviderImpl

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

the class AbstractMultiTenancyTest method registerConnectionProvider.

// tag::multitenacy-hibernate-MultiTenantConnectionProvider-example[]
protected void registerConnectionProvider(String tenantIdentifier) {
    Properties properties = properties();
    properties.put(Environment.URL, tenantUrl(properties.getProperty(Environment.URL), tenantIdentifier));
    DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
    connectionProvider.configure(properties);
    connectionProviderMap.put(tenantIdentifier, connectionProvider);
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) Properties(java.util.Properties)

Example 5 with DriverManagerConnectionProviderImpl

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

the class SchemaMultiTenantConnectionProvider method initConnectionProvider.

private ConnectionProvider initConnectionProvider() throws IOException {
    Properties properties = new Properties();
    properties.load(getClass().getResourceAsStream("/hibernate-schema-multitenancy.properties"));
    DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
    connectionProvider.configure(properties);
    return connectionProvider;
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) Properties(java.util.Properties)

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