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();
}
}
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);
}
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();
}
}
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;
}
};
}
Aggregations