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.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  }