Skip to content

Commit

Permalink
do some validation at the service level.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Mar 8, 2011
1 parent 2873e68 commit 1d4ca12
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 48 deletions.
Expand Up @@ -76,29 +76,36 @@ public List<Date> listIncomingBatchTimes(List<String> nodeIds, List<String> chan

public List<IncomingBatch> listIncomingBatches(List<String> nodeIds, List<String> channels,
List<IncomingBatch.Status> statuses, Date startAtCreateTime, final int maxRowsToRetrieve) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("NODES", nodeIds);
params.put("CHANNELS", channels);
params.put("STATUSES", toStringList(statuses));
params.put("CREATE_TIME", startAtCreateTime);

NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(jdbcTemplate);
ResultSetExtractor<List<IncomingBatch>> extractor = new ResultSetExtractor<List<IncomingBatch>>() {
IncomingBatchMapper rowMapper = new IncomingBatchMapper();
public List<IncomingBatch> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<IncomingBatch> list = new ArrayList<IncomingBatch>(maxRowsToRetrieve);
int count = 0;
while (rs.next() && count < maxRowsToRetrieve) {
list.add(rowMapper.mapRow(rs, ++count));
if (nodeIds.size() > 0 && channels.size() > 0 && statuses.size() > 0) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("NODES", nodeIds);
params.put("CHANNELS", channels);
params.put("STATUSES", toStringList(statuses));
params.put("CREATE_TIME", startAtCreateTime);

NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(jdbcTemplate);
ResultSetExtractor<List<IncomingBatch>> extractor = new ResultSetExtractor<List<IncomingBatch>>() {
IncomingBatchMapper rowMapper = new IncomingBatchMapper();

public List<IncomingBatch> extractData(ResultSet rs) throws SQLException,
DataAccessException {
List<IncomingBatch> list = new ArrayList<IncomingBatch>(maxRowsToRetrieve);
int count = 0;
while (rs.next() && count < maxRowsToRetrieve) {
list.add(rowMapper.mapRow(rs, ++count));
}
return list;
}
return list;
}
};

List<IncomingBatch> list = template.query(
getSql("selectIncomingBatchPrefixSql","listIncomingBatchesSql"), new MapSqlParameterSource(params), extractor);
return list;
}
};

List<IncomingBatch> list = template.query(
getSql("selectIncomingBatchPrefixSql", "listIncomingBatchesSql"),
new MapSqlParameterSource(params), extractor);
return list;
} else {
return new ArrayList<IncomingBatch>(0);
}
}

protected List<String> toStringList(List<IncomingBatch.Status> statuses) {
List<String> statusStrings = new ArrayList<String>(statuses.size());
Expand Down
Expand Up @@ -166,33 +166,41 @@ public int countOutgoingBatches(List<String> nodeIds, List<String> channels,

public List<OutgoingBatch> listOutgoingBatches(List<String> nodeIds, List<String> channels,
List<OutgoingBatch.Status> statuses, long startAtBatchId, final int maxRowsToRetrieve) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("NODES", nodeIds);
params.put("CHANNELS", channels);
params.put("STATUSES", toStringList(statuses));
String startAtBatchIdSql = null;
if (startAtBatchId > 0) {
params.put("BATCH_ID", startAtBatchId);
startAtBatchIdSql = " and batch_id < :BATCH_ID ";
}

NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource);
ResultSetExtractor<List<OutgoingBatch>> extractor = new ResultSetExtractor<List<OutgoingBatch>>() {
OutgoingBatchMapper rowMapper = new OutgoingBatchMapper();
public List<OutgoingBatch> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<OutgoingBatch> list = new ArrayList<OutgoingBatch>(maxRowsToRetrieve);
int count = 0;
while (rs.next() && count < maxRowsToRetrieve) {
list.add(rowMapper.mapRow(rs, ++count));
}
return list;
if (nodeIds.size() > 0 && channels.size() > 0 && statuses.size() > 0) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("NODES", nodeIds);
params.put("CHANNELS", channels);
params.put("STATUSES", toStringList(statuses));
String startAtBatchIdSql = null;
if (startAtBatchId > 0) {
params.put("BATCH_ID", startAtBatchId);
startAtBatchIdSql = " and batch_id < :BATCH_ID ";
}
};

List<OutgoingBatch> list = template.query(
getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchByChannelAndStatusSql",
startAtBatchIdSql, " order by batch_id desc"), new MapSqlParameterSource(params), extractor);
return list;

NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource);
ResultSetExtractor<List<OutgoingBatch>> extractor = new ResultSetExtractor<List<OutgoingBatch>>() {
OutgoingBatchMapper rowMapper = new OutgoingBatchMapper();

public List<OutgoingBatch> extractData(ResultSet rs) throws SQLException,
DataAccessException {
List<OutgoingBatch> list = new ArrayList<OutgoingBatch>(maxRowsToRetrieve);
int count = 0;
while (rs.next() && count < maxRowsToRetrieve) {
list.add(rowMapper.mapRow(rs, ++count));
}
return list;
}
};

List<OutgoingBatch> list = template.query(
getSql("selectOutgoingBatchPrefixSql",
"selectOutgoingBatchByChannelAndStatusSql", startAtBatchIdSql,
" order by batch_id desc"), new MapSqlParameterSource(params),
extractor);
return list;
} else {
return new ArrayList<OutgoingBatch>(0);
}
}

protected List<String> toStringList(List<OutgoingBatch.Status> statuses) {
Expand Down

0 comments on commit 1d4ca12

Please sign in to comment.