use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NoticeFactory method acknowledge.
/**
* Acknowledge a list of notices with the given username and the given time.
*
* @param noticeIds an array of int.
* @param user a {@link java.lang.String} object.
* @param time a java$util$Date object.
* @throws java.sql.SQLException if any.
*/
public static void acknowledge(int[] noticeIds, String user, Date time) throws SQLException {
if (noticeIds == null || user == null || time == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
if (noticeIds.length > 0) {
StringBuffer update = new StringBuffer("UPDATE NOTIFICATIONS SET RESPONDTIME=?, ANSWEREDBY=?");
update.append(" WHERE NOTIFYID IN (");
update.append(noticeIds[0]);
for (int i = 1; i < noticeIds.length; i++) {
update.append(",");
update.append(noticeIds[i]);
}
update.append(")");
update.append(" AND RESPONDTIME IS NULL");
DBUtils d = new DBUtils(NoticeFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement(update.toString());
d.watch(stmt);
stmt.setTimestamp(1, new Timestamp(time.getTime()));
stmt.setString(2, user);
stmt.executeUpdate();
} finally {
d.cleanUp();
}
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method getEventCount.
/**
* Count the number of events for a given acknowledgement type.
*
* @param ackType a {@link org.opennms.web.event.AcknowledgeType} object.
* @param filters an array of org$opennms$web$filter$Filter objects.
* @return a int.
* @throws java.sql.SQLException if any.
*/
public static int getEventCount(AcknowledgeType ackType, Filter[] filters) throws SQLException {
if (ackType == null || filters == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
int eventCount = 0;
final Connection conn = DataSourceFactory.getInstance().getConnection();
final DBUtils d = new DBUtils(EventFactory.class, conn);
try {
StringBuffer select = new StringBuffer("SELECT COUNT(EVENTID) AS EVENTCOUNT FROM EVENTS LEFT OUTER JOIN NODE USING (NODEID) LEFT OUTER JOIN SERVICE USING (SERVICEID) WHERE ");
select.append(getAcknowledgeTypeClause(ackType));
for (Filter filter : filters) {
select.append(" AND");
select.append(filter.getParamSql());
}
select.append(" AND EVENTDISPLAY='Y' ");
PreparedStatement stmt = conn.prepareStatement(select.toString());
d.watch(stmt);
int parameterIndex = 1;
for (Filter filter : filters) {
parameterIndex += filter.bindParam(stmt, parameterIndex);
}
ResultSet rs = stmt.executeQuery();
d.watch(rs);
if (rs.next()) {
eventCount = rs.getInt("EVENTCOUNT");
}
stmt.close();
} finally {
d.cleanUp();
}
return eventCount;
}
Aggregations