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.getConnection();
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 public 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 +
068 "' where " + 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 "DLFileVersion", "fileVersionId"
081 },
082 new String[] {
083 "JournalArticleResource", "resourcePrimKey"
084 },
085 new String[] {
086 "JournalFeed", "id_"
087 },
088 new String[] {
089 "JournalStructure", "id_"
090 },
091 new String[] {
092 "JournalTemplate", "id_"
093 },
094 new String[] {
095 "Layout", "plid"
096 },
097 new String[] {
098 "LayoutPrototype", "layoutPrototypeId"
099 },
100 new String[] {
101 "LayoutSetPrototype", "layoutSetPrototypeId"
102 },
103 new String[] {
104 "WikiPageResource", "resourcePrimKey"
105 }
106 };
107
108 }