001
014
015 package com.liferay.portal.upgrade.v5_1_5.util;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018
019 import java.sql.Connection;
020 import java.sql.PreparedStatement;
021 import java.sql.ResultSet;
022
023
026 public class ResourceCodeDependencyManager extends DependencyManager {
027
028 @Override
029 public void update(
030 long oldPrimaryKeyValue, Object[] oldColumnValues,
031 Object[] oldExtraColumnValues, long newPrimaryKeyValue,
032 Object[] newColumnValues, Object[] newExtraColumnValues)
033 throws Exception {
034
035 long codeId = newPrimaryKeyValue;
036
037 long resourceId = getResourceId(codeId);
038
039 deleteDuplicateData("Resource_", codeId);
040
041 if (resourceId > 0) {
042 DependencyManager resourceDependencyManager =
043 new ResourceDependencyManager();
044
045 resourceDependencyManager.setPrimaryKeyName("resourceId");
046
047 resourceDependencyManager.update(resourceId);
048 }
049 }
050
051 protected long getResourceId(long codeId) throws Exception {
052 Connection con = null;
053 PreparedStatement ps = null;
054 ResultSet rs = null;
055
056 try {
057 con = DataAccess.getUpgradeOptimizedConnection();
058
059 ps = con.prepareStatement(
060 "select resourceId from Resource_ where codeId = ?");
061
062 ps.setLong(1, codeId);
063
064 rs = ps.executeQuery();
065
066 while (rs.next()) {
067 long resourceId = rs.getLong("resourceId");
068
069 return resourceId;
070 }
071 }
072 finally {
073 DataAccess.cleanUp(con, ps, rs);
074 }
075
076 return 0;
077 }
078
079 }