use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method insertSystemStatistics.
public void insertSystemStatistics(int testCaseId, String machine, String statisticIds, String statisticValues, long timestamp, boolean closeConnection) throws DatabaseAccessException {
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_insert_system_statistic_by_ids(?, ?, ?, ?, ?) }");
callableStatement.setString(3, statisticIds);
callableStatement.setInt(1, testCaseId);
callableStatement.setString(2, machine);
callableStatement.setString(4, statisticValues);
callableStatement.setTimestamp(5, new Timestamp(timestamp));
callableStatement.execute();
} catch (Exception e) {
String errMsg = "Unable to insert system statistics, statistic IDs '" + statisticIds + "', statistic values '" + statisticValues + "', timestamp " + timestamp;
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 startLoadQueue.
public int startLoadQueue(String name, int sequence, String hostsList, String threadingPattern, int numberThreads, String machine, long timestamp, int testcaseId, boolean closeConnection) throws DatabaseAccessException {
if (testcaseId < 1) {
log.warn("Load queue '" + name + "' will not be registered because there is no database connection!");
return -1;
}
final String errMsg = "Unable to start load queue with name " + name;
// create a new load queue
final int indexRowsInserted = 9;
final int indexLoadQueueId = 10;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_start_loadqueue(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }");
callableStatement.setInt(1, testcaseId);
callableStatement.setString(2, name);
callableStatement.setInt(3, sequence);
callableStatement.setString(4, hostsList);
callableStatement.setString(5, threadingPattern);
callableStatement.setInt(6, numberThreads);
callableStatement.setString(7, machine);
callableStatement.setTimestamp(8, new Timestamp(timestamp));
callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
callableStatement.registerOutParameter(indexLoadQueueId, Types.INTEGER);
callableStatement.execute();
if (callableStatement.getInt(indexRowsInserted) != 1) {
throw new DatabaseAccessException(errMsg);
} else {
if (callableStatement.getInt(indexLoadQueueId) == 0) {
throw new DatabaseAccessException(errMsg + " - load queue id returned was 0");
}
}
// get the result
return callableStatement.getInt(indexLoadQueueId);
} 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 insertCheckpoint.
public boolean insertCheckpoint(String name, String threadName, long startTimestamp, long responseTime, long transferSize, String transferUnit, int result, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
Connection currentConnection;
if (!isBatchMode) {
currentConnection = refreshInternalConnection();
} else {
currentConnection = dbEventsCache.connection;
}
CallableStatement insertCheckpointStatement = insertFactory.getInsersCheckpointStatement(currentConnection, name, threadName, responseTime, startTimestamp + responseTime, transferSize, transferUnit, result, checkpointLogLevel, loadQueueId);
if (isBatchMode) {
// schedule this event for batch execution
return dbEventsCache.addInsertCheckpointEventToBatch(insertCheckpointStatement);
} else {
// execute this event now
final String errMsg = "Unable to insert checkpoint '" + name + "'";
try {
insertCheckpointStatement.execute();
// if( insertCheckpointStatement.getInt( indexRowsInserted ) < 1 ) {
// throw new DatabaseAccessException( errMsg );
// }
} catch (SQLException e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, insertCheckpointStatement);
} else {
DbUtils.closeStatement(insertCheckpointStatement);
}
}
return false;
}
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method endTestCase.
public void endTestCase(int testcaseResult, long timestamp, int testcaseId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to end testcase with id " + testcaseId;
final int indexRowsInserted = 4;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_end_testcase(?, ?, ?, ?) }");
callableStatement.setInt(1, testcaseId);
callableStatement.setInt(2, testcaseResult);
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 AbstractDbAccess method getDatabaseVersion.
public String getDatabaseVersion() throws DatabaseAccessException {
if (dbVersion == null) {
Connection connection = getConnection();
PreparedStatement statement = null;
ResultSet rs = null;
try {
statement = connection.prepareStatement("SELECT value from tInternal where [key] = 'version'");
rs = statement.executeQuery();
// we expect only one record
if (rs.next()) {
dbVersion = rs.getString(1);
} else {
throw new DatabaseAccessException("Could not fetch the DB version");
}
} catch (Exception e) {
throw new DatabaseAccessException("Error fetching DB version", e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, statement);
}
}
return dbVersion;
}
Aggregations