private void doExecute(final Object[] values) throws SQLException { final DBUtils d = new DBUtils(getClass()); try { final Connection conn = m_db.getConnection(); d.watch(conn); final PreparedStatement stmt = conn.prepareStatement(m_sql); d.watch(stmt); for(int i = 0; i < values.length; i++) { stmt.setObject(i+1, values[i]); } executeStmt(stmt); } finally { d.cleanUp(); } }
/** * This method determines what label should be associated with a particular * node. A database connection is retrieved from the Vault. * * WARNING: A properly instantiated and initialized Vault class object is * required prior to calling this method. This method will initially only be * called from the WEB UI. * * @param nodeID * Unique identifier of the node to be updated. * @return NodeLabel Object containing label and source values * @throws java.sql.SQLException if any. * * @deprecated Update this to use modern DAO methods instead of raw SQL */ public NodeLabel computeLabel(final int nodeID) throws SQLException { final Connection dbConnection = DataSourceFactory.getInstance().getConnection(); final DBUtils d = new DBUtils(NodeLabelJDBCImpl.class, dbConnection); try { return computeLabel(nodeID, dbConnection); } finally { d.cleanUp(); } }
public DBUtils(Class<?> loggingClass, Object... targets) { this(loggingClass); for (final Object o : targets) { watch(o); } } /**
DBUtils mysql_obj = new DBUtils(); mysql_obj.setServer_name(server_name); mysql_obj.setDatabase(database); mysql_obj.setUsername(username); mysql_obj.setPassword(password); return mysql_obj;
private void doClose() throws SQLException { m_dbUtils.cleanUp(); }
/** * This method updates the 'nodelabel' and 'nodelabelsource' fields of the * 'node' table for the specified nodeID. A database connection is retrieved * from the Vault. * * WARNING: A properly instantiated and initialized Vault class object is * required prior to calling this method. This method will initially only be * called from the WEB UI. * * @param nodeID * Unique identifier of the node to be updated. * @param nodeLabel * Object containing label and source values. * @throws java.sql.SQLException if any. * * @deprecated Use a {@link NodeDao#update(org.opennms.netmgt.model.OnmsNode)} method call instead */ @Override public void assignLabel(final int nodeID, final NodeLabel nodeLabel) throws SQLException { final Connection dbConnection = DataSourceFactory.getInstance().getConnection(); final DBUtils d = new DBUtils(NodeLabelJDBCImpl.class, dbConnection); try { assignLabel(nodeID, nodeLabel, dbConnection); } finally { d.cleanUp(); } }
private void doRegister(ResultSet rs) { m_dbUtils.watch(rs); m_resultSets.add(rs); }
/** * <p>finalize</p> * @throws Throwable */ @Override protected void finalize() throws Throwable { m_dbUtils.cleanUp(); super.finalize(); }
/** {@inheritDoc} */ @Override protected void executeStmt(PreparedStatement stmt) throws SQLException { final DBUtils d = new DBUtils(getClass()); try { ResultSet rs = stmt.executeQuery(); d.watch(rs); m_count = 0; while (rs.next()) { m_rowProcessor.processRow(rs); m_count++; } } finally { d.cleanUp(); } }
/** * This method queries the 'node' table for the value of the 'nodelabel' and * 'nodelabelsource' fields for the node with the provided nodeID. A * NodeLabel object is returned initialized with the retrieved values. * * WARNING: A properly instantiated and initialized Vault class object is * required prior to calling this method. This method will initially only be * called from the WEB UI. * * @param nodeID * Unique identifier of the node to be updated. * @return Object containing label and source values. * @throws java.sql.SQLException if any. * * @deprecated Use a {@link NodeDao#load(Integer)} method call instead */ @Override public NodeLabel retrieveLabel(final int nodeID) throws SQLException { final Connection dbConnection = DataSourceFactory.getInstance().getConnection(); final DBUtils d = new DBUtils(NodeLabelJDBCImpl.class, dbConnection); try { return retrieveLabel(nodeID, dbConnection); } finally { d.cleanUp(); } }
private void doRegister(Statement stmt) { m_dbUtils.watch(stmt); m_statements.add(stmt); }
/** * This method queries the database in search of a service id for a given service name * * @param service * the name of the service * @return the serviceID of the service */ private int getServiceId(final String service) throws SQLException { int serviceID = 0; Connection connection = null; final DBUtils d = new DBUtils(getClass()); try { connection = getConnection(); d.watch(connection); final PreparedStatement statement = connection.prepareStatement("SELECT serviceID from service where serviceName = ?"); d.watch(statement); statement.setString(1, service); final ResultSet results = statement.executeQuery(); d.watch(results); if (!results.next()) { throw new SQLException("No serviceID found for service with serviceName: " + service); } serviceID = results.getInt(1); return serviceID; } finally { d.cleanUp(); } }
private Connection doGetConnection(String dsName) throws SQLException { if (!m_connections.containsKey(dsName)) { DataSource ds = DataSourceFactory.getInstance(dsName); if (ds == null) { throw new IllegalArgumentException("Could not find this datasource by using the DataSourceFactory: " + dsName); } Connection conn = ds.getConnection(); m_dbUtils.watch(conn); m_connections.put(dsName, conn); conn.setAutoCommit(false); } return m_connections.get(dsName); }
final DBUtils d = new DBUtils(getClass()); d.watch(conn); PreparedStatement stmt = conn.prepareStatement(ALL_IP_ADDRS_SQL); d.watch(stmt); ResultSet rs = stmt.executeQuery(); d.watch(rs); if (rs != null) { while (rs.next()) { LOG.warn("Caught SQLException while trying to query for all IP addresses: {}", sqle.getMessage()); } finally { d.cleanUp();
LOG.debug("updating usersnotified: ID = {} User = {}, notice ID = {}, contactinfo = {}, media = {}, autoNotify = {}", autoNotify, userNotifId, userId, noticeId, contactInfo, media); Connection connection = null; final DBUtils d = new DBUtils(getClass()); try { connection = getConnection(); d.watch(connection); final PreparedStatement insert = connection.prepareStatement("INSERT INTO usersNotified (id, userid, notifyid, notifytime, media, contactinfo, autonotify) values (?,?,?,?,?,?,?)"); d.watch(insert); d.cleanUp();
final DBUtils d = new DBUtils(CategoryModel.class); try { Connection conn = DataSourceFactory.getInstance().getConnection(); d.watch(conn); d.watch(stmt); d.watch(rs); LOG.warn("Failed to get service availability for nodeId {}, interface {}, serviceId {}", nodeId, ipAddr, serviceId, e); } finally { d.cleanUp();