List of usage examples for java.sql SQLException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Delete Metric data - maintenance cleanup function * /*from ww w .ja v a 2s. com*/ * @param metricNamespace * @param startDate * @param endDate */ @Override public void deleteMetricData(String metricNamespace, Date startDate, Date endDate) { Connection conn = null; CallableStatement stmt = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); // Delete metric data stmt = conn.prepareCall("uspMetricData_Delete(?,?,?,?)"); stmt.setString(1, metricNamespace); stmt.setNull(2, Types.NULL); if (startDate != null) stmt.setString(3, sdf.format(startDate)); else stmt.setString(3, null); if (endDate != null) stmt.setString(4, sdf.format(endDate)); else stmt.setString(4, null); stmt.execute(); } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * List all the metrics for a namespace/*from ww w . j a v a 2 s . com*/ * * @param metricNamespace * @return ArrayList<HashMap<String, String>> */ @Override public ArrayList<HashMap<String, String>> getMetrics(String metricNamespace) { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; ArrayList<HashMap<String, String>> retData = new ArrayList<HashMap<String, String>>(); try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); stmt = conn.prepareCall("uspMetricData_GetMetrics(?)"); stmt.setString(1, metricNamespace); rs = stmt.executeQuery(); while (rs.next()) { // Create a new container HashMap<String, String> metricNameContainer = new HashMap<String, String>(); metricNameContainer.put("metricnamespace", rs.getString("MetricNamespace")); metricNameContainer.put("metricname", rs.getString("MetricName")); // Add the name retData.add(metricNameContainer); } } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return retData; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Add metric data/* w ww.j a v a 2s . c om*/ * * @param metricNamespace * @param metricName * @param unit * @param value * @data the extra data field */ @Override public void addMetricData(String metricNamespace, String metricName, MetricUnit unit, Double value, String data) { Connection conn = null; CallableStatement stmt = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); // create new metric data stmt = conn.prepareCall("uspMetricData_Insert(?,?,?,?,?)"); stmt.setString(1, metricNamespace); stmt.setString(2, metricName); stmt.setInt(3, unit.getValue()); stmt.setDouble(4, value); stmt.setString(5, data); stmt.execute(); // Create a data item MetricData dataitem = new MetricData(); dataitem.setMetricName(metricName); dataitem.setMetricNamespace(metricNamespace); dataitem.setUnit(unit); dataitem.setValue(value); dataitem.setData(data); // Evaluate for alarms evaluateMetricAlarm(dataitem); } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Update a metric alarm//from w ww. j ava 2 s . c o m * * @param metricAlarmId * @param alarmName * @param alarmDescription * @param comparisonOperator * @param metricNamespace * @param metricName * @param statistic * @param threshold * @param unit * @param stateReason * @param stateReasonData * @param alarmState * @return rowsUpdated */ @Override public Integer updateMetricAlarm(Integer metricAlarmId, String alarmName, String alarmDescription, AlarmComparisonOperator comparisonOperator, String metricNamespace, String metricName, MetricStatistic statistic, Double threshold, MetricUnit unit, String stateReason, String stateReasonData, AlarmState alarmState) { Connection conn = null; CallableStatement stmt = null; Integer rowsUpdated = 0; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); // create new alarm stmt = conn.prepareCall("uspMetricAlarm_Update(?,?,?,?,?,?,?,?,?,?,?,?)"); stmt.setInt(1, metricAlarmId); stmt.setInt(2, comparisonOperator.getValue()); stmt.setInt(3, statistic.getValue()); stmt.setInt(4, unit.getValue()); stmt.setString(5, alarmName); stmt.setString(6, alarmDescription); stmt.setString(7, metricNamespace); stmt.setString(8, metricName); stmt.setDouble(9, threshold); stmt.setString(10, stateReason); stmt.setString(11, stateReasonData); stmt.setInt(12, alarmState.getValue()); rowsUpdated = stmt.executeUpdate(); } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return rowsUpdated; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Add a metric alarm//from w w w. ja va 2 s. c o m * * @param alarmName * @param alarmDescription * @param comparisonOperator * @param metricNamespace * @param metricName * @param satistic * @param threshold * @param unit * @return lastId */ @Override public Integer addMetricAlarm(String alarmName, String alarmDescription, AlarmComparisonOperator comparisonOperator, String metricNamespace, String metricName, MetricStatistic statistic, Double threshold, MetricUnit unit) { Integer lastId = 0; Connection conn = null; CallableStatement stmt = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); // create new alarm stmt = conn.prepareCall("uspMetricAlarm_Insert(?,?,?,?,?,?,?,?,?,?,?,?)"); stmt.setInt(1, comparisonOperator.getValue()); stmt.setInt(2, statistic.getValue()); stmt.setInt(3, unit.getValue()); stmt.setString(4, alarmName); stmt.setString(5, alarmDescription); stmt.setString(6, metricNamespace); stmt.setString(7, metricName); stmt.setDouble(8, threshold); stmt.setString(9, null); stmt.setString(10, null); stmt.setInt(11, AlarmState.OK.getValue()); stmt.registerOutParameter(12, Types.INTEGER); stmt.execute(); lastId = stmt.getInt(12); } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return lastId; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Get metric data object by id//from www.j av a2s . com * * @param metricDataId * @return MetricData */ @Override public MetricData getMetricData(Integer metricDataId) { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); MetricData dataitem = null; MetricUnit metricUnit = MetricUnit.None; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); stmt = conn.prepareCall("dbo.uspMetricData_Get(?)"); stmt.setInt(1, metricDataId); rs = stmt.executeQuery(); while (rs.next()) { dataitem = new MetricData(); dataitem.setMetricId(rs.getInt("MetricDataId")); dataitem.setUnit(metricUnit.findByValue(rs.getInt("MetricUnitId"))); dataitem.setMetricNamespace(rs.getString("MetricNamespace")); dataitem.setMetricName(rs.getString("MetricName")); dataitem.setValue(rs.getDouble("Value")); dataitem.setData(rs.getString("Data")); dataitem.setTimestamp(sdf.parse(rs.getString("DateCreated"))); } } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ParseException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return dataitem; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Get list of MetricSLAExclusionTime(s) by MetricSlaId * //from w w w .j a va 2s . co m * @param metricSlaId * @return ArrayList<MetricSLAExclusionTime> */ @Override public ArrayList<MetricSLAExclusionTime> getMetricSlaExclusionTime(Integer metricSlaId) { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; // create a container for the data ArrayList<MetricSLAExclusionTime> metricSLAExclusionTimeList = new ArrayList<MetricSLAExclusionTime>(); try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); stmt = conn.prepareCall("uspMetricSlaExclusionTime_GetBySlaId(?)"); stmt.setInt(1, metricSlaId); rs = stmt.executeQuery(); while (rs.next()) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DayOfWeek dayOfWeek = DayOfWeek.Monday; MetricSLA metricSla = new MetricSLA(); metricSla = getMetricSla(rs.getInt("MetricSlaId"), null); MetricSLAExclusionTime dataitem = new MetricSLAExclusionTime(); dataitem.setMetricSLAExclusionTimeId(rs.getInt("MetricSLAExclusionTimeId")); dataitem.setMetricSla(metricSla); dataitem.setDayOfWeek(dayOfWeek.findByValue(rs.getInt("DayOfWeekId"))); dataitem.setStartTime(rs.getString("StartTime")); dataitem.setEndTime(rs.getString("EndTime")); dataitem.setTimestamp(sdf.parse(rs.getString("DateCreated"))); metricSLAExclusionTimeList.add(dataitem); } } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ParseException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return metricSLAExclusionTimeList; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * List all metric sla's or by metric alarmid * // ww w .j a v a 2s. com * @param metricAlarmId * * @return ArrayList<MetricSLA> */ @Override public ArrayList<MetricSLA> getMetricSlas(Integer metricAlarmId) { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; // create a container for the data ArrayList<MetricSLA> metricSlaList = new ArrayList<MetricSLA>(); try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); stmt = conn.prepareCall("uspMetricSla_GetByMetricAlarmId(?)"); if (metricAlarmId == null) stmt.setNull(1, Types.NULL); else stmt.setInt(1, metricAlarmId); rs = stmt.executeQuery(); while (rs.next()) { AlarmMetricAlarm alarmMetricAlarm = new AlarmMetricAlarm(); alarmMetricAlarm = getMetricAlarm(rs.getInt("MetricAlarmId"), null); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); MetricSLA dataitem = new MetricSLA(); dataitem.setMetricSLAId(rs.getInt("MetricSlaId")); dataitem.setAlarmMetricAlarm(alarmMetricAlarm); dataitem.setSLAName(rs.getString("Name")); dataitem.setSLADescription(rs.getString("Description")); dataitem.setPercentage(rs.getDouble("Percentage")); dataitem.setDateModified(sdf.parse(rs.getString("DateModified"))); dataitem.setDateCreated(sdf.parse(rs.getString("DateCreated"))); metricSlaList.add(dataitem); } } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ParseException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return metricSlaList; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Get metric sla by MetricSlaId/Sla Name * // ww w .j a v a 2s . c o m * @param metricSlaId * @param slaName * @return MetricSLA */ @Override public MetricSLA getMetricSla(Integer metricSlaId, String slaName) { Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; // create a container for the data MetricSLA dataitem = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); stmt = conn.prepareCall("uspMetricSla_Get(?,?)"); if (metricSlaId == null) stmt.setNull(1, Types.NULL); else stmt.setInt(1, metricSlaId); if (slaName == null) stmt.setNull(2, Types.NULL); else stmt.setString(2, slaName); rs = stmt.executeQuery(); while (rs.next()) { AlarmMetricAlarm alarmMetricAlarm = new AlarmMetricAlarm(); alarmMetricAlarm = getMetricAlarm(rs.getInt("MetricAlarmId"), null); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dataitem = new MetricSLA(); dataitem.setMetricSLAId(rs.getInt("MetricSlaId")); dataitem.setAlarmMetricAlarm(alarmMetricAlarm); dataitem.setSLAName(rs.getString("Name")); dataitem.setSLADescription(rs.getString("Description")); dataitem.setPercentage(rs.getDouble("Percentage")); dataitem.setDateModified(sdf.parse(rs.getString("DateModified"))); dataitem.setDateCreated(sdf.parse(rs.getString("DateCreated"))); } } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ParseException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return dataitem; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Get the history for a MetricAlarm by an alarm name and dates * // w ww .j ava 2s. co m * @param alarmName * @param startDate * @param endDate */ @Override public ArrayList<AlarmHistoryItem> getMetricAlarmHistory(String alarmName, Date startDate, Date endDate) { ArrayList<AlarmHistoryItem> alarmHistoryItems = new ArrayList<AlarmHistoryItem>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); stmt = conn.prepareCall("uspMetricAlarmHistoryItem_GetByAlarmName(?,?,?)"); stmt.setString(1, alarmName); if (startDate != null) stmt.setString(2, sdf.format(startDate)); else stmt.setString(2, null); if (endDate != null) stmt.setString(3, sdf.format(endDate)); else stmt.setString(3, null); rs = stmt.executeQuery(); while (rs.next()) { AlarmState alarmState = AlarmState.NONE; AlarmMetricAlarm alarmMetricAlarm = new AlarmMetricAlarm(); alarmMetricAlarm = getMetricAlarm(rs.getInt("MetricAlarmId"), null); AlarmHistoryItem alarmHistoryItem = new AlarmHistoryItem(); alarmHistoryItem.setAlarmHistoryItemId(rs.getInt("MetricAlarmHistoryItemId")); alarmHistoryItem.setAlarmMetricAlarm(alarmMetricAlarm); alarmHistoryItem.setStateReason(rs.getString("StateReason")); alarmHistoryItem.setStateReasonData(rs.getString("StateReasonData")); alarmHistoryItem.setAlarmState(alarmState.findByValue(rs.getInt("AlarmStateId"))); alarmHistoryItem.setTimestamp(sdf.parse(rs.getString("DateCreated"))); alarmHistoryItems.add(alarmHistoryItem); } } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ParseException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return alarmHistoryItems; }