mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +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,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
|
||||
Reference in new issue
Block a user