Skip to content

Commit

Permalink
0004771: Added sorting to batch services (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-miller-jumpmind committed Jan 18, 2021
1 parent c199f12 commit 9e79e21
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
Expand Up @@ -66,7 +66,8 @@ public List<Date> listIncomingBatchTimes(List<String> nodeIds, List<String> chan
public List<IncomingBatch> listIncomingBatches(List<String> nodeIds, List<String> channels,
List<IncomingBatch.Status> statuses, List<Long> loads, Date startAtCreateTime, int maxRowsToRetrieve, boolean ascending);

public List<IncomingBatch> listIncomingBatchesWithLimit(int offset, int limit, List<FilterCriterion> filter);
public List<IncomingBatch> listIncomingBatchesWithLimit(int offset, int limit, List<FilterCriterion> filter,
String orderColumn, String orderDirection);

public int countIncomingBatchesWithLimit(List<FilterCriterion> filter);

Expand Down
Expand Up @@ -120,7 +120,8 @@ public int countOutgoingBatches(List<String> nodeIds, List<String> channels,
public List<OutgoingBatch> listOutgoingBatches(List<String> nodeIds, List<String> channels,
List<OutgoingBatch.Status> statuses, List<Long> loads, long startAtBatchId, int rowsExpected, boolean ascending);

public List<OutgoingBatch> listOutgoingBatchesWithLimit(int offset, int limit, List<FilterCriterion> filter);
public List<OutgoingBatch> listOutgoingBatchesWithLimit(int offset, int limit, List<FilterCriterion> filter,
String orderColumn, String orderDirection);

public int countOutgoingBatchesWithLimit(List<FilterCriterion> filter);

Expand Down
Expand Up @@ -343,6 +343,30 @@ protected Map<String, Object> buildBatchParams(List<FilterCriterion> filter) {
return params;
}

protected String buildBatchOrderBy(String orderColumn, String orderDirection) {
String orderBy = " order by ";
if (orderColumn == null) {
if (this instanceof OutgoingBatchService) {
orderBy += "batch_id desc";
} else {
orderBy += "create_time desc";
}
} else {
if (orderColumn.equals("lastUpdatedTime")) {
orderColumn = "last_update_time";
} else if (orderColumn.equals("lastUpdatedHostName")) {
orderColumn = "last_update_hostname";
} else {
orderColumn = orderColumn.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase();
}
orderBy += orderColumn;
if (orderDirection.equals("DESCENDING")) {
orderBy += " desc";
}
}
return orderBy;
}

/**
* Try a configured number of times to get the ACK through.
*/
Expand Down
Expand Up @@ -170,10 +170,12 @@ public List<IncomingBatch> listIncomingBatches(List<String> nodeIds, List<String

}

public List<IncomingBatch> listIncomingBatchesWithLimit(int offset, int limit, List<FilterCriterion> filter) {
public List<IncomingBatch> listIncomingBatchesWithLimit(int offset, int limit, List<FilterCriterion> filter,
String orderColumn, String orderDirection) {
String where = filter != null ? buildBatchWhereFromFilter(filter) : null;
Map<String, Object> params = filter != null ? buildBatchParams(filter) : new HashMap<String, Object>();
String sql = getSql("selectIncomingBatchPrefixSql", where, " order by create_time desc");
String orderBy = buildBatchOrderBy(orderColumn, orderDirection);
String sql = getSql("selectIncomingBatchPrefixSql", where, orderBy);
List<IncomingBatch> batchList;

if (platform.supportsLimitOffset()) {
Expand Down
Expand Up @@ -459,10 +459,13 @@ public List<OutgoingBatch> listOutgoingBatches(List<String> nodeIds, List<String

}

public List<OutgoingBatch> listOutgoingBatchesWithLimit(int offset, int limit, List<FilterCriterion> filter) {
public List<OutgoingBatch> listOutgoingBatchesWithLimit(int offset, int limit, List<FilterCriterion> filter,
String orderColumn, String orderDirection) {
String where = filter != null ? buildBatchWhereFromFilter(filter) : null;
Map<String, Object> params = filter != null ? buildBatchParams(filter) : new HashMap<String, Object>();
String sql = getSql("selectOutgoingBatchPrefixSql", where, " order by batch_id desc");
String orderBy = buildBatchOrderBy(orderColumn, orderDirection);
String sql = getSql("selectOutgoingBatchPrefixSql", where, orderBy);

List<OutgoingBatch> batchList;

if (platform.supportsLimitOffset()) {
Expand Down

0 comments on commit 9e79e21

Please sign in to comment.