use of org.springframework.jdbc.core.JdbcOperations in project spring-boot by spring-projects.
the class DataSourceInitializerTests method testDataSourceInitializedWithExplicitScript.
@Test
public void testDataSourceInitializedWithExplicitScript() throws Exception {
this.context.register(DataSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.initialize:true", "spring.datasource.schema:" + ClassUtils.addResourcePathToPackagePath(getClass(), "schema.sql"), "spring.datasource.data:" + ClassUtils.addResourcePathToPackagePath(getClass(), "data.sql"));
this.context.refresh();
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue();
assertThat(dataSource).isNotNull();
JdbcOperations template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject("SELECT COUNT(*) from FOO", Integer.class)).isEqualTo(1);
}
use of org.springframework.jdbc.core.JdbcOperations in project uPortal by Jasig.
the class DbTestImpl method printDbInfo.
@Override
public void printDbInfo() {
boolean fail = false;
logger.info("JDBC DataSources");
for (final Entry<String, JdbcOperations> jdbcEntry : this.jdbcOperations.entrySet()) {
final String jdbcName = jdbcEntry.getKey();
try {
logger.info("\t" + jdbcName);
final JdbcOperations jdbcOps = jdbcEntry.getValue();
jdbcOps.execute(new ConnectionCallback<Object>() {
@Override
public Object doInConnection(Connection con) throws SQLException, DataAccessException {
printInfo(con);
return null;
}
});
} catch (Exception e) {
logger.error("\t" + jdbcName + ": parse info", e);
fail = true;
}
logger.info("");
}
logger.info("Hibernate Dialects");
for (final Entry<String, HibernateConfiguration> configEntry : this.hibernateConfigurations.entrySet()) {
final String persistenceUnit = configEntry.getKey();
try {
final HibernateConfiguration hibernateConfiguration = configEntry.getValue();
final SessionFactoryImplementor sessionFactory = hibernateConfiguration.getSessionFactory();
final Dialect dialect = sessionFactory.getDialect();
logger.info("\t" + persistenceUnit + ": " + dialect);
} catch (Exception e) {
logger.error("\t" + persistenceUnit + ": Failed to resolve Dialect", e);
fail = true;
}
logger.info("");
}
if (fail) {
throw new RuntimeException("One or more of the portal data sources is not configured correctly or the target database is not available.");
}
}
Aggregations