001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.upgrade.v4_3_0.util;
016    
017    import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018    
019    import java.sql.Connection;
020    import java.sql.PreparedStatement;
021    import java.sql.ResultSet;
022    
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class WebIdUtil {
030    
031            public static String[] getWebIds() throws Exception {
032                    if (_webIds != null) {
033                            return _webIds;
034                    }
035    
036                    List<String> webIds = new ArrayList<String>();
037    
038                    Connection con = null;
039                    PreparedStatement ps = null;
040                    ResultSet rs = null;
041    
042                    try {
043                            con = DataAccess.getConnection();
044    
045                            ps = con.prepareStatement(_GET_WEB_IDS);
046    
047                            rs = ps.executeQuery();
048    
049                            while (rs.next()) {
050                                    String companyId = rs.getString("companyId");
051    
052                                    webIds.add(companyId);
053                            }
054                    }
055                    finally {
056                            DataAccess.cleanUp(con, ps, rs);
057                    }
058    
059                    _webIds = webIds.toArray(new String[webIds.size()]);
060    
061                    return _webIds;
062            }
063    
064            private static final String _GET_WEB_IDS = "select companyId from Company";
065    
066            private static String[] _webIds;
067    
068    }