1 /*
2 * Copyright 2003 - 2013 The eFaps Team
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.db.print.value;
22
23 import java.math.BigDecimal;
24
25 import org.efaps.admin.datamodel.Attribute;
26 import org.efaps.admin.datamodel.Type;
27 import org.efaps.db.print.OneSelect;
28 import org.efaps.db.wrapper.SQLSelect;
29 import org.efaps.util.EFapsException;
30
31 /**
32 * Class is used to select an id.
33 * Can be used directly or in conjunction with {@link TypeValueSelect}
34 * or Status.
35 *
36 * @author The eFaps Team
37 * @version $Id$
38 */
39 public class IDValueSelect
40 extends AbstractValueSelect
41 {
42 /**
43 * Attribute belonging to this IDValueSelect.
44 */
45 private Attribute attribute;
46
47 /**
48 * @param _oneSelect OneSelect
49 */
50 public IDValueSelect(final OneSelect _oneSelect)
51 {
52 super(_oneSelect);
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 @Override
59 public int append2SQLSelect(final Type _type,
60 final SQLSelect _select,
61 final int _tableIndex,
62 final int _colIndex)
63 {
64 int ret = 0;
65 if (getParent() == null || !"type".equals(getParent().getValueType())) {
66 _select.column(_tableIndex, "ID");
67 getColIndexs().add(_colIndex);
68 ret++;
69 this.attribute = _type.getAttribute("ID");
70 }
71 return ret;
72 }
73
74 @Override
75 public Object getValue(final Object _object)
76 throws EFapsException
77 {
78 Long tempId;
79 // check is necessary because Oracle JDBC returns for getObject always a BigDecimal
80 if (_object instanceof BigDecimal) {
81 tempId = ((BigDecimal) _object).longValue();
82 } else {
83 tempId = (Long) _object;
84 }
85 return tempId;
86 }
87
88 /**
89 * {@inheritDoc}
90 */
91 @Override
92 public Attribute getAttribute()
93 {
94 return this.attribute;
95 }
96
97 /**
98 * {@inheritDoc}
99 */
100 @Override
101 public String getValueType()
102 {
103 return "id";
104 }
105 }