#2091 - Using Postgis types with query gives PersistenceException Caused by: java.sql.SQLException: Unhandled data type [6000] bind number[0]

This commit is contained in:
rob bygrave committed 2020-10-22 22:48:53 +13:00
1 parent 59bd2bb251
commit 6ecc10a35c
15 files changed
+171 -87

No files matched your search

+21 -17
View File
@@ -1,36 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgis</artifactId>
<version>12.4.2-SNAPSHOT</version>
<parent>
<groupId>org.avaje</groupId>
<artifactId>java8-oss</artifactId>
<version>2.2</version>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>12.5.2-SNAPSHOT</version>
</parent>
<name>ebean postgis</name>
<description>ebean postgis module</description>
<url>https://ebean.io/</url>
<artifactId>ebean-postgis</artifactId>
<properties>
<postgis.jdbc.version>2.2.1</postgis.jdbc.version>
<jackson-core.version>2.11.3</jackson-core.version>
</properties>
<scm>
<developerConnection>scm:git:git@github.com:ebean-orm/ebean-postgis.git</developerConnection>
<tag>HEAD</tag>
</scm>
<dependencies>
<!-- Needs Ebean 8.6.1 or later -->
<!-- provided scope -->
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean</artifactId>
<version>12.4.1</version>
<artifactId>ebean-core</artifactId>
<version>12.5.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-core.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
@@ -64,7 +68,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>12.4.1</version>
<version>12.5.1</version>
<scope>test</scope>
</dependency>
@@ -13,12 +13,12 @@ import io.ebeaninternal.server.type.ScalarType;
import java.util.ArrayList;
import java.util.List;
public class RegisterFactory implements ExtraTypeFactory {
public class PostgisExtraTypeFactory implements ExtraTypeFactory {
@Override
public List<ScalarType<?>> createTypes(DatabaseConfig config, Object objectMapper) {
List<ScalarType<?>> list = new ArrayList<ScalarType<?>>();
List<ScalarType<?>> list = new ArrayList<>();
list.add(new ScalarTypePgisPoint());
list.add(new ScalarTypePgisPolygon());
list.add(new ScalarTypePgisLineString());
@@ -0,0 +1,14 @@
package io.ebean.postgis;
import io.ebean.config.DatabaseConfig;
import io.ebeaninternal.api.GeoTypeProvider;
import io.ebeaninternal.server.type.GeoTypeBinder;
public class PostgisGeoTypeBindProvider implements GeoTypeProvider {
@Override
public GeoTypeBinder createBinder(DatabaseConfig config) {
boolean withGeolatte = config.getClassLoadConfig().isPresent("org.geolatte.geom.Geometry");
return new PostgisGeoTypeBinder(withGeolatte);
}
}
@@ -0,0 +1,32 @@
package io.ebean.postgis;
import io.ebeaninternal.server.type.DataBind;
import io.ebeaninternal.server.type.GeoTypeBinder;
import org.geolatte.geom.codec.Wkt;
import org.postgis.Geometry;
import org.postgis.PGgeometryLW;
import java.sql.SQLException;
class PostgisGeoTypeBinder implements GeoTypeBinder {
private final boolean withGeolatte;
PostgisGeoTypeBinder(boolean withGeolatte) {
this.withGeolatte = withGeolatte;
}
@Override
public void bind(DataBind b, int dataType, Object data) throws SQLException {
if (data instanceof Geometry) {
b.setObject(new PGgeometryLW((Geometry) data));
} else if (withGeolatte) {
b.setObject(new PGgeometryLW(toWktString(data)));
}
}
private String toWktString(Object data) {
org.geolatte.geom.Geometry<?> geoLatte = (org.geolatte.geom.Geometry<?>)data;
return Wkt.newEncoder(Wkt.Dialect.POSTGIS_EWKT_1).encode(geoLatte);
}
}
@@ -1,11 +1,11 @@
package io.ebean.postgis;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import io.ebeaninternal.server.type.DataBind;
import io.ebeaninternal.server.type.DataReader;
import io.ebeaninternal.server.type.ScalarType;
import io.ebeanservice.docstore.api.mapping.DocPropertyType;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import org.postgis.Geometry;
import org.postgis.PGgeometry;
import org.postgis.PGgeometryLW;
@@ -13,7 +13,6 @@ import org.postgresql.util.PGobject;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Types;
@@ -77,12 +76,12 @@ abstract class ScalarTypePgisBase<T extends Geometry> implements ScalarType<T> {
}
@Override
public T readData(DataInput dataInput) throws IOException {
public T readData(DataInput dataInput) {
return null;
}
@Override
public void writeData(DataOutput dataOutput, T v) throws IOException {
public void writeData(DataOutput dataOutput, T v) {
}
@@ -158,12 +157,12 @@ abstract class ScalarTypePgisBase<T extends Geometry> implements ScalarType<T> {
@Override
public T jsonRead(JsonParser parser) throws IOException {
public T jsonRead(JsonParser parser) {
return null;
}
@Override
public void jsonWrite(JsonGenerator writer, T value) throws IOException {
public void jsonWrite(JsonGenerator writer, T value) {
}
}
@@ -1,11 +1,11 @@
package io.ebean.postgis.latte;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import io.ebeaninternal.server.type.DataBind;
import io.ebeaninternal.server.type.DataReader;
import io.ebeaninternal.server.type.ScalarType;
import io.ebeanservice.docstore.api.mapping.DocPropertyType;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import org.geolatte.geom.Geometry;
import org.geolatte.geom.codec.Wkt;
import org.postgis.PGgeometry;
@@ -13,7 +13,6 @@ import org.postgis.PGgeometryLW;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Types;
@@ -71,12 +70,12 @@ abstract class ScalarTypeGeoLatteBase<T extends Geometry> implements ScalarType<
}
@Override
public T readData(DataInput dataInput) throws IOException {
public T readData(DataInput dataInput) {
return null;
}
@Override
public void writeData(DataOutput dataOutput, T v) throws IOException {
public void writeData(DataOutput dataOutput, T v) {
}
@@ -151,12 +150,12 @@ abstract class ScalarTypeGeoLatteBase<T extends Geometry> implements ScalarType<
}
@Override
public T jsonRead(JsonParser parser) throws IOException {
public T jsonRead(JsonParser parser) {
return null;
}
@Override
public void jsonWrite(JsonGenerator writer, T value) throws IOException {
public void jsonWrite(JsonGenerator writer, T value) {
}
}
@@ -1 +1 @@
io.ebean.postgis.RegisterFactory
io.ebean.postgis.PostgisExtraTypeFactory
@@ -0,0 +1 @@
io.ebean.postgis.PostgisGeoTypeBindProvider
@@ -1,9 +1,6 @@
package org.example.domain;
import static org.geolatte.geom.codec.Wkt.toWkt;
import static org.testng.Assert.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import io.ebean.DB;
import org.geolatte.geom.G2D;
import org.geolatte.geom.LineString;
import org.geolatte.geom.MultiLineString;
@@ -17,7 +14,9 @@ import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.ebean.DB;
import static org.geolatte.geom.codec.Wkt.toWkt;
import static org.testng.Assert.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
public class TestQuery {
@@ -110,18 +109,19 @@ public class TestQuery {
// Approx 1100 meters away
// 0.009999999999990905 degrees away
// System.err.println(
// DB
// .sqlQuery("SELECT st_distance(wgs84_point, ?), * FROM mybean").setParameter(toWkt(geolatteClosePoint))
// .findOne()
// );
System.err.println(
DB
.sqlQuery("SELECT st_distance(wgs84_point, ?), * FROM mybean")
.setParameter(toWkt(geolatteClosePoint))
.findOne()
);
assertNotNull(
DB
.find(OtherBeanGeoLatte.class)
.where()
.raw("st_distance(wgs84Point, ?) < 0.011", toWkt(geolatteClosePoint))
// .raw("st_distance(wgs84Point, ?) < 0.011 ", geolatteClosePoint)
.raw("st_distance(wgs84Point, ?) < 0.011 ", geolatteClosePoint)
.findOne()
);
@@ -130,7 +130,7 @@ public class TestQuery {
.find(OtherBeanGeoLatte.class)
.where()
.raw("st_distance(wgs84Point, ?) < 0.009", toWkt(geolatteClosePoint))
// .raw("st_distance(wgs84Point, ?) < 0.009", geolatteClosePoint)
.raw("st_distance(wgs84Point, ?) < 0.009", geolatteClosePoint)
.findOne()
);
@@ -139,7 +139,7 @@ public class TestQuery {
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("ST_Within(wgs84Point, ST_GeomFromText(?))", toWkt(enclosingPolygon))
// .raw("ST_Within(wgs84Point, ?)", enclosingPolygon)
.raw("ST_Within(wgs84Point, ?)", enclosingPolygon)
.findOne()
);
@@ -147,7 +147,7 @@ public class TestQuery {
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("wgs84Point = ST_PointN(ST_GeomFromText(?), 2)", toWkt(lineString))
// .raw("wgs84Point = ST_PointN(?, 2)", lineString)
.raw("wgs84Point = ST_PointN(?, 2)", lineString)
.findOne()
);
@@ -155,7 +155,7 @@ public class TestQuery {
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(ST_GeomFromText(?)), 2)", toWkt(multiPoint))
// .raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(?), 2)", multiPoint)
.raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(?), 2)", multiPoint)
.findOne()
);
@@ -163,7 +163,7 @@ public class TestQuery {
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("ST_Within(wgs84Point, ST_GeomFromText(?))", toWkt(multiPolygon))
// .raw("ST_Within(wgs84Point, ?)", multiPolygon)
.raw("ST_Within(wgs84Point, ?)", multiPolygon)
.findOne()
);
@@ -171,7 +171,7 @@ public class TestQuery {
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("ST_Intersects(wgs84Point, ST_GeomFromText(?))", toWkt(multiLineString))
// .raw("ST_Intersects(wgs84Point, ?)", multiLineString)
.raw("ST_Intersects(wgs84Point, ?)", multiLineString)
.findOne()
);
}
@@ -184,7 +184,7 @@ public class TestQuery {
.find(MyBean.class)
.where()
.raw("st_distance(wgs84Point, ?) < 0.011", toWkt(geolatteClosePoint))
// .raw("st_distance(wgs84Point, ?) < 0.011", new org.postgis.Point(toWkt(geolatteClosePoint)))
.raw("st_distance(wgs84Point, ?) < 0.011", new org.postgis.Point(toWkt(geolatteClosePoint)))
.findOne()
);
@@ -193,7 +193,7 @@ public class TestQuery {
.find(MyBean.class)
.where()
.raw("st_distance(wgs84Point, ?) < 0.009", toWkt(geolatteClosePoint))
// .raw("st_distance(wgs84Point, ?) < 0.009", postgisClosePoint)
.raw("st_distance(wgs84Point, ?) < 0.009", new org.postgis.Point(toWkt(geolatteClosePoint)))
.findOne()
);
@@ -202,7 +202,7 @@ public class TestQuery {
.find(MyBean.class)
.where()
.raw("ST_Within(wgs84Point, ST_GeomFromText(?))", toWkt(enclosingPolygon))
// .raw("ST_Within(wgs84Point, ?)", new org.postgis.Polygon(toWkt(enclosingPolygon)))
.raw("ST_Within(wgs84Point, ?)", new org.postgis.Polygon(toWkt(enclosingPolygon)))
.findOne()
);
@@ -210,7 +210,7 @@ public class TestQuery {
DB.find(MyBean.class)
.where()
.raw("wgs84Point = ST_PointN(ST_GeomFromText(?), 2)", toWkt(lineString))
// .raw("wgs84Point = ST_PointN(?, 2)", new org.postgis.LineString(toWkt(lineString)))
.raw("wgs84Point = ST_PointN(?, 2)", new org.postgis.LineString(toWkt(lineString)))
.findOne()
);
@@ -218,7 +218,7 @@ public class TestQuery {
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(ST_GeomFromText(?)), 2)", toWkt(multiPoint))
// .raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(?), 2)", new org.postgis.MultiPoint(toWkt(multiPoint)))
.raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(?), 2)", new org.postgis.MultiPoint(toWkt(multiPoint)))
.findOne()
);
@@ -226,7 +226,7 @@ public class TestQuery {
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(ST_GeomFromText(?)), 2)", toWkt(multiPoint))
// .raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(?), 2)", new org.postgis.MultiPoint(toWkt(multiPoint)))
.raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(?), 2)", new org.postgis.MultiPoint(toWkt(multiPoint)))
.findOne()
);
@@ -235,7 +235,7 @@ public class TestQuery {
.find(MyBean.class)
.where()
.raw("ST_Within(wgs84Point, ST_GeomFromText(?))", toWkt(multiPolygon))
// .raw("ST_Within(wgs84Point, ?)", new org.postgis.Polygon(toWkt(multiPolygon)))
.raw("ST_Within(wgs84Point, ?)", new org.postgis.MultiPolygon(toWkt(multiPolygon)))
.findOne()
);
@@ -243,7 +243,7 @@ public class TestQuery {
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("ST_Intersects(wgs84Point, ST_GeomFromText(?))", toWkt(multiLineString))
// .raw("ST_Intersects(wgs84Point, ?)", new org.postgis.MultiLineString(toWkt(multiLineString)))
.raw("ST_Intersects(wgs84Point, ?)", new org.postgis.MultiLineString(toWkt(multiLineString)))
.findOne()
);
}