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  
22  import java.sql.Types;
23  
24  /**
25   * <a href="JournalTemplatePKUpgradeColumnImpl.java.html"><b><i>View Source</i>
26   * </b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class JournalTemplatePKUpgradeColumnImpl extends PKUpgradeColumnImpl {
31  
32      public JournalTemplatePKUpgradeColumnImpl(
33          UpgradeColumn companyIdColumn, UpgradeColumn groupIdColumn) {
34  
35          super("id_", new Integer(Types.VARCHAR), false);
36  
37          _companyIdColumn = companyIdColumn;
38          _groupIdColumn = groupIdColumn;
39          _journalTemplateIdMapper = ValueMapperFactoryUtil.getValueMapper();
40      }
41  
42      public Object getNewValue(Object oldValue) throws Exception {
43          Object newValue = super.getNewValue(oldValue);
44  
45          String companyId = (String)_companyIdColumn.getOldValue();
46          Long groupId = (Long)_groupIdColumn.getOldValue();
47          String templateId = (String)oldValue;
48  
49          String oldIdValue =
50              "{companyId=" + companyId + ", groupId=" + groupId +
51                  ", templateId=" + templateId + "}";
52  
53          _journalTemplateIdMapper.mapValue(oldIdValue, newValue);
54  
55          return newValue;
56      }
57  
58      public ValueMapper getValueMapper() {
59          return _journalTemplateIdMapper;
60      }
61  
62      private UpgradeColumn _companyIdColumn;
63      private UpgradeColumn _groupIdColumn;
64      private ValueMapper _journalTemplateIdMapper;
65  
66  }