Liferay 启动过程分析14

在MainServlet中,当初始化resource actions之后,就开始初始化resource code ,这是由以下代码来完成的:if (_log.isDebugEnabled()) {             _log.debug("Initialize resource codes");         }          try {             initResourceCodes(portlets);         } .. 

它会去调用initResourceCodes方法:

protected void initResourceCodes(List<Portlet> portlets) throws Exception {         long[] companyIds = PortalInstances.getCompanyIdsBySQL();          Iterator<Portlet> itr = portlets.iterator();          while (itr.hasNext()) {             Portlet portlet = itr.next();              List<String> modelNames =                 ResourceActionsUtil.getPortletModelResources(                     portlet.getPortletId());              for (long companyId : companyIds) {                 ResourceCodeLocalServiceUtil.checkResourceCodes(                     companyId, portlet.getPortletId());                  for (String modelName : modelNames) {                     ResourceCodeLocalServiceUtil.checkResourceCodes(                         companyId, modelName);                 }             }         }     } 

我们逐行分析:

02行:

02行会发起一个数据库的查询,来获取Liferay实例对应的数据库中存放的所有company的id,这个方法在PortalInstances类中:

private long[] _getCompanyIdsBySQL() throws SQLException {         List<Long> companyIds = new ArrayList<Long>();          ...        try {             con = DataAccess.getConnection();              ps = con.prepareStatement(_GET_COMPANY_IDS);              rs = ps.executeQuery();              while (rs.next()) {                 long companyId = rs.getLong("companyId");                  companyIds.add(companyId);             }         }         finally {             DataAccess.cleanUp(con, ps, rs);         }          return ArrayUtil.toArray(             companyIds.toArray(new Long[companyIds.size()]));     } 

04-06行会迭代所有的portlet,对于每一个portlet:

09-11行:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/953a58e6fa9568dd2f863b2a32ed8dcc.html