Search in sources :

Example 21 with DBUtils

use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.

the class NotificationWizardServlet method setCriticalPath.

private void setCriticalPath(final int node, final String criticalIp, final String criticalSvc, final Connection conn) throws SQLException {
    final DBUtils d = new DBUtils(getClass());
    try {
        final PreparedStatement stmt = conn.prepareStatement(SQL_SET_CRITICAL_PATH);
        d.watch(stmt);
        stmt.setInt(1, node);
        stmt.setString(2, InetAddressUtils.normalize(criticalIp));
        stmt.setString(3, criticalSvc);
        stmt.execute();
    } finally {
        d.cleanUp();
    }
}
Also used : DBUtils(org.opennms.core.utils.DBUtils) PreparedStatement(java.sql.PreparedStatement)

Example 22 with DBUtils

use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.

the class NotificationWizardServlet method updatePaths.

private void updatePaths(final String rule, final String criticalIp, final String criticalSvc) throws FilterParseException, SQLException {
    final Connection conn = DataSourceFactory.getInstance().getConnection();
    final DBUtils d = new DBUtils(getClass(), conn);
    try {
        final SortedMap<Integer, String> nodes = getFilterDao().getNodeMap(rule);
        for (final Map.Entry<Integer, String> entry : nodes.entrySet()) {
            final int key = entry.getKey().intValue();
            deleteCriticalPath(key, conn);
            if (criticalIp != null && !"".equals(criticalIp)) {
                setCriticalPath(key, criticalIp, criticalSvc, conn);
            }
        }
    } finally {
        d.cleanUp();
    }
}
Also used : Connection(java.sql.Connection) DBUtils(org.opennms.core.utils.DBUtils) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 23 with DBUtils

use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.

the class AssetModel method getAsset.

/**
     * <p>getAsset</p>
     *
     * @param nodeId a int.
     * @return a {@link org.opennms.web.asset.Asset} object.
     * @throws java.sql.SQLException if any.
     */
public Asset getAsset(int nodeId) throws SQLException {
    Asset asset = null;
    final DBUtils d = new DBUtils(getClass());
    try {
        Connection conn = DataSourceFactory.getInstance().getConnection();
        d.watch(conn);
        PreparedStatement stmt = conn.prepareStatement("SELECT * FROM ASSETS WHERE NODEID=?");
        d.watch(stmt);
        stmt.setInt(1, nodeId);
        ResultSet rs = stmt.executeQuery();
        d.watch(rs);
        Asset[] assets = rs2Assets(rs);
        // XXX what if this returns more than one?
        if (assets.length > 0) {
            asset = assets[0];
        }
    } finally {
        d.cleanUp();
    }
    return asset;
}
Also used : DBUtils(org.opennms.core.utils.DBUtils) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 24 with DBUtils

use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.

the class AssetModel method modifyAsset.

/**
     * <p>modifyAsset</p>
     *
     * @param asset a {@link org.opennms.web.asset.Asset} object.
     * @throws java.sql.SQLException if any.
     */
public void modifyAsset(Asset asset) throws SQLException {
    Assert.notNull(asset, "argument asset cannot be null");
    final DBUtils d = new DBUtils(getClass());
    try {
        Connection conn = DataSourceFactory.getInstance().getConnection();
        d.watch(conn);
        PreparedStatement stmt = conn.prepareStatement("UPDATE ASSETS SET category=?,manufacturer=?,vendor=?,modelNumber=?,serialNumber=?,description=?,circuitId=?,assetNumber=?,operatingSystem=?,rack=?,slot=?,port=?,region=?,division=?,department=?,address1=?,address2=?,city=?,state=?,zip=?,building=?,floor=?,room=?,vendorPhone=?,vendorFax=?,userLastModified=?,lastModifiedDate=?,dateInstalled=?,lease=?,leaseExpires=?,supportPhone=?,maintContract=?,vendorAssetNumber=?,maintContractExpires=?,displayCategory=?,notifyCategory=?,pollerCategory=?,thresholdCategory=?,comment=?, username=?, password=?,enable=?,connection=?,autoenable=?,cpu=?,ram=?,storagectrl=?,hdd1=?,hdd2=?,hdd3=?,hdd4=?,hdd5=?,hdd6=?,numpowersupplies=?,inputpower=?,additionalhardware=?,admin=?,snmpcommunity=?,rackunitheight=?,longitude=?,latitude=?,country=? WHERE nodeid=?");
        d.watch(stmt);
        stmt.setString(1, asset.category);
        stmt.setString(2, asset.manufacturer);
        stmt.setString(3, asset.vendor);
        stmt.setString(4, asset.modelNumber);
        stmt.setString(5, asset.serialNumber);
        stmt.setString(6, asset.description);
        stmt.setString(7, asset.circuitId);
        stmt.setString(8, asset.assetNumber);
        stmt.setString(9, asset.operatingSystem);
        stmt.setString(10, asset.rack);
        stmt.setString(11, asset.slot);
        stmt.setString(12, asset.port);
        stmt.setString(13, asset.region);
        stmt.setString(14, asset.division);
        stmt.setString(15, asset.department);
        stmt.setString(16, asset.address1);
        stmt.setString(17, asset.address2);
        stmt.setString(18, asset.city);
        stmt.setString(19, asset.state);
        stmt.setString(20, asset.zip);
        stmt.setString(21, asset.building);
        stmt.setString(22, asset.floor);
        stmt.setString(23, asset.room);
        stmt.setString(24, asset.vendorPhone);
        stmt.setString(25, asset.vendorFax);
        stmt.setString(26, asset.userLastModified);
        stmt.setTimestamp(27, new Timestamp(asset.lastModifiedDate.getTime()));
        stmt.setString(28, asset.dateInstalled);
        stmt.setString(29, asset.lease);
        stmt.setString(30, asset.leaseExpires);
        stmt.setString(31, asset.supportPhone);
        stmt.setString(32, asset.maintContract);
        stmt.setString(33, asset.vendorAssetNumber);
        stmt.setString(34, asset.maintContractExpires);
        stmt.setString(35, asset.displayCategory);
        stmt.setString(36, asset.notifyCategory);
        stmt.setString(37, asset.pollerCategory);
        stmt.setString(38, asset.thresholdCategory);
        stmt.setString(39, asset.comments);
        stmt.setString(40, asset.username);
        stmt.setString(41, asset.password);
        stmt.setString(42, asset.enable);
        stmt.setString(43, asset.connection);
        stmt.setString(44, asset.autoenable);
        stmt.setString(45, asset.cpu);
        stmt.setString(46, asset.ram);
        stmt.setString(47, asset.storagectrl);
        stmt.setString(48, asset.hdd1);
        stmt.setString(49, asset.hdd2);
        stmt.setString(50, asset.hdd3);
        stmt.setString(51, asset.hdd4);
        stmt.setString(52, asset.hdd5);
        stmt.setString(53, asset.hdd6);
        stmt.setString(54, asset.numpowersupplies);
        stmt.setString(55, asset.inputpower);
        stmt.setString(56, asset.additionalhardware);
        stmt.setString(57, asset.admin);
        stmt.setString(58, asset.snmpcommunity);
        stmt.setString(59, asset.rackunitheight);
        final Float longitude = safeFloat(asset.longitude);
        if (longitude == null) {
            stmt.setNull(60, Types.FLOAT);
        } else {
            stmt.setFloat(60, longitude);
        }
        final Float latitude = safeFloat(asset.latitude);
        if (latitude == null) {
            stmt.setNull(61, Types.FLOAT);
        } else {
            stmt.setFloat(61, latitude);
        }
        stmt.setString(62, asset.country);
        stmt.setInt(63, asset.nodeId);
        stmt.execute();
    } finally {
        d.cleanUp();
    }
}
Also used : DBUtils(org.opennms.core.utils.DBUtils) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 25 with DBUtils

use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.

the class NotificationModel method allNotifications.

/**
     * Return all notifications, both outstanding and acknowledged.
     *
     * @param order a {@link java.lang.String} object.
     * @return an array of {@link org.opennms.web.notification.Notification} objects.
     * @throws java.sql.SQLException if any.
     */
public Notification[] allNotifications(String order) throws SQLException {
    Notification[] notices = null;
    final Connection conn = DataSourceFactory.getInstance().getConnection();
    final DBUtils d = new DBUtils(getClass(), conn);
    try {
        final Statement stmt = conn.createStatement();
        d.watch(stmt);
        // oh man this is lame, but it'll be a DAO soon right?  right?  :P
        String query = SELECT;
        if (order != null) {
            if (order.equalsIgnoreCase("asc")) {
                query += " ORDER BY pagetime ASC";
            } else if (order.equalsIgnoreCase("desc")) {
                query += " ORDER BY pagetime DESC";
            }
        }
        query += ";";
        final ResultSet rs = stmt.executeQuery(query);
        d.watch(rs);
        notices = rs2NotifyBean(conn, rs);
    } catch (SQLException e) {
        LOG.error("allNotifications: Problem getting data from the notifications table: {}", e, e);
        throw e;
    } finally {
        d.cleanUp();
    }
    return (notices);
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) DBUtils(org.opennms.core.utils.DBUtils) ResultSet(java.sql.ResultSet)

Aggregations

DBUtils (org.opennms.core.utils.DBUtils)77 Connection (java.sql.Connection)68 PreparedStatement (java.sql.PreparedStatement)64 ResultSet (java.sql.ResultSet)50 SQLException (java.sql.SQLException)17 ArrayList (java.util.ArrayList)14 Timestamp (java.sql.Timestamp)12 Statement (java.sql.Statement)10 Filter (org.opennms.web.filter.Filter)9 ServletException (javax.servlet.ServletException)5 FilterParseException (org.opennms.netmgt.filter.api.FilterParseException)5 IfIndexFilter (org.opennms.web.event.filter.IfIndexFilter)5 InterfaceFilter (org.opennms.web.event.filter.InterfaceFilter)5 NodeFilter (org.opennms.web.event.filter.NodeFilter)5 ServiceFilter (org.opennms.web.event.filter.ServiceFilter)5 SeverityFilter (org.opennms.web.event.filter.SeverityFilter)5 Date (java.util.Date)4 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)3 InetAddress (java.net.InetAddress)3 RequestDispatcher (javax.servlet.RequestDispatcher)3