|
@@ -1,14 +1,12 @@
|
|
|
package org.dbsyncer.connector.schema;
|
|
|
|
|
|
-import com.microsoft.sqlserver.jdbc.Geometry;
|
|
|
-import oracle.jdbc.OracleConnection;
|
|
|
-import oracle.spatial.geometry.JGeometry;
|
|
|
import org.dbsyncer.common.spi.ConnectorMapper;
|
|
|
import org.dbsyncer.connector.AbstractValueMapper;
|
|
|
import org.dbsyncer.connector.ConnectorException;
|
|
|
-import org.dbsyncer.connector.database.ds.SimpleConnection;
|
|
|
+import org.postgis.Geometry;
|
|
|
+import org.postgis.binary.BinaryParser;
|
|
|
+import org.postgis.binary.BinaryWriter;
|
|
|
|
|
|
-import java.sql.Connection;
|
|
|
import java.sql.Struct;
|
|
|
|
|
|
/**
|
|
@@ -16,7 +14,7 @@ import java.sql.Struct;
|
|
|
* @version 1.0.0
|
|
|
* @date 2022/9/16 16:54
|
|
|
*/
|
|
|
-public class OtherValueMapper extends AbstractValueMapper<Struct> {
|
|
|
+public class OtherValueMapper extends AbstractValueMapper<Object> {
|
|
|
|
|
|
@Override
|
|
|
protected boolean skipConvert(Object val) {
|
|
@@ -24,22 +22,37 @@ public class OtherValueMapper extends AbstractValueMapper<Struct> {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected Struct convert(ConnectorMapper connectorMapper, Object val) throws Exception {
|
|
|
- // SqlServer Geometry
|
|
|
- if (val instanceof byte[]) {
|
|
|
- Object connection = connectorMapper.getConnection();
|
|
|
- if (connection instanceof Connection) {
|
|
|
- SimpleConnection simpleConnection = (SimpleConnection) connection;
|
|
|
- if (simpleConnection instanceof OracleConnection) {
|
|
|
- OracleConnection conn = simpleConnection.unwrap(OracleConnection.class);
|
|
|
- Geometry geometry = Geometry.deserialize((byte[]) val);
|
|
|
- Double x = geometry.getX();
|
|
|
- Double y = geometry.getY();
|
|
|
- JGeometry jGeometry = new JGeometry(x, y, 0);
|
|
|
- return JGeometry.store(jGeometry, conn);
|
|
|
- }
|
|
|
+ protected Object convert(ConnectorMapper connectorMapper, Object val) throws Exception {
|
|
|
+
|
|
|
+ if (val instanceof oracle.sql.STRUCT) {
|
|
|
+ return (Struct) val;
|
|
|
+ }
|
|
|
+
|
|
|
+ //PostGIS Geometry的情况
|
|
|
+ if (val instanceof String)
|
|
|
+ {
|
|
|
+ //测试下Geometry能不能用起来
|
|
|
+ try
|
|
|
+ {
|
|
|
+ BinaryParser parser= new BinaryParser();
|
|
|
+ org.postgis.Geometry geo = parser.parse((String) val);
|
|
|
+ BinaryWriter bw = new BinaryWriter();
|
|
|
+ return bw.writeBinary(geo);
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ System.out.println(val);
|
|
|
+ return val;
|
|
|
}
|
|
|
}
|
|
|
+ if (val instanceof Geometry)
|
|
|
+ {
|
|
|
+ return val;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // SqlServer Geometry
|
|
|
+
|
|
|
throw new ConnectorException(String.format("%s can not find type [%s], val [%s]", getClass().getSimpleName(), val.getClass(), val));
|
|
|
}
|
|
|
+
|
|
|
}
|