181 |
ilm |
1 |
package org.openconcerto.modules.common.batchprocessing;
|
|
|
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
|
|
5 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
6 |
import org.openconcerto.sql.element.SQLElementDirectory;
|
|
|
7 |
import org.openconcerto.sql.model.SQLField;
|
|
|
8 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
9 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
10 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
|
|
11 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
12 |
import org.openconcerto.sql.model.Where;
|
|
|
13 |
import org.openconcerto.sql.request.SQLFieldTranslator;
|
|
|
14 |
|
|
|
15 |
public class BatchField {
|
|
|
16 |
|
|
|
17 |
private final SQLField field;
|
|
|
18 |
private final SQLRowAccessor foreignLinkRow;
|
|
|
19 |
private final SQLFieldTranslator translator;
|
|
|
20 |
private final SQLElement elementLink;
|
183 |
ilm |
21 |
private final SQLElementDirectory dir;
|
181 |
ilm |
22 |
|
|
|
23 |
public BatchField(SQLElementDirectory dir, SQLField field, SQLRowAccessor foreignLinkRow) {
|
|
|
24 |
this.field = field;
|
183 |
ilm |
25 |
this.dir = dir;
|
181 |
ilm |
26 |
this.foreignLinkRow = foreignLinkRow;
|
|
|
27 |
|
|
|
28 |
this.translator = dir.getTranslator();
|
|
|
29 |
if (foreignLinkRow == null) {
|
|
|
30 |
this.elementLink = null;
|
|
|
31 |
} else {
|
|
|
32 |
this.elementLink = dir.getElement(foreignLinkRow.getTable());
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
183 |
ilm |
36 |
private SQLField fieldToMatch;
|
|
|
37 |
private Object matchingValue;
|
|
|
38 |
|
|
|
39 |
public void setDefaultMatchingValue(SQLField fieldToMatch, Object value) {
|
|
|
40 |
this.fieldToMatch = fieldToMatch;
|
|
|
41 |
this.matchingValue = value;
|
|
|
42 |
}
|
|
|
43 |
|
181 |
ilm |
44 |
public SQLField getField() {
|
|
|
45 |
return field;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public SQLRowAccessor getForeignLinkRow() {
|
|
|
49 |
return foreignLinkRow;
|
|
|
50 |
}
|
183 |
ilm |
51 |
|
|
|
52 |
public SQLField getFieldToMatch() {
|
|
|
53 |
return fieldToMatch;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
public Object getMatchingValue() {
|
|
|
57 |
return matchingValue;
|
|
|
58 |
}
|
181 |
ilm |
59 |
|
|
|
60 |
public String getComboName() {
|
183 |
ilm |
61 |
if (this.fieldToMatch != null) {
|
|
|
62 |
return this.dir.getElement(this.fieldToMatch.getTable()).getPluralName() + " " + this.translator.getLabelFor(this.field) + " " + this.matchingValue;
|
|
|
63 |
} else if (this.foreignLinkRow == null) {
|
181 |
ilm |
64 |
return this.translator.getLabelFor(this.field);
|
|
|
65 |
} else {
|
|
|
66 |
return this.elementLink.getPluralName() + " " + this.foreignLinkRow.getString("NOM") + " " + this.translator.getLabelFor(this.field);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public List<SQLRow> getReferentRows(SQLRowAccessor rowOrigin) {
|
|
|
71 |
SQLSelect sel = new SQLSelect();
|
|
|
72 |
sel.addSelectStar(this.field.getTable());
|
|
|
73 |
final Where w = new Where(this.field.getTable().getField("ID_" + rowOrigin.getTable().getName()), "=", rowOrigin.getID());
|
|
|
74 |
sel.setWhere(w.and(new Where(this.field.getTable().getField("ID_" + foreignLinkRow.getTable().getName()), "=", foreignLinkRow.getID())));
|
|
|
75 |
return SQLRowListRSH.execute(sel);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
}
|