mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-26 16:01:45 +00:00
Failing testcase for ebean query serializer
This commit is contained in:
@@ -7,6 +7,7 @@ import org.postgis.MultiPolygon;
|
||||
import org.postgis.Point;
|
||||
import org.postgis.Polygon;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@@ -28,6 +29,9 @@ public class MyBean extends BaseEntity {
|
||||
|
||||
MultiPolygon mpoly;
|
||||
|
||||
@Column(columnDefinition = "geometry(Point, 4326)")
|
||||
Point wgs84Point;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -83,4 +87,12 @@ public class MyBean extends BaseEntity {
|
||||
public void setMpoly(MultiPolygon mpoly) {
|
||||
this.mpoly = mpoly;
|
||||
}
|
||||
|
||||
public Point getWgs84Point() {
|
||||
return wgs84Point;
|
||||
}
|
||||
|
||||
public void setWgs84Point(final Point wgs84Point) {
|
||||
this.wgs84Point = wgs84Point;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.example.domain;
|
||||
|
||||
|
||||
import org.geolatte.geom.G2D;
|
||||
import org.geolatte.geom.LineString;
|
||||
import org.geolatte.geom.MultiLineString;
|
||||
import org.geolatte.geom.MultiPoint;
|
||||
@@ -8,6 +9,7 @@ import org.geolatte.geom.MultiPolygon;
|
||||
import org.geolatte.geom.Point;
|
||||
import org.geolatte.geom.Polygon;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@@ -29,6 +31,9 @@ public class OtherBeanGeoLatte extends BaseEntity {
|
||||
|
||||
MultiPolygon mpoly;
|
||||
|
||||
@Column(columnDefinition = "geometry(Point, 4326)")
|
||||
Point<G2D> wgs84Point;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -84,4 +89,12 @@ public class OtherBeanGeoLatte extends BaseEntity {
|
||||
public void setMultiPoint(MultiPoint multiPoint) {
|
||||
this.multiPoint = multiPoint;
|
||||
}
|
||||
|
||||
public Point<G2D> getWgs84Point() {
|
||||
return wgs84Point;
|
||||
}
|
||||
|
||||
public void setWgs84Point(final Point<G2D> wgs84Point) {
|
||||
this.wgs84Point = wgs84Point;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.example.domain;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.AssertJUnit.assertNull;
|
||||
|
||||
import org.geolatte.geom.G2D;
|
||||
import org.geolatte.geom.Point;
|
||||
import org.geolatte.geom.crs.CoordinateReferenceSystems;
|
||||
import org.junit.Ignore;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import io.ebean.DB;
|
||||
|
||||
public class TestQuery {
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGeoQueryGeoLatte() {
|
||||
OtherBeanGeoLatte mb = new OtherBeanGeoLatte();
|
||||
mb.setWgs84Point(
|
||||
new Point<>(
|
||||
new G2D(174.76345825195312, -36.85315704345703),
|
||||
CoordinateReferenceSystems.WGS84
|
||||
)
|
||||
);
|
||||
DB.save(mb);
|
||||
|
||||
// Approx 1100 meters away
|
||||
// 0.009999999999990905 degrees away
|
||||
Point<G2D> closePoint = new Point<>(
|
||||
new G2D(174.75345825195312, -36.85315704345703),
|
||||
CoordinateReferenceSystems.WGS84
|
||||
);
|
||||
|
||||
assertNotNull(
|
||||
DB
|
||||
.find(OtherBeanGeoLatte.class)
|
||||
.where()
|
||||
// .raw("st_distance(wgs84Point, ?) < 0.011", Wkt.newEncoder().encode(closePoint))
|
||||
.raw("st_distance(wgs84Point, ?) < 0.011 ", closePoint)
|
||||
.findOne()
|
||||
);
|
||||
|
||||
assertNull(
|
||||
DB
|
||||
.find(OtherBeanGeoLatte.class)
|
||||
.where()
|
||||
// .raw("st_distance(wgs84Point, ?) < 0.009", Wkt.newEncoder().encode(closePoint))
|
||||
.raw("st_distance(wgs84Point, ?) < 0.009", closePoint)
|
||||
.findOne()
|
||||
);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGeoQueryPostgis() {
|
||||
MyBean mb = new MyBean();
|
||||
final org.postgis.Point wgs84Point = new org.postgis.Point(174.76345825195312, -36.85315704345703);
|
||||
wgs84Point.setSrid(4326);
|
||||
mb.setWgs84Point(wgs84Point);
|
||||
DB.save(mb);
|
||||
|
||||
org.postgis.Point closePoint = new org.postgis.Point(174.75345825195312, -36.85315704345703);
|
||||
|
||||
assertNotNull(
|
||||
DB
|
||||
.find(MyBean.class)
|
||||
.where()
|
||||
// .raw("st_distance(wgs84Point, ?) < 0.011", toText(closePoint))
|
||||
.raw("st_distance(wgs84Point, ?) < 0.011", closePoint)
|
||||
.findOne()
|
||||
);
|
||||
|
||||
assertNull(
|
||||
DB
|
||||
.find(MyBean.class)
|
||||
.where()
|
||||
// .raw("st_distance(wgs84Point, ?) < 0.009", toText(closePoint))
|
||||
.raw("st_distance(wgs84Point, ?) < 0.009", closePoint)
|
||||
.findOne()
|
||||
);
|
||||
}
|
||||
|
||||
public String toText(org.postgis.Point wgs84Point) {
|
||||
return "SRID=4326;POINT(" + wgs84Point.getX() + " " + wgs84Point.getY() + ")";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user