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