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="ResourceCodeDependencyManager.java.html"><b><i>View Source</i></b>
25   * </a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class ResourceCodeDependencyManager extends DependencyManager {
30  
31      public void update(
32              long oldPrimaryKeyValue, Object[] oldColumnValues,
33              Object[] oldExtraColumnValues, long newPrimaryKeyValue,
34              Object[] newColumnValues, Object[] newExtraColumnValues)
35          throws Exception {
36  
37          long codeId = newPrimaryKeyValue;
38  
39          long resourceId = getResourceId(codeId);
40  
41          deleteDuplicateData("Resource_", codeId);
42  
43          if (resourceId > 0) {
44              DependencyManager resourceDependencyManager =
45                  new ResourceDependencyManager();
46  
47              resourceDependencyManager.setPrimaryKeyName("resourceId");
48  
49              resourceDependencyManager.update(resourceId);
50          }
51      }
52  
53      protected long getResourceId(long codeId) throws Exception {
54          Connection con = null;
55          PreparedStatement ps = null;
56          ResultSet rs = null;
57  
58          try {
59              con = DataAccess.getConnection();
60  
61              ps = con.prepareStatement(
62                  "select resourceId from Resource_ where codeId = ?");
63  
64              ps.setLong(1, codeId);
65  
66              rs = ps.executeQuery();
67  
68              while (rs.next()) {
69                  long resourceId = rs.getLong("resourceId");
70  
71                  return resourceId;
72              }
73          }
74          finally {
75              DataAccess.cleanUp(con, ps, rs);
76          }
77  
78          return 0;
79      }
80  
81  }