mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
Move into ebean-postgres sub directory
This commit is contained in:
1 parent
f383f3f759
commit
9fa83cdd5a
29 files changed
No files matched your search
@@ -0,0 +1,17 @@
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
spaces_around_operators = true
|
||||
max_line_length = 130
|
||||
|
||||
[pom.xml]
|
||||
# Because of <project... line
|
||||
max_line_length = 999
|
||||
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,2 @@
|
||||
# ebean-com.avaje.ebean.postgis
|
||||
Ebean support for Postgres Geometry types - org.com.avaje.ebean.postgis and org.geolatte.geom
|
||||
@@ -0,0 +1,107 @@
|
||||
<?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>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<postgis.jdbc.version>2.2.1</postgis.jdbc.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 -->
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean</artifactId>
|
||||
<version>12.4.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.postgis</groupId>
|
||||
<artifactId>postgis-jdbc</artifactId>
|
||||
<version>[${postgis.jdbc.version}]</version>
|
||||
</dependency>
|
||||
|
||||
<!-- expected to be provided -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- expected to be provided -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- optionally use geolatte-geom -->
|
||||
<dependency>
|
||||
<groupId>org.geolatte</groupId>
|
||||
<artifactId>geolatte-geom</artifactId>
|
||||
<version>1.0.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-test</artifactId>
|
||||
<version>12.4.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.avaje.composite</groupId>
|
||||
<artifactId>logback</artifactId>
|
||||
<version>1.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.avaje.composite</groupId>
|
||||
<artifactId>composite-testing</artifactId>
|
||||
<version>3.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<!-- for testing -->
|
||||
<plugin>
|
||||
<groupId>io.repaint.maven</groupId>
|
||||
<artifactId>tiles-maven-plugin</artifactId>
|
||||
<version>2.17</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
<tile>io.ebean.tile:enhancement:12.4.1</tile>
|
||||
</tiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.ebean.postgis;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.postgis.latte.ScalarTypeGeoLatteLineString;
|
||||
import io.ebean.postgis.latte.ScalarTypeGeoLatteMultiLineString;
|
||||
import io.ebean.postgis.latte.ScalarTypeGeoLatteMultiPoint;
|
||||
import io.ebean.postgis.latte.ScalarTypeGeoLatteMultiPolygon;
|
||||
import io.ebean.postgis.latte.ScalarTypeGeoLattePoint;
|
||||
import io.ebean.postgis.latte.ScalarTypeGeoLattePolygon;
|
||||
import io.ebeaninternal.api.ExtraTypeFactory;
|
||||
import io.ebeaninternal.server.type.ScalarType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RegisterFactory implements ExtraTypeFactory {
|
||||
|
||||
@Override
|
||||
public List<ScalarType<?>> createTypes(DatabaseConfig config, Object objectMapper) {
|
||||
|
||||
List<ScalarType<?>> list = new ArrayList<ScalarType<?>>();
|
||||
list.add(new ScalarTypePgisPoint());
|
||||
list.add(new ScalarTypePgisPolygon());
|
||||
list.add(new ScalarTypePgisLineString());
|
||||
list.add(new ScalarTypePgisMultiPolygon());
|
||||
list.add(new ScalarTypePgisMultiPoint());
|
||||
list.add(new ScalarTypePgisMultiLineString());
|
||||
|
||||
if (config.getClassLoadConfig().isPresent("org.geolatte.geom.Geometry")) {
|
||||
list.add(new ScalarTypeGeoLattePoint());
|
||||
list.add(new ScalarTypeGeoLattePolygon());
|
||||
list.add(new ScalarTypeGeoLatteLineString());
|
||||
list.add(new ScalarTypeGeoLatteMultiPolygon());
|
||||
list.add(new ScalarTypeGeoLatteMultiPoint());
|
||||
list.add(new ScalarTypeGeoLatteMultiLineString());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package io.ebean.postgis;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
abstract class ScalarTypePgisBase<T extends Geometry> implements ScalarType<T> {
|
||||
|
||||
private final int jdbcType;
|
||||
|
||||
private final Class<T> cls;
|
||||
|
||||
ScalarTypePgisBase(int jdbcType, Class<T> cls) {
|
||||
this.jdbcType = jdbcType;
|
||||
this.cls = cls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind bind, T value) throws SQLException {
|
||||
if (value == null) {
|
||||
bind.setNull(Types.NULL);
|
||||
} else {
|
||||
bind.setObject(new PGgeometryLW(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T read(DataReader reader) throws SQLException {
|
||||
|
||||
Object object = reader.getObject();
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
if (object instanceof PGgeometryLW) {
|
||||
return (T) ((PGgeometryLW) object).getGeometry();
|
||||
|
||||
} else if (object instanceof PGgeometry) {
|
||||
return (T) ((PGgeometry) object).getGeometry();
|
||||
|
||||
} else if (object instanceof PGobject) {
|
||||
return (T) PGgeometry.geomFromString(((PGobject) object).getValue());
|
||||
|
||||
} else {
|
||||
throw new IllegalStateException("Could not convert from " + object.getClass() + " to " + cls);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isJdbcNative() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getJdbcType() {
|
||||
return jdbcType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> getType() {
|
||||
return cls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T readData(DataInput dataInput) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, T v) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBinaryType() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMutable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty(Object value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIgnore(DataReader reader) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T toBeanType(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(T value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T parse(String value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocPropertyType getDocType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asVersion(T value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T convertFromMillis(long dateTime) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public T jsonRead(JsonParser parser) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator writer, T value) throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.ebean.postgis;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.postgis.LineString;
|
||||
|
||||
public class ScalarTypePgisLineString extends ScalarTypePgisBase<LineString> {
|
||||
|
||||
public ScalarTypePgisLineString() {
|
||||
super(ExtraDbTypes.LINESTRING, LineString.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.ebean.postgis;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.postgis.MultiLineString;
|
||||
|
||||
public class ScalarTypePgisMultiLineString extends ScalarTypePgisBase<MultiLineString> {
|
||||
|
||||
public ScalarTypePgisMultiLineString() {
|
||||
super(ExtraDbTypes.MULTILINESTRING, MultiLineString.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.ebean.postgis;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.postgis.MultiPoint;
|
||||
|
||||
public class ScalarTypePgisMultiPoint extends ScalarTypePgisBase<MultiPoint> {
|
||||
|
||||
public ScalarTypePgisMultiPoint() {
|
||||
super(ExtraDbTypes.MULTIPOINT, MultiPoint.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.ebean.postgis;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.postgis.MultiPolygon;
|
||||
|
||||
public class ScalarTypePgisMultiPolygon extends ScalarTypePgisBase<MultiPolygon> {
|
||||
|
||||
public ScalarTypePgisMultiPolygon() {
|
||||
super(ExtraDbTypes.MULTIPOLYGON, MultiPolygon.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.ebean.postgis;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.postgis.Point;
|
||||
|
||||
public class ScalarTypePgisPoint extends ScalarTypePgisBase<Point> {
|
||||
|
||||
public ScalarTypePgisPoint() {
|
||||
super(ExtraDbTypes.POINT, Point.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.ebean.postgis;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.postgis.Polygon;
|
||||
|
||||
public class ScalarTypePgisPolygon extends ScalarTypePgisBase<Polygon> {
|
||||
|
||||
public ScalarTypePgisPolygon() {
|
||||
super(ExtraDbTypes.POLYGON, Polygon.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package io.ebean.postgis.latte;
|
||||
|
||||
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;
|
||||
import org.postgis.PGgeometryLW;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
abstract class ScalarTypeGeoLatteBase<T extends Geometry> implements ScalarType<T> {
|
||||
|
||||
private final int jdbcType;
|
||||
|
||||
private final Class<T> cls;
|
||||
|
||||
ScalarTypeGeoLatteBase(int jdbcType, Class<T> cls) {
|
||||
this.jdbcType = jdbcType;
|
||||
this.cls = cls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJdbcNative() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getJdbcType() {
|
||||
return jdbcType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> getType() {
|
||||
return cls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind bind, T value) throws SQLException {
|
||||
|
||||
if (value == null) {
|
||||
bind.setNull(Types.OTHER);
|
||||
} else {
|
||||
String wkt = Wkt.newEncoder(Wkt.Dialect.POSTGIS_EWKT_1).encode(value);
|
||||
bind.setObject(new PGgeometryLW(wkt));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T read(DataReader reader) throws SQLException {
|
||||
|
||||
Object object = reader.getObject();
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
if (object instanceof PGgeometry) {
|
||||
org.postgis.Geometry geometry = ((PGgeometry) object).getGeometry();
|
||||
return (T) Wkt.newDecoder(Wkt.Dialect.POSTGIS_EWKT_1).decode(geometry.toString());
|
||||
}
|
||||
throw new IllegalStateException("Received object of type " + object.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T readData(DataInput dataInput) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, T v) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBinaryType() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMutable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty(Object value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIgnore(DataReader reader) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T toBeanType(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(T value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T parse(String value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocPropertyType getDocType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asVersion(T value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T convertFromMillis(long dateTime) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T jsonRead(JsonParser parser) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator writer, T value) throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.ebean.postgis.latte;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.geolatte.geom.LineString;
|
||||
|
||||
public class ScalarTypeGeoLatteLineString extends ScalarTypeGeoLatteBase<LineString> {
|
||||
|
||||
public ScalarTypeGeoLatteLineString() {
|
||||
super(ExtraDbTypes.LINESTRING, LineString.class);
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package io.ebean.postgis.latte;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.geolatte.geom.MultiLineString;
|
||||
|
||||
public class ScalarTypeGeoLatteMultiLineString extends ScalarTypeGeoLatteBase<MultiLineString> {
|
||||
|
||||
public ScalarTypeGeoLatteMultiLineString() {
|
||||
super(ExtraDbTypes.MULTILINESTRING, MultiLineString.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.ebean.postgis.latte;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.geolatte.geom.MultiPoint;
|
||||
|
||||
public class ScalarTypeGeoLatteMultiPoint extends ScalarTypeGeoLatteBase<MultiPoint> {
|
||||
|
||||
public ScalarTypeGeoLatteMultiPoint() {
|
||||
super(ExtraDbTypes.MULTIPOINT, MultiPoint.class);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package io.ebean.postgis.latte;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.geolatte.geom.MultiPolygon;
|
||||
|
||||
public class ScalarTypeGeoLatteMultiPolygon extends ScalarTypeGeoLatteBase<MultiPolygon> {
|
||||
|
||||
public ScalarTypeGeoLatteMultiPolygon() {
|
||||
super(ExtraDbTypes.MULTIPOLYGON, MultiPolygon.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.ebean.postgis.latte;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.geolatte.geom.Point;
|
||||
|
||||
public class ScalarTypeGeoLattePoint extends ScalarTypeGeoLatteBase<Point> {
|
||||
|
||||
public ScalarTypeGeoLattePoint() {
|
||||
super(ExtraDbTypes.POINT, Point.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.ebean.postgis.latte;
|
||||
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import org.geolatte.geom.Polygon;
|
||||
|
||||
public class ScalarTypeGeoLattePolygon extends ScalarTypeGeoLatteBase<Polygon> {
|
||||
|
||||
public ScalarTypeGeoLattePolygon() {
|
||||
super(ExtraDbTypes.POLYGON, Polygon.class);
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
io.ebean.postgis.RegisterFactory
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user