1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.upgrade.v4_3_0.util;
16  
17  import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
18  import com.liferay.portal.kernel.upgrade.util.ValueMapper;
19  import com.liferay.portal.kernel.upgrade.util.ValueMapperFactoryUtil;
20  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
21  import com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil;
22  
23  import java.sql.Types;
24  
25  /**
26   * <a href="JournalArticlePKUpgradeColumnImpl.java.html"><b><i>View Source</i>
27   * </b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class JournalArticlePKUpgradeColumnImpl extends PKUpgradeColumnImpl {
32  
33      public JournalArticlePKUpgradeColumnImpl(
34          UpgradeColumn companyIdColumn, UpgradeColumn groupIdColumn) {
35  
36          super("id_", new Integer(Types.VARCHAR), false);
37  
38          _companyIdColumn = companyIdColumn;
39          _groupIdColumn = groupIdColumn;
40          _journalArticleIdMapper = ValueMapperFactoryUtil.getValueMapper();
41      }
42  
43      public Object getNewValue(Object oldValue) throws Exception {
44          _resourcePrimKey = null;
45  
46          Object newValue = super.getNewValue(oldValue);
47  
48          String companyId = (String)_companyIdColumn.getOldValue();
49          Long oldGroupId = (Long)_groupIdColumn.getOldValue();
50          Long newGroupId = (Long)_groupIdColumn.getNewValue();
51          String articleId = (String)oldValue;
52  
53          String oldIdValue =
54              "{companyId=" + companyId + ", groupId=" + oldGroupId +
55                  ", articleId=" + articleId + ", version=1.0}";
56  
57          _resourcePrimKey = new Long(JournalArticleResourceLocalServiceUtil.
58              getArticleResourcePrimKey(newGroupId.longValue(), articleId));
59  
60          _journalArticleIdMapper.mapValue(oldIdValue, _resourcePrimKey);
61  
62          return newValue;
63      }
64  
65      public ValueMapper getValueMapper() {
66          return _journalArticleIdMapper;
67      }
68  
69      public Long getResourcePrimKey() {
70          return _resourcePrimKey;
71      }
72  
73      private UpgradeColumn _companyIdColumn;
74      private UpgradeColumn _groupIdColumn;
75      private ValueMapper _journalArticleIdMapper;
76      private Long _resourcePrimKey;
77  
78  }