001
014
015 package com.liferay.portal.upgrade.v5_2_5_to_6_0_0;
016
017 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018 import com.liferay.portal.kernel.util.LoggingTimer;
019 import com.liferay.portal.kernel.util.PortalUtil;
020
021 import java.sql.PreparedStatement;
022 import java.sql.ResultSet;
023
024
027 public class UpgradeGroup extends UpgradeProcess {
028
029 @Override
030 protected void doUpgrade() throws Exception {
031 updateParentGroupId();
032 }
033
034 protected Object[] getLayout(long plid) throws Exception {
035 try (PreparedStatement ps = connection.prepareStatement(_GET_LAYOUT)) {
036 ps.setLong(1, plid);
037
038 try (ResultSet rs = ps.executeQuery()) {
039 if (rs.next()) {
040 long groupId = rs.getLong("groupId");
041
042 return new Object[] {groupId};
043 }
044
045 return null;
046 }
047 }
048 }
049
050 protected void updateParentGroupId() throws Exception {
051 try (LoggingTimer loggingTimer = new LoggingTimer()) {
052 long classNameId = PortalUtil.getClassNameId(
053 "com.liferay.portal.model.Layout");
054
055 try (PreparedStatement ps = connection.prepareStatement(
056 "select groupId, classPK from Group_ where classNameId = " +
057 classNameId);
058 ResultSet rs = ps.executeQuery()) {
059
060 while (rs.next()) {
061 long groupId = rs.getLong("groupId");
062 long classPK = rs.getLong("classPK");
063
064 Object[] layout = getLayout(classPK);
065
066 if (layout != null) {
067 long layoutGroupId = (Long)layout[0];
068
069 runSQL(
070 "update Group_ set parentGroupId = " +
071 layoutGroupId + " where groupId = " + groupId);
072 }
073 }
074 }
075 }
076 }
077
078 private static final String _GET_LAYOUT =
079 "select groupId from Layout where plid = ?";
080
081 }