assetmodel.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 357 行 · 第 1/2 页

JAVA
357
字号
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Modifications:// // 2006 Aug 08: Bug #1547: Fix for FROM clause missing entry for node table. - dj@opennms.org// 2004 Jan 06: Added support for Display, Notify, Poller, and Threshold categories// 2003 Feb 05: Added ORDER BY to SQL statement.//// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// For more information contact://      OpenNMS Licensing       <license@opennms.org>//      http://www.opennms.org///      http://www.opennms.com///package org.opennms.web.asset;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.Timestamp;import java.util.Vector;import org.opennms.core.resource.Vault;public class AssetModel extends Object {    public Asset getAsset(int nodeId) throws SQLException {        Asset asset = null;        Connection conn = Vault.getDbConnection();        try {            Statement stmt = conn.createStatement();            ResultSet rs = stmt.executeQuery("SELECT * FROM ASSETS WHERE NODEID=" + nodeId);            Asset[] assets = rs2Assets(rs);            // what if this returns more than one?            if (assets.length > 0) {                asset = assets[0];            }            rs.close();            stmt.close();        } finally {            Vault.releaseDbConnection(conn);        }        return (asset);    }    public Asset[] getAllAssets() throws SQLException {        Asset[] assets = new Asset[0];        Connection conn = Vault.getDbConnection();        try {            Statement stmt = conn.createStatement();            ResultSet rs = stmt.executeQuery("SELECT * FROM ASSETS");            assets = rs2Assets(rs);            rs.close();            stmt.close();        } finally {            Vault.releaseDbConnection(conn);        }        return (assets);    }    public void createAsset(Asset asset) throws SQLException {        if (asset == null) {            throw new IllegalArgumentException("Cannot take null parameters.");        }        Connection conn = Vault.getDbConnection();        try {            PreparedStatement stmt = conn.prepareStatement("INSERT INTO ASSETS (nodeID,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) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");            stmt.setInt(1, asset.nodeId);            stmt.setString(2, asset.category);            stmt.setString(3, asset.manufacturer);            stmt.setString(4, asset.vendor);            stmt.setString(5, asset.modelNumber);            stmt.setString(6, asset.serialNumber);            stmt.setString(7, asset.description);            stmt.setString(8, asset.circuitId);            stmt.setString(9, asset.assetNumber);            stmt.setString(10, asset.operatingSystem);            stmt.setString(11, asset.rack);            stmt.setString(12, asset.slot);            stmt.setString(13, asset.port);            stmt.setString(14, asset.region);            stmt.setString(15, asset.division);            stmt.setString(16, asset.department);            stmt.setString(17, asset.address1);            stmt.setString(18, asset.address2);            stmt.setString(19, asset.city);            stmt.setString(20, asset.state);            stmt.setString(21, asset.zip);            stmt.setString(22, asset.building);            stmt.setString(23, asset.floor);            stmt.setString(24, asset.room);            stmt.setString(25, asset.vendorPhone);            stmt.setString(26, asset.vendorFax);            stmt.setString(27, asset.userLastModified);            stmt.setTimestamp(28, new Timestamp(asset.lastModifiedDate.getTime()));            stmt.setString(29, asset.dateInstalled);            stmt.setString(30, asset.lease);            stmt.setString(31, asset.leaseExpires);            stmt.setString(32, asset.supportPhone);            stmt.setString(33, asset.maintContract);            stmt.setString(34, asset.vendorAssetNumber);            stmt.setString(35, asset.maintContractExpires);            stmt.setString(36, asset.displayCategory);            stmt.setString(37, asset.notifyCategory);            stmt.setString(38, asset.pollerCategory);            stmt.setString(39, asset.thresholdCategory);            stmt.setString(40, asset.comments);            stmt.execute();            stmt.close();        } finally {            Vault.releaseDbConnection(conn);        }    }    public void modifyAsset(Asset asset) throws SQLException {        if (asset == null) {            throw new IllegalArgumentException("Cannot take null parameters.");        }        Connection conn = Vault.getDbConnection();        try {            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=? WHERE nodeid=?");            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);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?