1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.upgrade.v5_2_3.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  /**
24   * <a href="ResourceDependencyManager.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class ResourceDependencyManager extends DependencyManager {
29  
30      public void update(
31              long oldPrimaryKeyValue, Object[] oldColumnValues,
32              Object[] oldExtraColumnValues, long newPrimaryKeyValue,
33              Object[] newColumnValues, Object[] newExtraColumnValues)
34          throws Exception {
35  
36          long resourceId = newPrimaryKeyValue;
37  
38          long permissionId = getPermissionId(resourceId);
39  
40          deleteDuplicateData("Permission_", resourceId);
41  
42          if (permissionId > 0) {
43              DependencyManager permissionDependencyManager =
44                  new PermissionDependencyManager();
45  
46              permissionDependencyManager.setPrimaryKeyName("permissionId");
47  
48              permissionDependencyManager.update(permissionId);
49          }
50      }
51  
52      protected long getPermissionId(long resourceId) throws Exception {
53          Connection con = null;
54          PreparedStatement ps = null;
55          ResultSet rs = null;
56  
57          try {
58              con = DataAccess.getConnection();
59  
60              ps = con.prepareStatement(
61                  "select permissionId from Permission_ where resourceId = ?");
62  
63              ps.setLong(1, resourceId);
64  
65              rs = ps.executeQuery();
66  
67              while (rs.next()) {
68                  long permissionId = rs.getLong("permissionId");
69  
70                  return permissionId;
71              }
72          }
73          finally {
74              DataAccess.cleanUp(con, ps, rs);
75          }
76  
77          return 0;
78      }
79  
80  }