1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package ar.com.fdvs.dj.domain.entities.columns;
31
32 import java.util.Collection;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36
37 import ar.com.fdvs.dj.domain.CustomExpression;
38 import ar.com.fdvs.dj.domain.DJCalculation;
39 import ar.com.fdvs.dj.domain.entities.Entity;
40 import ar.com.fdvs.dj.util.ExpressionUtils;
41
42
43
44
45
46 public class ExpressionColumn extends SimpleColumn {
47
48 private static final long serialVersionUID = Entity.SERIAL_VERSION_UID;
49
50 private static final Log log = LogFactory.getLog(ExpressionColumn.class);
51
52 private CustomExpression expression;
53 private CustomExpression expressionForCalculation;
54
55 private Collection columns;
56 private Collection variables;
57
58 private String calculatedExpressionText = null;
59
60 protected String getCalculatedExpressionText() {
61 return calculatedExpressionText;
62 }
63
64 protected void setCalculatedExpressionText(String calculatedExpressionText) {
65 this.calculatedExpressionText = calculatedExpressionText;
66 }
67
68 public Collection getVariables() {
69 return variables;
70 }
71
72 public void setVariables(Collection variables) {
73 this.variables = variables;
74 }
75
76 public Collection getColumns() {
77 return columns;
78 }
79
80 public void setColumns(Collection columns) {
81 this.columns = columns;
82 }
83
84 public CustomExpression getExpression() {
85 return expression;
86 }
87
88 public void setExpression(CustomExpression expression) {
89 this.expression = expression;
90 }
91
92 public String getValueClassNameForExpression() {
93 if (expression == null)
94 return Object.class.getName();
95
96 return expression.getClassName();
97 }
98
99 public String getTextForExpression() {
100
101 if (this.calculatedExpressionText != null)
102 return this.calculatedExpressionText;
103
104 String stringExpression = ExpressionUtils.createCustomExpressionInvocationText(expression, getColumnProperty().getProperty());
105
106 log.debug("Expression for CustomExpression = " + stringExpression);
107
108 this.calculatedExpressionText = stringExpression;
109 return stringExpression;
110 }
111
112 public String getTextForExpressionForCalculartion() {
113
114 String stringExpression = ExpressionUtils.createCustomExpressionInvocationText(expressionForCalculation, getColumnProperty().getProperty()+"_calc");
115
116 log.debug("Calculation Expression for CustomExpression = " + stringExpression);
117
118 return stringExpression;
119 }
120
121 public CustomExpression getExpressionForCalculation() {
122 return expressionForCalculation;
123 }
124
125 public void setExpressionForCalculation(
126 CustomExpression expressionForCalculation) {
127 this.expressionForCalculation = expressionForCalculation;
128 }
129
130 public String getVariableClassName(DJCalculation op) {
131 if (op == DJCalculation.COUNT || op == DJCalculation.DISTINCT_COUNT)
132 return Long.class.getName();
133
134 if (expressionForCalculation != null)
135 return expressionForCalculation.getClassName();
136
137 if (expression != null)
138 return expression.getClassName();
139
140 return super.getVariableClassName(op);
141
142 }
143
144 public String getInitialExpression(DJCalculation op) {
145 if (op == DJCalculation.COUNT || op == DJCalculation.DISTINCT_COUNT)
146 return "new java.lang.Long(\"0\")";
147 else if (op == DJCalculation.SUM) {
148
149 return "new " + getVariableClassName(op) +"(\"0\")";
150 }
151 else return null;
152 }
153
154
155 }