Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add upgrade task to set initial_load_select on sym_trigger 'config' c…
…hannel entries
  • Loading branch information
erilong committed Jan 3, 2008
1 parent f779041 commit b0571fc
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 3 deletions.
Expand Up @@ -78,6 +78,7 @@ public String createInitalLoadSql(Node node, IDbDialect dialect, Trigger trig, T
// Replace these parameters to give the initiaLoadContition a chance to reference domainNames and domainIds
sql = replace("groupId", node.getNodeGroupId(), sql);
sql = replace("externalId", node.getExternalId(), sql);
sql = replace("nodeId", node.getNodeId(), sql);

Column[] columns = trig.orderColumnsForTable(metaData);
String columnsText = buildColumnString("t", "t", columns);
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.Version;
Expand Down Expand Up @@ -56,7 +57,7 @@ public void upgrade() {
int[] fromVersion = Version.parseVersion(node.getSymmetricVersion());

if (Version.isOlderMinorVersion(node.getSymmetricVersion())) {
runUpgrade(fromVersion);
runUpgrade(node, fromVersion);
node.setSymmetricVersion(Version.VERSION);
nodeService.updateNode(node);
}
Expand All @@ -65,14 +66,18 @@ public void upgrade() {
}
}

private void runUpgrade(int[] fromVersion) {
private void runUpgrade(Node node, int[] fromVersion) {
String majorMinorVersion = fromVersion[0] + "." + fromVersion[1];
List<IUpgradeTask> upgradeTaskList = upgradeTaskMap.get(majorMinorVersion);
logger.info("Starting upgrade from version " + majorMinorVersion + " to " + Version.MAJOR + "."
+ Version.MINOR);
boolean isRegistrationServer = StringUtils.isEmpty(runtimeConfiguration.getRegistrationUrl());
if (upgradeTaskList != null) {
for (IUpgradeTask upgradeTask : upgradeTaskList) {
upgradeTask.upgrade(fromVersion);
if ((isRegistrationServer && upgradeTask.isUpgradeRegistrationServer())
|| (!isRegistrationServer && upgradeTask.isUpgradeNonRegistrationServer())) {
upgradeTask.upgrade(node, fromVersion);
}
}
}
logger.info("Completed upgrade");
Expand Down
Expand Up @@ -20,8 +20,16 @@

package org.jumpmind.symmetric.upgrade;

import org.jumpmind.symmetric.model.Node;

public interface IUpgradeTask {

@Deprecated
public void upgrade(int[] fromVersion);

public void upgrade(Node node, int[] fromVersion);

public boolean isUpgradeRegistrationServer();

public boolean isUpgradeNonRegistrationServer();
}
Expand Up @@ -22,8 +22,10 @@

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.model.Node;
import org.springframework.jdbc.core.JdbcTemplate;

public class SqlUpgradeTask implements IUpgradeTask {
Expand All @@ -33,6 +35,10 @@ public class SqlUpgradeTask implements IUpgradeTask {
protected JdbcTemplate jdbcTemplate;

protected List<String> sqlList;

protected boolean isUpgradeRegistrationServer = true;

protected boolean isUpgradeNonRegistrationServer = true;

public void upgrade(int[] fromVersion) {
for (String sql : sqlList) {
Expand All @@ -41,6 +47,20 @@ public void upgrade(int[] fromVersion) {
}
}

public void upgrade(Node node, int[] fromVersion) {
for (String sql : sqlList) {
logger.debug("upgrade->" + sql);
sql = replace("groupId", node.getNodeGroupId(), sql);
sql = replace("externalId", node.getExternalId(), sql);
sql = replace("nodeId", node.getNodeId(), sql);
jdbcTemplate.update(sql);
}
}

private String replace(String prop, String replaceWith, String sourceString) {
return StringUtils.replace(sourceString, "$(" + prop + ")", replaceWith);
}

public void setJdbcTemplate(JdbcTemplate jdbc) {
this.jdbcTemplate = jdbc;
}
Expand All @@ -49,4 +69,28 @@ public void setSqlList(List<String> sqlList) {
this.sqlList = sqlList;
}

public boolean isUpgradeNonRegistrationServer() {
return isUpgradeNonRegistrationServer;
}

public boolean getUpgradeNonRegistrationServer() {
return isUpgradeNonRegistrationServer;
}

public void setUpgradeNonRegistrationServer(boolean isUpgradeNonRegistrationServer) {
this.isUpgradeNonRegistrationServer = isUpgradeNonRegistrationServer;
}

public boolean isUpgradeRegistrationServer() {
return isUpgradeRegistrationServer;
}

public boolean getUpgradeRegistrationServer() {
return isUpgradeRegistrationServer;
}

public void setUpgradeRegistrationServer(boolean isUpgradeRegistrationServer) {
this.isUpgradeRegistrationServer = isUpgradeRegistrationServer;
}

}
62 changes: 62 additions & 0 deletions symmetric/src/main/resources/symmetric-upgrade.xml
Expand Up @@ -29,6 +29,7 @@
<constructor-arg>
<list>
<ref bean="changes1.2" />
<ref bean="changes1.2-nonRegServer" />
</list>
</constructor-arg>
</bean>
Expand Down Expand Up @@ -75,6 +76,67 @@
update ${sync.table.prefix}_node_security
set initial_load_time = registration_time
</value>
<value>
update sym_trigger
set initial_load_select = 'node_group_id = ''$(groupId)'' or node_group_id in (select source_node_group_id from ${sync.table.prefix}_node_group_link where target_node_group_id = ''$(groupId)'') or node_group_id in (select target_node_group_id from ${sync.table.prefix}_node_group_link where source_node_group_id = ''$(groupId)'')'
where channel_id = 'config' and source_table_name = '${sync.table.prefix}_node_group'
</value>
<value>
update sym_trigger
set initial_load_select = 'source_node_group_id = ''$(groupId)'' or target_node_group_id = ''$(groupId)'''
where channel_id = 'config' and source_table_name = '${sync.table.prefix}_node_group_link'
</value>
<value>
update sym_trigger
set initial_load_select = 'node_id = ''$(nodeId)'' or node_group_id in (select source_node_group_id from ${sync.table.prefix}_node_group_link where target_node_group_id = ''$(groupId)'') or node_group_id in (select target_node_group_id from ${sync.table.prefix}_node_group_link where source_node_group_id = ''$(groupId)'')'
where channel_id = 'config' and source_table_name = '${sync.table.prefix}_node'
</value>
<value>
update sym_trigger
set initial_load_select = 'node_id = ''$(nodeId)'' or node_id in (select s.node_id from ${sync.table.prefix}_node s inner join ${sync.table.prefix}_node_group_link l on s.node_group_id = l.source_node_group_id where l.target_node_group_id = ''$(groupId)'') or node_id in (select s.node_id from ${sync.table.prefix}_node s inner join ${sync.table.prefix}_node_group_link l on s.node_group_id = l.target_node_group_id where l.source_node_group_id = ''$(groupId)'')'
where channel_id = 'config' and source_table_name = '${sync.table.prefix}_node_security'
</value>
<value>
update sym_trigger
set initial_load_select = 'node_group_id = ''$(groupId)'''
where channel_id = 'config' and source_table_name = '${sync.table.prefix}_global_parameter'
</value>
<value>
update sym_trigger
set initial_load_select = 'channel_id in (select channel_id from ${sync.table.prefix}_trigger where source_node_group_id = ''$(groupId)'')'
where channel_id = 'config' and source_table_name = '${sync.table.prefix}_channel'
</value>
<value>
update sym_trigger
set initial_load_select = 'node_id = ''$(nodeId)'''
where channel_id = 'config' and source_table_name = '${sync.table.prefix}_node_channel_ctl'
</value>
<value>
update sym_trigger
set initial_load_select = 'source_node_group_id = ''$(groupId)'''
where channel_id = 'config' and source_table_name = '${sync.table.prefix}_trigger'
</value>
</list>
</property>
</bean>

<bean id="changes1.2-nonRegServer" class="org.jumpmind.symmetric.upgrade.SqlUpgradeTask">
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="upgradeRegistrationServer" value="false" />
<property name="sqlList">
<list>
<value>
delete from ${sync.table.prefix}_node where
node_id != '$(nodeId)' and
node_group_id not in (select source_node_group_id from ${sync.table.prefix}_node_group_link where target_node_group_id = '$(groupId)') and
node_group_id not in (select target_node_group_id from ${sync.table.prefix}_node_group_link where source_node_group_id = '$(groupId)')
</value>
<value>
delete from ${sync.table.prefix}_node_security where
node_id != '$(nodeId)' and
node_id not in (select s.node_id from ${sync.table.prefix}_node s inner join ${sync.table.prefix}_node_group_link l on s.node_group_id = l.source_node_group_id where l.target_node_group_id = '$(groupId)') and
node_id not in (select s.node_id from ${sync.table.prefix}_node s inner join ${sync.table.prefix}_node_group_link l on s.node_group_id = l.target_node_group_id where l.source_node_group_id = '$(groupId)')
</value>
</list>
</property>
</bean>
Expand Down

0 comments on commit b0571fc

Please sign in to comment.