notificationmodel.java
来自「opennms得相关源码 请大家看看」· Java 代码 · 共 516 行 · 第 1/2 页
JAVA
516 行
nbean.m_responder = (String) element; element = new Integer(rs.getInt(NODE)); nbean.m_nodeID = ((Integer) element).intValue(); element = rs.getString(INTERFACE); nbean.m_interfaceID = (String) element; element = new Integer(rs.getInt(SERVICE)); nbean.m_serviceId = ((Integer) element).intValue(); element = new Integer(rs.getInt(EVENTID)); nbean.m_eventId = ((Integer) element).intValue(); Statement stmttmp = conn.createStatement(); ResultSet rstmp = stmttmp.executeQuery("SELECT servicename from service where serviceid = " + nbean.m_serviceId); if (rstmp.next()) { element = rstmp.getString("servicename"); if (element != null) { nbean.m_serviceName = (String) element; } } rstmp.close(); stmttmp.close(); vector.addElement(nbean); } } catch (SQLException e) { m_logger.debug("Error:" + e.getLocalizedMessage()); m_logger.debug("Error occured in rs2NotifyBean"); throw e; } notices = new Notification[vector.size()]; for (int i = 0; i < notices.length; i++) { notices[i] = (Notification) vector.elementAt(i); } return notices; } /** * This method returns the count of all outstanding notices. */ public Notification[] getOutstandingNotices() throws SQLException { Notification[] notices = null; Connection conn = Vault.getDbConnection(); try { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(OUTSTANDING); notices = rs2NotifyBean(conn, rs); rs.close(); stmt.close(); } catch (SQLException e) { m_logger.debug("Problem getting data from the notifications table."); m_logger.debug("Error: " + e.getLocalizedMessage()); throw e; } finally { Vault.releaseDbConnection(conn); } return (notices); } /** * This method returns notices not yet acknowledged. */ public int getOutstandingNoticeCount() throws SQLException { int count = 0; Connection conn = Vault.getDbConnection(); try { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(OUTSTANDING_COUNT); if (rs.next()) { count = rs.getInt("TOTAL"); } rs.close(); stmt.close(); } catch (SQLException e) { m_logger.debug("Problem getting data from the notifications table."); m_logger.debug("Error: " + e.getLocalizedMessage()); throw e; } finally { Vault.releaseDbConnection(conn); } return (count); } /** * This method returns notices not yet acknowledged. */ public int getOutstandingNoticeCount(String username) throws SQLException { if (username == null) { throw new IllegalArgumentException("Cannot take null parameters."); } int count = 0; Connection conn = Vault.getDbConnection(); try { PreparedStatement pstmt = conn.prepareStatement(USER_OUTSTANDING_COUNT); pstmt.setString(1, username); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { count = rs.getInt("TOTAL"); } rs.close(); pstmt.close(); } catch (SQLException e) { m_logger.debug("Problem getting data from the notifications table."); m_logger.debug("Error: " + e.getLocalizedMessage()); throw e; } finally { Vault.releaseDbConnection(conn); } return (count); } /** * This method returns notices not yet acknowledged. */ public Notification[] getOutstandingNotices(String name) throws SQLException { Notification[] notices = null; Connection conn = Vault.getDbConnection(); try { PreparedStatement pstmt = conn.prepareStatement(USER_OUTSTANDING); pstmt.setString(1, name); ResultSet rs = pstmt.executeQuery(); notices = rs2NotifyBean(conn, rs); rs.close(); pstmt.close(); } catch (SQLException e) { m_logger.debug("Problem getting data from the notifications table."); m_logger.debug("Error: " + e.getLocalizedMessage()); throw e; } finally { Vault.releaseDbConnection(conn); } return (notices); } /** * This method updates the table when the user acknowledges the pager * information. */ public void acknowledged(String name, int noticeId) throws SQLException { if (name == null) { throw new IllegalArgumentException("Cannot take null parameters."); } Connection conn = Vault.getDbConnection(); try { PreparedStatement pstmt = conn.prepareStatement("UPDATE notifications SET respondtime = ? , answeredby = ? WHERE notifyid= ?"); pstmt.setTimestamp(1, new Timestamp(System.currentTimeMillis())); pstmt.setString(2, name); pstmt.setInt(3, noticeId); pstmt.execute(); pstmt.close(); } catch (SQLException e) { m_logger.debug("Problem acknowledging."); m_logger.debug("Error: " + e.getLocalizedMessage()); throw e; } finally { Vault.releaseDbConnection(conn); } } /** * This method helps insert into the database. */ public void insert(Notification nbean) throws SQLException { if (nbean == null || nbean.m_txtMsg == null) { throw new IllegalArgumentException("Cannot take null parameters."); } Connection conn = Vault.getDbConnection(); try { PreparedStatement pstmt = conn.prepareStatement(INSERT_NOTIFY); pstmt.setString(1, nbean.m_txtMsg); pstmt.setString(2, nbean.m_numMsg); pstmt.setLong(3, nbean.m_timeSent); pstmt.setLong(4, nbean.m_timeReply); pstmt.setString(5, nbean.m_responder); pstmt.setInt(6, nbean.m_nodeID); pstmt.setString(7, nbean.m_interfaceID); pstmt.setInt(8, nbean.m_serviceId); pstmt.setInt(9, nbean.m_eventId); pstmt.execute(); // Close prepared statement. pstmt.close(); } catch (SQLException e) { m_logger.debug("Problem getting data from the notifications table."); m_logger.debug("Error: " + e.getLocalizedMessage()); throw e; } finally { Vault.releaseDbConnection(conn); } } /** * This method may be used to insert / update the database. */ /* * public void execute(String query) { if(m_dbConn == null) { * m_logger.debug("Problem executing query."); m_logger.debug("We do not * have a database connection yet"); } else { try { Statement stmt = * m_dbConn.createStatement(); stmt.executeQuery(query); * // Close statement. if(stmt != null) stmt.close(); } catch(Exception e) { * m_logger.debug("Problem inserting"); m_logger.debug("Error: " + * e.getLocalizedMessage()); } } } */ /** * This method is used for formatting the date attributes in a proper * format. */ private String appendZero(String values) { int len = values.length(); if (values != null) { if (len >= 0 && len < 2) { while (2 - len > 0) { values = "0" + values; len++; } } else if (len > 2) m_logger.debug("Incorrect attributes for time"); } return values; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?