Skip to content

Commit

Permalink
Add support for Postgis JTS (#416)
Browse files Browse the repository at this point in the history
* Add support for Postgis JTS

* Return project build to java 11

---------

Co-authored-by: Marvin <velo@users.noreply.github.com>
  • Loading branch information
vidakovic and velo committed May 2, 2024
1 parent ebb438f commit d303e8b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 0 additions & 1 deletion .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions querydsl-libraries/querydsl-sql-spatial/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
<version>2023.1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.postgis</groupId>
<artifactId>postgis-jdbc-jts</artifactId>
<version>2023.1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Geometry> {

public static final JtsGeometryType DEFAULT = new JtsGeometryType();

public JtsGeometryType() {
super(Types.STRUCT);
}

@Override
public Class<Geometry> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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})");
Expand Down

0 comments on commit d303e8b

Please sign in to comment.