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
027 public class MBDiscussionDependencyManager extends DependencyManager {
028
029 @Override
030 public void update(
031 long oldPrimaryKeyValue, Object[] oldColumnValues,
032 Object[] oldExtraColumnValues, long newPrimaryKeyValue,
033 Object[] newColumnValues, Object[] newExtraColumnValues)
034 throws Exception {
035
036 long threadId = 0;
037
038 for (int i = 0; i < columns.length; i++) {
039 if (columns[i][0].equals("threadId")) {
040 threadId = (Long)newColumnValues[i];
041 }
042 }
043
044 if ((threadId == 0) && (extraColumns != null)) {
045 for (int i = 0; i < extraColumns.length; i++) {
046 if (extraColumns[i][0].equals("threadId")) {
047 threadId = (Long)newExtraColumnValues[i];
048 }
049 }
050 }
051
052 if (isDuplicateThread(threadId)) {
053 deleteDuplicateData("MBMessage", "threadId", threadId);
054 deleteDuplicateData("MBMessageFlag", "threadId", threadId);
055 deleteDuplicateData("MBThread", "threadId", threadId);
056 }
057 }
058
059 protected boolean isDuplicateThread(long threadId) throws Exception {
060 Connection con = null;
061 PreparedStatement ps = null;
062 ResultSet rs = null;
063
064 try {
065 con = DataAccess.getUpgradeOptimizedConnection();
066
067 ps = con.prepareStatement(
068 "select count(*) from MBDiscussion where threadId = ?");
069
070 ps.setLong(1, threadId);
071
072 rs = ps.executeQuery();
073
074 while (rs.next()) {
075 int count = rs.getInt(1);
076
077 if (count > 0) {
078 return false;
079 }
080 }
081
082 return true;
083 }
084 finally {
085 DataAccess.cleanUp(con, ps, rs);
086 }
087 }
088
089 }