1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.upgrade;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.util.InstancePool;
28  import com.liferay.portal.tools.sql.DBUtil;
29  
30  import java.io.IOException;
31  
32  import java.sql.SQLException;
33  
34  import javax.naming.NamingException;
35  
36  /**
37   * <a href="UpgradeProcess.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   * @author Alexander Chow
41   */
42  public abstract class UpgradeProcess {
43  
44      public UpgradeProcess() {
45      }
46  
47      public int getThreshold() {
48  
49          // This upgrade process will only run if the build number is larger than
50          // the returned threshold value. Return 0 to always run this upgrade
51          // process.
52  
53          return 0;
54      }
55  
56      public boolean isSupportsAlterColumnName() {
57          return DBUtil.getInstance().isSupportsAlterColumnName();
58      }
59  
60      public boolean isSupportsAlterColumnType() {
61          return DBUtil.getInstance().isSupportsAlterColumnType();
62      }
63  
64      public boolean isSupportsStringCaseSensitiveQuery() {
65          return DBUtil.getInstance().isSupportsStringCaseSensitiveQuery();
66      }
67  
68      public boolean isSupportsUpdateWithInnerJoin() {
69          return DBUtil.getInstance().isSupportsUpdateWithInnerJoin();
70      }
71  
72      public void runSQL(String template) throws IOException, SQLException {
73          DBUtil.getInstance().runSQL(template);
74      }
75  
76      public void runSQL(String[] templates) throws IOException, SQLException {
77          DBUtil.getInstance().runSQL(templates);
78      }
79  
80      public void runSQLTemplate(String path)
81          throws IOException, NamingException, SQLException {
82  
83          DBUtil.getInstance().runSQLTemplate(path);
84      }
85  
86      public void runSQLTemplate(String path, boolean failOnError)
87          throws IOException, NamingException, SQLException {
88  
89          DBUtil.getInstance().runSQLTemplate(path, failOnError);
90      }
91  
92      public void upgrade() throws UpgradeException {
93          try {
94              if (_log.isInfoEnabled()) {
95                  _log.info("Upgrading " + getClass().getName());
96              }
97  
98              doUpgrade();
99          }
100         catch (Exception e) {
101             throw new UpgradeException(e);
102         }
103     }
104 
105     public void upgrade(Class<?> upgradeProcessClass)
106         throws UpgradeException {
107 
108         UpgradeProcess upgradeProcess = (UpgradeProcess)InstancePool.get(
109             upgradeProcessClass.getName());
110 
111         upgradeProcess.upgrade();
112     }
113 
114     public void upgrade(UpgradeProcess upgradeProcess)
115         throws UpgradeException {
116 
117         upgradeProcess.upgrade();
118     }
119 
120     protected void doUpgrade() throws Exception {
121     }
122 
123     private static Log _log = LogFactoryUtil.getLog(UpgradeProcess.class);
124 
125 }