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.verify;
16  
17  import com.liferay.portal.kernel.dao.jdbc.DataAccess;
18  import com.liferay.portal.kernel.util.LongWrapper;
19  import com.liferay.portal.kernel.util.MethodInvoker;
20  import com.liferay.portal.kernel.util.MethodWrapper;
21  import com.liferay.portlet.imagegallery.service.IGFolderLocalServiceUtil;
22  import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
23  import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
24  import com.liferay.portlet.journal.service.JournalFeedLocalServiceUtil;
25  import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
26  import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
27  
28  import java.sql.Connection;
29  import java.sql.PreparedStatement;
30  import java.sql.ResultSet;
31  
32  /**
33   * <a href="VerifyUUID.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class VerifyUUID extends VerifyProcess {
38  
39      protected void doVerify() throws Exception {
40          for (String[] model : _MODELS) {
41              verifyModel(model[0], model[1], model[2]);
42          }
43      }
44  
45      protected void verifyModel(
46              String serviceClassName, String modelName, String pkColumnName)
47          throws Exception {
48  
49          Connection con = null;
50          PreparedStatement ps = null;
51          ResultSet rs = null;
52  
53          try {
54              con = DataAccess.getConnection();
55  
56              ps = con.prepareStatement(
57                  "select " + pkColumnName + " from " + modelName +
58                      " where uuid_ is null or uuid_ = ''");
59  
60              rs = ps.executeQuery();
61  
62              while (rs.next()) {
63                  long pk = rs.getLong(pkColumnName);
64  
65                  verifyModel(serviceClassName, modelName, pk);
66              }
67          }
68          finally {
69              DataAccess.cleanUp(con, ps, rs);
70          }
71      }
72  
73      protected void verifyModel(
74              String serviceClassName, String modelName, long pk)
75          throws Exception {
76  
77          Object obj = MethodInvoker.invoke(
78              new MethodWrapper(
79                  serviceClassName, "get" + modelName, new LongWrapper(pk)));
80  
81          MethodInvoker.invoke(
82              new MethodWrapper(serviceClassName, "update" + modelName, obj));
83      }
84  
85      private static final String[][] _MODELS = new String[][] {
86          new String[] {
87              IGFolderLocalServiceUtil.class.getName(),
88              "IGFolder",
89              "folderId"
90          },
91          new String[] {
92              IGImageLocalServiceUtil.class.getName(),
93              "IGImage",
94              "imageId"
95          },
96          new String[] {
97              JournalArticleLocalServiceUtil.class.getName(),
98              "JournalArticle",
99              "id_"
100         },
101         new String[] {
102             JournalFeedLocalServiceUtil.class.getName(),
103             "JournalFeed",
104             "id_"
105         },
106         new String[] {
107             JournalStructureLocalServiceUtil.class.getName(),
108             "JournalStructure",
109             "id_"
110         },
111         new String[] {
112             JournalTemplateLocalServiceUtil.class.getName(),
113             "JournalTemplate",
114             "id_"
115         }
116     };
117 
118 }