1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.efaps.db;
23
24 import java.util.UUID;
25
26 import org.efaps.admin.datamodel.Type;
27 import org.efaps.ci.CIAttribute;
28 import org.efaps.ci.CIType;
29 import org.efaps.util.cache.CacheReloadException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38
39
40
41 public class SelectBuilder
42 {
43
44
45
46 private static final Logger LOG = LoggerFactory.getLogger(SelectBuilder.class);
47
48
49
50
51 private final StringBuilder bldr = new StringBuilder();
52
53
54
55
56 public SelectBuilder()
57 {
58 }
59
60
61
62
63
64 public SelectBuilder(final SelectBuilder _selectBuilder)
65 {
66 this.bldr.append(_selectBuilder.toString());
67 }
68
69
70
71
72
73 public SelectBuilder(final String _select)
74 {
75 this.bldr.append(_select);
76 }
77
78
79
80
81
82 public SelectBuilder linkto(final CIAttribute _attribute)
83 {
84 return linkto(_attribute.name);
85 }
86
87
88
89
90
91 public SelectBuilder linkto(final String _attribute)
92 {
93 addPoint();
94 this.bldr.append("linkto[").append(_attribute).append("]");
95 return this;
96 }
97
98
99
100
101
102 public SelectBuilder linkfrom(final CIAttribute _attribute)
103 {
104 return linkfrom(_attribute.ciType, _attribute);
105 }
106
107
108
109
110
111
112 public SelectBuilder linkfrom(final CIType _type,
113 final CIAttribute _attribute)
114 {
115 return linkfrom(_type.getType().getName(), _attribute.name);
116 }
117
118
119
120
121
122
123 public SelectBuilder linkfrom(final UUID _typeUUID,
124 final CIAttribute _attribute)
125 {
126 String typeName = "";
127 try {
128 typeName = Type.get(_typeUUID).getName();
129 } catch (final CacheReloadException e) {
130 SelectBuilder.LOG.error("Could not read type from Cache for uuid: {}", _typeUUID);
131 }
132 return linkfrom(typeName, _attribute.name);
133 }
134
135
136
137
138
139
140 public SelectBuilder linkfrom(final String _type,
141 final String _attribute)
142 {
143 addPoint();
144 this.bldr.append("linkfrom[").append(_type).append("#").append(_attribute).append("]");
145 return this;
146 }
147
148
149
150
151
152 public SelectBuilder attribute(final CIAttribute _attribute)
153 {
154 return attribute(_attribute.name);
155 }
156
157
158
159
160
161 public SelectBuilder attribute(final String _attribute)
162 {
163 addPoint();
164 this.bldr.append("attribute[").append(_attribute).append("]");
165 return this;
166 }
167
168
169
170
171
172 private void addPoint()
173 {
174 if (this.bldr.length() > 0) {
175 this.bldr.append(".");
176 }
177 }
178
179
180
181
182
183
184 public SelectBuilder oid()
185 {
186 addPoint();
187 this.bldr.append("oid");
188 return this;
189 }
190
191
192
193
194
195
196 public SelectBuilder instance()
197 {
198 addPoint();
199 this.bldr.append("instance");
200 return this;
201 }
202
203
204
205
206
207
208 public SelectBuilder type()
209 {
210 addPoint();
211 this.bldr.append("type");
212 return this;
213 }
214
215
216
217
218
219
220 public SelectBuilder value()
221 {
222 addPoint();
223 this.bldr.append("value");
224 return this;
225 }
226
227
228
229
230
231
232 public SelectBuilder label()
233 {
234 addPoint();
235 this.bldr.append("label");
236 return this;
237 }
238
239
240
241
242
243
244 public SelectBuilder id()
245 {
246 addPoint();
247 this.bldr.append("id");
248 return this;
249 }
250
251
252
253
254
255
256 public SelectBuilder uuid()
257 {
258 addPoint();
259 this.bldr.append("uuid");
260 return this;
261 }
262
263
264
265
266
267
268 public SelectBuilder name()
269 {
270 addPoint();
271 this.bldr.append("name");
272 return this;
273 }
274
275
276
277
278
279
280 public SelectBuilder key()
281 {
282 addPoint();
283 this.bldr.append("key");
284 return this;
285 }
286
287
288
289
290
291
292 public SelectBuilder status()
293 {
294 addPoint();
295 this.bldr.append("status");
296 return this;
297 }
298
299
300
301
302
303 public SelectBuilder file()
304 {
305 addPoint();
306 this.bldr.append("file");
307 return this;
308 }
309
310
311
312
313
314
315 public SelectBuilder length()
316 {
317 addPoint();
318 this.bldr.append("length");
319 return this;
320 }
321
322
323
324
325
326
327 public SelectBuilder base()
328 {
329 addPoint();
330 this.bldr.append("base");
331 return this;
332 }
333
334
335
336
337
338
339 public SelectBuilder uom()
340 {
341 addPoint();
342 this.bldr.append("uom");
343 return this;
344 }
345
346
347
348
349
350
351 public SelectBuilder clazz()
352 {
353 addPoint();
354 this.bldr.append("class");
355 return this;
356 }
357
358
359
360
361
362 public SelectBuilder clazz(final CIType _class)
363 {
364 return clazz(_class.getType().getName());
365 }
366
367
368
369
370
371 public SelectBuilder clazz(final UUID _typeUUID)
372 {
373 String typeName = "";
374 try {
375 typeName = Type.get(_typeUUID).getName();
376 } catch (final CacheReloadException e) {
377 SelectBuilder.LOG.error("Could not read type from Cache for uuid: {}", _typeUUID);
378 }
379 return clazz(typeName);
380 }
381
382
383
384
385
386 public SelectBuilder clazz(final String _class)
387 {
388 addPoint();
389 this.bldr.append("class[").append(_class).append("]");
390 return this;
391 }
392
393
394
395
396
397 public SelectBuilder attributeset(final CIAttribute _attribute)
398 {
399 return attributeset(_attribute.name);
400 }
401
402
403
404
405
406 public SelectBuilder attributeset(final String _attribute)
407 {
408 addPoint();
409 this.bldr.append("attributeset[").append(_attribute).append("]");
410 return this;
411 }
412
413
414
415
416
417
418
419 public SelectBuilder format(final String _pattern)
420 {
421 addPoint();
422 this.bldr.append("format[").append(_pattern).append("]");
423 return this;
424 }
425
426
427
428
429 public static SelectBuilder get()
430 {
431 return new SelectBuilder();
432 }
433
434
435
436
437
438 @Override
439 public String toString()
440 {
441 return this.bldr.toString();
442 }
443
444 }