use of org.springframework.jdbc.core.RowCallbackHandler in project opennms by OpenNMS.
the class AlarmdIT method assertEmptyAlarmTable.
private void assertEmptyAlarmTable() {
List<String> alarmDescriptions = new LinkedList<>();
m_jdbcTemplate.query("select alarmId, reductionKey, severity from alarms", new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
alarmDescriptions.add(String.format("Alarm[id=%s, reductionKey=%s, severity=%s]", rs.getString(1), rs.getObject(2), rs.getObject(3)));
}
});
assertEquals("Found one or more alarms: " + alarmDescriptions, 0, alarmDescriptions.size());
}
use of org.springframework.jdbc.core.RowCallbackHandler in project ignite by apache.
the class CacheSpringPersonStore method loadCache.
/**
* {@inheritDoc}
*/
@Override
public void loadCache(final IgniteBiInClosure<Long, Person> clo, Object... args) {
if (args == null || args.length == 0 || args[0] == null)
throw new CacheLoaderException("Expected entry count parameter is not provided.");
int entryCnt = (Integer) args[0];
final AtomicInteger cnt = new AtomicInteger();
jdbcTemplate.query("select * from PERSON limit ?", new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
clo.apply(person.id, person);
cnt.incrementAndGet();
}
}, entryCnt);
System.out.println(">>> Loaded " + cnt + " values into cache.");
}
use of org.springframework.jdbc.core.RowCallbackHandler in project dhis2-core by dhis2.
the class HibernateOrganisationUnitStore method getOrganisationUnitDataSetAssocationMap.
@Override
public Map<String, Set<String>> getOrganisationUnitDataSetAssocationMap() {
final String sql = "select ds.uid as ds_uid, ou.uid as ou_uid from datasetsource d " + "left join organisationunit ou on ou.organisationunitid=d.sourceid " + "left join dataset ds on ds.datasetid=d.datasetid";
final SetMap<String, String> map = new SetMap<>();
jdbcTemplate.query(sql, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
String dataSetId = rs.getString("ds_uid");
String organisationUnitId = rs.getString("ou_uid");
map.putValue(organisationUnitId, dataSetId);
}
});
return map;
}
use of org.springframework.jdbc.core.RowCallbackHandler in project opennms by OpenNMS.
the class JdbcEventdServiceManager method dataSourceSync.
/* (non-Javadoc)
* @see org.opennms.netmgt.eventd.EventdServiceManager#dataSourceSync()
*/
/**
* <p>dataSourceSync</p>
*/
@Override
public synchronized void dataSourceSync() {
m_serviceMap.clear();
new JdbcTemplate(m_dataSource).query(SQL_DB_SVC_TABLE_READ, new RowCallbackHandler() {
@Override
public void processRow(ResultSet resultSet) throws SQLException {
m_serviceMap.put(resultSet.getString(2), resultSet.getInt(1));
}
});
}
use of org.springframework.jdbc.core.RowCallbackHandler in project opennms by OpenNMS.
the class DataManager method populateNodesFromDB.
/**
* Populates nodes from the database. For each category in the categories
* list, this reads the services and outage tables to get the initial data,
* creates 'RTCNode' objects that are added to the map and and to the
* appropriate category.
* @param dbConn
* the database connection.
*
* @throws SQLException
* if the database read fails due to an SQL error
* @throws FilterParseException
* if filtering the data against the category rule fails due to
* the rule being incorrect
* @throws RTCException
* if the database read or filtering the data against the
* category rule fails for some reason
*/
private void populateNodesFromDB(String query, Object[] args) throws SQLException, FilterParseException, RTCException {
final String getOutagesInWindow = "select " + " ifsvc.nodeid as nodeid, " + " ifsvc.ipAddr as ipaddr, " + " s.servicename as servicename, " + " o.ifLostService as ifLostService, " + " o.ifRegainedService as ifRegainedService " + " from " + " ifservices ifsvc " + " join " + " service s on (ifsvc.serviceid = s.serviceid) " + "left outer join " + " outages o on " + " (" + " o.nodeid = ifsvc.nodeid " + " and o.ipaddr = ifsvc.ipaddr " + " and o.serviceid = ifsvc.serviceid " + " and " + " (" + " o.ifLostService > ? " + " OR o.ifRegainedService > ? " + " OR o.ifRegainedService is null " + " )" + " ) " + " where ifsvc.status='A' " + (query == null ? "" : "and " + query) + " order by " + " ifsvc.nodeid, ifsvc.ipAddr, ifsvc.serviceid, o.ifLostService ";
long window = (new Date()).getTime() - (24L * 60L * 60L * 1000L);
Timestamp windowTS = new Timestamp(window);
RowCallbackHandler rowHandler = new RTCNodeProcessor();
Object[] sqlArgs = createArgs(windowTS, windowTS, args);
m_jdbcTemplate.query(getOutagesInWindow, sqlArgs, rowHandler);
}
Aggregations