use of com.axway.ats.core.utils.BackwardCompatibility in project ats-framework by Axway.
the class AbstractDbAccess method getDatabaseInternalVersion.
@BackwardCompatibility
public int getDatabaseInternalVersion() throws NumberFormatException {
if (dbInternalVersion == -1) {
// not yet tried to be extracted from DB
Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
connection = getConnection();
statement = connection.prepareStatement("SELECT value from tInternal where [key] = 'internalVersion'");
rs = statement.executeQuery();
// we expect only one record
if (rs.next()) {
String value = rs.getString(1);
if (StringUtils.isNullOrEmpty(value)) {
dbInternalVersion = 0;
} else {
dbInternalVersion = Integer.parseInt(value.trim());
}
} else {
dbInternalVersion = 0;
}
if (dbInternalVersion == 0) {
//Seems to be pre 3.10.0 version
log.debug("DB internalVersion not found.");
}
} catch (NumberFormatException nfe) {
throw new NumberFormatException("Error parsing DB internalVersion");
} catch (Exception e) {
log.debug("Error fetching DB internalVersion", e);
dbInternalVersion = 0;
} finally {
DbUtils.close(connection, statement);
DbUtils.closeResultSet(rs);
}
}
return dbInternalVersion;
}
use of com.axway.ats.core.utils.BackwardCompatibility in project ats-framework by Axway.
the class AbstractDbAccess method getDatabaseInitialVersion.
@BackwardCompatibility
public int getDatabaseInitialVersion() throws NumberFormatException {
if (dbInitialVersion == -1) {
// not yet tried to be extracted from DB
Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
connection = getConnection();
statement = connection.prepareStatement("SELECT value from tInternal where [key] = 'initialVersion'");
rs = statement.executeQuery();
// we expect only one record
if (rs.next()) {
String value = rs.getString(1);
if (StringUtils.isNullOrEmpty(value)) {
dbInitialVersion = 0;
} else {
dbInitialVersion = Integer.parseInt(value.trim());
}
} else {
dbInitialVersion = 0;
}
if (dbInitialVersion == 0) {
//Seems to be pre 3.10.0 version
log.debug("DB initialVersion not found.");
}
} catch (NumberFormatException nfe) {
throw new NumberFormatException("Error parsing DB initialVersion");
} catch (Exception e) {
log.debug("Error fetching DB initialVersion", e);
dbInitialVersion = 0;
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, statement);
}
}
return dbInitialVersion;
}
use of com.axway.ats.core.utils.BackwardCompatibility 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.core.utils.BackwardCompatibility in project ats-framework by Axway.
the class DbReadAccess method getSuites.
@BackwardCompatibility
public List<Suite> getSuites(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending, boolean dateFormatNoYear) throws DatabaseAccessException {
List<Suite> suites = new ArrayList<Suite>();
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_suites(?, ?, ?, ?, ?) }");
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()) {
Suite suite = new Suite();
suite.suiteId = rs.getString("suiteId");
try {
@BackwardCompatibility int // suite.runId introduced 3.11.0 (internalVersion=3)
dbInternalVersion = getDatabaseInternalVersion();
if (dbInternalVersion >= 3) {
suite.runId = rs.getString("runId");
}
} catch (NumberFormatException nfe) {
suite.runId = "";
log.warn("Error parsing dbInternalVersion. ", nfe);
}
suite.name = rs.getString("name");
if (dateFormatNoYear) {
suite.dateStart = formatDateNoYear(rs.getTimestamp("dateStart"));
suite.dateEnd = formatDateNoYear(rs.getTimestamp("dateEnd"));
} else {
suite.dateStart = formatDate(rs.getTimestamp("dateStart"));
suite.dateEnd = formatDate(rs.getTimestamp("dateEnd"));
}
int duration = rs.getInt("duration");
if (duration < 0) {
// this may happen when the suite is not ended and the time of the log server
// is behind with the time of the test executor host
duration = 0;
}
suite.duration = formatTimeDiffereceFromSecondsToString(duration);
suite.scenariosTotal = rs.getInt("scenariosTotal");
suite.scenariosFailed = rs.getInt("scenariosFailed");
suite.scenariosSkipped = rs.getInt("scenariosSkipped");
suite.testcasesTotal = rs.getInt("testcasesTotal");
suite.testcasesFailed = rs.getInt("testcasesFailed");
suite.testcasesPassedPercent = String.valueOf(rs.getInt("testcasesPassedPercent")) + "%";
suite.testcaseIsRunning = rs.getBoolean("testcaseIsRunning");
suite.total = suite.scenariosTotal + "/" + suite.testcasesTotal;
suite.failed = suite.scenariosFailed + "/" + suite.testcasesFailed;
suite.userNote = rs.getString("userNote");
suite.packageName = "";
try {
@BackwardCompatibility int // suite.packageName introduced 3.5.0 and internalVersion=1 (in 3.10.0)
dbInternalVersion = getDatabaseInternalVersion();
if (dbInternalVersion >= 1) {
suite.packageName = rs.getString("package");
}
} catch (NumberFormatException nfe) {
suite.packageName = "";
log.warn("Error parsing dbInternalVersion. ", nfe);
}
suites.add(suite);
numberRecords++;
}
logQuerySuccess(sqlLog, "suites", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return suites;
}
Aggregations