001
014
015 package com.liferay.portal.upgrade.v6_0_0;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
019 import com.liferay.portal.kernel.util.PortalUtil;
020
021 import java.sql.Connection;
022 import java.sql.PreparedStatement;
023 import java.sql.ResultSet;
024
025
028 public class UpgradeGroup extends UpgradeProcess {
029
030 @Override
031 protected void doUpgrade() throws Exception {
032 updateParentGroupId();
033 }
034
035 protected Object[] getLayout(long plid) throws Exception {
036 Connection con = null;
037 PreparedStatement ps = null;
038 ResultSet rs = null;
039
040 try {
041 con = DataAccess.getUpgradeOptimizedConnection();
042
043 ps = con.prepareStatement(_GET_LAYOUT);
044
045 ps.setLong(1, plid);
046
047 rs = ps.executeQuery();
048
049 if (rs.next()) {
050 long groupId = rs.getLong("groupId");
051
052 return new Object[] {groupId};
053 }
054
055 return null;
056 }
057 finally {
058 DataAccess.cleanUp(con, ps, rs);
059 }
060 }
061
062 protected void updateParentGroupId() throws Exception {
063 Connection con = null;
064 PreparedStatement ps = null;
065 ResultSet rs = null;
066
067 try {
068 con = DataAccess.getUpgradeOptimizedConnection();
069
070 long classNameId = PortalUtil.getClassNameId(
071 "com.liferay.portal.model.Layout");
072
073 ps = con.prepareStatement(
074 "select groupId, classPK from Group_ where classNameId = " +
075 classNameId);
076
077 rs = ps.executeQuery();
078
079 while (rs.next()) {
080 long groupId = rs.getLong("groupId");
081 long classPK = rs.getLong("classPK");
082
083 Object[] layout = getLayout(classPK);
084
085 if (layout != null) {
086 long layoutGroupId = (Long)layout[0];
087
088 runSQL(
089 "update Group_ set parentGroupId = " + layoutGroupId +
090 " where groupId = " + groupId);
091 }
092 }
093 }
094 finally {
095 DataAccess.cleanUp(con, ps, rs);
096 }
097 }
098
099 private static final String _GET_LAYOUT =
100 "select * from Layout where plid = ?";
101
102 }