@Override
public List<AuditTrailInfo> getAuditTrails(String transactionId,String conversationId,String correlationId,Integer level, int maxResult) {
SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
String sortClause = "SEQ_ID";
String whereClause = "where 1=1 ";
List<Object> args = new ArrayList<Object>();
if(level != null){
whereClause += " and LOGLEVEL <= ? ";
sortClause = "LOGLEVEL";
args.add(level);
}
if(StringUtils.hasText(correlationId)){
whereClause += " and CORRELATION_ID = ? ";
sortClause = "CORRELATION_ID";
args.add(correlationId);
}
if(StringUtils.hasText(conversationId)){
whereClause += " and CONVERSATION_ID = ? ";
sortClause = "CONVERSATION_ID";
args.add(conversationId);
}
if(StringUtils.hasText(transactionId)){
whereClause += " and TRANSACTION_ID = ? ";
sortClause = "TRANSACTION_ID";
args.add(transactionId);
}
String selectClause = "select "
+"SEQ_ID,"
+"TRANSACTION_ID,"
+"CONVERSATION_ID,"
+"CORRELATION_ID,"
+"OCCURRENCE,"
+"LOGLEVEL,"
+"CONTEXT,"
+"INSTANCE_ID,"
+"MESSAGE_TYPE";
factory.setDataSource(getDataSource());
factory.setFromClause("from COP_AUDIT_TRAIL_EVENT ");
factory.setSelectClause(selectClause);
factory.setWhereClause(whereClause);
factory.setSortKey(sortClause);
PagingQueryProvider queryProvider = null;
try {
queryProvider = (PagingQueryProvider)factory.getObject();
} catch (Exception e) {
logger.error(e.getMessage(),e);
return null;
}