1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }