1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  /**
41   * <a href="VerifyUUID.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   */
45  public class VerifyUUID extends VerifyProcess {
46  
47      protected void doVerify() throws Exception {
48          for (String[] model : _MODELS) {
49              verifyModel(model[0], model[1], model[2]);
50          }
51      }
52  
53      protected void verifyModel(
54              String serviceClassName, String modelName, String pkColumnName)
55          throws Exception {
56  
57          Connection con = null;
58          PreparedStatement ps = null;
59          ResultSet rs = null;
60  
61          try {
62              con = DataAccess.getConnection();
63  
64              ps = con.prepareStatement(
65                  "select " + pkColumnName + " from " + modelName +
66                      " where uuid_ is null or uuid_ = ''");
67  
68              rs = ps.executeQuery();
69  
70              while (rs.next()) {
71                  long pk = rs.getLong(pkColumnName);
72  
73                  verifyModel(serviceClassName, modelName, pk);
74              }
75          }
76          finally {
77              DataAccess.cleanUp(con, ps, rs);
78          }
79      }
80  
81      protected void verifyModel(
82              String serviceClassName, String modelName, long pk)
83          throws Exception {
84  
85          Object obj = MethodInvoker.invoke(
86              new MethodWrapper(
87                  serviceClassName, "get" + modelName, new LongWrapper(pk)));
88  
89          MethodInvoker.invoke(
90              new MethodWrapper(serviceClassName, "update" + modelName, obj));
91      }
92  
93      private static final String[][] _MODELS = new String[][] {
94          new String[] {
95              IGFolderLocalServiceUtil.class.getName(),
96              "IGFolder",
97              "folderId"
98          },
99          new String[] {
100             IGImageLocalServiceUtil.class.getName(),
101             "IGImage",
102             "imageId"
103         },
104         new String[] {
105             JournalArticleLocalServiceUtil.class.getName(),
106             "JournalArticle",
107             "id_"
108         },
109         new String[] {
110             JournalFeedLocalServiceUtil.class.getName(),
111             "JournalFeed",
112             "id_"
113         },
114         new String[] {
115             JournalStructureLocalServiceUtil.class.getName(),
116             "JournalStructure",
117             "id_"
118         },
119         new String[] {
120             JournalTemplateLocalServiceUtil.class.getName(),
121             "JournalTemplate",
122             "id_"
123         }
124     };
125 
126 }