dbipinterfaceentry.java
来自「opennms得相关源码 请大家看看」· Java 代码 · 共 1,120 行 · 第 1/3 页
JAVA
1,120 行
stmt.setNull(ndx++, Types.VARCHAR); } if ((m_changed & CHANGED_MANAGED) == CHANGED_MANAGED) { if (m_managedState == STATE_UNKNOWN) stmt.setNull(ndx++, Types.CHAR); else stmt.setString(ndx++, new String(new char[] { m_managedState })); } if ((m_changed & CHANGED_STATUS) == CHANGED_STATUS) { if (m_status == -1) stmt.setNull(ndx++, Types.INTEGER); else stmt.setInt(ndx++, m_status); } if ((m_changed & CHANGED_POLLTIME) == CHANGED_POLLTIME) { if (m_lastPoll != null) { stmt.setTimestamp(ndx++, m_lastPoll); } else stmt.setNull(ndx++, Types.TIMESTAMP); } if ((m_changed & CHANGED_PRIMARY) == CHANGED_PRIMARY) { if (m_primaryState == SNMP_UNKNOWN) stmt.setNull(ndx++, Types.CHAR); else stmt.setString(ndx++, new String(new char[] { m_primaryState })); } stmt.setInt(ndx++, m_nodeId); stmt.setString(ndx++, m_ipAddr.getHostAddress()); if (m_useIfIndexAsKey) { if (m_ifIndex == -1) stmt.setNull(ndx++, Types.INTEGER); else stmt.setInt(ndx++, m_ifIndex); } // Run the insert // int rc = stmt.executeUpdate(); log.debug("DbIpInterfaceEntry.update: update result = " + rc); } finally { if (stmt != null) stmt.close(); } // clear the mask and mark as backed // by the database // m_changed = 0; } /** * Load the current interface from the database. If the interface was * modified, the modifications are lost. The nodeid and ip address must be * set prior to this call. * * @param c * The connection used to load the data. * * @throws java.sql.SQLException * Thrown if an error occurs with the connection */ private boolean load(Connection c) throws SQLException { if (!m_fromDb) throw new IllegalStateException("The record does not exists in the database"); // create the Prepared statment and then // start setting the result values // PreparedStatement stmt = null; if (m_useIfIndexAsKey) { stmt = c.prepareStatement(SQL_LOAD_REC_IFINDEX); stmt.setInt(1, m_nodeId); stmt.setString(2, m_ipAddr.getHostAddress()); stmt.setInt(3, m_ifIndex); } else { stmt = c.prepareStatement(SQL_LOAD_REC); stmt.setInt(1, m_nodeId); stmt.setString(2, m_ipAddr.getHostAddress()); } // Run the insert // ResultSet rset = stmt.executeQuery(); if (!rset.next()) { rset.close(); stmt.close(); return false; } // extract the values. // int ndx = 1; // get the ifIndex // m_ifIndex = rset.getInt(ndx++); if (rset.wasNull()) m_ifIndex = -1; // get the hostname // m_hostname = rset.getString(ndx++); if (rset.wasNull()) m_hostname = null; // get the managed status // String str = rset.getString(ndx++); if (str != null && rset.wasNull() == false) m_managedState = str.charAt(0); else m_managedState = STATE_UNKNOWN; // get the status // m_status = rset.getInt(ndx++); if (rset.wasNull()) m_status = -1; // get the time // m_lastPoll = rset.getTimestamp(ndx++); // get the snmp primary state // str = rset.getString(ndx++); if (str != null && rset.wasNull() == false) m_primaryState = str.charAt(0); else m_primaryState = STATE_UNKNOWN; rset.close(); stmt.close(); // clear the mask and mark as backed // by the database // m_changed = 0; return true; } /** * Default constructor. * */ private DbIpInterfaceEntry() { throw new UnsupportedOperationException("Default constructor not supported!"); } /** * Constructs a new interface. * * @param nid * The node identifier. * @param address * The target interface address. * @param exists * True if the interface already exists. * */ private DbIpInterfaceEntry(int nid, InetAddress address, boolean exists) { m_fromDb = exists; m_nodeId = nid; m_ipAddr = address; m_ifIndex = -1; m_managedState = STATE_UNKNOWN; m_status = -1; m_lastPoll = null; m_primaryState = SNMP_UNKNOWN; m_changed = 0; m_useIfIndexAsKey = false; } /** * Constructs a new interface, this constructor will only work for entries * loaded from the database! * * @param nid * The node identifier. * @param address * The target interface address. * @param ifIndex * The target ifIndex of the node/address pair * @param exists * True if the interface already exists. * */ private DbIpInterfaceEntry(int nid, InetAddress address, int ifIndex, boolean exists) { m_fromDb = exists; m_nodeId = nid; m_ipAddr = address; m_ifIndex = ifIndex; m_status = -1; m_lastPoll = null; m_managedState = STATE_UNKNOWN; m_primaryState = SNMP_UNKNOWN; m_changed = 0; m_useIfIndexAsKey = true; } /** * Returns the node entry's unique identifier. This is a non-mutable * element. If the record does not yet exist in the database then a -1 is * returned. * */ int getNodeId() { return m_nodeId; } /** * Returns the name of the distributed poller for the entry. This is a * non-mutable element of the record. * */ InetAddress getIfAddress() { return m_ipAddr; } /** * Gets the last poll time of the record */ String getLastPollString() { String result = null; if (m_lastPoll != null) { result = m_lastPoll.toString(); } return result; } /** * Gets the last poll time of the record */ Timestamp getLastPoll() { return m_lastPoll; } /** * Sets the current creation time. * * @param time * The creation time. * */ void setLastPoll(String time) throws ParseException { if (time == null) { m_lastPoll = null; } else { Date tmpDate = EventConstants.parseToDate(time); m_lastPoll = new Timestamp(tmpDate.getTime()); } m_changed |= CHANGED_POLLTIME; } /** * Sets the current creation time. * * @param time * The creation time. * */ void setLastPoll(Date time) { m_lastPoll = new Timestamp(time.getTime()); m_changed |= CHANGED_POLLTIME; } /** * Sets the current creation time. * * @param time * The creation time. * */ void setLastPoll(Timestamp time) { m_lastPoll = time; m_changed |= CHANGED_POLLTIME; } /** * Returns true if the ifIndex is defined. */ boolean hasIfIndex() { return m_ifIndex != -1; } /** * Returns the current ifIndex */ int getIfIndex() { return m_ifIndex; } /** * Sets the ifIndex value * * @param ndx * The new ifIndex. */ void setIfIndex(int ndx) { m_ifIndex = ndx; m_changed |= CHANGED_IFINDEX; } boolean hasIfIndexChanged() { if ((m_changed & CHANGED_IFINDEX) == CHANGED_IFINDEX) return true; else return false; } boolean updateIfIndex(int newIfIndex) { if (newIfIndex != -1 && newIfIndex != m_ifIndex) { setIfIndex(newIfIndex); return true; } return false; } /** * Returns the current hostname. */ String getHostname() { return m_hostname; } /** * Sets the current hostname. * * @param name * The new hostname */ void setHostname(String name) { m_hostname = name; m_changed |= CHANGED_HOSTNAME; } boolean hasHostnameChanged() { if ((m_changed & CHANGED_HOSTNAME) == CHANGED_HOSTNAME) return true; else return false; } boolean updateHostname(String newHostname) { boolean doUpdate = false; if (newHostname != null && m_hostname != null) { if (!newHostname.equals(m_hostname)) doUpdate = true; } else if (newHostname == null && m_hostname == null) { // do nothing } else // one is null the other isn't, do the update doUpdate = true; if (doUpdate) { setHostname(newHostname); return true; } else return false; } /** * Returns the current managed state of the interface */ char getManagedState() { return m_managedState; } /**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?