001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.verify;
016    
017    import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018    import com.liferay.portal.kernel.util.LongWrapper;
019    import com.liferay.portal.kernel.util.MethodInvoker;
020    import com.liferay.portal.kernel.util.MethodWrapper;
021    import com.liferay.portal.service.LayoutLocalServiceUtil;
022    import com.liferay.portlet.imagegallery.service.IGFolderLocalServiceUtil;
023    import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
024    import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
025    import com.liferay.portlet.journal.service.JournalFeedLocalServiceUtil;
026    import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
027    import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
028    import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
029    
030    import java.sql.Connection;
031    import java.sql.PreparedStatement;
032    import java.sql.ResultSet;
033    
034    /**
035     * @author Brian Wing Shun Chan
036     */
037    public class VerifyUUID extends VerifyProcess {
038    
039            public static void verifyModel(
040                            String serviceClassName, String modelName, String pkColumnName)
041                    throws Exception {
042    
043                    Connection con = null;
044                    PreparedStatement ps = null;
045                    ResultSet rs = null;
046    
047                    try {
048                            con = DataAccess.getConnection();
049    
050                            ps = con.prepareStatement(
051                                    "select " + pkColumnName + " from " + modelName +
052                                            " where uuid_ is null or uuid_ = ''");
053    
054                            rs = ps.executeQuery();
055    
056                            while (rs.next()) {
057                                    long pk = rs.getLong(pkColumnName);
058    
059                                    verifyModel(serviceClassName, modelName, pk);
060                            }
061                    }
062                    finally {
063                            DataAccess.cleanUp(con, ps, rs);
064                    }
065            }
066    
067            public static void verifyModel(
068                            String serviceClassName, String modelName, long pk)
069                    throws Exception {
070    
071                    Object obj = MethodInvoker.invoke(
072                            new MethodWrapper(
073                                    serviceClassName, "get" + modelName, new LongWrapper(pk)));
074    
075                    MethodInvoker.invoke(
076                            new MethodWrapper(serviceClassName, "update" + modelName, obj));
077            }
078    
079            protected void doVerify() throws Exception {
080                    for (String[] model : _MODELS) {
081                            verifyModel(model[0], model[1], model[2]);
082                    }
083            }
084    
085            private static final String[][] _MODELS = new String[][] {
086                    new String[] {
087                            IGFolderLocalServiceUtil.class.getName(),
088                            "IGFolder",
089                            "folderId"
090                    },
091                    new String[] {
092                            IGImageLocalServiceUtil.class.getName(),
093                            "IGImage",
094                            "imageId"
095                    },
096                    new String[] {
097                            JournalArticleLocalServiceUtil.class.getName(),
098                            "JournalArticle",
099                            "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                    new String[] {
117                            LayoutLocalServiceUtil.class.getName(),
118                            "Layout",
119                            "plid"
120                    },
121                    new String[] {
122                            WikiPageResourceLocalServiceUtil.class.getName(),
123                            "WikiPageResource",
124                            "resourcePrimKey"
125                    }
126            };
127    
128    }