use of com.axway.ats.log.autodb.entities.Message 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.entities.Message in project ats-framework by Axway.
the class DbReadAccess method getRunMessages.
public List<Message> getRunMessages(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending) throws DatabaseAccessException {
List<Message> runMessages = 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_run_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 runMessage = new Message();
runMessage.messageId = rs.getInt("runMessageId");
runMessage.messageContent = rs.getString("message");
runMessage.messageType = rs.getString("typeName");
Timestamp timestamp = rs.getTimestamp("timestamp");
runMessage.date = dateFormat.format(timestamp);
runMessage.time = timeFormat.format(timestamp);
runMessage.machineName = rs.getString("machineName");
runMessage.threadName = rs.getString("threadName");
runMessages.add(runMessage);
numberRecords++;
}
logQuerySuccess(sqlLog, "run messages", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return runMessages;
}
use of com.axway.ats.log.autodb.entities.Message in project ats-framework by Axway.
the class DbReadAccess method getMessages.
public List<Message> getMessages(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending) throws DatabaseAccessException {
List<Message> messages = 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_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();
// <parentMessageId, Message>
Map<Integer, Message> splitMessages = new HashMap<Integer, Message>();
while (rs.next()) {
Message message = new Message();
message.messageId = rs.getInt("messageId");
message.messageContent = rs.getString("message");
message.messageType = rs.getString("typeName");
Timestamp timestamp = rs.getTimestamp("timestamp");
message.date = dateFormat.format(timestamp);
message.time = timeFormat.format(timestamp);
message.machineName = rs.getString("machineName");
message.threadName = rs.getString("threadName");
message.parentMessageId = rs.getInt("parentMessageId");
if (message.parentMessageId != 0) {
// split message
if (splitMessages.containsKey(message.parentMessageId)) {
// append to the message - result set is ordered by message ID
Message splitMessage = splitMessages.get(message.parentMessageId);
if (splitMessage.messageId < message.messageId) {
// append at the end
splitMessage.messageContent = splitMessage.messageContent + message.messageContent;
} else {
// append at the beginning
splitMessage.messageContent = message.messageContent + splitMessage.messageContent;
}
} else {
// first part of the split message
splitMessages.put(message.parentMessageId, message);
messages.add(message);
}
} else {
// single message
messages.add(message);
}
numberRecords++;
}
logQuerySuccess(sqlLog, "messages", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return messages;
}
Aggregations