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
22 package org.efaps.db.print.value;
23
24 import java.math.BigDecimal;
25
26 import org.efaps.admin.datamodel.Type;
27 import org.efaps.db.print.OneSelect;
28 import org.efaps.db.store.AbstractStoreResource;
29 import org.efaps.db.wrapper.SQLSelect;
30 import org.efaps.util.EFapsException;
31
32
33 /**
34 * ValueSelct to select the length value from a store instance.
35 *
36 * @author The eFaps Team
37 * @version $Id$
38 */
39 public class LengthValueSelect
40 extends AbstractValueSelect
41 {
42 /**
43 * Constructor setting the OneSelect this LengthValueSelect belongs to.
44 *
45 * @param _oneSelect OneSelect
46 */
47 public LengthValueSelect(final OneSelect _oneSelect)
48 {
49 super(_oneSelect);
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 @Override
56 public int append2SQLSelect(final Type _type,
57 final SQLSelect _select,
58 final int _tableIndex,
59 final int _colIndex)
60 {
61 _select.column(_tableIndex, AbstractStoreResource.COLNAME_FILELENGTH);
62 getColIndexs().add(_colIndex);
63 return 1;
64 }
65
66 /**
67 * {@inheritDoc}
68 */
69 @Override
70 public String getValueType()
71 {
72 return "length";
73 }
74
75 @Override
76 public Object getValue(final Object _object)
77 throws EFapsException
78 {
79 Object tempId;
80 // check is necessary because Oracle JDBC returns for getObject always a BigDecimal
81 if (_object instanceof BigDecimal) {
82 tempId = ((BigDecimal) _object).longValue();
83 } else {
84 tempId = _object;
85 }
86 return tempId;
87 }
88 }