|
@@ -1,13 +1,14 @@
|
|
package org.dbsyncer.connector.schema;
|
|
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.common.spi.ConnectorMapper;
|
|
import org.dbsyncer.connector.AbstractValueMapper;
|
|
import org.dbsyncer.connector.AbstractValueMapper;
|
|
import org.dbsyncer.connector.ConnectorException;
|
|
import org.dbsyncer.connector.ConnectorException;
|
|
-import org.postgis.Geometry;
|
|
|
|
-import org.postgis.PGgeometry;
|
|
|
|
-import org.postgis.binary.BinaryParser;
|
|
|
|
-import org.postgis.binary.BinaryWriter;
|
|
|
|
|
|
+import org.dbsyncer.connector.database.ds.SimpleConnection;
|
|
|
|
|
|
|
|
+import java.sql.Connection;
|
|
import java.sql.Struct;
|
|
import java.sql.Struct;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -15,48 +16,30 @@ import java.sql.Struct;
|
|
* @version 1.0.0
|
|
* @version 1.0.0
|
|
* @date 2022/9/16 16:54
|
|
* @date 2022/9/16 16:54
|
|
*/
|
|
*/
|
|
-public class OtherValueMapper extends AbstractValueMapper<Object> {
|
|
|
|
|
|
+public class OtherValueMapper extends AbstractValueMapper<Struct> {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected boolean skipConvert(Object val) {
|
|
protected boolean skipConvert(Object val) {
|
|
- return val instanceof oracle.sql.STRUCT;
|
|
|
|
|
|
+ return val instanceof oracle.sql.STRUCT || val instanceof String;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- 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;
|
|
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (val instanceof Geometry)
|
|
|
|
- {
|
|
|
|
- return val;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (val instanceof PGgeometry)
|
|
|
|
- return val;
|
|
|
|
-
|
|
|
|
- // SqlServer Geometry
|
|
|
|
-
|
|
|
|
throw new ConnectorException(String.format("%s can not find type [%s], val [%s]", getClass().getSimpleName(), val.getClass(), val));
|
|
throw new ConnectorException(String.format("%s can not find type [%s], val [%s]", getClass().getSimpleName(), val.getClass(), val));
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|