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