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