1
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
30 public class MBDiscussionDependencyManager extends DependencyManager {
31
32 public void update(
33 long oldPrimaryKeyValue, Object[] oldColumnValues,
34 Object[] oldExtraColumnValues, long newPrimaryKeyValue,
35 Object[] newColumnValues, Object[] newExtraColumnValues)
36 throws Exception {
37
38 long threadId = 0;
39
40 for (int i = 0; i < columns.length; i++) {
41 if (columns[i][0].equals("threadId")) {
42 threadId = (Long)newColumnValues[i];
43 }
44 }
45
46 if ((threadId == 0) && (extraColumns != null)) {
47 for (int i = 0; i < extraColumns.length; i++) {
48 if (extraColumns[i][0].equals("threadId")) {
49 threadId = (Long)newExtraColumnValues[i];
50 }
51 }
52 }
53
54 if (isDuplicateThread(threadId)) {
55 deleteDuplicateData("MBMessage", "threadId", threadId);
56 deleteDuplicateData("MBMessageFlag", "threadId", threadId);
57 deleteDuplicateData("MBThread", "threadId", threadId);
58 }
59 }
60
61 protected boolean isDuplicateThread(long threadId) throws Exception {
62 Connection con = null;
63 PreparedStatement ps = null;
64 ResultSet rs = null;
65
66 try {
67 con = DataAccess.getConnection();
68
69 ps = con.prepareStatement(
70 "select count(*) from MBDiscussion where threadId = ?");
71
72 ps.setLong(1, threadId);
73
74 rs = ps.executeQuery();
75
76 while (rs.next()) {
77 long count = rs.getLong(1);
78
79 if (count > 0) {
80 return false;
81 }
82 }
83
84 return true;
85 }
86 finally {
87 DataAccess.cleanUp(con, ps, rs);
88 }
89 }
90
91 }