|
@@ -3,9 +3,16 @@
|
|
|
*/
|
|
|
package org.dbsyncer.connector.oracle.schema.support;
|
|
|
|
|
|
+import oracle.sql.CLOB;
|
|
|
+import org.dbsyncer.connector.oracle.OracleException;
|
|
|
import org.dbsyncer.sdk.model.Field;
|
|
|
import org.dbsyncer.sdk.schema.support.StringType;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.Reader;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.sql.SQLException;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -46,7 +53,27 @@ public final class OracleStringType extends StringType {
|
|
|
|
|
|
@Override
|
|
|
protected String merge(Object val, Field field) {
|
|
|
+ if (val instanceof byte[]) {
|
|
|
+ return new String((byte[]) val, StandardCharsets.UTF_8);
|
|
|
+ }
|
|
|
+ if (val instanceof CLOB) {
|
|
|
+ return clobToString((CLOB) val);
|
|
|
+ }
|
|
|
return throwUnsupportedException(val, field);
|
|
|
}
|
|
|
|
|
|
+ public String clobToString(CLOB clob) {
|
|
|
+ try (Reader is = clob.getCharacterStream(); BufferedReader br = new BufferedReader(is)) {
|
|
|
+ String s = br.readLine();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ while (s != null) {
|
|
|
+ sb.append(s);
|
|
|
+ s = br.readLine();
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ } catch (SQLException | IOException e) {
|
|
|
+ throw new OracleException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|