1
22
23 package com.liferay.portal.upgrade.v5_2_6;
24
25 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
26 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
27 import com.liferay.portal.model.Layout;
28 import com.liferay.portal.util.PortalUtil;
29
30 import java.sql.Connection;
31 import java.sql.PreparedStatement;
32 import java.sql.ResultSet;
33
34
39 public class UpgradeGroup extends UpgradeProcess {
40
41 protected void doUpgrade() throws Exception {
42 updateParentGroupId();
43 }
44
45 protected Object[] getLayout(long plid) throws Exception {
46 Object[] layout = null;
47
48 Connection con = null;
49 PreparedStatement ps = null;
50 ResultSet rs = null;
51
52 try {
53 con = DataAccess.getConnection();
54
55 ps = con.prepareStatement(_GET_LAYOUT);
56
57 ps.setLong(1, plid);
58
59 rs = ps.executeQuery();
60
61 while (rs.next()) {
62 long groupId = rs.getLong("groupId");
63
64 layout = new Object[] {groupId};
65 }
66 }
67 finally {
68 DataAccess.cleanUp(con, ps, rs);
69 }
70
71 return layout;
72 }
73
74 protected void updateParentGroupId() throws Exception {
75 Connection con = null;
76 PreparedStatement ps = null;
77 ResultSet rs = null;
78
79 try {
80 con = DataAccess.getConnection();
81
82 long classNameId = PortalUtil.getClassNameId(
83 Layout.class.getName());
84
85 ps = con.prepareStatement(
86 "select groupId, classPK from Group_ where classNameId = " +
87 classNameId);
88
89 rs = ps.executeQuery();
90
91 while (rs.next()) {
92 long groupId = rs.getLong("groupId");
93 long classPK = rs.getLong("classPK");
94
95 Object[] layout = getLayout(classPK);
96
97 if (layout != null) {
98 long layoutGroupId = (Long)layout[0];
99
100 runSQL(
101 "update Group_ set parentGroupId = " + layoutGroupId +
102 " where groupId = " + groupId);
103 }
104 }
105 }
106 finally {
107 DataAccess.cleanUp(con, ps, rs);
108 }
109 }
110
111 private static final String _GET_LAYOUT =
112 "select groupId from Layout where plid = ?";
113
114 }