Navigation Menu

Skip to content

Commit

Permalink
Add reloadChannels option to the API for saving channels
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Sep 9, 2009
1 parent d69ace8 commit cb6d08b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
Expand Up @@ -38,13 +38,13 @@ public interface IConfigurationService {

public List<NodeGroupLink> getGroupLinksFor(String sourceGroupId);

public void saveChannel(Channel channel);
public void saveChannel(Channel channel, boolean reloadChannels);

public void saveChannel(NodeChannel channel);

public void saveNodeChannel(NodeChannel channel);

public void saveNodeChannelControl(NodeChannel channel);
public void saveNodeChannelControl(NodeChannel channel, boolean reloadChannels);

public void deleteChannel(Channel channel);

Expand Down
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.Map;

import org.hsqldb.Types;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.model.Channel;
import org.jumpmind.symmetric.model.DataEventAction;
Expand Down Expand Up @@ -63,35 +62,39 @@ public List<NodeGroupLink> getGroupLinksFor(String nodeGroupId) {
return jdbcTemplate.query(getSql("groupsLinksForSql"), new Object[] { nodeGroupId }, new NodeGroupLinkMapper());
}

public void saveChannel(Channel channel) {
public void saveChannel(Channel channel, boolean reloadChannels) {
if (0 == jdbcTemplate.update(getSql("updateChannelSql"), new Object[] { channel.getProcessingOrder(),
channel.getMaxBatchSize(), channel.getMaxBatchToSend(), channel.isEnabled() ? 1 : 0,
channel.getBatchAlgorithm(), channel.getId() })) {
jdbcTemplate.update(getSql("insertChannelSql"), new Object[] { channel.getId(),
channel.getProcessingOrder(), channel.getMaxBatchSize(), channel.getMaxBatchToSend(),
channel.isEnabled() ? 1 : 0, channel.getBatchAlgorithm() });
}
reloadChannels();
if (reloadChannels) {
reloadChannels();
}
}

public void saveChannel(NodeChannel nodeChannel) {
saveChannel(nodeChannel.getChannel());
saveChannel(nodeChannel.getChannel(), true);
}

public void saveNodeChannel(NodeChannel nodeChannel) {
saveChannel(nodeChannel.getChannel());
saveNodeChannelControl(nodeChannel);
saveChannel(nodeChannel.getChannel(), true);
saveNodeChannelControl(nodeChannel, false);
}

public void saveNodeChannelControl(NodeChannel nodeChannel) {
public void saveNodeChannelControl(NodeChannel nodeChannel, boolean reloadChannels) {
if (0 == jdbcTemplate.update(getSql("updateNodeChannelControlSql"), new Object[] {
nodeChannel.isSuspended() ? 1 : 0, nodeChannel.isIgnored() ? 1 : 0, nodeChannel.getLastExtractedTime(),
nodeChannel.getNodeId(), nodeChannel.getId() })) {
jdbcTemplate.update(getSql("insertNodeChannelControlSql"), new Object[] { nodeChannel.getNodeId(),
nodeChannel.getId(), nodeChannel.isSuspended() ? 1 : 0, nodeChannel.isIgnored() ? 1 : 0,
nodeChannel.getLastExtractedTime() });
}
reloadChannels();
if (reloadChannels) {
reloadChannels();
}
}

public void deleteChannel(Channel channel) {
Expand Down Expand Up @@ -183,7 +186,7 @@ public void autoConfigDatabase(boolean force) {
for (Channel defaultChannel : defaultChannels) {
if (!defaultChannel.isInList(channels)) {
log.info("ChannelAutoConfiguring", defaultChannel.getId());
saveChannel(defaultChannel);
saveChannel(defaultChannel, true);
} else {
log.info("ChannelExists", defaultChannel.getId());
}
Expand Down
Expand Up @@ -83,15 +83,15 @@ public void testGetNodeChannelsById() throws Exception {

// Test "ignored"
nc.setIgnored(true);
configurationService.saveNodeChannelControl(nc);
configurationService.saveNodeChannelControl(nc, false);
NodeChannel compareTo = configurationService.getNodeChannel(updatedChannelId, nodeId);
Assert.assertTrue(compareTo.isIgnored());
Assert.assertFalse(compareTo.isSuspended());
Assert.assertNull(compareTo.getLastExtractedTime());

// Test "suspended"
compareTo.setSuspended(true);
configurationService.saveNodeChannelControl(compareTo);
configurationService.saveNodeChannelControl(compareTo, false);
compareTo = configurationService.getNodeChannel(updatedChannelId, nodeId);
Assert.assertTrue(compareTo.isIgnored());
Assert.assertTrue(compareTo.isSuspended());
Expand All @@ -103,7 +103,7 @@ public void testGetNodeChannelsById() throws Exception {

Date date = new Date();
nc1.setLastExtractedTime(date);
configurationService.saveNodeChannelControl(nc1);
configurationService.saveNodeChannelControl(nc1, false);

compareTo = configurationService.getNodeChannel(updatedChannelId1, nodeId);
Assert.assertFalse(compareTo.isIgnored());
Expand Down
Expand Up @@ -72,7 +72,7 @@ public void setUp() {
public void testDisabledChannel() {
NodeChannel nodeChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID);
nodeChannel.setEnabled(false);
getConfigurationService().saveChannel(nodeChannel.getChannel());
getConfigurationService().saveChannel(nodeChannel.getChannel(), true);

cleanSlate("sym_data_event", "sym_data",
"sym_outgoing_batch");
Expand Down
Expand Up @@ -218,7 +218,7 @@ public void testGetSuspendIgnoreChannels() throws Exception {
String channelId = ncs.get(1).getId();

nc.setSuspended(true);
configurationService.saveNodeChannelControl(nc);
configurationService.saveNodeChannelControl(nc, false);

result = filter.getSuspendIgnoreChannels(nodeId);

Expand All @@ -228,7 +228,7 @@ public void testGetSuspendIgnoreChannels() throws Exception {
nc = ncs.get(0);
nc.setSuspended(true);

configurationService.saveNodeChannelControl(nc);
configurationService.saveNodeChannelControl(nc, false);

String channelIds = ncs.get(0).getId() + "," + ncs.get(1).getId();
result = filter.getSuspendIgnoreChannels(nodeId);
Expand All @@ -237,7 +237,7 @@ public void testGetSuspendIgnoreChannels() throws Exception {
Assert.assertTrue(channelIds.equals(result.get(WebConstants.SUSPENDED_CHANNELS)));

nc.setIgnored(true);
configurationService.saveNodeChannelControl(nc);
configurationService.saveNodeChannelControl(nc, false);
result = filter.getSuspendIgnoreChannels(nodeId);

Assert.assertEquals(2, result.size());
Expand Down Expand Up @@ -283,9 +283,9 @@ public void testBuildSuspendIgnoreResponseHeaders() throws Exception {
ncs.get(1).setIgnored(true);
ncs.get(2).setSuspended(true);

configurationService.saveNodeChannelControl(ncs.get(0));
configurationService.saveNodeChannelControl(ncs.get(1));
configurationService.saveNodeChannelControl(ncs.get(2));
configurationService.saveNodeChannelControl(ncs.get(0), false);
configurationService.saveNodeChannelControl(ncs.get(1), false);
configurationService.saveNodeChannelControl(ncs.get(2), false);

filter.buildSuspendIgnoreResponseHeaders(nodeId, resp);

Expand Down

0 comments on commit cb6d08b

Please sign in to comment.