Revision 46050
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeature.java | ||
---|---|---|
912 | 912 |
// int index = featureAttributeDescriptor.getIndex(); |
913 | 913 |
// value = this.data.get(index); |
914 | 914 |
// if( value==null ) { |
915 |
value = emulator.get(this); |
|
915 |
value = this.getExtraValue(featureAttributeDescriptor.getName()); |
|
916 |
if (value==null) { |
|
917 |
value = emulator.get(this); |
|
918 |
} |
|
916 | 919 |
// this.data.set(index,value); |
917 | 920 |
// } |
918 | 921 |
} else { |
... | ... | |
1346 | 1349 |
@Override |
1347 | 1350 |
public String getLabelOfValue(String name) { |
1348 | 1351 |
FeatureAttributeDescriptor attrdesc = this.data.getType().getAttributeDescriptor(name); |
1349 |
if (attrdesc == null) { |
|
1350 |
throw new IllegalArgumentException("Attribute name '" + name + "' not found in the feature."); |
|
1352 |
Object value; |
|
1353 |
if (attrdesc == null) { // extra column |
|
1354 |
FeatureExtraColumns extraColumns = this.data.getType().getExtraColumns(); |
|
1355 |
if (extraColumns==null) { |
|
1356 |
return name; |
|
1357 |
} |
|
1358 |
attrdesc = extraColumns.get(name); |
|
1359 |
if(attrdesc==null) { |
|
1360 |
return name; |
|
1361 |
} |
|
1362 |
value = this.get(name); |
|
1363 |
} else { |
|
1364 |
value = this.get(attrdesc.getIndex()); |
|
1351 | 1365 |
} |
1352 |
Object value = this.get(attrdesc.getIndex()); |
|
1353 | 1366 |
String label = attrdesc.getLabelOfValue(value); |
1354 | 1367 |
return label; |
1355 | 1368 |
} |
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/JDBCSQLBuilderBase.java | ||
---|---|---|
66 | 66 |
public static final String PROP_TABLE = "Table"; |
67 | 67 |
public static final String PROP_SYMBOLTABLE = "SymbolTable"; |
68 | 68 |
public static final String PROP_JDBCHELPER = "JDBCHelper"; |
69 |
public static final String PROP_QUERY = "Query"; |
|
69 | 70 |
|
70 | 71 |
private GeometryManager geometryManager = null; |
71 | 72 |
protected final JDBCHelper helper; |
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/expressionbuilder/formatters/$$Constant.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
|
25 |
|
|
26 |
import java.util.Objects; |
|
27 |
import org.apache.commons.lang3.StringUtils; |
|
28 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
29 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$$CONSTANT; |
|
30 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
31 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
32 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
33 |
import org.gvsig.expressionevaluator.Formatter; |
|
34 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
35 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
36 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE; |
|
37 |
|
|
38 |
/** |
|
39 |
* |
|
40 |
* @author jjdelcerro |
|
41 |
*/ |
|
42 |
public class $$Constant implements Formatter<Value> { |
|
43 |
|
|
44 |
private final SQLBuilder sqlbuilder; |
|
45 |
private final Formatter<Value> formatter; |
|
46 |
|
|
47 |
public $$Constant(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
|
48 |
this.sqlbuilder = sqlbuilder; |
|
49 |
this.formatter = formatter; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public boolean canApply(ExpressionBuilder.Value value) { |
|
54 |
if (value instanceof ExpressionBuilder.Function) { |
|
55 |
return StringUtils.equalsIgnoreCase(FUNCTION_$$CONSTANT, ((Function) value).name()); |
|
56 |
} |
|
57 |
return false; |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public String format(Value value) { |
|
62 |
return resolve(this.sqlbuilder.expression(), this.formatter, value); |
|
63 |
} |
|
64 |
|
|
65 |
public static boolean isConstant(Value value) { |
|
66 |
if( value instanceof ExpressionBuilder.Constant) { |
|
67 |
return true; |
|
68 |
} |
|
69 |
return value instanceof ExpressionBuilder.Function && |
|
70 |
StringUtils.equalsIgnoreCase(((ExpressionBuilder.Function)value).name(),FUNCTION_$$CONSTANT); |
|
71 |
} |
|
72 |
|
|
73 |
public static String resolve(Value value) { |
|
74 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
|
75 |
return resolve(builder, null, value); |
|
76 |
} |
|
77 |
|
|
78 |
public static String resolve(ExpressionBuilder builder, Formatter<Value> formatter, Value value) { |
|
79 |
if( value instanceof ExpressionBuilder.Constant) { |
|
80 |
Object x = ((ExpressionBuilder.Constant)value).value(); |
|
81 |
return builder.constant(x).toString(formatter); |
|
82 |
} else if( value instanceof ExpressionBuilder.Function && |
|
83 |
StringUtils.equalsIgnoreCase(((ExpressionBuilder.Function)value).name(),FUNCTION_$$CONSTANT) ) { |
|
84 |
SymbolTable symbolTable = (SymbolTable) value.getProperty(PROP_SYMBOLTABLE); |
|
85 |
Object x = ExpressionUtils.evaluate(symbolTable, value.toString()); |
|
86 |
return builder.constant(x).toString(formatter); |
|
87 |
} |
|
88 |
throw new RuntimeException("Expected constant value or $$CONSTANT function ("+Objects.toString(value)+")."); |
|
89 |
} |
|
90 |
} |
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/expressionbuilder/formatters/$$Identifier.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
|
25 |
|
|
26 |
import java.util.Objects; |
|
27 |
import org.apache.commons.lang3.StringUtils; |
|
28 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
29 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$$IDENTIFIER; |
|
30 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
31 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
32 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
33 |
import org.gvsig.expressionevaluator.Formatter; |
|
34 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
35 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
36 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE; |
|
37 |
|
|
38 |
/** |
|
39 |
* |
|
40 |
* @author jjdelcerro |
|
41 |
*/ |
|
42 |
public class $$Identifier implements Formatter<Value> { |
|
43 |
|
|
44 |
private final SQLBuilder sqlbuilder; |
|
45 |
private final Formatter<Value> formatter; |
|
46 |
|
|
47 |
public $$Identifier(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
|
48 |
this.sqlbuilder = sqlbuilder; |
|
49 |
this.formatter = formatter; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public boolean canApply(ExpressionBuilder.Value value) { |
|
54 |
if (value instanceof ExpressionBuilder.Function) { |
|
55 |
return StringUtils.equalsIgnoreCase(FUNCTION_$$IDENTIFIER, ((Function) value).name()); |
|
56 |
} |
|
57 |
return false; |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public String format(Value value) { |
|
62 |
SymbolTable symbolTable = (SymbolTable) value.getProperty(PROP_SYMBOLTABLE); |
|
63 |
Value p1 = ((ExpressionBuilder.Function)value).parameters().get(0); |
|
64 |
Object x = ExpressionUtils.evaluate(symbolTable, p1.toString()); |
|
65 |
return this.sqlbuilder.expression().variable(Objects.toString(x, "")).toString(this.formatter); |
|
66 |
} |
|
67 |
|
|
68 |
} |
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/expressionbuilder/formatters/ComputedAttribute.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
25 | 25 |
|
26 |
import org.gvsig.expressionevaluator.Code; |
|
26 | 27 |
import org.gvsig.expressionevaluator.Expression; |
27 | 28 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
28 | 29 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
29 | 30 |
import org.gvsig.expressionevaluator.Formatter; |
31 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
30 | 32 |
import org.gvsig.fmap.dal.SQLBuilder; |
31 | 33 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
32 | 34 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
33 | 35 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
36 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
34 | 37 |
import org.gvsig.fmap.dal.feature.FeatureType; |
35 | 38 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
36 | 39 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
37 | 40 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
38 | 41 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_JDBCHELPER; |
42 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_QUERY; |
|
39 | 43 |
|
40 | 44 |
/** |
41 | 45 |
* |
... | ... | |
64 | 68 |
} |
65 | 69 |
ExpressionBuilder.Variable variable = (ExpressionBuilder.Variable) value; |
66 | 70 |
FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(variable.name()); |
67 |
if( attr==null || !attr.isComputed() ) { |
|
71 |
if (attr == null) { |
|
72 |
FeatureQuery query = (FeatureQuery) value.getProperty(PROP_QUERY); |
|
73 |
attr = query.getExtraColumn().get(variable.name()); |
|
74 |
} |
|
75 |
|
|
76 |
if (attr == null || !attr.isComputed()) { |
|
68 | 77 |
return false; |
69 | 78 |
} |
79 |
|
|
70 | 80 |
FeatureAttributeEmulator emulator = attr.getFeatureAttributeEmulator(); |
71 | 81 |
if( !(emulator instanceof FeatureAttributeEmulatorExpression) ) { |
72 | 82 |
return false; |
... | ... | |
82 | 92 |
FeatureType featureType = (FeatureType) value.getProperty(PROP_FEATURE_TYPE); |
83 | 93 |
ExpressionBuilder.Variable variable = (ExpressionBuilder.Variable) value; |
84 | 94 |
FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(variable.name()); |
95 |
if (attr == null) { |
|
96 |
FeatureQuery query = (FeatureQuery) value.getProperty(PROP_QUERY); |
|
97 |
attr = query.getExtraColumn().get(variable.name()); |
|
98 |
} |
|
85 | 99 |
FeatureAttributeEmulator emulator = attr.getFeatureAttributeEmulator(); |
86 | 100 |
Expression expr = ((FeatureAttributeEmulatorExpression)emulator).getExpression(); |
87 |
return "("+ this.formatter.format(expr.getCode().toValue(this.sqlbuilder.expression()))+")"; |
|
101 |
Code code = expr.getCode(); |
|
102 |
GeometryExpressionBuilder builder = this.sqlbuilder.expression(); |
|
103 |
Value valueExpr = code.toValue(builder); |
|
104 |
return "("+ this.formatter.format(valueExpr)+")"; |
|
88 | 105 |
} |
89 | 106 |
|
90 | 107 |
} |
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/expressionbuilder/formatters/$Identifier.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
|
25 |
|
|
26 |
import java.util.Objects; |
|
27 |
import org.apache.commons.lang3.StringUtils; |
|
28 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
29 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
30 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
31 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
32 |
import org.gvsig.expressionevaluator.Formatter; |
|
33 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
34 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
35 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE; |
|
36 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$IDENTIFIER; |
|
37 |
|
|
38 |
/** |
|
39 |
* |
|
40 |
* @author jjdelcerro |
|
41 |
*/ |
|
42 |
public class $Identifier implements Formatter<Value> { |
|
43 |
|
|
44 |
private final SQLBuilder sqlbuilder; |
|
45 |
private final Formatter<Value> formatter; |
|
46 |
|
|
47 |
public $Identifier(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
|
48 |
this.sqlbuilder = sqlbuilder; |
|
49 |
this.formatter = formatter; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public boolean canApply(ExpressionBuilder.Value value) { |
|
54 |
if (value instanceof ExpressionBuilder.Function) { |
|
55 |
return StringUtils.equalsIgnoreCase(FUNCTION_$IDENTIFIER, ((Function) value).name()); |
|
56 |
} |
|
57 |
return false; |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public String format(Value value) { |
|
62 |
SymbolTable symbolTable = (SymbolTable) value.getProperty(PROP_SYMBOLTABLE); |
|
63 |
Value p1 = ((ExpressionBuilder.Function)value).parameters().get(0); |
|
64 |
Object x = ExpressionUtils.evaluate(symbolTable, p1.toString()); |
|
65 |
return this.sqlbuilder.expression().variable(Objects.toString(x, "")).toString(this.formatter); |
|
66 |
} |
|
67 |
|
|
68 |
} |
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/expressionbuilder/formatters/$Constant.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
|
25 |
|
|
26 |
import java.util.Objects; |
|
27 |
import org.apache.commons.lang3.StringUtils; |
|
28 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
29 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
30 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
31 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
32 |
import org.gvsig.expressionevaluator.Formatter; |
|
33 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
34 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
35 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE; |
|
36 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$CONSTANT; |
|
37 |
|
|
38 |
/** |
|
39 |
* |
|
40 |
* @author jjdelcerro |
|
41 |
*/ |
|
42 |
public class $Constant implements Formatter<Value> { |
|
43 |
|
|
44 |
private final SQLBuilder sqlbuilder; |
|
45 |
private final Formatter<Value> formatter; |
|
46 |
|
|
47 |
public $Constant(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
|
48 |
this.sqlbuilder = sqlbuilder; |
|
49 |
this.formatter = formatter; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public boolean canApply(ExpressionBuilder.Value value) { |
|
54 |
if (value instanceof ExpressionBuilder.Function) { |
|
55 |
return StringUtils.equalsIgnoreCase(FUNCTION_$CONSTANT, ((Function) value).name()); |
|
56 |
} |
|
57 |
return false; |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public String format(Value value) { |
|
62 |
return resolve(this.sqlbuilder.expression(), this.formatter, value); |
|
63 |
} |
|
64 |
|
|
65 |
public static boolean isConstant(Value value) { |
|
66 |
if( value instanceof ExpressionBuilder.Constant) { |
|
67 |
return true; |
|
68 |
} |
|
69 |
return value instanceof ExpressionBuilder.Function && |
|
70 |
StringUtils.equalsIgnoreCase(((ExpressionBuilder.Function)value).name(),FUNCTION_$CONSTANT); |
|
71 |
} |
|
72 |
|
|
73 |
public static String resolve(Value value) { |
|
74 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
|
75 |
return resolve(builder, null, value); |
|
76 |
} |
|
77 |
|
|
78 |
public static String resolve(ExpressionBuilder builder, Formatter<Value> formatter, Value value) { |
|
79 |
if( value instanceof ExpressionBuilder.Constant) { |
|
80 |
Object x = ((ExpressionBuilder.Constant)value).value(); |
|
81 |
return builder.constant(x).toString(formatter); |
|
82 |
} else if( value instanceof ExpressionBuilder.Function && |
|
83 |
StringUtils.equalsIgnoreCase(((ExpressionBuilder.Function)value).name(),FUNCTION_$CONSTANT) ) { |
|
84 |
SymbolTable symbolTable = (SymbolTable) value.getProperty(PROP_SYMBOLTABLE); |
|
85 |
Object x = ExpressionUtils.evaluate(symbolTable, value.toString()); |
|
86 |
return builder.constant(x).toString(formatter); |
|
87 |
} |
|
88 |
throw new RuntimeException("Expected constant value or $$CONSTANT function ("+Objects.toString(value)+")."); |
|
89 |
} |
|
90 |
} |
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/JDBCHelperBase.java | ||
---|---|---|
39 | 39 |
import org.gvsig.expressionevaluator.Code; |
40 | 40 |
import org.gvsig.expressionevaluator.Expression; |
41 | 41 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
42 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$$CONSTANT; |
|
43 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$$IDENTIFIER; |
|
44 | 42 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
45 | 43 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
46 | 44 |
import org.gvsig.expressionevaluator.Function; |
... | ... | |
96 | 94 |
import org.gvsig.tools.visitor.Visitor; |
97 | 95 |
import org.slf4j.Logger; |
98 | 96 |
import org.slf4j.LoggerFactory; |
97 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$CONSTANT; |
|
98 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$IDENTIFIER; |
|
99 | 99 |
|
100 | 100 |
@SuppressWarnings("UseSpecificCatch") |
101 | 101 |
public class JDBCHelperBase extends AbstractDisposable implements ResourceConsumer, JDBCHelper { |
... | ... | |
336 | 336 |
public boolean test(FilteredVisitable code0) { |
337 | 337 |
if (code0 instanceof Code.Callable) { |
338 | 338 |
String name = ((Code.Callable) code0).name(); |
339 |
return StringUtils.equalsIgnoreCase(name, FUNCTION_$$CONSTANT)
|
|
340 |
|| StringUtils.equalsIgnoreCase(name, FUNCTION_$$IDENTIFIER);
|
|
339 |
return StringUtils.equalsIgnoreCase(name, FUNCTION_$CONSTANT) |
|
340 |
|| StringUtils.equalsIgnoreCase(name, FUNCTION_$IDENTIFIER); |
|
341 | 341 |
} |
342 | 342 |
return false; |
343 | 343 |
} |
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 | ||
---|---|---|
52 | 52 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
53 | 53 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
54 | 54 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_JDBCHELPER; |
55 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_QUERY; |
|
55 | 56 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE; |
56 | 57 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_TABLE; |
57 | 58 |
import org.gvsig.fmap.geom.DataTypes; |
58 | 59 |
import org.gvsig.tools.dynobject.DynField; |
59 | 60 |
import org.gvsig.tools.evaluator.Evaluator; |
61 |
import org.gvsig.tools.util.ContainerUtils; |
|
60 | 62 |
|
61 | 63 |
public class ResultSetForSetProviderOperation extends AbstractConnectionOperation { |
62 | 64 |
|
... | ... | |
117 | 119 |
List<FeatureAttributeDescriptor> columns, |
118 | 120 |
List<String> extraColumnNames |
119 | 121 |
) { |
120 |
double tolerance = -1; //query.getScale(); |
|
122 |
double tolerance = -1; //query.getScale();
|
|
121 | 123 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
122 | 124 |
SelectBuilder select = sqlbuilder.select(); |
123 | 125 |
|
... | ... | |
141 | 143 |
if (query != null && query.hasConstantsAttributeNames()) { |
142 | 144 |
constantsAttributeNames = query.getConstantsAttributeNames(); |
143 | 145 |
} |
146 |
ArrayList<ExpressionBuilder.Value> valuesToRemoveFeatureType = new ArrayList<>(); |
|
144 | 147 |
for (FeatureAttributeDescriptor attr : setType) { |
145 | 148 |
if (attr.isComputed()) { |
146 |
// if(StringUtils.isNotBlank(System.getenv("ENABLE_COMPUTED_SQL_ATTR"))) { |
|
149 |
// if(StringUtils.isNotBlank(System.getenv("ENABLE_COMPUTED_SQL_ATTR"))) {
|
|
147 | 150 |
if (attr.getRelationType() == DynField.RELATION_TYPE_NONE) { |
148 | 151 |
FeatureAttributeEmulator attrEmulator = attr.getFeatureAttributeEmulator(); |
149 | 152 |
if (attrEmulator instanceof FeatureAttributeEmulatorExpression) { |
150 | 153 |
FeatureAttributeEmulatorExpression x = (FeatureAttributeEmulatorExpression) attrEmulator; |
151 | 154 |
Expression exp = x.getExpression(); |
152 |
if (exp != null && !exp.isEmpty() && this.helper.supportExpression(setType, exp.getPhrase())) { |
|
153 |
Code code = exp.getCode(); |
|
154 |
select.column() |
|
155 |
.value(code.toValue(expbuilder)) |
|
156 |
.as(attr.getName()); |
|
157 |
if (!extraColumnNames.contains(attr.getName())) { |
|
158 |
extraColumnNames.add(attr.getName()); |
|
155 |
|
|
156 |
if (query != null && query.hasGroupByColumns()) { |
|
157 |
String aggregate = query.getAggregate(this.table.getTable(), attr.getName()); |
|
158 |
if (this.query.isAGroupByColumn(attr.getName())) { |
|
159 |
if (!select.has_column(attr.getName())) { |
|
160 |
select.column().value(exp.getCode().toValue()).as(attr.getName()); |
|
161 |
} |
|
162 |
if (extraColumnNames != null && !extraColumnNames.contains(attr.getName())) { |
|
163 |
extraColumnNames.add(attr.getName()); |
|
164 |
} |
|
165 |
} else if (aggregate == null) { |
|
166 |
select.column().value(expbuilder.constant(null)).as(attr.getName()); |
|
167 |
} else { |
|
168 |
String fn = this.query.getAggregateFunctions().get(attr.getName()); |
|
169 |
ExpressionBuilder.Function aggregateExp = expbuilder.function(fn, exp.getCode().toValue()); |
|
170 |
if (!select.has_column(attr.getName())) { |
|
171 |
select.column().value(aggregateExp).as(attr.getName()); |
|
172 |
} |
|
173 |
if (extraColumnNames != null && !extraColumnNames.contains(attr.getName())) { |
|
174 |
extraColumnNames.add(attr.getName()); |
|
175 |
} |
|
159 | 176 |
} |
177 |
} else { |
|
178 |
if (exp != null && !exp.isEmpty() && this.helper.supportExpression(setType, exp.getPhrase())) { |
|
179 |
Code code = exp.getCode(); |
|
180 |
select.column() |
|
181 |
.value(code.toValue(expbuilder)) |
|
182 |
.as(attr.getName()); |
|
183 |
if (extraColumnNames != null && !extraColumnNames.contains(attr.getName())) { |
|
184 |
extraColumnNames.add(attr.getName()); |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
160 | 188 |
} |
161 | 189 |
} |
162 | 190 |
} |
... | ... | |
209 | 237 |
if (!select.has_column(attr.getName())) { |
210 | 238 |
select.column().value(aggregateExp).as(attr.getName()); |
211 | 239 |
} |
212 |
if (!extraColumnNames.contains(attr.getName())) { |
|
240 |
if (extraColumnNames!=null && !extraColumnNames.contains(attr.getName())) {
|
|
213 | 241 |
extraColumnNames.add(attr.getName()); |
214 | 242 |
} |
215 | 243 |
} |
... | ... | |
217 | 245 |
for (String attrName : query.getGroupByColumns()) { |
218 | 246 |
if (allExtraColumns.get(attrName) != null) { //from setType and query |
219 | 247 |
EditableFeatureAttributeDescriptor attr = allExtraColumns.get(attrName); |
220 |
select.group_by(expbuilder.column(attrName)); |
|
248 |
ExpressionBuilder.Variable col = expbuilder.column(attrName); |
|
249 |
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); |
|
221 | 254 |
Expression exp = ((FeatureAttributeEmulatorExpression) attr.getFeatureAttributeEmulator()).getExpression(); |
222 | 255 |
if (!select.has_column(attrName)) { |
223 | 256 |
select.column().value(exp.getCode().toValue()).as(attrName); |
224 | 257 |
} |
225 |
if (!extraColumnNames.contains(attr.getName())) { |
|
258 |
if (extraColumnNames!=null && !extraColumnNames.contains(attr.getName())) {
|
|
226 | 259 |
extraColumnNames.add(attrName); |
227 | 260 |
} |
228 | 261 |
} else if (setType.get(attrName) != null && setType.getAttributeDescriptor(attrName).isComputed()) { |
229 | 262 |
FeatureAttributeDescriptor attr = setType.getAttributeDescriptor(attrName); |
230 |
select.group_by(expbuilder.column(attrName)); |
|
263 |
ExpressionBuilder.Variable col = expbuilder.column(attrName); |
|
264 |
select.group_by(col); |
|
265 |
valuesToRemoveFeatureType.add(col); |
|
231 | 266 |
Expression exp = ((FeatureAttributeEmulatorExpression) attr.getFeatureAttributeEmulator()).getExpression(); |
232 | 267 |
if (!select.has_column(attrName)) { |
233 | 268 |
select.column().value(exp.getCode().toValue()).as(attrName); |
234 | 269 |
} |
235 |
if (!extraColumnNames.contains(attr.getName())) { |
|
270 |
if (extraColumnNames!=null && !extraColumnNames.contains(attr.getName())) {
|
|
236 | 271 |
extraColumnNames.add(attrName); |
237 | 272 |
} |
238 | 273 |
} else if (setType.get(attrName) == null) { |
... | ... | |
268 | 303 |
select.column() |
269 | 304 |
.value(code.toValue(expbuilder)) |
270 | 305 |
.as(attr.getName()); |
271 |
if (!extraColumnNames.contains(attr.getName())) { |
|
306 |
if (extraColumnNames!=null && !extraColumnNames.contains(attr.getName())) {
|
|
272 | 307 |
extraColumnNames.add(attr.getName()); |
273 | 308 |
} |
274 | 309 |
} |
... | ... | |
312 | 347 |
if (!select.has_column(attrName)) { |
313 | 348 |
select.column().value(exp.getCode().toValue()).as(attrName); |
314 | 349 |
} |
315 |
if (!extraColumnNames.contains(attrName)) { |
|
350 |
if (extraColumnNames!=null && !extraColumnNames.contains(attrName)) {
|
|
316 | 351 |
extraColumnNames.add(attrName); |
317 | 352 |
} |
318 | 353 |
} else if (setType.get(attrName) != null && setType.getAttributeDescriptor(attrName).isComputed()) { |
... | ... | |
320 | 355 |
if (!select.has_column(attrName)) { |
321 | 356 |
select.column().value(exp.getCode().toValue()).as(attrName); |
322 | 357 |
} |
323 |
if (!extraColumnNames.contains(attrName)) { |
|
358 |
if (extraColumnNames!=null && !extraColumnNames.contains(attrName)) {
|
|
324 | 359 |
extraColumnNames.add(attrName); |
325 | 360 |
} |
326 | 361 |
} |
... | ... | |
386 | 421 |
PROP_FEATURE_TYPE, this.storeType, |
387 | 422 |
PROP_TABLE, table, |
388 | 423 |
PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable(), |
389 |
PROP_JDBCHELPER, this.helper |
|
424 |
PROP_JDBCHELPER, this.helper, |
|
425 |
PROP_QUERY, this.query |
|
390 | 426 |
); |
427 |
for (ExpressionBuilder.Value value : valuesToRemoveFeatureType) { |
|
428 |
value.setProperty(PROP_FEATURE_TYPE, null); |
|
429 |
} |
|
391 | 430 |
this.helper.processSpecialFunctions(sqlbuilder, storeType, extraColumnNames); |
392 | 431 |
String sql = sqlbuilder.toString(); |
393 | 432 |
return sql; |
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/CountOperation.java | ||
---|---|---|
27 | 27 |
import java.sql.ResultSet; |
28 | 28 |
import java.sql.SQLException; |
29 | 29 |
import java.sql.Statement; |
30 |
import java.util.ArrayList; |
|
30 | 31 |
import java.util.List; |
31 | 32 |
import org.apache.commons.lang3.StringUtils; |
32 | 33 |
import org.gvsig.expressionevaluator.Code; |
... | ... | |
38 | 39 |
import org.gvsig.fmap.dal.exception.DataException; |
39 | 40 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
40 | 41 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
42 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
43 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
|
41 | 44 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
42 | 45 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
43 | 46 |
import org.gvsig.fmap.dal.feature.FeatureType; |
... | ... | |
48 | 51 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
49 | 52 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
50 | 53 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_JDBCHELPER; |
54 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_QUERY; |
|
51 | 55 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE; |
52 | 56 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_TABLE; |
57 |
import org.gvsig.tools.dynobject.DynField; |
|
53 | 58 |
import org.gvsig.tools.evaluator.Evaluator; |
54 | 59 |
|
55 | 60 |
public class CountOperation extends AbstractConnectionOperation { |
... | ... | |
89 | 94 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
90 | 95 |
|
91 | 96 |
SelectBuilder select = sqlbuilder.select(); |
97 |
ArrayList<ExpressionBuilder.Value> valuesToRemoveFeatureType = new ArrayList<>(); |
|
92 | 98 |
|
93 | 99 |
if (this.query != null && this.query.hasGroupByColumns()) { |
94 | 100 |
JDBCSQLBuilderBase subsqlbuilder = this.createSQLBuilder(); |
95 | 101 |
SelectBuilder subselect = subsqlbuilder.select(); |
102 |
|
|
103 |
subselect.column().value(subsqlbuilder.count().all()); |
|
104 |
for (FeatureAttributeDescriptor attr : this.featureType) { |
|
105 |
if (attr.isComputed()) { |
|
106 |
if (attr.getRelationType() == DynField.RELATION_TYPE_NONE) { |
|
107 |
FeatureAttributeEmulator attrEmulator = attr.getFeatureAttributeEmulator(); |
|
108 |
if (attrEmulator instanceof FeatureAttributeEmulatorExpression) { |
|
109 |
FeatureAttributeEmulatorExpression x = (FeatureAttributeEmulatorExpression) attrEmulator; |
|
110 |
Expression exp = x.getExpression(); |
|
111 |
|
|
112 |
if (query != null && query.hasGroupByColumns()) { |
|
113 |
String aggregate = query.getAggregate(this.table.getTable(), attr.getName()); |
|
114 |
if (this.query.isAGroupByColumn(attr.getName())) { |
|
115 |
if (!subselect.has_column(attr.getName())) { |
|
116 |
subselect.column().value(exp.getCode().toValue()).as(attr.getName()); |
|
117 |
} |
|
118 |
|
|
119 |
} else if (aggregate == null) { |
|
120 |
subselect.column().value(expbuilder.constant(null)).as(attr.getName()); |
|
121 |
} else { |
|
122 |
String fn = this.query.getAggregateFunctions().get(attr.getName()); |
|
123 |
ExpressionBuilder.Function aggregateExp = expbuilder.function(fn, exp.getCode().toValue()); |
|
124 |
if (!subselect.has_column(attr.getName())) { |
|
125 |
subselect.column().value(aggregateExp).as(attr.getName()); |
|
126 |
} |
|
127 |
|
|
128 |
} |
|
129 |
} else { |
|
130 |
if (exp != null && !exp.isEmpty() && this.helper.supportExpression(this.featureType, exp.getPhrase())) { |
|
131 |
Code code = exp.getCode(); |
|
132 |
subselect.column() |
|
133 |
.value(code.toValue(expbuilder)) |
|
134 |
.as(attr.getName()); |
|
135 |
|
|
136 |
} |
|
137 |
|
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
96 | 148 |
if (this.query.hasGroupByColumns()) { |
97 | 149 |
if (this.query.hasOrder()) { |
98 | 150 |
FeatureQueryOrder order = query.getOrder(); |
... | ... | |
113 | 165 |
} |
114 | 166 |
} |
115 | 167 |
} |
116 |
subselect.column().value(subsqlbuilder.count().all()); |
|
117 | 168 |
subselect.from().table() |
118 | 169 |
.database(this.table.getDatabase()) |
119 | 170 |
.schema(this.table.getSchema()) |
... | ... | |
171 | 222 |
this.helper.processSpecialFunctions(subsqlbuilder, featureType, null); |
172 | 223 |
subsqlbuilder.setProperties( |
173 | 224 |
ExpressionBuilder.Variable.class, |
174 |
PROP_TABLE, table |
|
225 |
PROP_FEATURE_TYPE, this.featureType, |
|
226 |
PROP_TABLE, table, |
|
227 |
PROP_SYMBOLTABLE, this.query == null ? null : this.query.getSymbolTable(), |
|
228 |
PROP_JDBCHELPER, this.helper, |
|
229 |
PROP_QUERY, this.query |
|
175 | 230 |
); |
176 | 231 |
String subsql = subselect.toString(); |
177 | 232 |
select.from().table() |
... | ... | |
211 | 266 |
PROP_FEATURE_TYPE, this.featureType, |
212 | 267 |
PROP_TABLE, table, |
213 | 268 |
PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable(), |
214 |
PROP_JDBCHELPER, this.helper |
|
269 |
PROP_JDBCHELPER, this.helper, |
|
270 |
PROP_QUERY, this.query |
|
215 | 271 |
); |
216 | 272 |
|
217 | 273 |
String sql = select.toString(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/DALActionFactory.java | ||
---|---|---|
6 | 6 |
import org.gvsig.fmap.dal.DataStore; |
7 | 7 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
8 | 8 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
9 |
import org.gvsig.tools.util.IsApplicable; |
|
9 | 10 |
|
10 | 11 |
/** |
11 | 12 |
* |
12 | 13 |
* @author jjdelcerro |
13 | 14 |
*/ |
14 |
public interface DALActionFactory { |
|
15 |
public interface DALActionFactory extends IsApplicable {
|
|
15 | 16 |
|
16 | 17 |
public interface DALActionContext { |
17 | 18 |
public String getName(); |
... | ... | |
29 | 30 |
|
30 | 31 |
public String getName(); |
31 | 32 |
|
32 |
public boolean isApplicable(DALActionContext context); |
|
33 |
/** |
|
34 |
* Check if this factory is applicable to the first argument. |
|
35 |
* The first argument can be instanceof DALActionContext |
|
36 |
* @param args |
|
37 |
* @return |
|
38 |
*/ |
|
39 |
@Override |
|
40 |
public boolean isApplicable(Object... args); |
|
33 | 41 |
|
34 | 42 |
public Action createAction(DALActionContext context); |
35 | 43 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/AbstractDALActionFactory.java | ||
---|---|---|
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
@Override |
77 |
public boolean isApplicable(DALActionContext context) {
|
|
77 |
public boolean isApplicable(Object... args) {
|
|
78 | 78 |
return true; |
79 | 79 |
} |
80 | 80 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/featuretable/SimpleFeaturesTableModel.java | ||
---|---|---|
22 | 22 |
package org.gvsig.fmap.dal.swing.featuretable; |
23 | 23 |
|
24 | 24 |
import java.util.List; |
25 |
import java.util.Map; |
|
25 | 26 |
import javax.swing.JTable; |
27 |
import javax.swing.table.TableCellRenderer; |
|
26 | 28 |
import javax.swing.table.TableModel; |
27 | 29 |
import org.gvsig.fmap.dal.feature.Feature; |
28 | 30 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
41 | 43 |
|
42 | 44 |
public void setCellRenderers(JTable table); |
43 | 45 |
|
46 |
public void setCellRenderers(JTable table, Map<String, TableCellRenderer> renderers); |
|
47 |
|
|
44 | 48 |
public FeatureAttributeDescriptor getFeatureDescriptor(int columnIndex); |
45 | 49 |
|
46 | 50 |
public Feature getFeatureAt(int rowIndex); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/DefaultDataSwingManager.java | ||
---|---|---|
110 | 110 |
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel; |
111 | 111 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeListCellRenderer; |
112 | 112 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel; |
113 |
import org.gvsig.fmap.dal.swing.impl.actions.GraphAction.GraphActionFactory; |
|
113 | 114 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.CheckTableFieldsSuggestionProviderFactory; |
114 | 115 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.QuotesForFieldNameSuggestionProviderFactory; |
115 | 116 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.StorePointFieldSuggestionProviderFactory; |
... | ... | |
135 | 136 |
this.registerStoreAction(new SelectionFilterActionFactory()); |
136 | 137 |
this.registerStoreAction(new SelectionSetActionFactory()); |
137 | 138 |
this.registerStoreAction(new ShowFormActionFactory()); |
139 |
this.registerStoreAction(new GraphActionFactory()); |
|
138 | 140 |
|
139 | 141 |
this.searchPostProcess = new HashMap<>(); |
140 | 142 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/BaseStoresRepository.java | ||
---|---|---|
4 | 4 |
import java.util.Map; |
5 | 5 |
import java.util.Set; |
6 | 6 |
import org.apache.commons.lang3.StringUtils; |
7 |
import org.gvsig.tools.util.PropertiesSupport; |
|
7 | 8 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
8 | 9 |
import org.gvsig.tools.util.UnmodifiableBasicSetAdapter; |
9 | 10 |
|
... | ... | |
48 | 49 |
} |
49 | 50 |
return new UnmodifiableBasicSetAdapter<>(keyset); |
50 | 51 |
} |
51 |
|
|
52 |
|
|
53 |
public PropertiesSupport getProperties(String name) { |
|
54 |
return null; |
|
55 |
} |
|
56 |
|
|
52 | 57 |
@Override |
53 | 58 |
public void add(String name, DataStoreParameters parameters) { |
59 |
this.add(name, parameters, null); |
|
60 |
} |
|
61 |
|
|
62 |
public void add(String name, DataStoreParameters parameters, PropertiesSupport properties) { |
|
54 | 63 |
if( parameters == null ) { |
55 | 64 |
throw new IllegalArgumentException("parameters can't be null."); |
56 | 65 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/AbstractStoresRepository.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.ArrayList; |
4 | 4 |
import java.util.Collection; |
5 |
import java.util.Collections; |
|
5 | 6 |
import java.util.Iterator; |
6 | 7 |
import java.util.List; |
7 | 8 |
import java.util.Map; |
9 |
import java.util.Objects; |
|
8 | 10 |
import org.apache.commons.lang3.StringUtils; |
9 | 11 |
import org.gvsig.tools.observer.Notification; |
10 | 12 |
import org.gvsig.tools.observer.ObservableHelper; |
11 | 13 |
import org.gvsig.tools.observer.Observer; |
14 |
import org.gvsig.tools.util.PropertiesSupport; |
|
12 | 15 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
13 | 16 |
import org.gvsig.tools.util.UnmodifiableBasicSetChained; |
14 | 17 |
import org.slf4j.Logger; |
... | ... | |
157 | 160 |
} |
158 | 161 |
return null; |
159 | 162 |
} |
163 |
|
|
164 |
public PropertiesSupport getProperties(String name) { |
|
165 |
return new PropertiesSupport() { |
|
166 |
@Override |
|
167 |
public Object getProperty(String name) { |
|
168 |
return null; |
|
169 |
} |
|
160 | 170 |
|
171 |
@Override |
|
172 |
public void setProperty(String name, Object value) { |
|
173 |
|
|
174 |
} |
|
175 |
|
|
176 |
@Override |
|
177 |
public Map<String, Object> getProperties() { |
|
178 |
return Collections.EMPTY_MAP; |
|
179 |
} |
|
180 |
}; |
|
181 |
} |
|
182 |
|
|
161 | 183 |
@Override |
162 | 184 |
public DataStore getStore(String name) { |
185 |
PropertiesSupport properties = this.getProperties(name); |
|
186 |
if(properties!=null && |
|
187 |
StringUtils.equalsIgnoreCase(Objects.toString(properties.getProperty("ignoreDALResource")),"true")) { |
|
188 |
return this.getStore(name, true); |
|
189 |
} |
|
190 |
return this.getStore(name, false); |
|
191 |
} |
|
192 |
|
|
193 |
public DataStore getStore(String name, boolean ignoreDALResource) { |
|
163 | 194 |
DataStoreParameters parameters = this.getMyParameters(name); |
164 | 195 |
if( parameters!=null ) { |
165 | 196 |
try { |
166 | 197 |
DataStore store = DALLocator.getDataManager().openStore( |
167 | 198 |
parameters.getDataStoreName(), |
168 |
parameters |
|
199 |
parameters, |
|
200 |
ignoreDALResource |
|
169 | 201 |
); |
170 | 202 |
return store; |
171 | 203 |
} catch (Exception ex) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java | ||
---|---|---|
51 | 51 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
52 | 52 |
import org.gvsig.fmap.geom.Geometry; |
53 | 53 |
import org.gvsig.tools.dataTypes.DataType; |
54 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
|
54 | 55 |
import org.slf4j.Logger; |
55 | 56 |
import org.slf4j.LoggerFactory; |
56 | 57 |
|
... | ... | |
2600 | 2601 |
|
2601 | 2602 |
@Override |
2602 | 2603 |
public void setProperties(Class filter, final Object... values) { |
2604 |
this.expressionBuilder.setProperties(filter, values); |
|
2603 | 2605 |
this.accept(new Visitor() { |
2604 | 2606 |
@Override |
2605 | 2607 |
public void visit(Visitable v) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableManager.java | ||
---|---|---|
274 | 274 |
public AbstractDocument createDocumentByUser() { |
275 | 275 |
return (AbstractDocument) createDocumentsByUser().next(); |
276 | 276 |
} |
277 |
|
|
277 |
|
|
278 | 278 |
/** |
279 | 279 |
* Registers in the points of extension the Factory with alias. |
280 | 280 |
* |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/expressionbuilderformatter/H2SpatialFormatter.java | ||
---|---|---|
5 | 5 |
import org.gvsig.expressionevaluator.Formatter; |
6 | 6 |
import org.gvsig.fmap.dal.DALLocator; |
7 | 7 |
import org.gvsig.fmap.dal.SQLBuilder; |
8 |
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.$$Constant;
|
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.$$Identifier;
|
|
8 |
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.$Constant; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.$Identifier; |
|
10 | 10 |
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.ComputedAttribute; |
11 | 11 |
|
12 | 12 |
/** |
... | ... | |
37 | 37 |
new ST_AsBinary(this.builder, this), |
38 | 38 |
new Exists(this.builder, this), |
39 | 39 |
new Getattr(this.builder, this), |
40 |
new $$Constant(this.builder, this),
|
|
41 |
new $$Identifier(this.builder, this),
|
|
40 |
new $Constant(this.builder, this), |
|
41 |
new $Identifier(this.builder, this), |
|
42 | 42 |
new ComputedAttribute(this.builder, this), |
43 | 43 |
DALLocator.getDataManager().createDALExpressionBuilder().formatter(this), |
44 | 44 |
}; |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialHelper.java | ||
---|---|---|
168 | 168 |
|
169 | 169 |
String[] sqls = new String[] { |
170 | 170 |
"CREATE SCHEMA IF NOT EXISTS PUBLIC;SET SCHEMA PUBLIC", |
171 |
Json_value.getSQL(),
|
|
172 |
Reverse.getSQL(),
|
|
173 |
Reverseinstr.getSQL()
|
|
171 |
Json_value.getSQL(),
|
|
172 |
Reverse.getSQL(),
|
|
173 |
Reverseinstr.getSQL()
|
|
174 | 174 |
}; |
175 | 175 |
for (String sql : sqls) { |
176 | 176 |
try { |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/resources/org/gvsig/fmap/dal/store/h2/resultSetForSetProvider.sql | ||
---|---|---|
57 | 57 |
"Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", |
58 | 58 |
NVL2("Geometry",ST_AsBinary("Geometry"),NULL), "ID" |
59 | 59 |
FROM "PUBLIC"."test" ORDER BY "ID" ASC; |
60 |
|
|
61 |
-- Computed Attribute |
|
62 |
SELECT "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", |
|
63 |
"Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", |
|
64 |
NVL2("Geometry",ST_AsBinary("Geometry"),NULL), |
|
65 |
("ID" * 2) AS "Compu1" |
|
66 |
FROM "PUBLIC"."test" ORDER BY "ID" ASC; |
|
67 |
|
|
68 |
-- Computed Attribute 2 |
|
69 |
SELECT "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", |
|
70 |
"Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", |
|
71 |
NVL2("Geometry",ST_AsBinary("Geometry"),NULL), |
|
72 |
("ID" * 2) AS "Compu1", |
|
73 |
(("Long" + 10) + (("ID" * 2))) AS "Compu2" |
|
74 |
FROM "PUBLIC"."test" ORDER BY "ID" ASC; |
|
75 |
|
|
76 |
-- Computed Extra column 1 |
|
77 |
SELECT "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", |
|
78 |
"Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", |
|
79 |
NVL2("Geometry",ST_AsBinary("Geometry"),NULL), |
|
80 |
("ID" * 2) AS "Compu1", |
|
81 |
(("Long" + 10) + (("ID" * 2))) AS "Extra1" |
|
82 |
FROM "PUBLIC"."test" ORDER BY "ID" ASC; |
|
83 |
|
|
84 |
-- Computed Extra column 2 |
|
85 |
SELECT "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", |
|
86 |
"Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", |
|
87 |
NVL2("Geometry",ST_AsBinary("Geometry"),NULL), |
|
88 |
("ID" * 2) AS "Extra1", |
|
89 |
(("Long" + 10) + (("ID" * 2))) AS "Extra2" |
|
90 |
FROM "PUBLIC"."test" ORDER BY "ID" ASC; |
|
91 |
|
|
92 |
-- Computed Extra column with where |
|
93 |
SELECT "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", |
|
94 |
"Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", |
|
95 |
NVL2("Geometry",ST_AsBinary("Geometry"),NULL), |
|
96 |
("ID" * 2) AS "Compu1", |
|
97 |
(("Long" + 10) + (("ID" * 2))) AS "Extra1" |
|
98 |
FROM "PUBLIC"."test" WHERE (((("Long" + 10) + (("ID" * 2)))) > 10) ORDER BY ((("Long" + 10) + (("ID" * 2)))) ASC, "ID" ASC; |
|
99 |
|
|
100 |
-- Group by with computed columns and aggregate functions |
|
101 |
SELECT MIN("test"."ID") AS "ID", MAX("test"."Byte") AS "Byte", NULL AS "Bool1", "Long", |
|
102 |
NULL AS "Timestamp", NULL AS "Date", NULL AS "Time", NULL AS "Bool2", |
|
103 |
NULL AS "String", NULL AS "Bool3", SUM("test"."Double") AS "Double", |
|
104 |
NULL AS "Bool4", NULL AS "Float", NULL AS "Bool5", NULL AS "Decimal", |
|
105 |
NULL AS "Geometry", |
|
106 |
("ID" * 2) AS "Compu1", |
|
107 |
SUM(("Long" + 300)) AS "Compu2", |
|
108 |
SUM(((20 + "Byte") + (("ID" * 2)))) AS "Extra2", |
|
109 |
(("Long" + 10) + (("ID" * 2))) AS "Extra1" |
|
110 |
FROM "PUBLIC"."test" GROUP BY "test"."Long", "Extra1", "Compu1" ORDER BY "ID" ASC; |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/resources/org/gvsig/fmap/dal/store/h2/testCreateSource2.csv | ||
---|---|---|
1 |
ID/Integer/set/pk=true;Comunidad/String/set/size=10;Provincia/String/set/size=10;Ciudad/String/set/size=10;Poblacion/Integer;Densidad/Double;Fecha/TimeStamp |
|
2 |
0;;;;;; |
|
3 |
1;GVA;Valencia;Cullera;1000;1.01;20191229121314 |
|
4 |
2;GVA;Valencia;Pinedo;500;2.02;20191229121314 |
|
5 |
3;GVA;Valencia;Gandia;300;3.03;20201229121314 |
|
6 |
4;GVA;Valencia;Sueca;50;4.04;20201229121314 |
|
7 |
5;GVA;Alicante;Calpe;200;5.05;20191229121314 |
|
8 |
6;GVA;Alicante;Cullera;400;6.06;20201229121314 |
|
9 |
7;GVA;Alicante;Oliva;20;7,07;20201229121314 |
|
10 |
8;GVA;Castellon;Nules;100;8.08;20191229121314 |
|
11 |
9;GVA;Castellon;Oropesa;600;9.09;20191229121314 |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/TestUtils.java | ||
---|---|---|
94 | 94 |
); |
95 | 95 |
return store; |
96 | 96 |
} |
97 |
|
|
98 |
public static FeatureStore openSourceStore2() throws Exception { |
|
99 |
DataManager dataManager = DALLocator.getDataManager(); |
|
100 |
File f = getResourceAsFile("/org/gvsig/fmap/dal/store/h2/testCreateSource2.csv"); |
|
101 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
|
102 |
DataStore.CSV_PROVIDER_NAME, |
|
103 |
"file=",f, |
|
104 |
"automaticTypesDetection=", false, |
|
105 |
"locale=","en" |
|
106 |
); |
|
107 |
return store; |
|
108 |
} |
|
97 | 109 |
|
98 | 110 |
|
99 | 111 |
public static List<String> getSQLs(String name) throws Exception { |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/TestCreate.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.h2; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
3 | 4 |
import java.util.Date; |
4 | 5 |
import java.util.List; |
5 | 6 |
import junit.framework.TestCase; |
... | ... | |
12 | 13 |
import org.gvsig.fmap.dal.DataStore; |
13 | 14 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
14 | 15 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
16 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
15 | 17 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
16 | 18 |
import org.gvsig.fmap.dal.feature.Feature; |
17 | 19 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
19 | 21 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
20 | 22 |
import org.gvsig.fmap.dal.feature.FeatureType; |
21 | 23 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
24 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
22 | 25 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
23 | 26 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
27 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
24 | 28 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
25 | 29 |
import org.slf4j.Logger; |
26 | 30 |
import org.slf4j.LoggerFactory; |
... | ... | |
307 | 311 |
List<Feature> features = h2Store.getFeatures(query); |
308 | 312 |
int sz = features.size(); |
309 | 313 |
} |
314 |
|
|
315 |
public void testComputed1() throws Exception { |
|
316 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
317 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
318 |
|
|
319 |
createFrom(explorer, sourceStore); |
|
320 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
321 |
|
|
322 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
323 |
h2Store.edit(); |
|
324 |
FeatureType featureType = h2Store.getDefaultFeatureType(); |
|
325 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
326 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
327 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
328 |
h2Store.update(eFeatureType); |
|
329 |
h2Store.finishEditing(); |
|
330 |
List<Feature> features = h2Store.getFeatures(); |
|
331 |
for (int i = 0; i < features.size(); i++) { |
|
332 |
Feature feature = features.get(i); |
|
333 |
assertEquals("Compu1 "+i, feature.getInt("ID") * 2, feature.getInt("Compu1")); |
|
334 |
if(feature.get("Long")==null) { |
|
335 |
assertEquals("Compu2 "+i, null, feature.get("Compu2")); |
|
336 |
} else { |
|
337 |
assertEquals("Compu2 "+i, feature.getInt("Long") + 10 + feature.getInt("Compu1"), feature.getInt("Compu2")); |
|
338 |
} |
|
339 |
} |
|
340 |
DisposeUtils.dispose(h2Store); |
|
341 |
} |
|
342 |
|
|
343 |
public void testComputed2() throws Exception { |
|
344 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
345 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
346 |
|
|
347 |
createFrom(explorer, sourceStore); |
|
348 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
349 |
|
|
350 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
351 |
h2Store.edit(); |
|
352 |
FeatureType featureType = h2Store.getDefaultFeatureType(); |
|
353 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
354 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
355 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("MOD(ID,10)"))); |
|
356 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+300"))); |
|
357 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
358 |
EditableFeatureAttributeDescriptor extraColumn2 = query.getExtraColumn().add("Extra2", DataTypes.INTEGER); |
|
359 |
// EditableFeatureAttributeDescriptor extraColumn3 = query.getExtraColumn().add("LongMax", DataTypes.INTEGER); |
|
360 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Compu1+1"))); |
|
361 |
extraColumn2.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("20+Byte"))); |
|
362 |
// extraColumn3.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long"))); |
|
363 |
query.getGroupByColumns().add("Decimal"); |
|
364 |
query.getGroupByColumns().add("Extra1"); |
|
365 |
// query.getGroupByColumns().add("Compu1"); |
|
366 |
query.getAggregateFunctions().put("ID", "MIN"); |
|
367 |
query.getAggregateFunctions().put("Byte", "MIN"); |
|
368 |
// query.getAggregateFunctions().put("Long", "MIN"); |
|
369 |
// query.getAggregateFunctions().put("LongMax", "MAX"); |
|
370 |
query.getAggregateFunctions().put("Compu1", "MIN"); |
|
371 |
query.getAggregateFunctions().put("Double", "SUM"); |
|
372 |
query.getAggregateFunctions().put("Extra2", "SUM"); |
|
373 |
query.getAggregateFunctions().put("Compu2", "SUM"); |
|
374 |
h2Store.update(eFeatureType); |
|
375 |
h2Store.finishEditing(); |
|
376 |
|
|
377 |
|
|
378 |
List<Feature> features0 = h2Store.getFeatures(query); |
|
379 |
ArrayList<Feature> features = new ArrayList<>(); |
|
380 |
|
|
381 |
for (int i = 0; i < features0.size(); i++) { |
|
382 |
Feature feature = features0.get(i); |
|
383 |
features.add(feature.getCopy()); |
|
384 |
} |
|
385 |
features0 = null; |
|
386 |
features.get(1).get("Compu1"); |
|
387 |
features.get(1).get("Compu2"); |
|
388 |
// assertEquals("Long0",null,features.get(0).get("Long")); |
|
389 |
// assertEquals("Long1",null,features.get(1).get("Long")); |
|
390 |
// assertEquals("Long2",1000L,features.get(2).getLong("Long")); |
|
391 |
// assertEquals("Long3",1001L,features.get(3).getLong("Long")); |
|
392 |
// assertEquals("Long4",2000L,features.get(4).getLong("Long")); |
|
393 |
// assertEquals("Long5",2002L,features.get(5).getLong("Long")); |
|
394 |
// assertEquals("Long6",3000L,features.get(6).getLong("Long")); |
|
395 |
// assertEquals("Long7",4000L,features.get(7).getLong("Long")); |
|
396 |
// assertEquals("Long8",4001L,features.get(8).getLong("Long")); |
|
397 |
// assertEquals("Long9",5000L,features.get(9).getLong("Long")); |
|
398 |
// assertEquals("Long10",5002L,features.get(10).getLong("Long")); |
|
399 |
// assertEquals("Long11",6000L,features.get(11).getLong("Long")); |
|
400 |
// assertEquals("Long12",6003L,features.get(12).getLong("Long")); |
|
401 |
// assertEquals("Long13",7000L,features.get(13).getLong("Long")); |
|
402 |
// assertEquals("Long14",7004L,features.get(14).getLong("Long")); |
|
403 |
// assertEquals("Long15",8000L,features.get(15).getLong("Long")); |
|
404 |
// assertEquals("Long16",8005L,features.get(16).getLong("Long")); |
|
405 |
// assertEquals("Long17",9000L,features.get(17).getLong("Long")); |
|
406 |
// assertEquals("Long18",9006L,features.get(18).getLong("Long")); |
|
407 |
|
|
408 |
// for (int i = 0; i < features.size(); i++) { |
|
409 |
// Feature feature = features.get(i); |
|
410 |
// assertEquals("Long", feature.getInt("ID") * 2, feature.getInt("Compu1")); |
|
411 |
// assertEquals("Compu2", feature.getInt("Long") + 10 + feature.getInt("Compu1"), feature.getInt("Compu2")); |
|
412 |
// } |
|
413 |
DisposeUtils.dispose(h2Store); |
|
414 |
} |
|
415 |
|
|
416 |
|
|
310 | 417 |
|
311 | 418 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/operations/sql/TestResultSetForSetProvider.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 | 4 |
import junit.framework.TestCase; |
5 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
6 |
import org.gvsig.fmap.dal.DataTypes; |
|
7 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
8 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
5 | 9 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
6 | 10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
7 | 11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
12 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
8 | 13 |
import org.gvsig.fmap.dal.store.h2.TestUtils; |
9 | 14 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
10 | 15 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
... | ... | |
65 | 70 |
String sql = resultSetForSetProvider.getSQL(); |
66 | 71 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(0), sql); |
67 | 72 |
} |
73 |
public void testComputedAttribute() throws Exception { |
|
74 |
try { |
|
75 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
76 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
77 |
OperationsFactory operations = helper.getOperations(); |
|
68 | 78 |
|
79 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
80 |
|
|
81 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
82 |
|
|
83 |
TableReference table = operations.createTableReference( |
|
84 |
"dbtest", |
|
85 |
sqlbuilder.default_schema(), |
|
86 |
"test", |
|
87 |
null |
|
88 |
); |
|
89 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
90 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
91 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
92 |
|
|
93 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
94 |
table, |
|
95 |
null, |
|
96 |
null, |
|
97 |
null, |
|
98 |
eFeatureType, |
|
99 |
eFeatureType, |
|
100 |
0, |
|
101 |
0, |
|
102 |
0 |
|
103 |
); |
|
104 |
String sql = resultSetForSetProvider.getSQL(); |
|
105 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(5), sql); |
|
106 |
} catch (Exception ex) { |
|
107 |
ex.printStackTrace(); |
|
108 |
throw ex; |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
public void testComputedAttribute2() throws Exception { |
|
113 |
try { |
|
114 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
115 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
116 |
OperationsFactory operations = helper.getOperations(); |
|
117 |
|
|
118 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
119 |
|
|
120 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
121 |
|
|
122 |
TableReference table = operations.createTableReference( |
|
123 |
"dbtest", |
|
124 |
sqlbuilder.default_schema(), |
|
125 |
"test", |
|
126 |
null |
|
127 |
); |
|
128 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
129 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
130 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
131 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
132 |
|
|
133 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
134 |
table, |
|
135 |
null, |
|
136 |
null, |
|
137 |
null, |
|
138 |
eFeatureType, |
|
139 |
eFeatureType, |
|
140 |
0, |
|
141 |
0, |
|
142 |
0 |
|
143 |
); |
|
144 |
String sql = resultSetForSetProvider.getSQL(); |
|
145 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(6), sql); |
|
146 |
} catch (Exception ex) { |
|
147 |
ex.printStackTrace(); |
|
148 |
throw ex; |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
public void testComputedExtraColumn() throws Exception { |
|
153 |
try { |
|
154 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
155 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
156 |
OperationsFactory operations = helper.getOperations(); |
|
157 |
|
|
158 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
159 |
|
|
160 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
161 |
|
|
162 |
TableReference table = operations.createTableReference( |
|
163 |
"dbtest", |
|
164 |
sqlbuilder.default_schema(), |
|
165 |
"test", |
|
166 |
null |
|
167 |
); |
|
168 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
169 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
170 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
171 |
|
|
172 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
173 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
174 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
175 |
|
|
176 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
177 |
table, |
|
178 |
null, |
|
179 |
null, |
|
180 |
query, |
|
181 |
eFeatureType, |
|
182 |
eFeatureType, |
|
183 |
0, |
|
184 |
0, |
|
185 |
0 |
|
186 |
); |
|
187 |
String sql = resultSetForSetProvider.getSQL(); |
|
188 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(7), sql); |
|
189 |
} catch (Exception ex) { |
|
190 |
ex.printStackTrace(); |
|
191 |
throw ex; |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
public void testComputedExtraColumn2() throws Exception { |
|
196 |
try { |
|
197 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
198 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
199 |
OperationsFactory operations = helper.getOperations(); |
|
200 |
|
|
201 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
202 |
|
|
203 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
204 |
|
|
205 |
TableReference table = operations.createTableReference( |
|
206 |
"dbtest", |
|
207 |
sqlbuilder.default_schema(), |
|
208 |
"test", |
|
209 |
null |
|
210 |
); |
|
211 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
212 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
213 |
|
|
214 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
215 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
216 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
217 |
EditableFeatureAttributeDescriptor extraColumn2 = query.getExtraColumn().add("Extra2", DataTypes.INTEGER); |
|
218 |
extraColumn2.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Extra1"))); |
|
219 |
|
|
220 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
221 |
table, |
|
222 |
null, |
|
223 |
null, |
|
224 |
query, |
|
225 |
eFeatureType, |
|
226 |
eFeatureType, |
|
227 |
0, |
|
228 |
0, |
|
229 |
0 |
|
230 |
); |
|
231 |
String sql = resultSetForSetProvider.getSQL(); |
|
232 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(8), sql); |
|
233 |
} catch (Exception ex) { |
|
234 |
ex.printStackTrace(); |
|
235 |
throw ex; |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
public void testComputedExtraColumnWithWhere() throws Exception { |
|
240 |
try { |
|
241 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
242 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
243 |
OperationsFactory operations = helper.getOperations(); |
|
244 |
|
|
245 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
246 |
|
|
247 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
248 |
|
|
249 |
TableReference table = operations.createTableReference( |
|
250 |
"dbtest", |
|
251 |
sqlbuilder.default_schema(), |
|
252 |
"test", |
|
253 |
null |
|
254 |
); |
|
255 |
|
|
256 |
StringBuilder filter = new StringBuilder(); |
|
257 |
filter.append("Extra1 > 10"); |
|
258 |
|
|
259 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
260 |
|
|
261 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
262 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
263 |
|
|
264 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
265 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
266 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
267 |
query.addFilter(filter.toString()); |
|
268 |
query.getOrder().add("Extra1"); |
|
269 |
|
|
270 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
271 |
table, |
|
272 |
null, |
|
273 |
null, |
|
274 |
query, |
Also available in: Unified diff