Search in sources :

Example 1 with RowCallbackHandler

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());
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) LinkedList(java.util.LinkedList)

Example 2 with RowCallbackHandler

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.");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SQLException(java.sql.SQLException) CacheLoaderException(javax.cache.integration.CacheLoaderException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) Person(org.apache.ignite.examples.model.Person)

Example 3 with RowCallbackHandler

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;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) SetMap(org.hisp.dhis.common.SetMap)

Example 4 with RowCallbackHandler

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));
        }
    });
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 5 with RowCallbackHandler

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);
}
Also used : RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

RowCallbackHandler (org.springframework.jdbc.core.RowCallbackHandler)36 ResultSet (java.sql.ResultSet)33 SQLException (java.sql.SQLException)32 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)2 ExportPointInfo (com.serotonin.m2m2.vo.export.ExportPointInfo)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Calendar (org.hisp.dhis.calendar.Calendar)2 PeriodType (org.hisp.dhis.period.PeriodType)2 Test (org.junit.Test)2 MockNode (org.opennms.netmgt.mock.MockNode)2