提交 016a7e99 编写于 作者: S serge-rider

Geometry value bind/copy

上级 14ed345a
......@@ -94,7 +94,11 @@ public class GISGeometryValueHandler extends JDBCAbstractValueHandler {
if (object == null) {
geometry = new DBGeometry();
} else if (object instanceof DBGeometry) {
geometry = (DBGeometry) object;
if (copy) {
geometry = ((DBGeometry) object).copy();
} else {
geometry = (DBGeometry) object;
}
} else if (object instanceof Geometry) {
geometry = new DBGeometry((Geometry)object);
} else if (object instanceof byte[]) {
......
......@@ -25,6 +25,7 @@ import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import java.util.LinkedHashMap;
import java.util.Map;
/**
......@@ -44,6 +45,12 @@ public class DBGeometry implements DBDValue {
this.rawValue = rawValue;
}
public DBGeometry(DBGeometry source) {
this.rawValue = source.rawValue;
this.srid = source.srid;
this.properties = source.properties == null ? null : new LinkedHashMap<>(source.properties);
}
public DBGeometry(Geometry rawValue) {
this.rawValue = rawValue;
this.srid = rawValue == null ? 0 : rawValue.getSRID();
......@@ -118,4 +125,7 @@ public class DBGeometry implements DBDValue {
this.properties = properties;
}
public DBGeometry copy() {
return new DBGeometry(this);
}
}
......@@ -16,6 +16,7 @@
*/
package org.jkiss.dbeaver.ext.postgresql.model.data;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.data.gis.handlers.WKGUtils;
import org.jkiss.dbeaver.ext.postgresql.PostgreConstants;
import org.jkiss.dbeaver.ext.postgresql.PostgreUtils;
......@@ -25,6 +26,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.gis.DBGeometry;
import org.jkiss.dbeaver.model.gis.GisAttribute;
import org.jkiss.dbeaver.model.impl.jdbc.data.handlers.JDBCAbstractValueHandler;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.utils.CommonUtils;
......@@ -60,29 +62,48 @@ public class PostgreGeometryValueHandler extends JDBCAbstractValueHandler {
@Override
protected void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType, int paramIndex, Object value) throws DBCException, SQLException {
int valueSRID = 0;
if (value instanceof DBGeometry) {
valueSRID = ((DBGeometry) value).getSRID();
value = ((DBGeometry) value).getRawValue();
}
if (valueSRID == 0 && paramType instanceof GisAttribute) {
valueSRID = ((GisAttribute) paramType).getAttributeGeometrySRID(session.getProgressMonitor());
}
if (value == null) {
statement.setNull(paramIndex, paramType.getTypeID());
} else if (value instanceof Geometry) {
if (((Geometry) value).getSRID() == 0) {
((Geometry) value).setSRID(valueSRID);
}
statement.setObject(paramIndex, getStringFromGeometry(session, (Geometry)value), Types.OTHER);
} else if (value.getClass().getName().equals(PostgreConstants.PG_GEOMETRY_CLASS)) {
statement.setObject(paramIndex, value, Types.OTHER);
} else {
statement.setObject(paramIndex, value.toString(), Types.OTHER);
String strValue = value.toString();
if (valueSRID != 0 && !strValue.startsWith("SRID=")) {
strValue = "SRID=" + valueSRID + ";" + strValue;
}
statement.setObject(paramIndex, strValue, Types.OTHER);
}
}
@NotNull
@Override
public Class<?> getValueObjectType(DBSTypedObject attribute) {
public Class<?> getValueObjectType(@NotNull DBSTypedObject attribute) {
return DBGeometry.class;
}
@Override
public Object getValueFromObject(DBCSession session, DBSTypedObject type, Object object, boolean copy) throws DBCException {
public Object getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException {
if (object == null) {
return new DBGeometry();
} else if (object instanceof DBGeometry) {
if (copy) {
return ((DBGeometry) object).copy();
} else {
return object;
}
} else if (object instanceof Geometry) {
return new DBGeometry((Geometry) object);
} else if (object instanceof String) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册