Loader.java :  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » loader » Java Open Source

Java Open Source » Database JDBC Connection Pool » octopus 
octopus » org » webdocwf » util » loader » Loader.java
/*
 Loader - tool for transfering data from one JDBC source to another and
 doing transformations during copy.
 Copyright (C) 2002-2003  Together
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 Loader.java
 Date: 03.03.2003.
 @version 2.1 alpha
 @authors:
 Milosevic Sinisa sinisa@prozone.yu
 Radoslav Dutina  rale@prozone.co.yu
 */

package org.webdocwf.util.loader;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.webdocwf.util.loader.logging.Logger;
import org.webdocwf.util.loader.logging.StandardLogger;
import org.webdocwf.util.loader.transformation.QueryTransformationSet;
import org.webdocwf.util.loader.transformation.Transformation;
import org.webdocwf.util.loader.transformation.Transformations;
import org.xml.sax.SAXException;

/**
 * <p>
 * Loader class loads data from source database into target database using
 * criteria set in XML file which is used as parameter. Also Loader can execute
 * SQL statements which import from XML file. <br>
 * All loading rolls are set in XML file. Some capabilities of this loader are:
 * there could be more then one importDefinition and number of them is not
 * limited, source and target database could be different, source database could
 * be ASCII,Excel or Access file too, operator (the person or application which
 * starts Loader) have to define. Restart mode with second parameter (optional).
 * </p>
 * <p>
 * There are two possible ways to start Loader. The first is as stand alone
 * application, the sintaxs is: <br>
 * <code><B>java org.webdocwf.util.loader.Loader [-options] urlOfTheXmlFile.xml</B></code>
 * <br>
 * urlOfTheXmlFile.xml is URL of the XML file with loading criteria,<br>
 * </p>
 * <p>
 * The second way is to start Loader as package, the sintax is:<br>
 * <code><B>public Loader(String loadJobFileName, String mode, String userID, String logDirName,
 *  String logFileName, boolean restartIndicator, Map variableValues, String vendorFileName,
 *  boolean onErrorContinue, String additionalPaths, int commitCount, int returnCode);
 * </code><br>
 * ldr.load();</B> <br>
 * If we want to execute Loader class without last for parameters, we must put
 * null as these arguments
 * </p>
 * <p>
 * When the Loader is started the log file is generated. Log file is txt file
 * and its name defines date and time when the Loader is started. There are
 * three Log modes: none - report only begining and finishing the application,
 * and exceptions if there are any, normal - add to log importing blocks and
 * full - with detailed report to operator.
 * </p>
 * <p>
 * Another big adventage of Loader is its possibility to execute any SQL
 * statements in target database. (creating database; creating, modifying and
 * deleting tables...)
 * </p>
 * <p>
 * XML file is the key part for loading criteria. XML tags define how the
 * loading job will be done.
 * </p>
 * 
 * @author Milosevic Sinisa
 * @author Radoslav Dutina
 * @author Zoran Milakovic
 */
public class Loader {
    int iValueColumns;

    Vector vecValueColumnsTargetTables = new Vector();

    // Vector vecTransformColumnsTargetTables = new Vector();
    Vector vecSourceColumnName = new Vector();

    Vector vecTargetColumnName = new Vector();

    Vector vecValueMode = new Vector();

    Vector vecTargetColumnValue = new Vector();

    Vector vecTargetKeyColumnName = new Vector();

    Vector vecVariableUseIDTableName = new Vector();

    Vector vecVariableUseIDTableID = new Vector();

    Vector vecVariableUseIDColumnName = new Vector();

    Vector vecVariableUseIDValueMode = new Vector();

    Vector vecVariableColumnName = new Vector();

    Vector vecVariableColumnTargetTableName = new Vector();

    Vector vecVariableColumnTargetTableID = new Vector();

    Vector vecVariableColumnTargetColumnName = new Vector();

    Vector vecVariableColumnValueMode = new Vector();

    Vector vecVariableColumnTypes = new Vector();

    Vector vecVariableTimesTableName = new Vector();

    Vector vecVariableTimesTableID = new Vector();

    Vector vecVariableTimesColumnName = new Vector();

    Vector vecVariableTimesValueMode = new Vector();

    int iConstantColumns;

    Vector vecConstantTargetColumnName = new Vector();

    Vector vecConstantValueMode = new Vector();

    Vector vecConstantConstantValue = new Vector();

    Vector vecConstantColumnTargetTableName = new Vector();

    Vector vecConstantColumnTargetTableID = new Vector();

    int iRelationColumns;

    Vector vecRelationColumnSourceTableName = new Vector();

    Vector vecRelationColumnSourceTableID = new Vector();

    Vector vecRelationColumnSourceColumnName = new Vector();

    Vector vecRelationColumnTargetTableName = new Vector();

    Vector vecRelationColumnTargetColumnName = new Vector();

    Vector vecRelationColumnTargetTableID = new Vector();

    Vector vecRelationColumnRelationMode = new Vector();

    int iTables;

    Vector vecTableTableName = new Vector();

    Vector vecTableTableID = new Vector();

    Vector vecTableInsert = new Vector();

    Vector vecTableTableMode = new Vector();

    Vector vecTableOidLogic = new Vector();

    Vector vecRelationSourceValue = new Vector();

    Vector vecRelationSourceType = new Vector();

    Vector vecTargetColumnType = new Vector();

    Vector vecConstantColumnType = new Vector();

    BigDecimal bdecOidNumber = new BigDecimal(0);

    BigDecimal bdecOidNumber2000 = new BigDecimal(0);

    String strLoaderJobFileName = "";

    boolean bRestartIndicator;

    Map mapVariableValues = new HashMap();

    boolean bOnErrorContinue;

    String strUserID = "";

    String strLogDirName = "";

    String strLogFileName = "";

    String strVendorFileName = "";

    String strAdditionalPaths = "";

    String confJarStructure = "";

    // interne Sinisa
    boolean hasRestartCounter;

    boolean hasUserID;

    Vector vecRelationKeyColumns = new Vector();

    Vector vecRelationKeyTypes = new Vector();

    Vector vecSortValues = new Vector();

    Vector vecSqlStmt = new Vector();

    String strSourceDriverName = "";

    String strTargetDriverName = "";

    // conf file default
    int iFirstColumnResult = 1;

    int iTargetFirstColumnResult = 1;

    //
    Vector vecVariableName = new Vector();

    Vector vecVariableValue = new Vector();

    Vector vecVariablePrefix = new Vector();

    Vector vecVariableSufix = new Vector();

    Vector vecVariableOverride = new Vector();

    Vector vecReplaceInConstants = new Vector();

    Vector vecReplaceInSQL = new Vector();

    Vector vecReplaceInData = new Vector();

    Vector vecReplaceInJDBC = new Vector();

    public static final String LOGMODE_NONE = "none";

    public static final String LOGMODE_NORMAL = "normal";

    public static final String LOGMODE_FULL = "full";

    ByteArrayOutputStream foStreamTmp = new ByteArrayOutputStream();

    boolean bReplaceInData = false;

    int iColumnsInSourceTable = 0;

    boolean isDefaultJdbc = false;

    private String defaultLogMode = LOGMODE_NORMAL;

    ArrayList logModes = new ArrayList();

    // private Cache cacheValues;
    // private EchoElement echo;
    private Logger logger;

    private CounterColumns counterColumns;

    private TimeWatch timeCounter;

    private Transformations transformations;

    // NEW CLASSES
    private JdbcParametersElement jdbcParametersElement = new JdbcParametersElement();

    private SqlElement sqlElement = new SqlElement();

    private ConfigReader configReaderSource = new ConfigReader();

    private ConfigReader configReaderTarget = new ConfigReader();

    private LoaderJobAttrReader loaderJobReader = new LoaderJobAttrReader();

    private ImportDefinitionElement importDefinitionElement = new ImportDefinitionElement();

    private DataCleaning dataCleaning = new DataCleaning(configReaderTarget);

    // rale
    private String strQuerySet = "";

    QueryWhereSet queryWhereSet = null;

    QueryConstantSet queryConstantSet = null;

    QueryTransformationSet queryTransformationSet = null;

    Hashtable queryStatement = new Hashtable();

    Hashtable indexDValue = new Hashtable();

    Hashtable indexDRelationValue = new Hashtable();

    Hashtable indexConstantDValue = new Hashtable();

    Hashtable indexDVariableValue = new Hashtable();

    Hashtable indexDTransformationValue = new Hashtable();

    Hashtable updateStatement = new Hashtable();

    Hashtable indexDOverwrite = new Hashtable();

    Hashtable indexDSetNull = new Hashtable();

    Hashtable updateConstantStatement = new Hashtable();

    Hashtable indexDConstantOver = new Hashtable();

    Hashtable indexDConstantNull = new Hashtable();

    // zk added this
    Hashtable resultVector = new Hashtable();

    Hashtable updateTransformationStatement = new Hashtable();

    Hashtable indexDTransformationOver = new Hashtable();

    Hashtable indexDTransformationNull = new Hashtable();

    Hashtable indexDTransformationUpdate = new Hashtable();

    // insert row
    Hashtable queryInsertRow = new Hashtable();

    Hashtable indexIsNotRelationsColumns = new Hashtable();

    Hashtable pstmtForInsert = new Hashtable();

    Hashtable pstmtColumnNames = new Hashtable();

    // Hashtable pstmtColumnTypes = new Hashtable();

    Vector pstmtKeys = new Vector();

    // default value
    Vector vecDefaultValue = new Vector();

    Vector vecDefaultVariableValue = new Vector();

    Vector vecDefaultVariableName = new Vector();

    Vector vecDefaultRelationValue = new Vector();

    Vector vecTempUserID = new Vector();

    boolean userIDExists = false;

    private int currentRow = 0;

    // coy table
    // source data which are not maped in to target data
    Hashtable allSourceColumnNameNoMap = new Hashtable();

    Hashtable allSourceColumnValueNoMap = new Hashtable();

    Hashtable allSourceColumnTypeNoMap = new Hashtable();

    Vector ImportDefinitionSourceColumnName = new Vector();

    Vector ImportDefinitionTargetColumnName = new Vector();

    private String currentJobName = "";

    Vector vecCTAutoMapp = new Vector();

    Vector vecCTDefaultMode = new Vector();

    Vector vecBlobVector = new Vector();

    Vector vecToHex = new Vector();

    Vector vecFromHex = new Vector();

    // caching the relations
    RelationsCache relationsCache = new RelationsCache();

    private Vector includeTables = new Vector();

    // caching the 'row check' query
    CheckRowCache checkRowCache = new CheckRowCache();

    // restart counter
    DataTransmition dataTransmition = new DataTransmition(
            importDefinitionElement);

    // oid and version column name
    private String currentOidColumnName = "oid";

    private String currentVersionColumnName = "version";

    // private PreparedStatementMethods pstmtMethods=new
    // PreparedStatementMethods();
    private Vector transformationsColumnNames = new Vector();

    private Vector transformationsValueModes = new Vector();

    private Vector transformationsColumnValueMode = new Vector();

    private Vector transformationsColumnTypes = new Vector();

    private Vector transformationsResultVectorTypes = new Vector();

    private Vector resultVectorTypes = new Vector();

    // ValidateSelectStmt validStmt = new ValidateSelectStmt();

    // number of columns before transformation values from source query
//    private int iOffsetForTransColumns = 0;

    // values for transformations, used from source ResultSet for all
    // transformation
    // source coulmns
    Vector transformationValues = new Vector();

    /**
     * Construct object Loader with an associated parameters.
     * 
     * @param loadJobFileName
     *            defines xml input file.
     * @param mode
     *            defines the default logmode. Possible values are "none",
     *            "normal" (is the default) and "full". Is "normal" otherwise -m
     *            none
     * @param userID
     *            String which is name of user. This argument is used for
     *            writing userID into variable columns. If it is 'null' there is
     *            no define userID columns.
     * @param logDirName
     *            defines the logfile directory. The default is the current
     *            working directory.
     * @param logFileName
     *            defines the logfile name. The default is
     *            "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
     * @param restartIndicator
     *            which is true if "restart" mode and false if "new" mode.
     * @param variableValues
     *            Map defines variables used in variable columns.
     * @param vendorFileName
     *            the filename of the XML DB-vendor configuration file. The
     *            default is "OctopusDBVendors.xml".
     * @param onErrorContinue
     *            defines to set the default of "onErrorContinue" to "true". Is
     *            false otherwise.
     * @param additionalPaths
     *            Extend the classpath with additional paths.
     * @param commitCount
     *            Sets the default commit count. System default is "100".
     * @param returnCode
     *            Sets the default error return code. System default is "1".
     * @param includeTables
     *            defines tables which will be processed
     */
    public Loader(String loadJobFileName, String mode, String userID,
            String logDirName, String logFileName, boolean restartIndicator,
            Map variableValues, String vendorFileName, boolean onErrorContinue,
            String additionalPaths, int commitCount, int returnCode,
            String[] includeTables, String confJarStructure) {
        this.strLoaderJobFileName = loadJobFileName;
        // defines the log mode,
        if (mode != null) {
            if (mode.equalsIgnoreCase("none")
                    || mode.equalsIgnoreCase("normal")
                    || mode.equalsIgnoreCase("full")) {
                // importDefinitionElement.strLogMode = mode;
                this.defaultLogMode = mode;
                // sqlElement.strLogMode = mode;
            } // else {
            // importDefinitionElement.strLogMode = "";
            // sqlElement.strLogMode = "";
        }

        if (userID != null) {
            this.strUserID = userID;
            this.hasUserID = true;
        } else
            this.hasUserID = false;
        if (logDirName != null)
            this.strLogDirName = logDirName;
        else {
            File fCurrent = new File("");
            this.strLogDirName = fCurrent.getAbsolutePath();
        }
        if (logFileName != null) {
            this.strLogFileName = logFileName;
        } else
            this.strLogFileName = "default";
        this.bRestartIndicator = restartIndicator;
        if (this.bRestartIndicator == true)
            this.hasRestartCounter = true;
        else
            this.hasRestartCounter = false;
        this.mapVariableValues = variableValues;
        if (vendorFileName != null) {
            this.strVendorFileName = vendorFileName;
        }
        this.bOnErrorContinue = onErrorContinue;
        if (additionalPaths != null) {
            try {
                this.strAdditionalPaths = additionalPaths;
                StringTokenizer st = new StringTokenizer(
                        this.strAdditionalPaths, ";");
                URL[] urls = new URL[st.countTokens()];
                int count = 0;
                while (st.hasMoreTokens()) {
                    urls[count] = new File(st.nextElement().toString()).toURL();
                    count++;
                }
                for (int i = 0; i < urls.length; i++) {
                    OctopusClassLoader.addURL(urls[i]);
                }
            } catch (Exception ne) {
                ne.printStackTrace();
            }
        }
        if (includeTables != null) {
            for (int i = 0; i < includeTables.length; i++) {
                this.includeTables.add(includeTables[i]);
            }
        }
        importDefinitionElement.iCommitCount = commitCount;
        ReturnCode.setDefaultErrorReturnCode(returnCode);
        this.confJarStructure = confJarStructure;
    }

    /**
     * Construct object Loader with an associated parameters.
     * 
     * @param loadJobFileName
     *            defines xml input file.
     * @param mode
     *            defines the default logmode. Possible values are "none",
     *            "normal" (is the default) and "full". Is "normal" otherwise -m
     *            none
     * @param userID
     *            String which is name of user. This argument is used for
     *            writing userID into variable columns. If it is 'null' there is
     *            no define userID columns.
     * @param logDirName
     *            defines the logfile directory. The default is the current
     *            working directory.
     * @param logFileName
     *            defines the logfile name. The default is
     *            "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
     * @param restartIndicator
     *            which is true if "restart" mode and false if "new" mode.
     * @param variableValues
     *            Map defines variables used in variable columns.
     * @param vendorFileName
     *            the filename of the XML DB-vendor configuration file. The
     *            default is "OctopusDBVendors.xml".
     * @param onErrorContinue
     *            defines to set the default of "onErrorContinue" to "true". Is
     *            false otherwise.
     * @param additionalPaths
     *            Extend the classpath with additional paths.
     * @param commitCount
     *            Sets the default commit count. System default is "100".
     * @param returnCode
     *            Sets the default error return code. System default is "1".
     */
    public Loader(String loadJobFileName, String mode, String userID,
            String logDirName, String logFileName, boolean restartIndicator,
            Map variableValues, String vendorFileName, boolean onErrorContinue,
            String additionalPaths, int commitCount, int returnCode) {

        this(loadJobFileName, mode, userID, logDirName, logFileName,
                restartIndicator, variableValues, vendorFileName,
                onErrorContinue, additionalPaths, commitCount, returnCode,
                null, null);

    }

    /**
     * Construct object Loader with an associated parameters.
     * 
     * @param loadJobFileName
     *            defines xml input file.
     * @param mode
     *            defines the default logmode. Possible values are "none",
     *            "normal" (is the default) and "full". Is "normal" otherwise -m
     *            none
     * @param userID
     *            String which is name of user. This argument is used for
     *            writing userID into variable columns. If it is 'null' there is
     *            no define userID columns.
     * @param logDirName
     *            defines the logfile directory. The default is the current
     *            working directory.
     * @param logFileName
     *            defines the logfile name. The default is
     *            "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
     * @param restartIndicator
     *            which is true if "restart" mode and false if "new" mode.
     * @param variableValues
     *            Map defines variables used in variable columns.
     * @param vendorFileName
     *            the filename of the XML DB-vendor configuration file. The
     *            default is "OctopusDBVendors.xml".
     * @param onErrorContinue
     *            defines to set the default of "onErrorContinue" to "true". Is
     *            false otherwise.
     * @param additionalPaths
     *            Extend the classpath with additional paths.
     * @param commitCount
     *            Sets the default commit count. System default is "100".
     * @param returnCode
     *            Sets the default error return code. System default is "1".
     */
    public Loader(String loadJobFileName, String mode, String userID,
            String logDirName, String logFileName, boolean restartIndicator,
            Map variableValues, String vendorFileName, boolean onErrorContinue,
            String additionalPaths, int commitCount, int returnCode,
            String[] includeTables) {

        this(loadJobFileName, mode, userID, logDirName, logFileName,
                restartIndicator, variableValues, vendorFileName,
                onErrorContinue, additionalPaths, commitCount, returnCode,
                includeTables, null);

    }

    /**
     * Construct object Loader with an associated parameters.
     * 
     * @param loadJobFileName
     *            defines xml input file.
     * @param mode
     *            defines the default logmode. Possible values are "none",
     *            "normal" (is the default) and "full". Is "normal" otherwise -m
     *            none
     * @param userID
     *            String which is name of user. This argument is used for
     *            writing userID into variable columns. If it is 'null' there is
     *            no define userID columns.
     * @param logDirName
     *            defines the logfile directory. The default is the current
     *            working directory.
     * @param logFileName
     *            defines the logfile name. The default is
     *            "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
     * @param restartIndicator
     *            which is true if "restart" mode and false if "new" mode.
     * @param variableValues
     *            Map defines variables used in variable columns.
     * @param vendorFileName
     *            the filename of the XML DB-vendor configuration file. The
     *            default is "OctopusDBVendors.xml".
     * @param onErrorContinue
     *            defines to set the default of "onErrorContinue" to "true". Is
     *            false otherwise.
     * @param additionalPaths
     *            Extend the classpath with additional paths.
     * @param commitCount
     *            Sets the default commit count. System default is "100".
     * @param returnCode
     *            Sets the default error return code. System default is "1".
     */
    public Loader(String loadJobFileName, String mode, String userID,
            String logDirName, String logFileName, boolean restartIndicator,
            Map variableValues, String vendorFileName, boolean onErrorContinue,
            String additionalPaths, int commitCount, int returnCode,
            String confJarStructure) {

        this(loadJobFileName, mode, userID, logDirName, logFileName,
                restartIndicator, variableValues, vendorFileName,
                onErrorContinue, additionalPaths, commitCount, returnCode,
                null, confJarStructure);

    }

    /**
     * Method addClassPath adds additional class paths into system classpath
     * property
     * 
     * @param oldClassPath -
     *            System classpath;
     * @param add -
     *            additional class paths.
     * @return value of parameter classPath
     */
    private String addClassPath(String oldClassPath, String add) {

        String classPath = oldClassPath;
        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
            if (!classPath.trim().endsWith(";"))
                classPath += ";";
            add = add.replace('\n', '\\');
            add = add.replace('\t', '\\');
            add = add.replace('\b', '\\');
            add = add.replace('\r', '\\');
            add = add.replace('\f', '\\');
            classPath = classPath.concat(add);
        } else {
            if (!classPath.trim().endsWith(":"))
                classPath += ":";
            add = add.replace('\n', '/');
            add = add.replace('\t', '/');
            add = add.replace('\b', '/');
            add = add.replace('\r', '/');
            add = add.replace('\f', '/');
            classPath = classPath.concat(add);

        }
        return classPath;
    }

    /**
     * Public constructor of Loader class. Constructor set value for
     * loadJobFileName attribute. Class set all other attributes to the default
     * values.
     * 
     * @param loadJobFileName
     *            Name of loadJob import XML file.
     * 
     */
    public Loader(String loadJobFileName) {
        this(loadJobFileName, null);
    }

    /**
     * Public constructor of Loader class. Constructor set value for
     * loadJobFileName attribute. Class set all other attributes to the default
     * values.
     * 
     * @param loadJobFileName
     *            Name of loadJob import XML file.
     * 
     */
    public Loader(String loadJobFileName, String confJarStructure) {
        this.strLoaderJobFileName = loadJobFileName;
        // importDefinitionElement.strLogMode = "";
        this.hasUserID = false;
        File fCurrent = new File("");
        this.strLogDirName = fCurrent.getAbsolutePath();
        this.strLogFileName = "default";
        this.bRestartIndicator = false;
        this.hasRestartCounter = false;
        this.bOnErrorContinue = false;
        importDefinitionElement.iCommitCount = 100;
        ReturnCode.setDefaultErrorReturnCode(1);
        this.confJarStructure = confJarStructure;
    }

    /**
     * Read value of loadJobFileName attribute.
     * 
     * @return String value of loadFileName attribute
     */
    public String getLoadJobFileName() {
        return this.strLoaderJobFileName;
    }

    /**
     * This method sets value of loadJobFileName attribute.
     * 
     * @param loadJobFileName
     *            loadJob XML file name
     */
    public void setLoadJobFileName(String loadJobFileName) {
        this.strLoaderJobFileName = loadJobFileName;
    }

    /**
     * Read value of Mode(LogMode) attribute.
     * 
     * @return value of attribute.
     */
    // public String getMode() {
    // return importDefinitionElement.strLogMode;
    // }
    /**
     * This method sets value of Mode attribute.
     * 
     * @param mode
     *            define Log mode. Possible values are: Loader.LOGMODE_NONE,
     *            Loader.LOGMODE_NORMAL, Loader.LOGMODE_FULL.
     */
    // public void setMode(String mode) {
    // importDefinitionElement.strLogMode = mode;
    // }
    /**
     * Read value of userID attribute.
     * 
     * @return value of attribute.
     */
    public String getUserID() {
        return this.strUserID;
    }

    /**
     * This method sets value of userID attribute.
     * 
     * @param userID
     *            attribute.
     */
    public void setUserID(String userID) {
        this.strUserID = userID;
    }

    /**
     * Read value of logDirName attribute
     * 
     * @return value of attribute
     */
    public String getLogDirName() {
        return this.strLogDirName;
    }

    /**
     * This method sets value of logDirName attribute.
     * 
     * @param logDirName
     *            value of attribute.
     */
    public void setLogDirName(String logDirName) {
        this.strLogDirName = logDirName;
    }

    /**
     * Read value of logFileName attribute.
     * 
     * @return value of attribute.
     */
    public String getLogFileName() {
        return this.strLogFileName;
    }

    /**
     * This method sets value of logFileName attribute.
     * 
     * @param logFileName
     *            value of attribute.
     */
    public void setLogFileName(String logFileName) {
        this.strLogFileName = logFileName;
    }

    /**
     * Read value of restartIndicator attribute.
     * 
     * @return value of attribute.
     */
    public boolean getRestartIndicator() {
        return this.bRestartIndicator;
    }

    /**
     * This method sets value of restartIndicator attribute.
     * 
     * @param restartIndicator
     *            value of attribute.
     */
    public void setRestartIndicator(boolean restartIndicator) {
        this.bRestartIndicator = restartIndicator;
    }

    /**
     * Read value of variableValues attribute.
     * 
     * @return value of attribute.
     */
    public Map getVariableValues() {
        return this.mapVariableValues;
    }

    /**
     * This method sets value of variableValues attribute.
     * 
     * @param variableValue
     *            value of attribute.
     */
    public void setVariableValues(Map variableValue) {
        this.mapVariableValues = variableValue;
    }

    /**
     * Read value of vendorFileName.
     * 
     * @return value of attribute.
     */
    public String getVendorFileName() {
        return this.strVendorFileName;
    }

    /**
     * This method sets value of vendorFileName attribute.
     * 
     * @param vendorFileName
     *            value of attribute.
     */
    public void setVendorFileName(String vendorFileName) {
        this.strVendorFileName = vendorFileName;
    }

    /**
     * read value of onErrorContinue attribute.
     * 
     * @return value of attribute.
     */
    public boolean getOnErrorContinue() {
        return this.bOnErrorContinue;
    }

    /**
     * This method sets value of onErrorContinue attribute.
     * 
     * @param onErrorContinue
     *            value of attribute.
     */
    public void setOnErrorContinue(boolean onErrorContinue) {
        this.bOnErrorContinue = onErrorContinue;
    }

    /**
     * Read value of additionalPaths attribute.
     * 
     * @return value of attribute.
     */
    public String getAdditionalPaths() {
        return this.strAdditionalPaths;
    }

    /**
     * This method sets value of additionalPaths attribute.
     * 
     * @param additionalPaths
     *            value of attribute.
     */
    public void setAdditionalPaths(String additionalPaths) {
        this.strAdditionalPaths = additionalPaths;
        String strClassPath = System.getProperty("java.class.path");
        strClassPath = this.addClassPath(strClassPath, this.strAdditionalPaths);
        try {
            this.getClass().getClassLoader().loadClass(strClassPath);
        } catch (ClassNotFoundException ne) {
            ne.printStackTrace();
        }
        // System.setProperty("java.class.path", strClassPath);
    }

    /**
     * Read value of commitCount attribute.
     * 
     * @return value of attribute.
     */
    public int getCommitCount() {
        return importDefinitionElement.iCommitCount;
    }

    /**
     * This method sets value of commitCount attribute.
     * 
     * @param commitCount
     *            value of attribute.
     */
    public void setCommitCount(int commitCount) {
        importDefinitionElement.iCommitCount = commitCount;
    }

    /**
     * Read value of default error return code attribute.
     * 
     * @return value of attribute.
     */
    public int getDefaultReturnCode() {
        return ReturnCode.getDefaultErrorReturnCode();
    }

    /**
     * This method sets value of default error return code attribute.
     * 
     * @param code
     *            is value of attribute.
     */
    public void setDefaultReturnCode(int code) {
        ReturnCode.setDefaultErrorReturnCode(code);
    }

    /**
     * This method set value of includeJobs parameter
     * 
     * @param include_Tables
     *            is value of parameter
     */
    public void setIncludedJobs(String include_Tables[]) {
        for (int i = 0; i < include_Tables.length; i++) {
            includeTables.add(include_Tables[i]);
        }
    }

    /**
     * This method read value of includeJobs parameter
     * 
     * @return value of parameter
     */
    public String[] getIncludedJobs() {
        String ret[] = new String[this.includeTables.size()];
        for (int i = 0; i < includeTables.size(); i++) {
            ret[i] = includeTables.get(i).toString();
        }
        return ret;
    }

    /**
     * This method read value of confJarStructure parameter
     * 
     * @return value of parameter
     */
    public String getConfJarStructure() {

        return this.confJarStructure;
    }

    /**
     * This method read value of defaultLogMode parameter
     * 
     * @return value of parameter
     */
    public String getDefaultLogMode() {

        return this.defaultLogMode;
    }

    /**
     * Main method Loader with an associated XML, restart mode (optional) i user
     * (optional). Main method controls parameters, it they are OK starts load
     * method, but if they aren't makes alert. Usage: java
     * org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
     * Options: -m defines the default logmode. Possible values are 'none',
     * 'normal' (is the default) and 'full'. -r starts the Loader in restart
     * mode after abnormal termination in a prior execution. -u defines the
     * current UserID used in UserID value columns. -v defines variables used in
     * variable columns. -l defines the logfile directory. The default is the
     * current working directory. -f defines the logfile name. The default is
     * 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. -d the filename of the XML DB-vendor
     * configuration file. The default is 'OctopusDBVendors.xml'. -e defines to
     * set the default of 'onErrorContinue' to 'true'. Is false otherwise. -p
     * Extend the classpath with additional paths. -c Sets the default commit
     * count. System default is '100'. -rc Sets the default error return code.
     * System default is '1'. -it Sets the table names which will be proccesed
     * 
     * @param argv
     *            represents input parmeters
     */
    public static void main(String argv[]) {
        String loadJobFileName = null;
        String mode = null;
        String userID = null;
        String logDirName = null;
        String logFileName = null;
        boolean restartIndicator = false;
        Map variableValues = null;
        String strVariableValues = null;
        String vendorFileName = null;
        boolean onErrorContinue = false;
        String additionalPaths = null;
        int defaultReturnCode = 1;
        int commitCount = 0;
        String[] includeTables = null;
        String confJarStructure = null;

        if (argv.length > 0 && argv.length < 26) {
            loadJobFileName = argv[argv.length - 1];
            for (int i = 0; i < argv.length - 1; i = i + 1) {
                if (argv[i].equalsIgnoreCase("-m"))
                    mode = argv[++i];
                else if (argv[i].equalsIgnoreCase("-r"))
                    restartIndicator = true;
                else if (argv[i].equalsIgnoreCase("-u"))
                    userID = argv[++i];
                else if (argv[i].equalsIgnoreCase("-l"))
                    logDirName = argv[++i];
                else if (argv[i].equalsIgnoreCase("-f"))
                    logFileName = argv[++i];
                else if (argv[i].equalsIgnoreCase("-d"))
                    vendorFileName = argv[++i];
                else if (argv[i].equalsIgnoreCase("-e"))
                    onErrorContinue = true;
                else if (argv[i].equalsIgnoreCase("-p"))
                    additionalPaths = argv[++i];
                else if (argv[i].equalsIgnoreCase("-c"))
                    commitCount = (new Integer(argv[++i])).intValue();
                else if (argv[i].equalsIgnoreCase("-v")) {
                    strVariableValues = argv[++i];
                    variableValues = new HashMap(
                            convertToMap(strVariableValues));
                } else if (argv[i].equalsIgnoreCase("-rc")) {
                    defaultReturnCode = (new Integer(argv[++i])).intValue();
                    ReturnCode.isParameter = true;
                } else if (argv[i].equalsIgnoreCase("-it")) {
                    String array = argv[++i];
                    StringTokenizer st = new StringTokenizer(array, ";");
                    includeTables = new String[st.countTokens()];
                    int pos = 0;
                    while (st.hasMoreTokens()) {
                        includeTables[pos] = st.nextToken();
                        pos++;
                    }
                } else if (argv[i].equalsIgnoreCase("-cjs")) {
                    confJarStructure = argv[++i];
                }
            }
        } else
            printUsage();
        Loader l = new Loader(loadJobFileName, mode, userID, logDirName,
                logFileName, restartIndicator, variableValues, vendorFileName,
                onErrorContinue, additionalPaths, commitCount,
                defaultReturnCode, includeTables, confJarStructure);
        try {
            l.load();
            BufferOctopusClass.getInstance().writeToBuffer(
                    String.valueOf(ReturnCode.getOKReturnCode()));
        } catch (LoaderException le) {
            BufferOctopusClass.getInstance()
                    .writeToBuffer(le.getCause() + "\n");
            BufferOctopusClass.getInstance().writeToBuffer(
                    String.valueOf(ReturnCode.getErrorReturnCode()));
            System.exit(ReturnCode.getErrorReturnCode());
        }
    }

    /**
     * put your documentation comment here
     */
    static void printUsage() {
        System.out
                .println("Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
        System.out.println(" Options:");
        System.out
                .println(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
        System.out
                .println(" -r starts the Loader in restart mode after abnormal termination in a prior execution. \n");
        System.out
                .println(" -u defines the current UserID used in UserID value columns. \n");
        System.out
                .println(" -v defines variables used in variable columns.  \n");
        System.out
                .println(" -l defines the logfile directory. The default is the current working directory.   \n");
        System.out
                .println(" -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
        System.out
                .println(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n");
        System.out
                .println(" -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n");
        System.out.println(" -p Extend the classpath with additional paths \n");
        System.out
                .println(" -c Sets the default commit count. System default is '100'.  \n");
        System.out
                .println(" -rc Sets the default error return code. System default is '1'.  \n");
        System.out
                .println(" -it Sets the table names which will be proccesed ");
        System.exit(ReturnCode.getErrorReturnCode());
    }

    /**
     * Method load is main method in class Loader. It is used to load data from
     * the source table into target tables and(or) execute SQL statements.
     * Loading parameters are set in XML file. During loading, load status is
     * printed on the screen and also put into log file. If there is an error
     * Exception "LoaderException" is thrown.
     * 
     * @throws LoaderException
     */
    public void load() throws LoaderException {
        int iImportJobs = 0;
        int iCopyTable = 0;
        int iConnection = 0;
        int iSqlTags = 0;
        int iEchoElements = 0;
        int iLastImportDefinition = 0;
        Vector vecXmlElements = new Vector();
        Vector vecJDBCTargetConnections = new Vector();

        // initializing logger
        // videti jos oko ulaznih parametara, iz main methode ili is xml fajla
        ParseLoggerParam loggerParam = new ParseLoggerParam(
                this.strLoaderJobFileName);
        String logClassName = loggerParam.getLogClassName();

        String pathToLoggerConf = loggerParam.getPathToLoggerConf();
        String strLoggerParam = "";
        boolean standardLogger = false;
        try {
            this.logger = (org.webdocwf.util.loader.logging.Logger) Class
                    .forName(logClassName).newInstance();
            if (pathToLoggerConf != null && pathToLoggerConf.length() != 0)
                strLoggerParam = pathToLoggerConf;
            else
                strLoggerParam = this.strLogDirName + ";" + this.strLogFileName;
        } catch (Exception e) {
            this.logger = new StandardLogger();
            strLoggerParam = this.strLogDirName + ";" + this.strLogFileName;
            standardLogger = true;
        }

        try {
            logger.configure(strLoggerParam);
            logger.setEnabledLogLevels(this.defaultLogMode);
            if (standardLogger == true) {
                // if
                // (!importDefinitionElement.strLogMode.equalsIgnoreCase("none"))
                // {
                this.logger.write("normal",
                        "Default (Standard) Logger is load.");
                // }
            }

        } catch (Exception ex) {
            String msg = "Error while configuring logger.";
            LoaderException le = new LoaderException(msg + "\n"
                    + ex.getMessage(), (Throwable) ex);
            BufferOctopusClass.getInstance().writeToBuffer(
                    msg + "\n" + ex.getMessage() + "\n");
            // this.logger.write("normal", msg + "\n" + ex.getMessage() + "\n");
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }

        this.timeCounter = new TimeWatch();

        // if (!this.echo.createLog(this.strLogDirName, this.strLogFileName))
        // this.echo.setLogFile(new File(this.strLogDirName,
        // this.strLogFileName));
        // this.createLog(this.strLogFileName);

        jdbcParametersElement.setLogger(this.logger);
        jdbcParametersElement.setConfigReaderSource(this.configReaderSource);
        jdbcParametersElement.setLoaderJobPath(this.strLoaderJobFileName);

        configReaderSource.setLogger(this.logger);
        configReaderTarget.setLogger(this.logger);
        configReaderSource.setConfJarStructure(this.confJarStructure);
        configReaderTarget.setConfJarStructure(this.confJarStructure);

        loaderJobReader.setLogger(this.logger);
        loaderJobReader.setDefaultOnErrorContinue(this.bOnErrorContinue);
        sqlElement.setLogger(this.logger);
        sqlElement.setLoaderJob(this.loaderJobReader);
        sqlElement.setConfigReader(this.configReaderTarget);
        sqlElement.setJdbcParametersElement(this.jdbcParametersElement);
        checkRowCache.setLogger(this.logger);
        dataTransmition.setLogger(this.logger);

        // if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
        this.logger.write("normal", "\nApplication is started.");
        // }

        this.timeCounter.setStartTime();
        ByteArrayInputStream inStream = null;
        ByteArrayOutputStream foStream = new ByteArrayOutputStream();
        // Loading XML file and replacing include tags
        LoaderXIncluder loaderInclude = new LoaderXIncluder(foStream);
        LocationOfException locationOfException = new LocationOfException(
                this.strLoaderJobFileName);
        loaderInclude.parseURI(this.strLoaderJobFileName);
        inStream = new ByteArrayInputStream(foStream.toByteArray());

        // for test only
        // try {
        // File file=new
        // File("c:/Users/Rale/Octopus/ObjectLoader/InputStream.txt");
        // FileOutputStream fileLogr=new FileOutputStream(file);
        // if(file.exists())
        // file.delete();
        // fileLogr.write(foStream.toByteArray());
        // fileLogr.close();
        // } catch(Exception e) { System.out.println("File error"); }

        // part for validating input xml file
        try {
            OctopusValidator validator = new OctopusValidator();
            validator
                    .validate(new ByteArrayInputStream(foStream.toByteArray()));
        } catch (Exception e) {
            this.logger.write("normal",
                    "Sorry, validation error occurred . Message was: "
                            + e.getMessage());

            BufferOctopusClass.getInstance().writeToBuffer(
                    "Sorry, validation error occurred . Message was: "
                            + e.getMessage());
            LoaderException le = new LoaderException("Exception:"
                    + e.getMessage(), (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;

        }
        // if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
        this.logger.write("normal", "\nXML document is valid.");

        // }

        // Import attribute values from variable tags from XML
        this.importVariable(inStream);
        // Setting bReplaceInData if there is even one ReplaceInData attribut
        // in variable tags
        for (int i = 0; i < this.vecReplaceInData.size(); i++) {
            if (this.vecReplaceInData.get(i).toString()
                    .equalsIgnoreCase("true"))
                bReplaceInData = true;
        }
        // Change variable values in SQL, JDBC and Constants Tags in XML
        this.foStreamTmp = foStream;
        foStream = new ByteArrayOutputStream();
        LoadVariable loadVariable = new LoadVariable(foStream, this);
        loadVariable.parseURI();
        // refresh inStream with replaced variables
        inStream = new ByteArrayInputStream(foStream.toByteArray());
        loaderJobReader.setDefaultLogMode(this.defaultLogMode);
        loaderJobReader.importLoaderJobAttributes(inStream);
        iImportJobs = this.parseImportJob(inStream);
        iCopyTable = this.parseCopyTable(inStream);
        iSqlTags = sqlElement.parseSql(inStream);
        iEchoElements = this.parseEcho(inStream);
        this.importRestartCounter(inStream);
        vecXmlElements = this.parseMainElements(inStream);

        // setting the last number of importDefinition tag
        iLastImportDefinition = 0;
        for (int i = 0; i < vecXmlElements.size(); i++) {
            if (vecXmlElements.get(i).toString().equalsIgnoreCase(
                    "importDefinition"))
                iLastImportDefinition = i;
        }
        jdbcParametersElement.parseTargetJDBCParameters(inStream);
        DBConnectionManager connManager = new DBConnectionManager(
                jdbcParametersElement.getTargetConnections());
        Connection connToPools = null;

        try {
            this.isDefaultJdbc = jdbcParametersElement
                    .parseImportJDBCDefaultParameters(inStream);

            if (this.strVendorFileName != null
                    && !this.strVendorFileName.equals(""))
                configReaderTarget.setVendorFileName(this.strVendorFileName);
            // this can be erased!!!?
            configReaderTarget.readConfigValues(jdbcParametersElement
                    .getTargetDBVendor(), jdbcParametersElement
                    .getTargetDriverName(), "target");
            this.currentOidColumnName = configReaderTarget.getOidColumnName();
            this.currentVersionColumnName = configReaderTarget
                    .getVersionColumnName();

            if (jdbcParametersElement.getJDBCTargetParameterDriver().equals("")
                    || jdbcParametersElement.getJDBCTargetParameterDriver() == null)
                jdbcParametersElement
                        .setJDBCTargetParameterDriver(configReaderTarget
                                .getDriverClassName());
            Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver());

            int iImport = 0;
            int iCopy = 0;
            int iSql = 0;
            int iEcho = 0;
            // main loop
            for (int l = 0; l < (iImportJobs + iCopyTable + iSqlTags + iEchoElements); l++) {
                Object tempLogMode = this.logModes.get(l);
                if (tempLogMode != null && !tempLogMode.equals(""))
                    this.logger.setEnabledLogLevels(tempLogMode.toString());
                else
                    this.logger.setEnabledLogLevels(loaderJobReader
                            .getDefaultLogMode());
                // reset global variables
                this.resetGlobalVariables();
                relationsCache.resetRelationsCache();
                checkRowCache.resetCheckRowCache();
                // if
                // (!importDefinitionElement.strLogMode.equalsIgnoreCase("none"))
                // {
                this.logger.write("normal", "\nImport job No. "
                        + (iImport + iCopy + iSql + 1) + " is started.");
                // }

                if (vecXmlElements.get(l).toString().equalsIgnoreCase(
                        "importDefinition")) {
                    this.logger.write("full",
                            "Importing and parsing XML file is started.");
                    // importing specific jdbc parameters if any exist
                    this.parseAndImport(inStream, iImport, true);
                    jdbcParametersElement.parseImportJDBCParameters(inStream,
                            iImport + 1, "importDefinition");

                    configReaderSource.readConfigValues(jdbcParametersElement
                            .getDbVendor(), jdbcParametersElement
                            .getDriverName(), "source");
                    configReaderTarget.readConfigValues(jdbcParametersElement
                            .getTargetDBVendor(), jdbcParametersElement
                            .getTargetDriverName(), "target");
                    // validStmt.setConfigReader(configReaderSource);
                    this.currentOidColumnName = configReaderTarget
                            .getOidColumnName();
                    this.currentVersionColumnName = configReaderTarget
                            .getVersionColumnName();

                }
                // rale 24.10.2003
                else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
                        "copyTable")) {
                    this.logger.write("full",
                            "Importing and parsing XML file is started.");
                    this.parseAndImport(inStream, iCopy, false);
                    // this.logger.setEnabledLogLevels(importDefinitionElement.strCopyTableLogMode);
                    jdbcParametersElement.parseImportJDBCParameters(inStream,
                            iCopy + 1, "copyTable");

                    configReaderSource.readConfigValues(jdbcParametersElement
                            .getDbVendor(), jdbcParametersElement
                            .getDriverName(), "source");
                    configReaderTarget.readConfigValues(jdbcParametersElement
                            .getTargetDBVendor(), jdbcParametersElement
                            .getTargetDriverName(), "target");
                    this.currentOidColumnName = configReaderTarget
                            .getOidColumnName();
                    this.currentVersionColumnName = configReaderTarget
                            .getVersionColumnName();
                } else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
                        "sql")) {
                    configReaderTarget.readConfigValues(jdbcParametersElement
                            .getTargetDBVendor(), jdbcParametersElement
                            .getTargetDriverName(), "target");

                    this.currentOidColumnName = configReaderTarget
                            .getOidColumnName();
                    this.currentVersionColumnName = configReaderTarget
                            .getVersionColumnName();

                    // this don't send enything to logger (importSQLStatement)
                    this.logger.write("full",
                            "Importing and parsing XML file is started.");
                    this.vecSqlStmt = sqlElement.importSQLStatement(inStream,
                            iSql);
                    // defining the log mode
                    // if (!sqlElement.getSqlLogMode().equals("") &&
                    // sqlElement.getSqlLogMode() != null)
                    // this.logger.setEnabledLogLevels(sqlElement.getSqlLogMode());
                    // else
                    // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());

                    // importing specific jdbc parameters if any exist
                    this.logger.write("full",
                            "Importing and parsing XML file is started.");
                    jdbcParametersElement.parseImportJDBCParameters(inStream,
                            iSql + 1, "sql");
                }
                if (vecXmlElements.get(l).toString().equalsIgnoreCase(
                        "importDefinition")
                        || vecXmlElements.get(l).toString().equalsIgnoreCase(
                                "sql")
                        || vecXmlElements.get(l).toString().equalsIgnoreCase(
                                "copyTable")) {

                    if (jdbcParametersElement.getJDBCSourceParameterDriver()
                            .equals("")
                            || jdbcParametersElement
                                    .getJDBCSourceParameterDriver() == null)
                        jdbcParametersElement
                                .setJDBCSourceParameterDriver(configReaderSource
                                        .getDriverClassName());

                    if (jdbcParametersElement.getJDBCTargetParameterDriver()
                            .equals("")
                            || jdbcParametersElement
                                    .getJDBCTargetParameterDriver() == null)
                        jdbcParametersElement
                                .setJDBCTargetParameterDriver(configReaderTarget
                                        .getDriverClassName());
                }
                this.logger.write("full",
                        "Importing and parsing XML file is finished.");

                connManager.setLoaderJobPath(this.strLoaderJobFileName);
                connManager.setConnectionPrefix(configReaderTarget
                        .getConnectionPrefix());
                connManager.setParsePermission(configReaderTarget
                        .getFileSystemDatabase());

                try {
                    connToPools = connManager
                            .getConnection(jdbcParametersElement
                                    .getJDBCTargetParameterConnection());
                    // TODO ZK 17.6 2004. This make problem with Excel
                    // jdbc-odbc.
                    connToPools.setAutoCommit(false);
                } catch (Exception ex) {
                    String message = "Can't get connection to Target Database."
                            + "\n"
                            + "Maybe connection "
                            + jdbcParametersElement
                                    .getJDBCTargetParameterConnection()
                            + " is wrong. ";
                    LoaderException le = new LoaderException("SQLException: "
                            + message + "\n" + ex.getMessage() + "\n",
                            (Throwable) ex);
                    this.logger.write("full", le.getStackTraceAsString());
                    throw le;
                }
                if (vecXmlElements.get(l).toString().equalsIgnoreCase(
                        "importDefinition")) {
                    if (importDefinitionElement.bRestartAutoCreate == true) {
                        dataTransmition.createRestartCounterTable(connToPools);
                    }
                    this.currentJobName = "importDefinition";
                    String importName = importDefinitionElement.strImportDefinitionName;
                    boolean doJob = true;
                    for (int i = 0; i < this.includeTables.size(); i++) {
                        if (importName.equalsIgnoreCase(this.includeTables.get(
                                i).toString())) {
                            doJob = true;
                            break;
                        } else {
                            doJob = false;
                        }
                    }
                    if (doJob) {
                        try {
                            this.loadSource(connToPools);

                        } catch (Exception ex) {
                            // this.logger.write("normal", "\t" +
                            // ex.getMessage().toString());
                            LoaderException le = new LoaderException(
                                    "SQLException: ", (Throwable) ex);
                            this.logger.write("full", le
                                    .getStackTraceAsString());
                            if (importDefinitionElement.strOnErrorContinueXml
                                    .equalsIgnoreCase("true")) {
                                this.logger
                                        .write(
                                                "normal",
                                                "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'");
                            } else {
                                this.logger
                                        .write(
                                                "normal",
                                                "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'");
                                connManager.release("true");
                                throw le;
                            }
                        }
                        // release resources
                        finally {
                            for (int i = 0; i < pstmtForInsert.size(); i++) {
                                String key = pstmtKeys.get(i).toString();
                                PreparedStatement pstmt = (PreparedStatement) pstmtForInsert
                                        .get(key);
                                pstmt.close();
                            }
                            pstmtKeys.clear();
                            pstmtForInsert.clear();
                            // release transformations
                            List transformations = this.transformations
                                    .getTransformations();
                            for (int iCount = 0; iCount < transformations
                                    .size(); iCount++) {
                                ((Transformation) transformations.get(iCount))
                                        .release();
                            }
                        }
                    } else
                        this.logger.write("normal", "\tImportDefinition "
                                + importName + " is excluded from process");
                    // this.logger.setEnabledLogLevels("none");
                    iImport++;
                }
                // rale 24.10.2003
                else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
                        "copyTable")) {
                    if (importDefinitionElement.bRestartAutoCreate == true) {
                        dataTransmition.createRestartCounterTable(connToPools);
                    }
                    this.currentJobName = "copyTable";
                    String importName = importDefinitionElement.strCopyTableName;
                    boolean doJob = true;
                    for (int i = 0; i < this.includeTables.size(); i++) {
                        if (importName.equalsIgnoreCase(this.includeTables.get(
                                i).toString())) {
                            doJob = true;
                            break;
                        } else {
                            doJob = false;
                        }
                    }
                    if (doJob) {
                        try {
                            this.loadSourceCT(connToPools);
                        } catch (Exception e) {
                            // this.logger.write("normal", "\t" +
                            // e.getMessage());
                            LoaderException le = new LoaderException(
                                    "SQLException: ", (Throwable) e);
                            this.logger.write("full", le
                                    .getStackTraceAsString());
                            if (importDefinitionElement.strCopyTableOnErrorContinue
                                    .equalsIgnoreCase("true")) {
                                this.logger
                                        .write(
                                                "normal",
                                                "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'");
                            } else {
                                this.logger
                                        .write(
                                                "normal",
                                                "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'");
                                connManager.release("true");
                                throw le;
                            }
                        }
                    } else {
                        this.logger.write("normal", "\tCopyTable " + importName
                                + " is excluded from process");
                    }
                    // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
                    iCopy++;
                } else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
                        "echo")) {
                    this.currentJobName = "echo";
                    logger.writeEcho(this.logger.getMessage(new Integer(iEcho)
                            .toString()));
                    iEcho++;
                } else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
                        "sql")) {
                    this.currentJobName = "sql";
                    String sqlName = sqlElement.getSqlName();
                    boolean doJob = true;
                    for (int i = 0; i < this.includeTables.size(); i++) {
                        if (sqlName.equalsIgnoreCase(this.includeTables.get(i)
                                .toString())) {
                            doJob = true;
                            break;
                        } else {
                            doJob = false;
                        }
                    }
                    if (doJob) {
                        try {
                            if (sqlElement.getSqlCommit().equalsIgnoreCase(
                                    "true")) {
                                connToPools.setAutoCommit(true);
                                // ZK change this because of problems with
                                // onErrorContinue="true" and commit="true" in
                                // <sql ...> tag
                                try {
                                    this.executeSQLStatement(connToPools);
                                } catch (Exception e) {
                                    throw e;
                                } finally {
                                    connToPools.setAutoCommit(false);
                                }
                            } else
                                this.executeSQLStatement(connToPools);
                        } catch (Exception e) {
                            LoaderException le = new LoaderException(
                                    "SQLException: ", (Throwable) e);
                            // this.logger.write("normal", "\t" +
                            // e.getMessage());
                            this.logger.write("full", le
                                    .getStackTraceAsString());
                            if (sqlElement.getSqlOnErrorContinue()
                                    .equalsIgnoreCase("true")) {
                                this.logger
                                        .write(
                                                "normal",
                                                "\tError : Because OnErrorContinue Attribute is true application is not terminated");
                            } else if (sqlElement.getSqlOnErrorContinue()
                                    .equalsIgnoreCase("")
                                    && loaderJobReader
                                            .getDefaultOnErrorContinue() == true) {

                                this.logger
                                        .write(
                                                "normal",
                                                "\tError : Because OnErrorContinue Attribute is true application is not terminated");
                            } else {
                                this.logger
                                        .write(
                                                "normal",
                                                "\tError : Because OnErrorContinue Attribute is false application is terminated");
                                connManager.release("true");
                                throw le;
                            }
                        }
                    } else {
                        this.logger.write("normal", "\tSql statement "
                                + sqlName + " is excluded from process");
                    }
                    iSql++;
                    // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
                } else {
                    // this.logger.write("normal",
                    // "Error : Loader supports loading data up to maximum 3 SQL
                    // database");
                    LoaderException le = new LoaderException(
                            "SQLException: ",
                            (Throwable) (new SQLException(
                                    "Error : Loader supports loading data up to maximum 3 SQL database")));
                    this.logger.write("full", le.getStackTraceAsString());
                    if (connToPools != null)
                        connManager.release("true");
                    throw le;
                }

                if (!this.hasRestartCounter && iLastImportDefinition == l) {
                    if (connToPools != null && !connToPools.isClosed())

                        connToPools.commit();
                }

            }
            this.logger.setEnabledLogLevels(this.defaultLogMode);
            connManager.release("false");
            this.logger.write("normal", "All rows are commited.");
            this.logger.write("normal", "Application is finished.");
            this.logger.write("normal", "All jobs duration: "
                    + this.timeCounter.getTotalTime());
        } catch (Exception e) {
            LoaderException le = new LoaderException("Exception: ",
                    (Throwable) e);
            // this.logger.write("normal", le.getCause().toString());
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        } finally {
            try {
                if (connToPools != null && !connToPools.isClosed())
                    connToPools.close();
                this.logger.close();
            } catch (SQLException e) {
                LoaderException le = new LoaderException("SQLException: ",
                        (Throwable) e);
                // this.logger.write("normal", le.getCause().toString());
                this.logger.write("full", le.getStackTraceAsString());
                throw le;
            }
        }
    }

    /**
     * Method loadSourceCT is used to load data from the source table (Csv,
     * MySql, MsSql, Exel...) into target tables.
     * 
     * @param connTarget
     *            is connection object to target database
     * @throws java.lang.Exception
     */
    private void loadSourceCT(Connection connTarget) throws Exception {

        this.timeCounter.setStartJobTime();
        DateFormat dfNow = DateFormat.getDateTimeInstance();
        Date currentDate = new Date();

        this.logger.write("full", "\tloadSourceCT method is started.");
        this.logger.write("normal", "Copy Table "
                + importDefinitionElement.strCopyTableName + " is started at "
                + dfNow.format(currentDate) + ".");

        Connection connSource = null;
        ResultSet rsetSource = null;
        ResultSet rsetTarget = null;
        Statement stmtSource = null;
        Statement stmtTarget = null;
        String logStatement = "";
        String strQuery = "";
        Vector vecNewColumnNames = new Vector();
        Vector vecNewColumnTypes = new Vector();
        Hashtable tmpColumnReader = new Hashtable();

        boolean bOidLogicCurrentTable = new Boolean(
                importDefinitionElement.strCopyTableOidLogic).booleanValue();
        boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
                .equals("") || importDefinitionElement.strObjectIDNameColumnValue
                .equals(""));
        try {
            this.checkOidLogic(connTarget);
            if (configReaderSource.getRequiredUser()) {
                if (jdbcParametersElement.getJDBCSourceParameterUser().equals(
                        ""))
                    this.inputUser(true);
                Class.forName(jdbcParametersElement
                        .getJDBCSourceParameterDriver());
                connSource = DriverManager.getConnection(jdbcParametersElement
                        .getJDBCSourceParameterConnection(),
                        jdbcParametersElement.getJDBCSourceParameterUser(),
                        jdbcParametersElement.getJDBCSourceParameterPassword());
            } else {
                Class.forName(jdbcParametersElement
                        .getJDBCSourceParameterDriver());
                connSource = DriverManager.getConnection(jdbcParametersElement
                        .getJDBCSourceParameterConnection());
            }

            int iRowNumber = 0;
            boolean isEndFlag = false;
            stmtSource = connSource.createStatement();
            stmtTarget = connTarget.createStatement();

            // setCursorName
            boolean setCursorName = false;
            if (!importDefinitionElement.setCursorNameCT.equalsIgnoreCase(""))
                setCursorName = new Boolean(
                        importDefinitionElement.setCursorNameCT).booleanValue();
            else
                setCursorName = configReaderSource.getSetCursorNameEnabled();

            if (setCursorName) {
                long cursorName = System.currentTimeMillis();
                stmtSource.setCursorName(String.valueOf(cursorName));
            }
            // setFetchSize
            boolean setFetchSize = false;
            if (!importDefinitionElement.setFetchSizeCT.equalsIgnoreCase(""))
                setFetchSize = new Boolean(
                        importDefinitionElement.setFetchSizeCT).booleanValue();
            else
                setFetchSize = configReaderSource.getSetFetchSizeEnabled();

            if (setFetchSize)
                stmtSource
                        .setFetchSize(importDefinitionElement.iCopyTableCommitCount);
            // ZK added this 5.4 2004
            // begin
            // next line will give me parameter getColumnsSupported from
            // *conf.xml. It describe is getColumns() method is suported
            // by used driver

            boolean columnsSuportedTarget = configReaderTarget
                    .getColumnsSupported();
            boolean columnsSuportedSource = configReaderSource
                    .getColumnsSupported();

            strQuery = "select * from ";

            // sourceColumnCount is used out of try block also
            rsetSource = stmtSource.executeQuery(strQuery
                    + importDefinitionElement.strCopyTableSourceTableName);
            int sourceColumnCount = rsetSource.getMetaData().getColumnCount();
            try {
                if (columnsSuportedSource) {
                    ResultSet rsetSourceTemp = connSource
                            .getMetaData()
                            .getColumns(
                                    connSource.getCatalog(),
                                    null,
                                    importDefinitionElement.strCopyTableSourceTableName,
                                    "%");
                    while (rsetSourceTemp.next()) {
                        vecNewColumnNames.add(rsetSourceTemp.getString(4));
                    }
                    rsetSourceTemp.close();

                } else {
                    // rsetSource and source column count are already maked
                    // above try block
                    for (int i = 1; i < sourceColumnCount + 1; i++) {
                        vecNewColumnNames.add(rsetSource.getMetaData()
                                .getColumnName(i));
                    }
                }

                if (columnsSuportedTarget) {
                    ResultSet rsetTargetTemp = connTarget
                            .getMetaData()
                            .getColumns(
                                    connTarget.getCatalog(),
                                    null,
                                    importDefinitionElement.strCopyTableTargetTableName,
                                    "%");

                    while (rsetTargetTemp.next()) {
                        String targetColumnName = rsetTargetTemp.getString(4);
                        String targetColumnType = rsetTargetTemp.getString(6);
                        tmpColumnReader.put(targetColumnName.toUpperCase(),
                                targetColumnType);
                    }
                    rsetTargetTemp.close();

                } else {
                    if (configReaderTarget.getMaxRowsSupported()) {
                        stmtTarget.setMaxRows(1);
                    }

                    rsetTarget = stmtTarget
                            .executeQuery(strQuery
                                    + importDefinitionElement.strCopyTableTargetTableName);
                    int targetColumnCount = 0;
                    targetColumnCount = rsetTarget.getMetaData()
                            .getColumnCount();
                    for (int i = 1; i < targetColumnCount + 1; i++) {
                        String targetColumnName = rsetTarget.getMetaData()
                                .getColumnName(i);
                        String targetColumnType = rsetTarget.getMetaData()
                                .getColumnTypeName(i);
                        tmpColumnReader.put(targetColumnName.toUpperCase(),
                                targetColumnType);
                    }
                    rsetTarget.close();
                }

                // same for both cases
                for (int i = 0; i < vecNewColumnNames.size(); i++) {
                    String columnName = vecNewColumnNames.get(i).toString()
                            .toUpperCase();
                    String tmpTargetColumnType = tmpColumnReader
                            .get(columnName).toString();
                    vecNewColumnTypes.add(tmpTargetColumnType);
                }

            }

            catch (Exception ex) {

                String msg = "In copy table job '"
                        + importDefinitionElement.strCopyTableName + "',"
                        + " Source and Target table are not compatibile.";
                Exception e = new Exception(msg + "\n" + ex.getMessage());
                throw e;
            }

            int currentBlock = 0;
            int blockNumber = 0;
            int bdecRowCount = 0;
            int currentVersion = 0;
            BigDecimal bdecCounter = new BigDecimal(0);

            if (configReaderSource.getRowCountEnabled()) {
                String countSQL = "";
                try {
                    // countSQL = " select count(*) as \"counter\" from "
                    // + importDefinitionElement.strCopyTableName;
                    countSQL = " select count(*) from "
                            + importDefinitionElement.strCopyTableName;
                    Statement stmtSourceCount = connSource.createStatement();
                    ResultSet rsetSourceCount = stmtSourceCount
                            .executeQuery(countSQL);
                    rsetSourceCount.next();
                    // iRowNumber = rsetSourceCount.getInt("counter");
                    iRowNumber = rsetSourceCount.getInt(configReaderSource
                            .getFirstColumnResult());
                    blockNumber = iRowNumber
                            / importDefinitionElement.iCopyTableCommitCount + 1;
                    rsetSourceCount.close();
                    stmtSourceCount.close();
                } catch (Exception e) {
                    this.logger.write(Logger.LOGMODE_NORMAL,
                            "Error while execute count sql: " + countSQL);
                }
            }

            boolean main = true;
            if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
                if (this.hasRestartCounter) {
                    bdecCounter = dataTransmition.checkDataTransmition(
                            connTarget, rsetSource, this.currentJobName,
                            configReaderTarget.getFirstColumnResult());

                    if (bdecCounter != null) {
                        if (bdecCounter.toString().equalsIgnoreCase("0")) {
                            // if is mycounter=0 in myrestart table escape this
                            // importdefinition
                            main = false;
                        }
                    } else {
                        bdecCounter = new BigDecimal(0);
                    }
                }
            }

            while (main) {
                // iCopyTableCommitCount (ImportDefinition or default (100))
                this.logger.write("normal", "Import block is started.");
                currentBlock++;
                if (configReaderSource.getRowCountEnabled()) {
                    this.logger.write("normal", "Working...  " + currentBlock
                            + ". block of " + blockNumber);
                } else {
                    this.logger.write("normal", "Working...  " + currentBlock
                            + ". block");
                }
                this.logger.write("full", "\tStarted from the "
                        + bdecCounter.add(new BigDecimal(1)).toString()
                        + ". row.");
                iRowNumber = 0;

                QueryInsertRowCt queryInsertRowCt = new QueryInsertRowCt(
                        bOidLogicCurrentTable, isTOS, vecNewColumnNames,
                        vecNewColumnTypes,
                        importDefinitionElement.strCopyTableTargetTableName,
                        this.bdecOidNumber, this.currentOidColumnName,
                        this.currentVersionColumnName, configReaderTarget
                                .getOidDbType(), configReaderTarget
                                .getVersionDbType(), configReaderTarget
                                .getJavaTypeMapings());

                String pstmtInsert = queryInsertRowCt
                        .getPreperedStatementForInsert();
                PreparedStatement pstmt = connTarget
                        .prepareStatement(pstmtInsert);

                while (iRowNumber < importDefinitionElement.iCopyTableCommitCount) {
                    if (!rsetSource.next()) {
                        isEndFlag = true;
                        break;
                    }
                    currentRow = iRowNumber;
                    if (bOidLogicCurrentTable) {
                        if (this.bdecOidNumber
                                .compareTo(this.bdecOidNumber2000) == 0) {
                            this.checkOidLogic(connTarget);
                            this.bdecOidNumber = this.bdecOidNumber
                                    .add(new BigDecimal(1));
                        } else {
                            this.bdecOidNumber = this.bdecOidNumber
                                    .add(new BigDecimal(1));
                        }
                    }
                    try {
                        int mnemonic = -1;
                        String insertForOut = pstmtInsert;
                        for (int i = 1; i < sourceColumnCount + 1; i++) {
                            String columnType = vecNewColumnTypes.get(i - 1)
                                    .toString();
                            String javaType = (String) configReaderTarget
                                    .getJavaTypeMapings().get(
                                            columnType.toUpperCase());

                            if (javaType == null) {
                                this.logger.write("normal",
                                        "There is no java type defined for sql type "
                                                + columnType.toUpperCase());
                                LoaderException le = new LoaderException(
                                        "Exception:", new Exception(
                                                "There is no java type defined for sql type "
                                                        + columnType
                                                                .toUpperCase()));
                                this.logger.write("full", le
                                        .getStackTraceAsString());
                                throw le;
                            }

                            int javaTypeInt = Integer.parseInt(javaType);
                            if (javaTypeInt == 1) {
                                byte[] isBlob = rsetSource.getBytes(i);
                                if (isBlob == null || isBlob.length == 0) {
                                    pstmt.setBytes(i, null);
                                    mnemonic = insertForOut.indexOf("?");
                                    insertForOut = insertForOut.substring(0,
                                            mnemonic)
                                            + "BinaryObject(null)"
                                            + insertForOut
                                                    .substring(mnemonic + 1);
                                } else {
                                    ByteArrayInputStream bais = new ByteArrayInputStream(
                                            isBlob);
                                    // TODO see how to solve this on general
                                    // way,best to make configurable which
                                    // method will be called
                                    pstmt.setBytes(i, isBlob);
                                    // pstmt.setBinaryStream(i,bais,isBlob.length);

                                    mnemonic = insertForOut.indexOf("?");
                                    insertForOut = insertForOut.substring(0,
                                            mnemonic)
                                            + "BinaryObject"
                                            + insertForOut
                                                    .substring(mnemonic + 1);
                                }
                            } else {
                                String value = rsetSource.getString(i);
                                if (value == null)
                                    value = "null";
                                if (bReplaceInData)
                                    value = this.replaceInData(value);

                                this.setValueOnStatement(value, javaTypeInt, i,
                                        pstmt);

                                mnemonic = insertForOut.indexOf("?");
                                insertForOut = insertForOut.substring(0,
                                        mnemonic)
                                        + value
                                        + insertForOut.substring(mnemonic + 1);

                            } // end of main else
                        } // end of for loop
                        logStatement = insertForOut;
                        this.logger.write("full", "\tQuery '" + insertForOut
                                + "' will be executed");
                        pstmt.executeUpdate();
                        pstmt.clearParameters();
                    } catch (Exception ex) {
                        if (importDefinitionElement.strCopyTableOnErrorContinue
                                .equalsIgnoreCase("true")) {
                            dataCleaning
                                    .cleaningInsert(
                                            importDefinitionElement.strCopyTableTargetTableName,
                                            connTarget, currentRow, "INSERT",
                                            ex.getMessage(), "COPY TABLE",
                                            logStatement);
                        } else {
                            throw ex;
                        }
                    }
                    this.logger
                            .write("full", "\tinsertRow method is finished.");
                    iRowNumber++;
                } // iRowNumber <
                // importDefinitionElement.iCopyTableCommitCount

                // restart counter table
                if (!importDefinitionElement.strRestartCounterTableName
                        .equals("")) {
                    if (this.hasRestartCounter) {
                        bdecCounter = bdecCounter
                                .add(new BigDecimal(iRowNumber));
                        dataTransmition.insertCounter(this.currentJobName,
                                bdecCounter, connTarget);
                    }
                }
                if (this.hasRestartCounter) {

                    connTarget.commit();
                    this.logger.write("normal", "Imported block is commited.");
                    this.logger.write("full", Integer.toString(iRowNumber)
                            + " rows are commited.");
                }

                iRowNumber = 0;
                if (isEndFlag) {
                    break;
                }
                pstmt.close();
            } // while(true)

            strQuery = "";
            rsetSource.close();
            // rsetTarget.close();
            stmtSource.close();
            stmtTarget.close();
            if (!connSource.isClosed())
                connSource.close();

            // seting mycounter=0 in myrestart table (success)
            if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
                if (this.hasRestartCounter) {
                    dataTransmition.resetRestartCounter(connTarget,
                            this.currentJobName);
                }
            }
            currentDate = new Date();
            dfNow = DateFormat.getDateTimeInstance();
            this.logger.write("normal", "Copy table "
                    + importDefinitionElement.strCopyTableName
                    + " is finished at " + dfNow.format(currentDate) + ".");
            this.logger.write("normal", " Duration of copyTable:"
                    + this.timeCounter.getJobTime());
        } catch (Exception e) {
            throw e;
        }
    }

    /**
     * Method loadSource is used to load data from the source table (Csv, MySql,
     * MsSql, Exel...) into target tables. This method uses configuration file
     * OctopusDbVendors.xml. Loading parameters are set in XML file. During
     * loading, load status is printed on the screen and also put into log file.
     * This method is used for loading data by rules which is defined in a
     * single importDefinition. If there is an error Exception "LoaderException"
     * is thrown.
     * 
     * @param connTarget
     *            represents connection of target table.
     * @throws LoaderException
     */
    private void loadSource(Connection connTarget) throws LoaderException {
        int iRowNumber = 0;
        BigDecimal bdecCounter = new BigDecimal(0);
        BigDecimal k = new BigDecimal(0);
        Date currentDate = new Date();
        DateFormat dfNow = DateFormat.getDateTimeInstance();
        boolean columnsSuportedTarget = configReaderTarget
                .getColumnsSupported();
        this.timeCounter.setStartJobTime();
        this.logger.write("full", "\tloadSource method is started.");
        this.logger.write("normal", "Import definition "
                + importDefinitionElement.strImportDefinitionName
                + " is started at " + dfNow.format(currentDate) + ".");
        Connection connSource = null;

        try {

            for (int i = 0; i < this.iTables; i++) {
                this.counterColumns.setTargetColumnStartValues(
                        this.vecTableTableName.get(i).toString(),
                        this.vecTableTableID.get(i).toString(), connTarget,
                        this.iTargetFirstColumnResult);
                this.counterColumns.counterColumnTypes(this.vecTableTableName
                        .get(i).toString(), this.vecTableTableID.get(i)
                        .toString(), connTarget, this.iTargetFirstColumnResult,
                        columnsSuportedTarget, configReaderTarget);

            }

            // source
            if (configReaderSource.getRequiredUser()) {
                if (jdbcParametersElement.getJDBCSourceParameterUser().equals(
                        ""))
                    this.inputUser(true);
                Class.forName(jdbcParametersElement
                        .getJDBCSourceParameterDriver());
                connSource = DriverManager.getConnection(jdbcParametersElement
                        .getJDBCSourceParameterConnection(),
                        jdbcParametersElement.getJDBCSourceParameterUser(),
                        jdbcParametersElement.getJDBCSourceParameterPassword());

            } else {
                Class.forName(jdbcParametersElement
                        .getJDBCSourceParameterDriver());
                connSource = DriverManager.getConnection(jdbcParametersElement
                        .getJDBCSourceParameterConnection());
            }

            Statement stmtSource = null;
            stmtSource = connSource.createStatement();

            // target
            if (importDefinitionElement.bObjectIDAutoCreate == true) {
                createObjectIDTable(connTarget);
                connTarget.commit();
            }
            // Statement stmtTarget = connTarget.createStatement();

            this.constantColumnTypes(connTarget);
            this.targetColumnTypes(connTarget);
            this.checkOidLogic(connTarget);

            int currentBlock = 0;
            String strQueryWhere = "";

            for (int i = 0; i < this.iTables; i++) {
                // ZK added 18.5.2004
                // QueryTransformationSet queryTransformationSet = null;
                // this.indexDTransformationOver = new Hashtable();
                // this.indexDTransformationOver = new Hashtable();
                // this.updateTransformationStatement = new Hashtable();
                // // end
                // ZK added this for transformations - 27.04.2004.
                ArrayList trans = this.transformations.getTransformations();
                Iterator iTrans = trans.iterator();

                while (iTrans.hasNext()) {
                    Transformation temp = (Transformation) iTrans.next();

                    // temp.setTargetParameters(this.vecTableTableName.get(i).toString(),this.vecTableTableID.get(i).toString());
                    temp.transformationColumnTypes(connTarget,
                            this.iTargetFirstColumnResult,
                            columnsSuportedTarget, configReaderTarget);

                }
                // end
                // ZK added this for transormations
                Vector pomTypes;
                Vector pomNames;
                Vector pomValueModes;
                Vector targetKeyColumnNames;
                Vector targetColumnNames;
                Vector targetColumnTypes;
                targetColumnNames = new Vector();
                targetKeyColumnNames = new Vector();
                Vector targetValueModes = new Vector();
                targetColumnTypes = new Vector();
                pomNames = new Vector();
                pomTypes = new Vector();
                pomValueModes = new Vector();

                String tableId = this.vecTableTableID.get(i).toString();
                ArrayList transTableIDs = this.transformations
                        .getTransformationsTableIDs();
                if (transTableIDs.contains(tableId)) {

                    for (int j = 0; j < trans.size(); j++) {
                        Transformation pom = (Transformation) trans.get(j);
                        targetColumnNames = pom.getTargetColumnNames(i);
                        targetColumnTypes = pom.getTargetColumnTypes(i);
                        targetKeyColumnNames = pom.getTargetKeyColumnNames(i);
                        targetValueModes = pom.getTargetValueModes(i);

                        for (int o = 0; o < targetColumnTypes.size(); o++) {
                            pomTypes.add(targetColumnTypes.get(o).toString());
                        }
                        for (int o = 0; o < targetColumnNames.size(); o++) {
                            pomNames.add(targetColumnNames.get(o).toString());
                        }
                        for (int o = 0; o < targetValueModes.size(); o++) {
                            pomValueModes.add(targetValueModes.get(o)
                                    .toString());
                        }
                    }

                }

                this.transformationsColumnTypes.add(pomTypes);
                this.transformationsColumnNames.add(pomNames);
                this.transformationsValueModes.add(pomValueModes);
                // end
                boolean bOidLogicCurrentTable = new Boolean(
                        this.vecTableOidLogic.get(i).toString()).booleanValue();
                boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
                        .equals("") || importDefinitionElement.strObjectIDNameColumnValue
                        .equals(""));
                boolean oid = false;
                if (bOidLogicCurrentTable && !isTOS)
                    oid = true;

                // source column data which are not maped to targetdatabase
                LoadAllSourceData allSourceData = null;
                Vector vecRelationColumns = this.vecRelationColumnTargetColumnName;
                Vector vecVariableColumns = this.vecVariableColumnTargetColumnName;
                Vector vecConstantColumns = (Vector) this.vecConstantTargetColumnName
                        .get(i);

                Vector vecUseIDColumns = this.vecVariableUseIDColumnName;
                Vector vecTimesColumns = this.vecVariableTimesColumnName;

                String ctAutoMapColumns = this.vecCTAutoMapp.get(i).toString();
                String ctDefaultMode = this.vecCTDefaultMode.get(i).toString();
                String sourceTableName = importDefinitionElement.strImportDefinitionTableName;
                // ZK change this. Added new parameter columnsSuportedTarget.

                if (ctAutoMapColumns.equalsIgnoreCase("true")) {
                    allSourceData = new LoadAllSourceData(connSource,
                            sourceTableName, ImportDefinitionSourceColumnName,
                            vecTableTableName.get(i).toString(), connTarget,
                            logger, vecRelationColumns, vecVariableColumns,
                            vecConstantColumns, vecUseIDColumns,
                            vecTimesColumns, columnsSuportedTarget,
                            configReaderTarget);
                } else {
                    // stmtTarget.close();
                }

                // source column data which are not maped to targetdatabase
                if (allSourceData != null) {
                    String keySource = String.valueOf(i);
                    allSourceColumnNameNoMap.put(keySource, allSourceData
                            .getNoMapSourceColumnName());
                    allSourceColumnTypeNoMap.put(keySource, allSourceData
                            .getNoMapSourceColumnType());
                    allSourceColumnValueNoMap.put(keySource, allSourceData
                            .getNoMapSourceColumnValue());
                }

                // set new column names, column types and value modes for column
                // which are not maped in to
                // target columns
                if (allSourceData != null) {
                    if (allSourceData.getNoMapSourceColumnName().size() > 0) {
                        for (int o = 0; o < allSourceData
                                .getNoMapSourceColumnName().size(); o++) {
                            ((Vector) this.vecTargetColumnName.get(i))
                                    .add(allSourceData
                                            .getNoMapSourceColumnName().get(o)
                                            .toString());
                            ((Vector) this.vecSourceColumnName.get(i))
                                    .add(allSourceData
                                            .getNoMapSourceColumnName().get(o)
                                            .toString());
                            ((Vector) this.vecToHex.get(i)).add("");
                            ((Vector) this.vecFromHex.get(i)).add("");
                            ((Vector) this.vecDefaultValue.get(i)).add("");
                        }
                        int map = Integer
                                .parseInt(this.vecValueColumnsTargetTables.get(
                                        i).toString());
                        int noMap = allSourceData.getNoMapSourceColumnName()
                                .size();
                        int all = map + noMap;
                        this.vecValueColumnsTargetTables.set(i,
                                new Integer(all));
                    }
                }
                if (allSourceData != null) {
                    if (allSourceData.getNoMapSourceColumnName().size() > 0) {
                        for (int o = 0; o < allSourceData
                                .getNoMapSourceColumnName().size(); o++) {
                            ((Vector) this.vecValueMode.get(i))
                                    .add(ctDefaultMode);
                        }
                    }
                }
                if (allSourceData != null) {
                    if (allSourceData.getNoMapSourceColumnType().size() > 0) {
                        for (int o = 0; o < allSourceData
                                .getNoMapSourceColumnType().size(); o++) {
                            ((Vector) this.vecTargetColumnType.get(i))
                                    .add(allSourceData
                                            .getNoMapSourceColumnType().get(o)
                                            .toString());
                        }
                    }
                }

                Vector vecColumnNames = (Vector) this.vecTargetColumnName
                        .get(i);
                Vector vecColumnTypes = (Vector) this.vecTargetColumnType
                        .get(i);
                Vector vecValueModes = (Vector) this.vecValueMode.get(i);

                // set query statement
                QuerySet querySet = new QuerySet(i, bOidLogicCurrentTable,
                        isTOS, vecColumnNames, vecTableTableName,
                        this.currentOidColumnName,
                        this.currentVersionColumnName);

                // set query where statement
                queryWhereSet = new QueryWhereSet(vecColumnNames,
                        vecColumnTypes, vecTableTableName.get(i).toString(),
                        vecTableTableID.get(i).toString());

                // set query update statement
                QueryUpdateSet queryUpdateSet = new QueryUpdateSet(
                        vecColumnNames, vecColumnTypes, vecValueModes,
                        vecTableTableName.get(i).toString(), oid,
                        this.currentVersionColumnName, configReaderTarget);

                if (((Vector) this.vecTargetKeyColumnName.get(i)).size() > 0)
                    // ZK change this 7.5.2004. Because of new parameter in
                    // getKeyColumns
                    queryWhereSet.getKeyColumns(
                            (Vector) this.vecTargetKeyColumnName.get(i),
                            configReaderTarget);

                // //ZK added this for transformations
                if (targetKeyColumnNames.size() > 0)
                    queryWhereSet.getTransformationKeyColumns(
                            targetColumnNames, targetKeyColumnNames,
                            targetColumnTypes, configReaderTarget);
                // //ZK end

                if (((Vector) this.vecRelationKeyColumns.get(i)).size() > 0)
                    queryWhereSet.getRelationKeyColumns(
                            (Vector) vecRelationKeyColumns.get(i),
                            iRelationColumns, vecRelationColumnTargetTableName,
                            vecRelationColumnTargetTableID,
                            vecRelationColumnTargetColumnName,
                            // TODO zoran, try this change, vecRelationKeyTypes
                            // to (Vector)vecRelationKeyTypes.get(i)
                            (Vector) vecRelationKeyTypes.get(i),
                            configReaderTarget);
                if (((Vector) this.vecConstantTargetColumnName.get(i)).size() > 0)
                    queryWhereSet.getConstantKeyColumns(
                            (Vector) this.vecConstantTargetColumnName.get(i),
                            (Vector) this.vecConstantValueMode.get(i),
                            (Vector) this.vecConstantColumnType.get(i),
                            configReaderTarget);

                if (vecVariableColumnTargetTableName.size() > 0)
                    queryWhereSet.getVariableKeyColumns(
                            vecVariableColumnTargetTableName,
                            vecVariableColumnTargetTableID,
                            vecVariableColumnValueMode, vecVariableName,
                            vecVariableColumnName,
                            vecVariableColumnTargetColumnName,
                            vecVariableColumnTypes, logger, configReaderTarget);
                // set insert row

                InsertRowQuerySet insertRowQuerySet = new InsertRowQuerySet(
                        connTarget, (Vector) this.vecTargetColumnName.get(i),
                        (Vector) this.vecValueMode.get(i), vecTableTableName
                                .get(i).toString(), vecTableTableID.get(i)
                                .toString(), i,
                        (Vector) this.vecConstantTargetColumnName.get(i),
                        vecVariableTimesTableName, vecVariableTimesTableID,
                        vecVariableTimesColumnName,
                        vecVariableColumnTargetTableName,
                        vecVariableColumnTargetTableID,
                        vecVariableColumnTargetColumnName,
                        vecRelationColumnTargetColumnName,
                        vecRelationColumnTargetTableName,
                        vecRelationColumnTargetTableID,
                        vecRelationColumnRelationMode, counterColumns,
                        transformations, bOidLogicCurrentTable, isTOS,
                        this.currentOidColumnName,
                        this.currentVersionColumnName);

                // set query constant statement
                if (((Vector) this.vecConstantTargetColumnName.get(i)).size() > 0)
                    queryConstantSet = new QueryConstantSet(vecTableTableName
                            .get(i).toString(),
                            (Vector) this.vecConstantTargetColumnName.get(i),
                            (Vector) this.vecConstantValueMode.get(i),
                            (Vector) this.vecConstantColumnType.get(i),
                            configReaderTarget);
                strQuerySet = querySet.getQuerySet();
                strQueryWhere = queryWhereSet.getQueryWhere();

                if (!(strQueryWhere.length() < 8)) {
                    strQueryWhere = strQueryWhere.substring(0, strQueryWhere
                            .length() - 4);
                } else {
                    strQueryWhere = "";
                }

                if ((((Vector) this.transformationsColumnNames).size() > 0))
                    queryTransformationSet = new QueryTransformationSet(
                            vecTableTableName.get(i).toString(),
                            (Vector) this.transformationsColumnNames.get(i),
                            (Vector) this.transformationsValueModes.get(i),
                            (Vector) this.transformationsColumnTypes.get(i),
                            configReaderTarget);

                // } //querySet+queryWhere
                String strQueryTarget = strQuerySet + strQueryWhere;
                String key = String.valueOf(i);
                Vector indexDommyValue = queryWhereSet.getIndexDummyValue();
                Vector indexDommyRelationValue = queryWhereSet
                        .getIndexDummyRelationValue();
                Vector indexDommyConstantValue = queryWhereSet
                        .getIndexDummyConstantValue();
                Vector indexDommyVariableValue = queryWhereSet
                        .getIndexDummyVariableValue();

                // ZK added this 28.4.2004 for transformations
                Vector indexDummyTransformationValue = queryWhereSet
                        .getTransformationKeyColumns();
                // ZK end
                queryStatement.put(key, strQueryTarget);
                indexDValue.put(key, indexDommyValue);
                indexDRelationValue.put(key, indexDommyRelationValue);
                indexConstantDValue.put(key, indexDommyConstantValue);
                indexDVariableValue.put(key, indexDommyVariableValue);
                // ZK added this 28.4.2004 for transformations
                indexDTransformationValue.put(key,
                        indexDummyTransformationValue);
                // end
                // query update
                String strUpdateTarget = queryUpdateSet.getQueryUpdate();
                Vector indexDommyOverwrite = queryUpdateSet
                        .getIndexDummyOverwrite();
                Vector indexDommySetNull = queryUpdateSet
                        .getIndexDummySetNull();

                updateStatement.put(key, strUpdateTarget);
                indexDOverwrite.put(key, indexDommyOverwrite);
                indexDSetNull.put(key, indexDommySetNull);

                // query update constant columns
                if (queryConstantSet != null) {
                    String strUpdateConstant = queryConstantSet
                            .getQueryConstant();
                    Vector indexConstantOver = queryConstantSet
                            .getIndexDummyOverwrite();
                    Vector indexConstantNull = queryConstantSet
                            .getIndexDummyNull();

                    updateConstantStatement.put(key, strUpdateConstant);
                    indexDConstantOver.put(key, indexConstantOver);
                    indexDConstantNull.put(key, indexConstantNull);
                }

                if (queryTransformationSet != null) {

                    String strUpdateTransformation = queryTransformationSet
                            .getQueryTransformation();
                    Vector indexTransformationOver = queryTransformationSet
                            .getIndexDummyOverwrite();
                    Vector indexTransformationNull = queryTransformationSet
                            .getIndexDummyNull();
                    Vector indexTransformationUpdate = queryTransformationSet
                            .getIndexDummyUpdate();

                    updateTransformationStatement.put(key,
                            strUpdateTransformation);
                    indexDTransformationOver.put(key, indexTransformationOver);
                    indexDTransformationNull.put(key, indexTransformationNull);
                    indexDTransformationUpdate.put(key,
                            indexTransformationUpdate);
                }
                // query insert row
                String strInsertRow = insertRowQuerySet.getStrQuery();
                Vector indexRelations = insertRowQuerySet
                        .getIndexDummyIsNotRelationsColumn();
                // prepare statement
                PreparedStatement pstmt = insertRowQuerySet
                        .getPreparedStatementForInsert();
                Vector pstmtCNames = insertRowQuerySet.getColumnNames();
                // Hashtable
                // pstmtCTypes=insertRowQuerySet.getPreparedStatemetTypes();

                // this vector keep tracking about key for prepareStmt...
                pstmtKeys.add(key);
                queryInsertRow.put(key, strInsertRow);
                indexIsNotRelationsColumns.put(key, indexRelations);
                pstmtForInsert.put(key, pstmt);
                pstmtColumnNames.put(key, pstmtCNames);
                // pstmtColumnTypes.put(key,pstmtCTypes);
            }

            String strQuery = "";
            // if we have select statement insted of table name
            if (importDefinitionElement.strImportDefinitionSelectStatement != null
                    && !importDefinitionElement.strImportDefinitionSelectStatement
                            .equals("")) {
                strQuery = importDefinitionElement.strImportDefinitionSelectStatement;
                // strQuery = this.replaceInSelectStatement(strQuery);
                // TODO Allow different order of columns which should be
                // transformed
                // this part is for determine where columns for transformation
                // are started in
                // source result set
                // In selectStatement, columns for transformation should be on
                // the end, and they must
                // be in order same as in sourceColumn tags in all
                // transformations.
//                if (this.transformations.getTransformations().size() > 0) {
//                    SqlParser parser = new SqlParser();
//                    try {
//                        parser.parse(strQuery);
//                    } catch (Throwable e) {
//                        this.logger
//                                .write(
//                                        "full",
//                                        "Unable to parse sql query from 'selectStatement' attribute. This is needed by transformations if they exists.");
//                    }
//                    String[] columnNames = parser.getColumnNames();
//                    List allSourceColNames = this.transformations
//                            .getAllTransformationSourceColNames();
//                    for (int br1 = 0; br1 < columnNames.length; br1++) {
//                        for (int br2 = 0; br2 < allSourceColNames.size(); br2++) {
//                            if (allSourceColNames.get(br2).toString()
//                                    .toUpperCase().equals(columnNames[br1]))
//                                this.iOffsetForTransColumns = br1;
//                            break;
//                        }
//                    }
//                }

                if (!configReaderSource.getReadingOrderRelevant()) {
                    int in = 0;
                    int jn = 0;
                    Vector vecVector = new Vector();
                    while (in < this.iTables) {
                        vecVector = (Vector) this.vecSourceColumnName.get(in);
                        while (jn < Integer
                                .parseInt(this.vecValueColumnsTargetTables.get(
                                        in).toString())) {
                            jn++;
                            this.iColumnsInSourceTable++;
                        }
                        jn = 0;
                        in++;
                    }
                }
            } else {
                // when table name is defined
                strQuery = this.querySource();
            }

            if (strQuery.indexOf("order by") != -1) {
                if (checkSortColumns(connSource)) {
                    this.logger
                            .write("normal",
                                    "Error : Sort columns have more rows with equals values.");
                    LoaderException le = new LoaderException(
                            "SQLException: ",
                            (Throwable) (new SQLException(
                                    "Error : Sort columns have more rows with equals values.")));
                    this.logger.write("full", le.getStackTraceAsString());
                    throw le;
                }
            }

            ResultSet rsetSource = null;
            int blockNumber = 0;
            boolean usingSelectStmt = false;
            if (importDefinitionElement.strImportDefinitionSelectStatement != null
                    && !importDefinitionElement.strImportDefinitionSelectStatement
                            .equals("")) {
                usingSelectStmt = true;
            } else {
                if (configReaderSource.getRowCountEnabled()) {
                    String countSQL = " select count(*) as \"counter\" from "
                            + importDefinitionElement.strImportDefinitionTableName;
                    Statement stmtSourceCount = connSource.createStatement();
                    ResultSet rsetSourceCount = stmtSourceCount
                            .executeQuery(countSQL);
                    rsetSourceCount.next();
                    iRowNumber = rsetSourceCount.getInt("counter");
                    blockNumber = iRowNumber
                            / importDefinitionElement.iImportDefinitionCommitCount
                            + 1;
                    rsetSourceCount.close();
                    stmtSourceCount.close();
                }
            }
            iRowNumber = 0;

            // set the number of rows in result set
            // setCursorName
            boolean setCursorName = false;
            if (!importDefinitionElement.setCursorNameID.equalsIgnoreCase(""))
                setCursorName = new Boolean(
                        importDefinitionElement.setCursorNameID).booleanValue();
            else
                setCursorName = configReaderSource.getSetCursorNameEnabled();

            if (setCursorName) {
                long cursorName = System.currentTimeMillis();
                stmtSource.setCursorName(String.valueOf(cursorName));
            }
            // setFetchSize
            boolean setFetchSize = false;
            if (!importDefinitionElement.setFetchSizeID.equalsIgnoreCase(""))
                setFetchSize = new Boolean(
                        importDefinitionElement.setFetchSizeID).booleanValue();
            else
                setFetchSize = configReaderSource.getSetFetchSizeEnabled();

            if (setFetchSize)
                stmtSource
                        .setFetchSize(importDefinitionElement.iImportDefinitionCommitCount);

            this.logger.write("full", "\tQuery '" + strQuery
                    + "' will be executed");
            rsetSource = stmtSource.executeQuery(strQuery);

            // this parameter defines if restartCounter has seccessfuly ended
            boolean main = true;
            if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
                if (this.hasRestartCounter) {
                    bdecCounter = dataTransmition.checkDataTransmition(
                            connTarget, rsetSource, this.currentJobName,
                            configReaderTarget.getFirstColumnResult());

                    if (bdecCounter != null) {
                        if (bdecCounter.toString().equalsIgnoreCase("0")) {
                            // if is mycounter=0 in myrestart table escape this
                            // importdefinition
                            main = false;
                        }
                    } else {
                        bdecCounter = new BigDecimal(0);
                    }
                }
                if (!bdecCounter.toString().equalsIgnoreCase("0")) {
//                    int num1 = Integer.parseInt(bdecCounter.toString());
//                    int num2 = Integer.parseInt(this.bdecOidNumber.toString());
//                    this.bdecOidNumber = new BigDecimal(num1 + num2);
                    this.bdecOidNumber = bdecCounter.add(this.bdecOidNumber);
                }
            }

            while (main) {
                boolean isEndFlag = false;
                this.logger.write("normal", "Import block is started.");
                currentBlock++;
                if (configReaderSource.getRowCountEnabled()) {
                    if (!usingSelectStmt)
                        this.logger.write("normal", "Working...  "
                                + currentBlock + ". block of " + blockNumber);
                    else
                        this.logger.write("normal", "Working...  "
                                + currentBlock + ". block");
                } else
                    this.logger.write("normal", "Working...  " + currentBlock
                            + ". block");
                this.logger.write("full", "\tStarted from the "
                        + bdecCounter.add(new BigDecimal(1)).toString()
                        + ". row.");
                int bdecRowCount = 0;
                while (iRowNumber < importDefinitionElement.iImportDefinitionCommitCount) {
                    if (!rsetSource.next()) {
                        isEndFlag = true;
                        break;
                    }
                    currentRow = iRowNumber;
                    boolean readingOrderRelevant = false;
                    if (configReaderSource.getReadingOrderRelevant())
                        readingOrderRelevant = true;

                    for (int i = 0; i < this.iTables; i++) {
                        Vector vecVektor = new Vector();
                        this.vecBlobVector.clear();

                        // only for microsoft driver
                        Hashtable orderRelevantColumnValues = new Hashtable();
                        Hashtable sourceColumnTypes = new Hashtable();
                        if (readingOrderRelevant) {
                            int orderRelevantColumnCount = rsetSource
                                    .getMetaData().getColumnCount();
                            for (int j = 1; j < orderRelevantColumnCount + 1; j++) {
                                String orderRelevantColumnName = rsetSource
                                        .getMetaData().getColumnName(j);
                                orderRelevantColumnName = orderRelevantColumnName
                                        .toUpperCase();
                                Object orderRelevantColumnValue;
                                if (configReaderSource.isDate(rsetSource
                                        .getMetaData().getColumnTypeName(j))) {
                                  // senka 27.12.2006 changed getData to getTimestamp
                                    orderRelevantColumnValue = rsetSource
                                          .getTimestamp(j);                                  
                                } else if (configReaderSource
                                        .isBinaryObject(rsetSource
                                                .getMetaData()
                                                .getColumnTypeName(j))) {
                                    orderRelevantColumnValue = rsetSource
                                            .getBytes(j);
                                } else {
                                    orderRelevantColumnValue = rsetSource
                                            .getString(j);
                                }
                                if (orderRelevantColumnValue == null) {
                                    orderRelevantColumnValues.put(
                                            orderRelevantColumnName, "null");
                                } else {
                                    orderRelevantColumnValues.put(
                                            orderRelevantColumnName,
                                            orderRelevantColumnValue);
                                }
                                // senka 27.12.2006 added to resolve problem with sourceColumnTypes for microsoft driver
                                // put type of column
                                sourceColumnTypes.put(orderRelevantColumnName,rsetSource.getMetaData().getColumnTypeName(j));
                                this.logger
                                        .write(
                                                "normal",
                                                "\torderRelevantColumnTypes.put(orderRelevantColumnName, rsetSource.getMetaData().getColumnTypeName(j));");
                                // orderRelevantColumnTypes.put(orderRelevantColumnName,
                                // rsetSource.getMetaData().getColumnTypeName(j));
                            }
                        }
                        // Read data from source
                        // selectStatement=XXX
                        if (importDefinitionElement.strImportDefinitionSelectStatement != null
                                && !importDefinitionElement.strImportDefinitionSelectStatement
                                        .equals("")) {
                            // for value columns
                            Vector srcNames = new Vector();
                            srcNames = (Vector) this.vecSourceColumnName.get(i);
                            Object readValue = "";
                            for (int s = 0; s < srcNames.size(); s++) {
                                if (srcNames.get(s) != null) {
                                    String columnName = srcNames.get(s)
                                            .toString();
                                    if (!readingOrderRelevant) {
                                        readValue = rsetSource
                                                .getString(columnName);
                                        // since types are not filled, fill it
                                        // now
                                        int colIndex = rsetSource
                                                .findColumn(columnName);
                                        sourceColumnTypes.put(
                                                columnName, rsetSource
                                                        .getMetaData()
                                                        .getColumnTypeName(
                                                                colIndex));
                                    } else {
                                        columnName = columnName.toUpperCase();
                                        // TODO Should readValue be String or
                                        // Object
                                        readValue = orderRelevantColumnValues
                                                .get(columnName);
                                        // .toString()
                                        ;
                                    }
                                    parseInputData(readValue, vecVektor,
                                            rsetSource, i, columnName, s + 1,
                                            readingOrderRelevant,
                                            orderRelevantColumnValues,
                                            sourceColumnTypes);
                                }
                            }
                            // orderRelevantColumnValues.clear();
                            // for transformations
                            this.transformationValues.clear();
                            List allSrcCls = this.transformations.getAllTransformationSourceColNames();
                            for (int j = 0; j < allSrcCls.size(); j++) {
                                Object value = "";
                                String columnName = (String)allSrcCls.get(j);
                                if (!readingOrderRelevant) {
                                        sourceColumnTypes.put(
                                                columnName, rsetSource
                                                        .getMetaData()
                                                        .getColumnTypeName(rsetSource.findColumn(columnName)));
                                        value = rsetSource.getString(columnName);
                                } else {
                                    columnName = columnName.toUpperCase();
                                    value = orderRelevantColumnValues
                                            .get(columnName);
                                }
                                this.transformationValues.add(value);
                            }
                            orderRelevantColumnValues.clear();
                        } else {
                            // When tableName is defined, tableName=XXX
                            // skip previous tables
                            int iCounterCol = 0;
                            for (int m = 0; m < i; m++) {
                                iCounterCol = iCounterCol
                                        + Integer
                                                .parseInt(this.vecValueColumnsTargetTables
                                                        .get(m).toString())
                                // +
                                // Integer.parseInt(this.vecTransformColumnsTargetTables.get(m).toString())
                                ;
                            }
                            iCounterCol++;
                            // for value columns
                            for (int j = iCounterCol; j < (iCounterCol + Integer
                                    .parseInt(this.vecValueColumnsTargetTables
                                            .get(i).toString())
                            // +
                            // Integer.parseInt(this.vecTransformColumnsTargetTables.get(i).toString())
                            ); j++) {
                                String readValue = "";
                                String columnName = rsetSource.getMetaData()
                                        .getColumnName(j);
                                if (!readingOrderRelevant) {
                                    if (this.iFirstColumnResult == 0) {
                                        readValue = rsetSource.getString(j - 1);
                                        sourceColumnTypes.put(
                                                columnName, rsetSource
                                                        .getMetaData()
                                                        .getColumnTypeName(
                                                                j - 1));
                                    } else {
                                        readValue = rsetSource.getString(j);
                                        sourceColumnTypes.put(
                                                columnName, rsetSource
                                                .getMetaData()
                                                .getColumnTypeName(
                                                        j));
                                    }
                                } else {
                                    columnName = columnName.toUpperCase();
                                    readValue = orderRelevantColumnValues.get(
                                            columnName).toString();
                                }
                                parseInputData(readValue, vecVektor,
                                        rsetSource, i, columnName, j
                                                - iCounterCol + 1,
                                        readingOrderRelevant,
                                        orderRelevantColumnValues,
                                        sourceColumnTypes);
                            }
                            // for transformations
                            this.transformationValues.clear();
                            List allSrcCls = this.transformations.getAllTransformationSourceColNames();
                            for (int j = 0; j < allSrcCls.size(); j++) {
                                Object value = "";
                                String columnName = (String)allSrcCls.get(j);
                                if (!readingOrderRelevant) {
                                    value = rsetSource.getString(columnName);
                                } else {
                                    value = orderRelevantColumnValues
                                            .get(columnName.toUpperCase());
                                }
                                this.transformationValues.add(value);
                            }
                        }
                        for (int l = 0; l < this.vecVariableUseIDTableName
                                .size(); l++) {
                            if (this.vecTableTableName.get(i).toString()
                                    .equalsIgnoreCase(
                                            this.vecVariableUseIDTableName.get(
                                                    l).toString())
                                    && this.vecVariableUseIDTableID.get(l)
                                            .toString().equalsIgnoreCase(
                                                    this.vecTableTableID.get(i)
                                                            .toString()))
                                vecVektor.add(this.strUserID);
                        }
                        Vector transformedValues = new Vector();
                        Vector resultVectorTypes = new Vector();
                        List trans = this.transformations.getTransformations();
                        Vector vecTransformedValues = new Vector();
                        Vector pomResultVectorTypes = new Vector();
                        String tableId = this.vecTableTableID.get(i).toString();
                        List transTableIDs = this.transformations
                                .getTransformationsTableIDs();
                        if (transTableIDs.contains(tableId)) {
                            this.logger.write("full",
                                    "\ttransformation of values is started");
                            int offset = 0;
                            for (int j = 0; j < trans.size(); j++) {
                                Transformation transformation = (Transformation) trans
                                        .get(j);
                                Vector sourceColumnNames = transformation
                                        .getSourceColumnNames();
                                Vector valuesForTrans = new Vector();
                                for (int n = offset; n < offset
                                        + sourceColumnNames.size(); n++) {
                                    valuesForTrans
                                            .add(this.transformationValues
                                                    .elementAt(n));
                                }
                                offset += sourceColumnNames.size();
                                vecTransformedValues = transformation
                                        .transformValues(valuesForTrans);
                    // senka 22.08.2007  changed i-->Integer.parseInt(tableId)
                                //pomResultVectorTypes = transformation
                                //        .getOrderedTargetColumnTypes(i);
                  pomResultVectorTypes = transformation
                                       .getOrderedTargetColumnTypes(Integer.parseInt(tableId));      
                                if (vecTransformedValues != null) {
                                    for (int m = 0; m < vecTransformedValues
                                            .size(); m++) {
                                        // use only values and types for
                                        // specified logic table
                                        if (pomResultVectorTypes.get(m) == null)
                                            continue;
                                        transformedValues
                                                .add(vecTransformedValues
                                                        .get(m));
                                        resultVectorTypes
                                                .add(pomResultVectorTypes
                                                        .get(m).toString());
                                    }
                                }
                            }
                            this.logger.write("full",
                                    "\ttransformation of values is finished");
                        }

                        // insert row into target logic table
                        this.insertTargetTable(i, vecVektor,
                                (Vector) this.vecTargetColumnName.get(i),
                                (Vector) this.vecValueMode.get(i),
                                (Vector) this.vecTargetColumnType.get(i),
                                connTarget, transformedValues,
                                resultVectorTypes);

                    }
                    iRowNumber++;
                }
                // restart counter table
                if (!importDefinitionElement.strRestartCounterTableName
                        .equals("")) {
                    if (this.hasRestartCounter) {
                        bdecCounter = bdecCounter
                                .add(new BigDecimal(iRowNumber));
                        dataTransmition.insertCounter(this.currentJobName,
                                bdecCounter, connTarget);
                    }
                }

                if (this.hasRestartCounter) {
                    // TODO THIS IS WRITE PLACE:ZK added this for update of
                    // counterColumns. This will update values in CounterTable
                    // for this import job.
                    // this.counterColumns.updateCounter(this.htValuesForCounterColumns,
                    // connTarget);
                    this.counterColumns.updateCounter(connTarget);
                    connTarget.commit();
                    this.logger.write("normal", "Imported block is commited.");
                    this.logger.write("full", Integer.toString(iRowNumber)
                            + " rows are commited.");
                }
                iRowNumber = 0;
                if (isEndFlag == true)
                    break;
            }// End of while(main)

            rsetSource.close();
            stmtSource.close();
            connSource.close();

            if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
                if (this.hasRestartCounter) {
                    dataTransmition.resetRestartCounter(connTarget,
                            this.currentJobName);
                }
            }
            // TODO ZK added this for update of counterColumns. This will update
            // values in CounterTable for every importDefinition.
            if (!this.hasRestartCounter) {
                this.counterColumns.updateCounter(connTarget);
            }
            // end
            currentDate = new Date();
            dfNow = DateFormat.getDateTimeInstance();
            this.logger.write("normal", "Import definition "
                    + importDefinitionElement.strImportDefinitionName
                    + " is finished at " + dfNow.format(currentDate) + ".");
            this.logger.write("normal", " Duration of importDefinition:"
                    + this.timeCounter.getJobTime());
        }

        catch (Exception e) {
            try {
                if (connSource != null)
                    connSource.close();
            } catch (Exception ex) {
                this.logger.write("normal", "\t" + ex.getMessage());
            }
            String msq = "Error: In import job '"
                    + importDefinitionElement.strImportDefinitionName + "', "
                    + "some error has occured:";
            this.logger.write("normal", "\t" + msq);
            LoaderException le = new LoaderException("Exception:"
                    + e.getMessage(), (Throwable) e);
            this.logger.write("full", "\t" + le.getStackTraceAsString());

            throw le;
        } finally {
            try {

                this.logger.write("full", "loadSource method is finished.");
                if (connSource != null && !connSource.isClosed())
                    connSource.close();
            } catch (SQLException e) {
                LoaderException le = new LoaderException("SQLException: ",
                        (Throwable) e);
                // this.logger.write("normal", le.getCause().toString());
                this.logger.write("full", le.getStackTraceAsString());
                throw le;
            }
        }
    }

    /**
     * This method read data from source table
     * 
     * @param readValue
     *            is data value which is reed
     * @param vecVektor
     *            defines vector
     * @param rsetSource
     *            defines ResultSet object
     * @param i
     *            is interger
     * @param columnName
     *            defines source column name
     * @param blobCount
     *            defines counter for blob object
     * @param isMicrosoftDriver
     *            defines if we use microsoft driver
     * @param columnValuesMicrosoft
     *            defines column values which is read with microsoft driver
     */
    public void parseInputData(Object readValueObject, Vector vecVektor,
            ResultSet rsetSource, int i, String columnName, int blobCount,
            boolean isMicrosoftDriver, Hashtable columnValuesMicrosoft,
            Hashtable sourceColumnTypes) throws LoaderException {
        try {
            String readValue = "";
            if (readValueObject instanceof String)
                readValue = (String) readValueObject;
            else
                readValue = readValueObject != null ? readValueObject
                        .toString() : "null";

            if (readValue == null
                    || readValue.toString().equalsIgnoreCase("null")) {
                vecVektor.add(null);
            } else if (readValue.toString().equalsIgnoreCase("")) {
                if (configReaderTarget.getSetEmptyStringAsNull())
                    vecVektor.add(null);
                else
                    vecVektor.add("");
            } else {
                // int indexOld = (
                // (Vector)this.vecTargetColumnName.get(i)).indexOf(columnName);
                int index = blobCount - 1;
                // if (index == -1) {
                // if (readValue.indexOf("'") != -1)
                // readValue = replaceChar(readValue, '\'', "\'\'");
                // vecVektor.add(readValue);
                // } else {
                byte[] blob;

                String columnTypeTarget = ((Vector) this.vecTargetColumnType
                        .get(i)).get(index).toString();

                String columnTypeSource = sourceColumnTypes.get(columnName)
                        .toString();

                String mode = ((Vector) this.vecValueMode.get(i)).get(index)
                        .toString();
                String toHex = ((Vector) this.vecToHex.get(i)).get(index)
                        .toString();
                String fromHex = ((Vector) this.vecFromHex.get(i)).get(index)
                        .toString();
                String blobObjectName = "binaryObject" + blobCount;

                if (toHex.equalsIgnoreCase("true")
                        && !fromHex.equalsIgnoreCase("true")) {
                    if (isMicrosoftDriver)
                        blob = (byte[]) columnValuesMicrosoft.get(columnName);
                    else
                        blob = rsetSource.getBytes(columnName);

                    String toHexString = ToAndFromHex.getStringFromBlob(blob);
                    vecVektor.add(toHexString);
                } else if (fromHex.equalsIgnoreCase("true")
                        && !toHex.equalsIgnoreCase("true")) {
                    // ZK change this 7.5.2004 from CheckType to
                    // configReaderTarget
                    if (configReaderTarget.isBinaryObject(columnTypeTarget)) {
                        // if (javaTypeInt==1) {
                        byte[] newBlob = ToAndFromHex
                                .getByteArrayFromString(readValue.toString());
                        if (mode.equalsIgnoreCase("Update")) {
                            this.vecBlobVector.add(columnName);
                            this.vecBlobVector.add(newBlob);
                            this.vecBlobVector.add(" where " + columnName
                                    + " is null and ");
                            this.vecBlobVector.add(mode);
                            this.vecBlobVector.add(blobObjectName);
                            vecVektor.add(blobObjectName);
                        } else {
                            this.vecBlobVector.add(columnName);
                            this.vecBlobVector.add(newBlob);
                            this.vecBlobVector.add(null);
                            this.vecBlobVector.add(mode);
                            this.vecBlobVector.add(blobObjectName);
                            vecVektor.add(blobObjectName);
                        }
                    } else {
                        if (readValue.toString().indexOf("'") != -1)
                            readValue = replaceChar(readValue, '\'', "\'\'");
                        vecVektor.add(readValue);
                    }
                } else {
                    // ZK change this 7.5.2004 from CheckType to
                    // configReaderSource
                    if (configReaderTarget.isBinaryObject(columnTypeTarget)) {
                        // if (javaTypeInt==1) {
                        if (isMicrosoftDriver)
                            blob = (byte[]) columnValuesMicrosoft
                                    .get(columnName);
                        else
                            blob = rsetSource.getBytes(columnName);
                        if (mode.equalsIgnoreCase("Update")) {
                            this.vecBlobVector.add(columnName);
                            this.vecBlobVector.add(blob);
                            this.vecBlobVector.add(" where " + columnName
                                    + " is null and ");
                            this.vecBlobVector.add(mode);
                            this.vecBlobVector.add(blobObjectName);
                            vecVektor.add(blobObjectName);
                        } else {
                            this.vecBlobVector.add(columnName);
                            this.vecBlobVector.add(blob);
                            this.vecBlobVector.add(null);
                            this.vecBlobVector.add(mode);
                            this.vecBlobVector.add(blobObjectName);
                            vecVektor.add(blobObjectName);
                        }
                    }
                    else if (configReaderSource.isDate(columnTypeSource)) { 

                        Date tmpDate = null;
                        // Senka 27.12.2006 , separated Date and Timestamp columns 
                        if (isMicrosoftDriver){
                          if (columnValuesMicrosoft.get(columnName).toString().length()>10)
                                tmpDate = (java.sql.Timestamp) columnValuesMicrosoft
                                    .get(columnName);
                          else
                            tmpDate = (java.sql.Date) columnValuesMicrosoft
                                .get(columnName);  
                          
                        }else{ 
                          if (rsetSource.getObject(columnName).toString().length()>10)
                           tmpDate = rsetSource.getTimestamp(columnName);
                          else
                             tmpDate= rsetSource.getDate(columnName);    
                        }   
                        if (!configReaderTarget.isDate(columnTypeTarget)) {
                          String format = this.configReaderTarget.getDateFormat();
                          SimpleDateFormat formatDate = new SimpleDateFormat(format);
                          vecVektor.add(formatDate.format(tmpDate));
                        } else {
                            vecVektor.add(tmpDate);
                        }
                    }
                    else {
                        if (readValue.indexOf("'") != -1)
                            readValue = replaceChar(readValue, '\'', "\'\'");
                        vecVektor.add(readValue);
                    }
                }
            }
            // }
        } catch (Exception ex) {
            LoaderException le = new LoaderException(
                    "Error in parseInputData.", ex);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
    }

    /**
     * Method parseImportJOB is used to analyse import XML file about
     * ImportDefinitions tags. Return number of importDefinition elements in
     * whole xml file.
     * 
     * @param inStream
     *            Data from inputXML file which is converted into InputStream.
     * @return Number of ImportDefinitions tags in an input XML file.
     * @throws LoaderException
     */
    private int parseImportJob(InputStream inStream) throws LoaderException {
        int iNumTagsImportJob = 0;
        Document doc = null;
        this.logger.write("full", "\tparseImportJob method is started.");
        try {

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = null;
            db = dbf.newDocumentBuilder();
            doc = db.parse(inStream);
        } catch (Exception e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("Exception: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        if (doc != null) {
            NodeList tagBasic = doc.getElementsByTagName("importDefinition");
            iNumTagsImportJob = tagBasic.getLength();
            Vector vecNames = new Vector();
            String strName = "";
            for (int i = 0; i < iNumTagsImportJob; i++) {
                strName = new String("");
                strName = OctopusXMLUtil.importAttributeValue(doc,
                        "importDefinition", "name", i);
                for (int j = 0; j < vecNames.size(); j++) {
                    if (strName.equals("")) {
                        this.logger
                                .write("normal",
                                        "Sorry, an error occurred: No importDefinition name .");
                        LoaderException le = new LoaderException(
                                "Exception: ",
                                (Throwable) (new Exception(
                                        "Sorry, an error occurred: No importDefinition name .")));
                        this.logger.write("full", le.getStackTraceAsString());
                        throw le;
                    }
                    if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
                        this.logger.write("normal",
                                "Sorry, an error occurred: More importDefinition with same name :"
                                        + strName);
                        LoaderException le = new LoaderException(
                                "Exception: ",
                                (Throwable) (new Exception(
                                        "Sorry, an error occurred: More importDefinition with same name :")));
                        this.logger.write("full", le.getStackTraceAsString());
                        throw le;
                    }
                }
                vecNames.addElement(strName);
            }
        }
        try {
            inStream.reset();
        } catch (IOException e) {
            // this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("IOException: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        this.logger.write("full", "\tparseImportJob method is finished.");
        return iNumTagsImportJob;
    }

    /**
     * Method parseCopyTable is used to analyse import XML file about copyTable
     * tags. Return number of copyTable elements in whole xml file.
     * 
     * @param inStream
     *            Data from inputXML file which is converted into InputStream.
     * @return Number of iNumTagsCopyTable tags in an input XML file.
     * @throws LoaderException
     */

    private int parseCopyTable(InputStream inStream) throws LoaderException {
        int iNumTagsCopyTable = 0;
        Document doc = null;
        this.logger.write("full", "\tparseCopyTable method is started.");
        try {

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = null;
            db = dbf.newDocumentBuilder();
            doc = db.parse(inStream);
        } catch (Exception e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("Exception: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        if (doc != null) {
            NodeList tagCopyTable = doc.getElementsByTagName("copyTable");
            iNumTagsCopyTable = tagCopyTable.getLength();
            Vector vecNames = new Vector();
            String strName = "";
            for (int i = 0; i < iNumTagsCopyTable; i++) {
                strName = new String("");
                strName = OctopusXMLUtil.importAttributeValue(doc, "copyTable",
                        "name", i);
                for (int j = 0; j < vecNames.size(); j++) {
                    if (strName.equals("")) {
                        this.logger
                                .write("normal",
                                        "Sorry, an error occurred: No copyTable name .");
                        LoaderException le = new LoaderException(
                                "Exception: ",
                                (Throwable) (new Exception(
                                        "Sorry, an error occurred: No copyTable name .")));
                        this.logger.write("full", le.getStackTraceAsString());
                        throw le;
                    }
                    if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
                        this.logger.write("normal",
                                "Sorry, an error occurred: More copyTable with same name :"
                                        + strName);
                        LoaderException le = new LoaderException(
                                "Exception: ",
                                (Throwable) (new Exception(
                                        "Sorry, an error occurred: More copyTable with same name :")));
                        this.logger.write("full", le.getStackTraceAsString());
                        throw le;
                    }
                }
                vecNames.addElement(strName);
            }
        }
        try {
            inStream.reset();
        } catch (IOException e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("IOException: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        this.logger.write("full", "\tparseImportJob method is finished.");
        return iNumTagsCopyTable;
    }

    /**
     * Method parseEchoElement is used to analyse import XML file about echo
     * tags. Return number of echo elements in a whole xml input file.
     * 
     * @param inStream
     *            Data from inputXML file which is converted into InputStream.
     * @return Number of echo tags in an input XML file.
     * @throws LoaderException
     */
    private int parseEcho(InputStream inStream) throws LoaderException {
        int iNumTagsEcho = 0;
        Document doc = null;
        this.logger.write("full", "\tparseEcho method is started.");
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = null;
            db = dbf.newDocumentBuilder();
            doc = db.parse(inStream);
        } catch (Exception e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("Exception: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        if (doc != null) {
            NodeList tagBasic = doc.getElementsByTagName("echo");
            iNumTagsEcho = tagBasic.getLength();
            String strMessage = "";
            for (int i = 0; i < iNumTagsEcho; i++) {
                strMessage = new String("");
                strMessage = OctopusXMLUtil.importAttributeValue(doc, "echo",
                        "message", i);
                if (strMessage != null)
                    logger.setMessage((new Integer(i)).toString(), strMessage);
            }
        }
        try {
            inStream.reset();
        } catch (IOException e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("IOxception: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
            // System.exit(1);
        }
        this.logger.write("full", "\tparseSql method is finished.");
        return iNumTagsEcho;
    }

    /**
     * Method parseMainElements is used to analyse import XML file about main
     * elements (sql and importDefinition). Puts names of elements (sql or
     * importDefinition) in Vector.
     * 
     * @param inStream
     *            Data from inputXML file which is converted into InputStream.
     * @return Vector which elements are names of main elements in the same
     *         order as in XML import file .
     * @throws LoaderException
     */
    private Vector parseMainElements(InputStream inStream)
            throws LoaderException {

        Vector vecLoaderElements = new Vector();
        Vector vecLoaderNamesOfElements = new Vector();

        Document doc = null;
        this.logger.write("full", "\tparseMainElements method is started.");
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = null;
            db = dbf.newDocumentBuilder();
            doc = db.parse(inStream);
        } catch (Exception e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("Exception: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        if (doc != null) {
            NodeList tagBasic = doc.getElementsByTagName("loaderJob");
            NodeList nlMainElements = tagBasic.item(0).getChildNodes();
            for (int i = 0; i < nlMainElements.getLength(); i++) {
                String strTagName = nlMainElements.item(i).getNodeName();
                if (strTagName.equalsIgnoreCase("sql")
                        || strTagName.equalsIgnoreCase("importDefinition")
                        || strTagName.equalsIgnoreCase("echo")
                        || strTagName.equalsIgnoreCase("copyTable"))
                    if (nlMainElements.item(i).getNodeType() == Node.ELEMENT_NODE) {
                        String strTagJobName = (((Element) nlMainElements
                                .item(i)).getAttribute("name"));
                        String strLogMode = (((Element) nlMainElements.item(i))
                                .getAttribute("logMode"));
                        vecLoaderElements.addElement(strTagName);
                        this.logModes.add(strLogMode);
                        boolean addJobName = true;
                        if (!strTagJobName.equalsIgnoreCase("")) {
                            for (int j = 0; j < vecLoaderNamesOfElements.size(); j++) {
                                if (strTagJobName
                                        .equalsIgnoreCase(vecLoaderNamesOfElements
                                                .get(j).toString())) {
                                    addJobName = false;
                                    break;
                                }
                            }
                            if (addJobName) {
                                vecLoaderNamesOfElements.add(strTagJobName);
                            } else {
                                String msg = "Sorry, an error occurred: More import jobs with same name :"
                                        + strTagJobName;
                                LoaderException le = new LoaderException(
                                        "Exception:", new Exception(msg));

                                throw le;
                            }
                        }
                    }
            }
        }
        try {
            inStream.reset();
        } catch (IOException e) {
            this.logger.write("normal", "Sorry, an error occurred: "
                    + e.getMessage());
            LoaderException le = new LoaderException("IOException: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        this.logger.write("full", "\tparseMainElements method is finished.");
        return vecLoaderElements;
    }

    /**
     * Method importRestartCounter is used to analyse import XML file and read
     * restart counter attributes. Values of these attributes puts in Vectors
     * 
     * @param inStream
     *            Data from inputXML file which is converted into InputStream.
     * @throws LoaderException
     */
    private void importRestartCounter(InputStream inStream)
            throws LoaderException {
        Document doc = null;
        this.logger.write("full", "\timportRestartCounter method is started.");
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = null;
            db = dbf.newDocumentBuilder();
            doc = db.parse(inStream);
        } catch (Exception e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("Exception: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
            // System.exit(1);
        }
        if (doc != null) {
            NodeList tagRestartCounter = doc
                    .getElementsByTagName("restartCounter");
            if (tagRestartCounter.getLength() != 0) {
                this.hasRestartCounter = true;
                NamedNodeMap attrs = tagRestartCounter.item(0).getAttributes();
                Node nodeResult = attrs.getNamedItem("tableName");
                if (nodeResult != null)
                    importDefinitionElement.strRestartCounterTableName = nodeResult
                            .getNodeValue();
                else
                    importDefinitionElement.strRestartCounterTableName = "LOADERRESTART";
                nodeResult = attrs.getNamedItem("importDefinitionColumnName");
                if (nodeResult != null)
                    importDefinitionElement.strRestartCounterImportDefinitionName = nodeResult
                            .getNodeValue();
                else
                    importDefinitionElement.strRestartCounterImportDefinitionName = "IMPORTDEFINITION";
                nodeResult = attrs.getNamedItem("restartCounterColumnName");
                if (nodeResult != null)
                    importDefinitionElement.strRestartCounterValue = nodeResult
                            .getNodeValue();
                else
                    importDefinitionElement.strRestartCounterValue = "RESTARTCOUNTER";
                nodeResult = attrs.getNamedItem("restartAutoCreate");
                if (nodeResult != null)
                    importDefinitionElement.bRestartAutoCreate = (new Boolean(
                            nodeResult.getNodeValue())).booleanValue();
                else
                    importDefinitionElement.bRestartAutoCreate = false;
            }
        }
        try {
            inStream.reset();
        } catch (IOException e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("IOException: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
            // System.exit(1);
        }
        this.logger.write("full", "\timportRestartCounter method is finished.");
    }

    /**
     * Method importVariable imports sql attributes from xml file and puts them
     * in the global variables. Return Vector. It's elements are strings which
     * represents sql statements.
     * 
     * @param inStream
     *            Data from inputXML file which is converted into InputStream.
     * @throws LoaderException
     */
    private void importVariable(InputStream inStream) throws LoaderException {
        Document doc = null;
        String strNodeValue = "";
        String strDefaultVariableOverride = "";
        String strDefaultReplaceInConstants = "";
        String strDefaultReplaceInSQL = "";
        String strDefaultReplaceInData = "";
        String strDefaultReplaceInJDBC = "";
        String strDefaultVariablePrefix = "";
        String strDefaultVariableSufix = "";
        this.logger.write("full", "\timportVariable  method is started.");
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = null;
            db = dbf.newDocumentBuilder();
            doc = db.parse(inStream);
            if (doc != null) {
                NodeList tagBasic = doc.getElementsByTagName("variables");
                if (tagBasic.getLength() != 0) {
                    Element docFragment = (Element) tagBasic.item(0);
                    strDefaultVariablePrefix = docFragment
                            .getAttribute("prefix");
                    if (strDefaultVariablePrefix.equals(""))
                        strDefaultVariablePrefix = "%";
                    strDefaultVariableSufix = docFragment
                            .getAttribute("suffix");
                    if (strDefaultVariableSufix.equals(""))
                        strDefaultVariableSufix = "%";
                    strDefaultVariableOverride = docFragment
                            .getAttribute("override");
                    if (strDefaultVariableOverride.equals(""))
                        strDefaultVariableOverride = "true";
                    strDefaultReplaceInConstants = docFragment
                            .getAttribute("replaceInConstants");
                    if (strDefaultReplaceInConstants.equals(""))
                        strDefaultReplaceInConstants = "false";
                    strDefaultReplaceInSQL = docFragment
                            .getAttribute("replaceInSQL");
                    if (strDefaultReplaceInSQL.equals(""))
                        strDefaultReplaceInSQL = "false";
                    strDefaultReplaceInData = docFragment
                            .getAttribute("replaceInData");
                    if (strDefaultReplaceInData.equals(""))
                        strDefaultReplaceInData = "false";
                    strDefaultReplaceInJDBC = docFragment
                            .getAttribute("replaceInJDBC");
                    if (strDefaultReplaceInJDBC.equals(""))
                        strDefaultReplaceInJDBC = "false";
                    NodeList tag = docFragment.getElementsByTagName("variable");
                    this.vecVariableName = OctopusXMLUtil.getAttributeValues(
                            tag, "name", null);
                    this.vecVariableValue = OctopusXMLUtil.getAttributeValues(
                            tag, "value", null);
                    this.vecVariablePrefix = OctopusXMLUtil.getAttributeValues(
                            tag, "prefix", strDefaultVariablePrefix);
                    this.vecVariableSufix = OctopusXMLUtil.getAttributeValues(
                            tag, "suffix", strDefaultVariableSufix);
                    this.vecVariableOverride = OctopusXMLUtil
                            .getAttributeValues(tag, "override",
                                    strDefaultVariableOverride);
                    this.vecReplaceInConstants = OctopusXMLUtil
                            .getAttributeValues(tag, "replaceInConstants",
                                    strDefaultReplaceInConstants);
                    this.vecReplaceInSQL = OctopusXMLUtil.getAttributeValues(
                            tag, "replaceInSQL", strDefaultReplaceInSQL);
                    this.vecReplaceInData = OctopusXMLUtil.getAttributeValues(
                            tag, "replaceInData", strDefaultReplaceInData);
                    this.vecReplaceInJDBC = OctopusXMLUtil.getAttributeValues(
                            tag, "replaceInJDBC", strDefaultReplaceInJDBC);
                    for (int i = 0; i < this.vecVariableOverride.size(); i++) {
                        if (this.vecVariableOverride.get(i).toString()
                                .equalsIgnoreCase("true")) {
                            if (this.mapVariableValues.get(this.vecVariableName
                                    .get(i)) == null)
                                this.vecVariableValue.setElementAt(null, i);
                            else
                                this.vecVariableValue
                                        .setElementAt(this.mapVariableValues
                                                .get(
                                                        this.vecVariableName
                                                                .get(i)
                                                                .toString())
                                                .toString(), i);
                        }
                    }
                }
            }
        } catch (Exception e) {
            this.logger.write("normal",
                    "Sorry, an error with the variables occurred: " + e);
            LoaderException le = new LoaderException("Exception: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        try {
            inStream.reset();
        } catch (IOException e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("IOException: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        this.logger.write("full", "\timportVariable  method is finished.");
    }

    /**
     * Method parseAndImport is used to analyse the importDefinition no. l in
     * xml file and input all values and puts them into global variables. If
     * there is an error, Exception "SAXException" is thrown.
     * 
     * @param inStream
     *            Data from inputXML file which is converted into InputStream.
     * @param l
     *            Number of ImportDefinition tag which is processed.
     * @param isImportDefinition
     *            true if ImportJob tag is "importDefinition".                       
     * @throws SAXException
     *             Constructs an JAXP 1.1 Exception with the specified detail
     *             message.
     * @throws Exception
     *             Constructs an Exception with the specified detail message.
     * @throws LoaderException
     */
    // 26.07.2007 senka added parameter isImportDefinition
    private void parseAndImport(InputStream inStream, int l, boolean isImportDefinition)
            throws SAXException, LoaderException, Exception {
        this.logger.write("full", "\tparseAndImport method is started.");
        Document doc = null;
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = null;
            db = dbf.newDocumentBuilder();
            doc = db.parse(inStream);
        } catch (SAXException e) {
            throw e;
        } catch (Exception e) {
            throw e;
        }
        if (doc != null)
            this.importXMLFile(doc, l, isImportDefinition);
        try {
            inStream.reset();
        } catch (IOException e) {
            this.logger.write("normal", "Sorry, an error occurred: " + e);
            LoaderException le = new LoaderException("IOException: ",
                    (Throwable) e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        this.logger.write("full", "\tparseAndImport method is finished.");
    }

    /**
     * Method importXMLFile is used for setting of global variables during
     * importing values from XML file. This method validates the imported data
     * from XML file. If there is an error Exception "NullPointerException" or
     * "Exception" is thrown.
     * 
     * @param doc
     *            Parsed imports XML file.
     * @param iJobNumber
     *            Number of ImportJob tag which is processed.
     * @param isImportDefinition
     *            true if ImportJob tag is "importDefinition".           
     * @throws NullPointerException
     *             Constructs a NullPointerException with the specified detail
     *             message.
     * @throws Exception
     *             Constructs an Exception with the specified detail message.
     */
//  26.07.2007 senka added parameter isImportDefinition
    private void importXMLFile(Document doc, int iJobNumber, boolean isImportDefinition)
            throws NullPointerException, Exception {
        this.logger.write("full", "\timportXMLFile method is started.");
        Vector vecValueColumnSourceColumnName = new Vector();
        Vector vecValueColumnTargetTableName = new Vector();
        Vector vecValueColumnTargetColumnName = new Vector();
        Vector vecValueColumnTargetTableID = new Vector();
        Vector vecValueColumnValueMode = new Vector();
        Vector vecConstantColumnTargetColumnName = new Vector();
        Vector vecConstantColumnValueMode = new Vector();
        Vector vecConstantColumnConstantValue = new Vector();
        Vector vecRestartCounterVector = new Vector();
        Vector vecJDBCSourceName = new Vector();
        Vector vecJDBCSourceValue = new Vector();
        Vector vecJDBCTargetName = new Vector();
        Vector vecJDBCTargetValue = new Vector();
        // vector for default values of columns
        Vector vecDefaultValueTemp = new Vector();
        this.vecDefaultValue = new Vector();
        this.vecDefaultRelationValue = null;
        this.vecDefaultVariableValue = null;
        this.vecDefaultVariableName = null;
        this.vecTempUserID = null;
        int iNumberOfColumns = 0;
        // to and form hex
        Vector vecToHexTemp = new Vector();
        Vector vecFromHexTemp = new Vector();
        this.vecToHex = new Vector();
        this.vecFromHex = new Vector();

        try {

            importDefinitionElement.setLogger(this.logger);
            dataCleaning.setLogger(this.logger);

            if (!this.loaderJobReader.getLogTableName().equalsIgnoreCase(""))
                dataCleaning.setLogTableName(this.loaderJobReader
                        .getLogTableName());

            if (!this.loaderJobReader.getLogTable().equalsIgnoreCase(""))
                dataCleaning.setLogTable(this.loaderJobReader.getLogTable());

            if (!this.loaderJobReader.getLogColumnName().equalsIgnoreCase(""))
                dataCleaning.setLogColumnName(this.loaderJobReader
                        .getLogColumnName());

            if (!this.loaderJobReader.getLogRowNumber().equalsIgnoreCase(""))
                dataCleaning.setLogRowNumber(this.loaderJobReader
                        .getLogRowNumber());

            if (!this.loaderJobReader.getLogOriginalValue()
                    .equalsIgnoreCase(""))
                dataCleaning.setLogOriginalValue(this.loaderJobReader
                        .getLogOriginalValue());

            if (!this.loaderJobReader.getLogNewValue().equalsIgnoreCase(""))
                dataCleaning.setLogNewValue(this.loaderJobReader
                        .getLogNewValue());

            if (!this.loaderJobReader.getLogImportDefinitionName()
                    .equalsIgnoreCase(""))
                dataCleaning.setLogImportDefinitionName(this.loaderJobReader
                        .getLogImportDefinitionName());

            if (!this.loaderJobReader.getLogOperationName()
                    .equalsIgnoreCase(""))
                dataCleaning.setLogOperationName(this.loaderJobReader
                        .getLogOperationName());
            if (!this.loaderJobReader.getLogTime().equalsIgnoreCase(""))
                dataCleaning.setLogTime(this.loaderJobReader.getLogTime());

            if (!this.loaderJobReader.getLogFailedStatement().equalsIgnoreCase(
                    ""))
                dataCleaning.setLogPrimaryKeyValue(this.loaderJobReader
                        .getLogFailedStatement());

            if (!this.loaderJobReader.getLogTypeName().equalsIgnoreCase(""))
                dataCleaning.setLogTypeName(this.loaderJobReader
                        .getLogTypeName());

            importDefinitionElement.setLoaderJob(this.loaderJobReader);
            // sqlElement.setLoaderJob(this.loaderJobReader);
            importDefinitionElement.importXMLFile(doc, iJobNumber);

            // set data cut off parameter based on priority
            if (importDefinitionElement.strDefaultCutOffData
                    .equalsIgnoreCase(""))
                importDefinitionElement.strDefaultCutOffData = loaderJobReader
                        .getDefaultDataCutOff();

            // set onErrorContinue parameter based on priority for xml
            if (importDefinitionElement.strOnErrorContinueXml
                    .equalsIgnoreCase(""))
                importDefinitionElement.strOnErrorContinueXml = ""
                        + loaderJobReader.getDefaultOnErrorContinue();

            if (importDefinitionElement.strCopyTableOnErrorContinue
                    .equalsIgnoreCase(""))
                importDefinitionElement.strCopyTableOnErrorContinue = ""
                        + loaderJobReader.getDefaultOnErrorContinue();
            if (isImportDefinition){ // 26.07.2007 senka added  this check
                  vecJDBCSourceValue = OctopusXMLUtil.importValue(doc,
                          "jdbcSourceParameter", "value", iJobNumber);
                  vecJDBCSourceName = OctopusXMLUtil.importValue(doc,
                          "jdbcSourceParameter", "name", iJobNumber);
               
               if (vecJDBCSourceValue.size() != 0) {
                   for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
                       if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase(
                               "JdbcDriver"))
                           jdbcParametersElement
                                   .setJDBCSourceParameterDriver(vecJDBCSourceValue
                                           .get(i).toString());
                       else if (vecJDBCSourceName.get(i).toString()
                               .equalsIgnoreCase("Connection.Url")) {
                           // Testing SelectMethod parameter in microsoft MSSQL
                           // driver
                           if (vecJDBCSourceValue.get(i).toString().indexOf(
                                   "jdbc:microsoft:sqlserver") != -1) {
                               if (vecJDBCSourceValue.get(i).toString().indexOf(
                                       "SelectMethod") == -1) {
                                   jdbcParametersElement
                                           .setJDBCSourceParameterConnection(vecJDBCSourceValue
                                                   .get(i).toString()
                                                   + ";SelectMethod=cursor");
                               } else if (vecJDBCSourceValue.get(i).toString()
                                       .indexOf("cursor") != -1) {
                                   jdbcParametersElement
                                           .setJDBCSourceParameterConnection(vecJDBCSourceValue
                                                   .get(i).toString());
                               } else {
                                   this.logger
                                           .write(
                                                   "normal",
                                                   "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor");
                                   LoaderException le = new LoaderException(
                                           "Exception:",
                                           new Exception(
                                                   "Value of Connection.Url perameter SelectMethod has to be cursor"));
                                   this.logger.write("full", le
                                           .getStackTraceAsString());
                                   throw le;
                               }
                           } else {
                               jdbcParametersElement
                                       .setJDBCSourceParameterConnection(vecJDBCSourceValue
                                               .get(i).toString());
                           }
                       } else if (vecJDBCSourceName.get(i).toString()
                               .equalsIgnoreCase("User"))
                           jdbcParametersElement
                                   .setJDBCSourceParameterUser(vecJDBCSourceValue
                                           .get(i).toString());
                       else if (vecJDBCSourceName.get(i).toString()
                               .equalsIgnoreCase("Password"))
                           jdbcParametersElement
                                   .setJDBCSourceParameterPassword(vecJDBCSourceValue
                                           .get(i).toString());
                   }
               }
               
                  vecJDBCTargetValue = OctopusXMLUtil.importValue(doc,
                          "jdbcTargetParameter", "value", iJobNumber);
                  vecJDBCTargetName = OctopusXMLUtil.importValue(doc,
                          "jdbcTargetParameter", "name", iJobNumber);
               
               if (vecJDBCTargetValue.size() != 0) {
                   for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
                       if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase(
                               "JdbcDriver"))
                           jdbcParametersElement
                                   .setJDBCTargetParameterDriver(vecJDBCTargetValue
                                           .get(i).toString());
                       else if (vecJDBCTargetName.get(i).toString()
                               .equalsIgnoreCase("Connection.Url")) {
                           // Testing SelectMethod parameter in microsoft MSSQL
                           // driver
                           if (vecJDBCTargetValue.get(i).toString().indexOf(
                                   "jdbc:microsoft:sqlserver") != -1) {
                               if (vecJDBCTargetValue.get(i).toString().indexOf(
                                       "SelectMethod") == -1) {
                                   jdbcParametersElement
                                           .setJDBCTargetParameterConnection(vecJDBCTargetValue
                                                   .get(i).toString()
                                                   + ";SelectMethod=cursor");
                               } else if (vecJDBCTargetValue.get(i).toString()
                                       .indexOf("cursor") != -1) {
                                   jdbcParametersElement
                                           .setJDBCTargetParameterConnection(vecJDBCTargetValue
                                                   .get(i).toString());
                               } else {
                                   this.logger
                                           .write(
                                                   "normal",
                                                   "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor");
                                   LoaderException le = new LoaderException(
                                           "Exception:",
                                           new Exception(
                                                   "value of Connection.Url parameter SelectMethod has to be cursor"));
                                   this.logger.write("full", le
                                           .getStackTraceAsString());
                                   throw le;
                               }
                           } else {
                               jdbcParametersElement
                                       .setJDBCTargetParameterConnection(vecJDBCTargetValue
                                               .get(i).toString());
                           }
                       } else if (vecJDBCTargetName.get(i).toString()
                               .equalsIgnoreCase("User"))
                           jdbcParametersElement
                                   .setJDBCTargetParameterUser(vecJDBCTargetValue
                                           .get(i).toString());
                       else if (vecJDBCTargetName.get(i).toString()
                               .equalsIgnoreCase("Password"))
                           jdbcParametersElement
                                   .setJDBCTargetParameterPassword(vecJDBCTargetValue
                                           .get(i).toString());
                   }
               }
               // to and form hex
              
                  vecToHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn",
                          "toHex", iJobNumber);
                  vecFromHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn",
                          "fromHex", iJobNumber);
                  // defalut values
                  vecDefaultValueTemp = OctopusXMLUtil.importValue(doc,
                          "valueColumn", "defaultValue", iJobNumber);
                  this.vecDefaultVariableValue = OctopusXMLUtil.importValue(doc,
                          "variableColumn", "defaultValue", iJobNumber);
                  this.vecDefaultVariableName = OctopusXMLUtil.importValue(doc,
                          "variableColumn", "name", iJobNumber);
                  this.vecDefaultRelationValue = OctopusXMLUtil.importValue(doc,
                          "relationColumn", "defaultValue", iJobNumber);
                  this.vecTempUserID = OctopusXMLUtil.importValue(doc,
                          "userIDColumn", "defaultValue", iJobNumber);
                  vecValueColumnSourceColumnName = OctopusXMLUtil.importValue(doc,
                          "valueColumn", "sourceColumnName", iJobNumber);
                  vecValueColumnTargetTableName = OctopusXMLUtil.importValue(doc,
                          "valueColumn", "targetTableName", iJobNumber);
                  this.iValueColumns = vecValueColumnTargetTableName.size();
                  vecValueColumnTargetColumnName = OctopusXMLUtil.importValue(doc,
                          "valueColumn", "targetColumnName", iJobNumber);
                  vecValueColumnTargetTableID = OctopusXMLUtil.importValue(doc,
                          "valueColumn", "targetTableID", iJobNumber);
                  vecValueColumnValueMode = OctopusXMLUtil.importValue(doc,
                          "valueColumn", "valueMode", iJobNumber);
                  this.vecVariableColumnName = OctopusXMLUtil.importValue(doc,
                          "variableColumn", "name", iJobNumber);
                  this.vecVariableColumnTargetTableName = OctopusXMLUtil.importValue(
                          doc, "variableColumn", "targetTableName", iJobNumber);
                  this.vecVariableColumnTargetColumnName = OctopusXMLUtil
                          .importValue(doc, "variableColumn", "targetColumnName",
                                  iJobNumber);
                  this.vecVariableColumnTargetTableID = OctopusXMLUtil.importValue(
                          doc, "variableColumn", "targetTableID", iJobNumber);
                  this.vecVariableColumnValueMode = OctopusXMLUtil.importValue(doc,
                          "variableColumn", "valueMode", iJobNumber);
                  this.vecVariableUseIDTableName = OctopusXMLUtil.importValue(doc,
                          "userIDColumn", "targetTableName", iJobNumber);
                  this.vecVariableUseIDColumnName = OctopusXMLUtil.importValue(doc,
                          "userIDColumn", "targetColumnName", iJobNumber);
                  this.vecVariableUseIDTableID = OctopusXMLUtil.importValue(doc,
                          "userIDColumn", "targetTableID", iJobNumber);
                  this.vecVariableUseIDValueMode = OctopusXMLUtil.importValue(doc,
                          "userIDColumn", "valueMode", iJobNumber);
                  this.vecVariableTimesTableName = OctopusXMLUtil.importValue(doc,
                          "timeStampColumn", "targetTableName", iJobNumber);
                  this.vecVariableTimesColumnName = OctopusXMLUtil.importValue(doc,
                          "timeStampColumn", "targetColumnName", iJobNumber);
                  this.vecVariableTimesTableID = OctopusXMLUtil.importValue(doc,
                          "timeStampColumn", "targetTableID", iJobNumber);
                  this.vecVariableTimesValueMode = OctopusXMLUtil.importValue(doc,
                          "timeStampColumn", "valueMode", iJobNumber);
                  this.vecConstantColumnTargetTableName = OctopusXMLUtil.importValue(
                          doc, "constantColumn", "targetTableName", iJobNumber);
                  this.iConstantColumns = this.vecConstantColumnTargetTableName
                          .size();
                  vecConstantColumnTargetColumnName = OctopusXMLUtil.importValue(doc,
                          "constantColumn", "targetColumnName", iJobNumber);
                  this.vecConstantColumnTargetTableID = OctopusXMLUtil.importValue(
                          doc, "constantColumn", "targetTableID", iJobNumber);
                  vecConstantColumnValueMode = OctopusXMLUtil.importValue(doc,
                          "constantColumn", "valueMode", iJobNumber);
      
                  vecConstantColumnConstantValue = OctopusXMLUtil.importValue(doc,
                          "constantColumn", "constantValue", iJobNumber, null);
                  this.vecRelationColumnSourceTableName = OctopusXMLUtil.importValue(
                          doc, "relationColumn", "relationSourceTableName",
                          iJobNumber);
                  this.iRelationColumns = this.vecRelationColumnSourceTableName
                          .size();
                  this.vecRelationColumnSourceTableID = OctopusXMLUtil.importValue(
                          doc, "relationColumn", "relationSourceTableID", iJobNumber);
                  this.vecRelationColumnSourceColumnName = OctopusXMLUtil
                          .importValue(doc, "relationColumn",
                                  "relationSourceColumnName", iJobNumber);
                  this.vecRelationColumnTargetTableName = OctopusXMLUtil.importValue(
                          doc, "relationColumn", "relationTargetTableName",
                          iJobNumber);
                  this.vecRelationColumnTargetColumnName = OctopusXMLUtil
                          .importValue(doc, "relationColumn",
                                  "relationTargetColumnName", iJobNumber);
                  this.vecRelationColumnTargetTableID = OctopusXMLUtil.importValue(
                          doc, "relationColumn", "relationTargetTableID", iJobNumber);
                  this.vecRelationColumnRelationMode = OctopusXMLUtil.importValue(
                          doc, "relationColumn", "relationMode", iJobNumber);
                  // rale
      
                  ImportDefinitionSourceColumnName = vecValueColumnSourceColumnName;
                  ImportDefinitionTargetColumnName = vecValueColumnTargetColumnName;
      
                  // sinisa 02.03.2003. Add counterColumns
                  this.counterColumns = new CounterColumns();
                  this.counterColumns.setLogger(this.logger);
                  this.counterColumns.resetSubCounterCache();
                  this.counterColumns.readConstantColumnAttributes(doc, iJobNumber);
                  this.counterColumns.readConstantColumnsParameters(doc, iJobNumber);
                  // end sinisa
      
                  // sinisa 02.03.2003. Add transformations
                  this.transformations = new Transformations(this.logger);
                  // ArrayList transTableNamesIDs =
                  // this.transformations.getTransformationsTableNamesAndIDs();
                  this.transformations.createTransformationElements(doc, iJobNumber);
                  ArrayList trans = this.transformations.getTransformations();
                  Iterator iTrans = trans.iterator();
      
                  while (iTrans.hasNext()) {
                      Transformation temp = (Transformation) iTrans.next();
                      temp.setLogger(this.logger);
      
                      // temp.readSourceColumns(doc, iJobNumber);
                      // temp.readTargetColumns(doc, iJobNumber);
                      // temp.readSourceColumns();
                      // temp.readTargetColumns();
      
                  }
      
                  // end sinisa
      
                  this.vecTableTableName = OctopusXMLUtil.importValue(doc, "table",
                          "tableName", iJobNumber);
                  this.iTables = this.vecTableTableName.size();
                  this.vecTableTableID = OctopusXMLUtil.importValue(doc, "table",
                          "tableID", iJobNumber);
                  this.vecTableInsert = OctopusXMLUtil.importValue(doc, "table",
                          "insert", iJobNumber);
                  this.vecTableTableMode = OctopusXMLUtil.importValue(doc, "table",
                          "tableMode", iJobNumber, loaderJobReader
                                  .getDefaultTableMode());
                  this.vecTableOidLogic = OctopusXMLUtil.importValue(doc, "table",
                          "oidLogic", iJobNumber, (new Boolean(loaderJobReader
                                  .getDefaultOidLogic())).toString());
      
                  this.vecCTAutoMapp = OctopusXMLUtil.importValue(doc, "table",
                          "autoMapColumns", iJobNumber);
                  this.vecCTDefaultMode = OctopusXMLUtil.importValue(doc, "table",
                          "defaultMode", iJobNumber);
            }  // senka added : end of if (isImportDefinition)
            if (this.vecRelationColumnSourceTableName.size() != 0) {
                this.changeRelationsOrder();
                this.changeTableOrder();
            }
            this.vecRelationKeyColumns.setSize(this.iTables);
            this.vecRelationKeyTypes.setSize(this.iTables);
            this.vecConstantTargetColumnName.setSize(this.iTables);
            // ZK added this
            // this.transformationsColumnNames.setSize(this.iTables);

            this.vecConstantValueMode.setSize(this.iTables);
            this.vecConstantConstantValue.setSize(this.iTables);
            this.vecConstantColumnType.setSize(this.iTables);
            for (int k = 0; k < vecValueColumnTargetTableName.size(); k++) {
                boolean isImportColumn = false;
                for (int l = 0; l < this.iTables; l++) {
                    if (vecValueColumnTargetTableName.get(k).toString()
                            .equalsIgnoreCase(
                                    this.vecTableTableName.get(l).toString())
                            && vecValueColumnTargetTableID.get(k).toString()
                                    .equalsIgnoreCase(
                                            this.vecTableTableID.get(l)
                                                    .toString())) {
                        isImportColumn = true;
                    }
                }
                if (!isImportColumn) {
                    this.logger.write("normal",
                            "Incorrect XML import variables - TABLE ID");
                    LoaderException le = new LoaderException(
                            "Exception: ",
                            (Throwable) (new Exception(
                                    "Incorrect XML import variables - TABLE ID")));
                    this.logger.write("full", le.getStackTraceAsString());
                    throw le;
                }
            }

            if (this.vecVariableUseIDTableName.size() != 0) {
                String tempUserID = this.vecTempUserID.get(0).toString();
                if (userIDExists)
                    this.strUserID = "";
                if (this.strUserID.equals("")) {
                    if (!tempUserID.equalsIgnoreCase("")) {
                        this.strUserID = tempUserID;
                        this.userIDExists = true;
                    } else {
                        this.logger.write("normal",
                                "Error : User parametar missing");
                        LoaderException le = new LoaderException("Exception: ",
                                (Throwable) (new Exception(
                                        "Error : User parametar missing")));
                        this.logger.write("full", le.getStackTraceAsString());
                        throw le;
                    }
                }
            }
            for (int k = 0; k < this.iTables; k++) {
                iNumberOfColumns = 0;
                Vector vecTargetTable1 = new Vector();
                Vector vecTargetTable2 = new Vector();
                Vector vecTargetTable3 = new Vector();
                Vector vecTargetTable4 = new Vector();
                Vector vecTargetTable5 = new Vector();
                Vector vecTargetTable6 = new Vector();
                Vector vecTargetTable7 = new Vector();
                Vector vecTargetTable8 = new Vector();
                Vector vecTargetTable9 = new Vector();
                Vector vecTargetTable10 = new Vector();
                Vector vecTargetTable11 = new Vector();

                for (int l = 0; l < this.iValueColumns; l++) {
                    if (this.vecTableTableName.get(k).toString()
                            .equalsIgnoreCase(
                                    vecValueColumnTargetTableName.get(l)
                                            .toString())
                            && vecValueColumnTargetTableID.get(l).toString()
                                    .equalsIgnoreCase(
                                            this.vecTableTableID.get(k)
                                                    .toString())) {
                        iNumberOfColumns++;
                        vecTargetTable1
                                .addElement(vecValueColumnSourceColumnName.get(
                                        l).toString());
                        vecTargetTable2
                                .addElement(vecValueColumnTargetColumnName.get(
                                        l).toString());
                        vecTargetTable4.addElement(vecValueColumnValueMode.get(
                                l).toString());
                        // rale
                        vecTargetTable9.addElement(vecDefaultValueTemp.get(l)
                                .toString());
                        vecTargetTable10.addElement(vecToHexTemp.get(l)
                                .toString());
                        vecTargetTable11.addElement(vecFromHexTemp.get(l)
                                .toString());
                        if (vecValueColumnValueMode.get(l).toString()
                                .equalsIgnoreCase("Key"))
                            vecTargetTable5
                                    .addElement(vecValueColumnTargetColumnName
                                            .get(l).toString());
                    }
                }
                for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) {
                    if (this.vecTableTableName.get(k).toString()
                            .equalsIgnoreCase(
                                    this.vecVariableUseIDTableName.get(l)
                                            .toString())
                            && this.vecVariableUseIDTableID.get(l).toString()
                                    .equalsIgnoreCase(
                                            this.vecTableTableID.get(k)
                                                    .toString())) {
                        vecTargetTable2
                                .addElement(this.vecVariableUseIDColumnName
                                        .get(l).toString());
                        vecTargetTable4
                                .addElement(this.vecVariableUseIDValueMode.get(
                                        l).toString());
                        // rale
                        // vecTargetTable9.addElement(vecDefaultValueTemp.get(l).toString());
                        // vecTargetTable10.addElement(vecToHexTemp.get(l).toString());
                        // vecTargetTable11.addElement(vecFromHexTemp.get(l).toString());

                        if (this.vecVariableUseIDValueMode.get(l).toString()
                                .equalsIgnoreCase("Key"))
                            vecTargetTable5
                                    .addElement(this.vecVariableUseIDColumnName
                                            .get(l).toString());
                    }
                }
                for (int l = 0; l < this.vecRelationColumnSourceColumnName
                        .size(); l++) {
                    if (this.vecTableTableName.get(k).toString()
                            .equalsIgnoreCase(
                                    this.vecRelationColumnTargetTableName
                                            .get(l).toString())
                            && this.vecRelationColumnTargetTableID.get(l)
                                    .toString().equalsIgnoreCase(
                                            this.vecTableTableID.get(k)
                                                    .toString())
                            && this.vecRelationColumnRelationMode.get(l)
                                    .toString().equalsIgnoreCase("Key")) {
                        vecTargetTable3
                                .addElement(this.vecRelationColumnTargetColumnName
                                        .get(l).toString());
                    }
                }

                // rale
                this.vecToHex.addElement(vecToHexTemp);
                this.vecFromHex.addElement(vecFromHexTemp);
                this.vecDefaultValue.addElement(vecTargetTable9);
                this.vecSourceColumnName.addElement(vecTargetTable1);
                this.vecTargetColumnName.addElement(vecTargetTable2);
                this.vecRelationKeyColumns.setElementAt(vecTargetTable3, k);
                this.vecValueMode.addElement(vecTargetTable4);
                this.vecTargetKeyColumnName.addElement(vecTargetTable5);
                this.vecValueColumnsTargetTables.addElement(new Integer(
                        iNumberOfColumns));
                for (int p = 0; p < this.iConstantColumns; p++) {
                    if (this.vecTableTableName.get(k).toString()
                            .equalsIgnoreCase(
                                    this.vecConstantColumnTargetTableName
                                            .get(p).toString())
                            && this.vecConstantColumnTargetTableID.get(p)
                                    .toString().equalsIgnoreCase(
                                            this.vecTableTableID.get(k)
                                                    .toString())) {
                        vecTargetTable6
                                .addElement(vecConstantColumnTargetColumnName
                                        .get(p).toString());
                        vecTargetTable7.addElement(vecConstantColumnValueMode
                                .get(p).toString());
                        if (vecConstantColumnConstantValue.get(p) == null)
                            vecTargetTable8.addElement(null);
                        else
                            vecTargetTable8
                                    .addElement(vecConstantColumnConstantValue
                                            .get(p).toString());
                    }
                }
                this.vecConstantTargetColumnName.setElementAt(vecTargetTable6,
                        k);
                this.vecConstantValueMode.setElementAt(vecTargetTable7, k);
                this.vecConstantConstantValue.setElementAt(vecTargetTable8, k);

                // sinisa 02.03.2003. Add counterColumns

                this.counterColumns.setConstantColumnsParameters(
                        this.vecTableTableName.get(k).toString(),
                        this.vecTableTableID.get(k).toString());
                // end sinisa
            }

            for (int i = 0; i < this.vecRelationColumnSourceColumnName.size(); i++) {
                if (this.vecRelationColumnSourceColumnName.get(i).toString()
                        .equals("")) {
                    for (int k = 0; k < this.vecTableTableName.size(); k++) {
                        if (this.vecRelationColumnSourceTableName.get(i)
                                .toString().equalsIgnoreCase(
                                        this.vecTableTableName.get(k)
                                                .toString())
                                && this.vecRelationColumnSourceTableID.get(i)
                                        .toString().equalsIgnoreCase(
                                                this.vecTableTableID.get(k)
                                                        .toString())) {
                            if (this.vecTableOidLogic.get(k).toString()
                                    .equalsIgnoreCase("true"))
                                this.vecRelationColumnSourceColumnName
                                        .setElementAt(
                                                this.currentOidColumnName, i);
                            // this.vecRelationColumnSourceColumnName.setElementAt("oid",i);
                        }
                    }
                }
            }
            this.vecRelationSourceValue.setSize(this.iRelationColumns);
            this.vecRelationSourceType.setSize(this.iRelationColumns);
        } catch (NullPointerException ex) {
            throw ex;
        } catch (Exception ex) {
            throw ex;
        }
        this.logger.write("full", "\timportXMLFile method is finished.");
    }

    /**
     * Method updateCurrentTime write system time into timeStamp variable
     * columns
     * 
     * @param c
     *            Connection to the target table.
     * @param iTable
     *            Number of target table.
     * @param strQueryWhereSQL
     *            Part of SQL query - where clause.
     * @param currentVersion
     *            represents current version of insert/update
     * @param oid
     *            repersents if the oid logic is present
     * @throws SQLException
     * @throws NullPointerException
     * @return true if something is written to database
     */
    private boolean updateCurrentTime(Connection c, int iTable,
            String strQueryWhereSQL, int currentVersion, boolean oid)
            throws SQLException, NullPointerException {
        String strQueryInsertTime = "";
        boolean bWriteData = false;
        String oidVersion = "";
        // if (oid)
        // oidVersion = ", version=" + currentVersion;
        if (oid)
            oidVersion = ", " + this.currentVersionColumnName + "="
                    + currentVersion;
        this.logger.write("full", "\t updateCurrentTime method is started.");
        try {
            for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
                if (this.vecVariableTimesTableName.get(i).toString()
                        .equalsIgnoreCase(
                                this.vecTableTableName.get(iTable).toString())
                        && this.vecVariableTimesTableID.get(i).toString()
                                .equalsIgnoreCase(
                                        this.vecTableTableID.get(iTable)
                                                .toString())) {
                    Statement stmtRelations = c.createStatement();
                    strQueryInsertTime = "update "
                            + this.vecVariableTimesTableName.get(i).toString()
                            + " set "
                            + this.vecVariableTimesColumnName.get(i).toString()
                            + " = ";
                    if (this.vecVariableTimesValueMode.get(i).toString()
                            .equalsIgnoreCase("Overwrite"))

                        // && bWriteData == true)
                        strQueryInsertTime += " '" + this.createCurrentDate()
                                + "'" + oidVersion + " where "
                                + strQueryWhereSQL;
                    else
                        strQueryInsertTime += " '"
                                + this.createCurrentDate()
                                + "'"
                                + oidVersion
                                + " where "
                                + this.vecVariableTimesColumnName.get(i)
                                        .toString() + " is null and "
                                + strQueryWhereSQL;
                    this.logger.write("full", "\tQuery '" + strQueryInsertTime
                            + "' will be executed");
                    if (bReplaceInData) {
                        strQueryInsertTime = this
                                .replaceInData(strQueryInsertTime);
                    }
                    int num = stmtRelations.executeUpdate(strQueryInsertTime);
                    if (num != 0) {
                        bWriteData = true;
                    }
                    stmtRelations.close();
                }
            }
        } catch (SQLException ex) {
            throw ex;
        } catch (NullPointerException ex) {
            throw ex;
        }
        this.logger.write("full", "\tupdateCurrentTime method is finished.");
        return bWriteData;
    }

    /**
     * Method updateNameValue writes nameValue value (Loader's argument) into
     * variable columns
     * 
     * @param c
     *            Connection to the target table.
     * @param iTable
     *            Number of target table.
     * @param strQueryWhereSQL
     *            Part of SQL query - where clause.
     * @param currentVersion
     *            represents current version of insert/update
     * @param oid
     *            define if oid logic is present
     * @throws SQLException
     * @throws NullPointerException
     * @throws LoaderException
     * @return true if something is written to database
     */
    private boolean updateNameValue(Connection c, int iTable,
            String strQueryWhereSQL, int currentVersion, boolean oid)
            throws SQLException, NullPointerException, LoaderException {

        String strQueryInsertName = "";
        boolean bWriteData = false;
        String oidVersion = "";
        // if (oid)
        // oidVersion = ", version=" + currentVersion;
        if (oid)
            oidVersion = ", " + this.currentVersionColumnName + "="
                    + currentVersion;

        this.logger.write("full", "\t updateNameValue method is started.");
        try {
            for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
                boolean bInsert = true;
                if (this.vecVariableColumnTargetTableName.get(i).toString()
                        .equalsIgnoreCase(
                                this.vecTableTableName.get(iTable).toString())
                        && this.vecVariableColumnTargetTableID.get(i)
                                .toString().equalsIgnoreCase(
                                        this.vecTableTableID.get(iTable)
                                                .toString())) {
                    int iPositionInVector = this.vecVariableName
                            .indexOf(this.vecVariableColumnName.get(i)
                                    .toString());
                    if (iPositionInVector != -1) {
                        Statement stmtRelations = c.createStatement();
                        strQueryInsertName = "update "
                                + this.vecVariableColumnTargetTableName.get(i)
                                        .toString()
                                + " set "
                                + this.vecVariableColumnTargetColumnName.get(i)
                                        .toString() + " = ";
                        if (this.vecVariableColumnValueMode.get(i).toString()
                                .equalsIgnoreCase("Overwrite")) {
                            if (this.vecVariableValue.get(iPositionInVector) == null) {
                                String variableName = this.vecVariableColumnName
                                        .get(i).toString();
                                for (int k = 0; k < this.vecDefaultVariableName
                                        .size(); k++) {
                                    if (this.vecDefaultVariableName.get(k)
                                            .toString().equalsIgnoreCase(
                                                    variableName)) {
                                        if (!this.vecDefaultVariableValue
                                                .get(k).toString()
                                                .equalsIgnoreCase("")) {
                                            // if
                                            // (!CheckType.isNumber(this.vecVariableColumnTypes.get(i).
                                            // toString()))
                                            // ZK change this from CheckType to
                                            // configReaderTarget this 7.5.2004

                                            if (!configReaderTarget
                                                    .isNumber(this.vecVariableColumnTypes
                                                            .get(i).toString()))

                                                strQueryInsertName += " '"
                                                        + this.vecDefaultVariableValue
                                                                .get(k)
                                                                .toString()
                                                        + "' " + oidVersion
                                                        + " where "
                                                        + strQueryWhereSQL;
                                            else
                                                strQueryInsertName += " "
                                                        + this.vecDefaultVariableValue
                                                                .get(k) + " "
                                                        + oidVersion
                                                        + " where "
                                                        + strQueryWhereSQL;

                                        } else {
                                            strQueryInsertName += " null"
                                                    + oidVersion + " where "
                                                    + strQueryWhereSQL;
                                        }
                                        break;
                                    }
                                }
                            } else {
                                // ZK change this from CheckType to
                                // configReaderTarget this 7.5.2004
                                if (!configReaderTarget
                                        .isNumber(this.vecVariableColumnTypes
                                                .get(i).toString()))
                                    strQueryInsertName += " '"
                                            + this.vecVariableValue.get(
                                                    iPositionInVector)
                                                    .toString() + "'"
                                            + oidVersion + " where "
                                            + strQueryWhereSQL;
                                else
                                    strQueryInsertName += this.vecVariableValue
                                            .get(iPositionInVector).toString()
                                            + oidVersion
                                            + " where "
                                            + strQueryWhereSQL;
                            }
                        } else if (this.vecVariableColumnValueMode.get(i)
                                .toString().equalsIgnoreCase("SetNull")) {
                            if (this.vecVariableValue.get(iPositionInVector) == null)
                                strQueryInsertName += " null" + oidVersion
                                        + " where " + strQueryWhereSQL;
                            else
                                bInsert = false;
                        } else {
                            if (this.vecVariableValue.get(iPositionInVector) == null) {
                                String variableName = this.vecVariableColumnName
                                        .get(i).toString();
                                for (int k = 0; k < this.vecDefaultVariableName
                                        .size(); k++) {
                                    if (this.vecDefaultVariableName.get(k)
                                            .toString().equalsIgnoreCase(
                                                    variableName)) {
                                        if (!this.vecDefaultVariableValue
                                                .get(k).toString()
                                                .equalsIgnoreCase("")) {
                                            // ZK change this from CheckType to
                                            // configReaderTarget this 7.5.2004
                                            if (!configReaderTarget
                                                    .isNumber(this.vecVariableColumnTypes
                                                            .get(i).toString()))
                                                strQueryInsertName += " '"
                                                        + this.vecDefaultVariableValue
                                                                .get(k)
                                                                .toString()
                                                        + "' "
                                                        + oidVersion
                                                        + " where "
                                                        + this.vecVariableColumnTargetColumnName
                                                                .get(i)
                                                                .toString()
                                                        + " is null and "
                                                        + strQueryWhereSQL;
                                            else
                                                strQueryInsertName += " "
                                                        + this.vecDefaultVariableValue
                                                                .get(k)
                                                        + " "
                                                        + oidVersion
                                                        + " where "
                                                        + this.vecVariableColumnTargetColumnName
                                                                .get(i)
                                                                .toString()
                                                        + " is null and "
                                                        + strQueryWhereSQL;
                                        } else {
                                            strQueryInsertName += " null"
                                                    + oidVersion
                                                    + " where "
                                                    + this.vecVariableColumnTargetColumnName
                                                            .get(i).toString()
                                                    + " is null and "
                                                    + strQueryWhereSQL;
                                        }
                                        break;
                                    }
                                }
                            } else {
                                // ZK change this from CheckType to
                                // configReaderTarget this 7.5.2004
                                if (!configReaderTarget
                                        .isNumber(this.vecVariableColumnTypes
                                                .get(i).toString()))
                                    strQueryInsertName += " '"
                                            + this.vecVariableValue.get(
                                                    iPositionInVector)
                                                    .toString()
                                            + "'"
                                            + oidVersion
                                            + " where "
                                            + this.vecVariableColumnTargetColumnName
                                                    .get(i).toString()
                                            + " is null and "
                                            + strQueryWhereSQL;
                                else
                                    strQueryInsertName += this.vecVariableValue
                                            .get(iPositionInVector).toString()
                                            + oidVersion
                                            + " where "
                                            + this.vecVariableColumnTargetColumnName
                                                    .get(i).toString()
                                            + " is null and "
                                            + strQueryWhereSQL;
                            }
                        }
                        if (bInsert)
                            this.logger
                                    .write("full", "\tQuery '"
                                            + strQueryInsertName
                                            + "' will be executed");

                        if (bReplaceInData) {
                            strQueryInsertName = this
                                    .replaceInData(strQueryInsertName);
                        }
                        if (bInsert) {
                            int num = 0;
                            try {
                                num = stmtRelations
                                        .executeUpdate(strQueryInsertName);
                            } catch (SQLException ex) {
                                stmtRelations.close();
                                stmtRelations = c.createStatement();
                                if ((importDefinitionElement.strDefaultCutOffData
                                        .equalsIgnoreCase("true"))) {
                                    dataCleaning
                                            .cutingDataLenghtUpdate(
                                                    this.vecTableTableName.get(
                                                            iTable).toString(),
                                                    c,
                                                    "",
                                                    currentRow,
                                                    strQueryInsertName,
                                                    importDefinitionElement.strOnErrorContinueXml,
                                                    importDefinitionElement.strImportDefinitionName,
                                                    strQueryInsertName);
                                } else
                                    throw ex;
                            }
                        }
                        // stmtRelations.close();
                    } else {
                        this.logger.write("normal",
                                "\tError: Cannot find value for variable column :"
                                        + this.vecVariableColumnName.get(i)
                                                .toString());
                        LoaderException le = new LoaderException(
                                "Exception: ",
                                (Throwable) (new Exception(
                                        "Error: Cannot find value for variable column :")));
                        this.logger.write("full", le.getStackTraceAsString());
                        throw le;
                    }
                }
            }
        } catch (SQLException ex) {
            throw ex;
        } catch (NullPointerException ex) {
            throw ex;
        }
        this.logger.write("full", "\tupdateNameValue method is finished.");
        return bWriteData;
    }

    /**
     * Method queryRelations is used to make SQL query for reading source value
     * for relations between target tables. It puts the value from the source
     * column in source relation table to the target column in target relation
     * table. If there is an error, Exception "SQLException" or
     * NullPointerException is thrown.
     * 
     * @param iTableInt
     *            Number of target table.
     * @param iNumberOfRelationColumn
     *            Number of relation tag.
     * @param strQueryWhere
     *            Part of SQL query - where clause.
     * @param conn
     *            represents connection to target database
     * @param currentVersion
     *            represents currnet version of insert/update
     * @param oid
     *            define if oid logic is present
     * @return String which will be executed for update or insert relation
     *         columns into target tables
     * @throws NullPointerException
     *             Constructs a NullPointerException with the specified detail
     *             message.
     * @throws LoaderException
     */
    private String queryRelations(int iTableInt, int iNumberOfRelationColumn,
            String strQueryWhere, Connection conn, int currentVersion,
            boolean oid) throws NullPointerException, LoaderException {
        this.logger.write("full", "\tqueryRelations method is started.");
        String strQueryRelations = "";
        String oidVersion = "";
        String selectValueInRel = "";
        String currentValueInRel = "";
        // if (oid)
        // oidVersion = ", version=" + currentVersion;
        if (oid)
            oidVersion = ", " + this.currentVersionColumnName + "="
                    + currentVersion;

        try {
            strQueryRelations = "update "
                    + this.vecRelationColumnTargetTableName.get(
                            iNumberOfRelationColumn).toString()
                    + " set "
                    + this.vecRelationColumnTargetColumnName.get(
                            iNumberOfRelationColumn).toString();
            if (this.vecRelationSourceValue.get(iNumberOfRelationColumn) == null) {
                String replacementValueInRel = vecDefaultRelationValue.get(
                        iNumberOfRelationColumn).toString();
                if (!replacementValueInRel.equalsIgnoreCase("")) {
                    try {
                        Statement stmt = conn.createStatement();
                        ResultSet newRelationValue;
                        String relationValue;
                        boolean isFull = false;
                        if (!replacementValueInRel
                                .equalsIgnoreCase(selectValueInRel)) {
                            selectValueInRel = replacementValueInRel;
                            newRelationValue = stmt
                                    .executeQuery(replacementValueInRel);
                            isFull = newRelationValue.next();
                            if (isFull) {
                                relationValue = newRelationValue.getString(1);
                                currentValueInRel = relationValue;
                            } else {
                                relationValue = "";
                                currentValueInRel = "";
                            }
                            newRelationValue.close();
                        } else {
                            if (!currentValueInRel.equalsIgnoreCase("")
                                    && currentValueInRel != null) {
                                relationValue = currentValueInRel;
                                isFull = true;
                            } else {
                                relationValue = "";
                            }
                        }
                        if (isFull) {
                            strQueryRelations += dataCleaning
                                    .cleaningRelationValues(
                                            this.vecTableTableName.get(
                                                    iTableInt).toString(),
                                            this.vecRelationColumnTargetColumnName
                                                    .get(
                                                            iNumberOfRelationColumn)
                                                    .toString(),
                                            relationValue,
                                            this.vecRelationSourceType.get(
                                                    iNumberOfRelationColumn)
                                                    .toString(),
                                            currentRow,
                                            conn,
                                            "UPDATE",
                                            currentVersion,
                                            oid,
                                            importDefinitionElement.strImportDefinitionName,
                                            this.currentVersionColumnName,
                                            replacementValueInRel);

                        } else {
                            dataCleaning
                                    .cleaningInsert(
                                            this.vecTableTableName.get(
                                                    iTableInt).toString(),
                                            conn,
                                            currentRow,
                                            "UPDATE",
                                            "Default value '"
                                                    + replacementValueInRel
                                                    + "' for relations is not valid.",
                                            importDefinitionElement.strImportDefinitionName,
                                            replacementValueInRel);
                            strQueryRelations += " = null " + oidVersion
                                    + " where ";
                        }
                    } catch (SQLException ex) {
                        String msg = "Default value for foreign key("
                                + replacementValueInRel
                                + ") is not valid. Import definition name: "
                                + importDefinitionElement.strImportDefinitionName;
                        LoaderException le = new LoaderException(
                                "SQLException: " + msg, (Throwable) ex);
                        this.logger.write("full", le.getStackTraceAsString());
                        throw le;
                    }

                } else
                    strQueryRelations += " = null " + oidVersion + " where ";
            } else {
                // TODO Check this part of code. ZK change from
                // configReaderSource to configReaderTarget because of problems
                // with relation columns.
                if (configReaderTarget.isNumber(this.vecRelationSourceType.get(
                        iNumberOfRelationColumn).toString())) {
                    strQueryRelations += " = "
                            + this.vecRelationSourceValue.get(
                                    iNumberOfRelationColumn).toString()
                            + oidVersion + " where ";
                } else {
                    strQueryRelations += " = ";
                    if (configReaderTarget.isWithN(this.vecRelationSourceType
                            .get(iNumberOfRelationColumn).toString())) {
                        strQueryRelations += "N";
                    }
                    strQueryRelations += "'"
                            + this.vecRelationSourceValue.get(
                                    iNumberOfRelationColumn).toString() + "'"
                            + oidVersion + " where ";
                }

            }
            strQueryRelations += strQueryWhere;
            if (strQueryRelations.trim().endsWith("where"))
                strQueryRelations = strQueryRelations.substring(0,
                        strQueryRelations.length() - 6);
            else {
                if (!this.vecRelationColumnRelationMode.get(
                        iNumberOfRelationColumn).toString().equalsIgnoreCase(
                        "overwrite")) {
                    // ||
                    // !this.vecRelationColumnRelationMode.get(iNumberOfRelationColumn).toString().
                    // equalsIgnoreCase("SetIfCreated")) {

                    strQueryRelations += " and "
                            + this.vecRelationColumnTargetColumnName.get(
                                    iNumberOfRelationColumn).toString()
                            + " is null";
                }
            }
        } catch (NullPointerException ex) {
            throw ex;
        }
        this.logger.write("full", "\tqueryRelations method is finished.");
        return strQueryRelations;
    }

    /**
     * Method insertTargetTable is used to put one row of data from columns of
     * source tables into target table ordered by column modes. If there is an
     * error, Exception "SQLException, "NullPointerException" or "Exception" is
     * thrown.
     * 
     * @param iTableInt
     *            Number of the target table which is processed.
     * @param vecColumnValues
     *            One row of values from the source table.
     * @param vecColumnNames
     *            Vector of column names in a target table.
     * @param vecColumnMode
     *            Modes of columns in the target table.
     * @param vecColumnTypes
     *            Types of columns in the target table.
     * @param c
     *            Connection to the target database.
     * @throws SQLException
     *             Constructs an SQLException object with a reason.
     * @throws NullPointerException
     *             Constructs a NullPointerException with the specified detail
     *             message.
     * @throws Exception
     *             Constructs an Exception with the specified detail message.
     */
    private void insertTargetTable(int iTableInt, Vector vecColumnValues,
            Vector vecColumnNames, Vector vecColumnMode, Vector vecColumnTypes,
            Connection c, Vector vecTransformationValue,
            Vector transTargetColumnTypes) throws SQLException,
            NullPointerException, Exception {

        this.logger.write("full", "\tinsertTargetTable method is started.");
        boolean bInsertTable = false;
        int iVersionValue = 0;
        int iVersionMax = 0;
        boolean bWriteData = false;
        String strQueryWhere = "";
        String strQuery = new String("select ");
        // for handling exception in FK (data cleanining)
        String exceptionInRelations = "";
        String replacementValueInRel = "";
        String replacementTable = "";
        String replacementColumn = "";
        // String replacementColumnType = "";
        boolean relationIsOk = false;
        boolean updateQueryIsOk = false;
        boolean updateConstantIsOk = false;
        String strQueryConstantApendix = "";

        boolean bOidLogicCurrentTable = new Boolean(this.vecTableOidLogic.get(
                iTableInt).toString()).booleanValue();
        boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
                .equals("") || importDefinitionElement.strObjectIDNameColumnValue
                .equals(""));
        boolean oid = false;
        if (bOidLogicCurrentTable && !isTOS)
            oid = true;

        Vector vecTempKeyColumns = (Vector) this.vecTargetKeyColumnName
                .get(iTableInt);

        String key = String.valueOf(iTableInt);
        String query = (String) queryStatement.get(key);
        // System.out.println("query="+query);
        String update = (String) updateStatement.get(key);
        String updateConstant = (String) updateConstantStatement.get(key);

        String updateTransformation = (String) updateTransformationStatement
                .get(key);

        // updateTransformation =
        // (String)this.updateTransformationStatement.get(key);
        Statement stmtTarget = null;
        // ZK added this. If (select something from ... )is valid (contains oid,
        // version and more) then do insert
        // String query1 = (String)queryStatement.get(key);
        // System.out.println("query="+query);
        // boolean isValidStmt = validStmt.checkStatement(query);
        // System.out.println("isValidStmt="+isValidStmt);
        String logStatement = "";
        try {
            // if (isValidStmt){
            if (query.indexOf(" where ") == -1) {
                this.insertRow(c, vecColumnValues, vecColumnTypes,
                        vecColumnNames, vecColumnMode, bOidLogicCurrentTable,
                        iTableInt, vecTransformationValue,
                        transTargetColumnTypes);
                bInsertTable = true;
            } else {
                Vector dv = (Vector) indexDValue.get(key);
                Vector drv = (Vector) indexDRelationValue.get(key);
                Vector dcv = (Vector) indexConstantDValue.get(key);
                Vector dvv = (Vector) indexDVariableValue.get(key);
                Vector dtv = (Vector) indexDTransformationValue.get(key);

                if (dv.size() > 0) {
                    for (int i = 0; i < dv.size(); i++) {
                        int index = Integer.parseInt(dv.get(i).toString());
                        if (vecColumnValues.get(index) == null) {
                            int str = query.indexOf("'dummyValue'");
                            int num = query.indexOf("dummyValue");
                            if (str != -1 && (num == -1 || str < num))
                                query = replaceFirst(query, "= 'dummyValue'",
                                        " is null ");
                            else
                                query = replaceFirst(query, "= dummyValue",
                                        " is null ");
                        } else {
                            query = replaceFirst(query, "dummyValue",
                                    vecColumnValues.get(index).toString());
                        }
                    }
                }
                if (drv.size() > 0) {
                    for (int i = 0; i < drv.size(); i++) {
                        int index = Integer.parseInt(drv.get(i).toString());
                        int str = query.indexOf("'dummyRelationValue'");
                        int num = query.indexOf("dummyRelationValue");
                        if ((this.vecRelationSourceValue.get(index) == null) ||
                            (this.vecRelationSourceValue.get(index).toString() == "null")) {
                          //  int str = query.indexOf("'dummyRelationValue'");
                          //  int num = query.indexOf("dummyRelationValue");
                            if (str != -1 && (num == -1 || str < num))
                                query = replaceFirst(query,
                                        "= 'dummyRelationValue'", " is null ");
                            else
                                query = replaceFirst(query,
                                        "= dummyRelationValue", " is null ");
                        } else {
                            //query = replaceFirst(query, "dummyRelationValue",
                           //         this.vecRelationSourceValue.get(index)
                           //                 .toString());
                          //  senka change 
                             String relValues=this.vecRelationSourceValue.get(index).toString();
                            if (relValues.startsWith(" IN")) {
                              if (str != -1 && (num == -1 || str < num))  
                                query = replaceFirst(query, "= 'dummyRelationValue'",relValues);
                              else
                                query = replaceFirst(query, "= dummyRelationValue",relValues);                    
                            }else{
                                query = replaceFirst(query, "dummyRelationValue",relValues);   
                            }
                        }
                    }
                }

                Vector vecTempConstantColumns = (Vector) this.vecConstantTargetColumnName
                        .get(iTableInt);
                Vector vecTempConstantValues = (Vector) this.vecConstantConstantValue
                        .get(iTableInt);
                Vector vecTempConstantMode = (Vector) this.vecConstantValueMode
                        .get(iTableInt);
                Vector vecTempConstantType = (Vector) this.vecConstantColumnType
                        .get(iTableInt);
                // ZK added 19.4.2004

                // Vector vecTempTransformationValues = (Vector)
                // vecTransformationValue.get(iTableInt);

                if (dcv.size() > 0) {
                    for (int i = 0; i < dcv.size(); i++) {
                        int index = Integer.parseInt(dcv.get(i).toString());
                        if (vecTempConstantValues.get(index) == null) {
                            int str = query.indexOf("'dummyConstantValue'");
                            int num = query.indexOf("dummyConstantValue");
                            if (str != -1 && (num == -1 || str < num))
                                query = replaceFirst(query,
                                        "= 'dummyConstantValue'", " is null ");
                            else
                                query = replaceFirst(query,
                                        "= dummyConstantValue", " is null ");
                        } else {
                            query = replaceFirst(query, "dummyConstantValue",
                                    vecTempConstantValues.get(index).toString());
                        }
                    }
                }

                if (dvv.size() > 0) {
                    for (int i = 0; i < dvv.size(); i++) {
                        int index = Integer.parseInt(dvv.get(i).toString());
                        if (vecVariableValue.get(index) == null) {
                            int str = query.indexOf("'dummyVariableValue'");
                            int num = query.indexOf("dummyVariableValue");
                            if (str != -1 && (num == -1 || str < num))
                                query = replaceFirst(query,
                                        "= 'dummyVariableValue'", " is null ");
                            else
                                query = replaceFirst(query,
                                        "= dummyVariableValue", " is null ");
                        } else {
                            query = replaceFirst(query, "dummyVariableValue",
                                    vecVariableValue.get(index).toString());
                        }
                    }
                }
                // ZK added this for transformation. Key colona.
                if (dtv.size() > 0) {
                    for (int i = 0; i < dtv.size(); i++) {
                        int index = Integer.parseInt(dtv.get(i).toString());
                        if (vecTransformationValue.get(index) == null) {
                            int str = query
                                    .indexOf("'dummyTransformationValue'");
                            int num = query.indexOf("dummyTransformationValue");
                            if (str != -1 && (num == -1 || str < num))
                                query = replaceFirst(query,
                                        "= 'dummyTransformationValue'",
                                        " is null ");
                            else
                                query = replaceFirst(query,
                                        "= dummyTransformationValue",
                                        " is null ");
                        } else {
                            query = replaceFirst(query,
                                    "dummyTransformationValue",
                                    vecTransformationValue.get(index)
                                            .toString());
                        }
                    }
                }
                // ZK end
                if (query.indexOf("where") != -1)
                    strQueryWhere = query.substring(query.indexOf("where") + 5);

                stmtTarget = c.createStatement();
                boolean rowExist;
                if (bOidLogicCurrentTable && !isTOS)
                    rowExist = this.checkRowCache.getCheckRowValue(query, c,
                            this.iTargetFirstColumnResult,
                            this.currentVersionColumnName);
                else
                    rowExist = this.checkRowCache.getCheckRowValue(query, c,
                            this.iTargetFirstColumnResult, null);

                if (!rowExist) {
                    this.insertRow(c, vecColumnValues, vecColumnTypes,
                            vecColumnNames, vecColumnMode,
                            bOidLogicCurrentTable, iTableInt,
                            vecTransformationValue, transTargetColumnTypes);
                    bInsertTable = true;
                } else { // row exist = true
                    if (bOidLogicCurrentTable && !isTOS) {
                        iVersionValue = this.checkRowCache
                                .getCheckRowVersionValue();
                        if (iVersionValue > iVersionMax)
                            iVersionMax = iVersionValue;
                    }
                    if (!bInsertTable) {
                        Vector dOverwrite = (Vector) indexDOverwrite.get(key);
                        Vector dSetNull = (Vector) indexDSetNull.get(key);

                        if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
                                .indexOf("UPDATE") != -1)) {
                            if (dOverwrite.size() > 0) {
                                int start = 0;
                                for (int i = 0; i < dOverwrite.size(); i++) {
                                    Vector replacedValue = (Vector) vecDefaultValue
                                            .get(iTableInt);
                                    int index = Integer.parseInt(dOverwrite
                                            .get(i).toString());
                                    if (vecColumnValues.get(index) == null) {
                                        int str = update
                                                .indexOf("'dummyOverwrite'");
                                        int num = update
                                                .indexOf("dummyOverwrite");
                                        if (replacedValue.get(index) != "") {
                                            if (str != -1
                                                    && (num == -1 || str < num))
                                                update = replaceFirst(
                                                        update,
                                                        "'dummyOverwrite'",
                                                        " '"
                                                                + replacedValue
                                                                        .get(
                                                                                index)
                                                                        .toString()
                                                                + "' ");
                                            else
                                                update = replaceFirst(
                                                        update,
                                                        "dummyOverwrite",
                                                        " "
                                                                + replacedValue
                                                                        .get(
                                                                                index)
                                                                        .toString()
                                                                + " ");

                                            dataCleaning
                                                    .cleaningColumnValues(
                                                            this.vecTableTableName
                                                                    .get(
                                                                            iTableInt)
                                                                    .toString(),
                                                            vecColumnNames.get(
                                                                    index)
                                                                    .toString(),
                                                            replacedValue.get(
                                                                    index)
                                                                    .toString(),
                                                            currentRow,
                                                            c,
                                                            "UPDATE",
                                                            importDefinitionElement.strImportDefinitionName);
                                        } else {
                                            if (str != -1
                                                    && (num == -1 || str < num)) {
                                                String forReplace = "'dummyOverwrite'";
                                                // patch from mail list
                                                // int thisIndex =
                                                // update.indexOf("N'dummyOverwrite'");
                                                // if (thisIndex != -1 &&
                                                // thisIndex < str)
                                                if (update
                                                        .indexOf("N'dummyOverwrite'") != -1)
                                                    forReplace = "N'dummyOverwrite'";
                                                update = replaceFirst(update,
                                                        forReplace, " null ");
                                            } else {
                                                update = replaceFirst(update,
                                                        "dummyOverwrite",
                                                        " null ");
                                            }
                                        }
                                    } else {
                                        String replacement = vecColumnValues
                                                .get(index).toString();
                                        start = update.indexOf(
                                                "dummyOverwrite", start);
                                        update = update.substring(0, start)
                                                + replacement
                                                + update.substring(start + 14);
                                        start = replacement.length();
                                    }
                                }
                            }
                            if (dSetNull.size() > 0) {
                                for (int j = 0; j < dSetNull.size(); j++) {
                                    int index = Integer.parseInt(dSetNull
                                            .get(j).toString());
                                    if (vecColumnValues.get(index) == null) {
                                        update = replaceFirst(update,
                                                "dummySetNull", vecColumnNames
                                                        .get(index).toString()
                                                        + "=" + " null ");
                                    } else {
                                        update = replaceFirst(update,
                                                "dummySetNull,", "");
                                    }
                                }
                            }
                            if (dOverwrite.size() > 0 || dSetNull.size() > 0) {
                                if (bWriteData)
                                    update = replaceFirst(update,
                                            "dummyVersionOverwrite", String
                                                    .valueOf(iVersionMax));
                                else
                                    update = replaceFirst(update,
                                            "dummyVersionOverwrite", String
                                                    .valueOf(iVersionMax + 1));
                                if (bReplaceInData) {
                                    update = this.replaceInData(update);
                                    strQueryWhere = this
                                            .replaceInData(strQueryWhere);
                                }
                                relationIsOk = true;
                                updateConstantIsOk = true;
                                updateQueryIsOk = false;
                                int iNumRowUp = 0;
                                // int ver = update.indexOf("version");
                                int ver = update
                                        .indexOf(this.currentVersionColumnName);
                                int equals = update.indexOf("=");
                                try {
                                    if (equals != ver + 8) { // update set
                                        // version=1
                                        // where x=x
                                        this.logger.write("full", "\tQuery '"
                                                + update + strQueryWhere
                                                + "' will be executed");
                                        logStatement = update + strQueryWhere;
                                        iNumRowUp = stmtTarget
                                                .executeUpdate(update
                                                        + strQueryWhere);
                                    }
                                    if (iNumRowUp != 0) {
                                        if (!bWriteData)
                                            iVersionMax = iVersionMax + 1;
                                        bWriteData = true;
                                    }
                                    String tableName = this.vecTableTableName
                                            .get(iTableInt).toString();
                                    for (int i = 0; i < this.vecBlobVector
                                            .size(); i = i + 5) {
                                        if (!this.vecBlobVector.get(i + 3)
                                                .toString().equalsIgnoreCase(
                                                        "update")) {
                                            String version = "";
                                            if (oid) {
                                                if (bWriteData) {
                                                    // version += ", version = "
                                                    // + iVersionMax;
                                                    version += ", "
                                                            + this.currentVersionColumnName
                                                            + " = "
                                                            + iVersionMax;
                                                } else {
                                                    // version += ", version = "
                                                    // + (iVersionMax + 1);
                                                    version += ", "
                                                            + this.currentVersionColumnName
                                                            + "= "
                                                            + (iVersionMax + 1);
                                                }
                                            }
                                            String columnName = this.vecBlobVector
                                                    .get(i).toString();
                                            byte[] isBlob = (byte[]) this.vecBlobVector
                                                    .get(i + 1);
                                            if (isBlob != null) {
                                                ByteArrayInputStream bais = new ByteArrayInputStream(
                                                        isBlob);
                                                logStatement = "update "
                                                        + tableName + " set "
                                                        + columnName + "=(?)"
                                                        + version + " where "
                                                        + columnName
                                                        + " is null";
                                                PreparedStatement pstmt = c
                                                        .prepareStatement("update "
                                                                + tableName
                                                                + " set "
                                                                + columnName
                                                                + "=(?)"
                                                                + version
                                                                + " where "
                                                                + columnName
                                                                + " is null");
                                                pstmt.setBytes(1, isBlob);
                                                int intRowStmt = pstmt
                                                        .executeUpdate();
                                                pstmt.close();
                                                if (intRowStmt != 0) {
                                                    if (!bWriteData)
                                                        iVersionMax = iVersionMax + 1;
                                                    bWriteData = true;
                                                }
                                            }
                                        }
                                    }
                                } catch (SQLException ex) {
                                    stmtTarget.close();
                                    stmtTarget = c.createStatement();

                                    if ((importDefinitionElement.strDefaultCutOffData
                                            .equalsIgnoreCase("true"))) {
                                        dataCleaning
                                                .cutingDataLenghtUpdate(
                                                        this.vecTableTableName
                                                                .get(iTableInt)
                                                                .toString(),
                                                        c,
                                                        strQueryWhere,
                                                        currentRow,
                                                        update,
                                                        importDefinitionElement.strOnErrorContinueXml,
                                                        importDefinitionElement.strImportDefinitionName,
                                                        update + strQueryWhere);
                                    } else

                                        throw ex;
                                }
                            }
                            for (int j = 0; j < vecColumnNames.size(); j++) {
                                if (vecColumnMode.get(j).toString()
                                        .equalsIgnoreCase("Update")) {
                                    // String javaType =
                                    // configReaderTarget.getJavaTypeMapings()
                                    // .get(vecColumnTypes.get(j).toString().toUpperCase()).toString();
                                    // ZK change this 7.5.2004 from CheckType to
                                    // configReaderSource
                                    if (configReaderTarget
                                            .isBinaryObject(vecColumnTypes.get(
                                                    j).toString())) {
                                        // int
                                        // javaTypeInt=Integer.parseInt(javaType);
                                        // if (javaTypeInt==1) {
                                        for (int i = 0; i < vecBlobVector
                                                .size(); i = i + 5) {
                                            if (vecBlobVector.get(i + 3)
                                                    .toString()
                                                    .equalsIgnoreCase("update")) {
                                                if (vecBlobVector
                                                        .get(i)
                                                        .toString()
                                                        .equalsIgnoreCase(
                                                                vecColumnNames
                                                                        .get(j)
                                                                        .toString())) {
                                                    String version = "";
                                                    if (oid) {
                                                        if (bWriteData) {
                                                            // version += ",
                                                            // version = " +
                                                            // (iVersionMax);
                                                            version += ", "
                                                                    + this.currentVersionColumnName
                                                                    + " = "
                                                                    + (iVersionMax);
                                                        } else {
                                                            // version += ",
                                                            // version = " +
                                                            // (iVersionMax +
                                                            // 1);
                                                            version += ", "
                                                                    + this.currentVersionColumnName
                                                                    + " = "
                                                                    + (iVersionMax + 1);
                                                        }
                                                    }
                                                    String tableName = this.vecTableTableName
                                                            .get(iTableInt)
                                                            .toString();
                                                    String columnName = this.vecBlobVector
                                                            .get(i).toString();
                                                    byte[] isBlob = (byte[]) this.vecBlobVector
                                                            .get(i + 1);
                                                    String condition = this.vecBlobVector
                                                            .get(i + 2)
                                                            .toString();
                                                    if (isBlob != null) {
                                                        ByteArrayInputStream bais = new ByteArrayInputStream(
                                                                isBlob);
                                                        PreparedStatement pstmt = c
                                                                .prepareStatement("update "
                                                                        + tableName
                                                                        + " set "
                                                                        + columnName
                                                                        + "=(?)"
                                                                        + version
                                                                        + condition
                                                                        + strQueryWhere);
                                                        pstmt.setBytes(1,
                                                                isBlob);
                                                        this.logger
                                                                .write(
                                                                        "full",
                                                                        "\tQuery '"
                                                                                + "update "
                                                                                + tableName
                                                                                + " set "
                                                                                + columnName
                                                                                + "=BlobObject"
                                                                                + version
                                                                                + condition
                                                                                + " where "
                                                                                + strQueryWhere
                                                                                + "' will be executed");
                                                        int intRowStmt = 0;
                                                        logStatement = "update "
                                                                + tableName
                                                                + " set "
                                                                + columnName
                                                                + "=BlobObject"
                                                                + version
                                                                + condition
                                                                + " where "
                                                                + strQueryWhere;
                                                        intRowStmt = pstmt
                                                                .executeUpdate();
                                                        pstmt.close();
                                                        if (intRowStmt != 0) {
                                                            if (!bWriteData)
                                                                iVersionMax = iVersionMax + 1;
                                                            bWriteData = true;
                                                        }
                                                    }
                                                }
                                            }
                                        } // for petlja za blob
                                    } else {
                                        String strQueryUpdate = "update "
                                                + this.vecTableTableName.get(
                                                        iTableInt).toString()
                                                + " set ";
                                        strQueryUpdate += vecColumnNames.get(j)
                                                .toString()
                                                + "=";
                                        if (vecColumnValues.get(j) == null)
                                            strQueryUpdate += " null ";
                                        else {
                                            // ZK change this from CheckType to
                                            // configReaderTarget this 7.5.2004
                                            if (!configReaderTarget
                                                    .isNumber(vecColumnTypes
                                                            .get(j).toString()))
                                                strQueryUpdate += "'"
                                                        + vecColumnValues
                                                                .get(j)
                                                                .toString()
                                                        + "' ";
                                            else
                                                strQueryUpdate += vecColumnValues
                                                        .get(j).toString()
                                                        + " ";
                                        }
                                        if (oid) {
                                            if (bWriteData) {
                                                // strQueryUpdate += ", version
                                                // = " + (iVersionMax) + " where
                                                // ";
                                                strQueryUpdate += ", "
                                                        + this.currentVersionColumnName
                                                        + " = " + (iVersionMax)
                                                        + " where ";
                                            } else {
                                                // strQueryUpdate += ", version
                                                // = " + (iVersionMax + 1) + "
                                                // where ";
                                                strQueryUpdate += ", "
                                                        + this.currentVersionColumnName
                                                        + " = "
                                                        + (iVersionMax + 1)
                                                        + " where ";
                                            }
                                        } else
                                            strQueryUpdate += " where ";
                                        strQueryUpdate += vecColumnNames.get(j)
                                                .toString()
                                                + " is null and ";
                                        if (bReplaceInData) {
                                            strQueryUpdate = this
                                                    .replaceInData(strQueryUpdate);
                                            strQueryWhere = this
                                                    .replaceInData(strQueryWhere);
                                        }
                                        this.logger.write("full", "\tQuery '"
                                                + strQueryUpdate
                                                + strQueryWhere
                                                + "' will be executed");
                                        int iNumRow = 0;
                                        try {
                                            iNumRow = stmtTarget
                                                    .executeUpdate(strQueryUpdate
                                                            + strQueryWhere);
                                        } catch (SQLException ex) {
                                            stmtTarget.close();
                                            stmtTarget = c.createStatement();
                                            if ((importDefinitionElement.strDefaultCutOffData
                                                    .equalsIgnoreCase("true"))) {
                                                dataCleaning
                                                        .cutingDataLenghtUpdate(
                                                                this.vecTableTableName
                                                                        .get(
                                                                                iTableInt)
                                                                        .toString(),
                                                                c,
                                                                strQueryWhere,
                                                                currentRow,
                                                                update,
                                                                importDefinitionElement.strOnErrorContinueXml,
                                                                importDefinitionElement.strImportDefinitionName,
                                                                strQueryUpdate
                                                                        + strQueryWhere);
                                            } else
                                                throw ex;
                                        }
                                        if (iNumRow != 0) {
                                            if (!bWriteData)
                                                iVersionMax = iVersionMax + 1;
                                            bWriteData = true;
                                        }
                                    }
                                } // end of main if loop
                            }
                        }
                        for (int i = 0; i < this.iRelationColumns; i++) {
                            outLoop: if (this.vecRelationColumnSourceTableName
                                    .get(i).toString().equalsIgnoreCase(
                                            this.vecTableTableName.get(
                                                    iTableInt).toString())
                                    && this.vecRelationColumnSourceTableID.get(
                                            i).toString().equalsIgnoreCase(
                                            this.vecTableTableID.get(iTableInt)
                                                    .toString())) {
                                for (int m = 0; m < this.vecVariableUseIDTableName
                                        .size(); m++) {
                                    if (this.vecRelationColumnSourceTableName
                                            .get(i)
                                            .toString()
                                            .equalsIgnoreCase(
                                                    this.vecVariableUseIDTableName
                                                            .get(m).toString())
                                            && this.vecRelationColumnSourceTableID
                                                    .get(i)
                                                    .toString()
                                                    .equalsIgnoreCase(
                                                            this.vecVariableUseIDTableID
                                                                    .get(m)
                                                                    .toString())) {
                                        String strQueryRelations = "select "
                                                + this.vecRelationColumnSourceColumnName
                                                        .get(i).toString()
                                                + " from "
                                                + this.vecRelationColumnSourceTableName
                                                        .get(i).toString()
                                                + " where ";
                                        strQueryRelations += vecTempKeyColumns
                                                .get(0).toString()
                                                + " = ";
                                        // ZK change this from CheckType to
                                        // configReaderTarget this 7.5.2004
                                        if (!configReaderTarget
                                                .isNumber(vecColumnTypes.get(0)
                                                        .toString()))
                                            strQueryRelations += "'"
                                                    + this.strUserID + "'";
                                        else
                                            strQueryRelations += this.strUserID;

                                        if (this.vecTableTableMode.get(
                                                iTableInt).toString()
                                                .equalsIgnoreCase("cache")) {
                                            Object obj = relationsCache
                                                    .getRelationsCacheValue(strQueryRelations);
                                            if (obj != null) {
                                                if (!obj.toString()
                                                        .equalsIgnoreCase(
                                                                "#$Together#$")) {
                                                    this.vecRelationSourceValue
                                                            .setElementAt(obj,
                                                                    i);
                                                    String type = relationsCache
                                                            .getRelationsCachType(strQueryRelations);
                                                    this.vecRelationSourceType
                                                            .setElementAt(type,
                                                                    i);
                                                }
                                            } else {
                                                Statement stmtForUserID1 = c
                                                        .createStatement();
                                                ResultSet rsForUserID1 = null;
                                                try {
                                                    this.logger
                                                            .write(
                                                                    "full",
                                                                    "\tQuery '"
                                                                            + strQueryRelations
                                                                            + "' will be executed");
                                                    rsForUserID1 = stmtForUserID1
                                                            .executeQuery(strQueryRelations);
                                                } catch (SQLException ex) {
                                                    rsForUserID1.close();
                                                    stmtForUserID1.close();
                                                    dataCleaning
                                                            .cutingDataLenghtUpdate(
                                                                    this.vecTableTableName
                                                                            .get(
                                                                                    iTableInt)
                                                                            .toString(),
                                                                    c,
                                                                    strQueryWhere,
                                                                    currentRow,
                                                                    update,
                                                                    importDefinitionElement.strOnErrorContinueXml,
                                                                    importDefinitionElement.strImportDefinitionName,
                                                                    strQueryRelations);
                                                }
                                                if (rsForUserID1.next()) {
                                                    if (this.iTargetFirstColumnResult == 1) {
                                                        this.vecRelationSourceValue
                                                                .setElementAt(
                                                                        rsForUserID1
                                                                                .getObject(1),
                                                                        i);
                                                        this.vecRelationSourceType
                                                                .setElementAt(
                                                                        rsForUserID1
                                                                                .getMetaData()
                                                                                .getColumnTypeName(
                                                                                        1),
                                                                        i);
                                                        relationsCache
                                                                .setRelationsCacheValue(
                                                                        strQueryRelations,
                                                                        rsForUserID1
                                                                                .getObject(1));
                                                        relationsCache
                                                                .setRelationsCacheType(
                                                                        strQueryRelations,
                                                                        rsForUserID1
                                                                                .getMetaData()
                                                                                .getColumnTypeName(
                                                                                        1));
                                                    }
                                                } else {
                                                    relationsCache
                                                            .setRelationsCacheValue(
                                                                    strQueryRelations,
                                                                    "#$Together#$");
                                                    relationsCache
                                                            .setRelationsCacheType(
                                                                    strQueryRelations,
                                                                    "#$Together#$");
                                                }
                                                rsForUserID1.close();
                                                stmtForUserID1.close();
                                                break outLoop;
                                            }
                                        } else { // tableMode=Query
                                            this.logger
                                                    .write(
                                                            "full",
                                                            "\tQuery '"
                                                                    + strQueryRelations
                                                                    + "' will be executed");
                                            Statement stmtForUserID2 = c
                                                    .createStatement();
                                            ResultSet rsForUserID2 = null;
                                            try {
                                                rsForUserID2 = stmtForUserID2
                                                        .executeQuery(strQueryRelations);
                                            } catch (SQLException ex) {
                                                rsForUserID2.close();
                                                stmtForUserID2.close();
                                                dataCleaning
                                                        .cutingDataLenghtUpdate(
                                                                this.vecTableTableName
                                                                        .get(
                                                                                iTableInt)
                                                                        .toString(),
                                                                c,
                                                                strQueryWhere,
                                                                currentRow,
                                                                update,
                                                                importDefinitionElement.strOnErrorContinueXml,
                                                                importDefinitionElement.strImportDefinitionName,
                                                                strQueryRelations);

                                            }
                                            if (rsForUserID2.next()) {
                                              
                                                if (this.iTargetFirstColumnResult == 1) {
                                                    this.vecRelationSourceValue
                                                            .setElementAt(
                                                                    rsForUserID2
                                                                            .getObject(1),
                                                                    i);
                                                    this.vecRelationSourceType
                                                            .setElementAt(
                                                                    rsForUserID2
                                                                            .getMetaData()
                                                                            .getColumnTypeName(
                                                                                    1),
                                                                    i);

                                                } else {
                                                    this.vecRelationSourceValue
                                                            .setElementAt(
                                                                    rsForUserID2
                                                                            .getObject(0),
                                                                    i);
                                                    this.vecRelationSourceType
                                                            .setElementAt(
                                                                    rsForUserID2
                                                                            .getMetaData()
                                                                            .getColumnTypeName(
                                                                                    0),
                                                                    i);
                                                }
                                            }
                                            rsForUserID2.close();
                                            stmtForUserID2.close();
                                            break outLoop;
                                        }
                                    }
                                } // end of vecVariableUseIDTableName loop
                                String strQueryRelations = "select "
                                        + this.vecRelationColumnSourceColumnName
                                                .get(i).toString()
                                        + " from "
                                        + this.vecRelationColumnSourceTableName
                                                .get(i).toString() + " where "
                                        + strQueryWhere;
                                if (this.vecTableTableMode.get(iTableInt)
                                        .toString().equalsIgnoreCase("cache")) {
                                    Object obj = relationsCache
                                            .getRelationsCacheValue(strQueryRelations);
                                    if (obj != null) {
                                        if (!obj.toString().equalsIgnoreCase(
                                                "#$Together#$")) {
                                            this.vecRelationSourceValue
                                                    .setElementAt(obj, i);
                                            String type = relationsCache
                                                    .getRelationsCachType(strQueryRelations);
                                            this.vecRelationSourceType
                                                    .setElementAt(type, i);
                                        }
                                    } else {
                                        Statement stmtForRel1 = c
                                                .createStatement();
                                        ResultSet rsForRel1 = null;
                                        try {
                                            this.logger
                                                    .write(
                                                            "full",
                                                            "\tQuery '"
                                                                    + strQueryRelations
                                                                    + "' will be executed");
                                            rsForRel1 = stmtForRel1
                                                    .executeQuery(strQueryRelations);
                                        } catch (SQLException ex) {
                                            rsForRel1.close();
                                            stmtForRel1.close();
                                            dataCleaning
                                                    .cutingDataLenghtUpdate(
                                                            this.vecTableTableName
                                                                    .get(
                                                                            iTableInt)
                                                                    .toString(),
                                                            c,
                                                            strQueryWhere,
                                                            currentRow,
                                                            update,
                                                            importDefinitionElement.strOnErrorContinueXml,
                                                            importDefinitionElement.strImportDefinitionName,
                                                            strQueryRelations);
                                        }

                                        if (rsForRel1.next()) {
                                            String relVal=getSQLRelationString(rsForRel1); //senka added
                                            if (this.iTargetFirstColumnResult == 1) {
                                               // this.vecRelationSourceValue
                                               //         .setElementAt(rsForRel1
                                               //                 .getObject(1),
                                               //                 i);
                                               // senka change
                                                this.vecRelationSourceValue
                                                 .setElementAt(relVal,
                                                         i); 
                                               
                                                this.vecRelationSourceType
                                                        .setElementAt(
                                                                rsForRel1
                                                                        .getMetaData()
                                                                        .getColumnTypeName(
                                                                                1),
                                                                i);
                                              //  relationsCache
                                              //          .setRelationsCacheValue(
                                              //                  strQueryRelations,
                                              //                  rsForRel1
                                              //                          .getObject(1));
                                              // senka change
                                                relationsCache
                                                        .setRelationsCacheValue(
                                                                strQueryRelations,
                                                                relVal
                                                                );
                                                relationsCache
                                                        .setRelationsCacheType(
                                                                strQueryRelations,
                                                                rsForRel1
                                                                        .getMetaData()
                                                                        .getColumnTypeName(
                                                                                1));
                                            } else {
                                               // this.vecRelationSourceValue
                                               //         .setElementAt(rsForRel1
                                              //                  .getObject(0),
                                              //                  i);
                                              // senka change
                                                this.vecRelationSourceValue
                                                        .setElementAt(relVal,                                                           
                                                                i);
                                                this.vecRelationSourceType
                                                        .setElementAt(
                                                                rsForRel1
                                                                        .getMetaData()
                                                                        .getColumnTypeName(
                                                                                0),
                                                                i);
                                              //  relationsCache
                                             //           .setRelationsCacheValue(
                                            //                    strQueryRelations,
                                            //                    rsForRel1
                                            //                            .getObject(0));
                                              // senka change
                                                relationsCache
                                                        .setRelationsCacheValue(
                                                                strQueryRelations,
                                                                relVal
                                                                );
                                                relationsCache
                                                        .setRelationsCacheType(
                                                                strQueryRelations,
                                                                rsForRel1
                                                                        .getMetaData()
                                                                        .getColumnTypeName(
                                                                                0));
                                            }
                                        } else {
                                            relationsCache
                                                    .setRelationsCacheValue(
                                                            strQueryRelations,
                                                            "#$Together#$");
                                            relationsCache
                                                    .setRelationsCacheType(
                                                            strQueryRelations,
                                                            "#$Together#$");
                                        }
                                        rsForRel1.close();
                                        stmtForRel1.close();
                                    }
                                } else { // tableMode=Query

                                    Statement stmtForRel2 = c.createStatement();
                                    ResultSet rsForRel2 = null;
                                    try {
                                        this.logger.write("full", "\tQuery '"
                                                + strQueryRelations
                                                + "' will be executed");
                                        rsForRel2 = stmtForRel2
                                                .executeQuery(strQueryRelations);
                                    } catch (SQLException ex) {
                                        rsForRel2.close();
                                        stmtForRel2.close();
                                        dataCleaning
                                                .cutingDataLenghtUpdate(
                                                        this.vecTableTableName
                                                                .get(iTableInt)
                                                                .toString(),
                                                        c,
                                                        strQueryWhere,
                                                        currentRow,
                                                        update,
                                                        importDefinitionElement.strOnErrorContinueXml,
                                                        importDefinitionElement.strImportDefinitionName,
                                                        strQueryRelations);
                                    }
                                    if (rsForRel2.next()) {
                                      String relVal2=getSQLRelationString(rsForRel2); //senka added
                                        if (this.iTargetFirstColumnResult == 1) {
                                           // this.vecRelationSourceValue
                                           //         .setElementAt(rsForRel2
                                           //                 .getObject(1), i);
                                          // senka   
                                          this.vecRelationSourceValue
                                             .setElementAt(relVal2, i);
                                            this.vecRelationSourceType
                                                    .setElementAt(rsForRel2
                                                            .getMetaData()
                                                            .getColumnTypeName(
                                                                    1), i);
                                        } else {
                                            //this.vecRelationSourceValue
                                            //        .setElementAt(rsForRel2
                                            //                .getObject(0), i);
//                                           senka   
                                          this.vecRelationSourceValue
                                            .setElementAt(relVal2, i);
                                            this.vecRelationSourceType
                                                    .setElementAt(rsForRel2
                                                            .getMetaData()
                                                            .getColumnTypeName(
                                                                    0), i);
                                        }
                                    }
                                    rsForRel2.close();
                                    stmtForRel2.close();
                                }
                            }
                        }

                        for (int i = 0; i < this.vecRelationColumnTargetColumnName
                                .size(); i++) {
                            if (this.vecRelationColumnTargetTableName.get(i)
                                    .toString().equalsIgnoreCase(
                                            this.vecTableTableName.get(
                                                    iTableInt).toString())
                                    && this.vecRelationColumnTargetTableID.get(
                                            i).toString().equalsIgnoreCase(
                                            this.vecTableTableID.get(iTableInt)
                                                    .toString())) {
                                int currentVersion = 0;
                                if (bWriteData)
                                    currentVersion = iVersionMax;
                                else
                                    currentVersion = iVersionMax + 1;

                                if (this.vecRelationColumnRelationMode.get(i)
                                        .toString().equalsIgnoreCase("SetNull")) {
                                    if (this.vecRelationSourceValue.get(i) == null) {
                                        String strUpdateRelations = this
                                                .queryRelations(iTableInt, i,
                                                        strQueryWhere, c,
                                                        currentVersion, oid);
                                        this.logger.write("full", "\tQuery '"
                                                + strUpdateRelations
                                                + "' will be executed");
                                        if (bReplaceInData) {
                                            strUpdateRelations = this
                                                    .replaceInData(strUpdateRelations);
                                        }
                                        int iNumRow = 0;
                                        logStatement = strUpdateRelations;
                                        iNumRow = stmtTarget
                                                .executeUpdate(strUpdateRelations);
                                        this.vecRelationSourceValue
                                                .setElementAt(null, i);
                                        // this.vecRelationSourceType.setElementAt(null,i);
                                        if (iNumRow != 0) {
                                            if (!bWriteData)
                                                iVersionMax = iVersionMax + 1;
                                            bWriteData = true;
                                        }
                                    }
                                } else if (this.vecRelationColumnRelationMode
                                        .get(i).toString().equalsIgnoreCase(
                                                "Overwrite")
                                        || (this.vecRelationColumnRelationMode
                                                .get(i).toString()
                                                .equalsIgnoreCase("Update"))) {

                                    // for handling exception in FK
                                    replacementValueInRel = vecDefaultRelationValue
                                            .get(i).toString();
                                    replacementTable = vecRelationColumnTargetTableName
                                            .get(i).toString();
                                    replacementColumn = vecRelationColumnTargetColumnName
                                            .get(i).toString();
                                    // replacementColumnType =
                                    // this.vecRelationSourceType.get(i).toString();
                                    String strUpdateRelations = this
                                            .queryRelations(iTableInt, i,
                                                    strQueryWhere, c,
                                                    currentVersion, oid);
                                    this.logger.write("full", "\tQuery '"
                                            + strUpdateRelations
                                            + "' will be executed");
                                    if (bReplaceInData) {
                                        strUpdateRelations = this
                                                .replaceInData(strUpdateRelations);
                                    }
                                    // only for catch exceptions in foreign keys
                                    // statement
                                    exceptionInRelations = strUpdateRelations;
                                    updateQueryIsOk = true;
                                    updateConstantIsOk = true;
                                    relationIsOk = false;
                                    int iNumRow = 0;
                                    try {
                                        logStatement = strUpdateRelations;
                                        iNumRow = stmtTarget
                                                .executeUpdate(strUpdateRelations);
                                        this.vecRelationSourceValue
                                                .setElementAt(null, i);
                                        // this.vecRelationSourceType.setElementAt(null,i);
                                    } catch (SQLException ex) {
                                        stmtTarget.close();

                                        stmtTarget = c.createStatement();
                                        if ((importDefinitionElement.strDefaultCutOffData
                                                .equalsIgnoreCase("true"))) {
                                            dataCleaning
                                                    .cutingDataLenghtUpdate(
                                                            this.vecTableTableName
                                                                    .get(
                                                                            iTableInt)
                                                                    .toString(),
                                                            c,
                                                            strQueryWhere,
                                                            currentRow,
                                                            update,
                                                            importDefinitionElement.strOnErrorContinueXml,
                                                            importDefinitionElement.strImportDefinitionName,
                                                            strUpdateRelations);
                                        } else
                                            throw ex;
                                    }
                                    if (iNumRow != 0) {
                                        if (!bWriteData)
                                            iVersionMax = iVersionMax + 1;
                                        bWriteData = true;
                                    }
                                }
                            }
                        }

                        if (this.vecTableInsert.get(iTableInt).toString()
                                .equalsIgnoreCase("true")) {
                            if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
                                    .indexOf("UPDATE") != -1)) {
                                if (vecTempConstantColumns.size() > 0) {
                                    if (updateConstant.indexOf(",") != -1)
                                        updateConstant = updateConstant
                                                .substring(0, updateConstant
                                                        .lastIndexOf(","));

                                    Vector cOverwrite = (Vector) indexDConstantOver
                                            .get(key);
                                    Vector cNull = (Vector) indexDConstantNull
                                            .get(key);
                                    strQueryConstantApendix = "";
                                    if (cOverwrite.size() > 0) {
                                        int startOver = 0;
                                        for (int i = 0; i < cOverwrite.size(); i++) {
                                            int index = Integer
                                                    .parseInt(cOverwrite.get(i)
                                                            .toString());
                                            if (vecTempConstantValues
                                                    .get(index) == null) {
                                                int str = updateConstant
                                                        .indexOf("'dummyConstantOver'");
                                                int num = updateConstant
                                                        .indexOf("dummyConstantOver");
                                                if (str != -1
                                                        && (num == -1 || str < num))
                                                    updateConstant = replaceFirst(
                                                            updateConstant,
                                                            "'dummyConstantOver'",
                                                            " null ");
                                                else
                                                    updateConstant = replaceFirst(
                                                            updateConstant,
                                                            "dummyConstantOver",
                                                            " null ");
                                            } else {
                                                String replacement = vecTempConstantValues
                                                        .get(index).toString();
                                                startOver = updateConstant
                                                        .indexOf(
                                                                "dummyConstantOver",
                                                                startOver);
                                                updateConstant = updateConstant
                                                        .substring(0, startOver)
                                                        + replacement
                                                        + updateConstant
                                                                .substring(startOver + 17);
                                                startOver = replacement
                                                        .length();
                                            }
                                        }
                                    }
                                    if (cNull.size() > 0) {
                                        int startNull = 0;
                                        for (int i = 0; i < cNull.size(); i++) {
                                            int index = Integer.parseInt(cNull
                                                    .get(i).toString());
                                            if (vecTempConstantValues
                                                    .get(index) == null) {
                                                int str = updateConstant
                                                        .indexOf("'dummyConstantNull'");
                                                int num = updateConstant
                                                        .indexOf("dummyConstantNull");
                                                if (str != -1
                                                        && (num == -1 || str < num))
                                                    updateConstant = replaceFirst(
                                                            updateConstant,
                                                            "'dummyConstantNull'",
                                                            " null ");
                                                else
                                                    updateConstant = replaceFirst(
                                                            updateConstant,
                                                            "dummyConstantNull",
                                                            " null ");

                                                strQueryConstantApendix += " and "
                                                        + vecTempConstantColumns
                                                                .get(index)
                                                                .toString()
                                                        + " is null ";
                                            } else {
                                                String replacement = vecTempConstantValues
                                                        .get(index).toString();
                                                startNull = updateConstant
                                                        .indexOf(
                                                                "dummyConstantNull",
                                                                startNull);
                                                updateConstant = updateConstant
                                                        .substring(0, startNull)
                                                        + replacement
                                                        + updateConstant
                                                                .substring(startNull + 17);
                                                startNull = replacement
                                                        .length();
                                            }
                                        }
                                    }

                                    if (bReplaceInData) {
                                        // System.out.println("bReplaceInData: "
                                        // + bReplaceInData);
                                        updateConstant = this
                                                .replaceInData(updateConstant);
                                        strQueryWhere = this
                                                .replaceInData(strQueryWhere);
                                    }

                                    if (oid) {
                                        if (bWriteData) {
                                            // updateConstant += ", version = "
                                            // + (iVersionMax);
                                            updateConstant += ", "
                                                    + this.currentVersionColumnName
                                                    + " = " + (iVersionMax);
                                        } else {
                                            // updateConstant += ", version = "
                                            // + (iVersionMax + 1);
                                            updateConstant += ", "
                                                    + this.currentVersionColumnName
                                                    + " = " + (iVersionMax + 1);
                                        }
                                    }
                                    updateQueryIsOk = true;
                                    relationIsOk = true;
                                    updateConstantIsOk = false;
                                    int iNumRow = 0;
                                    try {
                                        if (!updateConstant.endsWith(" set ")) {
                                            this.logger
                                                    .write(
                                                            "full",
                                                            "\tQuery '"
                                                                    + updateConstant
                                                                    + " where "
                                                                    + strQueryWhere
                                                                    + strQueryConstantApendix
                                                                    + "' will be executed");
                                            logStatement = updateConstant
                                                    + " where " + strQueryWhere;
                                            iNumRow = stmtTarget
                                                    .executeUpdate(updateConstant
                                                            + " where "
                                                            + strQueryWhere
                                                            + strQueryConstantApendix);
                                        }
                                    } catch (SQLException ex) {
                                        stmtTarget.close();

                                        stmtTarget = c.createStatement();
                                        if ((importDefinitionElement.strDefaultCutOffData
                                                .equalsIgnoreCase("true"))) {
                                            dataCleaning
                                                    .cutingDataLenghtUpdate(
                                                            this.vecTableTableName
                                                                    .get(
                                                                            iTableInt)
                                                                    .toString(),
                                                            c,
                                                            " where "
                                                                    + strQueryWhere
                                                                    + strQueryConstantApendix,
                                                            currentRow,
                                                            updateConstant,
                                                            importDefinitionElement.strOnErrorContinueXml,
                                                            importDefinitionElement.strImportDefinitionName,
                                                            updateConstant
                                                                    + " where "
                                                                    + strQueryWhere
                                                                    + strQueryConstantApendix);
                                        } else
                                            throw ex;
                                    }
                                    if (iNumRow != 0) {
                                        if (!bWriteData)
                                            iVersionMax = iVersionMax + 1;
                                        bWriteData = true;
                                    }
                                }
                                if (this.vecVariableTimesTableName.size() != 0) {
                                    int currentVersion = 0;
                                    boolean bool = false;
                                    if (!bWriteData)
                                        currentVersion = iVersionMax + 1;
                                    else
                                        currentVersion = iVersionMax;
                                    bool = this.updateCurrentTime(c, iTableInt,
                                            strQueryWhere, currentVersion, oid);
                                    if (bool) {
                                        if (!bWriteData)
                                            iVersionMax = iVersionMax + 1;
                                        bWriteData = true;
                                    }
                                }
                                if (this.vecVariableColumnTargetTableName
                                        .size() != 0) {
                                    int currentVersion = 0;
                                    boolean bool = false;
                                    if (!bWriteData)
                                        currentVersion = iVersionMax + 1;
                                    else
                                        currentVersion = iVersionMax;
                                    try {
                                        bool = this.updateNameValue(c,
                                                iTableInt, strQueryWhere,
                                                currentVersion, oid);
                                    } catch (SQLException ex) {
                                        throw ex;
                                    }
                                    if (bool) {
                                        if (!bWriteData)
                                            iVersionMax = iVersionMax + 1;
                                        bWriteData = true;
                                    }
                                }
                            }
                        } // insertTable=true
                        // ZK added this 17.5.2004
                        // System.out.println("iTableInt="+iTableInt);
                        // System.out.println("update + strQueryWhere="+update +
                        // strQueryWhere);

                        if (this.vecTableInsert.get(iTableInt).toString()
                                .equalsIgnoreCase("true")) {
                            if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
                                    .indexOf("UPDATE") != -1)) {

                                // if(((Vector)transformationsColumnNames.get(iTableInt)).size()
                                // > 0){

                                // System.out.println("updateTransformation =
                                // "+updateTransformation);
                                // System.out.println("transformedValues="+transformedValues);

                                Vector tOverwrite = (Vector) indexDTransformationOver
                                        .get(key);
                                Vector tNull = (Vector) indexDTransformationNull
                                        .get(key);

                                if ((updateTransformation.indexOf(",") != -1))
                                    updateTransformation = updateTransformation
                                            .substring(0, updateTransformation
                                                    .lastIndexOf(","));

                                if (tOverwrite.size() > 0) {
                                    int startOver = 0;
                                    for (int i = 0; i < tOverwrite.size(); i++) {
                                        int index = Integer.parseInt(tOverwrite
                                                .get(i).toString());
                                        if (vecTransformationValue.get(index) == null) {

                                            int str = updateTransformation
                                                    .indexOf("'dummyTransformationOver'");
                                            int num = updateTransformation
                                                    .indexOf("dummyTransformationOver");
                                            if (str != -1
                                                    && (num == -1 || str < num))
                                                updateTransformation = replaceFirst(
                                                        updateTransformation,
                                                        "'dummyTransformationOver'",
                                                        " null ");
                                            else
                                                updateTransformation = replaceFirst(
                                                        updateTransformation,
                                                        "dummyTransformationOver",
                                                        " null ");
                                        } else {
                                            String replacement = vecTransformationValue
                                                    .get(index).toString();
                                            startOver = updateTransformation
                                                    .indexOf(
                                                            "dummyTransformationOver",
                                                            startOver);
                                            updateTransformation = updateTransformation
                                                    .substring(0, startOver)
                                                    + replacement
                                                    + updateTransformation
                                                            .substring(startOver + 23);
                                            startOver = replacement.length();

                                        }

                                    }
                                }

                                if (tNull.size() > 0) {
                                    int startNull = 0;
                                    for (int i = 0; i < tNull.size(); i++) {
                                        int index = Integer.parseInt(tNull.get(
                                                i).toString());
                                        String colName = ((Vector) transformationsColumnNames
                                                .get(iTableInt)).get(index)
                                                .toString();
                                        if (vecTransformationValue.get(index) == null) {
                                            updateTransformation = replaceFirst(
                                                    updateTransformation,
                                                    "dummyTransformationNull",
                                                    colName + " = null ");
                                        } else {
                                            updateTransformation = replaceFirst(
                                                    updateTransformation,
                                                    "dummyTransformationNull,",
                                                    "  ");
                                        }
                                    }
                                }

                                if ((tOverwrite.size() > 0)
                                        || (tNull.size() > 0)) {

                                    if (bReplaceInData) {
                                        updateTransformation = this
                                                .replaceInData(updateTransformation);
                                        strQueryWhere = this
                                                .replaceInData(strQueryWhere);
                                    }

                                    if (oid) {
                                        if (bWriteData) {
                                            updateTransformation += ", "
                                                    + this.currentVersionColumnName
                                                    + " = " + (iVersionMax);
                                        } else {
                                            updateTransformation += ", "
                                                    + this.currentVersionColumnName
                                                    + " = " + (iVersionMax + 1);
                                        }
                                    }

                                    int iNumRow = 0;
                                    try {
                                        if (!updateTransformation
                                                .endsWith(" set ")) {
                                            this.logger
                                                    .write(
                                                            "full",
                                                            "\tQuery '"
                                                                    + updateTransformation
                                                                    + " where "
                                                                    + strQueryWhere
                                                                    + "' will be executed");
                                            logStatement = updateTransformation
                                                    + " where " + strQueryWhere;
                                            iNumRow = stmtTarget
                                                    .executeUpdate(updateTransformation
                                                            + " where "
                                                            + strQueryWhere);
                                        }
                                    } catch (SQLException ex) {
                                        stmtTarget.close();
                                        throw ex;
                                    }

                                    if (iNumRow != 0) {
                                        if (!bWriteData)
                                            iVersionMax = iVersionMax + 1;
                                        bWriteData = true;
                                    }

                                }

                            }// this is my
                        }// END IF
                        // ZK added 20.5 2004 for "Update" mode
                        if (this.vecTableInsert.get(iTableInt).toString()
                                .equalsIgnoreCase("true")) {
                            if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
                                    .indexOf("UPDATE") != -1)) {

                                // if(((Vector)transformationsColumnNames.get(iTableInt)).size()
                                // > 0){
                                Vector tUpdate = (Vector) indexDTransformationUpdate
                                        .get(key);
                                if (tUpdate.size() > 0) {
                                    // int startUpdate = 0;
                                    for (int j = 0; j < tUpdate.size(); j++) {
                                        int index = Integer.parseInt(tUpdate
                                                .get(j).toString());
                                        Vector tempTransValueModes = (Vector) transformationsValueModes
                                                .get(iTableInt);
                                        Vector tempTransColumnNames = (Vector) transformationsColumnNames
                                                .get(iTableInt);
                                        Vector tempTransColumnTypes = (Vector) transformationsColumnTypes
                                                .get(iTableInt);
                                        if (tempTransValueModes.get(index)
                                                .toString().equalsIgnoreCase(
                                                        "Update")) {

                                            String strQueryUpdate = "update "
                                                    + this.vecTableTableName
                                                            .get(iTableInt)
                                                            .toString()
                                                    + " set ";
                                            strQueryUpdate += tempTransColumnNames
                                                    .get(index).toString()
                                                    + "=";
                                            if (vecTransformationValue
                                                    .get(index) == null)
                                                strQueryUpdate += " null ";
                                            else {

                                                if (!configReaderTarget
                                                        .isNumber(tempTransColumnTypes
                                                                .get(index)
                                                                .toString()))
                                                    strQueryUpdate += "'"
                                                            + vecTransformationValue
                                                                    .get(index)
                                                                    .toString()
                                                            + "' ";
                                                else
                                                    strQueryUpdate += vecTransformationValue
                                                            .get(index)
                                                            .toString()
                                                            + " ";
                                            }
                                            if (oid) {
                                                if (bWriteData) {

                                                    strQueryUpdate += ", "
                                                            + this.currentVersionColumnName
                                                            + " = "
                                                            + (iVersionMax)
                                                            + " where ";
                                                } else {

                                                    strQueryUpdate += ", "
                                                            + this.currentVersionColumnName
                                                            + " = "
                                                            + (iVersionMax + 1)
                                                            + " where ";
                                                }
                                            }
                                            // strQueryUpdate += " where ";
                                            strQueryUpdate += tempTransColumnNames
                                                    .get(j).toString()
                                                    + " is null and ";

                                            if (bReplaceInData) {
                                                strQueryUpdate = this
                                                        .replaceInData(strQueryUpdate);
                                                strQueryWhere = this
                                                        .replaceInData(strQueryWhere);
                                            }
                                            this.logger
                                                    .write(
                                                            "full",
                                                            "\tQuery '"
                                                                    + strQueryUpdate
                                                                    + strQueryWhere
                                                                    + "' will be executed");
                                            int iNumRow = 0;
                                            try {
                                                logStatement = strQueryUpdate
                                                        + strQueryWhere;
                                                iNumRow = stmtTarget
                                                        .executeUpdate(strQueryUpdate
                                                                + strQueryWhere);
                                            } catch (SQLException ex) {
                                                stmtTarget.close();
                                                stmtTarget = c
                                                        .createStatement();
                                                if ((importDefinitionElement.strDefaultCutOffData
                                                        .equalsIgnoreCase("true"))) {
                                                    dataCleaning
                                                            .cutingDataLenghtUpdate(
                                                                    this.vecTableTableName
                                                                            .get(
                                                                                    iTableInt)
                                                                            .toString(),
                                                                    c,
                                                                    strQueryWhere,
                                                                    currentRow,
                                                                    update,
                                                                    importDefinitionElement.strOnErrorContinueXml,
                                                                    importDefinitionElement.strImportDefinitionName,
                                                                    strQueryUpdate
                                                                            + strQueryWhere);
                                                } else
                                                    throw ex;
                                            }
                                            if (iNumRow != 0) {
                                                if (!bWriteData)
                                                    iVersionMax = iVersionMax + 1;
                                                bWriteData = true;
                                            }

                                        }
                                        // }
                                    }
                                }
                            }
                        }

                        // ZK END
                    }

                    // checkRowCache.setCheckRowVersionValue(String
                    // .valueOf(iVersionMax - 1));
                }
                stmtTarget.close();

            }
        }
        // }
        catch (SQLException ex) {

            if (stmtTarget != null)
                stmtTarget.close();
            if ((importDefinitionElement.strDefaultCutOffData
                    .equalsIgnoreCase("true"))) {
                dataCleaning.cleaningInsert(this.vecTableTableName.get(
                        iTableInt).toString(), c, currentRow, "UPDATE", ex
                        .getMessage(),
                        importDefinitionElement.strImportDefinitionName,
                        logStatement);
                // } else if (
                // (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("false")
                // ||
                // importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase(""))
                // &&
                // importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true"))
                // {
                // dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(),
                // c, currentRow, "UPDATE", ex.getMessage(),
                // importDefinitionElement.strImportDefinitionName);
            } else {
                this.logger.write("normal",
                        "\tDataCleaning features is not turn on.");
                throw ex;
            }
        } catch (NullPointerException ex) {
            throw ex;
        } catch (Exception ex) {

            throw ex;
        }
        this.logger.write("full", "\tinsertTargetTable method is finished.");
    }

    /**
     * Method insertRow is used to insert new row in the target table. Also
     * includes inserting values into constant, variable and relation columns of
     * the target table. If there is an error, Exception "SQLException" or
     * "NullPointerException" or "Exception" is thrown.
     * 
     * @param c
     *            Connection to the target database.
     * @param vecColumnValues
     *            One row of values from source table.
     * @param vecColumnNamesTypes
     *            Types of columns in a target table.
     * @param vecColumnNames
     *            Vector of column names in a target table.
     * @param bOIDlogicValue
     *            true if oid column exists in the target table.
     * @param iTableInt
     *            Number of target table which is processed.
     * @param vecColumnMode
     *            represents vector of table modes for currnet table
     * @throws SQLException
     *             Constructs an SQLException object with a reason.
     * @throws NullPointerException
     *             Constructs a NullPointerException with the specified detail
     *             message.
     * @throws Exception
     *             Constructs an Exception with the specified detail message.
     */
    private void insertRow(Connection c, Vector vecColumnValues,
            Vector vecColumnNamesTypes, Vector vecColumnNames,
            Vector vecColumnMode, boolean bOIDlogicValue, int iTableInt,
            Vector vecTransformationValue,
            Vector transformationTargetColumnTypes) throws SQLException,
            NullPointerException, Exception {

        String key = String.valueOf(iTableInt);
        String strInsertRow = (String) queryInsertRow.get(key);
        Vector indexOfNotRelationColumns = (Vector) indexIsNotRelationsColumns
                .get(key);

        PreparedStatement pstmt = (PreparedStatement) pstmtForInsert.get(key);

        Vector pstmtColNames = (Vector) pstmtColumnNames.get(key);
        Vector pstmtValues = new Vector();
        Vector pstmtTypes = new Vector();
        // hendling select statement in relation tag!
        String selectValueInRel = "";
        String currentValueInRel = "";

        this.logger.write("full", "\tinsertRow method is started.");
        String strQuery = "";
        boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
                .equals("") || importDefinitionElement.strObjectIDNameColumnValue
                .equals(""));
        // sinisa 15.03.2003. Add subCouterColumns
        Vector subCounterKeyColumns = this.counterColumns
                .getSubCounterKeyColumns(this.vecTableTableName.get(iTableInt)
                        .toString(), this.vecTableTableID.get(iTableInt)
                        .toString());

        Hashtable subKeyValues = new Hashtable();
        try {
            Vector vecTempConstantColumns = (Vector) this.vecConstantTargetColumnName
                    .get(iTableInt);
            Vector vecTempConstantValues = (Vector) this.vecConstantConstantValue
                    .get(iTableInt);
            strInsertRow = strInsertRow.trim();
            int comma = strInsertRow.lastIndexOf(",");
            if (comma == (strInsertRow.length() - 1))
                strQuery = strInsertRow.substring(0, strInsertRow.length() - 1);
            else
                strQuery = strInsertRow;
            if (bOIDlogicValue) {
                if (isTOS) {
                    pstmtValues.add(this.bdecOidNumber);
                    pstmtTypes.add("java.math.BigDecimal");
                } else {
                    pstmtValues.add(this.bdecOidNumber);
                    pstmtValues.add(String.valueOf(0));
                    pstmtTypes.add("java.math.BigDecimal");
                    pstmtTypes.add("java.lang.Integer");
                }
            }

            strQuery = strQuery + ") VALUES (";

            if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase(
                    "true")) {
                if (indexOfNotRelationColumns.size() > 0) {
                    for (int k = 0; k < indexOfNotRelationColumns.size(); k++) {
                        int index = Integer.parseInt(indexOfNotRelationColumns
                                .get(k).toString());
                        Vector replacedValue = (Vector) vecDefaultValue
                                .get(iTableInt);
                        if (vecColumnValues.get(index) == null) {
                            if (replacedValue.get(index) != "") {
                                pstmtValues.add(replacedValue.get(index)
                                // .toString()
                                        );
                                pstmtTypes.add(vecColumnNamesTypes.get(index)
                                        .toString());
                                dataCleaning
                                        .cleaningColumnValues(
                                                this.vecTableTableName.get(
                                                        iTableInt).toString(),
                                                vecColumnNames.get(index)
                                                        .toString(),
                                                replacedValue.get(index)
                                                        .toString(),
                                                currentRow,
                                                c,
                                                "INSERT",
                                                importDefinitionElement.strImportDefinitionName);
                            } else {
                                pstmtValues.add("null");
                                pstmtTypes.add(vecColumnNamesTypes.get(index)
                                        .toString());
                            }
                        } else {
                            pstmtValues.add(vecColumnValues.get(index)
                            // .toString()
                                    );
                            pstmtTypes.add(vecColumnNamesTypes.get(index)
                                    .toString());
                        }

                        // sinisa 15.03 Add subCounter columns
                        for (int l = 0; l < subCounterKeyColumns.size(); l++) {
                            if (subCounterKeyColumns.get(l) != null
                                    && ((Vector) subCounterKeyColumns.get(l))
                                            .size() != 0
                                    && ((Vector) subCounterKeyColumns.get(l))
                                            .contains(vecColumnNames.get(index)
                                                    .toString())) {
                                if (vecColumnValues.get(index) != null) {
                                    subKeyValues.put(vecColumnNames.get(index)
                                            .toString(), vecColumnValues.get(
                                            index).toString());
                                }
                            }
                        }
                    }
                }
            }
            if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase(
                    "true")) {
                for (int p = 0; p < vecTempConstantValues.size(); p++) {
                    if (vecTempConstantValues.get(p) == null) {
                        pstmtValues.add("null");
                        pstmtTypes.add(((Vector) this.vecConstantColumnType
                                .get(iTableInt)).get(p).toString());
                    } else {
                        pstmtValues.add(vecTempConstantValues.get(p)
                        // .toString()
                                );
                        pstmtTypes.add(((Vector) this.vecConstantColumnType
                                .get(iTableInt)).get(p).toString());

                    }
                    // sinisa 15.03 Add subCounter columns
                    for (int l = 0; l < subCounterKeyColumns.size(); l++) {
                        if (subCounterKeyColumns.get(l) != null
                                && ((Vector) subCounterKeyColumns.get(l))
                                        .size() != 0
                                && ((Vector) subCounterKeyColumns.get(l))
                                        .contains(vecTempConstantColumns.get(p))) {
                            if (vecTempConstantValues.get(p) != null)
                                subKeyValues.put(vecTempConstantColumns.get(p)
                                        .toString(), vecTempConstantValues.get(
                                        p).toString());
                        }
                    }
                }
            }
            if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase(
                    "true")) {
                for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
                    if (this.vecVariableTimesTableName.get(i).toString()
                            .equalsIgnoreCase(
                                    this.vecTableTableName.get(iTableInt)
                                            .toString())
                            && this.vecVariableTimesTableID.get(i).toString()
                                    .equalsIgnoreCase(
                                            this.vecTableTableID.get(iTableInt)
                                                    .toString())) {
                        pstmtValues.add(createCurrentDate());
                        pstmtTypes.add("java.sql.Date");
                    }
                }
                for (int i = 0; i < this.vecVariableColumnTargetTableName
                        .size(); i++) {
                    if (this.vecVariableColumnTargetTableName.get(i).toString()
                            .equalsIgnoreCase(
                                    this.vecTableTableName.get(iTableInt)
                                            .toString())
                            && this.vecVariableColumnTargetTableID.get(i)
                                    .toString().equalsIgnoreCase(
                                            this.vecTableTableID.get(iTableInt)
                                                    .toString())) {
                        int iPositionInVector = this.vecVariableName
                                .indexOf(this.vecVariableColumnName.get(i)
                                        .toString());
                        if (iPositionInVector != -1) {
                            if (this.vecVariableValue.get(iPositionInVector) == null) {
                                String variableName = this.vecVariableColumnName
                                        .get(i).toString();
                                for (int k = 0; k < this.vecDefaultVariableName
                                        .size(); k++) {
                                    if (this.vecDefaultVariableName.get(k)
                                            .toString().equalsIgnoreCase(
                                                    variableName)) {
                                        if (!this.vecDefaultVariableValue
                                                .get(k).toString()
                                                .equalsIgnoreCase("")) {
                                            pstmtValues
                                                    .add(this.vecDefaultVariableValue
                                                            .get(k)
                                                    // .toString()
                                                    );
                                            pstmtTypes
                                                    .add(this.vecVariableColumnTypes
                                                            .get(i).toString());
                                        } else {
                                            pstmtValues.add("null");
                                            pstmtTypes
                                                    .add(this.vecVariableColumnTypes
                                                            .get(i).toString());
                                        }
                                        break;
                                    }
                                }
                            } else {
                                pstmtValues.add(this.vecVariableValue
                                        .get(iPositionInVector)
                                // .toString()
                                        );
                                pstmtTypes.add(this.vecVariableColumnTypes.get(
                                        i).toString());
                            }
                        } else {
                            this.logger.write("normal",
                                    "\tError: Cannot find value for variable column :"
                                            + this.vecVariableColumnName.get(i)
                                                    .toString());
                            LoaderException le = new LoaderException(
                                    "Exception: ",
                                    (Throwable) (new Exception(
                                            "Error: Cannot find value for variable column :")));
                            this.logger.write("full", le
                                    .getStackTraceAsString());
                            throw le;
                        }
                        // sinisa 15.03 Add subCounter columns
                        for (int l = 0; l < subCounterKeyColumns.size(); l++) {
                            if (subCounterKeyColumns.get(l) != null
                                    && ((Vector) subCounterKeyColumns.get(l))
                                            .size() != 0
                                    && ((Vector) subCounterKeyColumns.get(l))
                                            .contains(this.vecVariableColumnName
                                                    .get(iPositionInVector))) {
                                if (this.vecVariableValue
                                        .get(iPositionInVector) != null)
                                    subKeyValues.put(this.vecVariableColumnName
                                            .get(iPositionInVector).toString(),
                                            this.vecVariableValue.get(
                                                    iPositionInVector)
                                                    .toString());
                            }
                        }
                    }
                }
            }
            // find value for relation column - userID
            for (int i = 0; i < this.iRelationColumns; i++) {
                outLoop1: if (this.vecRelationColumnSourceTableName.get(i)
                        .toString().equalsIgnoreCase(
                                this.vecTableTableName.get(iTableInt)
                                        .toString())
                        && this.vecRelationColumnSourceTableID.get(i)
                                .toString().equalsIgnoreCase(
                                        this.vecTableTableID.get(iTableInt)
                                                .toString())) {
                    for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) {
                        if (this.vecRelationColumnSourceTableName.get(i)
                                .toString().equalsIgnoreCase(
                                        this.vecVariableUseIDTableName.get(m)
                                                .toString())
                                && this.vecRelationColumnSourceTableID.get(i)
                                        .toString().equalsIgnoreCase(
                                                this.vecVariableUseIDTableID
                                                        .get(m).toString())) {
                            String strQueryRelations = "select "
                                    + this.vecRelationColumnSourceColumnName
                                            .get(i).toString()
                                    + " from "
                                    + this.vecRelationColumnSourceTableName
                                            .get(i).toString() + " where ";
                            strQueryRelations += ((Vector) this.vecTargetKeyColumnName
                                    .get(iTableInt)).get(0).toString()
                                    + " = ";
                            // ZK change this from CheckType to
                            // configReaderTarget this 7.5.2004
                            if (!configReaderTarget
                                    .isNumber(vecColumnNamesTypes.get(0)
                                            .toString()))
                                strQueryRelations += "'" + this.strUserID + "'";
                            else
                                strQueryRelations += this.strUserID;
                            this.logger.write("full", "\tQuery '"
                                    + strQueryRelations + "' will be executed");
                            Statement stmt = c.createStatement();
                            ResultSet rsetTarget = stmt
                                    .executeQuery(strQueryRelations);
                            if (rsetTarget.next()) {
                                if (this.iTargetFirstColumnResult == 1) {
                                    this.vecRelationSourceValue.setElementAt(
                                            rsetTarget.getObject(1), i);
                                    this.vecRelationSourceType.setElementAt(
                                            rsetTarget.getMetaData()
                                                    .getColumnTypeName(1), i);
                                } else {
                                    this.vecRelationSourceValue.setElementAt(
                                            rsetTarget.getObject(0), i);
                                    this.vecRelationSourceType.setElementAt(
                                            rsetTarget.getMetaData()
                                                    .getColumnTypeName(0), i);
                                }
                            }
                            rsetTarget.close();
                            stmt.close();
                            break outLoop1;
                        }
                    }
                    if (bOIDlogicValue) {
                        String oidType = configReaderTarget.getOidDbType();
                        int end = oidType.indexOf("(");
                        if (end != -1)
                            oidType = (oidType.substring(0, end)).trim();
                        else
                            oidType = oidType.trim();
                        if (this.vecTableInsert.get(iTableInt).toString()
                                .equalsIgnoreCase("true")) {
                            // insertTable=true
                            this.vecRelationSourceValue.setElementAt(
                                    this.bdecOidNumber, i);
                            this.vecRelationSourceType.setElementAt(oidType
                                    .toLowerCase(), i);

                        } else {
                            // insertTable=false
                            this.vecRelationSourceValue.setElementAt(null, i);
                            this.vecRelationSourceType.setElementAt(oidType
                                    .toLowerCase(), i);

                        }
                    } else { // bOIDlogicValue=false
                        if (this.iRelationColumns > 0) {
                            for (int j = 0; j < vecColumnNames.size(); j++) {
                                if (this.vecRelationColumnSourceColumnName.get(
                                        i).toString().equalsIgnoreCase(
                                        vecColumnNames.get(j).toString())) {
                                    if (this.vecTableInsert.get(iTableInt)
                                            .toString()
                                            .equalsIgnoreCase("true")) {
                                        // insertTable=true
                                        this.vecRelationSourceValue
                                                .setElementAt(vecColumnValues
                                                        .get(j).toString(), i);
                                        this.vecRelationSourceType
                                                .setElementAt(
                                                        vecColumnNamesTypes
                                                                .get(j)
                                                                .toString(), i);
                                    } else {
                                        // insertTable=false;
                                        this.vecRelationSourceValue
                                                .setElementAt(null, i);
                                        this.vecRelationSourceType
                                                .setElementAt(
                                                        vecColumnNamesTypes
                                                                .get(j)
                                                                .toString(), i);
                                    }
                                }
                            } // end vecColumnNames.size()
                        }
                    }
                }
            }

            for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
                String tmpRelationForCount = "";
                if (this.vecRelationColumnTargetTableName.get(i).toString()
                        .equalsIgnoreCase(
                                this.vecTableTableName.get(iTableInt)
                                        .toString())
                        && this.vecRelationColumnTargetTableID.get(i)
                                .toString().equalsIgnoreCase(
                                        this.vecTableTableID.get(iTableInt)
                                                .toString())) {
                    if (this.vecRelationSourceValue.get(i) == null) {
                        String replacementValueInRel = vecDefaultRelationValue
                                .get(i).toString();
                        if (!replacementValueInRel.equalsIgnoreCase("")) {
                            // default value for relation exists
                            try {
                                Object obj = relationsCache
                                        .getRelationsCacheValue(replacementValueInRel);
                                String relationValue;
                                String relationType;
                                if (obj != null) {
                                    // relation (default value) is cached
                                    relationValue = obj.toString();
                                    relationType = relationsCache
                                            .getRelationsCachType(replacementValueInRel);
                                    pstmtValues.add(relationValue);
                                    pstmtTypes.add(relationType);
                                } else {
                                    // relation (default value) isn't cached
                                    ResultSet newRelationValue = null;
                                    Statement newRelationsStmt = c
                                            .createStatement();
                                    try {
                                        this.logger.write("full", "\tQuery '"
                                                + replacementValueInRel
                                                + "' will be executed");
                                        newRelationValue = newRelationsStmt
                                                .executeQuery(replacementValueInRel);
                                        if (newRelationValue.next()) {
                                            relationValue = newRelationValue
                                                    .getString(1);
                                            relationsCache
                                                    .setRelationsCacheValue(
                                                            replacementValueInRel,
                                                            relationValue);
                                            relationType = newRelationValue
                                                    .getMetaData()
                                                    .getColumnTypeName(1);
                                            relationsCache
                                                    .setRelationsCacheType(
                                                            replacementValueInRel,
                                                            relationType);

                                            newRelationValue.close();
                                            newRelationsStmt.close();

                                            String strDataCleaning = dataCleaning
                                                    .cleaningRelationValues(
                                                            this.vecTableTableName
                                                                    .get(
                                                                            iTableInt)
                                                                    .toString(),
                                                            this.vecRelationColumnTargetColumnName
                                                                    .get(i)
                                                                    .toString(),
                                                            relationValue,
                                                            relationType,
                                                            currentRow,
                                                            c,
                                                            "INSERT",
                                                            0,
                                                            false,
                                                            importDefinitionElement.strImportDefinitionName,
                                                            this.currentVersionColumnName,
                                                            replacementValueInRel);
                                            pstmtValues.add(strDataCleaning);
                                            pstmtTypes.add(relationType);
                                        } else { // newRelationValue.next()=false
                                            newRelationValue.close();
                                            newRelationsStmt.close();
                                            relationValue = "null";
                                            dataCleaning
                                                    .cleaningInsert(
                                                            this.vecTableTableName
                                                                    .get(
                                                                            iTableInt)
                                                                    .toString(),
                                                            c,
                                                            currentRow,
                                                            "INSERT",
                                                            "Default value '"
                                                                    + replacementValueInRel
                                                                    + "' for relations is not valid.",
                                                            importDefinitionElement.strImportDefinitionName,
                                                            replacementValueInRel);

                                            pstmtValues.add("null");
                                            pstmtTypes
                                                    .add(this.vecRelationSourceType
                                                            .get(i).toString());
                                        }
                                    } catch (SQLException ex) {
                                        newRelationValue.close();
                                        newRelationsStmt.close();
                                        LoaderException le = new LoaderException(
                                                "\n" + "SQLException: "
                                                        + ex.getMessage(),
                                                (Throwable) ex);
                                        this.logger.write("full", le
                                                .getStackTraceAsString());
                                        throw le;
                                    }
                                }

                            } catch (SQLException ex) {
                                String msg = "Default value for foreign key("
                                        + replacementValueInRel
                                        + ") is not valid. Import definition name: "
                                        + importDefinitionElement.strImportDefinitionName;
                                LoaderException le = new LoaderException(
                                        "SQLException: " + msg, (Throwable) ex);
                                this.logger.write("full", le
                                        .getStackTraceAsString());
                                throw le;
                            }

                        } else { // default value for relations doesn't
                            // exsist
                            pstmtValues.add("null");
                            if (this.vecRelationSourceType.get(i) != null)
                                pstmtTypes.add(this.vecRelationSourceType
                                        .get(i).toString());
                            else
                                pstmtTypes.add("java.lang.Object");
                        }
                    } else { // this.vecRelationSourceType.get(i)!=null
                        pstmtValues.add(this.vecRelationSourceValue.get(i)
                                .toString());
                        pstmtTypes.add(this.vecRelationSourceType.get(i)
                                .toString());

                        tmpRelationForCount = this.vecRelationSourceValue
                                .get(i).toString();//
                        this.vecRelationSourceValue.setElementAt(null, i);

                    }

                    // sinisa 15.03 Add subCounter columns
                    for (int l = 0; l < subCounterKeyColumns.size(); l++) {
                        if (subCounterKeyColumns.get(l) != null
                                && ((Vector) subCounterKeyColumns.get(l))
                                        .size() != 0
                                && ((Vector) subCounterKeyColumns.get(l))
                                        .contains(this.vecRelationColumnTargetColumnName
                                                .get(i))) {
                            if (tmpRelationForCount != null) {
                                subKeyValues.put(
                                        this.vecRelationColumnTargetColumnName
                                                .get(i).toString(),
                                        tmpRelationForCount);
                            }
                        }
                    }
                }
            }

            // sinisa 02.03.2003. Add couterColumns
            Vector counterColValues = this.counterColumns.getCounterValue(
                    this.vecTableTableName.get(iTableInt).toString(),
                    this.vecTableTableID.get(iTableInt).toString());
            for (int i = 0; i < counterColValues.size(); i++) {
                if (counterColValues.get(i) != null) {
                    int strInt = new BigDecimal(counterColValues.get(i)
                            .toString()).intValue();
                    pstmtValues.add(String.valueOf(strInt));
                    pstmtTypes.add("java.lang.Integer");
                } else {
                    pstmtValues.add("null");
                    pstmtTypes.add("java.lang.Integer");
                }
            }
            this.counterColumns.setCounterValue(this.vecTableTableName.get(
                    iTableInt).toString(), this.vecTableTableID.get(iTableInt)
                    .toString());
            // end sinisa

            // sinisa 15.03.2003. Add counterColumns
            if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase(
                    "true")) {
                this.counterColumns.setSubCounterKeyValues(
                        this.vecTableTableName.get(iTableInt).toString(),
                        this.vecTableTableID.get(iTableInt).toString(),
                        subKeyValues);
                Vector subCounterColValues = this.counterColumns
                        .readSubCounterValue(this.vecTableTableName.get(
                                iTableInt).toString(), this.vecTableTableID
                                .get(iTableInt).toString(), c,
                                this.iTargetFirstColumnResult,
                                this.vecTableTableMode.get(iTableInt)
                                        .toString(), configReaderTarget);
                for (int i = 0; i < subCounterColValues.size(); i++) {
                    if (subCounterColValues.get(i) != null) {
                        pstmtValues.add(new BigDecimal(subCounterColValues.get(
                                i).toString()));
                        pstmtTypes.add("java.math.BigDecimal");
                    } else {
                        pstmtValues.add("null");
                        pstmtTypes.add("java.math.BigDecimal");
                    }
                }
                if (bOIDlogicValue) {
                    if (this.bdecOidNumber.compareTo(this.bdecOidNumber2000) == 0) {
                        this.checkOidLogic(c);
                        this.bdecOidNumber = this.bdecOidNumber
                                .add(new BigDecimal(1));
                    } else
                        this.bdecOidNumber = this.bdecOidNumber
                                .add(new BigDecimal(1));
                }

                // ZK added this for transormations
                for (int i = 0; i < vecTransformationValue.size(); i++) {
                    if ((vecTransformationValue.get(i)) == null) {
                        String valueForPstmt = "null";
                        pstmtValues.add(valueForPstmt);
                    } else {
                        pstmtValues.add(vecTransformationValue.get(i)
                        // .toString()
                                );
                    }

                    pstmtTypes.add(transformationTargetColumnTypes.get(i)
                            .toString());

                }

                // String tableNameId=
                // this.vecTableTableName.get(iTableInt).toString()+this.vecTableTableID.get(iTableInt).toString();
                // if (transTableNamesIDs.contains(tableNameId)){
                // for (int i=0; i < trans.size();i++){
                // Transformation pom = (Transformation)trans.get(i);
                // Vector sourceColumnNames = pom.getSourceColumnNames();
                // Vector targetColumnNames =
                // pom.getTargetColumnNames(this.vecTableTableName.get(iTableInt).toString(),
                // this.vecTableTableID.get(iTableInt).toString());
                //          
                // Vector resultVector =
                // pom.readTransformationValues(sourceColumnNames,
                // this.vecTableTableName.get(iTableInt).toString(),
                // this.vecTableTableID.get(iTableInt).toString());
                // Vector resultVectorTypes =
                // pom.getTargetColumnTypes(this.vecTableTableName.get(iTableInt).toString(),
                // this.vecTableTableID.get(iTableInt).toString());
                // for(int j=0;j < resultVector.size();j++) {
                // pstmtValues.add(resultVector.get(j));
                // pstmtTypes.add(resultVectorTypes.get(j));
                // }
                // }
                // }
                // end

                // handling blob object
                // strQuery = strQuery + ") VALUES (";
                String pstmtColumnValue;
                for (int i = 0; i < pstmtValues.size(); i++) {

                    String javaType = pstmtTypes.get(i).toString()
                            .toUpperCase();
                    if (javaType.indexOf("JAVA") == -1) {
                        // //ZK Added next line because of DB2 type LONG VARCHAR
                        // javaType = Utils.replaceAll(javaType," ","_");
                        javaType = (String) configReaderTarget
                                .getJavaTypeMapings().get(
                                        javaType.toUpperCase());
                        if (javaType == null) {
                            LoaderException le = new LoaderException(
                                    "Exception:",
                                    new Exception(
                                            "This type of data "
                                                    + pstmtTypes.get(i)
                                                            .toString()
                                                            .toUpperCase()
                                                    + "  doesn't exists in the target table conf file!"));
                            this.logger.write("full", le
                                    .getStackTraceAsString());
                            throw le;
                        }
                    } else {
                        if (javaType.equalsIgnoreCase("java.math.BigDecimal"))
                            javaType = "2";
                        else if (javaType.equalsIgnoreCase("java.lang.Integer"))
                            javaType = "5";
                        else if (javaType.equalsIgnoreCase("java.sql.Date"))
                            javaType = "9";
                        else if (javaType.equalsIgnoreCase("java.lang.Object"))
                            javaType = "14";

                    }

                    int javaTypeInt = Integer.parseInt(javaType);
                    pstmtColumnValue = pstmtValues.get(i).toString();
                    Object pstmtColumnValueAsObject = pstmtValues.get(i);
                    // ZK changed this 17.6 2004 because of problems with null
                    // binary object.
                    // if (pstmtColumnValue.startsWith("binaryObject")) {
                    if (javaTypeInt == 1) {
                        if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                            String binaryName = pstmtValues.get(i).toString();
                            for (int j = 0; j < vecBlobVector.size(); j = j + 5) {
                                if (binaryName.equalsIgnoreCase(vecBlobVector
                                        .get(j + 4).toString())) {
                                    byte[] isBlob = (byte[]) this.vecBlobVector
                                            .get(j + 1);
                                    strQuery = strQuery + binaryName + ",";
                                    pstmt.setBytes(i + 1, isBlob);
                                    strQuery = strQuery + "BlobObject" + i
                                            + ",";
                                    break;
                                }
                            }
                        } else {
                            pstmt.setNull(i + 1, java.sql.Types.BINARY);
                            strQuery = strQuery + "null" + ",";
                        }
                    } else {
                        if (javaTypeInt == 2) { // java.math.BigDecimal
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                BigDecimal number = new BigDecimal(0);
                                if (!pstmtColumnValue.equalsIgnoreCase(""))
                                    number = new BigDecimal(pstmtColumnValue);
                                strQuery = strQuery + pstmtColumnValue + ",";
                                pstmt.setBigDecimal(i + 1, number);
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.DECIMAL);
                                strQuery = strQuery + "null" + ",";
                            }
                        } else if (javaTypeInt == 3) { // java.lang.Double
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                double number = 0;
                                if (!pstmtColumnValue.equalsIgnoreCase(""))
                                    number = Double
                                            .parseDouble(pstmtColumnValue);
                                strQuery = strQuery + pstmtColumnValue + ",";
                                pstmt.setDouble(i + 1, number);
                            } else {
                                strQuery = strQuery + "null" + ",";
                                pstmt.setNull(i + 1, java.sql.Types.DOUBLE);
                            }
                        } else if (javaTypeInt == 4) { // java.lang.Float
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                float number = 0;
                                if (!pstmtColumnValue.equalsIgnoreCase(""))
                                    number = Float.parseFloat(pstmtColumnValue);
                                pstmt.setFloat(i + 1, number);
                                strQuery = strQuery + pstmtColumnValue + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.FLOAT);
                                strQuery = strQuery + "null" + ",";
                            }
                        } else if (javaTypeInt == 5) { // java.lang.Integer
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                int number = 0;
                                if (!pstmtColumnValue.equalsIgnoreCase(""))
                                    number = Integer.parseInt(pstmtColumnValue);
                                pstmt.setInt(i + 1, number);
                                strQuery = strQuery + pstmtColumnValue + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.INTEGER);
                                strQuery = strQuery + "null" + ",";
                            }

                        } else if (javaTypeInt == 6) { // java.lang.Long
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                long number = 0;
                                if (!pstmtColumnValue.equalsIgnoreCase(""))
                                    number = Long.parseLong(pstmtColumnValue);
                                pstmt.setLong(i + 1, number);
                                strQuery = strQuery + pstmtColumnValue + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.DOUBLE);
                                strQuery = strQuery + "null" + ",";
                            }
                        } else if (javaTypeInt == 7) { // java.lang.Short
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                short number = 0;
                                if (!pstmtColumnValue.equalsIgnoreCase(""))
                                    number = Short.parseShort(pstmtColumnValue);
                                pstmt.setShort(i + 1, number);
                                strQuery = strQuery + pstmtColumnValue + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.SMALLINT);
                                strQuery = strQuery + "null" + ",";
                            }
                        } else if (javaTypeInt == 8) { // java.lang.String
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                // all '' back to ' (original value)
                                if (pstmtColumnValue.indexOf("''") != -1) {
                                    pstmtColumnValue = Utils.replaceAll(
                                            pstmtColumnValue, "''", "'");
                                }
                                pstmt.setString(i + 1, pstmtColumnValue);
                                strQuery = strQuery + "'" + pstmtColumnValue
                                        + "'" + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.VARCHAR);
                                strQuery = strQuery + "null" + ",";

                            }
                        } else if (javaTypeInt == 9) { // java.sql.Date
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                if (pstmtColumnValueAsObject instanceof java.sql.Date)
                                    pstmt
                                            .setDate(
                                                    i + 1,
                                                    (java.sql.Date) pstmtColumnValueAsObject);
                                else {
                                    //try {
                                    //    pstmt.setDate(i + 1, new java.sql.Date(getDateFromString(pstmtColumnValue).getTime()));
                                    //} catch (Exception e) {
                                        this.logger.write("full","call setString on date: "+ pstmtColumnValue);
                                        pstmt.setString(i + 1,pstmtColumnValue);
                                    //}
                                }
                                strQuery = strQuery + "'" + pstmtColumnValue
                                        + "'" + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.DATE);
                                strQuery = strQuery + "null" + ",";
                            }
                        } else if (javaTypeInt == 10) { // java.sql.Time
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                if (pstmtColumnValueAsObject instanceof Time)
                                    pstmt
                                            .setTime(
                                                    i + 1,
                                                    (java.sql.Time) pstmtColumnValueAsObject);
                                else {
                                    // String format =
                                    // this.configReaderSource.getDateFormat();
                                    // SimpleDateFormat formatDate = new
                                    // SimpleDateFormat(format);
                                    // Date tmpDate =
                                    // formatDate.parse(pstmtColumnValue);
                                    try {
                                        pstmt.setTime(i + 1, new java.sql.Time(
                                                getDateFromString(
                                                        pstmtColumnValue)
                                                        .getTime()));
                                    } catch (Exception e) {
                                        pstmt
                                                .setString(i + 1,
                                                        pstmtColumnValue);
                                    }
                                }
                                strQuery = strQuery + "'" + pstmtColumnValue
                                        + "'" + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.TIME);
                                strQuery = strQuery + "null" + ",";
                            }

                        } else if (javaTypeInt == 11) { // java.sql.Timestamp
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                if (pstmtColumnValueAsObject instanceof java.sql.Timestamp)
                                    pstmt
                                            .setTimestamp(
                                                    i + 1,
                                                    (java.sql.Timestamp) pstmtColumnValueAsObject);
                                else {
                                    // String format =
                                    // this.configReaderSource.getDateFormat();
                                    // SimpleDateFormat formatDate = new
                                    // SimpleDateFormat(format);
                                    // Date tmpDate =
                                    // formatDate.parse(pstmtColumnValue);
                                    try {
                                        pstmt
                                                .setTimestamp(
                                                        i + 1,
                                                        new Timestamp(
                                                                getDateFromString(
                                                                        pstmtColumnValue)
                                                                        .getTime()));
                                    } catch (Exception e) {
                                        pstmt
                                                .setString(i + 1,
                                                        pstmtColumnValue);
                                    }
                                }
                                strQuery = strQuery + "'" + pstmtColumnValue
                                        + "'" + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.TIMESTAMP);
                                strQuery = strQuery + "null" + ",";
                            }

                        } else if (javaTypeInt == 12) { // java.lang.Boolean
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                boolean bool = new Boolean(pstmtColumnValue)
                                        .booleanValue();
                                pstmt.setBoolean(i + 1, bool);
                                strQuery = strQuery + pstmtColumnValue + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.BIT);
                                strQuery = strQuery + "null" + ",";
                            }
                        } else if (javaTypeInt == 13) { // java.lang.Byte
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                pstmt.setString(i + 1, pstmtColumnValue);
                                strQuery = strQuery + "'" + pstmtColumnValue
                                        + "'" + ",";
                            } else {
                                pstmt.setNull(i + 1, java.sql.Types.BIT);
                                strQuery = strQuery + "null" + ",";
                            }
                        } else if (javaTypeInt == 14) { // java.lang.Object
                            if (!pstmtColumnValue.equalsIgnoreCase("null")) {
                                pstmt.setString(i + 1, pstmtColumnValue);
                                strQuery = strQuery + "'" + pstmtColumnValue
                                        + "'" + ",";
                            } else {
                                // TODO zoran pogledati ovo
                                try {
                                    pstmt.setNull(i + 1, java.sql.Types.NULL);
                                } catch (Exception e) {
                                    pstmt.setString(i + 1, null);
                                }
                                strQuery = strQuery + "null" + ",";
                            }
                        } else {
                            LoaderException le = new LoaderException(
                                    "Exception:", new Exception(
                                            "This java type is not supported!"));
                            this.logger.write("full", le
                                    .getStackTraceAsString());
                            throw le;
                        }
                    }// end of else (not blob)
                    pstmtColumnValue = null;
                }
                strQuery = strQuery.substring(0, strQuery.length() - 1) + ")";
                this.logger.write("full", "\tQuery '" + strQuery
                        + "' will be executed");

                int pstmtInsert = 0;
                pstmtInsert = pstmt.executeUpdate();
                // setting the cache value for inseted row
                // if (pstmtInsert != 0)
                // this.checkRowCache.setCheckRowValue();
                pstmt.clearParameters();
                pstmtValues.clear();
                pstmtTypes.clear();

                // TODO 14.6.2004 ZK Comented this because of problems with
                // update on counters table which are not needed.
                // this.counterColumns.updateCounter(this.vecTableTableName.get(iTableInt).toString(),
                // this.vecTableTableID.get(iTableInt).toString(), c);

            } else {
                // this.checkRowCache.setCheckRowValue();
            }
        } catch (SQLException ex) {
            pstmt.clearParameters();
            pstmtValues.clear();
            pstmtTypes.clear();
            LoaderException le = new LoaderException("SQLException: ",
                    (Throwable) ex);
            if (importDefinitionElement.strDefaultCutOffData
                    .equalsIgnoreCase("true")) {
                dataCleaning.cutingDataLenght(this.vecTableTableName.get(
                        iTableInt).toString(), c, strQuery, currentRow,
                        importDefinitionElement.strOnErrorContinueXml, ex
                                .getMessage(),
                        importDefinitionElement.strImportDefinitionName,
                        strQuery);
            } else if (importDefinitionElement.strOnErrorContinueXml
                    .equalsIgnoreCase("true")) {
                pstmt.clearParameters();
                pstmtValues.clear();
                pstmtTypes.clear();
                // this.logger.write("full", "\tError in SQL statement: " +
                // le.getStackCause());
                this.logger.write("full", "\tError in SQL statement: "
                        + le.getStackTraceAsString());
                dataCleaning.cleaningInsert(this.vecTableTableName.get(
                        iTableInt).toString(), c, currentRow, "INSERT", ex
                        .getMessage(),
                        importDefinitionElement.strImportDefinitionName,
                        strQuery);
            } else {
                pstmt.clearParameters();
                pstmtValues.clear();
                pstmtTypes.clear();
                this.logger.write("normal", "\tError in SQL statement: "
                        + le.getCause());
                this.logger.write("full", le.getStackTraceAsString());
                // throw ex;
                throw le;
            }
        } catch (NullPointerException ex) {
            throw ex;
        } catch (Exception ex) {
            throw ex;
        }
        this.logger.write("full", "\tinsertRow method is finished.");
    }

    /**
     * Method isRelationColumn checkes if the column(strColumnName) in target
     * table(iTable) is mentioned in relation tags (target column name). If it
     * is, return true, else return false.
     * 
     * @param strColumnName -
     *            Name of target column
     * @param iTable -
     *            Number of target table
     * @return boolean - true if strColumnName is relation target column, false
     *         if it is not.
     */
    private boolean isRelationColumn(String strColumnName, int iTable) {
        boolean bFind = false;
        endFor: for (int i = 0; i < this.vecRelationColumnTargetTableName
                .size(); i++) {
            if (this.vecRelationColumnTargetTableName.get(i).toString()
                    .equalsIgnoreCase(
                            this.vecTableTableName.get(iTable).toString())
                    && this.vecRelationColumnTargetTableID
                            .get(i)
                            .toString()
                            .equalsIgnoreCase(
                                    this.vecTableTableID.get(iTable).toString())
                    && this.vecRelationColumnTargetColumnName.get(i).toString()
                            .equalsIgnoreCase(strColumnName)) {
                bFind = true;
                break endFor;
            }
        }
        return bFind;
    }

    /**
     * Method checkOidLogic is used to increase the ObjectID value with adding
     * iObjectIDIncrement value. Method puts new value in ObjectID table for
     * current importDefinition. If there is an error, Exception "SQLException"
     * or NullPointerException is thrown.
     * 
     * @param c
     *            Connection to target database.
     * @throws SQLException
     *             Constructs an SQLException object with a reason.
     * @throws NullPointerException
     *             Constructs a NullPointerException with the specified detail
     *             message.
     */
    private void checkOidLogic(Connection c) throws SQLException,
            NullPointerException {
        String strQuery = "";
        this.logger.write("full", "\tcheckOidLogic method is started.");
        Boolean bTemp = new Boolean("false");

        if (currentJobName.equalsIgnoreCase("importDefinition")) {
            for (int i = 0; i < this.iTables; i++) {
                if (this.vecTableOidLogic.get(i).toString().equalsIgnoreCase(
                        "true")) {
                    bTemp = new Boolean("true");
                }
            }
        } else if (currentJobName.equalsIgnoreCase("copyTable")) {
            if (importDefinitionElement.strCopyTableOidLogic
                    .equalsIgnoreCase("true")) {
                bTemp = new Boolean("true");
            }
        }

        if (bTemp.booleanValue()) {
            try {
                if (!(importDefinitionElement.strObjectIDNameColumnName
                        .equals("") || importDefinitionElement.strObjectIDNameColumnValue
                        .equals(""))) {
                    strQuery = new String(
                            "SELECT "
                                    + importDefinitionElement.strObjectIDColumnName
                                    + " FROM "
                                    + importDefinitionElement.strObjectIDTableName
                                    + " WHERE "
                                    + importDefinitionElement.strObjectIDNameColumnName
                                    + " = '"
                                    + importDefinitionElement.strObjectIDNameColumnValue
                                    + "'");
                } else {
                    strQuery = new String("SELECT "
                            + importDefinitionElement.strObjectIDColumnName
                            + " FROM "
                            + importDefinitionElement.strObjectIDTableName);
                }
                this.logger.write("full", "\tQuery '" + strQuery
                        + "' will be executed");
                Statement stmtOid = c.createStatement();
                ResultSet rsetOid = stmtOid.executeQuery(strQuery);
                if (rsetOid.next()) {
                    if (this.iTargetFirstColumnResult == 1)
                        this.bdecOidNumber = new BigDecimal(rsetOid.getString(1));
                    else
                        this.bdecOidNumber = new BigDecimal(rsetOid.getString(0));
                } else {
                    if (!(importDefinitionElement.strObjectIDNameColumnName
                            .equals("") || importDefinitionElement.strObjectIDNameColumnValue
                            .equals(""))) {
                        String insert = "insert into "
                                + importDefinitionElement.strObjectIDTableName
                                + " ("
                                + importDefinitionElement.strObjectIDNameColumnName
                                + ","
                                + importDefinitionElement.strObjectIDColumnName
                                + ") values ('"
                                + importDefinitionElement.strObjectIDNameColumnValue
                                + "','"
                                + importDefinitionElement.iObjectIDStartValue
                                + "');";
                        stmtOid.execute(insert);
                    }
                }
                rsetOid.close();
                stmtOid.close();

                if (currentJobName.equalsIgnoreCase("copyTable")) {
                    this.bdecOidNumber2000 = this.bdecOidNumber
                            .add(new BigDecimal(
                                    importDefinitionElement.iObjectIDCT));
                } else {
                    this.bdecOidNumber2000 = this.bdecOidNumber
                            .add(new BigDecimal(
                                    importDefinitionElement.iObjectID));
                }
                Statement stmtOid2 = c.createStatement();
                if (!(importDefinitionElement.strObjectIDNameColumnName
                        .equals("") || importDefinitionElement.strObjectIDNameColumnValue
                        .equals(""))) {
                    this.logger
                            .write(
                                    "full",
                                    "\tQuery '"
                                            + "UPDATE "
                                            + importDefinitionElement.strObjectIDTableName
                                            + " SET "
                                            + importDefinitionElement.strObjectIDColumnName
                                            + " = "
                                            + this.bdecOidNumber2000
                                            + " where "
                                            + importDefinitionElement.strObjectIDNameColumnName
                                            + " = '"
                                            + importDefinitionElement.strObjectIDNameColumnValue
                                            + "'' will be executed");
                    stmtOid2
                            .executeUpdate("UPDATE "
                                    + importDefinitionElement.strObjectIDTableName
                                    + " SET "
                                    + importDefinitionElement.strObjectIDColumnName
                                    + " = "
                                    + this.bdecOidNumber2000
                                    + " where "
                                    + importDefinitionElement.strObjectIDNameColumnName
                                    + " = '"
                                    + importDefinitionElement.strObjectIDNameColumnValue
                                    + "'");
                } else {
                    this.logger
                            .write(
                                    "full",
                                    "\tQuery '"
                                            + "UPDATE "
                                            + importDefinitionElement.strObjectIDTableName
                                            + " SET "
                                            + importDefinitionElement.strObjectIDColumnName
                                            + " = "
                                            + this.bdecOidNumber2000
                                            + " where "
                                            + importDefinitionElement.strObjectIDColumnName
                                            + " = " + this.bdecOidNumber
                                            + "' will be executed");
                    stmtOid2.executeUpdate("UPDATE "
                            + importDefinitionElement.strObjectIDTableName
                            + " SET "
                            + importDefinitionElement.strObjectIDColumnName
                            + " = " + this.bdecOidNumber2000 + " where "
                            + importDefinitionElement.strObjectIDColumnName
                            + " = " + this.bdecOidNumber);
                }
                stmtOid2.close();
            } catch (SQLException ex) {
                throw ex;
            } catch (NullPointerException ex) {
                throw ex;
            }
        }
        this.logger.write("full", "\tcheckOidLogic method is finished.");
    }

    /**
     * Method querySource is used to make SQL query to source table and to sort
     * columns from source table ordered by sortColumns.
     * 
     * @return SQL Query to source table.
     * @throws LoaderException
     */
    private String querySource() throws LoaderException {
        int i = 0;
        int j = 0;
        this.logger.write("full", "\tquerySource method is started.");
        Vector vecVektor = new Vector();
        String strQuery = "select ";
        // this is pointer where transformations columns starts within result
        // set
//        this.iOffsetForTransColumns = 0;
        while (i < this.iTables) {
            vecVektor = (Vector) this.vecSourceColumnName.get(i);
//            this.iOffsetForTransColumns += vecVektor.size();
            while (j < Integer.parseInt(this.vecValueColumnsTargetTables.get(i)
                    .toString())) {
                strQuery = strQuery + vecVektor.get(j).toString() + ", ";
                j++;
                this.iColumnsInSourceTable++;
            }
            j = 0;
            i++;
        }
        ArrayList trans = this.transformations.getTransformations();
        // int numTransSourceColumns = 0;
        // read all source columns for all transformations
        // i = 0;
        // while (i < this.iTables) {
        for (int k = 0; k < trans.size(); k++) {
            Transformation transformation = (Transformation) trans.get(k);
            // if( i != Integer.parseInt( transformation.getTargetTableID() ) )
            // continue;
            Vector sourceColumnNames = transformation.getSourceColumnNames();
            for (int kk = 0; kk < sourceColumnNames.size(); kk++) {
                strQuery = strQuery + sourceColumnNames.get(kk).toString()
                        + ", ";
                // numTransSourceColumns++;
            }
        }
        // this.vecTransformColumnsTargetTables.add(
        // String.valueOf(numTransSourceColumns) );
        // numTransSourceColumns=0;
        // i++;
        // }
        strQuery = strQuery.substring(0, strQuery.length() - 2);
        strQuery += " from "
                + importDefinitionElement.strImportDefinitionTableName;
        if (importDefinitionElement.vecRestartCounterSortColumn.size() != 0) {
            if (configReaderSource.getEnableOrderBy()) {
                strQuery += " order by ";
                for (j = 0; j < importDefinitionElement.vecRestartCounterSortColumn
                        .size(); j++) {
                    strQuery += importDefinitionElement.vecRestartCounterSortColumn
                            .get(j).toString()
                            + ", ";
                }
                strQuery = strQuery.substring(0, strQuery.length() - 2);
            }
        }

        this.logger.write("full", "\tquerySource method is finished.");
        return strQuery;
    }

    /**
     * Method targetColumnTypes is used to put source table column types into
     * Vector "vecSourceColumnType". This includes columns from the querySource
     * method. If there is an error, Exception "SQLException" or
     * NullPointerException is thrown.
     * 
     * @param connTarget
     *            Connection to the target table.
     * @throws SQLException
     *             Constructs an SQLException object with a reason.
     * @throws NullPointerException
     *             Constructs a NullPointerException with the specified detail
     *             message.
     */
    private void targetColumnTypes(Connection connTarget) throws SQLException,
            NullPointerException {
        int iColumn;
        String strQueryTypes = "";
        this.logger.write("full", "\ttargetColumnTypes method is started.");
        try {
            for (int i = 0; i < this.iTables; i++) {
                Vector vecKeyTypesRelations = new Vector();
                Vector vecVektor = new Vector();
                iColumn = 0;
                Statement stmtTypes = connTarget.createStatement();
                // ZK added 11.6.2004 because of new parameter
                // GetMaxRowsSupported
                if (this.configReaderTarget.getMaxRowsSupported()) {
                    stmtTypes.setMaxRows(1);
                }

                strQueryTypes = "select ";
                for (int j = 0; j < ((Vector) this.vecTargetColumnName.get(i))
                        .size(); j++) {
                    strQueryTypes += (((Vector) this.vecTargetColumnName.get(i))
                            .get(j).toString())
                            + ",";
                }
                for (int j = 0; j < ((Vector) this.vecRelationKeyColumns.get(i))
                        .size(); j++) {
                    strQueryTypes += (((Vector) this.vecRelationKeyColumns
                            .get(i)).get(j).toString())
                            + ",";
                }
                strQueryTypes = strQueryTypes.substring(0, strQueryTypes
                        .length() - 1);
                strQueryTypes += " from ";
                strQueryTypes += " " + this.vecTableTableName.get(i).toString();

                if (((Vector) this.vecTargetColumnName.get(i)).size() != 0
                        || ((Vector) this.vecRelationKeyColumns.get(i)).size() != 0) {

                    this.logger.write("full", "\tQuery '" + strQueryTypes
                            + "' will be executed");
                    ResultSet rsetTypes = stmtTypes.executeQuery(strQueryTypes);
                    for (int j = 0; j < ((Vector) this.vecValueMode.get(i))
                            .size(); j++) {
                        iColumn++;
                        if (this.iTargetFirstColumnResult == 1)
                            vecVektor.add(rsetTypes.getMetaData()
                                    .getColumnTypeName(iColumn));
                        else
                            vecVektor.add(rsetTypes.getMetaData()
                                    .getColumnTypeName(iColumn - 1));
                    }
                    for (int j = 0; j < ((Vector) this.vecRelationKeyColumns
                            .get(i)).size(); j++) {
                        iColumn++;
                        if (this.iTargetFirstColumnResult == 1)
                            vecKeyTypesRelations.add(rsetTypes.getMetaData()
                                    .getColumnTypeName(iColumn));
                        else
                            vecKeyTypesRelations.add(rsetTypes.getMetaData()
                                    .getColumnTypeName(iColumn - 1));
                    }
                    rsetTypes.close();
                }
                stmtTypes.close();
                this.vecRelationKeyTypes.setElementAt(vecKeyTypesRelations, i);
                this.vecTargetColumnType.add(vecVektor);
            }
            Statement stmtVariableTypes = connTarget.createStatement();
            if (this.configReaderTarget.getMaxRowsSupported()) {
                stmtVariableTypes.setMaxRows(1);
            }
            for (int j = 0; j < this.vecVariableColumnTargetTableName.size(); j++) {
                strQueryTypes = "select ";
                strQueryTypes += this.vecVariableColumnTargetColumnName.get(j)
                        .toString()
                        + " from ";
                strQueryTypes += this.vecVariableColumnTargetTableName.get(j)
                        .toString();
                ResultSet rsetVariableTypes;
                this.logger.write("full", "\tQuery '" + strQueryTypes
                        + "' will be executed");
                rsetVariableTypes = stmtVariableTypes
                        .executeQuery(strQueryTypes);
                if (this.iTargetFirstColumnResult == 1)
                    this.vecVariableColumnTypes.add(rsetVariableTypes
                            .getMetaData().getColumnTypeName(1));
                else
                    this.vecVariableColumnTypes.add(rsetVariableTypes
                            .getMetaData().getColumnTypeName(0));
                rsetVariableTypes.close();
            }
            stmtVariableTypes.close();
        } catch (SQLException ex) {
            throw ex;
        } catch (NullPointerException ex) {
            throw ex;
        }
        this.logger.write("full", "\ttargetColumnTypes method is finished.");
    }

    /**
     * Metod createCurrentDate is used to create current date and time in format
     * that supported by SQL server.
     * 
     * @return String representation of current date and time.
     */
    private String createCurrentDate() {

        // it is read from configReaderSource because before call to setDate on
        // target database, it will be parsed using date format
        // from source config and transformed into java.sql.Date
        String strDateTimeFormat = this.configReaderSource.getDateFormat();
        SimpleDateFormat tmpDate = new SimpleDateFormat(strDateTimeFormat);
        String strDate = tmpDate.format(new Date(System.currentTimeMillis()));
        return strDate;

    }

    /**
     * Method constantColumnTypes is used to put types of constant columns into
     * global vector sorted in target tables.If there is an error, Exception
     * "SQLException" or "NullPointerException" is thrown.
     * 
     * @param c
     *            Connection to target database.
     * @throws SQLException
     *             Constructs an SQLException object with a reason.
     * @throws NullPointerException
     *             Constructs a NullPointerException with the specified detail
     *             message.
     */
    private void constantColumnTypes(Connection c) throws SQLException,
            NullPointerException {
        int iCnt = 0;
        this.logger.write("full", "\tconstantColumnTypes method is started.");
        try {
            for (int i = 0; i < this.iTables; i++) {
                Vector vecTempConstantType = new Vector();
                Vector vecTempConstantName = new Vector();
                String strQuery = "select ";
                vecTempConstantName = (Vector) this.vecConstantTargetColumnName
                        .get(i);
                if (vecTempConstantName.size() != 0) {
                    Statement stmtConstant = c.createStatement();
                    for (int j = 0; j < vecTempConstantName.size(); j++)
                        strQuery += vecTempConstantName.get(j).toString()
                                + ", ";
                    strQuery = strQuery.substring(0, strQuery.length() - 2);
                    strQuery += " from "
                            + this.vecTableTableName.get(i).toString();
                    this.logger.write("full", "\tQuery '" + strQuery
                            + "' will be executed");
                    ResultSet rsetConstant = stmtConstant
                            .executeQuery(strQuery);
                    iCnt = vecTempConstantName.size();
                    for (int k = 0; k < iCnt; k++) {
                        if (this.iTargetFirstColumnResult == 1)
                            vecTempConstantType.add(rsetConstant.getMetaData()
                                    .getColumnTypeName(k + 1));
                        else
                            vecTempConstantType.add(rsetConstant.getMetaData()
                                    .getColumnTypeName(k));
                    }
                    rsetConstant.close();
                    stmtConstant.close();
                }
                this.vecConstantColumnType.setElementAt(vecTempConstantType, i);
            }
        } catch (SQLException ex) {
            throw ex;
        } catch (NullPointerException ex) {
            throw ex;
        }
        this.logger.write("full", "\tconstantColumnTypes method is finished.");
    }

    /**
     * Method inputUser is used to give a user the possibility to connect to
     * Source and Target database using user name and password. If missing, user
     * and password parameters for database in XML file, Loader asks user for
     * these parameters. If there is an error, Exception "IOException" is
     * thrown.
     * 
     * @param b
     *            Boolean type. If b is true- source database, false- target
     *            database
     * @throws IOException
     *             Constructs an IOException with the specified detail message.
     */
    private void inputUser(boolean b) throws java.io.IOException {
        if (b) {
            if (BufferOctopusClass.getInstance().IsUsed())
                throw new IOException(
                        "Missing user name and password for the Source DB. Check LoaderJob.olj file!");
            else
                this.logger.write("normal",
                        "Missing user name and password for the Source DB.");
        } else {
            if (BufferOctopusClass.getInstance().IsUsed())
                throw new IOException(
                        "Missing user name and password for the Target DB. Check LoaderJob.olj file!");
            else
                this.logger.write("normal",
                        "Missing user name and password for the Target DB.");
        }
        String strUserName;
        String strPassword;
        char cu;
        char cp;
        StringBuffer bufu = new StringBuffer();
        StringBuffer bufp = new StringBuffer();
        System.out.println("User name: ");
        try {
            while ((cu = (char) System.in.read()) != '\n')
                bufu.append(cu);
            strUserName = bufu.toString();
            strUserName = strUserName.substring(0, strUserName.length() - 1);
            System.out.println("Password: ");
            while ((cp = (char) System.in.read()) != '\n')
                bufp.append(cp);
            strPassword = bufp.toString();
            if (strPassword.length() != 0)
                strPassword = strPassword
                        .substring(0, strPassword.length() - 1);
            if (b) {
                jdbcParametersElement.setJDBCSourceParameterUser(strUserName);
                jdbcParametersElement
                        .setJDBCSourceParameterPassword(strPassword);
            } else {
                jdbcParametersElement.setJDBCTargetParameterUser(strUserName);
                jdbcParametersElement
                        .setJDBCTargetParameterPassword(strPassword);
            }
        } catch (IOException ex) {
            throw ex;
        }
    }

    /**
     * Method changeTableOrder change order of Tables into public Vector
     * vecTableTableName Relation source tables puts before the others target
     * tables.
     */
    private void changeTableOrder() {
        Vector vecTempTableTableName = new Vector();
        Vector vecTempTableTableID = new Vector();
        Vector vecTempTableInsert = new Vector();
        Vector vecTempTableTableMode = new Vector();
        Vector vecTempTableOidLogic = new Vector();
        Vector vecNumberOfTable = new Vector();
        for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
            int iNumberOfTable = 0;
            for (int j = 0; j < this.vecTableTableName.size(); j++) {
                if (this.vecTableTableName.get(j).toString()
                        .equalsIgnoreCase(
                                this.vecRelationColumnSourceTableName.get(i)
                                        .toString())
                        && this.vecTableTableID.get(j).toString()
                                .equalsIgnoreCase(
                                        this.vecRelationColumnSourceTableID
                                                .get(i).toString())) {
                    iNumberOfTable = j;
                    boolean bEqualsRelationSource = false;
                    for (int k = 0; k < vecNumberOfTable.size(); k++) {
                        if (j == (new Integer(vecNumberOfTable.get(k)
                                .toString())).intValue())
                            bEqualsRelationSource = true;
                    }
                    if (!bEqualsRelationSource) {
                        vecTempTableTableName.addElement(this.vecTableTableName
                                .get(j).toString());
                        vecTempTableTableID.addElement(this.vecTableTableID
                                .get(j).toString());
                        vecTempTableInsert.addElement(this.vecTableInsert
                                .get(j).toString());
                        vecTempTableTableMode.addElement(this.vecTableTableMode
                                .get(j).toString());
                        vecTempTableOidLogic.addElement(this.vecTableOidLogic
                                .get(j).toString());
                        vecNumberOfTable
                                .addElement(new Integer(iNumberOfTable));
                    }
                }
            }
        }
        if (this.vecRelationColumnSourceTableName.size() != 0) {
            for (int i = 0; i < this.vecTableTableName.size(); i++) {
                boolean bEquals = false;
                for (int j = 0; j < vecNumberOfTable.size(); j++) {
                    if (i == (new Integer(vecNumberOfTable.get(j).toString()))
                            .intValue()) {
                        bEquals = true;
                    }
                }
                if (!bEquals) {
                    vecTempTableTableName.addElement(this.vecTableTableName
                            .get(i).toString());
                    vecTempTableTableID.addElement(this.vecTableTableID.get(i)
                            .toString());
                    vecTempTableInsert.addElement(this.vecTableInsert.get(i)
                            .toString());
                    vecTempTableTableMode.addElement(this.vecTableTableMode
                            .get(i).toString());
                    vecTempTableOidLogic.addElement(this.vecTableOidLogic
                            .get(i).toString());
                }
            }
            this.vecTableTableName = new Vector();
            this.vecTableTableID = new Vector();
            this.vecTableInsert = new Vector();
            this.vecTableTableMode = new Vector();
            this.vecTableOidLogic = new Vector();
            for (int i = 0; i < vecTempTableTableName.size(); i++) {
                this.vecTableTableName.addElement(vecTempTableTableName.get(i)
                        .toString());
                this.vecTableTableID.addElement(vecTempTableTableID.get(i)
                        .toString());
                this.vecTableInsert.addElement(vecTempTableInsert.get(i)
                        .toString());
                this.vecTableTableMode.addElement(vecTempTableTableMode.get(i)
                        .toString());
                this.vecTableOidLogic.addElement(vecTempTableOidLogic.get(i)
                        .toString());
            }
        }
    }

    /**
     * Method changeRelationsOrder change order of relation tags. Order of
     * relation tags depends of 'complex relations'. Method puts at the begining
     * of relation global Vectors relations which is used only to read source
     * values for another relation.
     * 
     */
    private void changeRelationsOrder() {
        Vector vecTempSourceTableName = new Vector();
        Vector vecTempSourceTableID = new Vector();
        Vector vecTempSourceColumnName = new Vector();
        Vector vecTempTargetTableName = new Vector();
        Vector vecTempTargetTableID = new Vector();
        Vector vecTempTargetColumnName = new Vector();
        Vector vecTempRelationMode = new Vector();
        Vector vecRelationsOrder = new Vector();
        vecRelationsOrder.setSize(this.vecRelationColumnSourceTableName.size());
        for (int i = 0; i < vecRelationsOrder.size(); i++)
            vecRelationsOrder.setElementAt(new Integer(i), i);
        for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
            if (this.vecRelationColumnRelationMode.get(i).toString()
                    .equalsIgnoreCase("Key")) {
                for (int j = 0; j < this.vecRelationColumnSourceTableName
                        .size(); j++) {
                    if (this.vecRelationColumnSourceTableName.get(i).toString()
                            .equalsIgnoreCase(
                                    this.vecRelationColumnTargetTableName
                                            .get(j).toString())
                            && this.vecRelationColumnSourceTableID.get(i)
                                    .toString().equalsIgnoreCase(
                                            this.vecRelationColumnTargetTableID
                                                    .get(j).toString()))
                        vecRelationsOrder = this.setAfter(vecRelationsOrder, i,
                                j);
                }
            } else {
                vecRelationsOrder = this.setLast(vecRelationsOrder, i);
            }
        }
        for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
            vecTempSourceTableName.add(this.vecRelationColumnSourceTableName
                    .get(i));
            vecTempSourceTableID
                    .add(this.vecRelationColumnSourceTableID.get(i));
            vecTempSourceColumnName.add(this.vecRelationColumnSourceColumnName
                    .get(i));
            vecTempTargetTableName.add(this.vecRelationColumnTargetTableName
                    .get(i));
            vecTempTargetTableID
                    .add(this.vecRelationColumnTargetTableID.get(i));
            vecTempTargetColumnName.add(this.vecRelationColumnTargetColumnName
                    .get(i));
            vecTempRelationMode.add(this.vecRelationColumnRelationMode.get(i));
        }
        for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
            this.vecRelationColumnSourceTableName.setElementAt(
                    vecTempSourceTableName.get(Integer
                            .parseInt(vecRelationsOrder.get(i).toString())), i);
            this.vecRelationColumnSourceTableID.setElementAt(
                    vecTempSourceTableID.get(Integer.parseInt(vecRelationsOrder
                            .get(i).toString())), i);
            this.vecRelationColumnSourceColumnName.setElementAt(
                    vecTempSourceColumnName.get(Integer
                            .parseInt(vecRelationsOrder.get(i).toString())), i);
            this.vecRelationColumnTargetTableName.setElementAt(
                    vecTempTargetTableName.get(Integer
                            .parseInt(vecRelationsOrder.get(i).toString())), i);
            this.vecRelationColumnTargetTableID.setElementAt(
                    vecTempTargetTableID.get(Integer.parseInt(vecRelationsOrder
                            .get(i).toString())), i);
            this.vecRelationColumnTargetColumnName.setElementAt(
                    vecTempTargetColumnName.get(Integer
                            .parseInt(vecRelationsOrder.get(i).toString())), i);
            this.vecRelationColumnRelationMode.setElementAt(
                    vecTempRelationMode.get(Integer.parseInt(vecRelationsOrder
                            .get(i).toString())), i);
        }
    }

    /**
     * Method setLast changes order of vecOrder's elements. Element at
     * iRelationTag position will be removed and inserted at the end of Vector.
     * 
     * @param vecOrder
     *            Vector - order of relation tags
     * @param iRelationTag
     *            integer - position of element in Vector which changes its
     *            position.
     * @return Vector - order of relation tags after changing positions of
     *         elements.
     */
    private Vector setLast(Vector vecOrder, int iRelationTag) {
        int iLast = vecOrder.indexOf(new Integer(iRelationTag));
        vecOrder.remove(iLast);
        vecOrder.add(new Integer(iRelationTag));
        return vecOrder;
    }

    /**
     * Method setAfter changes order of vecOrder's elements. Element at
     * iIndexCurrent position will be removed and inserted after element at
     * iIndexTarget position.
     * 
     * @param vecOrder
     *            Vector - order of relation tags
     * @param iIndexCurrent
     *            integer - position of element in Vector which changes its
     *            position.
     * @param iIndexTarget
     *            integer - position of 'target' element in Vector .
     * @return Vector - order of relation tags after changing element's
     *         positions.
     */
    Vector setAfter(Vector vecOrder, int iIndexCurrent, int iIndexTarget) {
        if (iIndexCurrent < iIndexTarget) {
            int iCurrent = vecOrder.indexOf(new Integer(iIndexCurrent));
            vecOrder.remove(iCurrent);
            int iTarget = vecOrder.indexOf(new Integer(iIndexTarget));
            vecOrder.insertElementAt(new Integer(iIndexCurrent), iTarget + 1);
        }
        return vecOrder;
    }

    /**
     * Method executeSQLStatement is used to execute SQL statement. This method
     * executes and commit changes immediately. JDBC parameters, Continue on
     * Error parameters and SQL statements are set in XML file. If there is an
     * error Exception "Exception" is thrown.
     * 
     * @throws Exception
     */
    private void executeSQLStatement() throws Exception {
        Connection conn = null;
        try {
            this.logger
                    .write("full", "\tmethod executeSQLStatement is started");
            // this.logger.write("normal", "SQL statement " + this.strSqlName +
            // " is started");
            Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver());
            conn = DriverManager.getConnection(jdbcParametersElement
                    .getJDBCTargetParameterConnection(), jdbcParametersElement
                    .getJDBCTargetParameterUser(), jdbcParametersElement
                    .getJDBCTargetParameterPassword());
            Statement stmtSeparate = conn.createStatement();
            for (int i = 0; i < this.vecSqlStmt.size(); i++) {
                this.logger.write("full", "\tSQL_stmt : '"
                        + this.vecSqlStmt.get(i).toString()
                        + "' will be executed");
                Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt
                        .get(i).toString());
                for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
                    executeSql(stmtSeparate,
                            vecSingleSqlStmt.get(j).toString(), 0);
                }
            }
            stmtSeparate.close();
            conn.close();
        } catch (SQLException e) {
            throw e;
        } finally {
            if (conn != null && !conn.isClosed())
                conn.close();
        }
    }

    /**
     * Method executeSQLStatement is used to execute SQL statement. This method
     * commit changes immediately only if is commit paremeter true. If it is
     * false commit changes after all aql stetements. JDBC parameters, Continue
     * on Error parameters and SQL statements are set in XML file. If there is
     * an error Exception "Exception" is thrown.
     * 
     * @param conn
     *            represents connection to target table
     * @throws Exception
     */
    private void executeSQLStatement(Connection conn) throws Exception {
        try {
            this.timeCounter.setStartJobTime();
            this.logger
                    .write("full", "\tmethod executeSQLStatement is started");
            this.logger.write("normal", "SQL statement "
                    + sqlElement.getSqlName() + " is started");
            boolean isCreateDatabaseStatement = false;
            out: for (int i = 0; i < this.vecSqlStmt.size(); i++) {
                if (this.vecSqlStmt.get(i).toString().toUpperCase().trim()
                        .startsWith("CREATE DATABASE")
                        || this.vecSqlStmt.get(i).toString().toUpperCase()
                                .trim().startsWith("DROP DATABASE")) {
                    isCreateDatabaseStatement = true;
                    break out;
                }
            }
            if (isCreateDatabaseStatement) {
                executeSQLStatement();
            } else {

                Statement stmtSeparate = conn.createStatement();
                for (int i = 0; i < this.vecSqlStmt.size(); i++) {
                    this.logger.write("full", "\tSQL_stmt : '"
                            + this.vecSqlStmt.get(i).toString()
                            + "' will be executed");
                    Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt
                            .get(i).toString());
                    for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
                        executeSql(stmtSeparate, vecSingleSqlStmt.get(j)
                                .toString(), j + 1);
                    }
                }
                if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) {
                    if (!conn.getAutoCommit())
                        conn.commit();
                }
                stmtSeparate.close();
            }

            this.logger.write("normal", "SQL statement "
                    + sqlElement.getSqlName() + " is finished");
            this.logger.write("full",
                    "\tmethod executeSQLStatement is finished");
            this.logger.write("normal", " Duration :"
                    + this.timeCounter.getJobTime());
        } catch (SQLException e) {
            throw e;
        }
    }

    /**
     * Method sqlStringToVector is used to cut Sql string with number of
     * statements into vector whose elements are single Sql statemnets.
     * 
     * @param sql
     *            Sql string with number of statements.
     * @return vector of sql statemetns
     */
    private Vector sqlStringToVector(String sql) {
        Vector vecSqlString = new Vector();
        int i = sql.indexOf(";");
        if (i != -1) {
            while (i != -1) {
                // vecSqlString.add(sql.substring(0, i + 1));
                vecSqlString.add(sql.substring(0, i));
                sql = sql.substring(i + 1);
                i = sql.indexOf(";");
            }
        } else

            // vecSqlString.add(sql.trim() + ";");
            vecSqlString.add(sql.trim());
        return vecSqlString;
    }

    /**
     * Method executeSql is used to execute singl Sql statement. If there is an
     * error depends on OnErrorContinue parameter throws exception or not. Error
     * message is always shown. If there is an error, message with the error
     * message, statement and number of statement is shown.
     * 
     * @param stmtSql
     *            Statement.
     * @param sqlStmt
     *            Sql statement to execute.
     * @param i
     *            Number of the Sql statement.
     * @throws SQLException
     */
    private void executeSql(Statement stmtSql, String sqlStmt, int i)
            throws SQLException {
        try {
            if (bReplaceInData) {
                sqlStmt = this.replaceInData(sqlStmt);
            }
            sqlStmt.trim();
            if (sqlStmt.length() != 0)
                stmtSql.execute(sqlStmt);
        } catch (SQLException e) {
            if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("true")) {
                if (sqlElement.getSqlCommit().equalsIgnoreCase("true"))
                    this.logger.write("normal", "\t Error in SQL statement: "
                            + sqlStmt
                            + "  executing SQL statements continue...");
                else
                    this.logger
                            .write(
                                    "normal",
                                    "\t Error in SQL statement: "
                                            + sqlStmt
                                            + "  \n\tStatement is number: "
                                            + i
                                            + " all statements before it is not commited, executing SQL statements continue...");
                LoaderException le = new LoaderException("SQLException: ",
                        (Throwable) e);
                this.logger.write("full", le.getStackTraceAsString());
                // this.logger.write("normal", "\t " + e.getMessage());
            } else {
                this.logger.write("normal", "\t Error in SQL statement: "
                        + sqlStmt);
                throw e;
            }
        }
    }

    /**
     * Method checkSortColumns checks if sort columns in source table have
     * unique values. If source table have more rows with equal values in sort
     * columns return true, if not return false.
     * 
     * @param connSource -
     *            Connection to the source table.
     * @return boolean - true - source table has more rows with equal values in
     *         sort columns, false - if source table has unique values in sort
     *         columns.
     * @throws LoaderException
     *             with the specified detail message.
     */
    private boolean checkSortColumns(Connection connSource)
            throws LoaderException {
        boolean isEqualValues = false;
        String strQuery = "select ";
        try {
            this.logger.write("full", "\tmethod checkSortColumns is started");
            for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
                    .size(); i++)
                strQuery += importDefinitionElement.vecRestartCounterSortColumn
                        .get(i).toString()
                        + ",";
            strQuery = strQuery.substring(0, strQuery.length() - 1);
            strQuery += " from "
                    + importDefinitionElement.strImportDefinitionTableName;
            strQuery += " order by ";
            for (int j = 0; j < importDefinitionElement.vecRestartCounterSortColumn
                    .size(); j++)
                strQuery += importDefinitionElement.vecRestartCounterSortColumn
                        .get(j).toString()
                        + ", ";
            strQuery = strQuery.substring(0, strQuery.length() - 2);
            this.logger.write("full", "\tQuery '" + strQuery + "'  executes");
            Statement stmtSort = connSource.createStatement();
            ResultSet rsetSort = stmtSort.executeQuery(strQuery);
            endWhile: while (rsetSort.next()) {
                Vector vecSortNewValues = new Vector();
                for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
                        .size(); i++)
                    vecSortNewValues.add(rsetSort.getString(i + 1));
                if (vecSortNewValues.equals(this.vecSortValues)) {
                    isEqualValues = true;
                    break endWhile;
                } else {
                    this.vecSortValues = new Vector();
                    for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
                            .size(); i++)
                        this.vecSortValues.add(vecSortNewValues.get(i));
                }
            }
            rsetSort.close();
            stmtSort.close();
        } catch (SQLException e) {
            LoaderException le = new LoaderException("SQLException: ",
                    (Throwable) e);
            // this.logger.write("normal", le.getCause().toString());
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
        this.logger.write("full", "\tmethod checkSortColumns is finished");
        return isEqualValues;
    }

    /**
     * put your documentation comment here
     * 
     * @param conn
     *            represents connection
     * @exception LoaderException
     */
    private void createObjectIDTable(Connection conn) throws LoaderException {
        try {
            Statement stmt = conn.createStatement();
            String sqlStmt = "";
            if (!(importDefinitionElement.strObjectIDNameColumnName.equals("") || importDefinitionElement.strObjectIDNameColumnValue
                    .equals(""))) {
                sqlStmt = "create table "
                        + importDefinitionElement.strObjectIDTableName + " ("
                        + importDefinitionElement.strObjectIDColumnName
                        + " VARCHAR(30) ,"
                        + importDefinitionElement.strObjectIDNameColumnName
                        + " VARCHAR(30)) NOT NULL;";

            } else {
                sqlStmt = "create table "
                        + importDefinitionElement.strObjectIDTableName + " ("
                        + importDefinitionElement.strObjectIDColumnName
                        + " DECIMAL(19,0) NOT NULL);";
            }
            stmt.execute(sqlStmt);
            String insert = "";
            if (!(importDefinitionElement.strObjectIDNameColumnName.equals("") || importDefinitionElement.strObjectIDNameColumnValue
                    .equals(""))) {
                insert = "insert "
                        + importDefinitionElement.strObjectIDTableName + " ("
                        + importDefinitionElement.strObjectIDNameColumnName
                        + "," + importDefinitionElement.strObjectIDColumnName
                        + ") values ('"
                        + importDefinitionElement.strObjectIDNameColumnValue
                        + "','" + importDefinitionElement.iObjectIDStartValue
                        + "');";
            } else {
                insert = "insert "
                        + importDefinitionElement.strObjectIDTableName + " ("
                        + importDefinitionElement.strObjectIDColumnName
                        + ") values ("
                        + importDefinitionElement.iObjectIDStartValue + ");";
            }
            if (bReplaceInData) {
                insert = this.replaceInData(insert);
            }
            stmt.execute(insert);
            conn.commit();
            stmt.close();
        } catch (SQLException e) {
            LoaderException le = new LoaderException("SQLException: ",
                    (Throwable) e);
            // this.logger.write("normal", le.getCause().toString());
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }
    }

    /**
     * put your documentation comment here
     * 
     * @param values
     *            represents map values
     * @return those values
     */
    private static Map convertToMap(String values) {
        Map mapValues = new HashMap();
        int i = values.indexOf(";");
        int k = 0;
        String part = new String(values);
        if (i != -1) {
            while (i != -1) {
                part = new String(values.substring(k, k + i));
                int j = part.indexOf("=");
                String strObject = part.substring(0, j);
                String strValue = part.substring(j + 1);
                if (strValue.equals(""))
                    strValue = null;
                mapValues.put(strObject, strValue);
                k += i + 1;
                i = values.substring(k).indexOf(";");
            }
            if (!(values.substring(k).trim().equals("") || values.substring(k)
                    .trim().equals(";"))) {
                part = new String(values.substring(k));
                int j = part.indexOf("=");
                String strObject = part.substring(0, j);
                String strValue = part.substring(j + 1);
                if (strValue.equals(""))
                    strValue = null;
                mapValues.put(strObject, strValue);
            }
        } else {
            int j = values.indexOf("=");
            String strObject = values.substring(k, j);
            String strValue = values.substring(j + 1);
            if (strValue.equals(""))
                strValue = null;
            mapValues.put(strObject, strValue);
        }
        return mapValues;
    }

    /**
     * Method replaceInData replace data in string if there is the same variable
     * as in attribut prefix+name+suffix in variable tag.
     * 
     * @param s -
     *            String to replace.
     * @return s
     */
    private String replaceInData(String s) {
        // going throw vector
        for (int k = 0; k < this.vecReplaceInData.size(); k++) {
            // if this is to change...
            if (this.vecReplaceInData.get(k).toString()
                    .equalsIgnoreCase("true")) {
                String sPreNameSu = this.vecVariablePrefix.get(k).toString()
                        + this.vecVariableName.get(k).toString()
                        + this.vecVariableSufix.get(k).toString();
                int j = s.indexOf(sPreNameSu);
                // if costant is variable
                while (j != -1) {
                    s = s.substring(0, j)
                            + this.vecVariableValue.get(k).toString()
                            + s.substring(j + sPreNameSu.length(), s.length());
                    j = s.indexOf(sPreNameSu);
                }
            }
        }
        return s;
    }

    /**
     * Method replaceInSelectStatement replace data in string if there is the
     * same variable as in attribut prefix+name+suffix in variable tag.
     * 
     * @param s -
     *            String to replace.
     * @return s
     */
    // private String replaceInSelectStatement(String s) {
    // // going throw vector
    // for (int k = 0; k < this.vecVariableValue.size(); k++) {
    // if( this.vecReplaceInSQL.get(k).toString().equalsIgnoreCase("false"))
    // continue;
    // String sPreNameSu = this.vecVariablePrefix.get(k).toString()
    // + this.vecVariableName.get(k).toString() +
    // this.vecVariableSufix.get(k).toString();
    // int j = s.indexOf(sPreNameSu);
    //      
    // while (j != -1) {
    // s = s.substring(0, j) + this.vecVariableValue.get(k).toString()
    // + s.substring(j + sPreNameSu.length(), s.length());
    // j = s.indexOf(sPreNameSu);
    // }
    // }
    // return s;
    // }
    /**
     * @param s -
     *            String to replace.
     * @param oldChar -
     *            Char
     * @param newValue -
     *            String
     * @return s
     */
    private String replaceChar(String s, char oldChar, String newValue) {

        int j = s.indexOf(oldChar);
        String replacedString = "";
        while (j != -1) {
            replacedString = replacedString + s.substring(0, j) + newValue;
            s = s.substring(j + 1);
            j = s.indexOf(oldChar);
        }
        replacedString = replacedString + s;
        return replacedString;
    }

    /**
     * Method resetGlobalVariables reset all global variables to the start
     * values after each importDefinition job.
     */
    private void resetGlobalVariables() {
        importDefinitionElement.strImportDefinitionName = "";
        importDefinitionElement.strImportDefinitionTableName = "";
        importDefinitionElement.iImportDefinitionCommitCount = 0;
        // importDefinitionElement.strImportDefinitionLogMode = "normal";
        importDefinitionElement.strImportDefinitionSelectStatement = "";
        importDefinitionElement.bObjectIDAutoCreate = loaderJobReader
                .getDefaultObjectIDAutoCreate();
        importDefinitionElement.iObjectIDStartValue = loaderJobReader
                .getDefaultObjectIDStartValue();

        importDefinitionElement.vecRestartCounterSortColumn = new Vector();
        this.iValueColumns = 0;
        this.vecValueColumnsTargetTables = new Vector();
        // this.vecTransformColumnsTargetTables = new Vector();
        this.vecSourceColumnName = new Vector();
        this.vecTargetColumnName = new Vector();
        this.vecValueMode = new Vector();
        this.vecTargetColumnValue = new Vector();
        this.vecTargetKeyColumnName = new Vector();
        this.iConstantColumns = 0;
        this.vecConstantTargetColumnName = new Vector();
        this.vecConstantValueMode = new Vector();
        this.vecConstantConstantValue = new Vector();
        this.vecConstantColumnTargetTableName = new Vector();
        this.vecConstantColumnTargetTableID = new Vector();
        this.iRelationColumns = 0;
        this.vecRelationColumnSourceTableName = new Vector();
        this.vecRelationColumnSourceTableID = new Vector();
        this.vecRelationColumnSourceColumnName = new Vector();
        this.vecRelationColumnTargetTableName = new Vector();
        this.vecRelationColumnTargetColumnName = new Vector();
        this.vecRelationColumnTargetTableID = new Vector();
        this.vecRelationColumnRelationMode = new Vector();
        this.iTables = 0;
        this.vecTableTableName = new Vector();
        this.vecTableTableID = new Vector();
        this.vecTableInsert = new Vector();
        this.vecTableTableMode = new Vector();
        this.vecTableOidLogic = new Vector();
        this.vecRelationSourceValue = new Vector();
        this.vecRelationSourceType = new Vector();
        this.vecTargetColumnType = new Vector();
        this.vecConstantColumnType = new Vector();
        this.bdecOidNumber = new BigDecimal(0);
        this.bdecOidNumber2000 = new BigDecimal(0);
        importDefinitionElement.iObjectID = 0;
        importDefinitionElement.iObjectIDCT = 0;
        importDefinitionElement.strObjectIDTableName = "";
        importDefinitionElement.strObjectIDColumnName = "";
        // TOS
        importDefinitionElement.strObjectIDNameColumnName = "";
        importDefinitionElement.strObjectIDNameColumnValue = "";

        this.vecVariableUseIDTableName = new Vector();
        this.vecVariableUseIDTableID = new Vector();
        this.vecVariableUseIDColumnName = new Vector();
        this.vecVariableUseIDValueMode = new Vector();
        this.vecVariableColumnName = new Vector();
        this.vecVariableColumnTargetTableName = new Vector();
        this.vecVariableColumnTargetTableID = new Vector();
        this.vecVariableColumnTargetColumnName = new Vector();
        this.vecVariableColumnValueMode = new Vector();
        this.vecVariableColumnTypes = new Vector();
        this.vecVariableTimesTableName = new Vector();
        this.vecVariableTimesTableID = new Vector();
        this.vecVariableTimesColumnName = new Vector();
        this.vecVariableTimesValueMode = new Vector();
        this.vecRelationKeyColumns = new Vector();
        this.vecRelationKeyTypes = new Vector();
        this.vecSortValues = new Vector();
        this.vecSqlStmt = new Vector();
        this.strSourceDriverName = "";
        this.strTargetDriverName = "";
        this.iFirstColumnResult = 1;
        this.iTargetFirstColumnResult = 1;
        this.iColumnsInSourceTable = 0;
        // copy table
        this.vecCTAutoMapp = new Vector();
        this.vecCTDefaultMode = new Vector();
        this.vecBlobVector = new Vector();
        // added for transformations
        this.transformationsColumnNames = new Vector();
        this.indexDTransformationOver = new Hashtable();
        this.indexDTransformationNull = new Hashtable();
        this.transformationsValueModes = new Vector();
        this.transformationsColumnTypes = new Vector();
        this.transformationValues = new Vector();

    }

    private String replaceFirst(String input, String forReplace,
            String replaceWith) {
        String retVal = input;
        int start = input.indexOf(forReplace);
        int end = start + forReplace.length();
        if (start != -1) {
            retVal = input.substring(0, start) + replaceWith
                    + input.substring(end);
        }
        return retVal;
    }

    /**
     * This method write values for all input parameters to log file when log
     * level is full
     * 
     * @throws LoaderException
     */
    public String inputToString() throws LoaderException {
        String resString = "";
        try {
            logger.write("full", "Log mode =" + getDefaultLogMode());
            logger.write("full", "Restart indicator =" + getRestartIndicator());
            logger.write("full", "UserID =" + getUserID());
            Hashtable resHashtable = new Hashtable();
            resHashtable = (Hashtable) getVariableValues();
            String pom2 = "";

            if (resHashtable != null) {
                logger.write("full", "Variables =" + resHashtable.toString());
                pom2 = "Variables =" + resHashtable.toString();
            } else {
                logger.write("full", "Variables = null");
                pom2 = "Variables = null";
            }
            logger.write("full", "Log directory =" + getLogDirName());
            logger.write("full", "Log file name =" + getLogFileName());
            logger.write("full", "LoadJob file name =" + getLoadJobFileName());
            logger.write("full", "On error continue =" + getOnErrorContinue());
            logger.write("full", "Commit count =" + getCommitCount());
            logger.write("full", "Return code =" + getDefaultReturnCode());
            logger.write("full", "Vendor conf file =" + getVendorFileName());

            logger.write("full", "Include list =");
            String pom1 = "";
            pom1 = "Include list =";
            String[] listOfJobs = getIncludedJobs();
            for (int j = 0; j < listOfJobs.length; j++) {
                logger.write("full", listOfJobs[j].toString());
                pom1 += listOfJobs[j].toString() + "\n";
            }
            logger.write("full", "Path to conf files in jar ="
                    + getConfJarStructure());
            logger.write("full", "Additional paths =" + getAdditionalPaths());
            resString = "Log mode =" + getDefaultLogMode() + "\n"
                    + "Restart indicator =" + getRestartIndicator() + "\n"
                    + "UserID =" + getUserID() + "\n" + pom2 + "\n"
                    + "Log directory =" + getLogDirName() + "\n"
                    + "Log file name =" + getLogFileName() + "\n"
                    + "LoadJob file name =" + getLoadJobFileName() + "\n"
                    + "On error continue =" + getOnErrorContinue() + "\n"
                    + "Commit count =" + getCommitCount() + "\n"
                    + "Return code =" + getDefaultReturnCode() + "\n"
                    + "Vendor conf file =" + getVendorFileName() + "\n" + pom1
                    + "\n" + "Path to conf files in jar ="
                    + getConfJarStructure() + "\n" + "Additional paths ="
                    + getAdditionalPaths() + "\n";

            return resString;
        } catch (Exception e) {

            LoaderException le = new LoaderException("Exception:"
                    + e.getMessage(), e);
            this.logger.write("full", le.getStackTraceAsString());
            throw le;
        }

    }

    protected java.util.Date getDateFromString(String date) throws Exception {
        Date tmpDate = null;
        try {
            this.logger.write("full", "Try to parse date with src config: "
                    + date);
            String format = this.configReaderSource.getDateFormat();
            SimpleDateFormat formatDate = new SimpleDateFormat(format);
            tmpDate = formatDate.parse(date);
        } catch (ParseException e) {
            try {
                this.logger.write("full",
                        "Try to parse date with target config: " + date);
                String format = this.configReaderTarget.getDateFormat();
                SimpleDateFormat formatDate = new SimpleDateFormat(format);
                tmpDate = formatDate.parse(date);
            } catch (ParseException e1) {
            }
        }
        if (tmpDate != null) {
            return tmpDate;
        } else {
            throw new LoaderException("Unable to parse date: " + date);
        }
    }

    protected void setValueOnStatement(String value, int javaTypeInt, int i,
            PreparedStatement pstmt) throws Exception {
        if (javaTypeInt == 2) { // java.math.BigDecimal
            if (!value.equalsIgnoreCase("null")) {
                BigDecimal number = new BigDecimal(0);
                if (!value.equalsIgnoreCase(""))
                    number = new BigDecimal(value);
                pstmt.setBigDecimal(i, number);
            } else {
                pstmt.setNull(i, java.sql.Types.DECIMAL);
            }
        } else if (javaTypeInt == 3) { // java.lang.Double
            if (!value.equalsIgnoreCase("null")) {
                double number = 0;
                if (!value.equalsIgnoreCase(""))
                    number = Double.parseDouble(value);
                pstmt.setDouble(i, number);
            } else {
                pstmt.setNull(i, java.sql.Types.DOUBLE);
            }
        } else if (javaTypeInt == 4) { // java.lang.Float
            if (!value.equalsIgnoreCase("null")) {
                float number = 0;
                if (!value.equalsIgnoreCase(""))
                    number = Float.parseFloat(value);
                pstmt.setFloat(i, number);
            } else {
                pstmt.setNull(i, java.sql.Types.FLOAT);
            }
        } else if (javaTypeInt == 5) { // java.lang.Integer
            if (!value.equalsIgnoreCase("null")) {
                int number = 0;
                if (!value.equalsIgnoreCase(""))
                    number = Integer.parseInt(value);
                pstmt.setInt(i, number);
            } else {
                pstmt.setNull(i, java.sql.Types.INTEGER);
            }

        } else if (javaTypeInt == 6) { // java.lang.Long
            if (!value.equalsIgnoreCase("null")) {
                long number = 0;
                if (!value.equalsIgnoreCase(""))
                    number = Long.parseLong(value);
                pstmt.setLong(i, number);
            } else {
                pstmt.setNull(i, java.sql.Types.DOUBLE);
            }
        } else if (javaTypeInt == 7) { // java.lang.Short
            if (!value.equalsIgnoreCase("null")) {
                short number = 0;
                if (!value.equalsIgnoreCase(""))
                    number = Short.parseShort(value);
                pstmt.setShort(i, number);
            } else {
                pstmt.setNull(i, java.sql.Types.SMALLINT);
            }
        } else if (javaTypeInt == 8) { // java.lang.String
            if (!value.equalsIgnoreCase("null")) {
                // all '' back to ' (original value)
                if (value.indexOf("''") != -1) {
                    value = Utils.replaceAll(value, "''", "'");
                }
                pstmt.setString(i, value);
            } else {
                pstmt.setNull(i, java.sql.Types.VARCHAR);
            }
        } else if (javaTypeInt == 9) { // java.sql.Date
            if (!value.equalsIgnoreCase("null")) {
                // String format = this.configReaderSource.getDateFormat();
                // SimpleDateFormat formatDate = new SimpleDateFormat(format);
                // Date tmpDate = formatDate.parse(value);
                try {
                    pstmt.setDate(i, new java.sql.Date(getDateFromString(value)
                            .getTime()));
                } catch (Exception e) {
                    this.logger.write("normal", "call setString on date: "
                            + value);
                    pstmt.setString(i, value);
                }
                // }

            } else {
                pstmt.setNull(i, java.sql.Types.DATE);
            }
        } else if (javaTypeInt == 10) { // java.sql.Time
            if (!value.equalsIgnoreCase("null")) {
                // String format = this.configReaderSource.getDateFormat();
                // SimpleDateFormat formatDate = new SimpleDateFormat(format);
                // Date tmpDate = formatDate.parse(value);
                try {
                    pstmt.setTime(i, new java.sql.Time(getDateFromString(value)
                            .getTime()));
                } catch (Exception e) {
                    pstmt.setString(i, value);
                }
            } else {
                pstmt.setNull(i, java.sql.Types.TIME);
            }

        } else if (javaTypeInt == 11) { // java.sql.Timestamp
            if (!value.equalsIgnoreCase("null")) {
                // String format = this.configReaderSource.getDateFormat();
                // SimpleDateFormat formatDate = new SimpleDateFormat(format);
                // Date tmpDate = formatDate.parse(value);
                try {
                    pstmt.setTimestamp(i, new Timestamp(
                            getDateFromString(value).getTime()));
                } catch (Exception e) {
                    pstmt.setString(i, value);
                }
            } else {
                pstmt.setNull(i, java.sql.Types.TIMESTAMP);
            }

        } else if (javaTypeInt == 12) { // java.lang.Boolean
            if (!value.equalsIgnoreCase("null")) {
                boolean bool = new Boolean(value).booleanValue();
                pstmt.setBoolean(i, bool);
            } else {
                // TODO test this peace of code
                pstmt.setNull(i, java.sql.Types.BIT);
            }
        } else if (javaTypeInt == 13) { // java.lang.Byte
            if (!value.equalsIgnoreCase("null")) {
                pstmt.setString(i, value);
            } else {
                pstmt.setNull(i, java.sql.Types.BIT);
            }
        } else if (javaTypeInt == 14) { // java.lang.Object
            if (!value.equalsIgnoreCase("null")) {
                pstmt.setString(i, value);
            } else {
                // TODO zoran pogledati ovo
                try {
                    pstmt.setNull(i, java.sql.Types.NULL);
                } catch (Exception e) {
                    pstmt.setString(i, null);
                }
            }
        }
    }
    
    //senka added
    protected String getSQLRelationString(ResultSet rs){
      String res="";
      String r="";
      String temp="";
      int col=0;
      int counter=1;
      
      if (this.iTargetFirstColumnResult == 1) col=1;              
      try {
        try {
        if (!configReaderTarget.isNumber(rs.getMetaData().getColumnTypeName(col))) temp="'";
      } catch (LoaderException e) {
        e.printStackTrace();
      }
      Object obj=rs.getObject(col);
            if (obj!=null){ 
          res=res+temp+obj.toString()+temp+",";
          while (rs.next()){
             obj=rs.getObject(col);  
             if (obj!=null){
               res=res+temp+obj.toString()+temp;
               res=res+",";
               counter++;
             }
          }
            } else{
              res=res+temp+"null"+temp+",";
            }  
 
      
    } catch (SQLException e) {
      e.printStackTrace();
    }
    
    if (counter==1) {
      r=res.substring(temp.length(),res.length()-1-temp.length());
    }
    else{
      r=" IN ("+res.substring(0,res.length()-1)+")";
    }
      return r;
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.