From e928e64134099adfa637662ae12644e8d4827d31 Mon Sep 17 00:00:00 2001 From: JORGE STALIN CALDERON BUSTAMANTE Date: Fri, 25 Oct 2024 15:19:03 -0500 Subject: [PATCH] Ajustar replica de datos CLOB para solventar error: java.sql.SQLException: ORA-22993: specified input amount is greater than actual source amount --- .gitignore | 1 + bin/configure-replicadb | 131 ------------------ bin/configure-replicadb.cmd | 90 ------------ bin/replicadb | 107 -------------- bin/replicadb.cmd | 36 ----- .../org/replicadb/manager/OracleManager.java | 29 +++- 6 files changed, 27 insertions(+), 367 deletions(-) delete mode 100755 bin/configure-replicadb delete mode 100755 bin/configure-replicadb.cmd delete mode 100755 bin/replicadb delete mode 100755 bin/replicadb.cmd diff --git a/.gitignore b/.gitignore index e831a94..aa45ebe 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ data/* create_db.log create_db_error.log .DS_Store +/target/ diff --git a/bin/configure-replicadb b/bin/configure-replicadb deleted file mode 100755 index b554f45..0000000 --- a/bin/configure-replicadb +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash -# -# Copyright 2011 The Apache Software Foundation -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# ----------------------------------------------------------------------------- -# This is sourced in by bin/replicadb to set environment variables prior to -# invoking ReplicaDB.jar. -# ----------------------------------------------------------------------------- - -bin="$1" - -if [[ -z "${bin}" ]]; then - bin=`dirname $0` - bin=`cd ${bin} && pwd` -fi - -if [[ -z "$REPLICADB_HOME" ]]; then - export REPLICADB_HOME=${bin}/.. -fi - -REPLICADB_CONF_DIR=${REPLICADB_CONF_DIR:-${REPLICADB_HOME}/conf} - -# Where to find the main ReplicaDB jar -REPLICADB_JAR_DIR=${REPLICADB_HOME} - -function add_to_classpath() { - dir=$1 - for f in ${dir}/*.jar; do - REPLICADB_CLASSPATH=${REPLICADB_CLASSPATH}:${f}; - done - - export REPLICADB_CLASSPATH -} - -# Add replicadb dependencies to classpath. -REPLICADB_CLASSPATH="" -if [[ -d "$REPLICADB_HOME/lib" ]]; then - add_to_classpath ${REPLICADB_HOME}/lib -fi - - -REPLICADB_CLASSPATH=${REPLICADB_CONF_DIR}:${REPLICADB_CLASSPATH} - -add_to_classpath ${REPLICADB_JAR_DIR} - -# ----------------------------------------------------------------------------- -# Set JAVA_HOME or JRE_HOME if not already set -# ----------------------------------------------------------------------------- - - -# Make sure prerequisite environment variables are set -if [[ -z "$JAVA_HOME" && -z "$JRE_HOME" ]]; then - if ${darwin}; then - # Bugzilla 54390 - if [[ -x '/usr/libexec/java_home' ]] ; then - JAVA_HOME=`/usr/libexec/java_home` - # Bugzilla 37284 (reviewed). - elif [[ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]]; then - JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" - fi - else - JAVA_PATH=`which java 2>/dev/null` - if [[ "x$JAVA_PATH" != "x" ]]; then - JAVA_PATH=`dirname ${JAVA_PATH} 2>/dev/null` - JRE_HOME=`dirname ${JAVA_PATH} 2>/dev/null` - fi - if [[ "x$JRE_HOME" = "x" ]]; then - # XXX: Should we try other locations? - if [[ -x /usr/bin/java ]]; then - JRE_HOME=/usr - fi - fi - fi - if [[ -z "$JAVA_HOME" && -z "$JRE_HOME" ]]; then - echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined" - echo "At least one of these environment variable is needed to run this program" - exit 1 - fi -fi - -if [[ -z "$JRE_HOME" ]]; then - JRE_HOME="$JAVA_HOME" -fi - -# Set standard commands for invoking Java, if not already set. -if [[ -z "$_RUNJAVA" ]]; then - _RUNJAVA="$JRE_HOME"/bin/java -fi - -# Set default initial memory allocation and maximum memory allocation -if [[ -z "$JAVA_OPTS" ]]; then - JAVA_OPTS="-Xmx256M -Xms256M" -fi - -if [[ -z "$JVM_PERFORMANCE_OPTS" ]]; then - JVM_PERFORMANCE_OPTS="-server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl" -fi - -# Uncomment this if you want to activate the monitoring via JMX -#JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" - - -export JAVA_HOME -export JAVA_PATH -export JRE_HOME -export _RUNJAVA - -export JAVA_OPTS -export JVM_PERFORMANCE_OPTS -export JMX_OPTS - -export REPLICADB_CLASSPATH -export REPLICADB_CONF_DIR -export REPLICADB_JAR_DIR - diff --git a/bin/configure-replicadb.cmd b/bin/configure-replicadb.cmd deleted file mode 100755 index 0c5916d..0000000 --- a/bin/configure-replicadb.cmd +++ /dev/null @@ -1,90 +0,0 @@ -:: Licensed to the Apache Software Foundation (ASF) under one or more -:: contributor license agreements. See the NOTICE file distributed with -:: this work for additional information regarding copyright ownership. -:: The ASF licenses this file to You under the Apache License, Version 2.0 -:: (the "License"); you may not use this file except in compliance with -:: the License. You may obtain a copy of the License at -:: -:: -:: http://www.apache.org/licenses/LICENSE-2.0 -:: -:: Unless required by applicable law or agreed to in writing, software -:: distributed under the License is distributed on an "AS IS" BASIS, -:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -:: See the License for the specific language governing permissions and -:: limitations under the License. - -if not exist %bin% ( - echo Error: Environment variable bin not defined. - echo This is generally because this script should not be invoked directly. Use replicadb instead. - exit /b 1 -) - -if not defined REPLICADB_HOME ( - set REPLICADB_HOME=%bin%\.. -) - -if not defined REPLICADB_CONF_DIR ( - set REPLICADB_CONF_DIR=%REPLICADB_HOME%\conf -) - -:: Add replicadb dependencies to classpath -set REPLICADB_CLASSPATH= - -:: Where to find the main ReplicaDB jar -set REPLICADB_JAR_DIR=%REPLICADB_HOME% -call :add_dir_to_classpath %REPLICADB_JAR_DIR% - -if exist "%REPLICADB_HOME%\lib" ( - call :add_dir_to_classpath %REPLICADB_HOME%\lib -) - -call :add_dir_to_classpath %REPLICADB_CONF_DIR% - -:: ----------------------------------------------------------------------------- -:: Set JAVA_HOME or JRE_HOME if not already set -:: ----------------------------------------------------------------------------- - -:: Make sure prerequisite environment variables are set -if not "%JRE_HOME%" == "" goto gotJreHome -if not "%JAVA_HOME%" == "" goto gotJavaHome -echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined -echo At least one of these environment variable is needed to run this program -goto exit - -:gotJavaHome -:: No JRE given, use JAVA_HOME as JRE_HOME -set "JRE_HOME=%JAVA_HOME%" - -:gotJreHome -:: Check if we have a usable JRE -if not exist "%JRE_HOME%\bin\java.exe" goto noJreHome -goto okJava - -:noJreHome -rem Needed at least a JRE -echo The JRE_HOME environment variable is not defined correctly -echo This environment variable is needed to run this program -goto exit - -:okJava -:: Don't override _RUNJAVA if the user has set it previously -if not "%_RUNJAVA%" == "" goto gotRunJava -:: Set standard command for invoking Java. -:: Also note the quoting as JRE_HOME may contain spaces. -set _RUNJAVA="%JRE_HOME%\bin\java.exe" -:gotRunJava - -goto :eof - - -:: ----------------------------------------------------------------------------- -:: Function to add the given directory to the list of classpath directories -:: All jars under the given directory are added to the classpath -:: ----------------------------------------------------------------------------- -:add_dir_to_classpath -if not "%1"=="" ( - set REPLICADB_CLASSPATH=!REPLICADB_CLASSPATH!;%1\* -) -goto :eof - diff --git a/bin/replicadb b/bin/replicadb deleted file mode 100755 index 117a91e..0000000 --- a/bin/replicadb +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash -# -# Copyright 2011 The Apache Software Foundation -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -follow_one() { - # Resolve symlinks and relative path components along a path. This requires - # its argument to be an absolute path. This does not recursively re-resolve - # symlinks; if that is required, use the 'follow' method. - - target=$1 - OIFS=$IFS - IFS='/' - - # Taking each dir component along the way, build up a new target directory, - # resolving '.', '..', and symlinks. - newtarget='' - for part in ${target}; do - if [[ -z "${part}" ]]; then - continue # Empty dir part. 'foo//bar' - elif [[ "." == "${part}" ]]; then - continue # Nothing special to do for '.' - elif [[ ".." == "${part}" ]]; then - IFS=$OIFS - newtarget=`dirname ${newtarget}` # pop a component. - elif [[ -h "${newtarget}/${part}" ]]; then - IFS=$OIFS - link=`readlink ${newtarget}/${part}` - # links can be relative or absolute. Relative ones get appended to - # newtarget; absolute ones replace it. - if [[ "${link:0:1}" != "/" ]]; then - newtarget="${newtarget}/${link}" # relative - else - newtarget="${link}" # absolute - fi - else # Regular file component. - newtarget="${newtarget}/${part}" - fi - IFS='/' - done - - IFS=$OIFS - echo $newtarget -} - -follow() { - # Portable 'readlink -f' function to follow a file's links to the final - # target. Calls follow_one recursively til we're finished tracing symlinks. - - target=$1 - depth=$2 - - if [[ -z "$depth" ]]; then - depth=0 - elif [[ "$depth" == "1000" ]]; then - # Don't recurse indefinitely; we've probably hit a symlink cycle. - # Just bail out here. - echo ${target} - return 1 - fi - - # Canonicalize the target to be an absolute path. - targetdir=`dirname ${target}` - targetdir=`cd ${targetdir} && pwd` - target=${targetdir}/`basename ${target}` - - # Use follow_one to resolve links. Test that we get the same result twice, - # to terminate iteration. - first=`follow_one ${target}` - second=`follow_one ${first}` - if [[ "${first}" == "${second}" ]]; then - # We're done. - echo "${second}" - else - # Need to continue resolving links. - echo `follow ${second} $(( $depth + 1 ))` - fi -} - -prgm=`follow $0` -bin=`dirname ${prgm}` -bin=`cd ${bin} && pwd` - -source ${bin}/configure-replicadb "${bin}" - -if [ "${REPLICADB_CONFIGURATION}" ]; then - echo "${REPLICADB_CONFIGURATION}" > ${REPLICADB_CONF_DIR}/replicadb.conf -fi - -exec ${_RUNJAVA} ${JAVA_OPTS} ${JVM_PERFORMANCE_OPTS} ${JMX_OPTS} -cp ${REPLICADB_CLASSPATH} org.replicadb.ReplicaDB "$@" - diff --git a/bin/replicadb.cmd b/bin/replicadb.cmd deleted file mode 100755 index a4549b7..0000000 --- a/bin/replicadb.cmd +++ /dev/null @@ -1,36 +0,0 @@ -@echo off -:: Licensed to the Apache Software Foundation (ASF) under one or more -:: contributor license agreements. See the NOTICE file distributed with -:: this work for additional information regarding copyright ownership. -:: The ASF licenses this file to You under the Apache License, Version 2.0 -:: (the "License"); you may not use this file except in compliance with -:: the License. You may obtain a copy of the License at -:: -:: -:: http://www.apache.org/licenses/LICENSE-2.0 -:: -:: Unless required by applicable law or agreed to in writing, software -:: distributed under the License is distributed on an "AS IS" BASIS, -:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -:: See the License for the specific language governing permissions and -:: limitations under the License. - -setlocal enabledelayedexpansion - -set prgm=%~f0 -set bin=%~dp0 -if "%bin:~-1%" == "\" ( - set bin=%bin:~0,-1% -) - -call "%bin%\configure-replicadb.cmd" "%bin%" - -:: echo _RUNJAVA "%_RUNJAVA%" -:: echo REPLICADB_CLASSPATH "%REPLICADB_CLASSPATH%" - -call %_RUNJAVA% -cp %REPLICADB_CLASSPATH% -Xmx256M -Xms256M -Dfile.encoding=UTF-8 -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl org.replicadb.ReplicaDB %* - -:: create exit code from java process -set /a exitCode=%errorlevel% -endlocal -exit /b %exitCode% \ No newline at end of file diff --git a/src/main/java/org/replicadb/manager/OracleManager.java b/src/main/java/org/replicadb/manager/OracleManager.java index 0979956..55914b8 100644 --- a/src/main/java/org/replicadb/manager/OracleManager.java +++ b/src/main/java/org/replicadb/manager/OracleManager.java @@ -176,16 +176,39 @@ public int insertDataToTable(ResultSet resultSet, int taskId) throws SQLExceptio if (blobData != null) blobData.free(); break; case Types.CLOB: + Clob clobData = resultSet.getClob(i); + if (clobData != null) { + // Obtiene la longitud del CLOB + long clobLength = clobData.length(); + + // Asegúrate de que el tamaño no sea cero antes de intentar establecer el stream + if (clobLength > 0) { + // Establece el CharacterStream con la longitud exacta + ps.setCharacterStream(i, clobData.getCharacterStream(), (int) clobLength); + } else { + // Si el CLOB está vacío, establece el campo como NULL + ps.setNull(i, Types.CLOB); + } + + // Libera el objeto CLOB después de usarlo + clobData.free(); + } else { + // Si el dato es null en el campo CLOB, se setea directamente como NULL + ps.setNull(i, Types.CLOB); + } + break; + + /*case Types.CLOB: Clob clobData = resultSet.getClob(i); if (clobData != null) { //Se establece los datos del campo CLOB como un objeto java.io.Reader - ps.setClob(i, clobData.getCharacterStream()); + ps.setCharacterStream(i, clobData.getCharacterStream()); clobData.free(); } else//si el dato es null en el campo CLOB, se setea directamente el clobData - ps.setClob(i, clobData); - break; + ps.setClob(i, clobData); + break;*/ case Types.BOOLEAN: ps.setBoolean(i, resultSet.getBoolean(i)); break;