1
14
15 package com.liferay.portal.upgrade.v5_2_3.util;
16
17 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
18 import com.liferay.portal.kernel.util.StringBundler;
19
20 import java.sql.Connection;
21 import java.sql.PreparedStatement;
22
23
28 public abstract class DependencyManager {
29
30 public void setColumns(Object[][] columns) {
31 this.columns = columns;
32 }
33
34 public void setExtraColumns(Object[][] extraColumns) {
35 this.extraColumns = extraColumns;
36 }
37
38 public void setPrimaryKeyName(String primaryKeyName) {
39 this.primaryKeyName = primaryKeyName;
40 }
41
42 public void setTableName(String tableName) {
43 this.tableName = tableName;
44 }
45
46 public void update(long newPrimaryKeyValue) throws Exception {
47 update(0, null, null, newPrimaryKeyValue, null, null);
48 }
49
50 public abstract void update(
51 long oldPrimaryKeyValue, Object[] oldColumnValues,
52 Object[] oldExtraColumnValues, long newPrimaryKeyValue,
53 Object[] newColumnValues, Object[] newExtraColumnValues)
54 throws Exception;
55
56 protected void deleteDuplicateData(String tableName, long primaryKeyValue)
57 throws Exception {
58
59 deleteDuplicateData(tableName, primaryKeyName, primaryKeyValue);
60 }
61
62 protected void deleteDuplicateData(
63 String tableName, String columnName, long columnValue)
64 throws Exception {
65
66 Connection con = null;
67 PreparedStatement ps = null;
68
69 try {
70 con = DataAccess.getConnection();
71
72 StringBundler sb = new StringBundler(5);
73
74 sb.append("delete from ");
75 sb.append(tableName);
76 sb.append(" where ");
77 sb.append(columnName);
78 sb.append(" = ?");
79
80 String sql = sb.toString();
81
82 ps = con.prepareStatement(sql);
83
84 ps.setLong(1, columnValue);
85
86 ps.executeUpdate();
87 }
88 finally {
89 DataAccess.cleanUp(con, ps);
90 }
91 }
92
93 protected void updateDuplicateData(
94 String tableName, long oldPrimaryKeyValue, long newPrimaryKeyValue)
95 throws Exception {
96
97 updateDuplicateData(
98 tableName, primaryKeyName, oldPrimaryKeyValue, newPrimaryKeyValue);
99 }
100
101 protected void updateDuplicateData(
102 String tableName, String columnName, long oldColumnValue,
103 long newColumnValue)
104 throws Exception {
105
106 Connection con = null;
107 PreparedStatement ps = null;
108
109 try {
110 con = DataAccess.getConnection();
111
112 StringBundler sb = new StringBundler(7);
113
114 sb.append("update ");
115 sb.append(tableName);
116 sb.append(" set ");
117 sb.append(columnName);
118 sb.append(" = ? where ");
119 sb.append(columnName);
120 sb.append(" = ?");
121
122 String sql = sb.toString();
123
124 ps = con.prepareStatement(sql);
125
126 ps.setLong(1, newColumnValue);
127 ps.setLong(2, oldColumnValue);
128
129 ps.executeUpdate();
130 }
131 finally {
132 DataAccess.cleanUp(con, ps);
133 }
134 }
135
136 protected Object[][] columns;
137 protected Object[][] extraColumns;
138 protected String primaryKeyName;
139 protected String tableName;
140
141 }