use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method isTestcasePresent.
public boolean isTestcasePresent(int testcaseId) throws DatabaseAccessException {
Connection connection = getConnection();
PreparedStatement statement = null;
ResultSet rs = null;
try {
statement = connection.prepareStatement("SELECT COUNT(*) FROM tTestcases WHERE testcaseId = " + testcaseId);
rs = statement.executeQuery();
if (rs.next()) {
return 1 == rs.getInt(1);
}
} catch (Exception e) {
throw new DatabaseAccessException("Error checking whether testcase with id " + testcaseId + " exists", e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, statement);
}
return false;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method updateRun.
/**
* Update the static information about an existing run
*
* @param runId
* @param runName
* @param osName
* @param productName
* @param versionName
* @param buildName
* @param userNote
* @param hostName
* @throws DatabaseAccessException
*/
public void updateRun(int runId, String runName, String osName, String productName, String versionName, String buildName, String userNote, String hostName, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to update run with name '" + runName + "' and id " + runId;
// then start the run
final int indexRowsUpdate = 9;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_update_run(?, ?, ?, ?, ?, ?, ?, ?, ?) }");
callableStatement.setInt(1, runId);
callableStatement.setString(2, productName);
callableStatement.setString(3, versionName);
callableStatement.setString(4, buildName);
callableStatement.setString(5, runName);
callableStatement.setString(6, osName);
callableStatement.setString(7, userNote);
callableStatement.setString(8, hostName);
callableStatement.registerOutParameter(indexRowsUpdate, Types.INTEGER);
callableStatement.execute();
if (callableStatement.getInt(indexRowsUpdate) != 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 insertRunMessage.
public boolean insertRunMessage(String message, int level, boolean escapeHtml, String machineName, String threadName, long timestamp, int runId, boolean closeConnection) throws DatabaseAccessException {
String dbVersionString = getDatabaseVersion();
int dbVersion = Integer.parseInt(dbVersionString.replace(".", ""));
if (dbVersion < 350) {
return false;
} else {
Connection currentConnection;
if (!isBatchMode) {
currentConnection = refreshInternalConnection();
} else {
currentConnection = dbEventsCache.connection;
}
CallableStatement insertMessageStatement = insertFactory.getInsertRunMessageStatement(currentConnection, message, level, escapeHtml, machineName, threadName, timestamp, runId);
if (isBatchMode) {
// schedule this event for batch execution
return dbEventsCache.addInsertRunMessageEventToBatch(insertMessageStatement);
} else {
// execute this event now
final String errMsg = "Unable to insert run message '" + message + "'";
final int indexRowsInserted = 8;
try {
insertMessageStatement.execute();
if (insertMessageStatement.getInt(indexRowsInserted) < 1) {
throw new DatabaseAccessException(errMsg);
}
} catch (SQLException e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, insertMessageStatement);
} else {
DbUtils.closeStatement(insertMessageStatement);
}
}
return false;
}
}
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method addRunMetainfo.
/**
* Update meta info about an existing run
*
* @param runId
* @param metaKey
* @param metaValue
* @param closeConnection
* @throws DatabaseAccessException
*/
public void addRunMetainfo(int runId, String metaKey, String metaValue, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to add run meta info '" + metaKey + "=" + metaValue + "' to run with id " + runId;
final int indexRowsInserted = 4;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_add_run_metainfo(?, ?, ?, ?) }");
callableStatement.setInt(1, runId);
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 insertMessage.
public boolean insertMessage(String message, int level, boolean escapeHtml, String machineName, String threadName, long timestamp, int testCaseId, boolean closeConnection) throws DatabaseAccessException {
Connection currentConnection;
if (!isBatchMode) {
currentConnection = refreshInternalConnection();
} else {
currentConnection = dbEventsCache.connection;
}
CallableStatement insertMessageStatement = insertFactory.getInsertTestcaseMessageStatement(currentConnection, message, level, escapeHtml, machineName, threadName, timestamp, testCaseId);
if (isBatchMode) {
// schedule this event for batch execution
return dbEventsCache.addInsertTestcaseMessageEventToBatch(insertMessageStatement);
} else {
// execute this event now
final String errMsg = "Unable to insert testcase message '" + message + "'";
final int indexRowsInserted = 8;
try {
insertMessageStatement.execute();
if (insertMessageStatement.getInt(indexRowsInserted) < 1) {
throw new DatabaseAccessException(errMsg);
}
} catch (SQLException e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
if (closeConnection) {
DbUtils.close(connection, insertMessageStatement);
} else {
DbUtils.closeStatement(insertMessageStatement);
}
}
return false;
}
}
Aggregations