From d3c694a14810a2f4a20b6b81cdf78284abe4aa54 Mon Sep 17 00:00:00 2001 From: wgzhao Date: Tue, 13 Aug 2024 13:18:14 +0800 Subject: [PATCH] [bugfix][plugin][oraclewriter] Fix ora-03106 while updating clob column, fix #1030 When the "merge into" statement is executed, if the updated field is of CLOB type and the length of the updated content is too long, the ORA-03106 error will be given. --- .../addax/rdbms/writer/CommonRdbmsWriter.java | 10 --------- .../writer/oraclewriter/OracleWriter.java | 21 ++++++++++++++++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/addax-rdbms/src/main/java/com/wgzhao/addax/rdbms/writer/CommonRdbmsWriter.java b/lib/addax-rdbms/src/main/java/com/wgzhao/addax/rdbms/writer/CommonRdbmsWriter.java index 75da4402f..81c8a0d11 100644 --- a/lib/addax-rdbms/src/main/java/com/wgzhao/addax/rdbms/writer/CommonRdbmsWriter.java +++ b/lib/addax-rdbms/src/main/java/com/wgzhao/addax/rdbms/writer/CommonRdbmsWriter.java @@ -470,16 +470,6 @@ protected PreparedStatement fillPreparedStatementColumnType(PreparedStatement pr java.util.Date utilDate; switch (columnSqlType) { case Types.CLOB: - if (dataBaseType.equals(DataBaseType.Oracle) && column.asString().length() >= 4000) { - Clob clob = preparedStatement.getConnection().createClob(); - clob.setString(1, column.asString()); - preparedStatement.setClob(columnIndex, clob); - } - else { - preparedStatement.setString(columnIndex, column.asString()); - } - break; - case Types.CHAR: case Types.NCHAR: case Types.NCLOB: diff --git a/plugin/writer/oraclewriter/src/main/java/com/wgzhao/addax/plugin/writer/oraclewriter/OracleWriter.java b/plugin/writer/oraclewriter/src/main/java/com/wgzhao/addax/plugin/writer/oraclewriter/OracleWriter.java index 1e7f5b2b4..d69828d17 100644 --- a/plugin/writer/oraclewriter/src/main/java/com/wgzhao/addax/plugin/writer/oraclewriter/OracleWriter.java +++ b/plugin/writer/oraclewriter/src/main/java/com/wgzhao/addax/plugin/writer/oraclewriter/OracleWriter.java @@ -20,6 +20,7 @@ package com.wgzhao.addax.plugin.writer.oraclewriter; import com.wgzhao.addax.common.base.Key; +import com.wgzhao.addax.common.element.Column; import com.wgzhao.addax.common.exception.AddaxException; import com.wgzhao.addax.common.plugin.RecordReceiver; import com.wgzhao.addax.common.spi.Writer; @@ -28,6 +29,10 @@ import com.wgzhao.addax.rdbms.util.DataBaseType; import com.wgzhao.addax.rdbms.writer.CommonRdbmsWriter; +import java.sql.Clob; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Types; import java.util.List; public class OracleWriter @@ -100,7 +105,21 @@ public static class Task public void init() { this.writerSliceConfig = getPluginJobConf(); - this.commonRdbmsWriterTask = new CommonRdbmsWriter.Task(DATABASE_TYPE); + this.commonRdbmsWriterTask = new CommonRdbmsWriter.Task(DATABASE_TYPE) { + @Override + protected PreparedStatement fillPreparedStatementColumnType(PreparedStatement preparedStatement, int columnIndex, int columnSqlType, Column column) + throws SQLException + { + if (writerSliceConfig.getString(Key.WRITE_MODE, "").startsWith("update") && columnSqlType == Types.CLOB ) { + Clob clob = preparedStatement.getConnection().createClob(); + clob.setString(1, column.asString()); + preparedStatement.setClob(columnIndex, clob); + return preparedStatement; + } + + return super.fillPreparedStatementColumnType(preparedStatement, columnIndex, columnSqlType, column); + } + }; commonRdbmsWriterTask.init(writerSliceConfig); }