use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getRunsCount.
public int getRunsCount(String whereClause) throws DatabaseAccessException {
Connection connection = getConnection();
String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_runs_count(?) }");
callableStatement.setString(1, whereClause);
rs = callableStatement.executeQuery();
int runsCount = 0;
while (rs.next()) {
runsCount = rs.getInt("runsCount");
logQuerySuccess(sqlLog, "runs", runsCount);
break;
}
return runsCount;
} 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 getMachines.
public List<Machine> getMachines() throws DatabaseAccessException {
List<Machine> machines = new ArrayList<Machine>();
Connection connection = getConnection();
PreparedStatement statement = null;
ResultSet rs = null;
try {
statement = connection.prepareStatement("SELECT * FROM tMachines ORDER BY machineName");
rs = statement.executeQuery();
while (rs.next()) {
Machine machine = new Machine();
machine.machineId = rs.getInt("machineId");
machine.name = rs.getString("machineName");
machine.alias = rs.getString("machineAlias");
machines.add(machine);
}
} catch (Exception e) {
throw new DatabaseAccessException("Error retrieving machines", e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, statement);
}
return machines;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbReadAccess method getSuiteMessages.
public List<Message> getSuiteMessages(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending) throws DatabaseAccessException {
List<Message> suiteMessages = 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_suite_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 suiteMessage = new Message();
suiteMessage.messageId = rs.getInt("suiteMessageId");
suiteMessage.messageContent = rs.getString("message");
suiteMessage.messageType = rs.getString("typeName");
Timestamp timestamp = rs.getTimestamp("timestamp");
suiteMessage.date = dateFormat.format(timestamp);
suiteMessage.time = timeFormat.format(timestamp);
suiteMessage.machineName = rs.getString("machineName");
suiteMessage.threadName = rs.getString("threadName");
suiteMessages.add(suiteMessage);
numberRecords++;
}
logQuerySuccess(sqlLog, "suite messages", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return suiteMessages;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class AbstractClientExecutor method retrieveQueueId.
/**
* Start performance queue in the database and retrieve its ID
*
* @return the started queue ID
* @throws AgentException
*/
public int retrieveQueueId(int sequence, String hostsList) throws AgentException {
int queueId;
try {
if (dbAccess == null) {
dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
}
queueId = dbAccess.startLoadQueue(queueName, sequence, hostsList, threadingPattern.getPatternDescription(), threadingPattern.getThreadCount(), LOCAL_MACHINE, Calendar.getInstance().getTimeInMillis(), ActiveDbAppender.getCurrentInstance().getTestCaseId(), true);
log.rememberLoadQueueState(queueName, queueId, threadingPattern.getPatternDescription(), threadingPattern.getThreadCount());
} catch (DatabaseAccessException e) {
if (ActiveDbAppender.getCurrentInstance() == null) {
// The log4j DB appender is not attached
// We assume the user is running a performance test without DB logging
log.warn("Unable to register a performance queue with name '" + queueName + "' in the loggging database." + " This means the results of running this queue will not be registered in the log DB." + " Check your DB configuration in order to fix this problem.");
// Return this invalid value will not cause an error on the Test Executor side
// We also know there will be no error on agent's side as our DB appender will not be present there
queueId = -1;
} else {
throw new AgentException("Unable to register a performance queue with name '" + queueName + "' in the loggging database. This queue will not run at all.", e);
}
}
return queueId;
}
use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.
the class DbWriteAccess method isSuitePresent.
public boolean isSuitePresent(int suiteId) throws DatabaseAccessException {
Connection connection = getConnection();
PreparedStatement statement = null;
ResultSet rs = null;
try {
statement = connection.prepareStatement("SELECT COUNT(*) FROM tSuites WHERE suiteId = " + suiteId);
rs = statement.executeQuery();
if (rs.next()) {
return 1 == rs.getInt(1);
}
} catch (Exception e) {
throw new DatabaseAccessException("Error checking whether suite with id " + suiteId + " exists", e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, statement);
}
return false;
}
Aggregations