1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.verify;
24  
25  import com.liferay.portal.kernel.dao.jdbc.DataAccess;
26  import com.liferay.portal.kernel.util.LongWrapper;
27  import com.liferay.portal.kernel.util.MethodInvoker;
28  import com.liferay.portal.kernel.util.MethodWrapper;
29  import com.liferay.portlet.imagegallery.service.IGFolderLocalServiceUtil;
30  import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
31  import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
32  import com.liferay.portlet.journal.service.JournalFeedLocalServiceUtil;
33  import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
34  import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
35  
36  import java.sql.Connection;
37  import java.sql.PreparedStatement;
38  import java.sql.ResultSet;
39  
40  import org.apache.commons.logging.Log;
41  import org.apache.commons.logging.LogFactory;
42  
43  /**
44   * <a href="VerifyUUID.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   *
48   */
49  public class VerifyUUID extends VerifyProcess {
50  
51      public void verify() throws VerifyException {
52          _log.info("Verifying");
53  
54          try {
55              verifyUUID();
56          }
57          catch (Exception e) {
58              throw new VerifyException(e);
59          }
60      }
61  
62      protected void verifyModel(
63              String serviceClassName, String modelName, String pkColumnName)
64          throws Exception {
65  
66          Connection con = null;
67          PreparedStatement ps = null;
68          ResultSet rs = null;
69  
70          try {
71              con = DataAccess.getConnection();
72  
73              ps = con.prepareStatement(
74                  "select " + pkColumnName + " from " + modelName +
75                      " where uuid_ is null or uuid_ = ''");
76  
77              rs = ps.executeQuery();
78  
79              while (rs.next()) {
80                  long pk = rs.getLong(pkColumnName);
81  
82                  verifyModel(serviceClassName, modelName, pk);
83              }
84          }
85          finally {
86              DataAccess.cleanUp(con, ps, rs);
87          }
88      }
89  
90      protected void verifyModel(
91              String serviceClassName, String modelName, long pk)
92          throws Exception {
93  
94          Object obj = MethodInvoker.invoke(
95              new MethodWrapper(
96                  serviceClassName, "get" + modelName, new LongWrapper(pk)));
97  
98          MethodInvoker.invoke(
99              new MethodWrapper(serviceClassName, "update" + modelName, obj));
100     }
101 
102     protected void verifyUUID() throws Exception {
103         for (String[] model : _MODELS) {
104             verifyModel(model[0], model[1], model[2]);
105         }
106     }
107 
108     private static final String[][] _MODELS = new String[][] {
109         new String[] {
110             IGFolderLocalServiceUtil.class.getName(),
111             "IGFolder",
112             "folderId"
113         },
114         new String[] {
115             IGImageLocalServiceUtil.class.getName(),
116             "IGImage",
117             "imageId"
118         },
119         new String[] {
120             JournalArticleLocalServiceUtil.class.getName(),
121             "JournalArticle",
122             "id_"
123         },
124         new String[] {
125             JournalFeedLocalServiceUtil.class.getName(),
126             "JournalFeed",
127             "id_"
128         },
129         new String[] {
130             JournalStructureLocalServiceUtil.class.getName(),
131             "JournalStructure",
132             "id_"
133         },
134         new String[] {
135             JournalTemplateLocalServiceUtil.class.getName(),
136             "JournalTemplate",
137             "id_"
138         }
139     };
140 
141     private static Log _log = LogFactory.getLog(VerifyUUID.class);
142 
143 }