1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.upgrade.v4_3_0.util;
16  
17  import com.liferay.portal.kernel.dao.jdbc.DataAccess;
18  
19  import java.sql.Connection;
20  import java.sql.PreparedStatement;
21  import java.sql.ResultSet;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  /**
27   * <a href="WebIdUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class WebIdUtil {
32  
33      public static String[] getWebIds() throws Exception {
34          if (_webIds != null) {
35              return _webIds;
36          }
37  
38          List<String> webIds = new ArrayList<String>();
39  
40          Connection con = null;
41          PreparedStatement ps = null;
42          ResultSet rs = null;
43  
44          try {
45              con = DataAccess.getConnection();
46  
47              ps = con.prepareStatement(_GET_WEB_IDS);
48  
49              rs = ps.executeQuery();
50  
51              while (rs.next()) {
52                  String companyId = rs.getString("companyId");
53  
54                  webIds.add(companyId);
55              }
56          }
57          finally {
58              DataAccess.cleanUp(con, ps, rs);
59          }
60  
61          _webIds = webIds.toArray(new String[webIds.size()]);
62  
63          return _webIds;
64      }
65  
66      private static final String _GET_WEB_IDS = "select companyId from Company";
67  
68      private static String[] _webIds;
69  
70  }