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.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  }