From d303e8b61032ee90c27258f05e39931ad49854a7 Mon Sep 17 00:00:00 2001 From: Aleksandar Vidakovic Date: Thu, 2 May 2024 20:57:35 +0200 Subject: [PATCH] Add support for Postgis JTS (#416) * Add support for Postgis JTS * Return project build to java 11 --------- Co-authored-by: Marvin --- .mvn/jvm.config | 1 - .../querydsl-sql-spatial/pom.xml | 6 +++ .../querydsl/sql/spatial/JtsGeometryType.java | 47 +++++++++++++++++++ .../sql/spatial/PostGISTemplates.java | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 querydsl-libraries/querydsl-sql-spatial/src/main/java/com/querydsl/sql/spatial/JtsGeometryType.java diff --git a/.mvn/jvm.config b/.mvn/jvm.config index e02ee82342..c149b870b8 100644 --- a/.mvn/jvm.config +++ b/.mvn/jvm.config @@ -1,4 +1,3 @@ ---illegal-access=permit --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED diff --git a/querydsl-libraries/querydsl-sql-spatial/pom.xml b/querydsl-libraries/querydsl-sql-spatial/pom.xml index df3231a0c2..b763b66218 100644 --- a/querydsl-libraries/querydsl-sql-spatial/pom.xml +++ b/querydsl-libraries/querydsl-sql-spatial/pom.xml @@ -93,6 +93,12 @@ 2023.1.0 true + + net.postgis + postgis-jdbc-jts + 2023.1.0 + true + com.oracle.database.jdbc ojdbc8 diff --git a/querydsl-libraries/querydsl-sql-spatial/src/main/java/com/querydsl/sql/spatial/JtsGeometryType.java b/querydsl-libraries/querydsl-sql-spatial/src/main/java/com/querydsl/sql/spatial/JtsGeometryType.java new file mode 100644 index 0000000000..23a991de26 --- /dev/null +++ b/querydsl-libraries/querydsl-sql-spatial/src/main/java/com/querydsl/sql/spatial/JtsGeometryType.java @@ -0,0 +1,47 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.querydsl.sql.spatial; + +import com.querydsl.sql.types.AbstractType; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import net.postgis.jdbc.jts.JtsGeometry; +import org.locationtech.jts.geom.Geometry; + +class JtsGeometryType extends AbstractType { + + public static final JtsGeometryType DEFAULT = new JtsGeometryType(); + + public JtsGeometryType() { + super(Types.STRUCT); + } + + @Override + public Class getReturnedClass() { + return Geometry.class; + } + + @Override + public Geometry getValue(ResultSet rs, int startIndex) throws SQLException { + var value = rs.getObject(startIndex, JtsGeometry.class); + return value.getGeometry(); + } + + @Override + public void setValue(PreparedStatement st, int startIndex, Geometry value) throws SQLException { + st.setObject(startIndex, new JtsGeometry(value)); + } +} diff --git a/querydsl-libraries/querydsl-sql-spatial/src/main/java/com/querydsl/sql/spatial/PostGISTemplates.java b/querydsl-libraries/querydsl-sql-spatial/src/main/java/com/querydsl/sql/spatial/PostGISTemplates.java index 90d756289a..51513fee05 100644 --- a/querydsl-libraries/querydsl-sql-spatial/src/main/java/com/querydsl/sql/spatial/PostGISTemplates.java +++ b/querydsl-libraries/querydsl-sql-spatial/src/main/java/com/querydsl/sql/spatial/PostGISTemplates.java @@ -47,6 +47,7 @@ public PostGISTemplates(boolean quote) { public PostGISTemplates(char escape, boolean quote) { super(escape, quote); addCustomType(PGgeometryType.DEFAULT); + addCustomType(JtsGeometryType.DEFAULT); add(SpatialTemplatesSupport.getSpatialOps(true)); add(SpatialOps.DISTANCE_SPHERE, "ST_Distance_Sphere({0}, {1})"); add(SpatialOps.DISTANCE_SPHEROID, "ST_Distance_Spheroid({0}, {1})");