001
014
015 package com.liferay.portal.upgrade.v5_2_2;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
019
020 import java.sql.Connection;
021 import java.sql.PreparedStatement;
022 import java.sql.ResultSet;
023
024
027 public class UpgradeWebForm extends UpgradeProcess {
028
029 protected void doUpgrade() throws Exception {
030 long oldClassNameId = getClassNameId(_OLD_WEBFORM_CLASS_NAME);
031
032 if (oldClassNameId == 0) {
033 return;
034 }
035
036 long newClassNameId = getClassNameId(_NEW_WEBFORM_CLASS_NAME);
037
038 if (newClassNameId == 0) {
039 runSQL(
040 "update ClassName_ set value = '" +
041 _NEW_WEBFORM_CLASS_NAME + "' where value = '" +
042 _OLD_WEBFORM_CLASS_NAME + "'");
043 }
044 else {
045 runSQL(
046 "update ExpandoTable set classNameId = '" + newClassNameId +
047 "' where classNameId = '" + oldClassNameId + "'");
048
049 runSQL(
050 "update ExpandoValue set classNameId = '" + newClassNameId +
051 "' where classNameId = '" + oldClassNameId + "'");
052
053 runSQL(
054 "delete from ClassName_ where value = '" +
055 _OLD_WEBFORM_CLASS_NAME + "'");
056 }
057 }
058
059 protected long getClassNameId(String className) throws Exception {
060 long classNameId = 0;
061
062 Connection con = null;
063 PreparedStatement ps = null;
064 ResultSet rs = null;
065
066 try {
067 con = DataAccess.getConnection();
068
069 ps = con.prepareStatement(
070 "select classNameId from ClassName_ where value = ?");
071
072 ps.setString(1, className);
073
074 rs = ps.executeQuery();
075
076 if (rs.next()) {
077 classNameId = rs.getLong("classNameId");
078 }
079 }
080 finally {
081 DataAccess.cleanUp(con, ps, rs);
082 }
083
084 return classNameId;
085 }
086
087 private static final String _NEW_WEBFORM_CLASS_NAME =
088 "com.liferay.webform.util.WebFormUtil";
089
090 private static final String _OLD_WEBFORM_CLASS_NAME =
091 "com.liferay.portlet.webform.util.WebFormUtil";
092
093 }