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;
22
23 import org.apache.commons.lang3.builder.ToStringBuilder;
24 import org.efaps.admin.datamodel.Attribute;
25 import org.efaps.admin.datamodel.Classification;
26 import org.efaps.admin.datamodel.Type;
27 import org.efaps.db.wrapper.SQLPart;
28 import org.efaps.db.wrapper.SQLSelect;
29 import org.efaps.util.EFapsException;
30 import org.efaps.util.cache.CacheReloadException;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37
38
39
40 public class ClassSelectPart
41 extends AbstractSelectPart
42 {
43
44
45
46 private static final Logger LOG = LoggerFactory.getLogger(OneSelect.class);
47
48
49
50
51 private final Classification classification;
52
53
54
55
56 private int tableIdx;
57
58
59
60
61
62 public ClassSelectPart(final String _classification)
63 throws CacheReloadException
64 {
65 this.classification = (Classification) Type.get(_classification);
66 }
67
68
69
70
71 @Override
72 public int join(final OneSelect _oneSelect,
73 final SQLSelect _select,
74 final int _relIndex)
75 throws EFapsException
76 {
77 Integer ret;
78 final String tableName = this.classification.getMainTable().getSqlTable();
79 final Attribute attr = this.classification.getAttribute(this.classification.getLinkAttributeName());
80 if (attr == null) {
81 ClassSelectPart.LOG.error("Could not find attribute: '{}'", this.classification.getLinkAttributeName());
82 throw new EFapsException(ClassSelectPart.class, "joinNoAttribute");
83 }
84 final String column = attr.getSqlColNames().get(0);
85 ret = _oneSelect.getTableIndex(tableName, column, _relIndex, this.classification.getId());
86 if (ret == null) {
87 ret = _oneSelect.getNewTableIndex(tableName, column, _relIndex, this.classification.getId());
88 _select.leftJoin(tableName, ret, column, _relIndex, "ID");
89 }
90 this.tableIdx = ret;
91 return ret;
92 }
93
94 @Override
95 public void add2Where(final OneSelect _oneselect,
96 final SQLSelect _select)
97 {
98 if (this.classification.getMainTable().getSqlColType() != null) {
99 _select.addPart(SQLPart.AND)
100 .addColumnPart(this.tableIdx, this.classification.getMainTable().getSqlColType())
101 .addPart(SQLPart.EQUAL)
102 .addValuePart(this.classification.getId());
103 }
104 }
105
106
107
108
109 @Override
110 public Type getType()
111 {
112 return this.classification;
113 }
114
115 @Override
116 public String toString()
117 {
118 return ToStringBuilder.reflectionToString(this);
119 }
120 }