mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
#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:
1 parent
59bd2bb251
commit
6ecc10a35c
15 files changed
+171
-87
No files matched your search
+2
-2
@@ -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
@@ -1 +1 @@
|
||||
io.ebean.postgis.RegisterFactory
|
||||
io.ebean.postgis.PostgisExtraTypeFactory
|
||||
+1
@@ -0,0 +1 @@
|
||||
io.ebean.postgis.PostgisGeoTypeBindProvider
|
||||
Reference in new issue
Block a user