Skip to content

Commit

Permalink
re-order the update status for sym_data_gap to remove the (unlikely) …
Browse files Browse the repository at this point in the history
…possibility of a partially filled in gap being marked as ok and not recording the new gaps
  • Loading branch information
chenson42 committed Apr 11, 2011
1 parent af59c47 commit b037800
Showing 1 changed file with 4 additions and 8 deletions.
Expand Up @@ -23,7 +23,6 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

Expand All @@ -40,7 +39,8 @@
import org.springframework.jdbc.core.ResultSetExtractor;

/**
*
* Responsible for managing gaps in data ids to ensure that all captured
* data is routed for delivery to other nodes.
*/
public class DataGapDetector implements IDataToRouteGapDetector {

Expand Down Expand Up @@ -86,18 +86,17 @@ public void beforeRouting() {
Object[] params = new Object[] { dataGap.getStartId(), dataGap.getEndId() };
lastDataId = jdbcTemplate.query(sql, params, new ResultSetExtractor<Long>() {
public Long extractData(ResultSet rs) throws SQLException, DataAccessException {
List<DataGap> newGaps = new ArrayList<DataGap>();
long lastDataId = -1;
while (rs.next()) {
long dataId = rs.getLong(1);
if (lastDataId != -1 && lastDataId + dataIdIncrementBy != dataId
&& lastDataId != dataId) {
// found a gap
newGaps.add(new DataGap(lastDataId + 1, dataId - 1));
dataService.insertDataGap(new DataGap(lastDataId + 1, dataId - 1));
}
lastDataId = dataId;
}

if (lastDataId != -1) {
dataService.updateDataGap(dataGap, DataGap.Status.OK);
} else if (!lastGap) {
Expand Down Expand Up @@ -125,9 +124,6 @@ public Long extractData(ResultSet rs) throws SQLException, DataAccessException {
}
}

for (DataGap dataGap : newGaps) {
dataService.insertDataGap(dataGap);
}

return lastDataId;
}
Expand Down

0 comments on commit b037800

Please sign in to comment.