"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "modules/extension/app-schema/app-schema/src/main/java/org/geotools/appschema/jdbc/NestedFilterToSQL.java" between
geotools-21.1-project.zip and geotools-21.2-project.zip

About: GeoTools (The Open Source Java GIS Toolkit) is a Java code library which provides standards compliant methods for the manipulation of geospatial data.

NestedFilterToSQL.java  (geotools-21.1-project):NestedFilterToSQL.java  (geotools-21.2-project)
skipping to change at line 193 skipping to change at line 193
store.dialect.encodeColumnName(multipleValue.getSourceColumn(), sql); store.dialect.encodeColumnName(multipleValue.getSourceColumn(), sql);
sql.append(" = "); sql.append(" = ");
store.dialect.encodeTableName(alias, sql); store.dialect.encodeTableName(alias, sql);
sql.append("."); sql.append(".");
store.dialect.encodeColumnName(multipleValue.getTargetColumn(), sql); store.dialect.encodeColumnName(multipleValue.getTargetColumn(), sql);
sql.append(" "); sql.append(" ");
} }
protected Object visitNestedFilter(Filter filter, Object extraData, String x path) { protected Object visitNestedFilter(Filter filter, Object extraData, String x path) {
try { try {
FeatureChainedAttributeVisitor nestedMappingsExtractor = FeatureChainedAttributeVisitor nestedMappingsExtractor =
new FeatureChainedAttributeVisitor(rootMapping); new FeatureChainedAttributeVisitor(rootMapping);
nestedMappingsExtractor.visit(ff.property(xpath), null); nestedMappingsExtractor.visit(ff.property(xpath), null);
List<FeatureChainedAttributeDescriptor> attributes = List<FeatureChainedAttributeDescriptor> attributes =
nestedMappingsExtractor.getFeatureChainedAttributes(); nestedMappingsExtractor.getFeatureChainedAttributes();
// encoding of filters on multiple nested attributes is not (yet) su if (attributes.size() >= 1) {
pported if (attributes.size() > 1) out.write("(");
if (attributes.size() == 1) { boolean first = true;
FeatureChainedAttributeDescriptor nestedAttrDescr = attributes.g for (FeatureChainedAttributeDescriptor nestedAttrDescr : attribu
et(0); tes) {
if (first) first = false;
int numMappings = nestedAttrDescr.chainSize(); else out.write(" OR ");
if (numMappings > 0 && nestedAttrDescr.isJoiningEnabled()) { encodeChainedAttribute(filter, xpath, nestedAttrDescr);
out.write("EXISTS (");
FeatureChainLink lastMappingStep = nestedAttrDescr.getLastLi
nk();
StringBuffer sql = encodeSelectKeyFrom(lastMappingStep);
JDBCDataStore store =
(JDBCDataStore)
lastMappingStep
.getFeatureTypeMapping()
.getSource()
.getDataStore();
encodeMultipleValueJoin(nestedAttrDescr, store, sql);
for (int i = numMappings - 2; i > 0; i--) {
FeatureChainLink mappingStep = nestedAttrDescr.getLink(i
);
if (mappingStep.hasNestedFeature()) {
FeatureTypeMapping parentFeature = mappingStep.getFe
atureTypeMapping();
store = (JDBCDataStore) parentFeature.getSource().ge
tDataStore();
String parentTableName =
parentFeature.getSource().getSchema().getNam
e().getLocalPart();
sql.append(" INNER JOIN ");
store.encodeTableName(parentTableName, sql, null);
sql.append(" ");
store.dialect.encodeTableName(mappingStep.getAlias()
, sql);
sql.append(" ON ");
encodeJoinCondition(nestedAttrDescr, i, sql);
}
}
if (nestedAttrDescr.getAttributePath() != null) {
createWhereClause(filter, xpath, nestedAttrDescr, sql);
sql.append(" AND ");
} else {
sql.append(" WHERE ");
}
// join with root table
encodeJoinCondition(nestedAttrDescr, 0, sql);
out.write(sql.toString());
out.write(")");
} }
if (attributes.size() > 1) out.write(")");
} }
return extraData; return extraData;
} catch (java.io.IOException ioe) { } catch (java.io.IOException ioe) {
throw new RuntimeException("Problem writing filter: ", ioe); throw new RuntimeException("Problem writing filter: ", ioe);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException("Problem writing filter: ", e); throw new RuntimeException("Problem writing filter: ", e);
} catch (FilterToSQLException e) { } catch (FilterToSQLException e) {
throw new RuntimeException("Problem writing filter: ", e); throw new RuntimeException("Problem writing filter: ", e);
} }
} }
private void encodeChainedAttribute(
Filter filter, String xpath, FeatureChainedAttributeDescriptor neste
dAttrDescr)
throws IOException, SQLException, FilterToSQLException {
int numMappings = nestedAttrDescr.chainSize();
if (numMappings > 0 && nestedAttrDescr.isJoiningEnabled()) {
out.write("EXISTS (");
FeatureChainLink lastMappingStep = nestedAttrDescr.getLastLink();
StringBuffer sql = encodeSelectKeyFrom(lastMappingStep);
JDBCDataStore store =
(JDBCDataStore)
lastMappingStep.getFeatureTypeMapping().getSource().
getDataStore();
encodeMultipleValueJoin(nestedAttrDescr, store, sql);
for (int i = numMappings - 2; i > 0; i--) {
FeatureChainLink mappingStep = nestedAttrDescr.getLink(i);
if (mappingStep.hasNestedFeature()) {
FeatureTypeMapping parentFeature = mappingStep.getFeatureTyp
eMapping();
store = (JDBCDataStore) parentFeature.getSource().getDataSto
re();
String parentTableName =
parentFeature.getSource().getSchema().getName().getL
ocalPart();
sql.append(" INNER JOIN ");
store.encodeTableName(parentTableName, sql, null);
sql.append(" ");
store.dialect.encodeTableName(mappingStep.getAlias(), sql);
sql.append(" ON ");
encodeJoinCondition(nestedAttrDescr, i, sql);
}
}
if (nestedAttrDescr.getAttributePath() != null) {
createWhereClause(filter, xpath, nestedAttrDescr, sql);
sql.append(" AND ");
} else {
sql.append(" WHERE ");
}
// join with root table
encodeJoinCondition(nestedAttrDescr, 0, sql);
out.write(sql.toString());
out.write(")");
}
}
private void encodeJoinCondition( private void encodeJoinCondition(
FeatureChainedAttributeDescriptor nestedAttrDescr, int stepIdx, Stri ngBuffer sql) FeatureChainedAttributeDescriptor nestedAttrDescr, int stepIdx, Stri ngBuffer sql)
throws SQLException, IOException, FilterToSQLException { throws SQLException, IOException, FilterToSQLException {
FeatureChainLink parentStep = nestedAttrDescr.getLink(stepIdx); FeatureChainLink parentStep = nestedAttrDescr.getLink(stepIdx);
FeatureChainLink nestedStep = nestedAttrDescr.getLink(stepIdx + 1); FeatureChainLink nestedStep = nestedAttrDescr.getLink(stepIdx + 1);
FeatureTypeMapping parentFeature = parentStep.getFeatureTypeMapping(); FeatureTypeMapping parentFeature = parentStep.getFeatureTypeMapping();
JDBCDataStore store = (JDBCDataStore) parentFeature.getSource().getDataS tore(); JDBCDataStore store = (JDBCDataStore) parentFeature.getSource().getDataS tore();
NestedAttributeMapping nestedFeatureAttr = parentStep.getNestedFeatureAt tribute(); NestedAttributeMapping nestedFeatureAttr = parentStep.getNestedFeatureAt tribute();
FeatureTypeMapping nestedFeature = nestedFeatureAttr.getFeatureTypeMappi ng(null); FeatureTypeMapping nestedFeature = nestedFeatureAttr.getFeatureTypeMappi ng(null);
 End of changes. 5 change blocks. 
58 lines changed or deleted 61 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)