use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getCheckpoints.
public List<Checkpoint> getCheckpoints(String testcaseId, String checkpointName) throws DatabaseAccessException {
List<Checkpoint> checkpoints = new ArrayList<Checkpoint>();
String sqlLog = new SqlRequestFormatter().add("testcase id", testcaseId).add("checkpoint name", checkpointName).format();
Connection connection = getConnection();
PreparedStatement statement = null;
ResultSet rs = null;
try {
statement = connection.prepareStatement("SELECT ch.checkpointId, ch.responseTime, ch.transferRate, ch.transferRateUnit, ch.result," + " DATEDIFF(second, CONVERT( datetime, '1970-01-01 00:00:00', 20), ch.endTime) as endTime " + "FROM tCheckpoints ch" + " INNER JOIN tCheckpointsSummary chs on (chs.checkpointSummaryId = ch.checkpointSummaryId)" + " INNER JOIN tLoadQueues c on (c.loadQueueId = chs.loadQueueId)" + " INNER JOIN tTestcases tt on (tt.testcaseId = c.testcaseId) " + "WHERE tt.testcaseId = ? AND ch.name = ?");
statement.setString(1, testcaseId);
statement.setString(2, checkpointName);
rs = statement.executeQuery();
while (rs.next()) {
Checkpoint checkpoint = new Checkpoint();
checkpoint.checkpointId = rs.getInt("checkpointId");
checkpoint.name = checkpointName;
checkpoint.responseTime = rs.getInt("responseTime");
checkpoint.transferRate = rs.getFloat("transferRate");
checkpoint.transferRateUnit = rs.getString("transferRateUnit");
checkpoint.result = rs.getInt("result");
checkpoint.endTime = rs.getLong("endTime");
checkpoints.add(checkpoint);
}
logQuerySuccess(sqlLog, "checkpoints", checkpoints.size());
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, statement);
}
return checkpoints;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getTestcasesCount.
public int getTestcasesCount(String whereClause) throws DatabaseAccessException {
String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_testcases_count(?) }");
callableStatement.setString(1, whereClause);
rs = callableStatement.executeQuery();
int testcasesCount = 0;
while (rs.next()) {
testcasesCount = rs.getInt("testcasesCount");
logQuerySuccess(sqlLog, "test cases", testcasesCount);
break;
}
return testcasesCount;
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getRuns.
@BackwardCompatibility
public List<Run> getRuns(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending) throws DatabaseAccessException {
List<Run> runs = new ArrayList<Run>();
Connection connection = getConnection();
String sqlLog = new SqlRequestFormatter().add("start record", startRecord).add("records", recordsCount).add("where", whereClause).add("sort by", sortColumn).add("asc", ascending).format();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_runs(?, ?, ?, ?, ?) }");
callableStatement.setString(1, String.valueOf(startRecord));
callableStatement.setString(2, String.valueOf(recordsCount));
callableStatement.setString(3, whereClause);
callableStatement.setString(4, sortColumn);
callableStatement.setString(5, (ascending ? "ASC" : "DESC"));
int numberRecords = 0;
rs = callableStatement.executeQuery();
while (rs.next()) {
Run run = new Run();
run.runId = rs.getString("runId");
run.productName = rs.getString("productName");
run.versionName = rs.getString("versionName");
run.buildName = rs.getString("buildName");
run.runName = rs.getString("runName");
run.os = rs.getString("OS");
run.hostName = "";
try {
@BackwardCompatibility int // run.hostName introduced in 3.10.0 (internalVersion = 1)
dbInternalVersion = getDatabaseInternalVersion();
if (dbInternalVersion >= 1) {
run.hostName = rs.getString("hostName");
}
} catch (NumberFormatException nfe) {
run.hostName = "";
log.warn("Error parsing dbInternalVersion. ", nfe);
}
Timestamp dateStartTimestamp = rs.getTimestamp("dateStart");
run.dateStart = formatDateNoYear(dateStartTimestamp);
run.dateStartLong = formatDate(dateStartTimestamp);
Timestamp dateEndTimestamp = rs.getTimestamp("dateEnd");
run.dateEnd = formatDateNoYear(dateEndTimestamp);
run.dateEndLong = formatDate(dateEndTimestamp);
int duration = rs.getInt("duration");
if (duration < 0) {
// this may happen when the run is not ended and the time of the log server
// is behind with the time of the test executor host
duration = 0;
}
run.durationSeconds = duration;
run.duration = formatTimeDiffereceFromSecondsToString(duration);
run.scenariosTotal = rs.getInt("scenariosTotal");
run.scenariosFailed = rs.getInt("scenariosFailed");
run.scenariosSkipped = rs.getInt("scenariosSkipped");
run.testcasesTotal = rs.getInt("testcasesTotal");
run.testcasesFailed = rs.getInt("testcasesFailed");
run.testcasesPassedPercent = String.valueOf(rs.getInt("testcasesPassedPercent")) + "%";
run.testcaseIsRunning = rs.getBoolean("testcaseIsRunning");
run.total = run.scenariosTotal + "/" + run.testcasesTotal;
run.failed = run.scenariosFailed + "/" + run.testcasesFailed;
run.userNote = rs.getString("userNote");
if (run.userNote == null) {
run.userNote = "";
}
runs.add(run);
numberRecords++;
}
logQuerySuccess(sqlLog, "runs", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return runs;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getScenarios.
public List<Scenario> getScenarios(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending, boolean dateFormatNoYear) throws DatabaseAccessException {
List<Scenario> scenarios = new ArrayList<Scenario>();
String sqlLog = new SqlRequestFormatter().add("start record", startRecord).add("records", recordsCount).add("where", whereClause).add("sort by", sortColumn).add("asc", ascending).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_scenarios(?, ?, ?, ?, ?) }");
callableStatement.setString(1, String.valueOf(startRecord));
callableStatement.setString(2, String.valueOf(recordsCount));
callableStatement.setString(3, whereClause);
callableStatement.setString(4, sortColumn);
callableStatement.setString(5, (ascending ? "ASC" : "DESC"));
int numberRecords = 0;
rs = callableStatement.executeQuery();
while (rs.next()) {
Scenario scenario = new Scenario();
scenario.scenarioId = rs.getString("scenarioId");
scenario.suiteId = rs.getString("suiteId");
scenario.name = rs.getString("name");
scenario.description = rs.getString("description");
scenario.testcasesTotal = rs.getInt("testcasesTotal");
scenario.testcasesFailed = rs.getInt("testcasesFailed");
scenario.testcasesPassedPercent = String.valueOf(rs.getInt("testcasesPassedPercent")) + "%";
scenario.testcaseIsRunning = rs.getBoolean("testcaseIsRunning");
if (dateFormatNoYear) {
scenario.dateStart = formatDateNoYear(rs.getTimestamp("dateStart"));
scenario.dateEnd = formatDateNoYear(rs.getTimestamp("dateEnd"));
} else {
scenario.dateStart = formatDate(rs.getTimestamp("dateStart"));
scenario.dateEnd = formatDate(rs.getTimestamp("dateEnd"));
}
int duration = rs.getInt("duration");
if (duration < 0) {
// this may happen when the scenario is not ended and the time of the log server
// is behind with the time of the test executor host
duration = 0;
}
scenario.duration = formatTimeDiffereceFromSecondsToString(duration);
scenario.result = rs.getInt("result");
/*
* -- 0 FAILED
* -- 1 PASSED
* -- 2 SKIPPED
* -- 4 RUNNING
*/
switch(scenario.result) {
case 0:
scenario.state = "FAILED";
break;
case 1:
scenario.state = "PASSED";
break;
case 2:
scenario.state = "SKIPPED";
break;
case 4:
scenario.state = "RUNNING";
break;
default:
//TODO: add warning
scenario.state = "unknown";
}
scenario.userNote = rs.getString("userNote");
scenarios.add(scenario);
numberRecords++;
}
logQuerySuccess(sqlLog, "scenarios", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return scenarios;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getRunMessages.
public List<Message> getRunMessages(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending) throws DatabaseAccessException {
List<Message> runMessages = new ArrayList<Message>();
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd");
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss:S");
String sqlLog = new SqlRequestFormatter().add("start record", startRecord).add("records", recordsCount).add("where", whereClause).add("sort by", sortColumn).add("asc", ascending).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_run_messages(?, ?, ?, ?, ?) }");
callableStatement.setString(1, String.valueOf(startRecord));
callableStatement.setString(2, String.valueOf(recordsCount));
callableStatement.setString(3, whereClause);
callableStatement.setString(4, sortColumn);
callableStatement.setString(5, (ascending ? "ASC" : "DESC"));
int numberRecords = 0;
rs = callableStatement.executeQuery();
while (rs.next()) {
Message runMessage = new Message();
runMessage.messageId = rs.getInt("runMessageId");
runMessage.messageContent = rs.getString("message");
runMessage.messageType = rs.getString("typeName");
Timestamp timestamp = rs.getTimestamp("timestamp");
runMessage.date = dateFormat.format(timestamp);
runMessage.time = timeFormat.format(timestamp);
runMessage.machineName = rs.getString("machineName");
runMessage.threadName = rs.getString("threadName");
runMessages.add(runMessage);
numberRecords++;
}
logQuerySuccess(sqlLog, "run messages", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return runMessages;
}
Aggregations