use of org.springframework.jdbc.datasource.DriverManagerDataSource in project tutorials by eugenp.
the class PersistenceJPAConfig method dataSource.
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.user"));
dataSource.setPassword(env.getProperty("jdbc.pass"));
return dataSource;
}
use of org.springframework.jdbc.datasource.DriverManagerDataSource in project evosuite by EvoSuite.
the class EvoEntityManagerFactory method createEMFWithSpring.
private EntityManagerFactory createEMFWithSpring() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
// DriverManagerDataSource uses the context classloader for some reason...
ClassLoader cl1 = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(EvoEntityManagerFactory.class.getClassLoader());
dataSource.setDriverClassName(org.hsqldb.jdbcDriver.class.getName());
dataSource.setUrl("jdbc:hsqldb:mem:.");
dataSource.setUsername("sa");
dataSource.setPassword("");
Thread.currentThread().setContextClassLoader(cl1);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
// search everything on classpath
em.setPackagesToScan("");
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
try {
/*
The code in this class works fine on Mac, but somehow it crashes on Debian (Lux cluster).
So, the following is just a workaround, although not fully understood while on Debian
it was behaving differently
*/
Field f = LocalContainerEntityManagerFactoryBean.class.getDeclaredField("internalPersistenceUnitManager");
f.setAccessible(true);
DefaultPersistenceUnitManager m = (DefaultPersistenceUnitManager) f.get(em);
m.setDefaultPersistenceUnitRootLocation(null);
} catch (Exception e) {
e.printStackTrace();
}
Properties properties = new Properties();
properties.setProperty("hibernate.show_sql", "true");
properties.setProperty("hibernate.dialect", HSQLDialect.class.getName());
properties.setProperty("hibernate.connection.shutdown", "true");
properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
properties.setProperty("hibernate.classloading.use_current_tccl_as_parent", "false");
em.setJpaProperties(properties);
em.afterPropertiesSet();
return em.getObject();
}
use of org.springframework.jdbc.datasource.DriverManagerDataSource in project simple-java by angryziber.
the class HibernatePhotoSpotRepositoryIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
dataSource = new DriverManagerDataSource("jdbc:h2:mem:hibernate;DB_CLOSE_DELAY=-1", "sa", "sa");
System.setProperty("hibernate.dialect", H2Dialect.class.getName());
System.setProperty("hibernate.hbm2ddl.auto", "create-drop");
AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setAnnotatedClasses(new Class[] { PhotoSpot.class });
sessionFactory.afterPropertiesSet();
repo.hibernate = new HibernateTemplate(sessionFactory.getObject());
}
use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.
the class RdbmsOperationTests method declareParameterAfterCompile.
@Test
public void declareParameterAfterCompile() {
operation.setDataSource(new DriverManagerDataSource());
operation.setSql("select * from mytable");
operation.compile();
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> operation.declareParameter(new SqlParameter(Types.INTEGER)));
}
use of org.springframework.jdbc.datasource.DriverManagerDataSource in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testSuccessfulDriverInitInConvertGeneric.
@Test
public void testSuccessfulDriverInitInConvertGeneric() throws DBDatasourceServiceException {
when(databaseType.getShortName()).thenReturn("GENERIC");
when(connection.getAttributes()).thenReturn(ImmutableMap.of(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS, nativeDriverName));
when(connection.getUsername()).thenReturn("suzy");
when(connection.getPassword()).thenReturn("password");
when(((IDriverLocator) driverLocatorDialect).initialize(nativeDriverName)).thenReturn(true);
DriverManagerDataSource dataSource = (DriverManagerDataSource) PooledDatasourceHelper.convert(connection, () -> dialectService);
verify(((IDriverLocator) driverLocatorDialect), times(1)).initialize(nativeDriverName);
assertThat(dataSource.getUrl(), is(jdbcUrl));
assertThat(dataSource.getUsername(), is("suzy"));
assertThat(dataSource.getPassword(), is("password"));
}
Aggregations