use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class MockDatabaseIT method testIFQuery.
public void testIFQuery() {
Querier querier = new Querier(m_db, "select * from ipInterface") {
@Override
public void processRow(ResultSet rs) throws SQLException {
int nodeId = rs.getInt("nodeId");
String ipAddr = rs.getString("ipAddr");
MockInterface iface = m_network.getInterface(nodeId, ipAddr);
assertNotNull(iface);
assertEquals(nodeId, iface.getNodeId());
assertEquals(ipAddr, iface.getIpAddr());
}
};
querier.execute();
assertEquals(m_network.getInterfaceCount(), querier.getCount());
}
use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class MockDatabaseIT method testMultipleDatabases.
public void testMultipleDatabases() throws Exception {
m_secondDb = new MockDatabase(m_db.getTestDatabase() + "_test2");
Querier secondQuerier = new Querier(m_secondDb, "select * from node");
secondQuerier.execute();
Querier querier = new Querier(m_db, "select * from node");
querier.execute();
assertFalse(secondQuerier.getCount() == querier.getCount());
MockNode node = m_network.getNode(1);
m_secondDb.writeNode(node);
secondQuerier = new Querier(m_secondDb, "select * from node");
secondQuerier.execute();
assertEquals(1, secondQuerier.getCount());
}
use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class NotificationManager method getActiveNodes.
/**
* <p>getActiveNodes</p>
*
* @return a {@link java.util.List} object.
* @throws java.sql.SQLException if any.
*/
public List<Integer> getActiveNodes() throws SQLException {
final List<Integer> allNodes = new ArrayList<>();
Querier querier = new Querier(m_dataSource, "SELECT n.nodeid FROM node n WHERE n.nodetype != 'D' ORDER BY n.nodelabel", new RowProcessor() {
@Override
public void processRow(ResultSet rs) throws SQLException {
allNodes.add(rs.getInt(1));
}
});
querier.execute(new Object[] {});
return allNodes;
}
use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class NotificationManager method rebuildParameterMap.
/**
* <p>rebuildParameterMap</p>
*
* @param notifId a int.
* @param resolutionPrefix a {@link java.lang.String} object.
* @param skipNumericPrefix a boolean.
* @return a {@link java.util.Map} object.
* @throws java.lang.Exception if any.
*/
public Map<String, String> rebuildParameterMap(final int notifId, final String resolutionPrefix, final boolean skipNumericPrefix) throws Exception {
final Map<String, String> parmMap = new HashMap<String, String>();
Querier querier = new Querier(m_dataSource, "select notifications.*, service.* from notifications left outer join service on notifications.serviceID = service.serviceID where notifyId = ?") {
@Override
public void processRow(ResultSet rs) throws SQLException {
/*
* Note, getString on results is valid for any SQL data type except the new SQL types:
* Blog, Clob, Array, Struct, Ref
* of which we have none in this table so this row processor is using getString
* to correctly align with annotated types in the map.
*/
parmMap.put(NotificationManager.PARAM_TEXT_MSG, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("textMsg"));
if (skipNumericPrefix) {
parmMap.put(NotificationManager.PARAM_NUM_MSG, rs.getString("numericMsg"));
} else {
parmMap.put(NotificationManager.PARAM_NUM_MSG, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("numericMsg"));
}
parmMap.put(NotificationManager.PARAM_SUBJECT, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("subject"));
parmMap.put(NotificationManager.PARAM_NODE, rs.getString("nodeID"));
parmMap.put(NotificationManager.PARAM_INTERFACE, rs.getString("interfaceID"));
parmMap.put(NotificationManager.PARAM_SERVICE, rs.getString("serviceName"));
parmMap.put("noticeid", rs.getString("notifyID"));
parmMap.put("eventID", rs.getString("eventID"));
parmMap.put("eventUEI", rs.getString("eventUEI"));
Notification notification = null;
try {
notification = getNotification(rs.getObject("notifConfigName").toString());
} catch (IOException e) {
}
if (notification != null) {
addNotificationParams(parmMap, notification);
}
}
};
querier.execute(notifId);
return parmMap;
}
use of org.opennms.core.utils.Querier in project opennms by OpenNMS.
the class NotificationManager method getEvent.
/**
* In the absence of DAOs and ORMs this creates an Event object from the persisted
* record.
*
* @param eventid a int.
* @return a populated Event object
*/
public Event getEvent(final int eventid) {
// don't switch using event builder since this event is read from the database
final Event event = new Event();
Querier querier = new Querier(m_dataSource, "select * from events where eventid = ?", new RowProcessor() {
@Override
public void processRow(ResultSet rs) throws SQLException {
event.setDbid(rs.getInt("eventid"));
event.setUei(rs.getString("eventuei"));
event.setNodeid(rs.getLong("nodeid"));
event.setTime(rs.getDate("eventtime"));
event.setHost(rs.getString("eventhost"));
event.setInterface(rs.getString("ipaddr"));
event.setSnmphost(rs.getString("eventsnmphost"));
event.setService(getServiceName(rs.getInt("serviceid")));
event.setCreationTime(rs.getDate("eventcreatetime"));
event.setSeverity(rs.getString("eventseverity"));
event.setPathoutage(rs.getString("eventpathoutage"));
Tticket tticket = new Tticket();
tticket.setContent(rs.getString("eventtticket"));
tticket.setState(rs.getString("eventtticketstate"));
event.setTticket(tticket);
event.setSource(rs.getString("eventsource"));
}
private String getServiceName(int serviceid) {
SingleResultQuerier querier = new SingleResultQuerier(m_dataSource, "select servicename from service where serviceid = ?");
return (String) querier.getResult();
}
});
querier.execute(eventid);
return event;
}
Aggregations