Skip to content

Commit

Permalink
Distinguish spatial queries for MariaDB and Postgres as the specific …
Browse files Browse the repository at this point in the history
…geometric functions differ. The ExpressionHandler class contains the functions similar for all database dialects. Specific differences in the dialects are implemented in PgExpressionHandler and MariaDbExpressionHandler.
  • Loading branch information
T-Hellmund committed Oct 9, 2024
1 parent bd35e90 commit e9b0459
Show file tree
Hide file tree
Showing 7 changed files with 1,291 additions and 1,245 deletions.

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,74 @@
/*
* 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 de.fraunhofer.iosb.ilt.frostserver.settings.Settings;
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);
private int maxCustomLinkDepth = -1;

public MariaDBExpressionHandler(CoreSettings settings, QueryBuilder queryBuilder) {
super(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
Loading

0 comments on commit e9b0459

Please sign in to comment.