Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
Expand Down Expand Up @@ -186,10 +187,11 @@ private List<FeatureSchema> getFeatureTypes(
featureProperty.excludedScopes(ImmutableList.of(Scope.RECEIVABLE));
}
if (featurePropertyType == SchemaBase.Type.GEOMETRY) {
if (!geometryInfos.containsKey(table.getName())) {
GeoInfo geometryInfo =
lookupGeometryInfo(geometryInfos, schema.getName(), table.getName());
if (Objects.isNull(geometryInfo)) {
continue;
}
GeoInfo geometryInfo = geometryInfos.get(table.getName());

// if srid=0, do not set, will use default
try {
Expand Down Expand Up @@ -258,10 +260,11 @@ private FeatureSchema getFeatureType(Table table, Map<String, GeoInfo> geometryI
}
}
if (featurePropertyType == SchemaBase.Type.GEOMETRY) {
if (!geometryInfos.containsKey(table.getName())) {
GeoInfo geometryInfo =
lookupGeometryInfo(geometryInfos, table.getSchema().getName(), table.getName());
if (Objects.isNull(geometryInfo)) {
continue;
}
GeoInfo geometryInfo = geometryInfos.get(table.getName());

// if srid=0, do not set, will use default
try {
Expand Down Expand Up @@ -292,11 +295,29 @@ private FeatureSchema getFeatureType(Table table, Map<String, GeoInfo> geometryI
return featureSchema;
}

private GeoInfo lookupGeometryInfo(
Map<String, GeoInfo> geometryInfos, String schema, String table) {
String geometryInfoKeySchema =
String.format("%s.%s", Objects.requireNonNullElse(schema, ""), table)
.toLowerCase(Locale.ROOT);
String geometryInfoKeyTable = table.toLowerCase(Locale.ROOT);

if (geometryInfos.containsKey(geometryInfoKeySchema)) {
return geometryInfos.get(geometryInfoKeySchema);
}
if (geometryInfos.containsKey(geometryInfoKeyTable)) {
return geometryInfos.get(geometryInfoKeyTable);
}

return null;
}

private SchemaBase.Type getFeaturePropertyType(ColumnDataType columnDataType) {
// TODO: pass GeoInfo to determine geo columns
try {
if ("GEOMETRY".equals(columnDataType.getName())
|| WktWkbGeometryType.valueOf(columnDataType.getName()) != WktWkbGeometryType.NONE) {
if ("GEOMETRY".equalsIgnoreCase(columnDataType.getName())
|| WktWkbGeometryType.valueOf(columnDataType.getName().toUpperCase(Locale.ROOT))
!= WktWkbGeometryType.NONE) {
return SchemaBase.Type.GEOMETRY;
}
} catch (Exception ignore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.text.Collator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -185,16 +186,23 @@ public Map<String, GeoInfo> getGeoInfo(Connection connection, DbInfo dbInfo) thr
Map<String, GeoInfo> result = new LinkedHashMap<>();

while (rs.next()) {
result.put(
rs.getString(GeoInfo.TABLE),
String table = rs.getString(GeoInfo.TABLE);
String tableKey = table.toLowerCase(Locale.ROOT);
String schemaTableKey = String.format("%s.%s", "main", table).toLowerCase(Locale.ROOT);
GeoInfo geoInfo =
ImmutableGeoInfo.of(
null,
rs.getString(GeoInfo.TABLE),
table,
rs.getString(GeoInfo.COLUMN),
rs.getString(GeoInfo.DIMENSION),
rs.getString(GeoInfo.SRID),
forceAxisOrder((DbInfoGpkg) dbInfo).name(),
rs.getString(GeoInfo.TYPE)));
rs.getString(GeoInfo.TYPE));

// keep a normalized table-only key as canonical lookup key
result.put(tableKey, geoInfo);
// additionally provide normalized schema.table compatibility key
result.put(schemaTableKey, geoInfo);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,15 @@ public Map<String, GeoInfo> getGeoInfo(Connection connection, DbInfo dbInfo) thr
Map<String, GeoInfo> result = new LinkedHashMap<>();

while (rs.next()) {
String schema = rs.getString(GeoInfo.SCHEMA);
String table = rs.getString(GeoInfo.TABLE);
String key = String.format("%s.%s", schema, table).toLowerCase(Locale.ROOT);

result.put(
rs.getString(GeoInfo.TABLE),
key,
ImmutableGeoInfo.of(
rs.getString(GeoInfo.SCHEMA),
rs.getString(GeoInfo.TABLE),
schema,
table,
rs.getString(GeoInfo.COLUMN),
rs.getString(GeoInfo.DIMENSION),
rs.getString(GeoInfo.SRID),
Expand Down
Loading