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.search.value;
23
24 import org.efaps.admin.datamodel.Status;
25 import org.efaps.db.AbstractObjectQuery;
26 import org.efaps.db.Context;
27 import org.efaps.db.Instance;
28 import org.efaps.db.search.AbstractQPart;
29 import org.efaps.db.search.compare.AbstractQAttrCompare;
30 import org.efaps.db.search.compare.QEqual;
31 import org.efaps.db.search.compare.QMatch;
32 import org.efaps.db.wrapper.SQLSelect;
33 import org.efaps.util.EFapsException;
34
35
36
37
38
39
40
41 public class QStringValue
42 extends AbstractQValue
43 {
44
45
46
47 private boolean noEscape = false;
48
49
50
51
52 private String value;
53
54
55
56
57 public QStringValue(final String _value)
58 {
59 this.value = _value;
60 }
61
62
63
64
65
66 @Override
67 public QStringValue prepare(final AbstractObjectQuery<?> _query,
68 final AbstractQPart _part)
69 throws EFapsException
70 {
71 if (_part instanceof AbstractQAttrCompare) {
72 if (((AbstractQAttrCompare) _part).isIgnoreCase()) {
73 this.value = this.value.toUpperCase(Context.getThreadContext().getLocale());
74 }
75 if (_part instanceof QMatch) {
76 this.value = Context.getDbType().prepare4Match(this.value);
77 }
78 if (_part instanceof QEqual && ((QEqual) _part).getAttribute().getAttribute() != null) {
79
80
81 if (((QEqual) _part).getAttribute().getAttribute().getParent().isCheckStatus()
82 && ((QEqual) _part).getAttribute().getAttribute().equals(
83 ((QEqual) _part).getAttribute().getAttribute().getParent().getStatusAttribute())) {
84 final Status status = Status.find(
85 ((QEqual) _part).getAttribute().getAttribute().getLink().getUUID(), this.value);
86 if (status != null) {
87 this.value = Long.valueOf(status.getId()).toString();
88 this.noEscape = true;
89 }
90
91 } else if (((QEqual) _part).getAttribute().getAttribute().hasLink()) {
92 final Instance insTmp = Instance.get(this.value);
93 if (insTmp.isValid()) {
94 this.value = Long.valueOf(insTmp.getId()).toString();
95 this.noEscape = true;
96 }
97 }
98 }
99 }
100 return this;
101 }
102
103
104
105
106 @Override
107 public QStringValue appendSQL(final SQLSelect _sql)
108 {
109 if (this.noEscape) {
110 _sql.addValuePart(this.value);
111 } else {
112 _sql.addEscapedValuePart(this.value);
113 }
114 return this;
115 }
116 }