use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method endSuite.
public void endSuite(long timestamp, int suiteId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to end suite with id " + suiteId;
final int indexRowsInserted = 3;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_end_suite(?, ?, ?) }");
callableStatement.setInt(1, suiteId);
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 ReportExtactor method extractRunEntities.
/**
* extract the runs
*
* @param runIds
* @return
*/
private List<RunWrapper> extractRunEntities(int[] runIds) {
StringBuilder whereClause = new StringBuilder();
whereClause.append(" WHERE runId IN (");
for (int runId : runIds) {
whereClause.append(runId).append(", ");
}
whereClause.setLength(whereClause.lastIndexOf(","));
whereClause.append(")");
List<Run> dbRuns;
try {
dbRuns = dbReadAccess.getRuns(0, 10000, whereClause.toString(), "runId", true);
} catch (DatabaseAccessException e) {
throw new ReportExtractorException("Error loading runs " + whereClause, e);
}
List<RunWrapper> runs = new ArrayList<RunWrapper>();
for (Run dbRun : dbRuns) {
// load this run's suites
List<Suite> suites;
try {
suites = dbReadAccess.getSuites(0, 10000, "WHERE runId=" + dbRun.runId, "suiteId", true, false);
} catch (DatabaseAccessException e) {
throw new ReportExtractorException("Error loading suites for run with id " + dbRun.runId, e);
}
RunWrapper run = new RunWrapper(dbRun, suites);
runs.add(run);
}
return runs;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method endLoadQueue.
public void endLoadQueue(int result, long timestamp, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to end load queue with id " + loadQueueId;
final int indexRowsInserted = 4;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_end_loadqueue(?, ?, ?, ?) }");
callableStatement.setInt(1, loadQueueId);
callableStatement.setInt(2, result);
callableStatement.setTimestamp(3, 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 startSuite.
public int startSuite(String packageName, String suiteName, long timestamp, int runId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to start suite with name " + suiteName;
// create a new suite
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
// TODO : remove me after 3.6.0
String dbVersionString = getDatabaseVersion();
int dbVersion = Integer.parseInt(dbVersionString.replace(".", ""));
if (dbVersion >= 350) {
callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?, ?) }");
if (packageName == null) {
packageName = "";
}
callableStatement.setString("@package", packageName);
} else {
callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?) }");
}
callableStatement.setString("@suiteName", suiteName);
callableStatement.setInt("@runId", runId);
callableStatement.setTimestamp("@dateStart", new Timestamp(timestamp));
callableStatement.registerOutParameter("@RowsInserted", Types.INTEGER);
callableStatement.registerOutParameter("@suiteId", Types.INTEGER);
callableStatement.execute();
if (callableStatement.getInt("@RowsInserted") != 1) {
throw new DatabaseAccessException(errMsg);
} else {
if (callableStatement.getInt("@suiteId") == 0) {
throw new DatabaseAccessException(errMsg + " - suite ID returned was 0");
}
}
// get the result
return callableStatement.getInt("@suiteId");
} 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 isRunPresent.
public boolean isRunPresent(int runId) throws DatabaseAccessException {
Connection connection = getConnection();
PreparedStatement statement = null;
ResultSet rs = null;
try {
statement = connection.prepareStatement("SELECT COUNT(*) FROM tRuns WHERE runId = " + runId);
rs = statement.executeQuery();
if (rs.next()) {
return 1 == rs.getInt(1);
}
} catch (Exception e) {
throw new DatabaseAccessException("Error checking whether run with id " + runId + " exists", e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, statement);
}
return false;
}
Aggregations