001    /**
002     * Copyright (c) 2000-present 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.portlet.asset.service.AssetCategoryLocalServiceUtil;
019    
020    import java.sql.Connection;
021    import java.sql.PreparedStatement;
022    import java.sql.ResultSet;
023    
024    /**
025     * @author Douglas Wong
026     */
027    public class VerifyAsset extends VerifyProcess {
028    
029            @Override
030            protected void doVerify() throws Exception {
031                    rebuildTree();
032            }
033    
034            protected void rebuildTree() throws Exception {
035                    Connection con = null;
036                    PreparedStatement ps = null;
037                    ResultSet rs = null;
038    
039                    try {
040                            con = DataAccess.getUpgradeOptimizedConnection();
041    
042                            ps = con.prepareStatement(
043                                    "select distinct groupId from AssetCategory where " +
044                                            "(leftCategoryId is null) or (rightCategoryId is null)");
045    
046                            rs = ps.executeQuery();
047    
048                            while (rs.next()) {
049                                    long groupId = rs.getLong("groupId");
050    
051                                    AssetCategoryLocalServiceUtil.rebuildTree(groupId, true);
052                            }
053                    }
054                    finally {
055                            DataAccess.cleanUp(con, ps, rs);
056                    }
057            }
058    
059    }