use of org.springframework.jdbc.core.JdbcTemplate in project opennms by OpenNMS.
the class TicketNotificationStrategy method getAlarmStateFromEvent.
/**
* <p>Helper function that gets the alarmid from the eventid</p>
*
* @return 0 if alarmid is null
*/
protected AlarmState getAlarmStateFromEvent(int eventID) {
AlarmStateRowCallbackHandler callbackHandler = new AlarmStateRowCallbackHandler();
JdbcTemplate template = new JdbcTemplate(DataSourceFactory.getInstance());
template.query("SELECT a.alarmid, a.tticketid, a.tticketstate FROM events AS e " + "LEFT JOIN alarms AS a ON a.alarmid = e.alarmid " + "WHERE e.eventid = ?", new Object[] { eventID }, callbackHandler);
return callbackHandler.getAlarmState();
}
use of org.springframework.jdbc.core.JdbcTemplate in project cas by apereo.
the class JpaLockingStrategyTests method getOwner.
private String getOwner(final String appId) {
final JdbcTemplate simpleJdbcTemplate = new JdbcTemplate(dataSource);
final List<Map<String, Object>> results = simpleJdbcTemplate.queryForList("SELECT unique_id FROM locks WHERE application_id=?", appId);
if (results.isEmpty()) {
return null;
}
return (String) results.get(0).get("unique_id");
}
use of org.springframework.jdbc.core.JdbcTemplate in project musiccabinet by hakko.
the class PostgreSQLUtil method loadFunction.
/**
* Load a named SQL function to database.
*
* If a previous version with the same name exists, it is dropped by a call to
* function drop_procedure (creation of this function is part of database set-up).
*
* @param rc RequestContext for call
* @param functionName Name of function
* @param functionBody Body of function
* @throws ApplicationException On failure
*/
public static void loadFunction(JdbcTemplateDao dao, PostgreSQLFunction dbFunction) throws ApplicationException {
JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
// initialize drop procedure, if database has been dropped
jdbcTemplate.execute(new ResourceUtil(DROP_FUNCTION.getURI()).getContent());
// drop previous function version, if necessary
jdbcTemplate.queryForInt("select util.drop_function( ?,? )", dbFunction.getSchema(), dbFunction.getFunctionName());
// load new function body
jdbcTemplate.execute(new ResourceUtil(dbFunction.getURI()).getContent());
}
use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.
the class SqlStoredComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String template, Map<String, Object> parameters) throws Exception {
DataSource target = null;
// endpoint options overrule component configured datasource
DataSource ds = resolveAndRemoveReferenceParameter(parameters, "dataSource", DataSource.class);
if (ds != null) {
target = ds;
}
if (target == null) {
// fallback and use component
target = dataSource;
}
if (target == null) {
// check if the registry contains a single instance of DataSource
Set<DataSource> dataSources = getCamelContext().getRegistry().findByType(DataSource.class);
if (dataSources.size() > 1) {
throw new IllegalArgumentException("Multiple DataSources found in the registry and no explicit configuration provided");
} else if (dataSources.size() == 1) {
target = dataSources.stream().findFirst().orElse(null);
}
}
if (target == null) {
throw new IllegalArgumentException("DataSource must be configured");
}
JdbcTemplate jdbcTemplate = new JdbcTemplate(target);
SqlStoredEndpoint endpoint = new SqlStoredEndpoint(uri, this, jdbcTemplate);
endpoint.setTemplate(template);
return endpoint;
}
use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.
the class JdbcAggregationRepository method setDataSource.
public final void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
jdbcTemplate = new JdbcTemplate(dataSource);
}
Aggregations