View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
19   */
20  
21  package org.jumpmind.symmetric.upgrade;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.jumpmind.symmetric.model.Node;
25  import org.springframework.jdbc.core.JdbcTemplate;
26  
27  abstract public class AbstractSqlUpgradeTask implements IUpgradeTask {
28  
29      protected JdbcTemplate jdbcTemplate;
30  
31      protected boolean isUpgradeRegistrationServer = true;
32  
33      protected boolean isUpgradeNonRegistrationServer = true;
34  
35      protected boolean useReplacement = true;
36  
37      public void upgrade(int[] fromVersion) {
38      }
39  
40      protected String prepareSql(Node node, String sql) {
41          if (useReplacement) {
42              sql = replace("groupId", node.getNodeGroupId(), sql);
43              sql = replace("externalId", node.getExternalId(), sql);
44              sql = replace("nodeId", node.getNodeId(), sql);
45          }
46          return sql;
47      }
48  
49      protected String replace(String prop, String replaceWith, String sourceString) {
50          return StringUtils.replace(sourceString, "$(" + prop + ")", replaceWith);
51      }
52  
53      public void setJdbcTemplate(JdbcTemplate jdbc) {
54          this.jdbcTemplate = jdbc;
55      }
56  
57      public boolean isUpgradeNonRegistrationServer() {
58          return isUpgradeNonRegistrationServer;
59      }
60  
61      public boolean getUpgradeNonRegistrationServer() {
62          return isUpgradeNonRegistrationServer;
63      }
64  
65      public void setUpgradeNonRegistrationServer(boolean isUpgradeNonRegistrationServer) {
66          this.isUpgradeNonRegistrationServer = isUpgradeNonRegistrationServer;
67      }
68  
69      public boolean isUpgradeRegistrationServer() {
70          return isUpgradeRegistrationServer;
71      }
72  
73      public boolean getUpgradeRegistrationServer() {
74          return isUpgradeRegistrationServer;
75      }
76  
77      public void setUpgradeRegistrationServer(boolean isUpgradeRegistrationServer) {
78          this.isUpgradeRegistrationServer = isUpgradeRegistrationServer;
79      }
80  
81      public boolean getUseReplacement() {
82          return useReplacement;
83      }
84  
85      public void setUseReplacement(boolean useReplacement) {
86          this.useReplacement = useReplacement;
87      }
88  
89  }