Revision 47168 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/SelectFunction.java
SelectFunction.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.util.Iterator; |
27 | 27 |
import java.util.List; |
28 |
import java.util.function.Function; |
|
28 | 29 |
import java.util.function.Predicate; |
29 | 30 |
import org.apache.commons.lang3.Range; |
30 | 31 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
77 | 78 |
public static final int MODE_FROM_STORE = 0; |
78 | 79 |
public static final int MODE_FROM_SELECTION = 1; |
79 | 80 |
public static final int MODE_FROM_SELECTION_IF_NOT_EMPTY = 2; |
81 |
|
|
82 |
public static final String PROP_FEATURETYPESUPPLIER = "FEATURETYPESUPPLIER"; |
|
80 | 83 |
|
81 | 84 |
private static final int COLUMNS = 0; |
82 | 85 |
private static final int TABLE = 1; |
... | ... | |
86 | 89 |
private static final int LIMIT = 5; |
87 | 90 |
private static final int INTOVAR = 6; |
88 | 91 |
private static final int MODE_FROM = 7; |
92 |
|
|
89 | 93 |
|
90 |
|
|
91 | 94 |
public SelectFunction() { |
92 | 95 |
super(DALFunctions.GROUP_DATA_ACCESS, |
93 | 96 |
FUNCTION_SELECT, |
... | ... | |
312 | 315 |
public Code optimize(Optimizer optimizer, Callable caller) { |
313 | 316 |
return caller; // Don't optimize SELECT |
314 | 317 |
} |
315 |
|
|
316 |
@Override |
|
318 |
|
|
317 | 319 |
public ExpressionBuilder.Value toValue(ExpressionBuilder builder, Codes args) { |
318 | 320 |
try { |
319 | 321 |
SQLBuilder sqlBuilder = (SQLBuilder) builder.getProperty(PROP_SQLBUILDER); |
320 |
if(sqlBuilder == null){
|
|
322 |
if (sqlBuilder == null) {
|
|
321 | 323 |
return super.toValue(builder, args); |
322 | 324 |
} |
325 |
Function<String, FeatureType> featureTypeSupplier = (Function<String, FeatureType>) builder.getProperty(PROP_FEATURETYPESUPPLIER); |
|
326 |
if (featureTypeSupplier == null) { |
|
327 |
featureTypeSupplier = (String tableName) -> { |
|
328 |
DataManager dataManager = DALLocator.getDataManager(); |
|
329 |
FeatureType featureType = dataManager.getStoresRepository().getFeatureType(tableName); |
|
330 |
return featureType; |
|
331 |
}; |
|
332 |
} |
|
323 | 333 |
FeatureType featureType = null; |
324 | 334 |
SQLBuilder.SelectBuilder select = sqlBuilder.createSelectBuilder(); |
325 | 335 |
String builderTableName = (String) builder.getProperty(SQLBuilder.PROP_TABLENAME); |
... | ... | |
393 | 403 |
if(StringUtils.equalsIgnoreCase(builderTableName, tableName)){ |
394 | 404 |
featureType = (FeatureType) builder.getProperty(SQLBuilder.PROP_FEATURE_TYPE); |
395 | 405 |
} else { |
396 |
DataManager dataManager = DALLocator.getDataManager(); |
|
397 |
featureType = dataManager.getStoresRepository().getFeatureType(tableName); |
|
406 |
featureType = featureTypeSupplier.apply(tableName); |
|
398 | 407 |
} |
399 | 408 |
} |
400 | 409 |
if(featureType == null){ |
... | ... | |
434 | 443 |
if (StringUtils.equalsIgnoreCase(builderTableName, tableName)) { |
435 | 444 |
featureType = (FeatureType) builder.getProperty(SQLBuilder.PROP_FEATURE_TYPE); |
436 | 445 |
} else { |
437 |
DataManager dataManager = DALLocator.getDataManager(); |
|
438 |
featureType = dataManager.getStoresRepository().getFeatureType(tableName); |
|
446 |
featureType = featureTypeSupplier.apply(tableName); |
|
439 | 447 |
} |
440 | 448 |
} |
441 | 449 |
|
... | ... | |
458 | 466 |
ExpressionEvaluatorManager expressionManager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager(); |
459 | 467 |
ExpressionBuilder expressionBuilder = expressionManager.createExpressionBuilder(); |
460 | 468 |
expressionBuilder.setProperty(PROP_SQLBUILDER, sqlbuilder); |
469 |
expressionBuilder.setProperty(PROP_FEATURETYPESUPPLIER, new Function<String, FeatureType>() { |
|
470 |
@Override |
|
471 |
public FeatureType apply(String t) { |
|
472 |
return null; |
|
473 |
} |
|
474 |
}); |
|
461 | 475 |
|
462 | 476 |
ExpressionBuilder.Value values = this.toValue(expressionBuilder, args); |
463 |
|
|
477 |
|
|
464 | 478 |
return values.toString(); |
465 | 479 |
} |
466 | 480 |
|
Also available in: Unified diff