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();
}
}
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();
}
}
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;
}
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();
}
}
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);
}
Aggregations