30 |
30 |
import java.util.Iterator;
|
31 |
31 |
import java.util.List;
|
32 |
32 |
import java.util.Map;
|
|
33 |
import java.util.logging.Level;
|
33 |
34 |
import javax.json.JsonObject;
|
34 |
35 |
import org.apache.commons.lang3.ArrayUtils;
|
35 |
36 |
import org.apache.commons.lang3.StringUtils;
|
36 |
37 |
import org.apache.commons.lang3.builder.ToStringBuilder;
|
|
38 |
import org.apache.commons.lang3.mutable.MutableBoolean;
|
|
39 |
import org.gvsig.expressionevaluator.Code;
|
|
40 |
import org.gvsig.expressionevaluator.CodeBuilder;
|
|
41 |
import org.gvsig.expressionevaluator.Codes;
|
37 |
42 |
import org.gvsig.expressionevaluator.Expression;
|
38 |
43 |
import org.gvsig.expressionevaluator.ExpressionEvaluator;
|
39 |
44 |
import org.gvsig.expressionevaluator.ExpressionUtils;
|
|
45 |
import org.gvsig.expressionevaluator.MutableCodes;
|
40 |
46 |
import org.gvsig.expressionevaluator.MutableSymbolTable;
|
41 |
47 |
import org.gvsig.fmap.dal.DALLocator;
|
42 |
48 |
import org.gvsig.fmap.dal.DataManager;
|
43 |
49 |
import org.gvsig.fmap.dal.DataTypes;
|
44 |
50 |
import org.gvsig.fmap.dal.exception.DataException;
|
45 |
51 |
import org.gvsig.fmap.dal.exception.InitializeException;
|
|
52 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression;
|
|
53 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
|
46 |
54 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
|
47 |
55 |
import org.gvsig.fmap.dal.feature.FeatureExtraColumns;
|
48 |
56 |
import org.gvsig.fmap.dal.feature.FeatureQuery;
|
... | ... | |
60 |
68 |
import org.gvsig.tools.evaluator.AndEvaluator;
|
61 |
69 |
import org.gvsig.tools.evaluator.Evaluator;
|
62 |
70 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo;
|
|
71 |
import org.gvsig.tools.exception.BaseException;
|
63 |
72 |
import org.gvsig.tools.packageutils.Version;
|
64 |
73 |
import org.gvsig.tools.packageutils.impl.DefaultVersion;
|
65 |
74 |
import org.gvsig.tools.persistence.PersistentState;
|
66 |
75 |
import org.gvsig.tools.persistence.exception.PersistenceException;
|
|
76 |
import org.gvsig.tools.visitor.VisitCanceledException;
|
|
77 |
import org.gvsig.tools.visitor.Visitor;
|
67 |
78 |
import org.slf4j.Logger;
|
68 |
79 |
import org.slf4j.LoggerFactory;
|
69 |
80 |
|
... | ... | |
715 |
726 |
// Correcciones por perdida de compatibilidad entre versiones
|
716 |
727 |
//
|
717 |
728 |
|
|
729 |
// Ver TC13-AC Listado peatones USUARIOS 2021.....
|
|
730 |
|
718 |
731 |
if(version == null || version.compareTo(VERSION_2_6_0)<0){
|
719 |
732 |
if(this.limit == 0) {
|
720 |
733 |
this.clearLimit();
|
721 |
734 |
}
|
|
735 |
Expression exp = this.getExpressionFilter();
|
|
736 |
fixOldExistsSelect(exp);
|
|
737 |
for (EditableFeatureAttributeDescriptor extraColumn : this.extraColumns) {
|
|
738 |
if(extraColumn.getFeatureAttributeEmulator() instanceof FeatureAttributeEmulatorExpression) {
|
|
739 |
exp = ((FeatureAttributeEmulatorExpression)extraColumn.getFeatureAttributeEmulator()).getExpression();
|
|
740 |
fixOldExistsSelect(exp);
|
|
741 |
}
|
|
742 |
}
|
722 |
743 |
}
|
723 |
744 |
}
|
724 |
745 |
|
... | ... | |
1216 |
1237 |
return super.toString();
|
1217 |
1238 |
}
|
1218 |
1239 |
}
|
|
1240 |
|
|
1241 |
private void fixOldExistsSelect(Expression exp) {
|
|
1242 |
try {
|
|
1243 |
if(exp == null || !StringUtils.containsIgnoreCase(exp.getPhrase(), "SELECT")
|
|
1244 |
|| !StringUtils.containsIgnoreCase(exp.getPhrase(), "EXISTS")){
|
|
1245 |
return;
|
|
1246 |
}
|
|
1247 |
|
|
1248 |
MutableBoolean modified = new MutableBoolean(false);
|
|
1249 |
Code code = exp.getCode();
|
|
1250 |
code.accept(new Visitor() {
|
|
1251 |
CodeBuilder codeBuilder = null;
|
|
1252 |
@Override
|
|
1253 |
public void visit(Object obj) throws VisitCanceledException, BaseException {
|
|
1254 |
if(Code.isFunction((Code) obj, "EXISTS")){
|
|
1255 |
Code.Callable fnExists = (Code.Callable) obj;
|
|
1256 |
if(Code.isFunction(fnExists.parameters().get(0), "SELECT")){
|
|
1257 |
Code.Callable fnSelect = (Code.Callable) fnExists.parameters().get(0);
|
|
1258 |
MutableCodes params = (MutableCodes) fnSelect.parameters();
|
|
1259 |
if(Code.isFunction(params.get(0), "GETATTR")){
|
|
1260 |
if(codeBuilder == null){
|
|
1261 |
codeBuilder = ExpressionUtils.createCodeBuilder();
|
|
1262 |
}
|
|
1263 |
|
|
1264 |
Code value = codeBuilder.tuple(codeBuilder.constant(1));
|
|
1265 |
params.set(0, value);
|
|
1266 |
modified.setTrue();
|
|
1267 |
}
|
|
1268 |
}
|
|
1269 |
}
|
|
1270 |
}
|
|
1271 |
});
|
|
1272 |
if(modified.isTrue()){
|
|
1273 |
code.link();
|
|
1274 |
exp.setPhrase(code.toString());
|
|
1275 |
}
|
|
1276 |
} catch (Exception ex) {
|
|
1277 |
LOGGER.debug("Can't fix old query with exists and select.", ex);
|
|
1278 |
}
|
|
1279 |
|
|
1280 |
}
|
1219 |
1281 |
|
1220 |
1282 |
}
|