001
014
015 package com.liferay.portal.upgrade.v4_4_0;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
019 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
020
021 import java.sql.Connection;
022 import java.sql.PreparedStatement;
023 import java.sql.ResultSet;
024
025
028 public class UpgradeUUID extends UpgradeProcess {
029
030 protected void doUpgrade() throws Exception {
031 updateTable("BlogsEntry", "entryId");
032 updateTable("BookmarksEntry", "entryId");
033 updateTable("BookmarksFolder", "folderId");
034 updateTable("DLFileEntry", "fileEntryId");
035 updateTable("DLFileShortcut", "fileShortcutId");
036 updateTable("DLFolder", "folderId");
037 updateTable("CalEvent", "eventId");
038 updateTable("IGFolder", "folderId");
039 updateTable("IGImage", "imageId");
040 updateTable("JournalArticle", "id_");
041 updateTable("JournalStructure", "id_");
042 updateTable("JournalTemplate", "id_");
043 updateTable("MBCategory", "categoryId");
044 updateTable("MBMessage", "messageId");
045 updateTable("PollsChoice", "choiceId");
046 updateTable("PollsQuestion", "questionId");
047 updateTable("User_", "userId");
048 updateTable("WikiNode", "nodeId");
049 updateTable("WikiPage", "pageId");
050 }
051
052 protected void updateTable(String tableName, String pkColName)
053 throws Exception {
054
055 Connection con = null;
056 PreparedStatement ps = null;
057 ResultSet rs = null;
058
059 try {
060 con = DataAccess.getConnection();
061
062 ps = con.prepareStatement(
063 "select " + pkColName + " from " + tableName +
064 " where uuid_ IS NULL or uuid_ = ''");
065
066 rs = ps.executeQuery();
067
068 while (rs.next()) {
069 long pkColValue = rs.getLong(pkColName);
070
071 String uuid = PortalUUIDUtil.generate();
072
073 runSQL(
074 "update " + tableName + " set uuid_ = '" + uuid +
075 "' where " + pkColName + " = " + pkColValue);
076 }
077 }
078 finally {
079 DataAccess.cleanUp(con, ps, rs);
080 }
081 }
082
083 }