Revision 45166 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/ResultSetForSetProviderOperation.java
ResultSetForSetProviderOperation.java | ||
---|---|---|
26 | 26 |
import java.sql.Connection; |
27 | 27 |
import java.util.ArrayList; |
28 | 28 |
import java.util.List; |
29 |
import java.util.Map; |
|
29 | 30 |
import org.apache.commons.lang3.ArrayUtils; |
30 | 31 |
import org.apache.commons.lang3.StringUtils; |
31 | 32 |
import org.gvsig.expressionevaluator.Code; |
32 | 33 |
import org.gvsig.expressionevaluator.Expression; |
33 | 34 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
34 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_LET; |
|
35 | 35 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
36 | 36 |
import org.gvsig.fmap.dal.SQLBuilder.SelectBuilder; |
37 | 37 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
165 | 165 |
} |
166 | 166 |
|
167 | 167 |
if( query !=null && query.hasGroupByColumns() ) { |
168 |
for (Map.Entry<String, String> entry : query.getAggregateFunctions().entrySet()) { |
|
169 |
EditableFeatureAttributeDescriptor attr = query.getExtraColumn().get(entry.getKey()); |
|
170 |
if( attr!=null ) { |
|
171 |
Expression exp = ((FeatureAttributeEmulatorExpression) attr.getFeatureAttributeEmulator()).getExpression(); |
|
172 |
ExpressionBuilder.Function aggregateExp = expbuilder.function(entry.getValue(),exp.getCode().toValue()); |
|
173 |
if (!select.has_column(attr.getName())) { |
|
174 |
select.column().value(aggregateExp).as(attr.getName()); |
|
175 |
} |
|
176 |
if (!extraColumnNames.contains(attr.getName())) { |
|
177 |
extraColumnNames.add(attr.getName()); |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
168 | 181 |
for(String attrName : query.getGroupByColumns() ) { |
169 | 182 |
if (this.setType.getExtraColumns().get(attrName) != null) { |
170 | 183 |
EditableFeatureAttributeDescriptor attr = this.setType.getExtraColumns().get(attrName); |
171 | 184 |
select.group_by(expbuilder.column(attrName)); |
172 | 185 |
Expression exp = ((FeatureAttributeEmulatorExpression) attr.getFeatureAttributeEmulator()).getExpression(); |
173 |
select.column().value(exp.getCode().toValue()).as(attrName); |
|
174 |
extraColumnNames.add(attrName); |
|
186 |
if (!select.has_column(attrName)) { |
|
187 |
select.column().value(exp.getCode().toValue()).as(attrName); |
|
188 |
} |
|
189 |
if (!extraColumnNames.contains(attr.getName())) { |
|
190 |
extraColumnNames.add(attrName); |
|
191 |
} |
|
175 | 192 |
} else if (setType.get(attrName) == null) { |
176 | 193 |
try { |
177 | 194 |
Code code = ExpressionUtils.compile(attrName); |
178 |
if( code.code()==Code.CALLABLE ) { |
|
179 |
Code.Callable callable = (Code.Callable) code; |
|
180 |
if( callable.name().equalsIgnoreCase(FUNCTION_LET) ) { |
|
181 |
code = callable.parameters().get(1); |
|
182 |
Code name = callable.parameters().get(0); |
|
183 |
select.column().value(callable.parameters().get(1).toValue()) |
|
184 |
.as((String) ((Code.Constant)name).value()); |
|
185 |
extraColumnNames.add((String) ((Code.Constant)name).value()); |
|
186 |
} |
|
187 |
} |
|
188 | 195 |
select.group_by(code.toValue()); |
189 | 196 |
} catch (Exception ex) { |
190 | 197 |
throw new RuntimeException("Not able to create column by expression in groupby query", ex); |
Also available in: Unified diff