Skip to content

Commit

Permalink
1918310 - check sym_node_security for isInitialLoadComplete()
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Mar 18, 2008
1 parent 841d051 commit 755a066
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Expand Up @@ -33,9 +33,10 @@
import org.jumpmind.symmetric.db.IDbDialect;
import org.jumpmind.symmetric.model.BatchType;
import org.jumpmind.symmetric.model.NodeChannel;
import org.jumpmind.symmetric.model.NodeSecurity;
import org.jumpmind.symmetric.model.OutgoingBatch;
import org.jumpmind.symmetric.model.OutgoingBatch.Status;
import org.jumpmind.symmetric.service.IConfigurationService;
import org.jumpmind.symmetric.service.INodeService;
import org.jumpmind.symmetric.service.IOutgoingBatchHistoryService;
import org.jumpmind.symmetric.service.IOutgoingBatchService;
import org.jumpmind.symmetric.util.MaxRowsStatementCreator;
Expand All @@ -50,7 +51,7 @@ public class OutgoingBatchService extends AbstractService implements IOutgoingBa

final static Log logger = LogFactory.getLog(OutgoingBatchService.class);

IConfigurationService configurationService;
private INodeService nodeService;

private int batchSizePeekAhead = 100;

Expand All @@ -72,7 +73,7 @@ public class OutgoingBatchService extends AbstractService implements IOutgoingBa

private JdbcTemplate outgoingBatchQueryTemplate;

private IOutgoingBatchHistoryService historyService;
private IOutgoingBatchHistoryService historyService;

private IDbDialect dbDialect;

Expand Down Expand Up @@ -243,25 +244,27 @@ public void setBatchStatus(String batchId, Status status) {
}
}

// TODO Unit test and probably refactor this method.
// TODO Should this move to DataService?
@SuppressWarnings("unchecked")
public boolean isInitialLoadComplete(String nodeId) {
boolean returnValue = false;

NodeSecurity security = nodeService.findNodeSecurity(nodeId);
if (security != null && security.isInitialLoadEnabled()) {
return false;
}

List<String> statuses = (List<String>) jdbcTemplate.queryForList(initialLoadStatusSql, new Object[] { nodeId },
String.class);
if (statuses == null || statuses.size() == 0) {
throw new RuntimeException("The initial load has not been started for " + nodeId);
}

for (String status : statuses) {
if (Status.ER.name().equals(status)) {
throw new RuntimeException("The initial load errored out for " + nodeId);
} else if (Status.OK.name().equals(status)) {
returnValue = true;
} else {
if (!Status.OK.name().equals(status)) {
return false;
}
}
return returnValue;
return true;
}

class OutgoingBatchMapper implements RowMapper {
Expand All @@ -277,10 +280,6 @@ public Object mapRow(ResultSet rs, int num) throws SQLException {
}
}

public void setConfigurationService(IConfigurationService configurationService) {
this.configurationService = configurationService;
}

public void setCreateBatchSql(String createBatchSql) {
this.createBatchSql = createBatchSql;
}
Expand Down Expand Up @@ -329,4 +328,8 @@ public void setBatchSizePeekAhead(int batchSizePeekAhead) {
this.batchSizePeekAhead = batchSizePeekAhead;
}

public void setNodeService(INodeService nodeService) {
this.nodeService = nodeService;
}

}
2 changes: 1 addition & 1 deletion symmetric/src/main/resources/symmetric-services.xml
Expand Up @@ -242,7 +242,7 @@
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="batchSizePeekAhead" value="${symmetric.runtime.outgoing.batches.peek.ahead.window.after.max.size}"/>
<property name="runtimeConfiguration" ref="runtimeConfiguration" />
<property name="configurationService" ref="configurationService" />
<property name="nodeService" ref="nodeService" />
<property name="historyService" ref="outgoingBatchHistoryService" />
<property name="dbDialect" ref="dbDialect" />
<property name="outgoingBatchQueryTemplate">
Expand Down

0 comments on commit 755a066

Please sign in to comment.