use of org.hibernate.testing.util.jpa.DelegatingPersistenceUnitInfo in project hibernate-orm by hibernate.
the class PersistenceUnitOverridesTests method testPassingIntegrationJpaJdbcOverrideForJtaDataSourceProperty.
@Test
public void testPassingIntegrationJpaJdbcOverrideForJtaDataSourceProperty() {
PersistenceProvider provider = new HibernatePersistenceProvider() {
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map integrationOverrides) {
return super.createContainerEntityManagerFactory(new DelegatingPersistenceUnitInfo(info) {
// inject a JPA JTA DataSource setting into the PU
final DataSource puDataSource;
final Properties puProperties;
{
puDataSource = new DataSourceStub("puDataSource");
puProperties = new Properties();
puProperties.putAll(info.getProperties());
puProperties.put(AvailableSettings.JPA_JTA_DATASOURCE, puDataSource);
}
@Override
public DataSource getJtaDataSource() {
return null;
}
@Override
public DataSource getNonJtaDataSource() {
return null;
}
@Override
public Properties getProperties() {
return puProperties;
}
}, integrationOverrides);
}
};
final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(new PersistenceUnitInfoAdapter(), // a JTA DataSource (nor the reverse). However, that is a useful thing to support
ConnectionProviderBuilder.getJpaConnectionProviderProperties("db2"));
try {
final Map<String, Object> properties = emf.getProperties();
final Object hibernateJdbcDriver = properties.get(AvailableSettings.URL);
assertThat(hibernateJdbcDriver, notNullValue());
final Object jpaJdbcDriver = properties.get(AvailableSettings.JPA_JDBC_URL);
assertThat((String) jpaJdbcDriver, containsString("db2"));
// see if the values had the affect to adjust the `ConnectionProvider` used
final ConnectionProvider connectionProvider = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(ConnectionProvider.class);
assertThat(connectionProvider, instanceOf(DriverManagerConnectionProviderImpl.class));
} finally {
emf.close();
}
}
use of org.hibernate.testing.util.jpa.DelegatingPersistenceUnitInfo in project hibernate-orm by hibernate.
the class PersistenceUnitOverridesTests method testPassingIntegrationJpaDataSourceOverrideForJtaDataSourceElement.
@Test
public // )
void testPassingIntegrationJpaDataSourceOverrideForJtaDataSourceElement() {
final DataSource puDataSource = new DataSourceStub("puDataSource");
final DataSource integrationDataSource = new DataSourceStub("integrationDataSource");
PersistenceProvider provider = new HibernatePersistenceProvider() {
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map integrationOverrides) {
return super.createContainerEntityManagerFactory(new DelegatingPersistenceUnitInfo(info) {
@Override
public DataSource getJtaDataSource() {
// - as opposed using `javax.persistence.jtaDataSource` under the `properties` element
return puDataSource;
}
}, integrationOverrides);
}
};
final Map integrationOverrides = new HashMap();
// noinspection unchecked
integrationOverrides.put(AvailableSettings.JPA_JTA_DATASOURCE, integrationDataSource);
// todo (6.0) : fix for Oracle see HHH-13432
// integrationOverrides.put( AvailableSettings.HQL_BULK_ID_STRATEGY, new MultiTableBulkIdStrategyStub() );
final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(new PersistenceUnitInfoAdapter(), integrationOverrides);
try {
final Map<String, Object> properties = emf.getProperties();
final Object datasource = properties.get(AvailableSettings.JPA_JTA_DATASOURCE);
assertThat(datasource, is(integrationDataSource));
// see if the values had the affect to adjust the `ConnectionProvider` used
final ConnectionProvider connectionProvider = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(ConnectionProvider.class);
assertThat(connectionProvider, instanceOf(DatasourceConnectionProviderImpl.class));
final DatasourceConnectionProviderImpl datasourceConnectionProvider = (DatasourceConnectionProviderImpl) connectionProvider;
assertThat(datasourceConnectionProvider.getDataSource(), is(integrationDataSource));
} finally {
emf.close();
}
}
use of org.hibernate.testing.util.jpa.DelegatingPersistenceUnitInfo in project hibernate-orm by hibernate.
the class PersistenceUnitOverridesTests method testPassingIntegrationJpaJdbcOverridesForJtaDataSourceElement.
@Test
public // )
void testPassingIntegrationJpaJdbcOverridesForJtaDataSourceElement() {
PersistenceProvider provider = new HibernatePersistenceProvider() {
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map integrationOverrides) {
return super.createContainerEntityManagerFactory(new DelegatingPersistenceUnitInfo(info) {
// inject a JPA JTA DataSource setting into the PU
final DataSource puDataSource = new DataSourceStub("puDataSource");
@Override
public DataSource getJtaDataSource() {
return puDataSource;
}
}, integrationOverrides);
}
};
final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(new PersistenceUnitInfoAdapter(), // a JTA DataSource (nor the reverse). However, that is a useful thing to support
ConnectionProviderBuilder.getJpaConnectionProviderProperties("db2"));
try {
final Map<String, Object> properties = emf.getProperties();
final Object hibernateJdbcDriver = properties.get(AvailableSettings.URL);
assertThat(hibernateJdbcDriver, notNullValue());
final Object jpaJdbcDriver = properties.get(AvailableSettings.JPA_JDBC_URL);
assertThat((String) jpaJdbcDriver, containsString("db2"));
// see if the values had the affect to adjust the `ConnectionProvider` used
final ConnectionProvider connectionProvider = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(ConnectionProvider.class);
assertThat(connectionProvider, instanceOf(DriverManagerConnectionProviderImpl.class));
} finally {
emf.close();
}
}
Aggregations