use of org.springframework.jdbc.core.JdbcTemplate in project perun by CESNET.
the class TaskResultDaoTest method setUp.
@Before
public void setUp() throws InternalErrorException {
if (perunSession == null || jdbcTemplate == null) {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
jdbcTemplate = new JdbcTemplate(dataSource);
}
}
use of org.springframework.jdbc.core.JdbcTemplate in project opennms by OpenNMS.
the class HttpNotificationStrategy method doSql.
private void doSql(String contents) {
if (getSql() == null) {
LOG.info("send: optional sql argument is null.");
return;
}
if (contents == null) {
LOG.info("doSql: HTTP reply is null");
return;
}
LOG.debug("send: compiling expression: {}", getSwitchValue("result-match"));
Pattern p = Pattern.compile(getSwitchValue("result-match"));
Matcher m = p.matcher(contents);
if (m.matches()) {
LOG.debug("send: compiled expression ready to run sql: {}", getSql());
MatchTable matches = new MatchTable(m);
String sqlString = PropertiesUtils.substitute(getSql(), matches);
LOG.debug("send: running sql: {}", sqlString);
JdbcTemplate template = new JdbcTemplate(DataSourceFactory.getInstance());
template.execute(sqlString);
} else {
LOG.info("send: result didn't match, not running sql");
}
}
use of org.springframework.jdbc.core.JdbcTemplate in project opennms by OpenNMS.
the class TemporaryDatabasePostgreSQL method setupDatabase.
public void setupDatabase() throws TemporaryDatabaseException {
try {
setDataSource(new SimpleDataSource(m_driver, m_url + getTestDatabase(), m_adminUser, m_adminPassword));
setAdminDataSource(new SimpleDataSource(m_driver, m_url + "template1", m_adminUser, m_adminPassword));
m_xaDataSource = new PGXADataSource();
m_xaDataSource.setServerName("localhost");
m_xaDataSource.setDatabaseName(getTestDatabase());
m_xaDataSource.setUser(m_adminUser);
m_xaDataSource.setPassword(m_adminPassword);
m_adminXaDataSource = new PGXADataSource();
m_adminXaDataSource.setServerName("localhost");
m_adminXaDataSource.setDatabaseName("template1");
m_adminXaDataSource.setUser(m_adminUser);
m_adminXaDataSource.setPassword(m_adminPassword);
} catch (final ClassNotFoundException e) {
throw new TemporaryDatabaseException("Failed to initialize driver " + m_driver, e);
}
if (!m_useExisting) {
// to the template1 database
synchronized (TEMPLATE1_MUTEX) {
createTestDatabase();
}
}
setJdbcTemplate(new JdbcTemplate(this));
// Test connecting to test database and ensuring we can do a basic query
try {
getJdbcTemplate().queryForObject("SELECT now()", Date.class);
} catch (DataAccessException e) {
throw new TemporaryDatabaseException("Error occurred while testing database is connectable: " + e.getMessage(), e);
}
if (!m_useExisting) {
setupBlame(getJdbcTemplate(), getBlame());
}
}
use of org.springframework.jdbc.core.JdbcTemplate in project libresonic by Libresonic.
the class AbstractDao method namedQueryWithLimit.
protected <T> List<T> namedQueryWithLimit(String sql, RowMapper<T> rowMapper, Map<String, Object> args, int limit) {
long t = System.nanoTime();
JdbcTemplate jdbcTemplate = new JdbcTemplate(daoHelper.getDataSource());
jdbcTemplate.setMaxRows(limit);
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<T> result = namedTemplate.query(sql, args, rowMapper);
log(sql, t);
return result;
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-boot by spring-projects.
the class DataSourceHealthIndicator method setDataSource.
/**
* Set the {@link DataSource} to use.
* @param dataSource the data source
*/
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
Aggregations