1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.efaps.db.print.value;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.efaps.admin.datamodel.Attribute;
27 import org.efaps.admin.datamodel.Type;
28 import org.efaps.db.print.OneSelect;
29 import org.efaps.db.wrapper.SQLSelect;
30 import org.efaps.util.EFapsException;
31
32
33
34
35
36
37
38 public class OIDValueSelect
39 extends AbstractValueSelect
40 {
41
42
43
44 private Attribute attribute;
45
46
47
48
49 private Type type;
50
51
52
53
54 public OIDValueSelect(final OneSelect _oneSelect)
55 {
56 super(_oneSelect);
57 }
58
59
60
61
62 @Override
63 public int append2SQLSelect(final Type _type,
64 final SQLSelect _select,
65 final int _tableIndex,
66 final int _colIndex)
67 {
68 int ret = 0;
69 if (getParent() == null || !"type".equals(getParent().getValueType())) {
70 this.type = _type;
71 _select.column(_tableIndex, "ID");
72 getColIndexs().add(_colIndex);
73 ret++;
74 }
75
76 if (this.type != null) {
77 if (this.type.getMainTable().getSqlColType() != null) {
78 _select.column(_tableIndex, this.type.getMainTable().getSqlColType());
79 getColIndexs().add(_colIndex + ret);
80 ret++;
81 }
82 }
83 this.attribute = _type.getAttribute("OID");
84 return ret;
85 }
86
87
88
89
90 @Override
91 public Object getValue(final Object _object)
92 throws EFapsException
93 {
94 final StringBuilder bldr = new StringBuilder();
95 boolean retNull = false;
96 if (_object instanceof Object[]) {
97 final Object[] object = (Object[]) _object;
98 if (object[0] == null || object[1] == null) {
99 retNull = true;
100 } else {
101 bldr.append(object[1]).append(".").append(object[0]);
102 }
103 } else {
104 if (_object == null) {
105 retNull = true;
106 } else {
107 bldr.append(this.type.getId()).append(".").append(_object);
108 }
109 }
110 return retNull ? null : bldr.toString();
111 }
112
113
114
115
116 @Override
117 public Object getValue(final List<Object> _objectList)
118 throws EFapsException
119 {
120 final List<Object> ret = new ArrayList<Object>();
121 for (final Object object : _objectList) {
122 ret.add(getValue(object));
123 }
124 return _objectList.size() > 0 ? (ret.size() > 1 ? ret : ret.get(0)) : null;
125 }
126
127
128
129
130 @Override
131 public String getValueType()
132 {
133 return "oid";
134 }
135
136
137
138
139 @Override
140 public Attribute getAttribute()
141 {
142 return this.attribute;
143 }
144
145
146
147
148
149
150 public Type getType()
151 {
152 return this.type;
153 }
154
155
156
157
158
159
160
161 public void setType(final Type _type)
162 {
163 this.type = _type;
164 }
165 }