use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method insertCheckpointSummary.
public void insertCheckpointSummary(String name, int numRunning, int numPassed, int numFailed, int minResponseTime, float avgResponseTime, int maxResponseTime, float minTransferRate, float avgTransferRate, float maxTransferRate, String transferRateUnit, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to insert checkpoint summary '" + name + "' for load queue " + loadQueueId;
PreparedStatement perparedStatement = null;
try {
refreshInternalConnection();
perparedStatement = connection.prepareStatement("INSERT INTO tCheckpointsSummary" + " (name,numRunning,numPassed,numFailed,minResponseTime,avgResponseTime,maxResponseTime,minTransferRate,avgTransferRate,maxTransferRate,transferRateUnit,loadQueueId) " + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
perparedStatement.setString(1, name);
perparedStatement.setInt(2, numRunning);
perparedStatement.setInt(3, numPassed);
perparedStatement.setInt(4, numFailed);
perparedStatement.setInt(5, minResponseTime);
perparedStatement.setFloat(6, avgResponseTime);
perparedStatement.setInt(7, maxResponseTime);
perparedStatement.setFloat(8, minTransferRate);
perparedStatement.setFloat(9, avgTransferRate);
perparedStatement.setFloat(10, maxTransferRate);
perparedStatement.setString(11, transferRateUnit);
perparedStatement.setInt(12, loadQueueId);
int updatedRecords = perparedStatement.executeUpdate();
if (updatedRecords != 1) {
throw new DatabaseAccessException(errMsg);
}
} catch (SQLException e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, perparedStatement);
} else {
DbUtils.closeStatement(perparedStatement);
}
}
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method endRun.
/**
* End a run in the database
*
* @param timestamp
* @param runId
*/
public void endRun(long timestamp, int runId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to end run with id " + runId;
final int indexRowsInserted = 3;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_end_run(?, ?, ?) }");
callableStatement.setInt(1, runId);
callableStatement.setTimestamp(2, new Timestamp(timestamp));
callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
callableStatement.execute();
if (callableStatement.getInt(indexRowsInserted) != 1) {
throw new DatabaseAccessException(errMsg);
}
} catch (Exception e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, callableStatement);
} else {
DbUtils.closeStatement(callableStatement);
}
}
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method populateSystemStatisticDefinition.
public int populateSystemStatisticDefinition(String name, String parentName, String internalName, String unit, String params) throws DatabaseAccessException {
if (parentName == null) {
parentName = "";
}
if (internalName == null) {
internalName = "";
}
CallableStatement callableStatement = null;
Connection con = null;
boolean useLocalConnection = false;
try {
if (connection == null || connection.isClosed()) {
// connection not set externally so use new connection only for this method invocation
useLocalConnection = true;
con = getConnection();
} else {
useLocalConnection = false;
con = connection;
}
final int statisticId = 6;
callableStatement = con.prepareCall("{ call sp_populate_system_statistic_definition(?, ?, ?, ?, ?, ?) }");
callableStatement.setString(1, parentName);
callableStatement.setString(2, internalName);
callableStatement.setString(3, name);
callableStatement.setString(4, unit);
callableStatement.setString(5, params);
callableStatement.registerOutParameter(statisticId, Types.INTEGER);
callableStatement.execute();
return callableStatement.getInt(statisticId);
} catch (Exception e) {
String errMsg = "Unable to populate statistic '" + name + "' with unit '" + unit + "' and params '" + params + "'";
throw new DatabaseAccessException(errMsg, e);
} finally {
DbUtils.closeStatement(callableStatement);
if (useLocalConnection) {
DbUtils.closeConnection(con);
}
}
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method addScenarioMetainfo.
/**
* Update meta info about an existing test scenario.
* This data is expected to come from java method annotations
*
* @param testcaseId
* @param metaKey
* @param metaValue
* @param closeConnection
* @throws DatabaseAccessException
*/
public void addScenarioMetainfo(int testcaseId, String metaKey, String metaValue, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to add scenario meta info '" + metaKey + "=" + metaValue + "' to scenario for testcase with id " + testcaseId;
final int indexRowsInserted = 4;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_add_scenario_metainfo(?, ?, ?, ?) }");
callableStatement.setInt(1, testcaseId);
callableStatement.setString(2, metaKey);
callableStatement.setString(3, metaValue);
callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
callableStatement.execute();
if (callableStatement.getInt(indexRowsInserted) != 1) {
throw new DatabaseAccessException(errMsg);
}
} catch (Exception e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, callableStatement);
} else {
DbUtils.closeStatement(callableStatement);
}
}
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method deleteTestcase.
public void deleteTestcase(List<Object> objectsToDelete) throws DatabaseAccessException {
StringBuilder testcaseIds = new StringBuilder();
for (Object obj : objectsToDelete) {
testcaseIds.append(((Testcase) obj).testcaseId);
testcaseIds.append(",");
}
testcaseIds.delete(testcaseIds.length() - 1, testcaseIds.length());
final String errMsg = "Unable to delete testcase(s) with id " + testcaseIds;
Connection connection = getConnection();
CallableStatement callableStatement = null;
try {
callableStatement = connection.prepareCall("{ call sp_delete_testcase(?) }");
callableStatement.setString(1, testcaseIds.toString());
callableStatement.execute();
} catch (SQLException e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
DbUtils.close(connection, callableStatement);
}
}
Aggregations