Revision 46104 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 | ||
---|---|---|
33 | 33 |
import org.gvsig.expressionevaluator.Code; |
34 | 34 |
import org.gvsig.expressionevaluator.Expression; |
35 | 35 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
36 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_LET; |
|
36 | 37 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
37 | 38 |
import org.gvsig.expressionevaluator.SymbolTable; |
38 | 39 |
import org.gvsig.fmap.dal.SQLBuilder.SelectBuilder; |
... | ... | |
55 | 56 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_QUERY; |
56 | 57 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE; |
57 | 58 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_TABLE; |
59 |
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.ComputedAttribute; |
|
58 | 60 |
import org.gvsig.fmap.geom.DataTypes; |
59 | 61 |
import org.gvsig.tools.dynobject.DynField; |
60 | 62 |
import org.gvsig.tools.evaluator.Evaluator; |
... | ... | |
230 | 232 |
|
231 | 233 |
if (query != null && query.hasGroupByColumns()) { |
232 | 234 |
for (Map.Entry<String, String> entry : query.getAggregateFunctions().entrySet()) { |
233 |
EditableFeatureAttributeDescriptor attr = allExtraColumns.get(entry.getKey()); |
|
234 |
if (attr != null) { |
|
235 |
Expression exp = ((FeatureAttributeEmulatorExpression) attr.getFeatureAttributeEmulator()).getExpression(); |
|
235 |
Expression exp; |
|
236 |
FeatureAttributeDescriptor attr = allExtraColumns.get(entry.getKey()); |
|
237 |
|
|
238 |
if (attr == null) { |
|
239 |
attr = this.setType.getAttributeDescriptorFromAll(entry.getKey()); |
|
240 |
|
|
241 |
if (attr == null) { |
|
242 |
exp = ExpressionUtils.createExpression(entry.getKey()); |
|
243 |
Code code = exp.getCode(); |
|
244 |
if (!(code instanceof Code.Callable)) { |
|
245 |
throw new RuntimeException("Not able to use aggregate function with this expression(1): " + entry.getKey()); |
|
246 |
} |
|
247 |
Code.Callable callable = (Code.Callable) code; |
|
248 |
if (!callable.name().equalsIgnoreCase(FUNCTION_LET)) { |
|
249 |
throw new RuntimeException("Not able to use aggregate function with this expression(2): " + entry.getKey()); |
|
250 |
} |
|
251 |
String name = ((Code.Identifier) callable.parameters().get(0)).name(); |
|
252 |
ExpressionBuilder.Value aggregate = callable.parameters().get(1).toValue(); |
|
253 |
|
|
254 |
ExpressionBuilder.Function aggregateExp = expbuilder.function(entry.getValue(), aggregate); |
|
255 |
|
|
256 |
select.remove_column(name); |
|
257 |
select.column().value(aggregateExp).as(name); |
|
258 |
} |
|
259 |
} else { |
|
260 |
exp = ((FeatureAttributeEmulatorExpression) attr.getFeatureAttributeEmulator()).getExpression(); |
|
236 | 261 |
ExpressionBuilder.Function aggregateExp = expbuilder.function(entry.getValue(), exp.getCode().toValue()); |
237 | 262 |
if (!select.has_column(attr.getName())) { |
238 | 263 |
select.column().value(aggregateExp).as(attr.getName()); |
239 | 264 |
} |
240 |
if (extraColumnNames!=null && !extraColumnNames.contains(attr.getName())) {
|
|
265 |
if (extraColumnNames != null && !extraColumnNames.contains(attr.getName())) {
|
|
241 | 266 |
extraColumnNames.add(attr.getName()); |
242 | 267 |
} |
243 | 268 |
} |
... | ... | |
247 | 272 |
EditableFeatureAttributeDescriptor attr = allExtraColumns.get(attrName); |
248 | 273 |
ExpressionBuilder.Variable col = expbuilder.column(attrName); |
249 | 274 |
select.group_by(col); |
250 |
// En el groupBy no queremos que se sustituya el nombre del campo calculado |
|
251 |
// por su expresion. Se encarga el formater y lo evitamos quitandole el ftype |
|
252 |
// al value. |
|
253 |
valuesToRemoveFeatureType.add(col); |
|
254 | 275 |
Expression exp = ((FeatureAttributeEmulatorExpression) attr.getFeatureAttributeEmulator()).getExpression(); |
255 | 276 |
if (!select.has_column(attrName)) { |
256 | 277 |
select.column().value(exp.getCode().toValue()).as(attrName); |
... | ... | |
262 | 283 |
FeatureAttributeDescriptor attr = setType.getAttributeDescriptor(attrName); |
263 | 284 |
ExpressionBuilder.Variable col = expbuilder.column(attrName); |
264 | 285 |
select.group_by(col); |
265 |
valuesToRemoveFeatureType.add(col); |
|
266 | 286 |
Expression exp = ((FeatureAttributeEmulatorExpression) attr.getFeatureAttributeEmulator()).getExpression(); |
267 | 287 |
if (!select.has_column(attrName)) { |
268 | 288 |
select.column().value(exp.getCode().toValue()).as(attrName); |
... | ... | |
359 | 379 |
extraColumnNames.add(attrName); |
360 | 380 |
} |
361 | 381 |
} |
362 |
select.order_by() |
|
363 |
.column(member.getAttributeName()) |
|
364 |
.ascending(member.getAscending()); |
|
382 |
ExpressionBuilder.Variable col = expbuilder.column(attrName); |
|
383 |
|
|
384 |
// En el groupBy no queremos que se sustituya el nombre del campo calculado |
|
385 |
// por su expresion. Se encarga el formater y lo evitamos quitandole el ftype |
|
386 |
// al value. |
|
387 |
valuesToRemoveFeatureType.add(col); |
|
388 |
select.order_by().value(col).ascending(member.getAscending()); |
|
389 |
// select.order_by() |
|
390 |
// .column(member.getAttributeName()) |
|
391 |
// .ascending(member.getAscending()); |
|
365 | 392 |
} |
366 | 393 |
} |
367 | 394 |
} |
... | ... | |
427 | 454 |
for (ExpressionBuilder.Value value : valuesToRemoveFeatureType) { |
428 | 455 |
value.setProperty(PROP_FEATURE_TYPE, null); |
429 | 456 |
} |
457 |
this.helper.expandCalculedColumns(sqlbuilder); |
|
430 | 458 |
this.helper.processSpecialFunctions(sqlbuilder, storeType, extraColumnNames); |
431 | 459 |
String sql = sqlbuilder.toString(); |
432 | 460 |
return sql; |
Also available in: Unified diff