public DBUtils(Class<?> loggingClass, Object... targets) { this(loggingClass); for (final Object o : targets) { watch(o); } } /**
private void doRegister(ResultSet rs) { m_dbUtils.watch(rs); m_resultSets.add(rs); }
private void doRegister(Statement stmt) { m_dbUtils.watch(stmt); m_statements.add(stmt); }
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); }
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 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(); } }
/** {@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(); } }
Connection conn = getDbConnection(); final DBUtils db = new DBUtils(getClass()); db.watch(conn); try { Statement st = conn.createStatement(); db.watch(st); String query = "SELECT n.nodeid, n.foreignsource, n.foreignid, i.snmpifdescr, i.snmpifname, i.snmpphysaddr from node n, snmpinterface i where n.nodeid = i.nodeid and i.snmpphysaddr is not null order by n.nodeid, i.snmpifdescr"; ResultSet rs = st.executeQuery(query); db.watch(rs); while (rs.next()) { interfacesToMerge.add(new SnmpInterface(rs, isStoreByForeignSourceEnabled()));
Connection conn = getDbConnection(); final DBUtils db = new DBUtils(getClass()); db.watch(conn); try { Statement st = conn.createStatement(); db.watch(st); String query = "SELECT n.nodeid, n.foreignsource, n.foreignid, i.snmpifdescr, i.snmpifname, i.snmpphysaddr from node n, snmpinterface i where n.nodeid = i.nodeid and i.snmpphysaddr is not null order by n.nodeid, i.snmpifdescr"; ResultSet rs = st.executeQuery(query); db.watch(rs); int count = 0; while (rs.next()) {
try { final Connection connection = DataSourceFactory.getInstance().getConnection(); db.watch(connection); JasperFillManager.fillReportToFile(jasperReport, outputFileName, reportParms, connection); } finally {
try { Connection connection = getConnection(); dbUtils.watch(connection); PreparedStatement statement = connection.prepareStatement("SELECT e.eventId FROM events e, alarms a WHERE e.alarmid = a.alarmid AND a.reductionkey= ?"); dbUtils.watch(statement); String resolvingKey = event.getAlarmData().getClearKey() == null ? event.getAlarmData().getReductionKey() : event.getAlarmData().getClearKey(); statement.setString(1, resolvingKey); ResultSet results = statement.executeQuery(); dbUtils.watch(results); while (results.next()) { int eventID = results.getInt(1);
try { final Connection connection = DataSourceFactory.getInstance().getConnection(); db.watch(connection); JasperFillManager.fillReportToFile(jasperReport, outputFileName, reportParms, connection); } finally {
@Override public Void call() throws Exception { final JasperReport jasperReport = getJasperReport(reportId); final Map<String, Object> jrReportParms = buildJRparameters(reportParms, jasperReport.getParameters()); jrReportParms.putAll(buildSubreport(reportId, jasperReport)); if ("jdbc".equalsIgnoreCase(m_globalReportRepository.getEngine(reportId))) { final DBUtils db = new DBUtils(); try { final Connection connection = DataSourceFactory.getInstance().getConnection(); db.watch(connection); final JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jrReportParms, connection); exportReport(format, jasperPrint, outputStream); } finally { db.cleanUp(); } } else if ("null".equalsIgnoreCase(m_globalReportRepository.getEngine(reportId))) { final JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jrReportParms, new JREmptyDataSource()); exportReport(format, jasperPrint, outputStream); } return null; } });
@Override public Void call() throws Exception { final JasperReport jasperReport = getJasperReport(reportId); final Map<String, Object> jrReportParms = buildJRparameters(reportParms, jasperReport.getParameters()); jrReportParms.putAll(buildSubreport(reportId, jasperReport)); if ("jdbc".equalsIgnoreCase(m_globalReportRepository.getEngine(reportId))) { final DBUtils db = new DBUtils(); try { final Connection connection = DataSourceFactory.getInstance().getConnection(); db.watch(connection); final JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jrReportParms, connection); exportReport(format, jasperPrint, outputStream); } finally { db.cleanUp(); } } else if ("null".equalsIgnoreCase(m_globalReportRepository.getEngine(reportId))) { final JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jrReportParms, new JREmptyDataSource()); exportReport(format, jasperPrint, outputStream); } return null; } });