use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method getEventCountForNode.
/**
* Return the number of events for this node and the given acknowledgment
* type.
*
* @param nodeId a int.
* @param ackType a {@link org.opennms.web.event.AcknowledgeType} object.
* @return a int.
* @throws java.sql.SQLException if any.
*/
public static int getEventCountForNode(int nodeId, AcknowledgeType ackType) throws SQLException {
if (ackType == 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 WHERE ");
select.append(getAcknowledgeTypeClause(ackType));
select.append(" AND NODEID=?");
select.append(" AND EVENTDISPLAY='Y' ");
final PreparedStatement stmt = conn.prepareStatement(select.toString());
d.watch(stmt);
stmt.setInt(1, nodeId);
final ResultSet rs = stmt.executeQuery();
d.watch(rs);
if (rs.next()) {
eventCount = rs.getInt("EVENTCOUNT");
}
} finally {
d.cleanUp();
}
return eventCount;
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method unacknowledgeAll.
/**
* Unacknowledge all acknowledged events.
*
* @throws java.sql.SQLException if any.
*/
public static void unacknowledgeAll() throws SQLException {
final DBUtils d = new DBUtils(EventFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement("UPDATE EVENTS SET EVENTACKUSER=NULL, EVENTACKTIME=NULL WHERE EVENTACKUSER IS NOT NULL");
d.watch(stmt);
stmt.executeUpdate();
} finally {
d.cleanUp();
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method unacknowledge.
/**
* Unacknowledge events that match the given filter criteria.
*
* @param filters an array of org$opennms$web$filter$Filter objects.
* @throws java.sql.SQLException if any.
*/
public static void unacknowledge(Filter[] filters) throws SQLException {
if (filters == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
StringBuffer update = new StringBuffer("UPDATE EVENTS SET EVENTACKUSER=NULL, EVENTACKTIME=NULL WHERE");
update.append(getAcknowledgeTypeClause(AcknowledgeType.ACKNOWLEDGED));
for (Filter filter : filters) {
update.append(" AND");
update.append(filter.getParamSql());
}
final DBUtils d = new DBUtils(EventFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement(update.toString());
d.watch(stmt);
int parameterIndex = 1;
for (Filter filter : filters) {
parameterIndex += filter.bindParam(stmt, parameterIndex);
}
stmt.executeUpdate();
} finally {
d.cleanUp();
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method acknowledgeAll.
/**
* Acknowledge all unacknowledged events with the given username and the
* given time.
*
* @param user a {@link java.lang.String} object.
* @param time a java$util$Date object.
* @throws java.sql.SQLException if any.
*/
public static void acknowledgeAll(String user, Date time) throws SQLException {
if (user == null || time == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
final DBUtils d = new DBUtils(EventFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement("UPDATE EVENTS SET EVENTACKUSER=?, EVENTACKTIME=? WHERE EVENTACKUSER IS NULL");
d.watch(stmt);
stmt.setString(1, user);
stmt.setTimestamp(2, new Timestamp(time.getTime()));
stmt.executeUpdate();
} finally {
d.cleanUp();
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method acknowledge.
/**
* Acknowledge with the given username and the given time all events that
* match the given filter criteria.
*
* @param filters an array of org$opennms$web$filter$Filter objects.
* @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(Filter[] filters, String user, Date time) throws SQLException {
if (filters == null || user == null || time == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
StringBuffer update = new StringBuffer("UPDATE EVENTS SET EVENTACKUSER=?, EVENTACKTIME=? WHERE");
update.append(getAcknowledgeTypeClause(AcknowledgeType.UNACKNOWLEDGED));
for (Filter filter : filters) {
update.append(" AND");
update.append(filter.getParamSql());
}
final DBUtils d = new DBUtils(EventFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement(update.toString());
d.watch(stmt);
stmt.setString(1, user);
stmt.setTimestamp(2, new Timestamp(time.getTime()));
int parameterIndex = 3;
for (Filter filter : filters) {
parameterIndex += filter.bindParam(stmt, parameterIndex);
}
stmt.executeUpdate();
} finally {
d.cleanUp();
}
}
Aggregations