| ClassPKUpgradeColumnImpl.java |
1 /**
2 * Copyright (c) 2000-2009 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 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 * SOFTWARE.
18 */
19
20 package com.liferay.portal.upgrade.v4_3_0.util;
21
22 import com.liferay.portal.kernel.util.GetterUtil;
23 import com.liferay.portal.upgrade.util.TempUpgradeColumnImpl;
24 import com.liferay.portal.upgrade.util.ValueMapper;
25
26 import java.sql.Types;
27
28 import java.util.Map;
29
30 /**
31 * <a href="ClassPKUpgradeColumnImpl.java.html"><b><i>View Source</i></b></a>
32 *
33 * @author Brian Wing Shun Chan
34 *
35 */
36 public class ClassPKUpgradeColumnImpl extends TempUpgradeColumnImpl {
37
38 public ClassPKUpgradeColumnImpl(
39 ClassNameIdUpgradeColumnImpl classNameIdColumn,
40 Map<Long, ClassPKContainer> classPKContainers) {
41
42 super("classPK", new Integer(Types.VARCHAR));
43
44 _classNameIdColumn = classNameIdColumn;
45 _classPKContainers = classPKContainers;
46 }
47
48 public Integer getNewColumnType(Integer defaultType) {
49 return new Integer(Types.BIGINT);
50 }
51
52 public Object getNewValue(Object oldValue) throws Exception {
53 Long classNameId = (Long)_classNameIdColumn.getNewValue();
54
55 ClassPKContainer classPKContainer = _classPKContainers.get(classNameId);
56
57 if (classPKContainer != null) {
58 ValueMapper valueMapper = classPKContainer.getValueMapper();
59
60 if (classPKContainer.isLong()) {
61 return valueMapper.getNewValue(
62 new Long(GetterUtil.getLong((String)oldValue)));
63 }
64 else {
65 return valueMapper.getNewValue(oldValue);
66 }
67 }
68 else {
69 if (oldValue instanceof String) {
70 return new Long(GetterUtil.getLong((String)oldValue));
71 }
72 else {
73 return oldValue;
74 }
75 }
76 }
77
78 private ClassNameIdUpgradeColumnImpl _classNameIdColumn;
79 private Map<Long, ClassPKContainer> _classPKContainers;
80
81 }