Revision 46505
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/SQLBuilder.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 | 4 |
import org.cresques.cts.IProjection; |
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
5 | 6 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter; |
6 | 7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
7 | 8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable; |
9 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Visitable; |
|
8 | 10 |
import org.gvsig.expressionevaluator.Formatter; |
9 | 11 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
10 | 12 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
11 | 13 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
12 |
import org.gvsig.fmap.geom.Geometry; |
|
13 | 14 |
import org.gvsig.fmap.geom.primitive.Envelope; |
14 | 15 |
|
15 |
public interface SQLBuilder { |
|
16 |
public interface SQLBuilder extends Visitable {
|
|
16 | 17 |
|
17 | 18 |
public static final String FEATURE_ATTRIBUTE_DESCRIPTOR = "FeatureAttributeDescriptor"; |
18 | 19 |
|
... | ... | |
120 | 121 |
public boolean has_database(); |
121 | 122 |
|
122 | 123 |
public boolean has_schema(); |
124 |
|
|
125 |
public boolean has_name(); |
|
123 | 126 |
} |
124 | 127 |
|
125 | 128 |
public interface CountBuilder extends StatementPart { |
... | ... | |
149 | 152 |
|
150 | 153 |
public String getAlias(); |
151 | 154 |
|
152 |
public String getValue();
|
|
155 |
public Value getValue();
|
|
153 | 156 |
|
154 | 157 |
public boolean isGeometry(); |
155 | 158 |
|
... | ... | |
228 | 231 |
public interface SelectBuilder extends Statement { |
229 | 232 |
|
230 | 233 |
public SelectColumnBuilder column(); |
234 |
|
|
235 |
public SelectColumnBuilder column(String name); |
|
231 | 236 |
|
232 | 237 |
public SelectBuilder remove_all_columns(); |
233 | 238 |
|
... | ... | |
295 | 300 |
|
296 | 301 |
public void remove_column(String columnName); |
297 | 302 |
|
303 |
public boolean isGroupBy(String name); |
|
304 |
|
|
298 | 305 |
} |
299 | 306 |
|
300 | 307 |
public interface UpdateBuilder extends Statement { |
... | ... | |
533 | 540 |
public Column column(TableNameBuilder table, String name); |
534 | 541 |
|
535 | 542 |
public void setProperties(Class classToApply, Object... values); |
543 |
|
|
544 |
public void setProperties(ExpressionBuilder.Visitable visitable, Class filter, final Object... values); |
|
536 | 545 |
|
537 | 546 |
public Formatter formatter(); |
538 | 547 |
|
539 | 548 |
public boolean isAggregateFunction(String funcname); |
540 | 549 |
|
541 | 550 |
public int getMaxRecomendedSQLLength(); |
551 |
|
|
552 |
public SelectBuilder createSelectBuilder(); |
|
553 |
|
|
542 | 554 |
} |
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/feature/FeatureQuery.java | ||
---|---|---|
340 | 340 |
public String getAggregate(String name); |
341 | 341 |
|
342 | 342 |
public String getAggregate(String tableName, String name); |
343 |
|
|
344 |
public boolean isAggregate(String name); |
|
343 | 345 |
|
344 | 346 |
public boolean hasAggregateFunctions(); |
345 | 347 |
|
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 | ||
---|---|---|
19 | 19 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT; |
20 | 20 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE; |
21 | 21 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter; |
22 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.VALUE_NULL; |
|
22 | 23 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
23 | 24 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable; |
24 | 25 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Visitable; |
... | ... | |
54 | 55 |
import org.gvsig.fmap.geom.primitive.Envelope; |
55 | 56 |
import org.gvsig.tools.dataTypes.DataType; |
56 | 57 |
import org.gvsig.tools.dynobject.Tags; |
58 |
import org.gvsig.tools.util.PropertiesSupport; |
|
57 | 59 |
import org.slf4j.Logger; |
58 | 60 |
import org.slf4j.LoggerFactory; |
59 | 61 |
|
... | ... | |
480 | 482 |
if (!support_schemas()) { |
481 | 483 |
return false; |
482 | 484 |
} |
483 |
return !StringUtils.isEmpty(this.schemaName);
|
|
485 |
return !StringUtils.isBlank(this.schemaName);
|
|
484 | 486 |
} |
485 | 487 |
|
486 | 488 |
@Override |
489 |
public boolean has_name() { |
|
490 |
return !StringUtils.isBlank(this.tableName); |
|
491 |
} |
|
492 |
|
|
493 |
@Override |
|
487 | 494 |
public boolean has_database() { |
488 |
return !StringUtils.isEmpty(this.databaseName);
|
|
495 |
return !StringUtils.isBlank(this.databaseName);
|
|
489 | 496 |
} |
490 | 497 |
|
491 | 498 |
@Override |
... | ... | |
713 | 720 |
|
714 | 721 |
@Override |
715 | 722 |
public void accept(Visitor visitor, VisitorFilter filter) { |
723 |
boolean visitChildren = true; |
|
716 | 724 |
if (filter==null || filter.accept(this)) { |
717 | 725 |
visitor.visit(this); |
726 |
} else { |
|
727 |
visitChildren = !filter.skipChildren(); |
|
718 | 728 |
} |
719 |
if (this.tableName != null) { |
|
720 |
this.tableName.accept(visitor, filter); |
|
729 |
if(visitChildren){ |
|
730 |
if (this.tableName != null) { |
|
731 |
this.tableName.accept(visitor, filter); |
|
732 |
} |
|
721 | 733 |
} |
722 | 734 |
} |
723 | 735 |
|
... | ... | |
767 | 779 |
extends AbstractStatementPart |
768 | 780 |
implements SelectColumnBuilder { |
769 | 781 |
|
770 |
protected Variable name = null;
|
|
782 |
protected Column name = null;
|
|
771 | 783 |
protected String alias = null; |
772 | 784 |
protected Value value = null; |
773 | 785 |
protected boolean asGeometry = false; |
... | ... | |
782 | 794 |
public SelectColumnBuilderBase clone() throws CloneNotSupportedException { |
783 | 795 |
SelectColumnBuilderBase other = (SelectColumnBuilderBase) super.clone(); |
784 | 796 |
other.value = (Value) org.gvsig.tools.lang.Cloneable.cloneQuietly(value); |
785 |
other.name = (Variable) org.gvsig.tools.lang.Cloneable.cloneQuietly(name);
|
|
797 |
other.name = (Column) org.gvsig.tools.lang.Cloneable.cloneQuietly(name);
|
|
786 | 798 |
other.table = (TableNameBuilder) org.gvsig.tools.lang.Cloneable.cloneQuietly(table); |
787 | 799 |
return other; |
788 | 800 |
} |
789 | 801 |
|
790 | 802 |
@Override |
791 | 803 |
public void accept(Visitor visitor, VisitorFilter filter) { |
804 |
boolean visitChildren = true; |
|
792 | 805 |
if (filter==null || filter.accept(this)) { |
793 | 806 |
visitor.visit(this); |
807 |
} else { |
|
808 |
visitChildren = !filter.skipChildren(); |
|
794 | 809 |
} |
795 |
if (this.name != null) { |
|
796 |
this.name.accept(visitor, filter); |
|
810 |
if(visitChildren){ |
|
811 |
if (this.value != null) { |
|
812 |
this.value.accept(visitor, filter); |
|
813 |
} else if (this.name != null) { |
|
814 |
this.name.accept(visitor, filter); |
|
815 |
} |
|
797 | 816 |
} |
798 |
if (this.value != null) { |
|
799 |
this.value.accept(visitor, filter); |
|
800 |
} |
|
801 | 817 |
} |
802 | 818 |
|
803 | 819 |
@Override |
804 | 820 |
public void replace(Value target, Value replacement) { |
805 | 821 |
if (this.name!=null ) { |
806 | 822 |
if( this.name == target) { |
807 |
this.name = (Variable) replacement; |
|
823 |
if(replacement == null){ |
|
824 |
this.name = null; |
|
825 |
} else if(replacement instanceof Column){ |
|
826 |
this.name = (Column) replacement; |
|
827 |
} else if(replacement instanceof Variable){ |
|
828 |
this.name = new ColumnBase(this.table, ((Variable) replacement).name()); |
|
829 |
} else { |
|
830 |
this.value = replacement; |
|
831 |
} |
|
808 | 832 |
} |
809 | 833 |
} |
810 | 834 |
if( this.value!=null ) { |
... | ... | |
828 | 852 |
// Remove quotes |
829 | 853 |
name = name.substring(1, name.length() - 1); |
830 | 854 |
} |
831 |
this.name = expression().variable(name); |
|
832 | 855 |
this.table = table; |
856 |
this.name = new ColumnBase(this.table, name); |
|
833 | 857 |
this.value = null; |
834 | 858 |
this.asGeometry = false; |
835 | 859 |
return this; |
... | ... | |
852 | 876 |
@Override |
853 | 877 |
public SelectColumnBuilder value(Value value) { |
854 | 878 |
this.value = value; |
855 |
this.name = null; |
|
856 | 879 |
return this; |
857 | 880 |
} |
858 | 881 |
|
... | ... | |
876 | 899 |
} |
877 | 900 |
|
878 | 901 |
@Override |
879 |
public String getValue() {
|
|
880 |
return this.alias;
|
|
902 |
public Value getValue() {
|
|
903 |
return this.value;
|
|
881 | 904 |
} |
882 | 905 |
|
883 | 906 |
@Override |
... | ... | |
892 | 915 |
} |
893 | 916 |
StringBuilder builder = new StringBuilder(); |
894 | 917 |
if (this.asGeometry) { |
895 |
builder.append(expression().ST_AsBinary(this.name).toString(formatter)); |
|
918 |
if(this.value == VALUE_NULL){ |
|
919 |
builder.append(this.value.toString(formatter)); |
|
920 |
} else { |
|
921 |
builder.append(expression().ST_AsBinary(this.name).toString(formatter)); |
|
922 |
} |
|
896 | 923 |
} else { |
897 |
if (this.name != null) { |
|
898 |
if( this.table==null ) { |
|
899 |
builder.append(this.name.toString(formatter)); |
|
900 |
} else { |
|
901 |
builder.append(this.table.toString(formatter)); |
|
902 |
builder.append("."); |
|
903 |
builder.append(this.name.toString(formatter)); |
|
904 |
} |
|
924 |
if (this.value == null) { |
|
925 |
builder.append(this.name.toString(formatter)); |
|
905 | 926 |
} else { |
906 | 927 |
builder.append(this.value.toString(formatter)); |
907 | 928 |
} |
... | ... | |
959 | 980 |
|
960 | 981 |
@Override |
961 | 982 |
public void accept(Visitor visitor, VisitorFilter filter) { |
983 |
boolean visitChildren = true; |
|
962 | 984 |
if (filter==null || filter.accept(this)) { |
963 | 985 |
visitor.visit(this); |
986 |
} else { |
|
987 |
visitChildren = !filter.skipChildren(); |
|
964 | 988 |
} |
965 |
if (this.value!=null) { |
|
966 |
this.value.accept(visitor, filter); |
|
989 |
if(visitChildren){ |
|
990 |
if (this.value!=null) { |
|
991 |
this.value.accept(visitor, filter); |
|
992 |
} |
|
967 | 993 |
} |
968 | 994 |
} |
969 | 995 |
|
... | ... | |
1062 | 1088 |
} |
1063 | 1089 |
return order_s; |
1064 | 1090 |
} |
1091 |
|
|
1092 |
@Override |
|
1093 |
public void replace(Value target, Value replacement) { |
|
1094 |
super.replace(target, replacement); |
|
1095 |
if(target == this.value){ |
|
1096 |
this.value = replacement; |
|
1097 |
return; |
|
1098 |
} |
|
1099 |
if(this.value == null){ |
|
1100 |
return; |
|
1101 |
} |
|
1102 |
this.value.replace(target, replacement); |
|
1103 |
} |
|
1104 |
|
|
1105 |
|
|
1065 | 1106 |
} |
1066 | 1107 |
|
1067 | 1108 |
public class SelectBuilderBase |
... | ... | |
1120 | 1161 |
|
1121 | 1162 |
@Override |
1122 | 1163 |
public void accept(Visitor visitor, VisitorFilter filter) { |
1164 |
boolean visitChildren = true; |
|
1123 | 1165 |
if (filter==null || filter.accept(this)) { |
1124 | 1166 |
visitor.visit(this); |
1167 |
} else { |
|
1168 |
visitChildren = !filter.skipChildren(); |
|
1125 | 1169 |
} |
1126 |
for (SelectColumnBuilder column : columns) { |
|
1127 |
column.accept(visitor, filter); |
|
1128 |
} |
|
1129 |
if (this.has_from()) { |
|
1130 |
this.from.accept(visitor, filter); |
|
1131 |
} |
|
1132 |
if (this.has_where()) { |
|
1133 |
this.where.accept(visitor, filter); |
|
1134 |
} |
|
1135 |
if (this.has_order_by()) { |
|
1136 |
for (OrderByBuilder order : order_by) { |
|
1137 |
order.accept(visitor, filter); |
|
1170 |
if(visitChildren){ |
|
1171 |
for (SelectColumnBuilder column : columns) { |
|
1172 |
column.accept(visitor, filter); |
|
1138 | 1173 |
} |
1139 |
} |
|
1140 |
if (this.has_group_by()) { |
|
1141 |
for (Value group : groupColumn) { |
|
1142 |
group.accept(visitor, filter); |
|
1174 |
if (this.has_from()) { |
|
1175 |
this.from.accept(visitor, filter); |
|
1143 | 1176 |
} |
1177 |
if (this.has_where()) { |
|
1178 |
this.where.accept(visitor, filter); |
|
1179 |
} |
|
1180 |
if (this.has_order_by()) { |
|
1181 |
for (OrderByBuilder order : order_by) { |
|
1182 |
order.accept(visitor, filter); |
|
1183 |
} |
|
1184 |
} |
|
1185 |
if (this.has_group_by()) { |
|
1186 |
for (Value group : groupColumn) { |
|
1187 |
group.accept(visitor, filter); |
|
1188 |
} |
|
1189 |
} |
|
1144 | 1190 |
} |
1145 | 1191 |
} |
1146 | 1192 |
|
... | ... | |
1208 | 1254 |
} |
1209 | 1255 |
|
1210 | 1256 |
@Override |
1257 |
public SelectColumnBuilder column(String name) { |
|
1258 |
for (SelectColumnBuilder column : columns) { |
|
1259 |
if (StringUtils.equals(name, column.getName())) { |
|
1260 |
return column; |
|
1261 |
} |
|
1262 |
} |
|
1263 |
SelectColumnBuilder builder = createSelectColumnBuilder(); |
|
1264 |
builder.name(name); |
|
1265 |
this.columns.add(builder); |
|
1266 |
return builder; |
|
1267 |
} |
|
1268 |
|
|
1269 |
@Override |
|
1211 | 1270 |
public SelectBuilder remove_all_columns() { |
1212 | 1271 |
this.columns = new ArrayList<>(); |
1213 | 1272 |
return this; |
... | ... | |
1322 | 1381 |
} |
1323 | 1382 |
return null; |
1324 | 1383 |
} |
1384 |
|
|
1385 |
@Override |
|
1386 |
public boolean isGroupBy(String column) { |
|
1387 |
if(this.groupColumn == null){ |
|
1388 |
return false; |
|
1389 |
} |
|
1390 |
for (Value group : this.groupColumn) { |
|
1391 |
if(group instanceof Variable){ |
|
1392 |
if(StringUtils.equalsIgnoreCase(((Variable)group).name(), column)){ |
|
1393 |
return true; |
|
1394 |
} |
|
1395 |
} |
|
1396 |
} |
|
1397 |
return false; |
|
1398 |
} |
|
1325 | 1399 |
|
1326 | 1400 |
@Override |
1327 | 1401 |
public boolean has_order_by() { |
... | ... | |
1460 | 1534 |
|
1461 | 1535 |
@Override |
1462 | 1536 |
public void accept(Visitor visitor, VisitorFilter filter) { |
1537 |
boolean visitChildren = true; |
|
1463 | 1538 |
if (filter==null || filter.accept(this)) { |
1464 | 1539 |
visitor.visit(this); |
1540 |
} else { |
|
1541 |
visitChildren = !filter.skipChildren(); |
|
1465 | 1542 |
} |
1466 |
this.table.accept(visitor, filter); |
|
1543 |
if(visitChildren){ |
|
1544 |
this.table.accept(visitor, filter); |
|
1545 |
} |
|
1467 | 1546 |
} |
1468 | 1547 |
|
1469 | 1548 |
@Override |
... | ... | |
1679 | 1758 |
|
1680 | 1759 |
@Override |
1681 | 1760 |
public void accept(Visitor visitor, VisitorFilter filter) { |
1761 |
boolean visitChildren = true; |
|
1682 | 1762 |
if (filter==null || filter.accept(this)) { |
1683 | 1763 |
visitor.visit(this); |
1764 |
} else { |
|
1765 |
visitChildren = !filter.skipChildren(); |
|
1684 | 1766 |
} |
1685 |
if (this.table != null) { |
|
1686 |
this.table.accept(visitor, filter); |
|
1767 |
if(visitChildren){ |
|
1768 |
if (this.table != null) { |
|
1769 |
this.table.accept(visitor, filter); |
|
1770 |
} |
|
1687 | 1771 |
} |
1688 | 1772 |
} |
1689 | 1773 |
|
... | ... | |
1772 | 1856 |
|
1773 | 1857 |
@Override |
1774 | 1858 |
public void accept(Visitor visitor, VisitorFilter filter) { |
1859 |
boolean visitChildren = true; |
|
1775 | 1860 |
if (filter==null || filter.accept(this)) { |
1776 | 1861 |
visitor.visit(this); |
1862 |
} else { |
|
1863 |
visitChildren = !filter.skipChildren(); |
|
1777 | 1864 |
} |
1778 |
if (this.table != null) { |
|
1779 |
this.table.accept(visitor, filter); |
|
1865 |
if(visitChildren){ |
|
1866 |
if (this.table != null) { |
|
1867 |
this.table.accept(visitor, filter); |
|
1868 |
} |
|
1869 |
for (UpdateColumnBuilder column : columns) { |
|
1870 |
column.accept(visitor, filter); |
|
1871 |
} |
|
1872 |
if (this.has_where()) { |
|
1873 |
this.where.accept(visitor, filter); |
|
1874 |
} |
|
1780 | 1875 |
} |
1781 |
for (UpdateColumnBuilder column : columns) { |
|
1782 |
column.accept(visitor, filter); |
|
1783 |
} |
|
1784 |
if (this.has_where()) { |
|
1785 |
this.where.accept(visitor, filter); |
|
1786 |
} |
|
1787 | 1876 |
} |
1788 | 1877 |
|
1789 | 1878 |
@Override |
... | ... | |
1875 | 1964 |
|
1876 | 1965 |
@Override |
1877 | 1966 |
public void accept(Visitor visitor, VisitorFilter filter) { |
1967 |
boolean visitChildren = true; |
|
1878 | 1968 |
if (filter==null || filter.accept(this)) { |
1879 | 1969 |
visitor.visit(this); |
1970 |
} else { |
|
1971 |
visitChildren = !filter.skipChildren(); |
|
1880 | 1972 |
} |
1881 |
if (this.table != null) { |
|
1882 |
this.table.accept(visitor, filter); |
|
1973 |
if(visitChildren){ |
|
1974 |
if (this.table != null) { |
|
1975 |
this.table.accept(visitor, filter); |
|
1976 |
} |
|
1977 |
if (this.has_where()) { |
|
1978 |
this.where.accept(visitor, filter); |
|
1979 |
} |
|
1883 | 1980 |
} |
1884 |
if (this.has_where()) { |
|
1885 |
this.where.accept(visitor, filter); |
|
1886 |
} |
|
1887 | 1981 |
} |
1888 | 1982 |
|
1889 | 1983 |
@Override |
... | ... | |
1999 | 2093 |
|
2000 | 2094 |
@Override |
2001 | 2095 |
public void accept(Visitor visitor, VisitorFilter filter) { |
2096 |
boolean visitChildren = true; |
|
2002 | 2097 |
if (filter==null || filter.accept(this)) { |
2003 | 2098 |
visitor.visit(this); |
2099 |
} else { |
|
2100 |
visitChildren = !filter.skipChildren(); |
|
2004 | 2101 |
} |
2005 |
if (this.table != null) { |
|
2006 |
this.table.accept(visitor, filter); |
|
2102 |
if(visitChildren){ |
|
2103 |
if (this.table != null) { |
|
2104 |
this.table.accept(visitor, filter); |
|
2105 |
} |
|
2007 | 2106 |
} |
2008 | 2107 |
} |
2009 | 2108 |
|
... | ... | |
2176 | 2275 |
|
2177 | 2276 |
@Override |
2178 | 2277 |
public void accept(Visitor visitor, VisitorFilter filter) { |
2278 |
boolean visitChildren = true; |
|
2179 | 2279 |
if (filter==null || filter.accept(this)) { |
2180 | 2280 |
visitor.visit(this); |
2281 |
} else { |
|
2282 |
visitChildren = !filter.skipChildren(); |
|
2181 | 2283 |
} |
2182 |
if (this.table != null) { |
|
2183 |
this.table.accept(visitor, filter); |
|
2284 |
if(visitChildren){ |
|
2285 |
if (this.table != null) { |
|
2286 |
this.table.accept(visitor, filter); |
|
2287 |
} |
|
2184 | 2288 |
} |
2185 | 2289 |
} |
2186 | 2290 |
|
... | ... | |
2429 | 2533 |
|
2430 | 2534 |
@Override |
2431 | 2535 |
public void accept(Visitor visitor, VisitorFilter filter) { |
2536 |
boolean visitChildren = true; |
|
2432 | 2537 |
if (filter==null || filter.accept(this)) { |
2433 | 2538 |
visitor.visit(this); |
2539 |
} else { |
|
2540 |
visitChildren = !filter.skipChildren(); |
|
2434 | 2541 |
} |
2435 |
if (this.table != null) { |
|
2436 |
this.table.accept(visitor, filter); |
|
2542 |
if(visitChildren){ |
|
2543 |
if (this.table != null) { |
|
2544 |
this.table.accept(visitor, filter); |
|
2545 |
} |
|
2437 | 2546 |
} |
2438 | 2547 |
} |
2439 | 2548 |
|
... | ... | |
2622 | 2731 |
|
2623 | 2732 |
@Override |
2624 | 2733 |
public void accept(Visitor visitor, VisitorFilter filter) { |
2734 |
boolean visitChildren = true; |
|
2625 | 2735 |
if (filter==null || filter.accept(this)) { |
2626 | 2736 |
visitor.visit(this); |
2737 |
} else { |
|
2738 |
visitChildren = !filter.skipChildren(); |
|
2627 | 2739 |
} |
2628 |
if (this.name != null) { |
|
2629 |
this.name.accept(visitor, filter); |
|
2740 |
if(visitChildren){ |
|
2741 |
if (this.name != null) { |
|
2742 |
this.name.accept(visitor, filter); |
|
2743 |
} |
|
2744 |
if (this.value != null) { |
|
2745 |
this.value.accept(visitor, filter); |
|
2746 |
} |
|
2630 | 2747 |
} |
2631 |
if (this.value != null) { |
|
2632 |
this.value.accept(visitor, filter); |
|
2633 |
} |
|
2634 | 2748 |
} |
2635 | 2749 |
|
2636 | 2750 |
@Override |
... | ... | |
2682 | 2796 |
|
2683 | 2797 |
@Override |
2684 | 2798 |
public void accept(Visitor visitor, VisitorFilter filter) { |
2799 |
boolean visitChildren = true; |
|
2685 | 2800 |
if (filter==null || filter.accept(this)) { |
2686 | 2801 |
visitor.visit(this); |
2802 |
} else { |
|
2803 |
visitChildren = !filter.skipChildren(); |
|
2687 | 2804 |
} |
2688 |
if (this.table != null) { |
|
2689 |
this.table.accept(visitor, filter); |
|
2805 |
if(visitChildren){ |
|
2806 |
if (this.table != null) { |
|
2807 |
this.table.accept(visitor, filter); |
|
2808 |
} |
|
2809 |
for (InsertColumnBuilder column : columns) { |
|
2810 |
column.accept(visitor, filter); |
|
2811 |
} |
|
2690 | 2812 |
} |
2691 |
for (InsertColumnBuilder column : columns) { |
|
2692 |
column.accept(visitor, filter); |
|
2693 |
} |
|
2694 | 2813 |
} |
2695 | 2814 |
|
2696 | 2815 |
@Override |
... | ... | |
2764 | 2883 |
|
2765 | 2884 |
@Override |
2766 | 2885 |
public void accept(Visitor visitor, VisitorFilter filter) { |
2886 |
boolean visitChildren = true; |
|
2767 | 2887 |
if (filter==null || filter.accept(this)) { |
2768 | 2888 |
visitor.visit(this); |
2889 |
} else { |
|
2890 |
visitChildren = !filter.skipChildren(); |
|
2769 | 2891 |
} |
2770 |
if (this.table != null) { |
|
2771 |
this.table.accept(visitor, filter); |
|
2892 |
if(visitChildren){ |
|
2893 |
if (this.table != null) { |
|
2894 |
this.table.accept(visitor, filter); |
|
2895 |
} |
|
2772 | 2896 |
} |
2773 | 2897 |
} |
2774 | 2898 |
|
... | ... | |
2876 | 3000 |
|
2877 | 3001 |
public SQLBuilderBase() { |
2878 | 3002 |
this.expressionBuilder = GeometryExpressionEvaluatorLocator.getManager().createExpressionBuilder(); |
3003 |
this.expressionBuilder.setProperty("SQLBUILDER", this); |
|
2879 | 3004 |
|
2880 | 3005 |
this.hasSpatialFunctions = false; |
2881 | 3006 |
this.supportSchemas = true; |
... | ... | |
2889 | 3014 |
@Override |
2890 | 3015 |
public void setProperties(Class filter, final Object... values) { |
2891 | 3016 |
this.expressionBuilder.setProperties(filter, values); |
2892 |
this.accept((Visitable v) -> { |
|
3017 |
setProperties(this, filter, values); |
|
3018 |
} |
|
3019 |
|
|
3020 |
@Override |
|
3021 |
public void setProperties(Visitable visitable, Class filter, final Object... values) { |
|
3022 |
if(visitable == null){ |
|
3023 |
return; |
|
3024 |
} |
|
3025 |
if(visitable instanceof PropertiesSupport){ |
|
2893 | 3026 |
for (int i = 0; i < values.length; i+=2) { |
2894 |
((Value)v).setProperty((String) values[i], values[i+1]);
|
|
3027 |
((PropertiesSupport)visitable).setProperty((String) values[i], values[i+1]);
|
|
2895 | 3028 |
} |
3029 |
} |
|
3030 |
visitable.accept((Visitable v) -> { |
|
3031 |
if(v instanceof PropertiesSupport){ |
|
3032 |
for (int i = 0; i < values.length; i+=2) { |
|
3033 |
((PropertiesSupport)v).setProperty((String) values[i], values[i+1]); |
|
3034 |
} |
|
3035 |
} |
|
2896 | 3036 |
}, new ClassVisitorFilter(filter) ); |
2897 | 3037 |
} |
2898 | 3038 |
|
... | ... | |
3165 | 3305 |
return new FromBuilderBase(); |
3166 | 3306 |
} |
3167 | 3307 |
|
3168 |
protected SelectBuilder createSelectBuilder() {
|
|
3308 |
public SelectBuilder createSelectBuilder() {
|
|
3169 | 3309 |
return new SelectBuilderBase(); |
3170 | 3310 |
} |
3171 | 3311 |
|
... | ... | |
3326 | 3466 |
return new JoinBase(type, table, expression); |
3327 | 3467 |
} |
3328 | 3468 |
|
3469 |
@Override |
|
3329 | 3470 |
public void accept(Visitor visitor, VisitorFilter filter) { |
3330 | 3471 |
if (this.select != null) { |
3331 | 3472 |
this.select.accept(visitor, filter); |
... | ... | |
3353 | 3494 |
} |
3354 | 3495 |
} |
3355 | 3496 |
|
3356 |
@Override
|
|
3497 |
@Override
|
|
3357 | 3498 |
public Formatter formatter() { |
3358 | 3499 |
return expression().formatter(); |
3359 | 3500 |
} |
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 | ||
---|---|---|
39 | 39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
40 | 40 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureExpressionEvaluator; |
41 | 41 |
import org.gvsig.expressionevaluator.Code.Callable; |
42 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
43 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
44 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
42 | 45 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureQueryOrder; |
43 | 46 |
|
44 | 47 |
/** |
... | ... | |
159 | 162 |
return caller; // Don't optimize SELECT |
160 | 163 |
} |
161 | 164 |
|
165 |
@Override |
|
166 |
public ExpressionBuilder.Value toValue(ExpressionBuilder builder, Codes args) { |
|
167 |
try { |
|
168 |
SQLBuilder sqlBuilder = (SQLBuilder) builder.getProperty("SQLBUILDER"); |
|
169 |
if(sqlBuilder == null){ |
|
170 |
return super.toValue(builder, args); |
|
171 |
} |
|
172 |
SQLBuilder.SelectBuilder select = sqlBuilder.createSelectBuilder(); |
|
173 |
|
|
174 |
String storeName = this.getTableName(args, TABLE); |
|
175 |
Callable columns = getTupleOrNull(args, COLUMNS); |
|
176 |
Code where = this.getWhereCode(args, WHERE); |
|
177 |
Callable order = getTupleOrNull(args, ORDER); |
|
178 |
Callable order_mode = getTupleOrNull(args, ORDER_MODE); |
|
179 |
Code limit = args.get(LIMIT); |
|
180 |
|
|
181 |
if (storeName != null) { |
|
182 |
select.from().table().name(storeName); |
|
183 |
} |
|
184 |
|
|
185 |
if (columns != null) { |
|
186 |
for (Code column : columns.parameters()) { |
|
187 |
if (column instanceof Code.Identifier) { |
|
188 |
select.column().name( |
|
189 |
select.from().table(), |
|
190 |
((Code.Identifier) column).name() |
|
191 |
); |
|
192 |
} |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
if (where != null) { |
|
197 |
select.where().value(where.toValue(builder)); |
|
198 |
} |
|
199 |
|
|
200 |
if (limit != null) { |
|
201 |
select.limit(((Number) ((Code.Constant) limit).value()).longValue()); |
|
202 |
} |
|
203 |
|
|
204 |
if (order != null || order_mode != null) { |
|
205 |
for (int n = 0; n < order.parameters().size(); n++) { |
|
206 |
Code member = order.parameters().get(n); |
|
207 |
Code.Constant mode = (Code.Constant) order_mode.parameters().get(n); |
|
208 |
select.order_by().value(member.toValue(builder)).ascending((boolean) mode.value()); |
|
209 |
} |
|
210 |
} |
|
211 |
return select; |
|
212 |
} catch (Exception ex) { |
|
213 |
return super.toValue(builder, args); |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
|
|
218 |
|
|
162 | 219 |
} |
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/complements/search/SearchImpl.java | ||
---|---|---|
137 | 137 |
} |
138 | 138 |
} |
139 | 139 |
|
140 |
for (FeatureAttributeDescriptor attribute : extra) { |
|
141 |
if (contains(mostUsed, attribute.getName())) { |
|
142 |
continue; |
|
140 |
if(extra != null){ |
|
141 |
for (FeatureAttributeDescriptor attribute : extra) { |
|
142 |
if (contains(mostUsed, attribute.getName())) { |
|
143 |
continue; |
|
144 |
} |
|
145 |
if (contains(favorites, attribute.getName())) { |
|
146 |
continue; |
|
147 |
} |
|
148 |
if (filter.test(attribute)) { |
|
149 |
normal.add(new AnOrderedAttribute(attribute, OrderedAttribute.TYPE_EXTRA)); |
|
150 |
} |
|
143 | 151 |
} |
144 |
if (contains(favorites, attribute.getName())) { |
|
145 |
continue; |
|
146 |
} |
|
147 |
if (filter.test(attribute)) { |
|
148 |
normal.add(new AnOrderedAttribute(attribute, OrderedAttribute.TYPE_EXTRA)); |
|
149 |
} |
|
150 | 152 |
} |
151 | 153 |
|
152 | 154 |
Comparator<OrderedAttribute> comparatorAdapter = new Comparator<OrderedAttribute>() { |
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/featureset/DefaultFeatureSet.java | ||
---|---|---|
248 | 248 |
private long calculateSize() throws DataException { |
249 | 249 |
boolean hasLimit = this.query.hasLimit(); |
250 | 250 |
long limit = this.query.getLimit(); |
251 |
if(hasLimit && limit == 0){ |
|
252 |
return 0; |
|
253 |
} |
|
251 | 254 |
long mySize = 0; |
252 | 255 |
|
253 | 256 |
int mode = this.getIteratorMode(); |
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/featureset/FastDefaultIterator.java | ||
---|---|---|
26 | 26 |
import org.gvsig.fmap.dal.exception.DataException; |
27 | 27 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
28 | 28 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
29 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
29 | 30 |
import org.gvsig.tools.exception.BaseException; |
30 | 31 |
|
31 | 32 |
public class FastDefaultIterator extends DefaultIterator { |
... | ... | |
35 | 36 |
public FastDefaultIterator(DefaultFeatureSet featureSet, long index, long elements) |
36 | 37 |
throws DataException { |
37 | 38 |
super(featureSet); |
38 |
this.initializeFeature(); |
|
39 |
if (index > 0 || elements>0 ) { |
|
40 |
if (featureSet.provider.canIterateFromIndex()) { |
|
41 |
try { |
|
42 |
this.iterator = featureSet.provider.fastIterator(index,elements); |
|
43 |
} catch (UnsupportedOperationException e) { |
|
44 |
this.iterator = featureSet.provider.fastIterator(); |
|
45 |
skypto(index); |
|
46 |
} |
|
47 |
} else { |
|
48 |
this.iterator = featureSet.provider.fastIterator(); |
|
49 |
skypto(index); |
|
50 |
} |
|
51 |
} else { |
|
52 |
this.iterator = featureSet.provider.fastIterator(); |
|
53 |
} |
|
39 |
try{ |
|
40 |
this.initializeFeature(); |
|
41 |
if (index > 0 || elements>0 ) { |
|
42 |
if (featureSet.provider.canIterateFromIndex()) { |
|
43 |
try { |
|
44 |
this.iterator = featureSet.provider.fastIterator(index,elements); |
|
45 |
} catch (UnsupportedOperationException e) { |
|
46 |
this.iterator = featureSet.provider.fastIterator(); |
|
47 |
skypto(index); |
|
48 |
} |
|
49 |
} else { |
|
50 |
this.iterator = featureSet.provider.fastIterator(); |
|
51 |
skypto(index); |
|
52 |
} |
|
53 |
} else { |
|
54 |
this.iterator = featureSet.provider.fastIterator(); |
|
55 |
} |
|
56 |
} catch (Throwable t) { |
|
57 |
DisposeUtils.dispose(this.fset); |
|
58 |
DisposeUtils.dispose(this); |
|
59 |
throw t; |
|
60 |
} |
|
54 | 61 |
|
55 | 62 |
} |
56 | 63 |
|
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/DefaultFeatureQuery.java | ||
---|---|---|
882 | 882 |
} |
883 | 883 |
return fn; |
884 | 884 |
} |
885 |
|
|
885 |
|
|
886 |
@Override |
|
887 |
public boolean isAggregate(String name) { |
|
888 |
return this.getAggregateFunctions().get(name) != null; |
|
889 |
} |
|
890 |
|
|
886 | 891 |
@Override |
887 | 892 |
public boolean hasAggregateFunctions() { |
888 | 893 |
return this.aggregateFunctions != null && !this.aggregateFunctions.isEmpty(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/test/java/org/gvsig/expressionevaluator/TestExpressionBuilder.java | ||
---|---|---|
4 | 4 |
import org.gvsig.expressionevaluator.impl.expressionbuilder.formatters.DALFormatter; |
5 | 5 |
import org.gvsig.fmap.dal.DALLocator; |
6 | 6 |
import org.gvsig.fmap.dal.DataManager; |
7 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
7 | 8 |
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder; |
8 | 9 |
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder.SelectBuilder; |
10 |
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase; |
|
9 | 11 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
10 | 12 |
|
11 | 13 |
/** |
... | ... | |
64 | 66 |
|
65 | 67 |
public void testUseCase1() { |
66 | 68 |
DataManager dataManager = DALLocator.getDataManager(); |
67 |
DALExpressionBuilder builder = dataManager.createDALExpressionBuilder(); |
|
69 |
DALExpressionBuilder builder1 = dataManager.createDALExpressionBuilder(); |
|
70 |
SQLBuilderBase builder = new SQLBuilderBase(); |
|
68 | 71 |
|
69 |
SelectBuilder select = builder.select() |
|
70 |
.column("LID_ACCIDENTE") |
|
71 |
.from("ARENA2_VEHICULOS") |
|
72 |
.where( |
|
73 |
builder.expression().and( |
|
74 |
builder.expression().eq( |
|
75 |
builder.expression().getattr("ARENA2_VEHICULOS","ID_ACCIDENTE"), |
|
76 |
builder.expression().getattr("ARENA2_ACCIDENTES","LID_ACCIDENTE") |
|
77 |
), |
|
78 |
builder.expression().eq( |
|
79 |
builder.expression().column("MODELO"), |
|
80 |
builder.expression().constant("307") |
|
81 |
) |
|
82 |
) |
|
83 |
) |
|
84 |
.limit(1); |
|
85 |
ExpressionBuilder.Value exists = builder.exists(select.toValue(), "EXISTS123"); |
|
72 |
SQLBuilder.SelectBuilder select = builder.select(); |
|
73 |
select.column().name("LID_ACCIDENTE"); |
|
74 |
select.from().table().name("ARENA2_VEHICULOS"); |
|
75 |
select.where().value( |
|
76 |
builder.expression().and( |
|
77 |
builder.expression().eq( |
|
78 |
builder.expression().getattr("ARENA2_VEHICULOS","ID_ACCIDENTE"), |
|
79 |
builder.expression().getattr("ARENA2_ACCIDENTES","LID_ACCIDENTE") |
|
80 |
), |
|
81 |
builder.expression().eq( |
|
82 |
builder.expression().column("MODELO"), |
|
83 |
builder.expression().constant("307") |
|
84 |
) |
|
85 |
) |
|
86 |
); |
|
87 |
select.limit(1); |
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
ExpressionBuilder.Value exists = builder1.exists(select, "EXISTS123"); |
|
86 | 92 |
|
87 | 93 |
String filter = exists.toString(new DALFormatter()); |
88 | 94 |
|
89 |
assertEquals("EXISTS((SELECT \"LID_ACCIDENTE\" FROM \"ARENA2_VEHICULOS\" WHERE (( (\"ARENA2_VEHICULOS\".\"ID_ACCIDENTE\") = (\"ARENA2_ACCIDENTES\".\"LID_ACCIDENTE\") ) AND ( (\"MODELO\") = ('307') )) LIMIT 1), 'EXISTS123')", filter);
|
|
95 |
assertEquals("EXISTS(SELECT \"LID_ACCIDENTE\" FROM \"ARENA2_VEHICULOS\" WHERE (( (\"ARENA2_VEHICULOS\".\"ID_ACCIDENTE\") = (\"ARENA2_ACCIDENTES\".\"LID_ACCIDENTE\") ) AND ( (\"MODELO\") = ('307') )) LIMIT 1, 'EXISTS123')", filter);
|
|
90 | 96 |
|
91 | 97 |
// Comprobamos que con el formatter por defecto obtenemos lo mismo. |
92 | 98 |
assertEquals(filter, exists.toString()); |
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 | ||
---|---|---|
27 | 27 |
import java.sql.Blob; |
28 | 28 |
import java.sql.Clob; |
29 | 29 |
import java.sql.ResultSet; |
30 |
import java.sql.ResultSetMetaData; |
|
30 | 31 |
import java.util.ArrayList; |
32 |
import java.util.Collections; |
|
33 |
import java.util.HashMap; |
|
31 | 34 |
import java.util.HashSet; |
32 | 35 |
import java.util.List; |
36 |
import java.util.Map; |
|
33 | 37 |
import java.util.function.Predicate; |
34 | 38 |
import org.apache.commons.io.IOUtils; |
35 | 39 |
import org.apache.commons.lang3.ArrayUtils; |
... | ... | |
97 | 101 |
import org.slf4j.LoggerFactory; |
98 | 102 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$CONSTANT; |
99 | 103 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$IDENTIFIER; |
104 |
import org.gvsig.fmap.dal.DataManager; |
|
105 |
import org.gvsig.fmap.dal.SQLBuilder.Column; |
|
106 |
import org.gvsig.fmap.dal.SQLBuilder.OrderByBuilder; |
|
107 |
import org.gvsig.fmap.dal.SQLBuilder.SelectBuilder; |
|
108 |
import org.gvsig.fmap.dal.SQLBuilder.SelectColumnBuilder; |
|
100 | 109 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
101 | 110 |
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.ComputedAttribute; |
102 | 111 |
import org.gvsig.tools.util.ContainerUtils; |
... | ... | |
107 | 116 |
private static final boolean ALLOW_AUTOMATIC_VALUES = true; |
108 | 117 |
private static final String QUOTE_FOR_USE_IN_IDENTIFIERS = "\""; |
109 | 118 |
private static final String QUOTE_FOR_USE_IN_STRINGS = "'"; |
119 |
public static final String DONT_ADD_TABLE_NAME_TO_COLUMNS = "DONT_ADD_TABLE_NAME"; |
|
110 | 120 |
|
111 | 121 |
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCHelperBase.class); |
112 | 122 |
|
... | ... | |
699 | 709 |
List<String> extra_column_names) { |
700 | 710 |
replaceForeingValueFunction(sqlbuilder, type, extra_column_names); |
701 | 711 |
replaceExistsFunction(sqlbuilder, type, extra_column_names); |
712 |
addTableToColumnReferences(sqlbuilder, type); |
|
702 | 713 |
} |
703 | 714 |
|
704 | 715 |
@SuppressWarnings("Convert2Lambda") |
... | ... | |
870 | 881 |
if (ContainerUtils.contains(extra_column_names, variable.name(), ContainerUtils.EQUALS_IGNORECASE_COMPARATOR)) { |
871 | 882 |
continue; |
872 | 883 |
} |
884 |
boolean alreadyReplaced = false; |
|
873 | 885 |
for (String foreingName : foreing_value_args) { |
874 | 886 |
String[] foreingNameParts = foreingName.split("[.]"); |
875 | 887 |
if (foreingNameParts.length != 2) { |
... | ... | |
878 | 890 |
String columnNameLocal = foreingNameParts[0]; |
879 | 891 |
String columnNameForeing = foreingNameParts[1]; |
880 | 892 |
if (StringUtils.equalsIgnoreCase(variable.name(), columnNameForeing)) { |
893 |
if(alreadyReplaced){ |
|
894 |
throw new RuntimeException("Column reference \""+ columnNameForeing+"\" is ambiguous"); |
|
895 |
} |
|
896 |
alreadyReplaced = true; |
|
881 | 897 |
|
882 | 898 |
FeatureAttributeDescriptor attr = type.getAttributeDescriptor(columnNameLocal); |
883 | 899 |
if (attr == null) { |
... | ... | |
960 | 976 |
); |
961 | 977 |
usedLeftJoins.add(foreingTable.getName()); |
962 | 978 |
} |
963 |
if ( !(sqlbuilder.select().has_group_by() || sqlbuilder.select().has_aggregate_functions()) ) { |
|
964 |
sqlbuilder.select().column().name(foreingTable, columnNameForeing); |
|
965 |
} |
|
979 |
//No est? claro si debe a?adirse esta columna o no, OJO quitarlo o ponerlo altera los test de H2 |
|
980 |
// if ( !(sqlbuilder.select().has_group_by() || sqlbuilder.select().has_aggregate_functions()) ) { |
|
981 |
// sqlbuilder.select().column().name(foreingTable, columnNameForeing); |
|
982 |
// } |
|
966 | 983 |
} |
967 | 984 |
} |
968 | 985 |
|
969 |
for (SQLBuilder.SelectColumnBuilder column : sqlbuilder.select().getColumns()) { |
|
970 |
if(column.getTable()==null && column.getName()!=null) { |
|
971 |
column.name(table, column.getName()); |
|
972 |
} |
|
973 |
} |
|
974 |
|
|
975 | 986 |
} catch (Throwable th) { |
976 | 987 |
LOGGER.warn("Can't replace FOREING_VALUE function.", th); |
977 | 988 |
throw th; |
... | ... | |
979 | 990 |
// LOGGER.trace("Exit from replaceForeingValueFunction."); |
980 | 991 |
} |
981 | 992 |
} |
993 |
|
|
994 |
protected void addTableToColumnReferences(SQLBuilder sqlbuilder, FeatureType type) { |
|
995 |
// List<SelectBuilder> selectBuilders = new ArrayList<>(); |
|
996 |
// selectBuilders.add(sqlbuilder.select()); |
|
997 |
// sqlbuilder.select().accept((ExpressionBuilder.Visitable value) -> { |
|
998 |
// selectBuilders.add((SelectBuilder) value); |
|
999 |
// |
|
1000 |
// }, (ExpressionBuilder.Visitable visitable) -> (visitable instanceof SelectBuilder)); |
|
1001 |
// for (SelectBuilder selectBuilder : selectBuilders) { |
|
1002 |
// addTableToColumnReferencesInSingleSelect(sqlbuilder, selectBuilder); |
|
1003 |
// } |
|
982 | 1004 |
|
1005 |
|
|
1006 |
addTableToColumnReferencesInSingleSelect(sqlbuilder, sqlbuilder.select(), new ArrayList<>()); |
|
1007 |
|
|
1008 |
} |
|
1009 |
|
|
1010 |
protected void addTableToColumnReferencesInSingleSelect(SQLBuilder sqlbuilder, SelectBuilder select, List<Column> parentColumns) { |
|
1011 |
|
|
1012 |
final SQLBuilder.TableNameBuilder table = select.from().table(); |
|
1013 |
|
|
1014 |
final List<ExpressionBuilder.Value[]> value_replacements = new ArrayList<>(); |
|
1015 |
List<ExpressionBuilder.Variable> variables = new ArrayList<>(); |
|
1016 |
List<ExpressionBuilder.Value> variablesToExclude = new ArrayList<>(); |
|
1017 |
|
|
1018 |
select.accept((ExpressionBuilder.Visitable value) -> { |
|
1019 |
if(value instanceof ExpressionBuilder.Function) { |
|
1020 |
ExpressionBuilder.Function fn = (ExpressionBuilder.Function) value; |
|
1021 |
if(StringUtils.equals(fn.name(), ExpressionBuilder.FUNCTION_GETATTR)){ |
|
1022 |
ExpressionBuilder.Value p1 = fn.parameters().get(0); |
|
1023 |
if(p1 instanceof ExpressionBuilder.Variable){ |
|
1024 |
ExpressionBuilder.Variable v = (ExpressionBuilder.Variable) p1; |
|
1025 |
variablesToExclude.add(v); |
|
1026 |
} |
|
1027 |
ExpressionBuilder.Value p2 = fn.parameters().get(1); |
|
1028 |
if(p2 instanceof ExpressionBuilder.Constant){ |
|
1029 |
ExpressionBuilder.Constant c = (ExpressionBuilder.Constant) p2; |
|
1030 |
variablesToExclude.add(c); |
|
1031 |
} |
|
1032 |
} |
|
1033 |
} else if(value instanceof Column) { |
|
1034 |
Column c = (Column)value; |
|
1035 |
if(c.table() == null || !c.table().has_name()){ |
|
1036 |
variables.add(c); |
|
1037 |
} |
|
1038 |
|
|
1039 |
} else if(value instanceof ExpressionBuilder.Variable) { |
|
1040 |
variables.add((ExpressionBuilder.Variable) value); |
|
1041 |
// } else if(value instanceof SelectColumnBuilder) { |
|
1042 |
// SelectColumnBuilder selectColumn = (SelectColumnBuilder)value; |
|
1043 |
// if(StringUtils.isNotBlank(selectColumn.getName()) && selectColumn.getTable().has_name()){ |
|
1044 |
// variablesToExclude.add(sel) |
|
1045 |
// } |
|
1046 |
} |
|
1047 |
|
|
1048 |
}, new ExpressionBuilder.VisitorFilter() { |
|
1049 |
@Override |
|
1050 |
public boolean skipChildren() { |
|
1051 |
return true; |
|
1052 |
} |
|
1053 |
|
|
1054 |
@Override |
|
1055 |
public boolean accept(ExpressionBuilder.Visitable visitable) { |
|
1056 |
if(select == visitable){ |
|
1057 |
return true; |
|
1058 |
} |
|
1059 |
if(visitable instanceof OrderByBuilder) { |
|
1060 |
return false; |
|
1061 |
} |
|
1062 |
if(visitable instanceof SelectBuilder) { |
|
1063 |
ArrayList<Column> columns = new ArrayList<>(parentColumns); |
|
1064 |
for (SelectColumnBuilder column : select.getColumns()) { |
|
1065 |
columns.add(sqlbuilder.column( |
|
1066 |
table, |
|
1067 |
column.getName())); |
|
1068 |
} |
|
1069 |
addTableToColumnReferencesInSingleSelect(sqlbuilder, (SelectBuilder) visitable, columns); |
|
1070 |
return false; |
|
1071 |
} |
|
1072 |
return true; |
|
1073 |
} |
|
1074 |
}); |
|
1075 |
|
|
1076 |
List<String> variableNamesToExclude = new ArrayList<>(); |
|
1077 |
for(SQLBuilder.SelectColumnBuilder column : select.getColumns()){ |
|
1078 |
if(StringUtils.isNotBlank(column.getAlias())){ |
|
1079 |
variableNamesToExclude.add(column.getAlias()); |
|
1080 |
} else { |
|
1081 |
parentColumns.add(sqlbuilder.column( |
|
1082 |
table, |
|
1083 |
column.getName())); |
|
1084 |
} |
|
1085 |
} |
|
1086 |
|
|
1087 |
for (ExpressionBuilder.Variable variable : variables) { |
|
1088 |
boolean found = false; |
|
1089 |
for (ExpressionBuilder.Value v : variablesToExclude) { |
|
1090 |
if(v == variable){ |
|
1091 |
found = true; |
|
1092 |
break; |
|
1093 |
} |
|
1094 |
} |
|
1095 |
if(found){ |
|
1096 |
continue; |
|
1097 |
} |
|
1098 |
// if(variableNamesToExclude.contains(variable.name())){ |
|
1099 |
// continue; |
|
1100 |
// } |
|
1101 |
Column column = getColumn(parentColumns,variable.name()); |
|
1102 |
if(column != null){ |
|
1103 |
ExpressionBuilder.Variable variable_replacement = sqlbuilder.column( |
|
1104 |
column.table(), |
|
1105 |
variable.name() |
|
1106 |
); |
|
1107 |
value_replacements.add( |
|
1108 |
new ExpressionBuilder.Value[]{ |
|
1109 |
variable, |
|
1110 |
variable_replacement |
|
1111 |
} |
|
1112 |
); |
|
1113 |
} else { |
|
1114 |
ExpressionBuilder.Variable variable_replacement = null; |
|
1115 |
if(variable instanceof SQLBuilder.Column){ |
|
1116 |
column = (SQLBuilder.Column) variable; |
|
1117 |
if (column.table() == null || !column.table().has_name()) { |
|
1118 |
variable_replacement = sqlbuilder.column( |
|
1119 |
table, |
|
1120 |
variable.name() |
|
1121 |
); |
|
1122 |
} else if(!column.table().has_schema()){ |
|
1123 |
SQLBuilder.TableNameBuilder t = sqlbuilder.table_name() |
|
1124 |
.name(column.table().getName()) |
|
1125 |
.schema(table.getSchema()); //Mismo esquema que en el FROM |
|
1126 |
variable_replacement = sqlbuilder.column( |
|
1127 |
t, |
|
1128 |
variable.name() |
|
1129 |
); |
|
1130 |
} |
|
1131 |
} else { |
|
1132 |
variable_replacement = sqlbuilder.column( |
|
1133 |
table, |
|
1134 |
variable.name() |
|
1135 |
); |
|
1136 |
} |
|
1137 |
if(variable_replacement != null){ |
|
1138 |
value_replacements.add( |
|
1139 |
new ExpressionBuilder.Value[]{ |
|
1140 |
variable, |
|
1141 |
variable_replacement |
|
1142 |
} |
|
1143 |
); |
|
1144 |
} |
|
1145 |
} |
|
1146 |
|
|
1147 |
} |
|
1148 |
|
|
1149 |
for (ExpressionBuilder.Value[] replaceValue : value_replacements) { |
|
1150 |
ExpressionBuilder.Value target = replaceValue[0]; |
|
1151 |
ExpressionBuilder.Value replacement = replaceValue[1]; |
|
1152 |
Boolean dontAddTableName = (Boolean) target.getProperty(DONT_ADD_TABLE_NAME_TO_COLUMNS); |
|
1153 |
if(dontAddTableName != null && dontAddTableName){ |
|
1154 |
continue; |
|
1155 |
} |
|
1156 |
select.replace(target, replacement); |
|
1157 |
} |
|
1158 |
|
|
1159 |
} |
|
1160 |
|
|
1161 |
protected Column getColumn(List<Column> columns, String name){ |
|
1162 |
for (int i = columns.size()-1; i >= 0; i--) { |
|
1163 |
if(StringUtils.equalsIgnoreCase(columns.get(i).name(), name)){ |
|
1164 |
return columns.get(i); |
|
1165 |
} |
|
1166 |
} |
|
1167 |
return null; |
|
1168 |
} |
|
1169 |
|
|
1170 |
|
|
983 | 1171 |
@Override |
984 | 1172 |
public void setTransaction(DataTransactionServices transaction) { |
985 | 1173 |
this.transaction = transaction; |
... | ... | |
1003 | 1191 |
public void expandCalculedColumns(JDBCSQLBuilderBase sqlbuilder) { |
1004 | 1192 |
ComputedAttribute computedAttributeFormater = new ComputedAttribute(sqlbuilder, sqlbuilder.formatter()); |
1005 | 1193 |
for (int i = 0; i < 10; i++) { |
1006 |
List<Pair<ExpressionBuilder.Value, ExpressionBuilder.Value>> variablesToReplace = new ArrayList<>(); |
|
1007 |
sqlbuilder.accept(new ExpressionBuilder.Visitor() { |
|
1008 |
@Override |
|
1009 |
public void visit(ExpressionBuilder.Visitable value) { |
|
1010 |
if (computedAttributeFormater.canApply((ExpressionBuilder.Value) value)) { |
|
1011 |
ExpressionBuilder.Variable variable = (ExpressionBuilder.Variable) value; |
|
1012 |
ExpressionBuilder.Value replace = computedAttributeFormater.expandedValue(variable); |
|
1013 |
variablesToReplace.add(Pair.of(variable, replace)); |
|
1014 |
} |
|
1194 |
List<Pair<ExpressionBuilder.Variable, ExpressionBuilder.Value>> variablesToReplace = new ArrayList<>(); |
|
1195 |
sqlbuilder.accept((ExpressionBuilder.Visitable value) -> { |
|
1196 |
if (computedAttributeFormater.canApply((ExpressionBuilder.Value) value)) { |
|
1197 |
ExpressionBuilder.Variable variable = (ExpressionBuilder.Variable) value; |
|
1198 |
ExpressionBuilder.Value replace = computedAttributeFormater.expandedValue(variable); |
|
1199 |
variablesToReplace.add(Pair.of(variable, replace)); |
|
1015 | 1200 |
} |
1016 | 1201 |
}, null); |
1017 | 1202 |
if (variablesToReplace.isEmpty()) { |
1018 | 1203 |
break; |
1019 | 1204 |
} |
1020 |
for (Pair<ExpressionBuilder.Value, ExpressionBuilder.Value> entry : variablesToReplace) {
|
|
1205 |
for (Pair<ExpressionBuilder.Variable, ExpressionBuilder.Value> entry : variablesToReplace) {
|
|
1021 | 1206 |
ExpressionBuilder.Value variable = entry.getKey(); |
1022 | 1207 |
ExpressionBuilder.Value replace = entry.getValue(); |
1208 |
Boolean dontAddTableName = (Boolean) variable.getProperty(DONT_ADD_TABLE_NAME_TO_COLUMNS); |
|
1209 |
if (dontAddTableName != null && dontAddTableName) { |
|
1210 |
continue; |
|
1211 |
} |
|
1023 | 1212 |
sqlbuilder.select().replace(variable, replace); |
1024 | 1213 |
} |
1025 | 1214 |
} |
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 | ||
---|---|---|
28 | 28 |
import java.util.List; |
29 | 29 |
import java.util.Map; |
30 | 30 |
import org.apache.commons.lang3.ArrayUtils; |
31 |
import org.apache.commons.lang3.BooleanUtils; |
|
32 | 31 |
import org.apache.commons.lang3.StringUtils; |
33 | 32 |
import org.gvsig.expressionevaluator.Code; |
34 | 33 |
import org.gvsig.expressionevaluator.Expression; |
35 | 34 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
36 | 35 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_LET; |
37 | 36 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
37 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
38 | 38 |
import org.gvsig.fmap.dal.SQLBuilder; |
39 |
import org.gvsig.fmap.dal.SQLBuilder.Column; |
|
39 | 40 |
import org.gvsig.fmap.dal.SQLBuilder.OrderByBuilder; |
40 | 41 |
import org.gvsig.fmap.dal.SQLBuilder.SelectBuilder; |
41 | 42 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
48 | 49 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
49 | 50 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder.FeatureQueryOrderMember; |
50 | 51 |
import org.gvsig.fmap.dal.feature.FeatureType; |
52 |
import org.gvsig.fmap.dal.feature.SQLBuilder_save; |
|
51 | 53 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
52 | 54 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
53 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
54 | 55 |
import static org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer.QUERY_DONT_ADD_PRIMARY_KEY_IN_THE_ORDER; |
55 | 56 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
56 | 57 |
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler.ResultSetEntry; |
58 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase.DONT_ADD_TABLE_NAME_TO_COLUMNS; |
|
57 | 59 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
58 | 60 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
59 | 61 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_JDBCHELPER; |
... | ... | |
128 | 130 |
double tolerance = -1; //query.getScale(); |
129 | 131 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
130 | 132 |
SelectBuilder select = sqlbuilder.select(); |
131 |
ArrayList<ExpressionBuilder.Value> valuesToRemoveFeatureType = new ArrayList<>(); |
|
133 |
select.from().table() |
|
134 |
.database(this.table.getDatabase()) |
|
135 |
.schema(this.table.getSchema()) |
|
136 |
.name(this.table.getTable()); |
|
137 |
select.from().subquery(this.table.getSubquery()); |
|
138 |
|
|
139 |
|
|
140 |
List<ExpressionBuilder.Value> valuesToRemoveFeatureType = new ArrayList<>(); |
|
132 | 141 |
|
133 | 142 |
if( shouldUseACustomSelect() ) { |
134 |
String sql = table.getSubquery(); |
|
135 |
if( StringUtils.containsAny(sql, "${where_filter}", "${and_filter}") ) { |
|
136 |
Evaluator filter = query.getFilter(); |
|
137 |
if (filter != null) { |
|
138 |
String sqlfilter = filter.getSQL(); |
|
139 |
if (!StringUtils.isEmpty(sqlfilter)) { |
|
140 |
if (this.helper.supportFilter(this.storeType, filter)) { |
|
141 |
select.where().set(expbuilder.toValue(sqlfilter)); |
|
142 |
} |
|
143 |
return processCustomSelect(select, expbuilder, sqlbuilder, valuesToRemoveFeatureType, columns); |
|
144 |
} |
|
145 |
|
|
146 |
|
|
147 |
Map<String, EditableFeatureAttributeDescriptor> allExtraColumns = getAllExtraColumns(this.setType, this.query); |
|
148 |
|
|
149 |
List<String> primaryKeys = new ArrayList<>(); |
|
150 |
for (FeatureAttributeDescriptor attr : storeType.getPrimaryKey()) { |
|
151 |
primaryKeys.add(attr.getName()); |
|
152 |
} |
|
153 |
|
|
154 |
//Don't change order of this processes |
|
155 |
process1_SimpleFields(helper, setType, query, sqlbuilder, select, columns, primaryKeys, extraColumnNames); |
|
156 |
process2_ComputedFields(helper, setType, query, sqlbuilder, select, extraColumnNames); |
|
157 |
process3_Where(helper, storeType, query, sqlbuilder, select); |
|
158 |
process4_Aggregates(this.table, this.setType, this.query, allExtraColumns, sqlbuilder, select, extraColumnNames); |
|
159 |
process5_GroupBys(this.table, this.setType, this.query, allExtraColumns, sqlbuilder, select, extraColumnNames); |
|
160 |
process6_OrderBy(storeType, setType, query, allExtraColumns, sqlbuilder, select, primaryKeys, extraColumnNames, valuesToRemoveFeatureType); |
|
161 |
|
|
162 |
if (!StringUtils.isEmpty(baseFilter)) { |
|
163 |
select.where().and(expbuilder.toValue(baseFilter)); |
|
164 |
} |
|
165 |
|
|
166 |
if (!StringUtils.isEmpty(baseOrder)) { |
|
167 |
select.order_by().custom(baseOrder); |
|
168 |
} |
|
169 |
|
|
170 |
|
|
171 |
if (limit > 0) { |
|
172 |
select.limit(limit); |
|
173 |
} else { |
|
174 |
select.limit(query == null ? null : query.getLimit()); |
|
175 |
} |
|
176 |
if (offset > 0) { |
|
177 |
select.offset(offset); |
|
178 |
} |
|
179 |
sqlbuilder.setProperties( |
|
180 |
null, |
|
181 |
PROP_FEATURE_TYPE, this.storeType, |
|
182 |
PROP_TABLE, table, |
|
183 |
PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable(), |
|
184 |
PROP_JDBCHELPER, this.helper, |
|
185 |
PROP_QUERY, this.query |
|
186 |
); |
|
187 |
for (ExpressionBuilder.Value value : valuesToRemoveFeatureType) { |
|
188 |
value.setProperty(PROP_FEATURE_TYPE, null); |
|
189 |
} |
|
190 |
this.helper.expandCalculedColumns(sqlbuilder); |
|
191 |
this.helper.processSpecialFunctions(sqlbuilder, storeType, extraColumnNames); |
|
192 |
String sql = sqlbuilder.toString(); |
|
193 |
LOGGER.debug(sql); |
|
194 |
return sql; |
|
195 |
} |
|
196 |
|
|
197 |
private String processCustomSelect(SelectBuilder select, ExpressionBuilder expbuilder, JDBCSQLBuilderBase sqlbuilder, List<ExpressionBuilder.Value> valuesToRemoveFeatureType, List<FeatureAttributeDescriptor> columns) { |
|
198 |
String sql = table.getSubquery(); |
|
199 |
if( StringUtils.containsAny(sql, "${where_filter}", "${and_filter}") ) { |
|
200 |
Evaluator filter = query.getFilter(); |
|
201 |
if (filter != null) { |
|
202 |
String sqlfilter = filter.getSQL(); |
|
203 |
if (!StringUtils.isEmpty(sqlfilter)) { |
|
204 |
if (this.helper.supportFilter(this.storeType, filter)) { |
|
205 |
select.where().set(expbuilder.toValue(sqlfilter)); |
|
143 | 206 |
} |
144 | 207 |
} |
145 |
if (!StringUtils.isEmpty(baseFilter)) { |
|
146 |
select.where().and(expbuilder.toValue(baseFilter)); |
|
147 |
} |
|
148 | 208 |
} |
149 |
if( StringUtils.containsAny(sql, "${order_by_orderspec}", "${comma_orderspec}") ) { |
|
150 |
FeatureQueryOrder order = query.getOrder(); |
|
151 |
if (order != null) { |
|
152 |
for (FeatureQueryOrderMember member : order.members()) { |
|
153 |
String attrName = member.getAttributeName(); |
|
154 |
ExpressionBuilder.Variable col = expbuilder.column(attrName); |
|
155 |
select.order_by().value(col).ascending(member.getAscending()); |
|
156 |
} |
|
157 |
} |
|
209 |
if (!StringUtils.isEmpty(baseFilter)) { |
|
210 |
select.where().and(expbuilder.toValue(baseFilter)); |
|
158 | 211 |
} |
159 |
if( select.has_where() || select.has_order_by() ) { |
|
160 |
sqlbuilder.setProperties( |
|
161 |
null, |
|
162 |
PROP_FEATURE_TYPE, this.storeType, |
|
163 |
PROP_TABLE, table, |
|
164 |
PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable(), |
|
165 |
PROP_JDBCHELPER, this.helper, |
|
166 |
PROP_QUERY, this.query |
|
167 |
); |
|
168 |
for (ExpressionBuilder.Value value : valuesToRemoveFeatureType) { |
|
169 |
value.setProperty(PROP_FEATURE_TYPE, null); |
|
212 |
} |
|
213 |
if( StringUtils.containsAny(sql, "${order_by_orderspec}", "${comma_orderspec}") ) { |
|
214 |
FeatureQueryOrder order = query.getOrder(); |
|
215 |
if (order != null) { |
|
216 |
for (FeatureQueryOrderMember member : order.members()) { |
|
217 |
String attrName = member.getAttributeName(); |
|
218 |
ExpressionBuilder.Variable col = expbuilder.column(attrName); |
|
219 |
select.order_by().value(col).ascending(member.getAscending()); |
|
170 | 220 |
} |
171 |
if( select.has_where()) { |
|
172 |
String s = select.where().toString(); |
|
173 |
sql = StringUtils.replace(sql, "${where_filter}", "WHERE " + s); |
|
174 |
sql = StringUtils.replace(sql, "${and_filter}", "AND (" + s + ")"); |
|
175 |
} |
|
176 |
if( select.has_order_by() ) { |
|
177 |
String s = select.order_by().toString(); |
|
178 |
sql = StringUtils.replace(sql, "${order_by_orderspec}", "ORDER BY " + s); |
|
179 |
sql = StringUtils.replace(sql, "${comma_orderspec}", ", "+ s); |
|
180 |
} |
|
181 | 221 |
} |
182 |
for (FeatureAttributeDescriptor attr : storeType) { |
|
183 |
columns.add(attr); |
|
222 |
} |
|
223 |
if( select.has_where() || select.has_order_by() ) { |
|
224 |
sqlbuilder.setProperties( |
|
225 |
null, |
|
226 |
PROP_FEATURE_TYPE, this.storeType, |
|
227 |
PROP_TABLE, table, |
|
228 |
PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable(), |
|
229 |
PROP_JDBCHELPER, this.helper, |
|
230 |
PROP_QUERY, this.query |
|
231 |
); |
|
232 |
for (ExpressionBuilder.Value value : valuesToRemoveFeatureType) { |
|
233 |
value.setProperty(PROP_FEATURE_TYPE, null); |
|
184 | 234 |
} |
185 |
return sql; |
|
235 |
if( select.has_where()) { |
|
236 |
String s = select.where().toString(); |
|
237 |
sql = StringUtils.replace(sql, "${where_filter}", "WHERE " + s); |
|
238 |
sql = StringUtils.replace(sql, "${and_filter}", "AND (" + s + ")"); |
|
239 |
} |
|
240 |
if( select.has_order_by() ) { |
|
241 |
String s = select.order_by().toString(); |
|
242 |
sql = StringUtils.replace(sql, "${order_by_orderspec}", "ORDER BY " + s); |
|
243 |
sql = StringUtils.replace(sql, "${comma_orderspec}", ", "+ s); |
|
244 |
} |
|
186 | 245 |
} |
187 |
|
|
188 |
|
|
189 |
Map<String, EditableFeatureAttributeDescriptor> allExtraColumns = new HashMap<>(); |
|
190 |
for (EditableFeatureAttributeDescriptor column : this.setType.getExtraColumns().getColumns()) { |
|
191 |
allExtraColumns.put(column.getName(), column); |
|
246 |
for (FeatureAttributeDescriptor attr : storeType) { |
|
247 |
columns.add(attr); |
|
192 | 248 |
} |
193 |
if(query != null){ |
|
194 |
for (EditableFeatureAttributeDescriptor column : this.query.getExtraColumn().getColumns()) { |
|
195 |
allExtraColumns.put(column.getName(), column); |
|
196 |
} |
|
249 |
return sql; |
|
250 |
} |
|
251 |
|
|
252 |
public static void process1_SimpleFields( |
|
253 |
JDBCHelper helper, |
|
254 |
FeatureType setType, |
|
255 |
FeatureQuery query, |
|
256 |
SQLBuilder sqlbuilder, |
|
257 |
SelectBuilder select, |
|
258 |
List<FeatureAttributeDescriptor> columns, |
|
259 |
List<String> primaryKeys, |
|
260 |
List<String> extraColumnNames |
|
261 |
){ |
|
262 |
if(!select.from().table().has_name()){ |
|
263 |
throw new IllegalStateException("Need table in FROM."); |
|
197 | 264 |
} |
198 |
|
|
199 |
List<String> primaryKeys = new ArrayList<>(); |
|
200 |
for (FeatureAttributeDescriptor attr : storeType.getPrimaryKey()) { |
|
201 |
primaryKeys.add(attr.getName()); |
|
202 |
} |
|
265 |
|
|
266 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
267 |
|
|
203 | 268 |
List<String> forcedColumns = new ArrayList<>(primaryKeys); |
204 | 269 |
|
205 | 270 |
String[] constantsAttributeNames = null; |
206 | 271 |
if (query != null && query.hasConstantsAttributeNames()) { |
207 | 272 |
constantsAttributeNames = query.getConstantsAttributeNames(); |
208 | 273 |
} |
274 |
|
|
209 | 275 |
for (FeatureAttributeDescriptor attr : setType) { |
210 | 276 |
if (attr.isComputed()) { |
211 | 277 |
// Campos calculados se a?aden despues para asegurarnos que |
... | ... | |
218 | 284 |
if (attr.isPrimaryKey()) { |
219 | 285 |
forcedColumns.remove(attr.getName()); |
220 | 286 |
} |
221 |
if (query != null && (query.hasGroupByColumns() || query.hasAggregateFunctions()) ) { |
|
222 |
String aggregate = query.getAggregate(this.table.getTable(), attr.getName()); |
|
223 |
if (aggregate == null) { |
|
224 |
if (this.query.isAGroupByColumn(attr.getName()) ) { |
|
225 |
select.column().name(attr.getName()); |
|
226 |
} else if (aggregate == null) { |
Also available in: Unified diff