Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish spatial queries for MariaDB and Postgres and enhance geospatial support for MariaDB. #2036

Merged
merged 1 commit into from
Oct 10, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FROST-Server version 2.5 and higher requires Java 21. This is because some libra
**New Features**
* Updated to jakarta EE 10: FROST-Server is now runs on Tomcat 10 and later.
* Added a validator that sets a time to now(), unless otherwise set.
* Added support for spatial queries on MariaDB.

**Internal changes & Bugfixes**
* Set limit to 1 for entity-by-primary-key requests.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public interface JooqPersistenceManager extends LiquibaseUser, PersistenceManage

void generateLiquibaseVariables(Map<String, Object> target, String entity, String type);

ExpressionHandler createExpressionHandler(QueryBuilder queryBuilder);

Entity get(EntityType entityType, PkValue id, Query query);

ConnectionUtils.ConnectionWrapper getConnectionProvider();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2024 Fraunhofer Institut IOSB, Fraunhoferstr. 1, D 76131
* Karlsruhe, Germany.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq;

import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings.PostGisGeometryBinding;
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.fieldwrapper.FieldWrapper;
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.fieldwrapper.SimpleFieldWrapper;
import de.fraunhofer.iosb.ilt.frostserver.query.expression.constant.GeoJsonConstant;
import de.fraunhofer.iosb.ilt.frostserver.query.expression.constant.LineStringConstant;
import de.fraunhofer.iosb.ilt.frostserver.query.expression.constant.PointConstant;
import de.fraunhofer.iosb.ilt.frostserver.query.expression.constant.PolygonConstant;
import de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings;
import org.geojson.GeoJsonObject;
import org.geolatte.geom.Geometry;
import org.geolatte.geom.codec.Wkt;
import org.jooq.impl.DSL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author Hylke van der Schaaf
*/
public class MariaDBExpressionHandler extends ExpressionHandler {

private static final String ST_GeomFromText = "ST_GeomFromText(?)";

private static final Logger LOGGER = LoggerFactory.getLogger(MariaDBExpressionHandler.class);

public MariaDBExpressionHandler(CoreSettings settings, QueryBuilder queryBuilder) {
super(settings, queryBuilder);
}

@Override
public FieldWrapper visit(LineStringConstant node) {
Geometry geom = fromGeoJsonConstant(node);
return new SimpleFieldWrapper(DSL.field(ST_GeomFromText, PostGisGeometryBinding.dataType(), geom.asText()));
}

@Override
public FieldWrapper visit(PointConstant node) {
Geometry geom = fromGeoJsonConstant(node);
return new SimpleFieldWrapper(DSL.field(ST_GeomFromText, PostGisGeometryBinding.dataType(), geom.asText()));
}

@Override
public FieldWrapper visit(PolygonConstant node) {
Geometry geom = fromGeoJsonConstant(node);
return new SimpleFieldWrapper(DSL.field(ST_GeomFromText, PostGisGeometryBinding.dataType(), geom.asText()));
}

public Geometry fromGeoJsonConstant(GeoJsonConstant<? extends GeoJsonObject> node) {
if (node.getValue().getCrs() == null) {
return Wkt.fromWkt(node.getSource());
}
return Wkt.fromWkt(node.getSource());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,11 @@ public void generateLiquibaseVariables(Map<String, Object> target, String entity
}
}

@Override
public ExpressionHandler createExpressionHandler(QueryBuilder queryBuilder) {
return new MariaDBExpressionHandler(settings, queryBuilder);
}

@Override
public String checkForUpgrades() {
Map<String, Object> props = CollectionsHelper.LinkedHashMapBuilder()
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,11 @@ public void generateLiquibaseVariables(Map<String, Object> target, String entity
}
}

@Override
public ExpressionHandler createExpressionHandler(QueryBuilder queryBuilder) {
return new PgExpressionHandler(settings, queryBuilder);
}

@Override
public String checkForUpgrades() {
Map<String, Object> props = CollectionsHelper.LinkedHashMapBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private void handleEntityExpand(QueryState sqlState, Expand expand, NavigationPr

private void parseOrder(Query query) {
if (query != null) {
PgExpressionHandler handler = new PgExpressionHandler(coreSettings, this);
ExpressionHandler handler = getPersistenceManager().createExpressionHandler(this);
for (OrderBy ob : query.getOrderBy()) {
handler.addOrderbyToQuery(ob, queryState.getSqlSortFields());
}
Expand All @@ -440,7 +440,7 @@ public void parseFilter(Query query) {
queryState.setFilter(true);
final Expression filter = query.getFilter();
final Expression skipFilter = query.getSkipFilter();
PgExpressionHandler handler = new PgExpressionHandler(coreSettings, this);
ExpressionHandler handler = getPersistenceManager().createExpressionHandler(this);
if (filter != null) {
queryState.setSqlWhere(handler.addFilterToWhere(filter, queryState.getSqlWhere()));
}
Expand Down