1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.upgrade.util;
16  
17  import com.liferay.portal.kernel.upgrade.util.BaseUpgradeColumnImpl;
18  import com.liferay.portal.kernel.upgrade.util.ValueMapper;
19  import com.liferay.portal.kernel.upgrade.util.ValueMapperFactoryUtil;
20  
21  import java.sql.Types;
22  
23  /**
24   * <a href="PKUpgradeColumnImpl.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   * @author Alexander Chow
28   */
29  public class PKUpgradeColumnImpl extends BaseUpgradeColumnImpl {
30  
31      public PKUpgradeColumnImpl(String name, boolean trackValues) {
32          this(name, null, trackValues);
33      }
34  
35      public PKUpgradeColumnImpl(
36          String name, Integer oldColumnType, boolean trackValues) {
37  
38          super(name, oldColumnType);
39  
40          _newColumnType = new Integer(Types.BIGINT);
41          _trackValues = trackValues;
42  
43          if (_trackValues) {
44              _valueMapper = ValueMapperFactoryUtil.getValueMapper();
45          }
46      }
47  
48      public Integer getNewColumnType(Integer defaultType) {
49          return _newColumnType;
50      }
51  
52      public Object getNewValue(Object oldValue) throws Exception {
53          Long newValue = new Long(increment());
54  
55          if (_trackValues) {
56              _valueMapper.mapValue(oldValue, newValue);
57          }
58  
59          return newValue;
60      }
61  
62      public boolean isTrackValues() {
63          return _trackValues;
64      }
65  
66      public ValueMapper getValueMapper() {
67          return _valueMapper;
68      }
69  
70      private Integer _newColumnType;
71      private boolean _trackValues;
72      private ValueMapper _valueMapper;
73  
74  }