001
014
015 package com.liferay.portal.verify;
016
017 import com.liferay.portal.kernel.dao.db.DB;
018 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
019 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
020 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
021
022 import java.sql.Connection;
023 import java.sql.PreparedStatement;
024 import java.sql.ResultSet;
025
026
029 public class VerifyUUID extends VerifyProcess {
030
031 public static void verifyModel(String modelName, String pkColumnName)
032 throws Exception {
033
034 Connection con = null;
035 PreparedStatement ps = null;
036 ResultSet rs = null;
037
038 try {
039 con = DataAccess.getUpgradeOptimizedConnection();
040
041 ps = con.prepareStatement(
042 "select " + pkColumnName + " from " + modelName +
043 " where uuid_ is null or uuid_ = ''");
044
045 rs = ps.executeQuery();
046
047 while (rs.next()) {
048 long pk = rs.getLong(pkColumnName);
049
050 verifyModel(modelName, pkColumnName, pk);
051 }
052 }
053 finally {
054 DataAccess.cleanUp(con, ps, rs);
055 }
056 }
057
058 protected static void verifyModel(
059 String modelName, String pkColumnName, long pk)
060 throws Exception {
061
062 String uuid = PortalUUIDUtil.generate();
063
064 DB db = DBFactoryUtil.getDB();
065
066 db.runSQL(
067 "update " + modelName + " set uuid_ = '" + uuid + "' where " +
068 pkColumnName + " = " + pk);
069 }
070
071 @Override
072 protected void doVerify() throws Exception {
073 for (String[] model : _MODELS) {
074 verifyModel(model[0], model[1]);
075 }
076 }
077
078 private static final String[][] _MODELS = new String[][] {
079 new String[] {
080 "Address", "addressId"
081 },
082 new String[] {
083 "DLFileVersion", "fileVersionId"
084 },
085 new String[] {
086 "EmailAddress", "emailAddressId"
087 },
088 new String[] {
089 "Group_", "groupId"
090 },
091 new String[] {
092 "JournalArticleResource", "resourcePrimKey"
093 },
094 new String[] {
095 "JournalFeed", "id_"
096 },
097 new String[] {
098 "Layout", "plid"
099 },
100 new String[] {
101 "LayoutPrototype", "layoutPrototypeId"
102 },
103 new String[] {
104 "LayoutSetPrototype", "layoutSetPrototypeId"
105 },
106 new String[] {
107 "MBBan", "banId"
108 },
109 new String[] {
110 "MBDiscussion", "discussionId"
111 },
112 new String[] {
113 "MBThread", "threadId"
114 },
115 new String[] {
116 "MBThreadFlag", "threadFlagId"
117 },
118 new String[] {
119 "Organization_", "organizationId"
120 },
121 new String[] {
122 "PasswordPolicy", "passwordPolicyId"
123 },
124 new String[] {
125 "Phone", "phoneId"
126 },
127 new String[] {
128 "PollsVote", "voteId"
129 },
130 new String[] {
131 "Role_", "roleId"
132 },
133 new String[] {
134 "UserGroup", "userGroupId"
135 },
136 new String[] {
137 "Website", "websiteId"
138 },
139 new String[] {
140 "WikiPageResource", "resourcePrimKey"
141 }
142 };
143
144 }