1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.upgrade.v5_2_2;
16  
17  import com.liferay.portal.kernel.dao.jdbc.DataAccess;
18  import com.liferay.portal.kernel.upgrade.UpgradeProcess;
19  
20  import java.sql.Connection;
21  import java.sql.PreparedStatement;
22  import java.sql.ResultSet;
23  
24  /**
25   * <a href="UpgradeWebForm.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Julio Camarero
28   */
29  public class UpgradeWebForm extends UpgradeProcess {
30  
31      protected void doUpgrade() throws Exception {
32          long oldClassNameId = getClassNameId(_OLD_WEBFORM_CLASS_NAME);
33  
34          if (oldClassNameId == 0) {
35              return;
36          }
37  
38          long newClassNameId = getClassNameId(_NEW_WEBFORM_CLASS_NAME);
39  
40          if (newClassNameId == 0) {
41              runSQL(
42                  "update ClassName_ set value = '" +
43                      _NEW_WEBFORM_CLASS_NAME + "' where value = '" +
44                          _OLD_WEBFORM_CLASS_NAME + "'");
45          }
46          else {
47              runSQL(
48                  "update ExpandoTable set classNameId = '" + newClassNameId +
49                      "' where classNameId = '" + oldClassNameId + "'");
50  
51              runSQL(
52                  "update ExpandoValue set classNameId = '" + newClassNameId +
53                      "' where classNameId = '" + oldClassNameId + "'");
54  
55              runSQL(
56                  "delete from ClassName_ where value = '" +
57                      _OLD_WEBFORM_CLASS_NAME + "'");
58          }
59      }
60  
61      protected long getClassNameId(String className) throws Exception {
62          long classNameId = 0;
63  
64          Connection con = null;
65          PreparedStatement ps = null;
66          ResultSet rs = null;
67  
68          try {
69              con = DataAccess.getConnection();
70  
71              ps = con.prepareStatement(
72                  "select classNameId from ClassName_ where value = ?");
73  
74              ps.setString(1, className);
75  
76              rs = ps.executeQuery();
77  
78              if (rs.next()) {
79                  classNameId = rs.getLong("classNameId");
80              }
81          }
82          finally {
83              DataAccess.cleanUp(con, ps, rs);
84          }
85  
86          return classNameId;
87      }
88  
89      private static final String _NEW_WEBFORM_CLASS_NAME =
90          "com.liferay.webform.util.WebFormUtil";
91  
92      private static final String _OLD_WEBFORM_CLASS_NAME =
93          "com.liferay.portlet.webform.util.WebFormUtil";
94  
95  }