Move into ebean-postgres sub directory

This commit is contained in:
rob bygrave committed 2020-10-22 21:18:18 +13:00
1 parent f383f3f759
commit 9fa83cdd5a
29 files changed

No files matched your search

@@ -0,0 +1,20 @@
package org.example.domain;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
@MappedSuperclass
abstract class BaseEntity {
@Id
Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
@@ -0,0 +1,98 @@
package org.example.domain;
import org.postgis.LineString;
import org.postgis.MultiLineString;
import org.postgis.MultiPoint;
import org.postgis.MultiPolygon;
import org.postgis.Point;
import org.postgis.Polygon;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name="mybean")
public class MyBean extends BaseEntity {
String name;
Point point;
Polygon poly;
LineString lineString;
MultiLineString multiLineString;
MultiPoint multiPoint;
MultiPolygon mpoly;
@Column(columnDefinition = "geometry(Point, 4326)", unique = true)
Point wgs84Point;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
public Polygon getPoly() {
return poly;
}
public void setPoly(Polygon poly) {
this.poly = poly;
}
public LineString getLineString() {
return lineString;
}
public void setLineString(LineString lineString) {
this.lineString = lineString;
}
public MultiLineString getMultiLineString() {
return multiLineString;
}
public void setMultiLineString(MultiLineString multiLineString) {
this.multiLineString = multiLineString;
}
public MultiPoint getMultiPoint() {
return multiPoint;
}
public void setMultiPoint(MultiPoint multiPoint) {
this.multiPoint = multiPoint;
}
public MultiPolygon getMpoly() {
return mpoly;
}
public void setMpoly(MultiPolygon mpoly) {
this.mpoly = mpoly;
}
public Point getWgs84Point() {
return wgs84Point;
}
public void setWgs84Point(final Point wgs84Point) {
this.wgs84Point = wgs84Point;
}
}
@@ -0,0 +1,100 @@
package org.example.domain;
import org.geolatte.geom.G2D;
import org.geolatte.geom.LineString;
import org.geolatte.geom.MultiLineString;
import org.geolatte.geom.MultiPoint;
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;
@Entity
@Table(name="mybean")
public class OtherBeanGeoLatte extends BaseEntity {
String name;
Point point;
Polygon poly;
LineString lineString;
MultiLineString multiLineString;
MultiPoint multiPoint;
MultiPolygon mpoly;
@Column(columnDefinition = "geometry(Point, 4326)", unique = true)
Point<G2D> wgs84Point;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
public Polygon getPoly() {
return poly;
}
public void setPoly(Polygon poly) {
this.poly = poly;
}
public MultiPolygon getMpoly() {
return mpoly;
}
public void setMpoly(MultiPolygon mpoly) {
this.mpoly = mpoly;
}
public LineString getLineString() {
return lineString;
}
public void setLineString(LineString lineString) {
this.lineString = lineString;
}
public MultiLineString getMultiLineString() {
return multiLineString;
}
public void setMultiLineString(MultiLineString multiLineString) {
this.multiLineString = multiLineString;
}
public MultiPoint getMultiPoint() {
return multiPoint;
}
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,62 @@
package org.example.domain;
import io.ebean.Ebean;
import org.postgis.LineString;
import org.postgis.MultiLineString;
import org.postgis.MultiPoint;
import org.postgis.MultiPolygon;
import org.postgis.Point;
import org.postgis.Polygon;
import org.testng.annotations.Test;
import java.sql.SQLException;
import java.util.List;
public class TestInsertQuery {
/**
* Not automated this test yet.
*/
@Test(enabled = false)
public void insert() throws SQLException {
List<MyBean> list = Ebean.find(MyBean.class).findList();
for (MyBean MyBean : list) {
System.out.println(MyBean.getPoint());
}
List<MyBean> list1 = Ebean.find(MyBean.class)
.where()
.raw("st_within(st_pointfromwkb(st_point(?, ?), 4674), poly)", 1.9, 1.9)
.findList();
System.out.println(list1);
Point point = new Point("SRID=4674;POINT(2.8 1.7)");
Polygon poly = new Polygon("SRID=4674;POLYGON((2 2, 2 -2, -2 -2, -2 2, 2 2))");
LineString lineString = new LineString("SRID=4674;LINESTRING(0 0, 1 2)");
MultiLineString multiLineString = new MultiLineString("SRID=4674;MULTILINESTRING((0 0, 1 2), (1 2, 3 -1))");
MultiPoint multiPoint = new MultiPoint("SRID=4674;MULTIPOINT((2 3), (7 8))");
MultiPolygon mpoly = new MultiPolygon("SRID=4674;MULTIPOLYGON(((1 1, 1 -1, -1 -1, -1 1, 1 1)),((1 1, 3 1, 3 3, 1 3, 1 1)))");
MyBean p = new MyBean();
p.setName("me at "+System.currentTimeMillis());
p.setPoint(point);
p.setPoly(poly);
p.setLineString(lineString);
p.setMultiLineString(multiLineString);
p.setMultiPoint(multiPoint);
p.setMpoly(mpoly);
Ebean.save(p);
List<String> content =
Ebean.find(MyBean.class)
.select("ST_AsText(lineString)::String")
.findSingleAttributeList();
System.out.println(content);
}
}
@@ -0,0 +1,57 @@
package org.example.domain;
import io.ebean.Ebean;
import org.geolatte.geom.Point;
import org.geolatte.geom.Polygon;
import org.geolatte.geom.codec.Wkt;
import org.geolatte.geom.LineString;
import org.geolatte.geom.MultiLineString;
import org.geolatte.geom.MultiPoint;
import org.geolatte.geom.MultiPolygon;
import org.testng.annotations.Test;
import java.sql.SQLException;
import java.util.List;
public class TestOtherInsertQuery {
/**
* Not automated this test yet.
*/
@Test(enabled = false)
public void insert() throws SQLException {
List<OtherBeanGeoLatte> list = Ebean.find(OtherBeanGeoLatte.class).findList();
for (OtherBeanGeoLatte OtherBeanGeoLatte : list) {
System.out.println(OtherBeanGeoLatte.getPoint());
}
List<OtherBeanGeoLatte> list1 = Ebean.find(OtherBeanGeoLatte.class)
.where()
.raw("st_within(st_pointfromwkb(st_point(?, ?), 4674), poly)", 1.9, 1.9)
.findList();
System.out.println(list1);
Point point = (Point) Wkt.fromWkt("SRID=4674;POINT (12 23)");
Polygon poly = (Polygon) Wkt.fromWkt("SRID=4674;POLYGON((2 2, 2 -2, -2 -2, -2 2, 2 2))");
LineString lineString = (LineString)Wkt.fromWkt("SRID=4674;LINESTRING(0 0, 1 2)");
MultiLineString multiLineString = (MultiLineString)Wkt.fromWkt("SRID=4674;MULTILINESTRING((0 0, 1 2), (1 2, 3 -1))");
MultiPoint multiPoint = (MultiPoint)Wkt.fromWkt("SRID=4674;MULTIPOINT(10 40, 40 30, 20 20, 30 10)");
MultiPolygon mpoly = (MultiPolygon)Wkt.fromWkt("SRID=4674;MULTIPOLYGON(((1 1, 1 -1, -1 -1, -1 1, 1 1)),((1 1, 3 1, 3 3, 1 3, 1 1)))");
OtherBeanGeoLatte p = new OtherBeanGeoLatte();
p.setName("geolatte at "+System.currentTimeMillis());
p.setPoint(point);
p.setPoly(poly);
p.setLineString(lineString);
p.setMpoly(mpoly);
p.setMultiPoint(multiPoint);
p.setMultiLineString(multiLineString);
Ebean.save(p);
}
}
@@ -0,0 +1,250 @@
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 org.geolatte.geom.G2D;
import org.geolatte.geom.LineString;
import org.geolatte.geom.MultiLineString;
import org.geolatte.geom.MultiPoint;
import org.geolatte.geom.MultiPolygon;
import org.geolatte.geom.Point;
import org.geolatte.geom.Polygon;
import org.geolatte.geom.PositionSequenceBuilders;
import org.geolatte.geom.crs.CoordinateReferenceSystems;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.ebean.DB;
public class TestQuery {
private final Point<G2D> wgs84Point = new Point<>(
new G2D(174.76345825195312, -36.85315704345703),
CoordinateReferenceSystems.WGS84
);
private final Point<G2D> geolatteClosePoint = new Point<>(
new G2D(174.75345825195312, -36.85315704345703),
CoordinateReferenceSystems.WGS84
);
private final Polygon<G2D> enclosingPolygon = new Polygon<>(
PositionSequenceBuilders
.variableSized(G2D.class)
.add(new G2D(174.70345825195312, -36.85315704345703))
.add(new G2D(174.79345825195312, -36.80315704345703))
.add(new G2D(174.79345825195312, -36.89315704345703))
.add(new G2D(174.70345825195312, -36.85315704345703))
.toPositionSequence(),
CoordinateReferenceSystems.WGS84
);
private final LineString<G2D> lineString = new LineString<>(
PositionSequenceBuilders
.variableSized(G2D.class)
.add(new G2D(174.70345825195312, -36.85315704345703))
.add(wgs84Point.getPosition())
.add(new G2D(174.79345825195312, -36.89315704345703))
.toPositionSequence(),
CoordinateReferenceSystems.WGS84
);
@SuppressWarnings("unchecked")
private final MultiPoint<G2D> multiPoint = new MultiPoint<>(
new Point<>(new G2D(174.70345825195312, -36.85315704345703), CoordinateReferenceSystems.WGS84),
wgs84Point,
new Point<>(new G2D(174.79345825195312, -36.89315704345703), CoordinateReferenceSystems.WGS84)
);
@SuppressWarnings("unchecked")
private final MultiPolygon<G2D> multiPolygon = new MultiPolygon<>(
enclosingPolygon,
new Polygon<>(
PositionSequenceBuilders
.variableSized(G2D.class)
.add(new G2D(0, 51.47))
.add(new G2D(0.01, 51.49))
.add(new G2D(-0.01, 51.49))
.add(new G2D(0, 51.47))
.toPositionSequence(),
CoordinateReferenceSystems.WGS84
)
);
@SuppressWarnings("unchecked")
private final MultiLineString<G2D> multiLineString = new MultiLineString<>(
lineString,
new LineString<>(
PositionSequenceBuilders
.variableSized(G2D.class)
.add(new G2D(0, 51.47))
.add(new G2D(0.01, 51.49))
.add(new G2D(-0.01, 51.49))
.add(new G2D(-0.00, 51.47))
.toPositionSequence(),
CoordinateReferenceSystems.WGS84
)
);
@BeforeTest
public void setupObjects() {
OtherBeanGeoLatte geoLatte = new OtherBeanGeoLatte();
geoLatte.setWgs84Point(wgs84Point);
DB.save(geoLatte);
}
@AfterTest
public void cleanup() {
DB
.find(MyBean.class)
.delete();
DB.find(OtherBeanGeoLatte.class)
.delete();
}
@Test
public void testGeoQueryGeoLatte() {
// Approx 1100 meters away
// 0.009999999999990905 degrees away
// 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)
.findOne()
);
assertNull(
DB
.find(OtherBeanGeoLatte.class)
.where()
.raw("st_distance(wgs84Point, ?) < 0.009", toWkt(geolatteClosePoint))
// .raw("st_distance(wgs84Point, ?) < 0.009", geolatteClosePoint)
.findOne()
);
assertNotNull(
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("ST_Within(wgs84Point, ST_GeomFromText(?))", toWkt(enclosingPolygon))
// .raw("ST_Within(wgs84Point, ?)", enclosingPolygon)
.findOne()
);
assertNotNull(
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("wgs84Point = ST_PointN(ST_GeomFromText(?), 2)", toWkt(lineString))
// .raw("wgs84Point = ST_PointN(?, 2)", lineString)
.findOne()
);
assertNotNull(
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(ST_GeomFromText(?)), 2)", toWkt(multiPoint))
// .raw("wgs84Point = ST_PointN(ST_LineFromMultiPoint(?), 2)", multiPoint)
.findOne()
);
assertNotNull(
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("ST_Within(wgs84Point, ST_GeomFromText(?))", toWkt(multiPolygon))
// .raw("ST_Within(wgs84Point, ?)", multiPolygon)
.findOne()
);
assertNotNull(
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("ST_Intersects(wgs84Point, ST_GeomFromText(?))", toWkt(multiLineString))
// .raw("ST_Intersects(wgs84Point, ?)", multiLineString)
.findOne()
);
}
@Test
public void testGeoQueryPostgis() throws Exception {
assertNotNull(
DB
.find(MyBean.class)
.where()
.raw("st_distance(wgs84Point, ?) < 0.011", toWkt(geolatteClosePoint))
// .raw("st_distance(wgs84Point, ?) < 0.011", new org.postgis.Point(toWkt(geolatteClosePoint)))
.findOne()
);
assertNull(
DB
.find(MyBean.class)
.where()
.raw("st_distance(wgs84Point, ?) < 0.009", toWkt(geolatteClosePoint))
// .raw("st_distance(wgs84Point, ?) < 0.009", postgisClosePoint)
.findOne()
);
assertNotNull(
DB
.find(MyBean.class)
.where()
.raw("ST_Within(wgs84Point, ST_GeomFromText(?))", toWkt(enclosingPolygon))
// .raw("ST_Within(wgs84Point, ?)", new org.postgis.Polygon(toWkt(enclosingPolygon)))
.findOne()
);
assertNotNull(
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)))
.findOne()
);
assertNotNull(
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)))
.findOne()
);
assertNotNull(
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)))
.findOne()
);
assertNotNull(
DB
.find(MyBean.class)
.where()
.raw("ST_Within(wgs84Point, ST_GeomFromText(?))", toWkt(multiPolygon))
// .raw("ST_Within(wgs84Point, ?)", new org.postgis.Polygon(toWkt(multiPolygon)))
.findOne()
);
assertNotNull(
DB.find(OtherBeanGeoLatte.class)
.where()
.raw("ST_Intersects(wgs84Point, ST_GeomFromText(?))", toWkt(multiLineString))
// .raw("ST_Intersects(wgs84Point, ?)", new org.postgis.MultiLineString(toWkt(multiLineString)))
.findOne()
);
}
}
@@ -0,0 +1,17 @@
ebean:
dbSchema: mygisapp
geometrySRID: 4674
test:
# useDocker: false
# shutdown: stop # stop | remove
platform: postgis
ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate
dbName: mygisapp
# postgres:
# containerName: postgis10
# image: mdillon/postgis
# extensions: postgis
# url: jdbc:postgresql_lwgis://localhost:6432/mygisapp
# driver: org.postgis.DriverWrapperLW
@@ -0,0 +1,23 @@
<configuration scan="true" scanPeriod="3 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
<!-- Logging for SQL etc -->
<logger name="io.ebean.docker" level="TRACE"/>
<logger name="io.ebean.SQL" level="TRACE"/>
<logger name="io.ebean.TXN" level="TRACE"/>
<logger name="io.ebean.SUM" level="TRACE"/>
<logger name="io.ebean.DDL" level="TRACE"/>
</configuration>
@@ -0,0 +1,18 @@
## when running tests
ebean.ddl.generate=true
#ebean.ddl.run=true
#ebean.ddl.createOnly=true
ebean.geometrySRID=4674
datasource.default=db
datasource.db.username=pgis
datasource.db.password=pgis
datasource.db.databaseUrl=jdbc:postgresql_lwgis://127.0.0.1:5432/pgis
datasource.db.databaseDriver=org.postgis.DriverWrapperLW