Source Code Cross Referenced for Loader.java in  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » loader » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » octopus » org.webdocwf.util.loader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


00001:        /*
00002:         Loader - tool for transfering data from one JDBC source to another and
00003:         doing transformations during copy.
00004:         Copyright (C) 2002-2003  Together
00005:         This library is free software; you can redistribute it and/or
00006:         modify it under the terms of the GNU Lesser General Public
00007:         License as published by the Free Software Foundation; either
00008:         version 2.1 of the License, or (at your option) any later version.
00009:         This library is distributed in the hope that it will be useful,
00010:         but WITHOUT ANY WARRANTY; without even the implied warranty of
00011:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012:         Lesser General Public License for more details.
00013:         You should have received a copy of the GNU Lesser General Public
00014:         License along with this library; if not, write to the Free Software
00015:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016:         Loader.java
00017:         Date: 03.03.2003.
00018:         @version 2.1 alpha
00019:         @authors:
00020:         Milosevic Sinisa sinisa@prozone.yu
00021:         Radoslav Dutina  rale@prozone.co.yu
00022:         */
00023:
00024:        package org.webdocwf.util.loader;
00025:
00026:        import java.io.ByteArrayInputStream;
00027:        import java.io.ByteArrayOutputStream;
00028:        import java.io.File;
00029:        import java.io.IOException;
00030:        import java.io.InputStream;
00031:        import java.math.BigDecimal;
00032:        import java.net.URL;
00033:        import java.sql.Connection;
00034:        import java.sql.DriverManager;
00035:        import java.sql.PreparedStatement;
00036:        import java.sql.ResultSet;
00037:        import java.sql.ResultSetMetaData;
00038:        import java.sql.SQLException;
00039:        import java.sql.Statement;
00040:        import java.sql.Time;
00041:        import java.sql.Timestamp;
00042:        import java.text.DateFormat;
00043:        import java.text.ParseException;
00044:        import java.text.SimpleDateFormat;
00045:        import java.util.ArrayList;
00046:        import java.util.Date;
00047:        import java.util.HashMap;
00048:        import java.util.Hashtable;
00049:        import java.util.Iterator;
00050:        import java.util.List;
00051:        import java.util.Map;
00052:        import java.util.StringTokenizer;
00053:        import java.util.Vector;
00054:
00055:        import javax.xml.parsers.DocumentBuilder;
00056:        import javax.xml.parsers.DocumentBuilderFactory;
00057:
00058:        import org.w3c.dom.Document;
00059:        import org.w3c.dom.Element;
00060:        import org.w3c.dom.NamedNodeMap;
00061:        import org.w3c.dom.Node;
00062:        import org.w3c.dom.NodeList;
00063:        import org.webdocwf.util.loader.logging.Logger;
00064:        import org.webdocwf.util.loader.logging.StandardLogger;
00065:        import org.webdocwf.util.loader.transformation.QueryTransformationSet;
00066:        import org.webdocwf.util.loader.transformation.Transformation;
00067:        import org.webdocwf.util.loader.transformation.Transformations;
00068:        import org.xml.sax.SAXException;
00069:
00070:        /**
00071:         * <p>
00072:         * Loader class loads data from source database into target database using
00073:         * criteria set in XML file which is used as parameter. Also Loader can execute
00074:         * SQL statements which import from XML file. <br>
00075:         * All loading rolls are set in XML file. Some capabilities of this loader are:
00076:         * there could be more then one importDefinition and number of them is not
00077:         * limited, source and target database could be different, source database could
00078:         * be ASCII,Excel or Access file too, operator (the person or application which
00079:         * starts Loader) have to define. Restart mode with second parameter (optional).
00080:         * </p>
00081:         * <p>
00082:         * There are two possible ways to start Loader. The first is as stand alone
00083:         * application, the sintaxs is: <br>
00084:         * <code><B>java org.webdocwf.util.loader.Loader [-options] urlOfTheXmlFile.xml</B></code>
00085:         * <br>
00086:         * urlOfTheXmlFile.xml is URL of the XML file with loading criteria,<br>
00087:         * </p>
00088:         * <p>
00089:         * The second way is to start Loader as package, the sintax is:<br>
00090:         * <code><B>public Loader(String loadJobFileName, String mode, String userID, String logDirName,
00091:         *	String logFileName, boolean restartIndicator, Map variableValues, String vendorFileName,
00092:         *	boolean onErrorContinue, String additionalPaths, int commitCount, int returnCode);
00093:         * </code><br>
00094:         * ldr.load();</B> <br>
00095:         * If we want to execute Loader class without last for parameters, we must put
00096:         * null as these arguments
00097:         * </p>
00098:         * <p>
00099:         * When the Loader is started the log file is generated. Log file is txt file
00100:         * and its name defines date and time when the Loader is started. There are
00101:         * three Log modes: none - report only begining and finishing the application,
00102:         * and exceptions if there are any, normal - add to log importing blocks and
00103:         * full - with detailed report to operator.
00104:         * </p>
00105:         * <p>
00106:         * Another big adventage of Loader is its possibility to execute any SQL
00107:         * statements in target database. (creating database; creating, modifying and
00108:         * deleting tables...)
00109:         * </p>
00110:         * <p>
00111:         * XML file is the key part for loading criteria. XML tags define how the
00112:         * loading job will be done.
00113:         * </p>
00114:         * 
00115:         * @author Milosevic Sinisa
00116:         * @author Radoslav Dutina
00117:         * @author Zoran Milakovic
00118:         */
00119:        public class Loader {
00120:            int iValueColumns;
00121:
00122:            Vector vecValueColumnsTargetTables = new Vector();
00123:
00124:            // Vector vecTransformColumnsTargetTables = new Vector();
00125:            Vector vecSourceColumnName = new Vector();
00126:
00127:            Vector vecTargetColumnName = new Vector();
00128:
00129:            Vector vecValueMode = new Vector();
00130:
00131:            Vector vecTargetColumnValue = new Vector();
00132:
00133:            Vector vecTargetKeyColumnName = new Vector();
00134:
00135:            Vector vecVariableUseIDTableName = new Vector();
00136:
00137:            Vector vecVariableUseIDTableID = new Vector();
00138:
00139:            Vector vecVariableUseIDColumnName = new Vector();
00140:
00141:            Vector vecVariableUseIDValueMode = new Vector();
00142:
00143:            Vector vecVariableColumnName = new Vector();
00144:
00145:            Vector vecVariableColumnTargetTableName = new Vector();
00146:
00147:            Vector vecVariableColumnTargetTableID = new Vector();
00148:
00149:            Vector vecVariableColumnTargetColumnName = new Vector();
00150:
00151:            Vector vecVariableColumnValueMode = new Vector();
00152:
00153:            Vector vecVariableColumnTypes = new Vector();
00154:
00155:            Vector vecVariableTimesTableName = new Vector();
00156:
00157:            Vector vecVariableTimesTableID = new Vector();
00158:
00159:            Vector vecVariableTimesColumnName = new Vector();
00160:
00161:            Vector vecVariableTimesValueMode = new Vector();
00162:
00163:            int iConstantColumns;
00164:
00165:            Vector vecConstantTargetColumnName = new Vector();
00166:
00167:            Vector vecConstantValueMode = new Vector();
00168:
00169:            Vector vecConstantConstantValue = new Vector();
00170:
00171:            Vector vecConstantColumnTargetTableName = new Vector();
00172:
00173:            Vector vecConstantColumnTargetTableID = new Vector();
00174:
00175:            int iRelationColumns;
00176:
00177:            Vector vecRelationColumnSourceTableName = new Vector();
00178:
00179:            Vector vecRelationColumnSourceTableID = new Vector();
00180:
00181:            Vector vecRelationColumnSourceColumnName = new Vector();
00182:
00183:            Vector vecRelationColumnTargetTableName = new Vector();
00184:
00185:            Vector vecRelationColumnTargetColumnName = new Vector();
00186:
00187:            Vector vecRelationColumnTargetTableID = new Vector();
00188:
00189:            Vector vecRelationColumnRelationMode = new Vector();
00190:
00191:            int iTables;
00192:
00193:            Vector vecTableTableName = new Vector();
00194:
00195:            Vector vecTableTableID = new Vector();
00196:
00197:            Vector vecTableInsert = new Vector();
00198:
00199:            Vector vecTableTableMode = new Vector();
00200:
00201:            Vector vecTableOidLogic = new Vector();
00202:
00203:            Vector vecRelationSourceValue = new Vector();
00204:
00205:            Vector vecRelationSourceType = new Vector();
00206:
00207:            Vector vecTargetColumnType = new Vector();
00208:
00209:            Vector vecConstantColumnType = new Vector();
00210:
00211:            BigDecimal bdecOidNumber = new BigDecimal(0);
00212:
00213:            BigDecimal bdecOidNumber2000 = new BigDecimal(0);
00214:
00215:            String strLoaderJobFileName = "";
00216:
00217:            boolean bRestartIndicator;
00218:
00219:            Map mapVariableValues = new HashMap();
00220:
00221:            boolean bOnErrorContinue;
00222:
00223:            String strUserID = "";
00224:
00225:            String strLogDirName = "";
00226:
00227:            String strLogFileName = "";
00228:
00229:            String strVendorFileName = "";
00230:
00231:            String strAdditionalPaths = "";
00232:
00233:            String confJarStructure = "";
00234:
00235:            // interne Sinisa
00236:            boolean hasRestartCounter;
00237:
00238:            boolean hasUserID;
00239:
00240:            Vector vecRelationKeyColumns = new Vector();
00241:
00242:            Vector vecRelationKeyTypes = new Vector();
00243:
00244:            Vector vecSortValues = new Vector();
00245:
00246:            Vector vecSqlStmt = new Vector();
00247:
00248:            String strSourceDriverName = "";
00249:
00250:            String strTargetDriverName = "";
00251:
00252:            // conf file default
00253:            int iFirstColumnResult = 1;
00254:
00255:            int iTargetFirstColumnResult = 1;
00256:
00257:            //
00258:            Vector vecVariableName = new Vector();
00259:
00260:            Vector vecVariableValue = new Vector();
00261:
00262:            Vector vecVariablePrefix = new Vector();
00263:
00264:            Vector vecVariableSufix = new Vector();
00265:
00266:            Vector vecVariableOverride = new Vector();
00267:
00268:            Vector vecReplaceInConstants = new Vector();
00269:
00270:            Vector vecReplaceInSQL = new Vector();
00271:
00272:            Vector vecReplaceInData = new Vector();
00273:
00274:            Vector vecReplaceInJDBC = new Vector();
00275:
00276:            public static final String LOGMODE_NONE = "none";
00277:
00278:            public static final String LOGMODE_NORMAL = "normal";
00279:
00280:            public static final String LOGMODE_FULL = "full";
00281:
00282:            ByteArrayOutputStream foStreamTmp = new ByteArrayOutputStream();
00283:
00284:            boolean bReplaceInData = false;
00285:
00286:            int iColumnsInSourceTable = 0;
00287:
00288:            boolean isDefaultJdbc = false;
00289:
00290:            private String defaultLogMode = LOGMODE_NORMAL;
00291:
00292:            ArrayList logModes = new ArrayList();
00293:
00294:            // private Cache cacheValues;
00295:            // private EchoElement echo;
00296:            private Logger logger;
00297:
00298:            private CounterColumns counterColumns;
00299:
00300:            private TimeWatch timeCounter;
00301:
00302:            private Transformations transformations;
00303:
00304:            // NEW CLASSES
00305:            private JdbcParametersElement jdbcParametersElement = new JdbcParametersElement();
00306:
00307:            private SqlElement sqlElement = new SqlElement();
00308:
00309:            private ConfigReader configReaderSource = new ConfigReader();
00310:
00311:            private ConfigReader configReaderTarget = new ConfigReader();
00312:
00313:            private LoaderJobAttrReader loaderJobReader = new LoaderJobAttrReader();
00314:
00315:            private ImportDefinitionElement importDefinitionElement = new ImportDefinitionElement();
00316:
00317:            private DataCleaning dataCleaning = new DataCleaning(
00318:                    configReaderTarget);
00319:
00320:            // rale
00321:            private String strQuerySet = "";
00322:
00323:            QueryWhereSet queryWhereSet = null;
00324:
00325:            QueryConstantSet queryConstantSet = null;
00326:
00327:            QueryTransformationSet queryTransformationSet = null;
00328:
00329:            Hashtable queryStatement = new Hashtable();
00330:
00331:            Hashtable indexDValue = new Hashtable();
00332:
00333:            Hashtable indexDRelationValue = new Hashtable();
00334:
00335:            Hashtable indexConstantDValue = new Hashtable();
00336:
00337:            Hashtable indexDVariableValue = new Hashtable();
00338:
00339:            Hashtable indexDTransformationValue = new Hashtable();
00340:
00341:            Hashtable updateStatement = new Hashtable();
00342:
00343:            Hashtable indexDOverwrite = new Hashtable();
00344:
00345:            Hashtable indexDSetNull = new Hashtable();
00346:
00347:            Hashtable updateConstantStatement = new Hashtable();
00348:
00349:            Hashtable indexDConstantOver = new Hashtable();
00350:
00351:            Hashtable indexDConstantNull = new Hashtable();
00352:
00353:            // zk added this
00354:            Hashtable resultVector = new Hashtable();
00355:
00356:            Hashtable updateTransformationStatement = new Hashtable();
00357:
00358:            Hashtable indexDTransformationOver = new Hashtable();
00359:
00360:            Hashtable indexDTransformationNull = new Hashtable();
00361:
00362:            Hashtable indexDTransformationUpdate = new Hashtable();
00363:
00364:            // insert row
00365:            Hashtable queryInsertRow = new Hashtable();
00366:
00367:            Hashtable indexIsNotRelationsColumns = new Hashtable();
00368:
00369:            Hashtable pstmtForInsert = new Hashtable();
00370:
00371:            Hashtable pstmtColumnNames = new Hashtable();
00372:
00373:            // Hashtable pstmtColumnTypes = new Hashtable();
00374:
00375:            Vector pstmtKeys = new Vector();
00376:
00377:            // default value
00378:            Vector vecDefaultValue = new Vector();
00379:
00380:            Vector vecDefaultVariableValue = new Vector();
00381:
00382:            Vector vecDefaultVariableName = new Vector();
00383:
00384:            Vector vecDefaultRelationValue = new Vector();
00385:
00386:            Vector vecTempUserID = new Vector();
00387:
00388:            boolean userIDExists = false;
00389:
00390:            private int currentRow = 0;
00391:
00392:            // coy table
00393:            // source data which are not maped in to target data
00394:            Hashtable allSourceColumnNameNoMap = new Hashtable();
00395:
00396:            Hashtable allSourceColumnValueNoMap = new Hashtable();
00397:
00398:            Hashtable allSourceColumnTypeNoMap = new Hashtable();
00399:
00400:            Vector ImportDefinitionSourceColumnName = new Vector();
00401:
00402:            Vector ImportDefinitionTargetColumnName = new Vector();
00403:
00404:            private String currentJobName = "";
00405:
00406:            Vector vecCTAutoMapp = new Vector();
00407:
00408:            Vector vecCTDefaultMode = new Vector();
00409:
00410:            Vector vecBlobVector = new Vector();
00411:
00412:            Vector vecToHex = new Vector();
00413:
00414:            Vector vecFromHex = new Vector();
00415:
00416:            // caching the relations
00417:            RelationsCache relationsCache = new RelationsCache();
00418:
00419:            private Vector includeTables = new Vector();
00420:
00421:            // caching the 'row check' query
00422:            CheckRowCache checkRowCache = new CheckRowCache();
00423:
00424:            // restart counter
00425:            DataTransmition dataTransmition = new DataTransmition(
00426:                    importDefinitionElement);
00427:
00428:            // oid and version column name
00429:            private String currentOidColumnName = "oid";
00430:
00431:            private String currentVersionColumnName = "version";
00432:
00433:            // private PreparedStatementMethods pstmtMethods=new
00434:            // PreparedStatementMethods();
00435:            private Vector transformationsColumnNames = new Vector();
00436:
00437:            private Vector transformationsValueModes = new Vector();
00438:
00439:            private Vector transformationsColumnValueMode = new Vector();
00440:
00441:            private Vector transformationsColumnTypes = new Vector();
00442:
00443:            private Vector transformationsResultVectorTypes = new Vector();
00444:
00445:            private Vector resultVectorTypes = new Vector();
00446:
00447:            // ValidateSelectStmt validStmt = new ValidateSelectStmt();
00448:
00449:            // number of columns before transformation values from source query
00450:            //    private int iOffsetForTransColumns = 0;
00451:
00452:            // values for transformations, used from source ResultSet for all
00453:            // transformation
00454:            // source coulmns
00455:            Vector transformationValues = new Vector();
00456:
00457:            /**
00458:             * Construct object Loader with an associated parameters.
00459:             * 
00460:             * @param loadJobFileName
00461:             *            defines xml input file.
00462:             * @param mode
00463:             *            defines the default logmode. Possible values are "none",
00464:             *            "normal" (is the default) and "full". Is "normal" otherwise -m
00465:             *            none
00466:             * @param userID
00467:             *            String which is name of user. This argument is used for
00468:             *            writing userID into variable columns. If it is 'null' there is
00469:             *            no define userID columns.
00470:             * @param logDirName
00471:             *            defines the logfile directory. The default is the current
00472:             *            working directory.
00473:             * @param logFileName
00474:             *            defines the logfile name. The default is
00475:             *            "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
00476:             * @param restartIndicator
00477:             *            which is true if "restart" mode and false if "new" mode.
00478:             * @param variableValues
00479:             *            Map defines variables used in variable columns.
00480:             * @param vendorFileName
00481:             *            the filename of the XML DB-vendor configuration file. The
00482:             *            default is "OctopusDBVendors.xml".
00483:             * @param onErrorContinue
00484:             *            defines to set the default of "onErrorContinue" to "true". Is
00485:             *            false otherwise.
00486:             * @param additionalPaths
00487:             *            Extend the classpath with additional paths.
00488:             * @param commitCount
00489:             *            Sets the default commit count. System default is "100".
00490:             * @param returnCode
00491:             *            Sets the default error return code. System default is "1".
00492:             * @param includeTables
00493:             *            defines tables which will be processed
00494:             */
00495:            public Loader(String loadJobFileName, String mode, String userID,
00496:                    String logDirName, String logFileName,
00497:                    boolean restartIndicator, Map variableValues,
00498:                    String vendorFileName, boolean onErrorContinue,
00499:                    String additionalPaths, int commitCount, int returnCode,
00500:                    String[] includeTables, String confJarStructure) {
00501:                this .strLoaderJobFileName = loadJobFileName;
00502:                // defines the log mode,
00503:                if (mode != null) {
00504:                    if (mode.equalsIgnoreCase("none")
00505:                            || mode.equalsIgnoreCase("normal")
00506:                            || mode.equalsIgnoreCase("full")) {
00507:                        // importDefinitionElement.strLogMode = mode;
00508:                        this .defaultLogMode = mode;
00509:                        // sqlElement.strLogMode = mode;
00510:                    } // else {
00511:                    // importDefinitionElement.strLogMode = "";
00512:                    // sqlElement.strLogMode = "";
00513:                }
00514:
00515:                if (userID != null) {
00516:                    this .strUserID = userID;
00517:                    this .hasUserID = true;
00518:                } else
00519:                    this .hasUserID = false;
00520:                if (logDirName != null)
00521:                    this .strLogDirName = logDirName;
00522:                else {
00523:                    File fCurrent = new File("");
00524:                    this .strLogDirName = fCurrent.getAbsolutePath();
00525:                }
00526:                if (logFileName != null) {
00527:                    this .strLogFileName = logFileName;
00528:                } else
00529:                    this .strLogFileName = "default";
00530:                this .bRestartIndicator = restartIndicator;
00531:                if (this .bRestartIndicator == true)
00532:                    this .hasRestartCounter = true;
00533:                else
00534:                    this .hasRestartCounter = false;
00535:                this .mapVariableValues = variableValues;
00536:                if (vendorFileName != null) {
00537:                    this .strVendorFileName = vendorFileName;
00538:                }
00539:                this .bOnErrorContinue = onErrorContinue;
00540:                if (additionalPaths != null) {
00541:                    try {
00542:                        this .strAdditionalPaths = additionalPaths;
00543:                        StringTokenizer st = new StringTokenizer(
00544:                                this .strAdditionalPaths, ";");
00545:                        URL[] urls = new URL[st.countTokens()];
00546:                        int count = 0;
00547:                        while (st.hasMoreTokens()) {
00548:                            urls[count] = new File(st.nextElement().toString())
00549:                                    .toURL();
00550:                            count++;
00551:                        }
00552:                        for (int i = 0; i < urls.length; i++) {
00553:                            OctopusClassLoader.addURL(urls[i]);
00554:                        }
00555:                    } catch (Exception ne) {
00556:                        ne.printStackTrace();
00557:                    }
00558:                }
00559:                if (includeTables != null) {
00560:                    for (int i = 0; i < includeTables.length; i++) {
00561:                        this .includeTables.add(includeTables[i]);
00562:                    }
00563:                }
00564:                importDefinitionElement.iCommitCount = commitCount;
00565:                ReturnCode.setDefaultErrorReturnCode(returnCode);
00566:                this .confJarStructure = confJarStructure;
00567:            }
00568:
00569:            /**
00570:             * Construct object Loader with an associated parameters.
00571:             * 
00572:             * @param loadJobFileName
00573:             *            defines xml input file.
00574:             * @param mode
00575:             *            defines the default logmode. Possible values are "none",
00576:             *            "normal" (is the default) and "full". Is "normal" otherwise -m
00577:             *            none
00578:             * @param userID
00579:             *            String which is name of user. This argument is used for
00580:             *            writing userID into variable columns. If it is 'null' there is
00581:             *            no define userID columns.
00582:             * @param logDirName
00583:             *            defines the logfile directory. The default is the current
00584:             *            working directory.
00585:             * @param logFileName
00586:             *            defines the logfile name. The default is
00587:             *            "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
00588:             * @param restartIndicator
00589:             *            which is true if "restart" mode and false if "new" mode.
00590:             * @param variableValues
00591:             *            Map defines variables used in variable columns.
00592:             * @param vendorFileName
00593:             *            the filename of the XML DB-vendor configuration file. The
00594:             *            default is "OctopusDBVendors.xml".
00595:             * @param onErrorContinue
00596:             *            defines to set the default of "onErrorContinue" to "true". Is
00597:             *            false otherwise.
00598:             * @param additionalPaths
00599:             *            Extend the classpath with additional paths.
00600:             * @param commitCount
00601:             *            Sets the default commit count. System default is "100".
00602:             * @param returnCode
00603:             *            Sets the default error return code. System default is "1".
00604:             */
00605:            public Loader(String loadJobFileName, String mode, String userID,
00606:                    String logDirName, String logFileName,
00607:                    boolean restartIndicator, Map variableValues,
00608:                    String vendorFileName, boolean onErrorContinue,
00609:                    String additionalPaths, int commitCount, int returnCode) {
00610:
00611:                this (loadJobFileName, mode, userID, logDirName, logFileName,
00612:                        restartIndicator, variableValues, vendorFileName,
00613:                        onErrorContinue, additionalPaths, commitCount,
00614:                        returnCode, null, null);
00615:
00616:            }
00617:
00618:            /**
00619:             * Construct object Loader with an associated parameters.
00620:             * 
00621:             * @param loadJobFileName
00622:             *            defines xml input file.
00623:             * @param mode
00624:             *            defines the default logmode. Possible values are "none",
00625:             *            "normal" (is the default) and "full". Is "normal" otherwise -m
00626:             *            none
00627:             * @param userID
00628:             *            String which is name of user. This argument is used for
00629:             *            writing userID into variable columns. If it is 'null' there is
00630:             *            no define userID columns.
00631:             * @param logDirName
00632:             *            defines the logfile directory. The default is the current
00633:             *            working directory.
00634:             * @param logFileName
00635:             *            defines the logfile name. The default is
00636:             *            "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
00637:             * @param restartIndicator
00638:             *            which is true if "restart" mode and false if "new" mode.
00639:             * @param variableValues
00640:             *            Map defines variables used in variable columns.
00641:             * @param vendorFileName
00642:             *            the filename of the XML DB-vendor configuration file. The
00643:             *            default is "OctopusDBVendors.xml".
00644:             * @param onErrorContinue
00645:             *            defines to set the default of "onErrorContinue" to "true". Is
00646:             *            false otherwise.
00647:             * @param additionalPaths
00648:             *            Extend the classpath with additional paths.
00649:             * @param commitCount
00650:             *            Sets the default commit count. System default is "100".
00651:             * @param returnCode
00652:             *            Sets the default error return code. System default is "1".
00653:             */
00654:            public Loader(String loadJobFileName, String mode, String userID,
00655:                    String logDirName, String logFileName,
00656:                    boolean restartIndicator, Map variableValues,
00657:                    String vendorFileName, boolean onErrorContinue,
00658:                    String additionalPaths, int commitCount, int returnCode,
00659:                    String[] includeTables) {
00660:
00661:                this (loadJobFileName, mode, userID, logDirName, logFileName,
00662:                        restartIndicator, variableValues, vendorFileName,
00663:                        onErrorContinue, additionalPaths, commitCount,
00664:                        returnCode, includeTables, null);
00665:
00666:            }
00667:
00668:            /**
00669:             * Construct object Loader with an associated parameters.
00670:             * 
00671:             * @param loadJobFileName
00672:             *            defines xml input file.
00673:             * @param mode
00674:             *            defines the default logmode. Possible values are "none",
00675:             *            "normal" (is the default) and "full". Is "normal" otherwise -m
00676:             *            none
00677:             * @param userID
00678:             *            String which is name of user. This argument is used for
00679:             *            writing userID into variable columns. If it is 'null' there is
00680:             *            no define userID columns.
00681:             * @param logDirName
00682:             *            defines the logfile directory. The default is the current
00683:             *            working directory.
00684:             * @param logFileName
00685:             *            defines the logfile name. The default is
00686:             *            "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
00687:             * @param restartIndicator
00688:             *            which is true if "restart" mode and false if "new" mode.
00689:             * @param variableValues
00690:             *            Map defines variables used in variable columns.
00691:             * @param vendorFileName
00692:             *            the filename of the XML DB-vendor configuration file. The
00693:             *            default is "OctopusDBVendors.xml".
00694:             * @param onErrorContinue
00695:             *            defines to set the default of "onErrorContinue" to "true". Is
00696:             *            false otherwise.
00697:             * @param additionalPaths
00698:             *            Extend the classpath with additional paths.
00699:             * @param commitCount
00700:             *            Sets the default commit count. System default is "100".
00701:             * @param returnCode
00702:             *            Sets the default error return code. System default is "1".
00703:             */
00704:            public Loader(String loadJobFileName, String mode, String userID,
00705:                    String logDirName, String logFileName,
00706:                    boolean restartIndicator, Map variableValues,
00707:                    String vendorFileName, boolean onErrorContinue,
00708:                    String additionalPaths, int commitCount, int returnCode,
00709:                    String confJarStructure) {
00710:
00711:                this (loadJobFileName, mode, userID, logDirName, logFileName,
00712:                        restartIndicator, variableValues, vendorFileName,
00713:                        onErrorContinue, additionalPaths, commitCount,
00714:                        returnCode, null, confJarStructure);
00715:
00716:            }
00717:
00718:            /**
00719:             * Method addClassPath adds additional class paths into system classpath
00720:             * property
00721:             * 
00722:             * @param oldClassPath -
00723:             *            System classpath;
00724:             * @param add -
00725:             *            additional class paths.
00726:             * @return value of parameter classPath
00727:             */
00728:            private String addClassPath(String oldClassPath, String add) {
00729:
00730:                String classPath = oldClassPath;
00731:                if (System.getProperty("os.name").toLowerCase().startsWith(
00732:                        "win")) {
00733:                    if (!classPath.trim().endsWith(";"))
00734:                        classPath += ";";
00735:                    add = add.replace('\n', '\\');
00736:                    add = add.replace('\t', '\\');
00737:                    add = add.replace('\b', '\\');
00738:                    add = add.replace('\r', '\\');
00739:                    add = add.replace('\f', '\\');
00740:                    classPath = classPath.concat(add);
00741:                } else {
00742:                    if (!classPath.trim().endsWith(":"))
00743:                        classPath += ":";
00744:                    add = add.replace('\n', '/');
00745:                    add = add.replace('\t', '/');
00746:                    add = add.replace('\b', '/');
00747:                    add = add.replace('\r', '/');
00748:                    add = add.replace('\f', '/');
00749:                    classPath = classPath.concat(add);
00750:
00751:                }
00752:                return classPath;
00753:            }
00754:
00755:            /**
00756:             * Public constructor of Loader class. Constructor set value for
00757:             * loadJobFileName attribute. Class set all other attributes to the default
00758:             * values.
00759:             * 
00760:             * @param loadJobFileName
00761:             *            Name of loadJob import XML file.
00762:             * 
00763:             */
00764:            public Loader(String loadJobFileName) {
00765:                this (loadJobFileName, null);
00766:            }
00767:
00768:            /**
00769:             * Public constructor of Loader class. Constructor set value for
00770:             * loadJobFileName attribute. Class set all other attributes to the default
00771:             * values.
00772:             * 
00773:             * @param loadJobFileName
00774:             *            Name of loadJob import XML file.
00775:             * 
00776:             */
00777:            public Loader(String loadJobFileName, String confJarStructure) {
00778:                this .strLoaderJobFileName = loadJobFileName;
00779:                // importDefinitionElement.strLogMode = "";
00780:                this .hasUserID = false;
00781:                File fCurrent = new File("");
00782:                this .strLogDirName = fCurrent.getAbsolutePath();
00783:                this .strLogFileName = "default";
00784:                this .bRestartIndicator = false;
00785:                this .hasRestartCounter = false;
00786:                this .bOnErrorContinue = false;
00787:                importDefinitionElement.iCommitCount = 100;
00788:                ReturnCode.setDefaultErrorReturnCode(1);
00789:                this .confJarStructure = confJarStructure;
00790:            }
00791:
00792:            /**
00793:             * Read value of loadJobFileName attribute.
00794:             * 
00795:             * @return String value of loadFileName attribute
00796:             */
00797:            public String getLoadJobFileName() {
00798:                return this .strLoaderJobFileName;
00799:            }
00800:
00801:            /**
00802:             * This method sets value of loadJobFileName attribute.
00803:             * 
00804:             * @param loadJobFileName
00805:             *            loadJob XML file name
00806:             */
00807:            public void setLoadJobFileName(String loadJobFileName) {
00808:                this .strLoaderJobFileName = loadJobFileName;
00809:            }
00810:
00811:            /**
00812:             * Read value of Mode(LogMode) attribute.
00813:             * 
00814:             * @return value of attribute.
00815:             */
00816:            // public String getMode() {
00817:            // return importDefinitionElement.strLogMode;
00818:            // }
00819:            /**
00820:             * This method sets value of Mode attribute.
00821:             * 
00822:             * @param mode
00823:             *            define Log mode. Possible values are: Loader.LOGMODE_NONE,
00824:             *            Loader.LOGMODE_NORMAL, Loader.LOGMODE_FULL.
00825:             */
00826:            // public void setMode(String mode) {
00827:            // importDefinitionElement.strLogMode = mode;
00828:            // }
00829:            /**
00830:             * Read value of userID attribute.
00831:             * 
00832:             * @return value of attribute.
00833:             */
00834:            public String getUserID() {
00835:                return this .strUserID;
00836:            }
00837:
00838:            /**
00839:             * This method sets value of userID attribute.
00840:             * 
00841:             * @param userID
00842:             *            attribute.
00843:             */
00844:            public void setUserID(String userID) {
00845:                this .strUserID = userID;
00846:            }
00847:
00848:            /**
00849:             * Read value of logDirName attribute
00850:             * 
00851:             * @return value of attribute
00852:             */
00853:            public String getLogDirName() {
00854:                return this .strLogDirName;
00855:            }
00856:
00857:            /**
00858:             * This method sets value of logDirName attribute.
00859:             * 
00860:             * @param logDirName
00861:             *            value of attribute.
00862:             */
00863:            public void setLogDirName(String logDirName) {
00864:                this .strLogDirName = logDirName;
00865:            }
00866:
00867:            /**
00868:             * Read value of logFileName attribute.
00869:             * 
00870:             * @return value of attribute.
00871:             */
00872:            public String getLogFileName() {
00873:                return this .strLogFileName;
00874:            }
00875:
00876:            /**
00877:             * This method sets value of logFileName attribute.
00878:             * 
00879:             * @param logFileName
00880:             *            value of attribute.
00881:             */
00882:            public void setLogFileName(String logFileName) {
00883:                this .strLogFileName = logFileName;
00884:            }
00885:
00886:            /**
00887:             * Read value of restartIndicator attribute.
00888:             * 
00889:             * @return value of attribute.
00890:             */
00891:            public boolean getRestartIndicator() {
00892:                return this .bRestartIndicator;
00893:            }
00894:
00895:            /**
00896:             * This method sets value of restartIndicator attribute.
00897:             * 
00898:             * @param restartIndicator
00899:             *            value of attribute.
00900:             */
00901:            public void setRestartIndicator(boolean restartIndicator) {
00902:                this .bRestartIndicator = restartIndicator;
00903:            }
00904:
00905:            /**
00906:             * Read value of variableValues attribute.
00907:             * 
00908:             * @return value of attribute.
00909:             */
00910:            public Map getVariableValues() {
00911:                return this .mapVariableValues;
00912:            }
00913:
00914:            /**
00915:             * This method sets value of variableValues attribute.
00916:             * 
00917:             * @param variableValue
00918:             *            value of attribute.
00919:             */
00920:            public void setVariableValues(Map variableValue) {
00921:                this .mapVariableValues = variableValue;
00922:            }
00923:
00924:            /**
00925:             * Read value of vendorFileName.
00926:             * 
00927:             * @return value of attribute.
00928:             */
00929:            public String getVendorFileName() {
00930:                return this .strVendorFileName;
00931:            }
00932:
00933:            /**
00934:             * This method sets value of vendorFileName attribute.
00935:             * 
00936:             * @param vendorFileName
00937:             *            value of attribute.
00938:             */
00939:            public void setVendorFileName(String vendorFileName) {
00940:                this .strVendorFileName = vendorFileName;
00941:            }
00942:
00943:            /**
00944:             * read value of onErrorContinue attribute.
00945:             * 
00946:             * @return value of attribute.
00947:             */
00948:            public boolean getOnErrorContinue() {
00949:                return this .bOnErrorContinue;
00950:            }
00951:
00952:            /**
00953:             * This method sets value of onErrorContinue attribute.
00954:             * 
00955:             * @param onErrorContinue
00956:             *            value of attribute.
00957:             */
00958:            public void setOnErrorContinue(boolean onErrorContinue) {
00959:                this .bOnErrorContinue = onErrorContinue;
00960:            }
00961:
00962:            /**
00963:             * Read value of additionalPaths attribute.
00964:             * 
00965:             * @return value of attribute.
00966:             */
00967:            public String getAdditionalPaths() {
00968:                return this .strAdditionalPaths;
00969:            }
00970:
00971:            /**
00972:             * This method sets value of additionalPaths attribute.
00973:             * 
00974:             * @param additionalPaths
00975:             *            value of attribute.
00976:             */
00977:            public void setAdditionalPaths(String additionalPaths) {
00978:                this .strAdditionalPaths = additionalPaths;
00979:                String strClassPath = System.getProperty("java.class.path");
00980:                strClassPath = this .addClassPath(strClassPath,
00981:                        this .strAdditionalPaths);
00982:                try {
00983:                    this .getClass().getClassLoader().loadClass(strClassPath);
00984:                } catch (ClassNotFoundException ne) {
00985:                    ne.printStackTrace();
00986:                }
00987:                // System.setProperty("java.class.path", strClassPath);
00988:            }
00989:
00990:            /**
00991:             * Read value of commitCount attribute.
00992:             * 
00993:             * @return value of attribute.
00994:             */
00995:            public int getCommitCount() {
00996:                return importDefinitionElement.iCommitCount;
00997:            }
00998:
00999:            /**
01000:             * This method sets value of commitCount attribute.
01001:             * 
01002:             * @param commitCount
01003:             *            value of attribute.
01004:             */
01005:            public void setCommitCount(int commitCount) {
01006:                importDefinitionElement.iCommitCount = commitCount;
01007:            }
01008:
01009:            /**
01010:             * Read value of default error return code attribute.
01011:             * 
01012:             * @return value of attribute.
01013:             */
01014:            public int getDefaultReturnCode() {
01015:                return ReturnCode.getDefaultErrorReturnCode();
01016:            }
01017:
01018:            /**
01019:             * This method sets value of default error return code attribute.
01020:             * 
01021:             * @param code
01022:             *            is value of attribute.
01023:             */
01024:            public void setDefaultReturnCode(int code) {
01025:                ReturnCode.setDefaultErrorReturnCode(code);
01026:            }
01027:
01028:            /**
01029:             * This method set value of includeJobs parameter
01030:             * 
01031:             * @param include_Tables
01032:             *            is value of parameter
01033:             */
01034:            public void setIncludedJobs(String include_Tables[]) {
01035:                for (int i = 0; i < include_Tables.length; i++) {
01036:                    includeTables.add(include_Tables[i]);
01037:                }
01038:            }
01039:
01040:            /**
01041:             * This method read value of includeJobs parameter
01042:             * 
01043:             * @return value of parameter
01044:             */
01045:            public String[] getIncludedJobs() {
01046:                String ret[] = new String[this .includeTables.size()];
01047:                for (int i = 0; i < includeTables.size(); i++) {
01048:                    ret[i] = includeTables.get(i).toString();
01049:                }
01050:                return ret;
01051:            }
01052:
01053:            /**
01054:             * This method read value of confJarStructure parameter
01055:             * 
01056:             * @return value of parameter
01057:             */
01058:            public String getConfJarStructure() {
01059:
01060:                return this .confJarStructure;
01061:            }
01062:
01063:            /**
01064:             * This method read value of defaultLogMode parameter
01065:             * 
01066:             * @return value of parameter
01067:             */
01068:            public String getDefaultLogMode() {
01069:
01070:                return this .defaultLogMode;
01071:            }
01072:
01073:            /**
01074:             * Main method Loader with an associated XML, restart mode (optional) i user
01075:             * (optional). Main method controls parameters, it they are OK starts load
01076:             * method, but if they aren't makes alert. Usage: java
01077:             * org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
01078:             * Options: -m defines the default logmode. Possible values are 'none',
01079:             * 'normal' (is the default) and 'full'. -r starts the Loader in restart
01080:             * mode after abnormal termination in a prior execution. -u defines the
01081:             * current UserID used in UserID value columns. -v defines variables used in
01082:             * variable columns. -l defines the logfile directory. The default is the
01083:             * current working directory. -f defines the logfile name. The default is
01084:             * 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. -d the filename of the XML DB-vendor
01085:             * configuration file. The default is 'OctopusDBVendors.xml'. -e defines to
01086:             * set the default of 'onErrorContinue' to 'true'. Is false otherwise. -p
01087:             * Extend the classpath with additional paths. -c Sets the default commit
01088:             * count. System default is '100'. -rc Sets the default error return code.
01089:             * System default is '1'. -it Sets the table names which will be proccesed
01090:             * 
01091:             * @param argv
01092:             *            represents input parmeters
01093:             */
01094:            public static void main(String argv[]) {
01095:                String loadJobFileName = null;
01096:                String mode = null;
01097:                String userID = null;
01098:                String logDirName = null;
01099:                String logFileName = null;
01100:                boolean restartIndicator = false;
01101:                Map variableValues = null;
01102:                String strVariableValues = null;
01103:                String vendorFileName = null;
01104:                boolean onErrorContinue = false;
01105:                String additionalPaths = null;
01106:                int defaultReturnCode = 1;
01107:                int commitCount = 0;
01108:                String[] includeTables = null;
01109:                String confJarStructure = null;
01110:
01111:                if (argv.length > 0 && argv.length < 26) {
01112:                    loadJobFileName = argv[argv.length - 1];
01113:                    for (int i = 0; i < argv.length - 1; i = i + 1) {
01114:                        if (argv[i].equalsIgnoreCase("-m"))
01115:                            mode = argv[++i];
01116:                        else if (argv[i].equalsIgnoreCase("-r"))
01117:                            restartIndicator = true;
01118:                        else if (argv[i].equalsIgnoreCase("-u"))
01119:                            userID = argv[++i];
01120:                        else if (argv[i].equalsIgnoreCase("-l"))
01121:                            logDirName = argv[++i];
01122:                        else if (argv[i].equalsIgnoreCase("-f"))
01123:                            logFileName = argv[++i];
01124:                        else if (argv[i].equalsIgnoreCase("-d"))
01125:                            vendorFileName = argv[++i];
01126:                        else if (argv[i].equalsIgnoreCase("-e"))
01127:                            onErrorContinue = true;
01128:                        else if (argv[i].equalsIgnoreCase("-p"))
01129:                            additionalPaths = argv[++i];
01130:                        else if (argv[i].equalsIgnoreCase("-c"))
01131:                            commitCount = (new Integer(argv[++i])).intValue();
01132:                        else if (argv[i].equalsIgnoreCase("-v")) {
01133:                            strVariableValues = argv[++i];
01134:                            variableValues = new HashMap(
01135:                                    convertToMap(strVariableValues));
01136:                        } else if (argv[i].equalsIgnoreCase("-rc")) {
01137:                            defaultReturnCode = (new Integer(argv[++i]))
01138:                                    .intValue();
01139:                            ReturnCode.isParameter = true;
01140:                        } else if (argv[i].equalsIgnoreCase("-it")) {
01141:                            String array = argv[++i];
01142:                            StringTokenizer st = new StringTokenizer(array, ";");
01143:                            includeTables = new String[st.countTokens()];
01144:                            int pos = 0;
01145:                            while (st.hasMoreTokens()) {
01146:                                includeTables[pos] = st.nextToken();
01147:                                pos++;
01148:                            }
01149:                        } else if (argv[i].equalsIgnoreCase("-cjs")) {
01150:                            confJarStructure = argv[++i];
01151:                        }
01152:                    }
01153:                } else
01154:                    printUsage();
01155:                Loader l = new Loader(loadJobFileName, mode, userID,
01156:                        logDirName, logFileName, restartIndicator,
01157:                        variableValues, vendorFileName, onErrorContinue,
01158:                        additionalPaths, commitCount, defaultReturnCode,
01159:                        includeTables, confJarStructure);
01160:                try {
01161:                    l.load();
01162:                    BufferOctopusClass.getInstance().writeToBuffer(
01163:                            String.valueOf(ReturnCode.getOKReturnCode()));
01164:                } catch (LoaderException le) {
01165:                    BufferOctopusClass.getInstance().writeToBuffer(
01166:                            le.getCause() + "\n");
01167:                    BufferOctopusClass.getInstance().writeToBuffer(
01168:                            String.valueOf(ReturnCode.getErrorReturnCode()));
01169:                    System.exit(ReturnCode.getErrorReturnCode());
01170:                }
01171:            }
01172:
01173:            /**
01174:             * put your documentation comment here
01175:             */
01176:            static void printUsage() {
01177:                System.out
01178:                        .println("Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
01179:                System.out.println(" Options:");
01180:                System.out
01181:                        .println(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
01182:                System.out
01183:                        .println(" -r starts the Loader in restart mode after abnormal termination in a prior execution. \n");
01184:                System.out
01185:                        .println(" -u defines the current UserID used in UserID value columns. \n");
01186:                System.out
01187:                        .println(" -v defines variables used in variable columns.  \n");
01188:                System.out
01189:                        .println(" -l defines the logfile directory. The default is the current working directory.   \n");
01190:                System.out
01191:                        .println(" -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
01192:                System.out
01193:                        .println(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n");
01194:                System.out
01195:                        .println(" -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n");
01196:                System.out
01197:                        .println(" -p Extend the classpath with additional paths \n");
01198:                System.out
01199:                        .println(" -c Sets the default commit count. System default is '100'.  \n");
01200:                System.out
01201:                        .println(" -rc Sets the default error return code. System default is '1'.  \n");
01202:                System.out
01203:                        .println(" -it Sets the table names which will be proccesed ");
01204:                System.exit(ReturnCode.getErrorReturnCode());
01205:            }
01206:
01207:            /**
01208:             * Method load is main method in class Loader. It is used to load data from
01209:             * the source table into target tables and(or) execute SQL statements.
01210:             * Loading parameters are set in XML file. During loading, load status is
01211:             * printed on the screen and also put into log file. If there is an error
01212:             * Exception "LoaderException" is thrown.
01213:             * 
01214:             * @throws LoaderException
01215:             */
01216:            public void load() throws LoaderException {
01217:                int iImportJobs = 0;
01218:                int iCopyTable = 0;
01219:                int iConnection = 0;
01220:                int iSqlTags = 0;
01221:                int iEchoElements = 0;
01222:                int iLastImportDefinition = 0;
01223:                Vector vecXmlElements = new Vector();
01224:                Vector vecJDBCTargetConnections = new Vector();
01225:
01226:                // initializing logger
01227:                // videti jos oko ulaznih parametara, iz main methode ili is xml fajla
01228:                ParseLoggerParam loggerParam = new ParseLoggerParam(
01229:                        this .strLoaderJobFileName);
01230:                String logClassName = loggerParam.getLogClassName();
01231:
01232:                String pathToLoggerConf = loggerParam.getPathToLoggerConf();
01233:                String strLoggerParam = "";
01234:                boolean standardLogger = false;
01235:                try {
01236:                    this .logger = (org.webdocwf.util.loader.logging.Logger) Class
01237:                            .forName(logClassName).newInstance();
01238:                    if (pathToLoggerConf != null
01239:                            && pathToLoggerConf.length() != 0)
01240:                        strLoggerParam = pathToLoggerConf;
01241:                    else
01242:                        strLoggerParam = this .strLogDirName + ";"
01243:                                + this .strLogFileName;
01244:                } catch (Exception e) {
01245:                    this .logger = new StandardLogger();
01246:                    strLoggerParam = this .strLogDirName + ";"
01247:                            + this .strLogFileName;
01248:                    standardLogger = true;
01249:                }
01250:
01251:                try {
01252:                    logger.configure(strLoggerParam);
01253:                    logger.setEnabledLogLevels(this .defaultLogMode);
01254:                    if (standardLogger == true) {
01255:                        // if
01256:                        // (!importDefinitionElement.strLogMode.equalsIgnoreCase("none"))
01257:                        // {
01258:                        this .logger.write("normal",
01259:                                "Default (Standard) Logger is load.");
01260:                        // }
01261:                    }
01262:
01263:                } catch (Exception ex) {
01264:                    String msg = "Error while configuring logger.";
01265:                    LoaderException le = new LoaderException(msg + "\n"
01266:                            + ex.getMessage(), (Throwable) ex);
01267:                    BufferOctopusClass.getInstance().writeToBuffer(
01268:                            msg + "\n" + ex.getMessage() + "\n");
01269:                    // this.logger.write("normal", msg + "\n" + ex.getMessage() + "\n");
01270:                    this .logger.write("full", le.getStackTraceAsString());
01271:                    throw le;
01272:                }
01273:
01274:                this .timeCounter = new TimeWatch();
01275:
01276:                // if (!this.echo.createLog(this.strLogDirName, this.strLogFileName))
01277:                // this.echo.setLogFile(new File(this.strLogDirName,
01278:                // this.strLogFileName));
01279:                // this.createLog(this.strLogFileName);
01280:
01281:                jdbcParametersElement.setLogger(this .logger);
01282:                jdbcParametersElement
01283:                        .setConfigReaderSource(this .configReaderSource);
01284:                jdbcParametersElement
01285:                        .setLoaderJobPath(this .strLoaderJobFileName);
01286:
01287:                configReaderSource.setLogger(this .logger);
01288:                configReaderTarget.setLogger(this .logger);
01289:                configReaderSource.setConfJarStructure(this .confJarStructure);
01290:                configReaderTarget.setConfJarStructure(this .confJarStructure);
01291:
01292:                loaderJobReader.setLogger(this .logger);
01293:                loaderJobReader
01294:                        .setDefaultOnErrorContinue(this .bOnErrorContinue);
01295:                sqlElement.setLogger(this .logger);
01296:                sqlElement.setLoaderJob(this .loaderJobReader);
01297:                sqlElement.setConfigReader(this .configReaderTarget);
01298:                sqlElement.setJdbcParametersElement(this .jdbcParametersElement);
01299:                checkRowCache.setLogger(this .logger);
01300:                dataTransmition.setLogger(this .logger);
01301:
01302:                // if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
01303:                this .logger.write("normal", "\nApplication is started.");
01304:                // }
01305:
01306:                this .timeCounter.setStartTime();
01307:                ByteArrayInputStream inStream = null;
01308:                ByteArrayOutputStream foStream = new ByteArrayOutputStream();
01309:                // Loading XML file and replacing include tags
01310:                LoaderXIncluder loaderInclude = new LoaderXIncluder(foStream);
01311:                LocationOfException locationOfException = new LocationOfException(
01312:                        this .strLoaderJobFileName);
01313:                loaderInclude.parseURI(this .strLoaderJobFileName);
01314:                inStream = new ByteArrayInputStream(foStream.toByteArray());
01315:
01316:                // for test only
01317:                // try {
01318:                // File file=new
01319:                // File("c:/Users/Rale/Octopus/ObjectLoader/InputStream.txt");
01320:                // FileOutputStream fileLogr=new FileOutputStream(file);
01321:                // if(file.exists())
01322:                // file.delete();
01323:                // fileLogr.write(foStream.toByteArray());
01324:                // fileLogr.close();
01325:                // } catch(Exception e) { System.out.println("File error"); }
01326:
01327:                // part for validating input xml file
01328:                try {
01329:                    OctopusValidator validator = new OctopusValidator();
01330:                    validator.validate(new ByteArrayInputStream(foStream
01331:                            .toByteArray()));
01332:                } catch (Exception e) {
01333:                    this .logger.write("normal",
01334:                            "Sorry, validation error occurred . Message was: "
01335:                                    + e.getMessage());
01336:
01337:                    BufferOctopusClass.getInstance().writeToBuffer(
01338:                            "Sorry, validation error occurred . Message was: "
01339:                                    + e.getMessage());
01340:                    LoaderException le = new LoaderException("Exception:"
01341:                            + e.getMessage(), (Throwable) e);
01342:                    this .logger.write("full", le.getStackTraceAsString());
01343:                    throw le;
01344:
01345:                }
01346:                // if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
01347:                this .logger.write("normal", "\nXML document is valid.");
01348:
01349:                // }
01350:
01351:                // Import attribute values from variable tags from XML
01352:                this .importVariable(inStream);
01353:                // Setting bReplaceInData if there is even one ReplaceInData attribut
01354:                // in variable tags
01355:                for (int i = 0; i < this .vecReplaceInData.size(); i++) {
01356:                    if (this .vecReplaceInData.get(i).toString()
01357:                            .equalsIgnoreCase("true"))
01358:                        bReplaceInData = true;
01359:                }
01360:                // Change variable values in SQL, JDBC and Constants Tags in XML
01361:                this .foStreamTmp = foStream;
01362:                foStream = new ByteArrayOutputStream();
01363:                LoadVariable loadVariable = new LoadVariable(foStream, this );
01364:                loadVariable.parseURI();
01365:                // refresh inStream with replaced variables
01366:                inStream = new ByteArrayInputStream(foStream.toByteArray());
01367:                loaderJobReader.setDefaultLogMode(this .defaultLogMode);
01368:                loaderJobReader.importLoaderJobAttributes(inStream);
01369:                iImportJobs = this .parseImportJob(inStream);
01370:                iCopyTable = this .parseCopyTable(inStream);
01371:                iSqlTags = sqlElement.parseSql(inStream);
01372:                iEchoElements = this .parseEcho(inStream);
01373:                this .importRestartCounter(inStream);
01374:                vecXmlElements = this .parseMainElements(inStream);
01375:
01376:                // setting the last number of importDefinition tag
01377:                iLastImportDefinition = 0;
01378:                for (int i = 0; i < vecXmlElements.size(); i++) {
01379:                    if (vecXmlElements.get(i).toString().equalsIgnoreCase(
01380:                            "importDefinition"))
01381:                        iLastImportDefinition = i;
01382:                }
01383:                jdbcParametersElement.parseTargetJDBCParameters(inStream);
01384:                DBConnectionManager connManager = new DBConnectionManager(
01385:                        jdbcParametersElement.getTargetConnections());
01386:                Connection connToPools = null;
01387:
01388:                try {
01389:                    this .isDefaultJdbc = jdbcParametersElement
01390:                            .parseImportJDBCDefaultParameters(inStream);
01391:
01392:                    if (this .strVendorFileName != null
01393:                            && !this .strVendorFileName.equals(""))
01394:                        configReaderTarget
01395:                                .setVendorFileName(this .strVendorFileName);
01396:                    // this can be erased!!!?
01397:                    configReaderTarget.readConfigValues(jdbcParametersElement
01398:                            .getTargetDBVendor(), jdbcParametersElement
01399:                            .getTargetDriverName(), "target");
01400:                    this .currentOidColumnName = configReaderTarget
01401:                            .getOidColumnName();
01402:                    this .currentVersionColumnName = configReaderTarget
01403:                            .getVersionColumnName();
01404:
01405:                    if (jdbcParametersElement.getJDBCTargetParameterDriver()
01406:                            .equals("")
01407:                            || jdbcParametersElement
01408:                                    .getJDBCTargetParameterDriver() == null)
01409:                        jdbcParametersElement
01410:                                .setJDBCTargetParameterDriver(configReaderTarget
01411:                                        .getDriverClassName());
01412:                    Class.forName(jdbcParametersElement
01413:                            .getJDBCTargetParameterDriver());
01414:
01415:                    int iImport = 0;
01416:                    int iCopy = 0;
01417:                    int iSql = 0;
01418:                    int iEcho = 0;
01419:                    // main loop
01420:                    for (int l = 0; l < (iImportJobs + iCopyTable + iSqlTags + iEchoElements); l++) {
01421:                        Object tempLogMode = this .logModes.get(l);
01422:                        if (tempLogMode != null && !tempLogMode.equals(""))
01423:                            this .logger.setEnabledLogLevels(tempLogMode
01424:                                    .toString());
01425:                        else
01426:                            this .logger.setEnabledLogLevels(loaderJobReader
01427:                                    .getDefaultLogMode());
01428:                        // reset global variables
01429:                        this .resetGlobalVariables();
01430:                        relationsCache.resetRelationsCache();
01431:                        checkRowCache.resetCheckRowCache();
01432:                        // if
01433:                        // (!importDefinitionElement.strLogMode.equalsIgnoreCase("none"))
01434:                        // {
01435:                        this .logger
01436:                                .write("normal", "\nImport job No. "
01437:                                        + (iImport + iCopy + iSql + 1)
01438:                                        + " is started.");
01439:                        // }
01440:
01441:                        if (vecXmlElements.get(l).toString().equalsIgnoreCase(
01442:                                "importDefinition")) {
01443:                            this .logger
01444:                                    .write("full",
01445:                                            "Importing and parsing XML file is started.");
01446:                            // importing specific jdbc parameters if any exist
01447:                            this .parseAndImport(inStream, iImport, true);
01448:                            jdbcParametersElement.parseImportJDBCParameters(
01449:                                    inStream, iImport + 1, "importDefinition");
01450:
01451:                            configReaderSource.readConfigValues(
01452:                                    jdbcParametersElement.getDbVendor(),
01453:                                    jdbcParametersElement.getDriverName(),
01454:                                    "source");
01455:                            configReaderTarget
01456:                                    .readConfigValues(jdbcParametersElement
01457:                                            .getTargetDBVendor(),
01458:                                            jdbcParametersElement
01459:                                                    .getTargetDriverName(),
01460:                                            "target");
01461:                            // validStmt.setConfigReader(configReaderSource);
01462:                            this .currentOidColumnName = configReaderTarget
01463:                                    .getOidColumnName();
01464:                            this .currentVersionColumnName = configReaderTarget
01465:                                    .getVersionColumnName();
01466:
01467:                        }
01468:                        // rale 24.10.2003
01469:                        else if (vecXmlElements.get(l).toString()
01470:                                .equalsIgnoreCase("copyTable")) {
01471:                            this .logger
01472:                                    .write("full",
01473:                                            "Importing and parsing XML file is started.");
01474:                            this .parseAndImport(inStream, iCopy, false);
01475:                            // this.logger.setEnabledLogLevels(importDefinitionElement.strCopyTableLogMode);
01476:                            jdbcParametersElement.parseImportJDBCParameters(
01477:                                    inStream, iCopy + 1, "copyTable");
01478:
01479:                            configReaderSource.readConfigValues(
01480:                                    jdbcParametersElement.getDbVendor(),
01481:                                    jdbcParametersElement.getDriverName(),
01482:                                    "source");
01483:                            configReaderTarget
01484:                                    .readConfigValues(jdbcParametersElement
01485:                                            .getTargetDBVendor(),
01486:                                            jdbcParametersElement
01487:                                                    .getTargetDriverName(),
01488:                                            "target");
01489:                            this .currentOidColumnName = configReaderTarget
01490:                                    .getOidColumnName();
01491:                            this .currentVersionColumnName = configReaderTarget
01492:                                    .getVersionColumnName();
01493:                        } else if (vecXmlElements.get(l).toString()
01494:                                .equalsIgnoreCase("sql")) {
01495:                            configReaderTarget
01496:                                    .readConfigValues(jdbcParametersElement
01497:                                            .getTargetDBVendor(),
01498:                                            jdbcParametersElement
01499:                                                    .getTargetDriverName(),
01500:                                            "target");
01501:
01502:                            this .currentOidColumnName = configReaderTarget
01503:                                    .getOidColumnName();
01504:                            this .currentVersionColumnName = configReaderTarget
01505:                                    .getVersionColumnName();
01506:
01507:                            // this don't send enything to logger (importSQLStatement)
01508:                            this .logger
01509:                                    .write("full",
01510:                                            "Importing and parsing XML file is started.");
01511:                            this .vecSqlStmt = sqlElement.importSQLStatement(
01512:                                    inStream, iSql);
01513:                            // defining the log mode
01514:                            // if (!sqlElement.getSqlLogMode().equals("") &&
01515:                            // sqlElement.getSqlLogMode() != null)
01516:                            // this.logger.setEnabledLogLevels(sqlElement.getSqlLogMode());
01517:                            // else
01518:                            // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
01519:
01520:                            // importing specific jdbc parameters if any exist
01521:                            this .logger
01522:                                    .write("full",
01523:                                            "Importing and parsing XML file is started.");
01524:                            jdbcParametersElement.parseImportJDBCParameters(
01525:                                    inStream, iSql + 1, "sql");
01526:                        }
01527:                        if (vecXmlElements.get(l).toString().equalsIgnoreCase(
01528:                                "importDefinition")
01529:                                || vecXmlElements.get(l).toString()
01530:                                        .equalsIgnoreCase("sql")
01531:                                || vecXmlElements.get(l).toString()
01532:                                        .equalsIgnoreCase("copyTable")) {
01533:
01534:                            if (jdbcParametersElement
01535:                                    .getJDBCSourceParameterDriver().equals("")
01536:                                    || jdbcParametersElement
01537:                                            .getJDBCSourceParameterDriver() == null)
01538:                                jdbcParametersElement
01539:                                        .setJDBCSourceParameterDriver(configReaderSource
01540:                                                .getDriverClassName());
01541:
01542:                            if (jdbcParametersElement
01543:                                    .getJDBCTargetParameterDriver().equals("")
01544:                                    || jdbcParametersElement
01545:                                            .getJDBCTargetParameterDriver() == null)
01546:                                jdbcParametersElement
01547:                                        .setJDBCTargetParameterDriver(configReaderTarget
01548:                                                .getDriverClassName());
01549:                        }
01550:                        this .logger.write("full",
01551:                                "Importing and parsing XML file is finished.");
01552:
01553:                        connManager.setLoaderJobPath(this .strLoaderJobFileName);
01554:                        connManager.setConnectionPrefix(configReaderTarget
01555:                                .getConnectionPrefix());
01556:                        connManager.setParsePermission(configReaderTarget
01557:                                .getFileSystemDatabase());
01558:
01559:                        try {
01560:                            connToPools = connManager
01561:                                    .getConnection(jdbcParametersElement
01562:                                            .getJDBCTargetParameterConnection());
01563:                            // TODO ZK 17.6 2004. This make problem with Excel
01564:                            // jdbc-odbc.
01565:                            connToPools.setAutoCommit(false);
01566:                        } catch (Exception ex) {
01567:                            String message = "Can't get connection to Target Database."
01568:                                    + "\n"
01569:                                    + "Maybe connection "
01570:                                    + jdbcParametersElement
01571:                                            .getJDBCTargetParameterConnection()
01572:                                    + " is wrong. ";
01573:                            LoaderException le = new LoaderException(
01574:                                    "SQLException: " + message + "\n"
01575:                                            + ex.getMessage() + "\n",
01576:                                    (Throwable) ex);
01577:                            this .logger.write("full", le
01578:                                    .getStackTraceAsString());
01579:                            throw le;
01580:                        }
01581:                        if (vecXmlElements.get(l).toString().equalsIgnoreCase(
01582:                                "importDefinition")) {
01583:                            if (importDefinitionElement.bRestartAutoCreate == true) {
01584:                                dataTransmition
01585:                                        .createRestartCounterTable(connToPools);
01586:                            }
01587:                            this .currentJobName = "importDefinition";
01588:                            String importName = importDefinitionElement.strImportDefinitionName;
01589:                            boolean doJob = true;
01590:                            for (int i = 0; i < this .includeTables.size(); i++) {
01591:                                if (importName
01592:                                        .equalsIgnoreCase(this .includeTables
01593:                                                .get(i).toString())) {
01594:                                    doJob = true;
01595:                                    break;
01596:                                } else {
01597:                                    doJob = false;
01598:                                }
01599:                            }
01600:                            if (doJob) {
01601:                                try {
01602:                                    this .loadSource(connToPools);
01603:
01604:                                } catch (Exception ex) {
01605:                                    // this.logger.write("normal", "\t" +
01606:                                    // ex.getMessage().toString());
01607:                                    LoaderException le = new LoaderException(
01608:                                            "SQLException: ", (Throwable) ex);
01609:                                    this .logger.write("full", le
01610:                                            .getStackTraceAsString());
01611:                                    if (importDefinitionElement.strOnErrorContinueXml
01612:                                            .equalsIgnoreCase("true")) {
01613:                                        this .logger
01614:                                                .write(
01615:                                                        "normal",
01616:                                                        "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'");
01617:                                    } else {
01618:                                        this .logger
01619:                                                .write(
01620:                                                        "normal",
01621:                                                        "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'");
01622:                                        connManager.release("true");
01623:                                        throw le;
01624:                                    }
01625:                                }
01626:                                // release resources
01627:                                finally {
01628:                                    for (int i = 0; i < pstmtForInsert.size(); i++) {
01629:                                        String key = pstmtKeys.get(i)
01630:                                                .toString();
01631:                                        PreparedStatement pstmt = (PreparedStatement) pstmtForInsert
01632:                                                .get(key);
01633:                                        pstmt.close();
01634:                                    }
01635:                                    pstmtKeys.clear();
01636:                                    pstmtForInsert.clear();
01637:                                    // release transformations
01638:                                    List transformations = this .transformations
01639:                                            .getTransformations();
01640:                                    for (int iCount = 0; iCount < transformations
01641:                                            .size(); iCount++) {
01642:                                        ((Transformation) transformations
01643:                                                .get(iCount)).release();
01644:                                    }
01645:                                }
01646:                            } else
01647:                                this .logger.write("normal",
01648:                                        "\tImportDefinition " + importName
01649:                                                + " is excluded from process");
01650:                            // this.logger.setEnabledLogLevels("none");
01651:                            iImport++;
01652:                        }
01653:                        // rale 24.10.2003
01654:                        else if (vecXmlElements.get(l).toString()
01655:                                .equalsIgnoreCase("copyTable")) {
01656:                            if (importDefinitionElement.bRestartAutoCreate == true) {
01657:                                dataTransmition
01658:                                        .createRestartCounterTable(connToPools);
01659:                            }
01660:                            this .currentJobName = "copyTable";
01661:                            String importName = importDefinitionElement.strCopyTableName;
01662:                            boolean doJob = true;
01663:                            for (int i = 0; i < this .includeTables.size(); i++) {
01664:                                if (importName
01665:                                        .equalsIgnoreCase(this .includeTables
01666:                                                .get(i).toString())) {
01667:                                    doJob = true;
01668:                                    break;
01669:                                } else {
01670:                                    doJob = false;
01671:                                }
01672:                            }
01673:                            if (doJob) {
01674:                                try {
01675:                                    this .loadSourceCT(connToPools);
01676:                                } catch (Exception e) {
01677:                                    // this.logger.write("normal", "\t" +
01678:                                    // e.getMessage());
01679:                                    LoaderException le = new LoaderException(
01680:                                            "SQLException: ", (Throwable) e);
01681:                                    this .logger.write("full", le
01682:                                            .getStackTraceAsString());
01683:                                    if (importDefinitionElement.strCopyTableOnErrorContinue
01684:                                            .equalsIgnoreCase("true")) {
01685:                                        this .logger
01686:                                                .write(
01687:                                                        "normal",
01688:                                                        "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'");
01689:                                    } else {
01690:                                        this .logger
01691:                                                .write(
01692:                                                        "normal",
01693:                                                        "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'");
01694:                                        connManager.release("true");
01695:                                        throw le;
01696:                                    }
01697:                                }
01698:                            } else {
01699:                                this .logger.write("normal", "\tCopyTable "
01700:                                        + importName
01701:                                        + " is excluded from process");
01702:                            }
01703:                            // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
01704:                            iCopy++;
01705:                        } else if (vecXmlElements.get(l).toString()
01706:                                .equalsIgnoreCase("echo")) {
01707:                            this .currentJobName = "echo";
01708:                            logger.writeEcho(this .logger
01709:                                    .getMessage(new Integer(iEcho).toString()));
01710:                            iEcho++;
01711:                        } else if (vecXmlElements.get(l).toString()
01712:                                .equalsIgnoreCase("sql")) {
01713:                            this .currentJobName = "sql";
01714:                            String sqlName = sqlElement.getSqlName();
01715:                            boolean doJob = true;
01716:                            for (int i = 0; i < this .includeTables.size(); i++) {
01717:                                if (sqlName.equalsIgnoreCase(this .includeTables
01718:                                        .get(i).toString())) {
01719:                                    doJob = true;
01720:                                    break;
01721:                                } else {
01722:                                    doJob = false;
01723:                                }
01724:                            }
01725:                            if (doJob) {
01726:                                try {
01727:                                    if (sqlElement.getSqlCommit()
01728:                                            .equalsIgnoreCase("true")) {
01729:                                        connToPools.setAutoCommit(true);
01730:                                        // ZK change this because of problems with
01731:                                        // onErrorContinue="true" and commit="true" in
01732:                                        // <sql ...> tag
01733:                                        try {
01734:                                            this 
01735:                                                    .executeSQLStatement(connToPools);
01736:                                        } catch (Exception e) {
01737:                                            throw e;
01738:                                        } finally {
01739:                                            connToPools.setAutoCommit(false);
01740:                                        }
01741:                                    } else
01742:                                        this .executeSQLStatement(connToPools);
01743:                                } catch (Exception e) {
01744:                                    LoaderException le = new LoaderException(
01745:                                            "SQLException: ", (Throwable) e);
01746:                                    // this.logger.write("normal", "\t" +
01747:                                    // e.getMessage());
01748:                                    this .logger.write("full", le
01749:                                            .getStackTraceAsString());
01750:                                    if (sqlElement.getSqlOnErrorContinue()
01751:                                            .equalsIgnoreCase("true")) {
01752:                                        this .logger
01753:                                                .write(
01754:                                                        "normal",
01755:                                                        "\tError : Because OnErrorContinue Attribute is true application is not terminated");
01756:                                    } else if (sqlElement
01757:                                            .getSqlOnErrorContinue()
01758:                                            .equalsIgnoreCase("")
01759:                                            && loaderJobReader
01760:                                                    .getDefaultOnErrorContinue() == true) {
01761:
01762:                                        this .logger
01763:                                                .write(
01764:                                                        "normal",
01765:                                                        "\tError : Because OnErrorContinue Attribute is true application is not terminated");
01766:                                    } else {
01767:                                        this .logger
01768:                                                .write(
01769:                                                        "normal",
01770:                                                        "\tError : Because OnErrorContinue Attribute is false application is terminated");
01771:                                        connManager.release("true");
01772:                                        throw le;
01773:                                    }
01774:                                }
01775:                            } else {
01776:                                this .logger
01777:                                        .write("normal", "\tSql statement "
01778:                                                + sqlName
01779:                                                + " is excluded from process");
01780:                            }
01781:                            iSql++;
01782:                            // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
01783:                        } else {
01784:                            // this.logger.write("normal",
01785:                            // "Error : Loader supports loading data up to maximum 3 SQL
01786:                            // database");
01787:                            LoaderException le = new LoaderException(
01788:                                    "SQLException: ",
01789:                                    (Throwable) (new SQLException(
01790:                                            "Error : Loader supports loading data up to maximum 3 SQL database")));
01791:                            this .logger.write("full", le
01792:                                    .getStackTraceAsString());
01793:                            if (connToPools != null)
01794:                                connManager.release("true");
01795:                            throw le;
01796:                        }
01797:
01798:                        if (!this .hasRestartCounter
01799:                                && iLastImportDefinition == l) {
01800:                            if (connToPools != null && !connToPools.isClosed())
01801:
01802:                                connToPools.commit();
01803:                        }
01804:
01805:                    }
01806:                    this .logger.setEnabledLogLevels(this .defaultLogMode);
01807:                    connManager.release("false");
01808:                    this .logger.write("normal", "All rows are commited.");
01809:                    this .logger.write("normal", "Application is finished.");
01810:                    this .logger.write("normal", "All jobs duration: "
01811:                            + this .timeCounter.getTotalTime());
01812:                } catch (Exception e) {
01813:                    LoaderException le = new LoaderException("Exception: ",
01814:                            (Throwable) e);
01815:                    // this.logger.write("normal", le.getCause().toString());
01816:                    this .logger.write("full", le.getStackTraceAsString());
01817:                    throw le;
01818:                } finally {
01819:                    try {
01820:                        if (connToPools != null && !connToPools.isClosed())
01821:                            connToPools.close();
01822:                        this .logger.close();
01823:                    } catch (SQLException e) {
01824:                        LoaderException le = new LoaderException(
01825:                                "SQLException: ", (Throwable) e);
01826:                        // this.logger.write("normal", le.getCause().toString());
01827:                        this .logger.write("full", le.getStackTraceAsString());
01828:                        throw le;
01829:                    }
01830:                }
01831:            }
01832:
01833:            /**
01834:             * Method loadSourceCT is used to load data from the source table (Csv,
01835:             * MySql, MsSql, Exel...) into target tables.
01836:             * 
01837:             * @param connTarget
01838:             *            is connection object to target database
01839:             * @throws java.lang.Exception
01840:             */
01841:            private void loadSourceCT(Connection connTarget) throws Exception {
01842:
01843:                this .timeCounter.setStartJobTime();
01844:                DateFormat dfNow = DateFormat.getDateTimeInstance();
01845:                Date currentDate = new Date();
01846:
01847:                this .logger.write("full", "\tloadSourceCT method is started.");
01848:                this .logger.write("normal", "Copy Table "
01849:                        + importDefinitionElement.strCopyTableName
01850:                        + " is started at " + dfNow.format(currentDate) + ".");
01851:
01852:                Connection connSource = null;
01853:                ResultSet rsetSource = null;
01854:                ResultSet rsetTarget = null;
01855:                Statement stmtSource = null;
01856:                Statement stmtTarget = null;
01857:                String logStatement = "";
01858:                String strQuery = "";
01859:                Vector vecNewColumnNames = new Vector();
01860:                Vector vecNewColumnTypes = new Vector();
01861:                Hashtable tmpColumnReader = new Hashtable();
01862:
01863:                boolean bOidLogicCurrentTable = new Boolean(
01864:                        importDefinitionElement.strCopyTableOidLogic)
01865:                        .booleanValue();
01866:                boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
01867:                        .equals("") || importDefinitionElement.strObjectIDNameColumnValue
01868:                        .equals(""));
01869:                try {
01870:                    this .checkOidLogic(connTarget);
01871:                    if (configReaderSource.getRequiredUser()) {
01872:                        if (jdbcParametersElement.getJDBCSourceParameterUser()
01873:                                .equals(""))
01874:                            this .inputUser(true);
01875:                        Class.forName(jdbcParametersElement
01876:                                .getJDBCSourceParameterDriver());
01877:                        connSource = DriverManager.getConnection(
01878:                                jdbcParametersElement
01879:                                        .getJDBCSourceParameterConnection(),
01880:                                jdbcParametersElement
01881:                                        .getJDBCSourceParameterUser(),
01882:                                jdbcParametersElement
01883:                                        .getJDBCSourceParameterPassword());
01884:                    } else {
01885:                        Class.forName(jdbcParametersElement
01886:                                .getJDBCSourceParameterDriver());
01887:                        connSource = DriverManager
01888:                                .getConnection(jdbcParametersElement
01889:                                        .getJDBCSourceParameterConnection());
01890:                    }
01891:
01892:                    int iRowNumber = 0;
01893:                    boolean isEndFlag = false;
01894:                    stmtSource = connSource.createStatement();
01895:                    stmtTarget = connTarget.createStatement();
01896:
01897:                    // setCursorName
01898:                    boolean setCursorName = false;
01899:                    if (!importDefinitionElement.setCursorNameCT
01900:                            .equalsIgnoreCase(""))
01901:                        setCursorName = new Boolean(
01902:                                importDefinitionElement.setCursorNameCT)
01903:                                .booleanValue();
01904:                    else
01905:                        setCursorName = configReaderSource
01906:                                .getSetCursorNameEnabled();
01907:
01908:                    if (setCursorName) {
01909:                        long cursorName = System.currentTimeMillis();
01910:                        stmtSource.setCursorName(String.valueOf(cursorName));
01911:                    }
01912:                    // setFetchSize
01913:                    boolean setFetchSize = false;
01914:                    if (!importDefinitionElement.setFetchSizeCT
01915:                            .equalsIgnoreCase(""))
01916:                        setFetchSize = new Boolean(
01917:                                importDefinitionElement.setFetchSizeCT)
01918:                                .booleanValue();
01919:                    else
01920:                        setFetchSize = configReaderSource
01921:                                .getSetFetchSizeEnabled();
01922:
01923:                    if (setFetchSize)
01924:                        stmtSource
01925:                                .setFetchSize(importDefinitionElement.iCopyTableCommitCount);
01926:                    // ZK added this 5.4 2004
01927:                    // begin
01928:                    // next line will give me parameter getColumnsSupported from
01929:                    // *conf.xml. It describe is getColumns() method is suported
01930:                    // by used driver
01931:
01932:                    boolean columnsSuportedTarget = configReaderTarget
01933:                            .getColumnsSupported();
01934:                    boolean columnsSuportedSource = configReaderSource
01935:                            .getColumnsSupported();
01936:
01937:                    strQuery = "select * from ";
01938:
01939:                    // sourceColumnCount is used out of try block also
01940:                    rsetSource = stmtSource
01941:                            .executeQuery(strQuery
01942:                                    + importDefinitionElement.strCopyTableSourceTableName);
01943:                    int sourceColumnCount = rsetSource.getMetaData()
01944:                            .getColumnCount();
01945:                    try {
01946:                        if (columnsSuportedSource) {
01947:                            ResultSet rsetSourceTemp = connSource
01948:                                    .getMetaData()
01949:                                    .getColumns(
01950:                                            connSource.getCatalog(),
01951:                                            null,
01952:                                            importDefinitionElement.strCopyTableSourceTableName,
01953:                                            "%");
01954:                            while (rsetSourceTemp.next()) {
01955:                                vecNewColumnNames.add(rsetSourceTemp
01956:                                        .getString(4));
01957:                            }
01958:                            rsetSourceTemp.close();
01959:
01960:                        } else {
01961:                            // rsetSource and source column count are already maked
01962:                            // above try block
01963:                            for (int i = 1; i < sourceColumnCount + 1; i++) {
01964:                                vecNewColumnNames.add(rsetSource.getMetaData()
01965:                                        .getColumnName(i));
01966:                            }
01967:                        }
01968:
01969:                        if (columnsSuportedTarget) {
01970:                            ResultSet rsetTargetTemp = connTarget
01971:                                    .getMetaData()
01972:                                    .getColumns(
01973:                                            connTarget.getCatalog(),
01974:                                            null,
01975:                                            importDefinitionElement.strCopyTableTargetTableName,
01976:                                            "%");
01977:
01978:                            while (rsetTargetTemp.next()) {
01979:                                String targetColumnName = rsetTargetTemp
01980:                                        .getString(4);
01981:                                String targetColumnType = rsetTargetTemp
01982:                                        .getString(6);
01983:                                tmpColumnReader.put(targetColumnName
01984:                                        .toUpperCase(), targetColumnType);
01985:                            }
01986:                            rsetTargetTemp.close();
01987:
01988:                        } else {
01989:                            if (configReaderTarget.getMaxRowsSupported()) {
01990:                                stmtTarget.setMaxRows(1);
01991:                            }
01992:
01993:                            rsetTarget = stmtTarget
01994:                                    .executeQuery(strQuery
01995:                                            + importDefinitionElement.strCopyTableTargetTableName);
01996:                            int targetColumnCount = 0;
01997:                            targetColumnCount = rsetTarget.getMetaData()
01998:                                    .getColumnCount();
01999:                            for (int i = 1; i < targetColumnCount + 1; i++) {
02000:                                String targetColumnName = rsetTarget
02001:                                        .getMetaData().getColumnName(i);
02002:                                String targetColumnType = rsetTarget
02003:                                        .getMetaData().getColumnTypeName(i);
02004:                                tmpColumnReader.put(targetColumnName
02005:                                        .toUpperCase(), targetColumnType);
02006:                            }
02007:                            rsetTarget.close();
02008:                        }
02009:
02010:                        // same for both cases
02011:                        for (int i = 0; i < vecNewColumnNames.size(); i++) {
02012:                            String columnName = vecNewColumnNames.get(i)
02013:                                    .toString().toUpperCase();
02014:                            String tmpTargetColumnType = tmpColumnReader.get(
02015:                                    columnName).toString();
02016:                            vecNewColumnTypes.add(tmpTargetColumnType);
02017:                        }
02018:
02019:                    }
02020:
02021:                    catch (Exception ex) {
02022:
02023:                        String msg = "In copy table job '"
02024:                                + importDefinitionElement.strCopyTableName
02025:                                + "',"
02026:                                + " Source and Target table are not compatibile.";
02027:                        Exception e = new Exception(msg + "\n"
02028:                                + ex.getMessage());
02029:                        throw e;
02030:                    }
02031:
02032:                    int currentBlock = 0;
02033:                    int blockNumber = 0;
02034:                    int bdecRowCount = 0;
02035:                    int currentVersion = 0;
02036:                    BigDecimal bdecCounter = new BigDecimal(0);
02037:
02038:                    if (configReaderSource.getRowCountEnabled()) {
02039:                        String countSQL = "";
02040:                        try {
02041:                            // countSQL = " select count(*) as \"counter\" from "
02042:                            // + importDefinitionElement.strCopyTableName;
02043:                            countSQL = " select count(*) from "
02044:                                    + importDefinitionElement.strCopyTableName;
02045:                            Statement stmtSourceCount = connSource
02046:                                    .createStatement();
02047:                            ResultSet rsetSourceCount = stmtSourceCount
02048:                                    .executeQuery(countSQL);
02049:                            rsetSourceCount.next();
02050:                            // iRowNumber = rsetSourceCount.getInt("counter");
02051:                            iRowNumber = rsetSourceCount
02052:                                    .getInt(configReaderSource
02053:                                            .getFirstColumnResult());
02054:                            blockNumber = iRowNumber
02055:                                    / importDefinitionElement.iCopyTableCommitCount
02056:                                    + 1;
02057:                            rsetSourceCount.close();
02058:                            stmtSourceCount.close();
02059:                        } catch (Exception e) {
02060:                            this .logger.write(Logger.LOGMODE_NORMAL,
02061:                                    "Error while execute count sql: "
02062:                                            + countSQL);
02063:                        }
02064:                    }
02065:
02066:                    boolean main = true;
02067:                    if (!importDefinitionElement.strRestartCounterTableName
02068:                            .equals("")) {
02069:                        if (this .hasRestartCounter) {
02070:                            bdecCounter = dataTransmition.checkDataTransmition(
02071:                                    connTarget, rsetSource,
02072:                                    this .currentJobName, configReaderTarget
02073:                                            .getFirstColumnResult());
02074:
02075:                            if (bdecCounter != null) {
02076:                                if (bdecCounter.toString()
02077:                                        .equalsIgnoreCase("0")) {
02078:                                    // if is mycounter=0 in myrestart table escape this
02079:                                    // importdefinition
02080:                                    main = false;
02081:                                }
02082:                            } else {
02083:                                bdecCounter = new BigDecimal(0);
02084:                            }
02085:                        }
02086:                    }
02087:
02088:                    while (main) {
02089:                        // iCopyTableCommitCount (ImportDefinition or default (100))
02090:                        this .logger.write("normal", "Import block is started.");
02091:                        currentBlock++;
02092:                        if (configReaderSource.getRowCountEnabled()) {
02093:                            this .logger.write("normal", "Working...  "
02094:                                    + currentBlock + ". block of "
02095:                                    + blockNumber);
02096:                        } else {
02097:                            this .logger.write("normal", "Working...  "
02098:                                    + currentBlock + ". block");
02099:                        }
02100:                        this .logger.write("full", "\tStarted from the "
02101:                                + bdecCounter.add(new BigDecimal(1)).toString()
02102:                                + ". row.");
02103:                        iRowNumber = 0;
02104:
02105:                        QueryInsertRowCt queryInsertRowCt = new QueryInsertRowCt(
02106:                                bOidLogicCurrentTable,
02107:                                isTOS,
02108:                                vecNewColumnNames,
02109:                                vecNewColumnTypes,
02110:                                importDefinitionElement.strCopyTableTargetTableName,
02111:                                this .bdecOidNumber, this .currentOidColumnName,
02112:                                this .currentVersionColumnName,
02113:                                configReaderTarget.getOidDbType(),
02114:                                configReaderTarget.getVersionDbType(),
02115:                                configReaderTarget.getJavaTypeMapings());
02116:
02117:                        String pstmtInsert = queryInsertRowCt
02118:                                .getPreperedStatementForInsert();
02119:                        PreparedStatement pstmt = connTarget
02120:                                .prepareStatement(pstmtInsert);
02121:
02122:                        while (iRowNumber < importDefinitionElement.iCopyTableCommitCount) {
02123:                            if (!rsetSource.next()) {
02124:                                isEndFlag = true;
02125:                                break;
02126:                            }
02127:                            currentRow = iRowNumber;
02128:                            if (bOidLogicCurrentTable) {
02129:                                if (this .bdecOidNumber
02130:                                        .compareTo(this .bdecOidNumber2000) == 0) {
02131:                                    this .checkOidLogic(connTarget);
02132:                                    this .bdecOidNumber = this .bdecOidNumber
02133:                                            .add(new BigDecimal(1));
02134:                                } else {
02135:                                    this .bdecOidNumber = this .bdecOidNumber
02136:                                            .add(new BigDecimal(1));
02137:                                }
02138:                            }
02139:                            try {
02140:                                int mnemonic = -1;
02141:                                String insertForOut = pstmtInsert;
02142:                                for (int i = 1; i < sourceColumnCount + 1; i++) {
02143:                                    String columnType = vecNewColumnTypes.get(
02144:                                            i - 1).toString();
02145:                                    String javaType = (String) configReaderTarget
02146:                                            .getJavaTypeMapings().get(
02147:                                                    columnType.toUpperCase());
02148:
02149:                                    if (javaType == null) {
02150:                                        this .logger.write("normal",
02151:                                                "There is no java type defined for sql type "
02152:                                                        + columnType
02153:                                                                .toUpperCase());
02154:                                        LoaderException le = new LoaderException(
02155:                                                "Exception:",
02156:                                                new Exception(
02157:                                                        "There is no java type defined for sql type "
02158:                                                                + columnType
02159:                                                                        .toUpperCase()));
02160:                                        this .logger.write("full", le
02161:                                                .getStackTraceAsString());
02162:                                        throw le;
02163:                                    }
02164:
02165:                                    int javaTypeInt = Integer
02166:                                            .parseInt(javaType);
02167:                                    if (javaTypeInt == 1) {
02168:                                        byte[] isBlob = rsetSource.getBytes(i);
02169:                                        if (isBlob == null
02170:                                                || isBlob.length == 0) {
02171:                                            pstmt.setBytes(i, null);
02172:                                            mnemonic = insertForOut
02173:                                                    .indexOf("?");
02174:                                            insertForOut = insertForOut
02175:                                                    .substring(0, mnemonic)
02176:                                                    + "BinaryObject(null)"
02177:                                                    + insertForOut
02178:                                                            .substring(mnemonic + 1);
02179:                                        } else {
02180:                                            ByteArrayInputStream bais = new ByteArrayInputStream(
02181:                                                    isBlob);
02182:                                            // TODO see how to solve this on general
02183:                                            // way,best to make configurable which
02184:                                            // method will be called
02185:                                            pstmt.setBytes(i, isBlob);
02186:                                            // pstmt.setBinaryStream(i,bais,isBlob.length);
02187:
02188:                                            mnemonic = insertForOut
02189:                                                    .indexOf("?");
02190:                                            insertForOut = insertForOut
02191:                                                    .substring(0, mnemonic)
02192:                                                    + "BinaryObject"
02193:                                                    + insertForOut
02194:                                                            .substring(mnemonic + 1);
02195:                                        }
02196:                                    } else {
02197:                                        String value = rsetSource.getString(i);
02198:                                        if (value == null)
02199:                                            value = "null";
02200:                                        if (bReplaceInData)
02201:                                            value = this .replaceInData(value);
02202:
02203:                                        this .setValueOnStatement(value,
02204:                                                javaTypeInt, i, pstmt);
02205:
02206:                                        mnemonic = insertForOut.indexOf("?");
02207:                                        insertForOut = insertForOut.substring(
02208:                                                0, mnemonic)
02209:                                                + value
02210:                                                + insertForOut
02211:                                                        .substring(mnemonic + 1);
02212:
02213:                                    } // end of main else
02214:                                } // end of for loop
02215:                                logStatement = insertForOut;
02216:                                this .logger.write("full", "\tQuery '"
02217:                                        + insertForOut + "' will be executed");
02218:                                pstmt.executeUpdate();
02219:                                pstmt.clearParameters();
02220:                            } catch (Exception ex) {
02221:                                if (importDefinitionElement.strCopyTableOnErrorContinue
02222:                                        .equalsIgnoreCase("true")) {
02223:                                    dataCleaning
02224:                                            .cleaningInsert(
02225:                                                    importDefinitionElement.strCopyTableTargetTableName,
02226:                                                    connTarget, currentRow,
02227:                                                    "INSERT", ex.getMessage(),
02228:                                                    "COPY TABLE", logStatement);
02229:                                } else {
02230:                                    throw ex;
02231:                                }
02232:                            }
02233:                            this .logger.write("full",
02234:                                    "\tinsertRow method is finished.");
02235:                            iRowNumber++;
02236:                        } // iRowNumber <
02237:                        // importDefinitionElement.iCopyTableCommitCount
02238:
02239:                        // restart counter table
02240:                        if (!importDefinitionElement.strRestartCounterTableName
02241:                                .equals("")) {
02242:                            if (this .hasRestartCounter) {
02243:                                bdecCounter = bdecCounter.add(new BigDecimal(
02244:                                        iRowNumber));
02245:                                dataTransmition.insertCounter(
02246:                                        this .currentJobName, bdecCounter,
02247:                                        connTarget);
02248:                            }
02249:                        }
02250:                        if (this .hasRestartCounter) {
02251:
02252:                            connTarget.commit();
02253:                            this .logger.write("normal",
02254:                                    "Imported block is commited.");
02255:                            this .logger.write("full", Integer
02256:                                    .toString(iRowNumber)
02257:                                    + " rows are commited.");
02258:                        }
02259:
02260:                        iRowNumber = 0;
02261:                        if (isEndFlag) {
02262:                            break;
02263:                        }
02264:                        pstmt.close();
02265:                    } // while(true)
02266:
02267:                    strQuery = "";
02268:                    rsetSource.close();
02269:                    // rsetTarget.close();
02270:                    stmtSource.close();
02271:                    stmtTarget.close();
02272:                    if (!connSource.isClosed())
02273:                        connSource.close();
02274:
02275:                    // seting mycounter=0 in myrestart table (success)
02276:                    if (!importDefinitionElement.strRestartCounterTableName
02277:                            .equals("")) {
02278:                        if (this .hasRestartCounter) {
02279:                            dataTransmition.resetRestartCounter(connTarget,
02280:                                    this .currentJobName);
02281:                        }
02282:                    }
02283:                    currentDate = new Date();
02284:                    dfNow = DateFormat.getDateTimeInstance();
02285:                    this .logger.write("normal", "Copy table "
02286:                            + importDefinitionElement.strCopyTableName
02287:                            + " is finished at " + dfNow.format(currentDate)
02288:                            + ".");
02289:                    this .logger.write("normal", " Duration of copyTable:"
02290:                            + this .timeCounter.getJobTime());
02291:                } catch (Exception e) {
02292:                    throw e;
02293:                }
02294:            }
02295:
02296:            /**
02297:             * Method loadSource is used to load data from the source table (Csv, MySql,
02298:             * MsSql, Exel...) into target tables. This method uses configuration file
02299:             * OctopusDbVendors.xml. Loading parameters are set in XML file. During
02300:             * loading, load status is printed on the screen and also put into log file.
02301:             * This method is used for loading data by rules which is defined in a
02302:             * single importDefinition. If there is an error Exception "LoaderException"
02303:             * is thrown.
02304:             * 
02305:             * @param connTarget
02306:             *            represents connection of target table.
02307:             * @throws LoaderException
02308:             */
02309:            private void loadSource(Connection connTarget)
02310:                    throws LoaderException {
02311:                int iRowNumber = 0;
02312:                BigDecimal bdecCounter = new BigDecimal(0);
02313:                BigDecimal k = new BigDecimal(0);
02314:                Date currentDate = new Date();
02315:                DateFormat dfNow = DateFormat.getDateTimeInstance();
02316:                boolean columnsSuportedTarget = configReaderTarget
02317:                        .getColumnsSupported();
02318:                this .timeCounter.setStartJobTime();
02319:                this .logger.write("full", "\tloadSource method is started.");
02320:                this .logger.write("normal", "Import definition "
02321:                        + importDefinitionElement.strImportDefinitionName
02322:                        + " is started at " + dfNow.format(currentDate) + ".");
02323:                Connection connSource = null;
02324:
02325:                try {
02326:
02327:                    for (int i = 0; i < this .iTables; i++) {
02328:                        this .counterColumns.setTargetColumnStartValues(
02329:                                this .vecTableTableName.get(i).toString(),
02330:                                this .vecTableTableID.get(i).toString(),
02331:                                connTarget, this .iTargetFirstColumnResult);
02332:                        this .counterColumns.counterColumnTypes(
02333:                                this .vecTableTableName.get(i).toString(),
02334:                                this .vecTableTableID.get(i).toString(),
02335:                                connTarget, this .iTargetFirstColumnResult,
02336:                                columnsSuportedTarget, configReaderTarget);
02337:
02338:                    }
02339:
02340:                    // source
02341:                    if (configReaderSource.getRequiredUser()) {
02342:                        if (jdbcParametersElement.getJDBCSourceParameterUser()
02343:                                .equals(""))
02344:                            this .inputUser(true);
02345:                        Class.forName(jdbcParametersElement
02346:                                .getJDBCSourceParameterDriver());
02347:                        connSource = DriverManager.getConnection(
02348:                                jdbcParametersElement
02349:                                        .getJDBCSourceParameterConnection(),
02350:                                jdbcParametersElement
02351:                                        .getJDBCSourceParameterUser(),
02352:                                jdbcParametersElement
02353:                                        .getJDBCSourceParameterPassword());
02354:
02355:                    } else {
02356:                        Class.forName(jdbcParametersElement
02357:                                .getJDBCSourceParameterDriver());
02358:                        connSource = DriverManager
02359:                                .getConnection(jdbcParametersElement
02360:                                        .getJDBCSourceParameterConnection());
02361:                    }
02362:
02363:                    Statement stmtSource = null;
02364:                    stmtSource = connSource.createStatement();
02365:
02366:                    // target
02367:                    if (importDefinitionElement.bObjectIDAutoCreate == true) {
02368:                        createObjectIDTable(connTarget);
02369:                        connTarget.commit();
02370:                    }
02371:                    // Statement stmtTarget = connTarget.createStatement();
02372:
02373:                    this .constantColumnTypes(connTarget);
02374:                    this .targetColumnTypes(connTarget);
02375:                    this .checkOidLogic(connTarget);
02376:
02377:                    int currentBlock = 0;
02378:                    String strQueryWhere = "";
02379:
02380:                    for (int i = 0; i < this .iTables; i++) {
02381:                        // ZK added 18.5.2004
02382:                        // QueryTransformationSet queryTransformationSet = null;
02383:                        // this.indexDTransformationOver = new Hashtable();
02384:                        // this.indexDTransformationOver = new Hashtable();
02385:                        // this.updateTransformationStatement = new Hashtable();
02386:                        // // end
02387:                        // ZK added this for transformations - 27.04.2004.
02388:                        ArrayList trans = this .transformations
02389:                                .getTransformations();
02390:                        Iterator iTrans = trans.iterator();
02391:
02392:                        while (iTrans.hasNext()) {
02393:                            Transformation temp = (Transformation) iTrans
02394:                                    .next();
02395:
02396:                            // temp.setTargetParameters(this.vecTableTableName.get(i).toString(),this.vecTableTableID.get(i).toString());
02397:                            temp.transformationColumnTypes(connTarget,
02398:                                    this .iTargetFirstColumnResult,
02399:                                    columnsSuportedTarget, configReaderTarget);
02400:
02401:                        }
02402:                        // end
02403:                        // ZK added this for transormations
02404:                        Vector pomTypes;
02405:                        Vector pomNames;
02406:                        Vector pomValueModes;
02407:                        Vector targetKeyColumnNames;
02408:                        Vector targetColumnNames;
02409:                        Vector targetColumnTypes;
02410:                        targetColumnNames = new Vector();
02411:                        targetKeyColumnNames = new Vector();
02412:                        Vector targetValueModes = new Vector();
02413:                        targetColumnTypes = new Vector();
02414:                        pomNames = new Vector();
02415:                        pomTypes = new Vector();
02416:                        pomValueModes = new Vector();
02417:
02418:                        String tableId = this .vecTableTableID.get(i).toString();
02419:                        ArrayList transTableIDs = this .transformations
02420:                                .getTransformationsTableIDs();
02421:                        if (transTableIDs.contains(tableId)) {
02422:
02423:                            for (int j = 0; j < trans.size(); j++) {
02424:                                Transformation pom = (Transformation) trans
02425:                                        .get(j);
02426:                                targetColumnNames = pom.getTargetColumnNames(i);
02427:                                targetColumnTypes = pom.getTargetColumnTypes(i);
02428:                                targetKeyColumnNames = pom
02429:                                        .getTargetKeyColumnNames(i);
02430:                                targetValueModes = pom.getTargetValueModes(i);
02431:
02432:                                for (int o = 0; o < targetColumnTypes.size(); o++) {
02433:                                    pomTypes.add(targetColumnTypes.get(o)
02434:                                            .toString());
02435:                                }
02436:                                for (int o = 0; o < targetColumnNames.size(); o++) {
02437:                                    pomNames.add(targetColumnNames.get(o)
02438:                                            .toString());
02439:                                }
02440:                                for (int o = 0; o < targetValueModes.size(); o++) {
02441:                                    pomValueModes.add(targetValueModes.get(o)
02442:                                            .toString());
02443:                                }
02444:                            }
02445:
02446:                        }
02447:
02448:                        this .transformationsColumnTypes.add(pomTypes);
02449:                        this .transformationsColumnNames.add(pomNames);
02450:                        this .transformationsValueModes.add(pomValueModes);
02451:                        // end
02452:                        boolean bOidLogicCurrentTable = new Boolean(
02453:                                this .vecTableOidLogic.get(i).toString())
02454:                                .booleanValue();
02455:                        boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
02456:                                .equals("") || importDefinitionElement.strObjectIDNameColumnValue
02457:                                .equals(""));
02458:                        boolean oid = false;
02459:                        if (bOidLogicCurrentTable && !isTOS)
02460:                            oid = true;
02461:
02462:                        // source column data which are not maped to targetdatabase
02463:                        LoadAllSourceData allSourceData = null;
02464:                        Vector vecRelationColumns = this .vecRelationColumnTargetColumnName;
02465:                        Vector vecVariableColumns = this .vecVariableColumnTargetColumnName;
02466:                        Vector vecConstantColumns = (Vector) this .vecConstantTargetColumnName
02467:                                .get(i);
02468:
02469:                        Vector vecUseIDColumns = this .vecVariableUseIDColumnName;
02470:                        Vector vecTimesColumns = this .vecVariableTimesColumnName;
02471:
02472:                        String ctAutoMapColumns = this .vecCTAutoMapp.get(i)
02473:                                .toString();
02474:                        String ctDefaultMode = this .vecCTDefaultMode.get(i)
02475:                                .toString();
02476:                        String sourceTableName = importDefinitionElement.strImportDefinitionTableName;
02477:                        // ZK change this. Added new parameter columnsSuportedTarget.
02478:
02479:                        if (ctAutoMapColumns.equalsIgnoreCase("true")) {
02480:                            allSourceData = new LoadAllSourceData(connSource,
02481:                                    sourceTableName,
02482:                                    ImportDefinitionSourceColumnName,
02483:                                    vecTableTableName.get(i).toString(),
02484:                                    connTarget, logger, vecRelationColumns,
02485:                                    vecVariableColumns, vecConstantColumns,
02486:                                    vecUseIDColumns, vecTimesColumns,
02487:                                    columnsSuportedTarget, configReaderTarget);
02488:                        } else {
02489:                            // stmtTarget.close();
02490:                        }
02491:
02492:                        // source column data which are not maped to targetdatabase
02493:                        if (allSourceData != null) {
02494:                            String keySource = String.valueOf(i);
02495:                            allSourceColumnNameNoMap.put(keySource,
02496:                                    allSourceData.getNoMapSourceColumnName());
02497:                            allSourceColumnTypeNoMap.put(keySource,
02498:                                    allSourceData.getNoMapSourceColumnType());
02499:                            allSourceColumnValueNoMap.put(keySource,
02500:                                    allSourceData.getNoMapSourceColumnValue());
02501:                        }
02502:
02503:                        // set new column names, column types and value modes for column
02504:                        // which are not maped in to
02505:                        // target columns
02506:                        if (allSourceData != null) {
02507:                            if (allSourceData.getNoMapSourceColumnName().size() > 0) {
02508:                                for (int o = 0; o < allSourceData
02509:                                        .getNoMapSourceColumnName().size(); o++) {
02510:                                    ((Vector) this .vecTargetColumnName.get(i))
02511:                                            .add(allSourceData
02512:                                                    .getNoMapSourceColumnName()
02513:                                                    .get(o).toString());
02514:                                    ((Vector) this .vecSourceColumnName.get(i))
02515:                                            .add(allSourceData
02516:                                                    .getNoMapSourceColumnName()
02517:                                                    .get(o).toString());
02518:                                    ((Vector) this .vecToHex.get(i)).add("");
02519:                                    ((Vector) this .vecFromHex.get(i)).add("");
02520:                                    ((Vector) this .vecDefaultValue.get(i))
02521:                                            .add("");
02522:                                }
02523:                                int map = Integer
02524:                                        .parseInt(this .vecValueColumnsTargetTables
02525:                                                .get(i).toString());
02526:                                int noMap = allSourceData
02527:                                        .getNoMapSourceColumnName().size();
02528:                                int all = map + noMap;
02529:                                this .vecValueColumnsTargetTables.set(i,
02530:                                        new Integer(all));
02531:                            }
02532:                        }
02533:                        if (allSourceData != null) {
02534:                            if (allSourceData.getNoMapSourceColumnName().size() > 0) {
02535:                                for (int o = 0; o < allSourceData
02536:                                        .getNoMapSourceColumnName().size(); o++) {
02537:                                    ((Vector) this .vecValueMode.get(i))
02538:                                            .add(ctDefaultMode);
02539:                                }
02540:                            }
02541:                        }
02542:                        if (allSourceData != null) {
02543:                            if (allSourceData.getNoMapSourceColumnType().size() > 0) {
02544:                                for (int o = 0; o < allSourceData
02545:                                        .getNoMapSourceColumnType().size(); o++) {
02546:                                    ((Vector) this .vecTargetColumnType.get(i))
02547:                                            .add(allSourceData
02548:                                                    .getNoMapSourceColumnType()
02549:                                                    .get(o).toString());
02550:                                }
02551:                            }
02552:                        }
02553:
02554:                        Vector vecColumnNames = (Vector) this .vecTargetColumnName
02555:                                .get(i);
02556:                        Vector vecColumnTypes = (Vector) this .vecTargetColumnType
02557:                                .get(i);
02558:                        Vector vecValueModes = (Vector) this .vecValueMode
02559:                                .get(i);
02560:
02561:                        // set query statement
02562:                        QuerySet querySet = new QuerySet(i,
02563:                                bOidLogicCurrentTable, isTOS, vecColumnNames,
02564:                                vecTableTableName, this .currentOidColumnName,
02565:                                this .currentVersionColumnName);
02566:
02567:                        // set query where statement
02568:                        queryWhereSet = new QueryWhereSet(vecColumnNames,
02569:                                vecColumnTypes, vecTableTableName.get(i)
02570:                                        .toString(), vecTableTableID.get(i)
02571:                                        .toString());
02572:
02573:                        // set query update statement
02574:                        QueryUpdateSet queryUpdateSet = new QueryUpdateSet(
02575:                                vecColumnNames, vecColumnTypes, vecValueModes,
02576:                                vecTableTableName.get(i).toString(), oid,
02577:                                this .currentVersionColumnName,
02578:                                configReaderTarget);
02579:
02580:                        if (((Vector) this .vecTargetKeyColumnName.get(i))
02581:                                .size() > 0)
02582:                            // ZK change this 7.5.2004. Because of new parameter in
02583:                            // getKeyColumns
02584:                            queryWhereSet
02585:                                    .getKeyColumns(
02586:                                            (Vector) this .vecTargetKeyColumnName
02587:                                                    .get(i), configReaderTarget);
02588:
02589:                        // //ZK added this for transformations
02590:                        if (targetKeyColumnNames.size() > 0)
02591:                            queryWhereSet.getTransformationKeyColumns(
02592:                                    targetColumnNames, targetKeyColumnNames,
02593:                                    targetColumnTypes, configReaderTarget);
02594:                        // //ZK end
02595:
02596:                        if (((Vector) this .vecRelationKeyColumns.get(i)).size() > 0)
02597:                            queryWhereSet.getRelationKeyColumns(
02598:                                    (Vector) vecRelationKeyColumns.get(i),
02599:                                    iRelationColumns,
02600:                                    vecRelationColumnTargetTableName,
02601:                                    vecRelationColumnTargetTableID,
02602:                                    vecRelationColumnTargetColumnName,
02603:                                    // TODO zoran, try this change, vecRelationKeyTypes
02604:                                    // to (Vector)vecRelationKeyTypes.get(i)
02605:                                    (Vector) vecRelationKeyTypes.get(i),
02606:                                    configReaderTarget);
02607:                        if (((Vector) this .vecConstantTargetColumnName.get(i))
02608:                                .size() > 0)
02609:                            queryWhereSet.getConstantKeyColumns(
02610:                                    (Vector) this .vecConstantTargetColumnName
02611:                                            .get(i),
02612:                                    (Vector) this .vecConstantValueMode.get(i),
02613:                                    (Vector) this .vecConstantColumnType.get(i),
02614:                                    configReaderTarget);
02615:
02616:                        if (vecVariableColumnTargetTableName.size() > 0)
02617:                            queryWhereSet.getVariableKeyColumns(
02618:                                    vecVariableColumnTargetTableName,
02619:                                    vecVariableColumnTargetTableID,
02620:                                    vecVariableColumnValueMode,
02621:                                    vecVariableName, vecVariableColumnName,
02622:                                    vecVariableColumnTargetColumnName,
02623:                                    vecVariableColumnTypes, logger,
02624:                                    configReaderTarget);
02625:                        // set insert row
02626:
02627:                        InsertRowQuerySet insertRowQuerySet = new InsertRowQuerySet(
02628:                                connTarget, (Vector) this .vecTargetColumnName
02629:                                        .get(i), (Vector) this .vecValueMode
02630:                                        .get(i), vecTableTableName.get(i)
02631:                                        .toString(), vecTableTableID.get(i)
02632:                                        .toString(), i,
02633:                                (Vector) this .vecConstantTargetColumnName
02634:                                        .get(i), vecVariableTimesTableName,
02635:                                vecVariableTimesTableID,
02636:                                vecVariableTimesColumnName,
02637:                                vecVariableColumnTargetTableName,
02638:                                vecVariableColumnTargetTableID,
02639:                                vecVariableColumnTargetColumnName,
02640:                                vecRelationColumnTargetColumnName,
02641:                                vecRelationColumnTargetTableName,
02642:                                vecRelationColumnTargetTableID,
02643:                                vecRelationColumnRelationMode, counterColumns,
02644:                                transformations, bOidLogicCurrentTable, isTOS,
02645:                                this .currentOidColumnName,
02646:                                this .currentVersionColumnName);
02647:
02648:                        // set query constant statement
02649:                        if (((Vector) this .vecConstantTargetColumnName.get(i))
02650:                                .size() > 0)
02651:                            queryConstantSet = new QueryConstantSet(
02652:                                    vecTableTableName.get(i).toString(),
02653:                                    (Vector) this .vecConstantTargetColumnName
02654:                                            .get(i),
02655:                                    (Vector) this .vecConstantValueMode.get(i),
02656:                                    (Vector) this .vecConstantColumnType.get(i),
02657:                                    configReaderTarget);
02658:                        strQuerySet = querySet.getQuerySet();
02659:                        strQueryWhere = queryWhereSet.getQueryWhere();
02660:
02661:                        if (!(strQueryWhere.length() < 8)) {
02662:                            strQueryWhere = strQueryWhere.substring(0,
02663:                                    strQueryWhere.length() - 4);
02664:                        } else {
02665:                            strQueryWhere = "";
02666:                        }
02667:
02668:                        if ((((Vector) this .transformationsColumnNames).size() > 0))
02669:                            queryTransformationSet = new QueryTransformationSet(
02670:                                    vecTableTableName.get(i).toString(),
02671:                                    (Vector) this .transformationsColumnNames
02672:                                            .get(i),
02673:                                    (Vector) this .transformationsValueModes
02674:                                            .get(i),
02675:                                    (Vector) this .transformationsColumnTypes
02676:                                            .get(i), configReaderTarget);
02677:
02678:                        // } //querySet+queryWhere
02679:                        String strQueryTarget = strQuerySet + strQueryWhere;
02680:                        String key = String.valueOf(i);
02681:                        Vector indexDommyValue = queryWhereSet
02682:                                .getIndexDummyValue();
02683:                        Vector indexDommyRelationValue = queryWhereSet
02684:                                .getIndexDummyRelationValue();
02685:                        Vector indexDommyConstantValue = queryWhereSet
02686:                                .getIndexDummyConstantValue();
02687:                        Vector indexDommyVariableValue = queryWhereSet
02688:                                .getIndexDummyVariableValue();
02689:
02690:                        // ZK added this 28.4.2004 for transformations
02691:                        Vector indexDummyTransformationValue = queryWhereSet
02692:                                .getTransformationKeyColumns();
02693:                        // ZK end
02694:                        queryStatement.put(key, strQueryTarget);
02695:                        indexDValue.put(key, indexDommyValue);
02696:                        indexDRelationValue.put(key, indexDommyRelationValue);
02697:                        indexConstantDValue.put(key, indexDommyConstantValue);
02698:                        indexDVariableValue.put(key, indexDommyVariableValue);
02699:                        // ZK added this 28.4.2004 for transformations
02700:                        indexDTransformationValue.put(key,
02701:                                indexDummyTransformationValue);
02702:                        // end
02703:                        // query update
02704:                        String strUpdateTarget = queryUpdateSet
02705:                                .getQueryUpdate();
02706:                        Vector indexDommyOverwrite = queryUpdateSet
02707:                                .getIndexDummyOverwrite();
02708:                        Vector indexDommySetNull = queryUpdateSet
02709:                                .getIndexDummySetNull();
02710:
02711:                        updateStatement.put(key, strUpdateTarget);
02712:                        indexDOverwrite.put(key, indexDommyOverwrite);
02713:                        indexDSetNull.put(key, indexDommySetNull);
02714:
02715:                        // query update constant columns
02716:                        if (queryConstantSet != null) {
02717:                            String strUpdateConstant = queryConstantSet
02718:                                    .getQueryConstant();
02719:                            Vector indexConstantOver = queryConstantSet
02720:                                    .getIndexDummyOverwrite();
02721:                            Vector indexConstantNull = queryConstantSet
02722:                                    .getIndexDummyNull();
02723:
02724:                            updateConstantStatement.put(key, strUpdateConstant);
02725:                            indexDConstantOver.put(key, indexConstantOver);
02726:                            indexDConstantNull.put(key, indexConstantNull);
02727:                        }
02728:
02729:                        if (queryTransformationSet != null) {
02730:
02731:                            String strUpdateTransformation = queryTransformationSet
02732:                                    .getQueryTransformation();
02733:                            Vector indexTransformationOver = queryTransformationSet
02734:                                    .getIndexDummyOverwrite();
02735:                            Vector indexTransformationNull = queryTransformationSet
02736:                                    .getIndexDummyNull();
02737:                            Vector indexTransformationUpdate = queryTransformationSet
02738:                                    .getIndexDummyUpdate();
02739:
02740:                            updateTransformationStatement.put(key,
02741:                                    strUpdateTransformation);
02742:                            indexDTransformationOver.put(key,
02743:                                    indexTransformationOver);
02744:                            indexDTransformationNull.put(key,
02745:                                    indexTransformationNull);
02746:                            indexDTransformationUpdate.put(key,
02747:                                    indexTransformationUpdate);
02748:                        }
02749:                        // query insert row
02750:                        String strInsertRow = insertRowQuerySet.getStrQuery();
02751:                        Vector indexRelations = insertRowQuerySet
02752:                                .getIndexDummyIsNotRelationsColumn();
02753:                        // prepare statement
02754:                        PreparedStatement pstmt = insertRowQuerySet
02755:                                .getPreparedStatementForInsert();
02756:                        Vector pstmtCNames = insertRowQuerySet.getColumnNames();
02757:                        // Hashtable
02758:                        // pstmtCTypes=insertRowQuerySet.getPreparedStatemetTypes();
02759:
02760:                        // this vector keep tracking about key for prepareStmt...
02761:                        pstmtKeys.add(key);
02762:                        queryInsertRow.put(key, strInsertRow);
02763:                        indexIsNotRelationsColumns.put(key, indexRelations);
02764:                        pstmtForInsert.put(key, pstmt);
02765:                        pstmtColumnNames.put(key, pstmtCNames);
02766:                        // pstmtColumnTypes.put(key,pstmtCTypes);
02767:                    }
02768:
02769:                    String strQuery = "";
02770:                    // if we have select statement insted of table name
02771:                    if (importDefinitionElement.strImportDefinitionSelectStatement != null
02772:                            && !importDefinitionElement.strImportDefinitionSelectStatement
02773:                                    .equals("")) {
02774:                        strQuery = importDefinitionElement.strImportDefinitionSelectStatement;
02775:                        // strQuery = this.replaceInSelectStatement(strQuery);
02776:                        // TODO Allow different order of columns which should be
02777:                        // transformed
02778:                        // this part is for determine where columns for transformation
02779:                        // are started in
02780:                        // source result set
02781:                        // In selectStatement, columns for transformation should be on
02782:                        // the end, and they must
02783:                        // be in order same as in sourceColumn tags in all
02784:                        // transformations.
02785:                        //                if (this.transformations.getTransformations().size() > 0) {
02786:                        //                    SqlParser parser = new SqlParser();
02787:                        //                    try {
02788:                        //                        parser.parse(strQuery);
02789:                        //                    } catch (Throwable e) {
02790:                        //                        this.logger
02791:                        //                                .write(
02792:                        //                                        "full",
02793:                        //                                        "Unable to parse sql query from 'selectStatement' attribute. This is needed by transformations if they exists.");
02794:                        //                    }
02795:                        //                    String[] columnNames = parser.getColumnNames();
02796:                        //                    List allSourceColNames = this.transformations
02797:                        //                            .getAllTransformationSourceColNames();
02798:                        //                    for (int br1 = 0; br1 < columnNames.length; br1++) {
02799:                        //                        for (int br2 = 0; br2 < allSourceColNames.size(); br2++) {
02800:                        //                            if (allSourceColNames.get(br2).toString()
02801:                        //                                    .toUpperCase().equals(columnNames[br1]))
02802:                        //                                this.iOffsetForTransColumns = br1;
02803:                        //                            break;
02804:                        //                        }
02805:                        //                    }
02806:                        //                }
02807:
02808:                        if (!configReaderSource.getReadingOrderRelevant()) {
02809:                            int in = 0;
02810:                            int jn = 0;
02811:                            Vector vecVector = new Vector();
02812:                            while (in < this .iTables) {
02813:                                vecVector = (Vector) this .vecSourceColumnName
02814:                                        .get(in);
02815:                                while (jn < Integer
02816:                                        .parseInt(this .vecValueColumnsTargetTables
02817:                                                .get(in).toString())) {
02818:                                    jn++;
02819:                                    this .iColumnsInSourceTable++;
02820:                                }
02821:                                jn = 0;
02822:                                in++;
02823:                            }
02824:                        }
02825:                    } else {
02826:                        // when table name is defined
02827:                        strQuery = this .querySource();
02828:                    }
02829:
02830:                    if (strQuery.indexOf("order by") != -1) {
02831:                        if (checkSortColumns(connSource)) {
02832:                            this .logger
02833:                                    .write("normal",
02834:                                            "Error : Sort columns have more rows with equals values.");
02835:                            LoaderException le = new LoaderException(
02836:                                    "SQLException: ",
02837:                                    (Throwable) (new SQLException(
02838:                                            "Error : Sort columns have more rows with equals values.")));
02839:                            this .logger.write("full", le
02840:                                    .getStackTraceAsString());
02841:                            throw le;
02842:                        }
02843:                    }
02844:
02845:                    ResultSet rsetSource = null;
02846:                    int blockNumber = 0;
02847:                    boolean usingSelectStmt = false;
02848:                    if (importDefinitionElement.strImportDefinitionSelectStatement != null
02849:                            && !importDefinitionElement.strImportDefinitionSelectStatement
02850:                                    .equals("")) {
02851:                        usingSelectStmt = true;
02852:                    } else {
02853:                        if (configReaderSource.getRowCountEnabled()) {
02854:                            String countSQL = " select count(*) as \"counter\" from "
02855:                                    + importDefinitionElement.strImportDefinitionTableName;
02856:                            Statement stmtSourceCount = connSource
02857:                                    .createStatement();
02858:                            ResultSet rsetSourceCount = stmtSourceCount
02859:                                    .executeQuery(countSQL);
02860:                            rsetSourceCount.next();
02861:                            iRowNumber = rsetSourceCount.getInt("counter");
02862:                            blockNumber = iRowNumber
02863:                                    / importDefinitionElement.iImportDefinitionCommitCount
02864:                                    + 1;
02865:                            rsetSourceCount.close();
02866:                            stmtSourceCount.close();
02867:                        }
02868:                    }
02869:                    iRowNumber = 0;
02870:
02871:                    // set the number of rows in result set
02872:                    // setCursorName
02873:                    boolean setCursorName = false;
02874:                    if (!importDefinitionElement.setCursorNameID
02875:                            .equalsIgnoreCase(""))
02876:                        setCursorName = new Boolean(
02877:                                importDefinitionElement.setCursorNameID)
02878:                                .booleanValue();
02879:                    else
02880:                        setCursorName = configReaderSource
02881:                                .getSetCursorNameEnabled();
02882:
02883:                    if (setCursorName) {
02884:                        long cursorName = System.currentTimeMillis();
02885:                        stmtSource.setCursorName(String.valueOf(cursorName));
02886:                    }
02887:                    // setFetchSize
02888:                    boolean setFetchSize = false;
02889:                    if (!importDefinitionElement.setFetchSizeID
02890:                            .equalsIgnoreCase(""))
02891:                        setFetchSize = new Boolean(
02892:                                importDefinitionElement.setFetchSizeID)
02893:                                .booleanValue();
02894:                    else
02895:                        setFetchSize = configReaderSource
02896:                                .getSetFetchSizeEnabled();
02897:
02898:                    if (setFetchSize)
02899:                        stmtSource
02900:                                .setFetchSize(importDefinitionElement.iImportDefinitionCommitCount);
02901:
02902:                    this .logger.write("full", "\tQuery '" + strQuery
02903:                            + "' will be executed");
02904:                    rsetSource = stmtSource.executeQuery(strQuery);
02905:
02906:                    // this parameter defines if restartCounter has seccessfuly ended
02907:                    boolean main = true;
02908:                    if (!importDefinitionElement.strRestartCounterTableName
02909:                            .equals("")) {
02910:                        if (this .hasRestartCounter) {
02911:                            bdecCounter = dataTransmition.checkDataTransmition(
02912:                                    connTarget, rsetSource,
02913:                                    this .currentJobName, configReaderTarget
02914:                                            .getFirstColumnResult());
02915:
02916:                            if (bdecCounter != null) {
02917:                                if (bdecCounter.toString()
02918:                                        .equalsIgnoreCase("0")) {
02919:                                    // if is mycounter=0 in myrestart table escape this
02920:                                    // importdefinition
02921:                                    main = false;
02922:                                }
02923:                            } else {
02924:                                bdecCounter = new BigDecimal(0);
02925:                            }
02926:                        }
02927:                        if (!bdecCounter.toString().equalsIgnoreCase("0")) {
02928:                            //                    int num1 = Integer.parseInt(bdecCounter.toString());
02929:                            //                    int num2 = Integer.parseInt(this.bdecOidNumber.toString());
02930:                            //                    this.bdecOidNumber = new BigDecimal(num1 + num2);
02931:                            this .bdecOidNumber = bdecCounter
02932:                                    .add(this .bdecOidNumber);
02933:                        }
02934:                    }
02935:
02936:                    while (main) {
02937:                        boolean isEndFlag = false;
02938:                        this .logger.write("normal", "Import block is started.");
02939:                        currentBlock++;
02940:                        if (configReaderSource.getRowCountEnabled()) {
02941:                            if (!usingSelectStmt)
02942:                                this .logger.write("normal", "Working...  "
02943:                                        + currentBlock + ". block of "
02944:                                        + blockNumber);
02945:                            else
02946:                                this .logger.write("normal", "Working...  "
02947:                                        + currentBlock + ". block");
02948:                        } else
02949:                            this .logger.write("normal", "Working...  "
02950:                                    + currentBlock + ". block");
02951:                        this .logger.write("full", "\tStarted from the "
02952:                                + bdecCounter.add(new BigDecimal(1)).toString()
02953:                                + ". row.");
02954:                        int bdecRowCount = 0;
02955:                        while (iRowNumber < importDefinitionElement.iImportDefinitionCommitCount) {
02956:                            if (!rsetSource.next()) {
02957:                                isEndFlag = true;
02958:                                break;
02959:                            }
02960:                            currentRow = iRowNumber;
02961:                            boolean readingOrderRelevant = false;
02962:                            if (configReaderSource.getReadingOrderRelevant())
02963:                                readingOrderRelevant = true;
02964:
02965:                            for (int i = 0; i < this .iTables; i++) {
02966:                                Vector vecVektor = new Vector();
02967:                                this .vecBlobVector.clear();
02968:
02969:                                // only for microsoft driver
02970:                                Hashtable orderRelevantColumnValues = new Hashtable();
02971:                                Hashtable sourceColumnTypes = new Hashtable();
02972:                                if (readingOrderRelevant) {
02973:                                    int orderRelevantColumnCount = rsetSource
02974:                                            .getMetaData().getColumnCount();
02975:                                    for (int j = 1; j < orderRelevantColumnCount + 1; j++) {
02976:                                        String orderRelevantColumnName = rsetSource
02977:                                                .getMetaData().getColumnName(j);
02978:                                        orderRelevantColumnName = orderRelevantColumnName
02979:                                                .toUpperCase();
02980:                                        Object orderRelevantColumnValue;
02981:                                        if (configReaderSource
02982:                                                .isDate(rsetSource
02983:                                                        .getMetaData()
02984:                                                        .getColumnTypeName(j))) {
02985:                                            // senka 27.12.2006 changed getData to getTimestamp
02986:                                            orderRelevantColumnValue = rsetSource
02987:                                                    .getTimestamp(j);
02988:                                        } else if (configReaderSource
02989:                                                .isBinaryObject(rsetSource
02990:                                                        .getMetaData()
02991:                                                        .getColumnTypeName(j))) {
02992:                                            orderRelevantColumnValue = rsetSource
02993:                                                    .getBytes(j);
02994:                                        } else {
02995:                                            orderRelevantColumnValue = rsetSource
02996:                                                    .getString(j);
02997:                                        }
02998:                                        if (orderRelevantColumnValue == null) {
02999:                                            orderRelevantColumnValues.put(
03000:                                                    orderRelevantColumnName,
03001:                                                    "null");
03002:                                        } else {
03003:                                            orderRelevantColumnValues.put(
03004:                                                    orderRelevantColumnName,
03005:                                                    orderRelevantColumnValue);
03006:                                        }
03007:                                        // senka 27.12.2006 added to resolve problem with sourceColumnTypes for microsoft driver
03008:                                        // put type of column
03009:                                        sourceColumnTypes.put(
03010:                                                orderRelevantColumnName,
03011:                                                rsetSource.getMetaData()
03012:                                                        .getColumnTypeName(j));
03013:                                        this .logger
03014:                                                .write(
03015:                                                        "normal",
03016:                                                        "\torderRelevantColumnTypes.put(orderRelevantColumnName, rsetSource.getMetaData().getColumnTypeName(j));");
03017:                                        // orderRelevantColumnTypes.put(orderRelevantColumnName,
03018:                                        // rsetSource.getMetaData().getColumnTypeName(j));
03019:                                    }
03020:                                }
03021:                                // Read data from source
03022:                                // selectStatement=XXX
03023:                                if (importDefinitionElement.strImportDefinitionSelectStatement != null
03024:                                        && !importDefinitionElement.strImportDefinitionSelectStatement
03025:                                                .equals("")) {
03026:                                    // for value columns
03027:                                    Vector srcNames = new Vector();
03028:                                    srcNames = (Vector) this .vecSourceColumnName
03029:                                            .get(i);
03030:                                    Object readValue = "";
03031:                                    for (int s = 0; s < srcNames.size(); s++) {
03032:                                        if (srcNames.get(s) != null) {
03033:                                            String columnName = srcNames.get(s)
03034:                                                    .toString();
03035:                                            if (!readingOrderRelevant) {
03036:                                                readValue = rsetSource
03037:                                                        .getString(columnName);
03038:                                                // since types are not filled, fill it
03039:                                                // now
03040:                                                int colIndex = rsetSource
03041:                                                        .findColumn(columnName);
03042:                                                sourceColumnTypes
03043:                                                        .put(
03044:                                                                columnName,
03045:                                                                rsetSource
03046:                                                                        .getMetaData()
03047:                                                                        .getColumnTypeName(
03048:                                                                                colIndex));
03049:                                            } else {
03050:                                                columnName = columnName
03051:                                                        .toUpperCase();
03052:                                                // TODO Should readValue be String or
03053:                                                // Object
03054:                                                readValue = orderRelevantColumnValues
03055:                                                        .get(columnName);
03056:                                                // .toString()
03057:                                                ;
03058:                                            }
03059:                                            parseInputData(readValue,
03060:                                                    vecVektor, rsetSource, i,
03061:                                                    columnName, s + 1,
03062:                                                    readingOrderRelevant,
03063:                                                    orderRelevantColumnValues,
03064:                                                    sourceColumnTypes);
03065:                                        }
03066:                                    }
03067:                                    // orderRelevantColumnValues.clear();
03068:                                    // for transformations
03069:                                    this .transformationValues.clear();
03070:                                    List allSrcCls = this .transformations
03071:                                            .getAllTransformationSourceColNames();
03072:                                    for (int j = 0; j < allSrcCls.size(); j++) {
03073:                                        Object value = "";
03074:                                        String columnName = (String) allSrcCls
03075:                                                .get(j);
03076:                                        if (!readingOrderRelevant) {
03077:                                            sourceColumnTypes
03078:                                                    .put(
03079:                                                            columnName,
03080:                                                            rsetSource
03081:                                                                    .getMetaData()
03082:                                                                    .getColumnTypeName(
03083:                                                                            rsetSource
03084:                                                                                    .findColumn(columnName)));
03085:                                            value = rsetSource
03086:                                                    .getString(columnName);
03087:                                        } else {
03088:                                            columnName = columnName
03089:                                                    .toUpperCase();
03090:                                            value = orderRelevantColumnValues
03091:                                                    .get(columnName);
03092:                                        }
03093:                                        this .transformationValues.add(value);
03094:                                    }
03095:                                    orderRelevantColumnValues.clear();
03096:                                } else {
03097:                                    // When tableName is defined, tableName=XXX
03098:                                    // skip previous tables
03099:                                    int iCounterCol = 0;
03100:                                    for (int m = 0; m < i; m++) {
03101:                                        iCounterCol = iCounterCol
03102:                                                + Integer
03103:                                                        .parseInt(this .vecValueColumnsTargetTables
03104:                                                                .get(m)
03105:                                                                .toString())
03106:                                        // +
03107:                                        // Integer.parseInt(this.vecTransformColumnsTargetTables.get(m).toString())
03108:                                        ;
03109:                                    }
03110:                                    iCounterCol++;
03111:                                    // for value columns
03112:                                    for (int j = iCounterCol; j < (iCounterCol + Integer
03113:                                            .parseInt(this .vecValueColumnsTargetTables
03114:                                                    .get(i).toString())
03115:                                    // +
03116:                                    // Integer.parseInt(this.vecTransformColumnsTargetTables.get(i).toString())
03117:                                    ); j++) {
03118:                                        String readValue = "";
03119:                                        String columnName = rsetSource
03120:                                                .getMetaData().getColumnName(j);
03121:                                        if (!readingOrderRelevant) {
03122:                                            if (this .iFirstColumnResult == 0) {
03123:                                                readValue = rsetSource
03124:                                                        .getString(j - 1);
03125:                                                sourceColumnTypes
03126:                                                        .put(
03127:                                                                columnName,
03128:                                                                rsetSource
03129:                                                                        .getMetaData()
03130:                                                                        .getColumnTypeName(
03131:                                                                                j - 1));
03132:                                            } else {
03133:                                                readValue = rsetSource
03134:                                                        .getString(j);
03135:                                                sourceColumnTypes
03136:                                                        .put(
03137:                                                                columnName,
03138:                                                                rsetSource
03139:                                                                        .getMetaData()
03140:                                                                        .getColumnTypeName(
03141:                                                                                j));
03142:                                            }
03143:                                        } else {
03144:                                            columnName = columnName
03145:                                                    .toUpperCase();
03146:                                            readValue = orderRelevantColumnValues
03147:                                                    .get(columnName).toString();
03148:                                        }
03149:                                        parseInputData(readValue, vecVektor,
03150:                                                rsetSource, i, columnName, j
03151:                                                        - iCounterCol + 1,
03152:                                                readingOrderRelevant,
03153:                                                orderRelevantColumnValues,
03154:                                                sourceColumnTypes);
03155:                                    }
03156:                                    // for transformations
03157:                                    this .transformationValues.clear();
03158:                                    List allSrcCls = this .transformations
03159:                                            .getAllTransformationSourceColNames();
03160:                                    for (int j = 0; j < allSrcCls.size(); j++) {
03161:                                        Object value = "";
03162:                                        String columnName = (String) allSrcCls
03163:                                                .get(j);
03164:                                        if (!readingOrderRelevant) {
03165:                                            value = rsetSource
03166:                                                    .getString(columnName);
03167:                                        } else {
03168:                                            value = orderRelevantColumnValues
03169:                                                    .get(columnName
03170:                                                            .toUpperCase());
03171:                                        }
03172:                                        this .transformationValues.add(value);
03173:                                    }
03174:                                }
03175:                                for (int l = 0; l < this .vecVariableUseIDTableName
03176:                                        .size(); l++) {
03177:                                    if (this .vecTableTableName
03178:                                            .get(i)
03179:                                            .toString()
03180:                                            .equalsIgnoreCase(
03181:                                                    this .vecVariableUseIDTableName
03182:                                                            .get(l).toString())
03183:                                            && this .vecVariableUseIDTableID
03184:                                                    .get(l)
03185:                                                    .toString()
03186:                                                    .equalsIgnoreCase(
03187:                                                            this .vecTableTableID
03188:                                                                    .get(i)
03189:                                                                    .toString()))
03190:                                        vecVektor.add(this .strUserID);
03191:                                }
03192:                                Vector transformedValues = new Vector();
03193:                                Vector resultVectorTypes = new Vector();
03194:                                List trans = this .transformations
03195:                                        .getTransformations();
03196:                                Vector vecTransformedValues = new Vector();
03197:                                Vector pomResultVectorTypes = new Vector();
03198:                                String tableId = this .vecTableTableID.get(i)
03199:                                        .toString();
03200:                                List transTableIDs = this .transformations
03201:                                        .getTransformationsTableIDs();
03202:                                if (transTableIDs.contains(tableId)) {
03203:                                    this .logger
03204:                                            .write("full",
03205:                                                    "\ttransformation of values is started");
03206:                                    int offset = 0;
03207:                                    for (int j = 0; j < trans.size(); j++) {
03208:                                        Transformation transformation = (Transformation) trans
03209:                                                .get(j);
03210:                                        Vector sourceColumnNames = transformation
03211:                                                .getSourceColumnNames();
03212:                                        Vector valuesForTrans = new Vector();
03213:                                        for (int n = offset; n < offset
03214:                                                + sourceColumnNames.size(); n++) {
03215:                                            valuesForTrans
03216:                                                    .add(this .transformationValues
03217:                                                            .elementAt(n));
03218:                                        }
03219:                                        offset += sourceColumnNames.size();
03220:                                        vecTransformedValues = transformation
03221:                                                .transformValues(valuesForTrans);
03222:                                        // senka 22.08.2007  changed i-->Integer.parseInt(tableId)
03223:                                        //pomResultVectorTypes = transformation
03224:                                        //        .getOrderedTargetColumnTypes(i);
03225:                                        pomResultVectorTypes = transformation
03226:                                                .getOrderedTargetColumnTypes(Integer
03227:                                                        .parseInt(tableId));
03228:                                        if (vecTransformedValues != null) {
03229:                                            for (int m = 0; m < vecTransformedValues
03230:                                                    .size(); m++) {
03231:                                                // use only values and types for
03232:                                                // specified logic table
03233:                                                if (pomResultVectorTypes.get(m) == null)
03234:                                                    continue;
03235:                                                transformedValues
03236:                                                        .add(vecTransformedValues
03237:                                                                .get(m));
03238:                                                resultVectorTypes
03239:                                                        .add(pomResultVectorTypes
03240:                                                                .get(m)
03241:                                                                .toString());
03242:                                            }
03243:                                        }
03244:                                    }
03245:                                    this .logger
03246:                                            .write("full",
03247:                                                    "\ttransformation of values is finished");
03248:                                }
03249:
03250:                                // insert row into target logic table
03251:                                this .insertTargetTable(i, vecVektor,
03252:                                        (Vector) this .vecTargetColumnName
03253:                                                .get(i),
03254:                                        (Vector) this .vecValueMode.get(i),
03255:                                        (Vector) this .vecTargetColumnType
03256:                                                .get(i), connTarget,
03257:                                        transformedValues, resultVectorTypes);
03258:
03259:                            }
03260:                            iRowNumber++;
03261:                        }
03262:                        // restart counter table
03263:                        if (!importDefinitionElement.strRestartCounterTableName
03264:                                .equals("")) {
03265:                            if (this .hasRestartCounter) {
03266:                                bdecCounter = bdecCounter.add(new BigDecimal(
03267:                                        iRowNumber));
03268:                                dataTransmition.insertCounter(
03269:                                        this .currentJobName, bdecCounter,
03270:                                        connTarget);
03271:                            }
03272:                        }
03273:
03274:                        if (this .hasRestartCounter) {
03275:                            // TODO THIS IS WRITE PLACE:ZK added this for update of
03276:                            // counterColumns. This will update values in CounterTable
03277:                            // for this import job.
03278:                            // this.counterColumns.updateCounter(this.htValuesForCounterColumns,
03279:                            // connTarget);
03280:                            this .counterColumns.updateCounter(connTarget);
03281:                            connTarget.commit();
03282:                            this .logger.write("normal",
03283:                                    "Imported block is commited.");
03284:                            this .logger.write("full", Integer
03285:                                    .toString(iRowNumber)
03286:                                    + " rows are commited.");
03287:                        }
03288:                        iRowNumber = 0;
03289:                        if (isEndFlag == true)
03290:                            break;
03291:                    }// End of while(main)
03292:
03293:                    rsetSource.close();
03294:                    stmtSource.close();
03295:                    connSource.close();
03296:
03297:                    if (!importDefinitionElement.strRestartCounterTableName
03298:                            .equals("")) {
03299:                        if (this .hasRestartCounter) {
03300:                            dataTransmition.resetRestartCounter(connTarget,
03301:                                    this .currentJobName);
03302:                        }
03303:                    }
03304:                    // TODO ZK added this for update of counterColumns. This will update
03305:                    // values in CounterTable for every importDefinition.
03306:                    if (!this .hasRestartCounter) {
03307:                        this .counterColumns.updateCounter(connTarget);
03308:                    }
03309:                    // end
03310:                    currentDate = new Date();
03311:                    dfNow = DateFormat.getDateTimeInstance();
03312:                    this .logger.write("normal", "Import definition "
03313:                            + importDefinitionElement.strImportDefinitionName
03314:                            + " is finished at " + dfNow.format(currentDate)
03315:                            + ".");
03316:                    this .logger.write("normal",
03317:                            " Duration of importDefinition:"
03318:                                    + this .timeCounter.getJobTime());
03319:                }
03320:
03321:                catch (Exception e) {
03322:                    try {
03323:                        if (connSource != null)
03324:                            connSource.close();
03325:                    } catch (Exception ex) {
03326:                        this .logger.write("normal", "\t" + ex.getMessage());
03327:                    }
03328:                    String msq = "Error: In import job '"
03329:                            + importDefinitionElement.strImportDefinitionName
03330:                            + "', " + "some error has occured:";
03331:                    this .logger.write("normal", "\t" + msq);
03332:                    LoaderException le = new LoaderException("Exception:"
03333:                            + e.getMessage(), (Throwable) e);
03334:                    this .logger
03335:                            .write("full", "\t" + le.getStackTraceAsString());
03336:
03337:                    throw le;
03338:                } finally {
03339:                    try {
03340:
03341:                        this .logger.write("full",
03342:                                "loadSource method is finished.");
03343:                        if (connSource != null && !connSource.isClosed())
03344:                            connSource.close();
03345:                    } catch (SQLException e) {
03346:                        LoaderException le = new LoaderException(
03347:                                "SQLException: ", (Throwable) e);
03348:                        // this.logger.write("normal", le.getCause().toString());
03349:                        this .logger.write("full", le.getStackTraceAsString());
03350:                        throw le;
03351:                    }
03352:                }
03353:            }
03354:
03355:            /**
03356:             * This method read data from source table
03357:             * 
03358:             * @param readValue
03359:             *            is data value which is reed
03360:             * @param vecVektor
03361:             *            defines vector
03362:             * @param rsetSource
03363:             *            defines ResultSet object
03364:             * @param i
03365:             *            is interger
03366:             * @param columnName
03367:             *            defines source column name
03368:             * @param blobCount
03369:             *            defines counter for blob object
03370:             * @param isMicrosoftDriver
03371:             *            defines if we use microsoft driver
03372:             * @param columnValuesMicrosoft
03373:             *            defines column values which is read with microsoft driver
03374:             */
03375:            public void parseInputData(Object readValueObject,
03376:                    Vector vecVektor, ResultSet rsetSource, int i,
03377:                    String columnName, int blobCount,
03378:                    boolean isMicrosoftDriver, Hashtable columnValuesMicrosoft,
03379:                    Hashtable sourceColumnTypes) throws LoaderException {
03380:                try {
03381:                    String readValue = "";
03382:                    if (readValueObject instanceof  String)
03383:                        readValue = (String) readValueObject;
03384:                    else
03385:                        readValue = readValueObject != null ? readValueObject
03386:                                .toString() : "null";
03387:
03388:                    if (readValue == null
03389:                            || readValue.toString().equalsIgnoreCase("null")) {
03390:                        vecVektor.add(null);
03391:                    } else if (readValue.toString().equalsIgnoreCase("")) {
03392:                        if (configReaderTarget.getSetEmptyStringAsNull())
03393:                            vecVektor.add(null);
03394:                        else
03395:                            vecVektor.add("");
03396:                    } else {
03397:                        // int indexOld = (
03398:                        // (Vector)this.vecTargetColumnName.get(i)).indexOf(columnName);
03399:                        int index = blobCount - 1;
03400:                        // if (index == -1) {
03401:                        // if (readValue.indexOf("'") != -1)
03402:                        // readValue = replaceChar(readValue, '\'', "\'\'");
03403:                        // vecVektor.add(readValue);
03404:                        // } else {
03405:                        byte[] blob;
03406:
03407:                        String columnTypeTarget = ((Vector) this .vecTargetColumnType
03408:                                .get(i)).get(index).toString();
03409:
03410:                        String columnTypeSource = sourceColumnTypes.get(
03411:                                columnName).toString();
03412:
03413:                        String mode = ((Vector) this .vecValueMode.get(i)).get(
03414:                                index).toString();
03415:                        String toHex = ((Vector) this .vecToHex.get(i)).get(
03416:                                index).toString();
03417:                        String fromHex = ((Vector) this .vecFromHex.get(i)).get(
03418:                                index).toString();
03419:                        String blobObjectName = "binaryObject" + blobCount;
03420:
03421:                        if (toHex.equalsIgnoreCase("true")
03422:                                && !fromHex.equalsIgnoreCase("true")) {
03423:                            if (isMicrosoftDriver)
03424:                                blob = (byte[]) columnValuesMicrosoft
03425:                                        .get(columnName);
03426:                            else
03427:                                blob = rsetSource.getBytes(columnName);
03428:
03429:                            String toHexString = ToAndFromHex
03430:                                    .getStringFromBlob(blob);
03431:                            vecVektor.add(toHexString);
03432:                        } else if (fromHex.equalsIgnoreCase("true")
03433:                                && !toHex.equalsIgnoreCase("true")) {
03434:                            // ZK change this 7.5.2004 from CheckType to
03435:                            // configReaderTarget
03436:                            if (configReaderTarget
03437:                                    .isBinaryObject(columnTypeTarget)) {
03438:                                // if (javaTypeInt==1) {
03439:                                byte[] newBlob = ToAndFromHex
03440:                                        .getByteArrayFromString(readValue
03441:                                                .toString());
03442:                                if (mode.equalsIgnoreCase("Update")) {
03443:                                    this .vecBlobVector.add(columnName);
03444:                                    this .vecBlobVector.add(newBlob);
03445:                                    this .vecBlobVector.add(" where "
03446:                                            + columnName + " is null and ");
03447:                                    this .vecBlobVector.add(mode);
03448:                                    this .vecBlobVector.add(blobObjectName);
03449:                                    vecVektor.add(blobObjectName);
03450:                                } else {
03451:                                    this .vecBlobVector.add(columnName);
03452:                                    this .vecBlobVector.add(newBlob);
03453:                                    this .vecBlobVector.add(null);
03454:                                    this .vecBlobVector.add(mode);
03455:                                    this .vecBlobVector.add(blobObjectName);
03456:                                    vecVektor.add(blobObjectName);
03457:                                }
03458:                            } else {
03459:                                if (readValue.toString().indexOf("'") != -1)
03460:                                    readValue = replaceChar(readValue, '\'',
03461:                                            "\'\'");
03462:                                vecVektor.add(readValue);
03463:                            }
03464:                        } else {
03465:                            // ZK change this 7.5.2004 from CheckType to
03466:                            // configReaderSource
03467:                            if (configReaderTarget
03468:                                    .isBinaryObject(columnTypeTarget)) {
03469:                                // if (javaTypeInt==1) {
03470:                                if (isMicrosoftDriver)
03471:                                    blob = (byte[]) columnValuesMicrosoft
03472:                                            .get(columnName);
03473:                                else
03474:                                    blob = rsetSource.getBytes(columnName);
03475:                                if (mode.equalsIgnoreCase("Update")) {
03476:                                    this .vecBlobVector.add(columnName);
03477:                                    this .vecBlobVector.add(blob);
03478:                                    this .vecBlobVector.add(" where "
03479:                                            + columnName + " is null and ");
03480:                                    this .vecBlobVector.add(mode);
03481:                                    this .vecBlobVector.add(blobObjectName);
03482:                                    vecVektor.add(blobObjectName);
03483:                                } else {
03484:                                    this .vecBlobVector.add(columnName);
03485:                                    this .vecBlobVector.add(blob);
03486:                                    this .vecBlobVector.add(null);
03487:                                    this .vecBlobVector.add(mode);
03488:                                    this .vecBlobVector.add(blobObjectName);
03489:                                    vecVektor.add(blobObjectName);
03490:                                }
03491:                            } else if (configReaderSource
03492:                                    .isDate(columnTypeSource)) {
03493:
03494:                                Date tmpDate = null;
03495:                                // Senka 27.12.2006 , separated Date and Timestamp columns 
03496:                                if (isMicrosoftDriver) {
03497:                                    if (columnValuesMicrosoft.get(columnName)
03498:                                            .toString().length() > 10)
03499:                                        tmpDate = (java.sql.Timestamp) columnValuesMicrosoft
03500:                                                .get(columnName);
03501:                                    else
03502:                                        tmpDate = (java.sql.Date) columnValuesMicrosoft
03503:                                                .get(columnName);
03504:
03505:                                } else {
03506:                                    if (rsetSource.getObject(columnName)
03507:                                            .toString().length() > 10)
03508:                                        tmpDate = rsetSource
03509:                                                .getTimestamp(columnName);
03510:                                    else
03511:                                        tmpDate = rsetSource
03512:                                                .getDate(columnName);
03513:                                }
03514:                                if (!configReaderTarget
03515:                                        .isDate(columnTypeTarget)) {
03516:                                    String format = this .configReaderTarget
03517:                                            .getDateFormat();
03518:                                    SimpleDateFormat formatDate = new SimpleDateFormat(
03519:                                            format);
03520:                                    vecVektor.add(formatDate.format(tmpDate));
03521:                                } else {
03522:                                    vecVektor.add(tmpDate);
03523:                                }
03524:                            } else {
03525:                                if (readValue.indexOf("'") != -1)
03526:                                    readValue = replaceChar(readValue, '\'',
03527:                                            "\'\'");
03528:                                vecVektor.add(readValue);
03529:                            }
03530:                        }
03531:                    }
03532:                    // }
03533:                } catch (Exception ex) {
03534:                    LoaderException le = new LoaderException(
03535:                            "Error in parseInputData.", ex);
03536:                    this .logger.write("full", le.getStackTraceAsString());
03537:                    throw le;
03538:                }
03539:            }
03540:
03541:            /**
03542:             * Method parseImportJOB is used to analyse import XML file about
03543:             * ImportDefinitions tags. Return number of importDefinition elements in
03544:             * whole xml file.
03545:             * 
03546:             * @param inStream
03547:             *            Data from inputXML file which is converted into InputStream.
03548:             * @return Number of ImportDefinitions tags in an input XML file.
03549:             * @throws LoaderException
03550:             */
03551:            private int parseImportJob(InputStream inStream)
03552:                    throws LoaderException {
03553:                int iNumTagsImportJob = 0;
03554:                Document doc = null;
03555:                this .logger
03556:                        .write("full", "\tparseImportJob method is started.");
03557:                try {
03558:
03559:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
03560:                            .newInstance();
03561:                    DocumentBuilder db = null;
03562:                    db = dbf.newDocumentBuilder();
03563:                    doc = db.parse(inStream);
03564:                } catch (Exception e) {
03565:                    this .logger.write("normal", "Sorry, an error occurred: "
03566:                            + e);
03567:                    LoaderException le = new LoaderException("Exception: ",
03568:                            (Throwable) e);
03569:                    this .logger.write("full", le.getStackTraceAsString());
03570:                    throw le;
03571:                }
03572:                if (doc != null) {
03573:                    NodeList tagBasic = doc
03574:                            .getElementsByTagName("importDefinition");
03575:                    iNumTagsImportJob = tagBasic.getLength();
03576:                    Vector vecNames = new Vector();
03577:                    String strName = "";
03578:                    for (int i = 0; i < iNumTagsImportJob; i++) {
03579:                        strName = new String("");
03580:                        strName = OctopusXMLUtil.importAttributeValue(doc,
03581:                                "importDefinition", "name", i);
03582:                        for (int j = 0; j < vecNames.size(); j++) {
03583:                            if (strName.equals("")) {
03584:                                this .logger
03585:                                        .write("normal",
03586:                                                "Sorry, an error occurred: No importDefinition name .");
03587:                                LoaderException le = new LoaderException(
03588:                                        "Exception: ",
03589:                                        (Throwable) (new Exception(
03590:                                                "Sorry, an error occurred: No importDefinition name .")));
03591:                                this .logger.write("full", le
03592:                                        .getStackTraceAsString());
03593:                                throw le;
03594:                            }
03595:                            if (strName.equalsIgnoreCase(vecNames.get(j)
03596:                                    .toString())) {
03597:                                this .logger.write("normal",
03598:                                        "Sorry, an error occurred: More importDefinition with same name :"
03599:                                                + strName);
03600:                                LoaderException le = new LoaderException(
03601:                                        "Exception: ",
03602:                                        (Throwable) (new Exception(
03603:                                                "Sorry, an error occurred: More importDefinition with same name :")));
03604:                                this .logger.write("full", le
03605:                                        .getStackTraceAsString());
03606:                                throw le;
03607:                            }
03608:                        }
03609:                        vecNames.addElement(strName);
03610:                    }
03611:                }
03612:                try {
03613:                    inStream.reset();
03614:                } catch (IOException e) {
03615:                    // this.logger.write("normal", "Sorry, an error occurred: " + e);
03616:                    LoaderException le = new LoaderException("IOException: ",
03617:                            (Throwable) e);
03618:                    this .logger.write("full", le.getStackTraceAsString());
03619:                    throw le;
03620:                }
03621:                this .logger.write("full",
03622:                        "\tparseImportJob method is finished.");
03623:                return iNumTagsImportJob;
03624:            }
03625:
03626:            /**
03627:             * Method parseCopyTable is used to analyse import XML file about copyTable
03628:             * tags. Return number of copyTable elements in whole xml file.
03629:             * 
03630:             * @param inStream
03631:             *            Data from inputXML file which is converted into InputStream.
03632:             * @return Number of iNumTagsCopyTable tags in an input XML file.
03633:             * @throws LoaderException
03634:             */
03635:
03636:            private int parseCopyTable(InputStream inStream)
03637:                    throws LoaderException {
03638:                int iNumTagsCopyTable = 0;
03639:                Document doc = null;
03640:                this .logger
03641:                        .write("full", "\tparseCopyTable method is started.");
03642:                try {
03643:
03644:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
03645:                            .newInstance();
03646:                    DocumentBuilder db = null;
03647:                    db = dbf.newDocumentBuilder();
03648:                    doc = db.parse(inStream);
03649:                } catch (Exception e) {
03650:                    this .logger.write("normal", "Sorry, an error occurred: "
03651:                            + e);
03652:                    LoaderException le = new LoaderException("Exception: ",
03653:                            (Throwable) e);
03654:                    this .logger.write("full", le.getStackTraceAsString());
03655:                    throw le;
03656:                }
03657:                if (doc != null) {
03658:                    NodeList tagCopyTable = doc
03659:                            .getElementsByTagName("copyTable");
03660:                    iNumTagsCopyTable = tagCopyTable.getLength();
03661:                    Vector vecNames = new Vector();
03662:                    String strName = "";
03663:                    for (int i = 0; i < iNumTagsCopyTable; i++) {
03664:                        strName = new String("");
03665:                        strName = OctopusXMLUtil.importAttributeValue(doc,
03666:                                "copyTable", "name", i);
03667:                        for (int j = 0; j < vecNames.size(); j++) {
03668:                            if (strName.equals("")) {
03669:                                this .logger
03670:                                        .write("normal",
03671:                                                "Sorry, an error occurred: No copyTable name .");
03672:                                LoaderException le = new LoaderException(
03673:                                        "Exception: ",
03674:                                        (Throwable) (new Exception(
03675:                                                "Sorry, an error occurred: No copyTable name .")));
03676:                                this .logger.write("full", le
03677:                                        .getStackTraceAsString());
03678:                                throw le;
03679:                            }
03680:                            if (strName.equalsIgnoreCase(vecNames.get(j)
03681:                                    .toString())) {
03682:                                this .logger.write("normal",
03683:                                        "Sorry, an error occurred: More copyTable with same name :"
03684:                                                + strName);
03685:                                LoaderException le = new LoaderException(
03686:                                        "Exception: ",
03687:                                        (Throwable) (new Exception(
03688:                                                "Sorry, an error occurred: More copyTable with same name :")));
03689:                                this .logger.write("full", le
03690:                                        .getStackTraceAsString());
03691:                                throw le;
03692:                            }
03693:                        }
03694:                        vecNames.addElement(strName);
03695:                    }
03696:                }
03697:                try {
03698:                    inStream.reset();
03699:                } catch (IOException e) {
03700:                    this .logger.write("normal", "Sorry, an error occurred: "
03701:                            + e);
03702:                    LoaderException le = new LoaderException("IOException: ",
03703:                            (Throwable) e);
03704:                    this .logger.write("full", le.getStackTraceAsString());
03705:                    throw le;
03706:                }
03707:                this .logger.write("full",
03708:                        "\tparseImportJob method is finished.");
03709:                return iNumTagsCopyTable;
03710:            }
03711:
03712:            /**
03713:             * Method parseEchoElement is used to analyse import XML file about echo
03714:             * tags. Return number of echo elements in a whole xml input file.
03715:             * 
03716:             * @param inStream
03717:             *            Data from inputXML file which is converted into InputStream.
03718:             * @return Number of echo tags in an input XML file.
03719:             * @throws LoaderException
03720:             */
03721:            private int parseEcho(InputStream inStream) throws LoaderException {
03722:                int iNumTagsEcho = 0;
03723:                Document doc = null;
03724:                this .logger.write("full", "\tparseEcho method is started.");
03725:                try {
03726:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
03727:                            .newInstance();
03728:                    DocumentBuilder db = null;
03729:                    db = dbf.newDocumentBuilder();
03730:                    doc = db.parse(inStream);
03731:                } catch (Exception e) {
03732:                    this .logger.write("normal", "Sorry, an error occurred: "
03733:                            + e);
03734:                    LoaderException le = new LoaderException("Exception: ",
03735:                            (Throwable) e);
03736:                    this .logger.write("full", le.getStackTraceAsString());
03737:                    throw le;
03738:                }
03739:                if (doc != null) {
03740:                    NodeList tagBasic = doc.getElementsByTagName("echo");
03741:                    iNumTagsEcho = tagBasic.getLength();
03742:                    String strMessage = "";
03743:                    for (int i = 0; i < iNumTagsEcho; i++) {
03744:                        strMessage = new String("");
03745:                        strMessage = OctopusXMLUtil.importAttributeValue(doc,
03746:                                "echo", "message", i);
03747:                        if (strMessage != null)
03748:                            logger.setMessage((new Integer(i)).toString(),
03749:                                    strMessage);
03750:                    }
03751:                }
03752:                try {
03753:                    inStream.reset();
03754:                } catch (IOException e) {
03755:                    this .logger.write("normal", "Sorry, an error occurred: "
03756:                            + e);
03757:                    LoaderException le = new LoaderException("IOxception: ",
03758:                            (Throwable) e);
03759:                    this .logger.write("full", le.getStackTraceAsString());
03760:                    throw le;
03761:                    // System.exit(1);
03762:                }
03763:                this .logger.write("full", "\tparseSql method is finished.");
03764:                return iNumTagsEcho;
03765:            }
03766:
03767:            /**
03768:             * Method parseMainElements is used to analyse import XML file about main
03769:             * elements (sql and importDefinition). Puts names of elements (sql or
03770:             * importDefinition) in Vector.
03771:             * 
03772:             * @param inStream
03773:             *            Data from inputXML file which is converted into InputStream.
03774:             * @return Vector which elements are names of main elements in the same
03775:             *         order as in XML import file .
03776:             * @throws LoaderException
03777:             */
03778:            private Vector parseMainElements(InputStream inStream)
03779:                    throws LoaderException {
03780:
03781:                Vector vecLoaderElements = new Vector();
03782:                Vector vecLoaderNamesOfElements = new Vector();
03783:
03784:                Document doc = null;
03785:                this .logger.write("full",
03786:                        "\tparseMainElements method is started.");
03787:                try {
03788:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
03789:                            .newInstance();
03790:                    DocumentBuilder db = null;
03791:                    db = dbf.newDocumentBuilder();
03792:                    doc = db.parse(inStream);
03793:                } catch (Exception e) {
03794:                    this .logger.write("normal", "Sorry, an error occurred: "
03795:                            + e);
03796:                    LoaderException le = new LoaderException("Exception: ",
03797:                            (Throwable) e);
03798:                    this .logger.write("full", le.getStackTraceAsString());
03799:                    throw le;
03800:                }
03801:                if (doc != null) {
03802:                    NodeList tagBasic = doc.getElementsByTagName("loaderJob");
03803:                    NodeList nlMainElements = tagBasic.item(0).getChildNodes();
03804:                    for (int i = 0; i < nlMainElements.getLength(); i++) {
03805:                        String strTagName = nlMainElements.item(i)
03806:                                .getNodeName();
03807:                        if (strTagName.equalsIgnoreCase("sql")
03808:                                || strTagName
03809:                                        .equalsIgnoreCase("importDefinition")
03810:                                || strTagName.equalsIgnoreCase("echo")
03811:                                || strTagName.equalsIgnoreCase("copyTable"))
03812:                            if (nlMainElements.item(i).getNodeType() == Node.ELEMENT_NODE) {
03813:                                String strTagJobName = (((Element) nlMainElements
03814:                                        .item(i)).getAttribute("name"));
03815:                                String strLogMode = (((Element) nlMainElements
03816:                                        .item(i)).getAttribute("logMode"));
03817:                                vecLoaderElements.addElement(strTagName);
03818:                                this .logModes.add(strLogMode);
03819:                                boolean addJobName = true;
03820:                                if (!strTagJobName.equalsIgnoreCase("")) {
03821:                                    for (int j = 0; j < vecLoaderNamesOfElements
03822:                                            .size(); j++) {
03823:                                        if (strTagJobName
03824:                                                .equalsIgnoreCase(vecLoaderNamesOfElements
03825:                                                        .get(j).toString())) {
03826:                                            addJobName = false;
03827:                                            break;
03828:                                        }
03829:                                    }
03830:                                    if (addJobName) {
03831:                                        vecLoaderNamesOfElements
03832:                                                .add(strTagJobName);
03833:                                    } else {
03834:                                        String msg = "Sorry, an error occurred: More import jobs with same name :"
03835:                                                + strTagJobName;
03836:                                        LoaderException le = new LoaderException(
03837:                                                "Exception:",
03838:                                                new Exception(msg));
03839:
03840:                                        throw le;
03841:                                    }
03842:                                }
03843:                            }
03844:                    }
03845:                }
03846:                try {
03847:                    inStream.reset();
03848:                } catch (IOException e) {
03849:                    this .logger.write("normal", "Sorry, an error occurred: "
03850:                            + e.getMessage());
03851:                    LoaderException le = new LoaderException("IOException: ",
03852:                            (Throwable) e);
03853:                    this .logger.write("full", le.getStackTraceAsString());
03854:                    throw le;
03855:                }
03856:                this .logger.write("full",
03857:                        "\tparseMainElements method is finished.");
03858:                return vecLoaderElements;
03859:            }
03860:
03861:            /**
03862:             * Method importRestartCounter is used to analyse import XML file and read
03863:             * restart counter attributes. Values of these attributes puts in Vectors
03864:             * 
03865:             * @param inStream
03866:             *            Data from inputXML file which is converted into InputStream.
03867:             * @throws LoaderException
03868:             */
03869:            private void importRestartCounter(InputStream inStream)
03870:                    throws LoaderException {
03871:                Document doc = null;
03872:                this .logger.write("full",
03873:                        "\timportRestartCounter method is started.");
03874:                try {
03875:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
03876:                            .newInstance();
03877:                    DocumentBuilder db = null;
03878:                    db = dbf.newDocumentBuilder();
03879:                    doc = db.parse(inStream);
03880:                } catch (Exception e) {
03881:                    this .logger.write("normal", "Sorry, an error occurred: "
03882:                            + e);
03883:                    LoaderException le = new LoaderException("Exception: ",
03884:                            (Throwable) e);
03885:                    this .logger.write("full", le.getStackTraceAsString());
03886:                    throw le;
03887:                    // System.exit(1);
03888:                }
03889:                if (doc != null) {
03890:                    NodeList tagRestartCounter = doc
03891:                            .getElementsByTagName("restartCounter");
03892:                    if (tagRestartCounter.getLength() != 0) {
03893:                        this .hasRestartCounter = true;
03894:                        NamedNodeMap attrs = tagRestartCounter.item(0)
03895:                                .getAttributes();
03896:                        Node nodeResult = attrs.getNamedItem("tableName");
03897:                        if (nodeResult != null)
03898:                            importDefinitionElement.strRestartCounterTableName = nodeResult
03899:                                    .getNodeValue();
03900:                        else
03901:                            importDefinitionElement.strRestartCounterTableName = "LOADERRESTART";
03902:                        nodeResult = attrs
03903:                                .getNamedItem("importDefinitionColumnName");
03904:                        if (nodeResult != null)
03905:                            importDefinitionElement.strRestartCounterImportDefinitionName = nodeResult
03906:                                    .getNodeValue();
03907:                        else
03908:                            importDefinitionElement.strRestartCounterImportDefinitionName = "IMPORTDEFINITION";
03909:                        nodeResult = attrs
03910:                                .getNamedItem("restartCounterColumnName");
03911:                        if (nodeResult != null)
03912:                            importDefinitionElement.strRestartCounterValue = nodeResult
03913:                                    .getNodeValue();
03914:                        else
03915:                            importDefinitionElement.strRestartCounterValue = "RESTARTCOUNTER";
03916:                        nodeResult = attrs.getNamedItem("restartAutoCreate");
03917:                        if (nodeResult != null)
03918:                            importDefinitionElement.bRestartAutoCreate = (new Boolean(
03919:                                    nodeResult.getNodeValue())).booleanValue();
03920:                        else
03921:                            importDefinitionElement.bRestartAutoCreate = false;
03922:                    }
03923:                }
03924:                try {
03925:                    inStream.reset();
03926:                } catch (IOException e) {
03927:                    this .logger.write("normal", "Sorry, an error occurred: "
03928:                            + e);
03929:                    LoaderException le = new LoaderException("IOException: ",
03930:                            (Throwable) e);
03931:                    this .logger.write("full", le.getStackTraceAsString());
03932:                    throw le;
03933:                    // System.exit(1);
03934:                }
03935:                this .logger.write("full",
03936:                        "\timportRestartCounter method is finished.");
03937:            }
03938:
03939:            /**
03940:             * Method importVariable imports sql attributes from xml file and puts them
03941:             * in the global variables. Return Vector. It's elements are strings which
03942:             * represents sql statements.
03943:             * 
03944:             * @param inStream
03945:             *            Data from inputXML file which is converted into InputStream.
03946:             * @throws LoaderException
03947:             */
03948:            private void importVariable(InputStream inStream)
03949:                    throws LoaderException {
03950:                Document doc = null;
03951:                String strNodeValue = "";
03952:                String strDefaultVariableOverride = "";
03953:                String strDefaultReplaceInConstants = "";
03954:                String strDefaultReplaceInSQL = "";
03955:                String strDefaultReplaceInData = "";
03956:                String strDefaultReplaceInJDBC = "";
03957:                String strDefaultVariablePrefix = "";
03958:                String strDefaultVariableSufix = "";
03959:                this .logger.write("full",
03960:                        "\timportVariable  method is started.");
03961:                try {
03962:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
03963:                            .newInstance();
03964:                    DocumentBuilder db = null;
03965:                    db = dbf.newDocumentBuilder();
03966:                    doc = db.parse(inStream);
03967:                    if (doc != null) {
03968:                        NodeList tagBasic = doc
03969:                                .getElementsByTagName("variables");
03970:                        if (tagBasic.getLength() != 0) {
03971:                            Element docFragment = (Element) tagBasic.item(0);
03972:                            strDefaultVariablePrefix = docFragment
03973:                                    .getAttribute("prefix");
03974:                            if (strDefaultVariablePrefix.equals(""))
03975:                                strDefaultVariablePrefix = "%";
03976:                            strDefaultVariableSufix = docFragment
03977:                                    .getAttribute("suffix");
03978:                            if (strDefaultVariableSufix.equals(""))
03979:                                strDefaultVariableSufix = "%";
03980:                            strDefaultVariableOverride = docFragment
03981:                                    .getAttribute("override");
03982:                            if (strDefaultVariableOverride.equals(""))
03983:                                strDefaultVariableOverride = "true";
03984:                            strDefaultReplaceInConstants = docFragment
03985:                                    .getAttribute("replaceInConstants");
03986:                            if (strDefaultReplaceInConstants.equals(""))
03987:                                strDefaultReplaceInConstants = "false";
03988:                            strDefaultReplaceInSQL = docFragment
03989:                                    .getAttribute("replaceInSQL");
03990:                            if (strDefaultReplaceInSQL.equals(""))
03991:                                strDefaultReplaceInSQL = "false";
03992:                            strDefaultReplaceInData = docFragment
03993:                                    .getAttribute("replaceInData");
03994:                            if (strDefaultReplaceInData.equals(""))
03995:                                strDefaultReplaceInData = "false";
03996:                            strDefaultReplaceInJDBC = docFragment
03997:                                    .getAttribute("replaceInJDBC");
03998:                            if (strDefaultReplaceInJDBC.equals(""))
03999:                                strDefaultReplaceInJDBC = "false";
04000:                            NodeList tag = docFragment
04001:                                    .getElementsByTagName("variable");
04002:                            this .vecVariableName = OctopusXMLUtil
04003:                                    .getAttributeValues(tag, "name", null);
04004:                            this .vecVariableValue = OctopusXMLUtil
04005:                                    .getAttributeValues(tag, "value", null);
04006:                            this .vecVariablePrefix = OctopusXMLUtil
04007:                                    .getAttributeValues(tag, "prefix",
04008:                                            strDefaultVariablePrefix);
04009:                            this .vecVariableSufix = OctopusXMLUtil
04010:                                    .getAttributeValues(tag, "suffix",
04011:                                            strDefaultVariableSufix);
04012:                            this .vecVariableOverride = OctopusXMLUtil
04013:                                    .getAttributeValues(tag, "override",
04014:                                            strDefaultVariableOverride);
04015:                            this .vecReplaceInConstants = OctopusXMLUtil
04016:                                    .getAttributeValues(tag,
04017:                                            "replaceInConstants",
04018:                                            strDefaultReplaceInConstants);
04019:                            this .vecReplaceInSQL = OctopusXMLUtil
04020:                                    .getAttributeValues(tag, "replaceInSQL",
04021:                                            strDefaultReplaceInSQL);
04022:                            this .vecReplaceInData = OctopusXMLUtil
04023:                                    .getAttributeValues(tag, "replaceInData",
04024:                                            strDefaultReplaceInData);
04025:                            this .vecReplaceInJDBC = OctopusXMLUtil
04026:                                    .getAttributeValues(tag, "replaceInJDBC",
04027:                                            strDefaultReplaceInJDBC);
04028:                            for (int i = 0; i < this .vecVariableOverride.size(); i++) {
04029:                                if (this .vecVariableOverride.get(i).toString()
04030:                                        .equalsIgnoreCase("true")) {
04031:                                    if (this .mapVariableValues
04032:                                            .get(this .vecVariableName.get(i)) == null)
04033:                                        this .vecVariableValue.setElementAt(
04034:                                                null, i);
04035:                                    else
04036:                                        this .vecVariableValue.setElementAt(
04037:                                                this .mapVariableValues.get(
04038:                                                        this .vecVariableName
04039:                                                                .get(i)
04040:                                                                .toString())
04041:                                                        .toString(), i);
04042:                                }
04043:                            }
04044:                        }
04045:                    }
04046:                } catch (Exception e) {
04047:                    this .logger
04048:                            .write("normal",
04049:                                    "Sorry, an error with the variables occurred: "
04050:                                            + e);
04051:                    LoaderException le = new LoaderException("Exception: ",
04052:                            (Throwable) e);
04053:                    this .logger.write("full", le.getStackTraceAsString());
04054:                    throw le;
04055:                }
04056:                try {
04057:                    inStream.reset();
04058:                } catch (IOException e) {
04059:                    this .logger.write("normal", "Sorry, an error occurred: "
04060:                            + e);
04061:                    LoaderException le = new LoaderException("IOException: ",
04062:                            (Throwable) e);
04063:                    this .logger.write("full", le.getStackTraceAsString());
04064:                    throw le;
04065:                }
04066:                this .logger.write("full",
04067:                        "\timportVariable  method is finished.");
04068:            }
04069:
04070:            /**
04071:             * Method parseAndImport is used to analyse the importDefinition no. l in
04072:             * xml file and input all values and puts them into global variables. If
04073:             * there is an error, Exception "SAXException" is thrown.
04074:             * 
04075:             * @param inStream
04076:             *            Data from inputXML file which is converted into InputStream.
04077:             * @param l
04078:             *            Number of ImportDefinition tag which is processed.
04079:             * @param isImportDefinition
04080:             *            true if ImportJob tag is "importDefinition".                       
04081:             * @throws SAXException
04082:             *             Constructs an JAXP 1.1 Exception with the specified detail
04083:             *             message.
04084:             * @throws Exception
04085:             *             Constructs an Exception with the specified detail message.
04086:             * @throws LoaderException
04087:             */
04088:            // 26.07.2007 senka added parameter isImportDefinition
04089:            private void parseAndImport(InputStream inStream, int l,
04090:                    boolean isImportDefinition) throws SAXException,
04091:                    LoaderException, Exception {
04092:                this .logger
04093:                        .write("full", "\tparseAndImport method is started.");
04094:                Document doc = null;
04095:                try {
04096:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
04097:                            .newInstance();
04098:                    DocumentBuilder db = null;
04099:                    db = dbf.newDocumentBuilder();
04100:                    doc = db.parse(inStream);
04101:                } catch (SAXException e) {
04102:                    throw e;
04103:                } catch (Exception e) {
04104:                    throw e;
04105:                }
04106:                if (doc != null)
04107:                    this .importXMLFile(doc, l, isImportDefinition);
04108:                try {
04109:                    inStream.reset();
04110:                } catch (IOException e) {
04111:                    this .logger.write("normal", "Sorry, an error occurred: "
04112:                            + e);
04113:                    LoaderException le = new LoaderException("IOException: ",
04114:                            (Throwable) e);
04115:                    this .logger.write("full", le.getStackTraceAsString());
04116:                    throw le;
04117:                }
04118:                this .logger.write("full",
04119:                        "\tparseAndImport method is finished.");
04120:            }
04121:
04122:            /**
04123:             * Method importXMLFile is used for setting of global variables during
04124:             * importing values from XML file. This method validates the imported data
04125:             * from XML file. If there is an error Exception "NullPointerException" or
04126:             * "Exception" is thrown.
04127:             * 
04128:             * @param doc
04129:             *            Parsed imports XML file.
04130:             * @param iJobNumber
04131:             *            Number of ImportJob tag which is processed.
04132:             * @param isImportDefinition
04133:             *            true if ImportJob tag is "importDefinition".           
04134:             * @throws NullPointerException
04135:             *             Constructs a NullPointerException with the specified detail
04136:             *             message.
04137:             * @throws Exception
04138:             *             Constructs an Exception with the specified detail message.
04139:             */
04140:            //  26.07.2007 senka added parameter isImportDefinition
04141:            private void importXMLFile(Document doc, int iJobNumber,
04142:                    boolean isImportDefinition) throws NullPointerException,
04143:                    Exception {
04144:                this .logger.write("full", "\timportXMLFile method is started.");
04145:                Vector vecValueColumnSourceColumnName = new Vector();
04146:                Vector vecValueColumnTargetTableName = new Vector();
04147:                Vector vecValueColumnTargetColumnName = new Vector();
04148:                Vector vecValueColumnTargetTableID = new Vector();
04149:                Vector vecValueColumnValueMode = new Vector();
04150:                Vector vecConstantColumnTargetColumnName = new Vector();
04151:                Vector vecConstantColumnValueMode = new Vector();
04152:                Vector vecConstantColumnConstantValue = new Vector();
04153:                Vector vecRestartCounterVector = new Vector();
04154:                Vector vecJDBCSourceName = new Vector();
04155:                Vector vecJDBCSourceValue = new Vector();
04156:                Vector vecJDBCTargetName = new Vector();
04157:                Vector vecJDBCTargetValue = new Vector();
04158:                // vector for default values of columns
04159:                Vector vecDefaultValueTemp = new Vector();
04160:                this .vecDefaultValue = new Vector();
04161:                this .vecDefaultRelationValue = null;
04162:                this .vecDefaultVariableValue = null;
04163:                this .vecDefaultVariableName = null;
04164:                this .vecTempUserID = null;
04165:                int iNumberOfColumns = 0;
04166:                // to and form hex
04167:                Vector vecToHexTemp = new Vector();
04168:                Vector vecFromHexTemp = new Vector();
04169:                this .vecToHex = new Vector();
04170:                this .vecFromHex = new Vector();
04171:
04172:                try {
04173:
04174:                    importDefinitionElement.setLogger(this .logger);
04175:                    dataCleaning.setLogger(this .logger);
04176:
04177:                    if (!this .loaderJobReader.getLogTableName()
04178:                            .equalsIgnoreCase(""))
04179:                        dataCleaning.setLogTableName(this .loaderJobReader
04180:                                .getLogTableName());
04181:
04182:                    if (!this .loaderJobReader.getLogTable()
04183:                            .equalsIgnoreCase(""))
04184:                        dataCleaning.setLogTable(this .loaderJobReader
04185:                                .getLogTable());
04186:
04187:                    if (!this .loaderJobReader.getLogColumnName()
04188:                            .equalsIgnoreCase(""))
04189:                        dataCleaning.setLogColumnName(this .loaderJobReader
04190:                                .getLogColumnName());
04191:
04192:                    if (!this .loaderJobReader.getLogRowNumber()
04193:                            .equalsIgnoreCase(""))
04194:                        dataCleaning.setLogRowNumber(this .loaderJobReader
04195:                                .getLogRowNumber());
04196:
04197:                    if (!this .loaderJobReader.getLogOriginalValue()
04198:                            .equalsIgnoreCase(""))
04199:                        dataCleaning.setLogOriginalValue(this .loaderJobReader
04200:                                .getLogOriginalValue());
04201:
04202:                    if (!this .loaderJobReader.getLogNewValue()
04203:                            .equalsIgnoreCase(""))
04204:                        dataCleaning.setLogNewValue(this .loaderJobReader
04205:                                .getLogNewValue());
04206:
04207:                    if (!this .loaderJobReader.getLogImportDefinitionName()
04208:                            .equalsIgnoreCase(""))
04209:                        dataCleaning
04210:                                .setLogImportDefinitionName(this .loaderJobReader
04211:                                        .getLogImportDefinitionName());
04212:
04213:                    if (!this .loaderJobReader.getLogOperationName()
04214:                            .equalsIgnoreCase(""))
04215:                        dataCleaning.setLogOperationName(this .loaderJobReader
04216:                                .getLogOperationName());
04217:                    if (!this .loaderJobReader.getLogTime().equalsIgnoreCase(""))
04218:                        dataCleaning.setLogTime(this .loaderJobReader
04219:                                .getLogTime());
04220:
04221:                    if (!this .loaderJobReader.getLogFailedStatement()
04222:                            .equalsIgnoreCase(""))
04223:                        dataCleaning.setLogPrimaryKeyValue(this .loaderJobReader
04224:                                .getLogFailedStatement());
04225:
04226:                    if (!this .loaderJobReader.getLogTypeName()
04227:                            .equalsIgnoreCase(""))
04228:                        dataCleaning.setLogTypeName(this .loaderJobReader
04229:                                .getLogTypeName());
04230:
04231:                    importDefinitionElement.setLoaderJob(this .loaderJobReader);
04232:                    // sqlElement.setLoaderJob(this.loaderJobReader);
04233:                    importDefinitionElement.importXMLFile(doc, iJobNumber);
04234:
04235:                    // set data cut off parameter based on priority
04236:                    if (importDefinitionElement.strDefaultCutOffData
04237:                            .equalsIgnoreCase(""))
04238:                        importDefinitionElement.strDefaultCutOffData = loaderJobReader
04239:                                .getDefaultDataCutOff();
04240:
04241:                    // set onErrorContinue parameter based on priority for xml
04242:                    if (importDefinitionElement.strOnErrorContinueXml
04243:                            .equalsIgnoreCase(""))
04244:                        importDefinitionElement.strOnErrorContinueXml = ""
04245:                                + loaderJobReader.getDefaultOnErrorContinue();
04246:
04247:                    if (importDefinitionElement.strCopyTableOnErrorContinue
04248:                            .equalsIgnoreCase(""))
04249:                        importDefinitionElement.strCopyTableOnErrorContinue = ""
04250:                                + loaderJobReader.getDefaultOnErrorContinue();
04251:                    if (isImportDefinition) { // 26.07.2007 senka added  this check
04252:                        vecJDBCSourceValue = OctopusXMLUtil.importValue(doc,
04253:                                "jdbcSourceParameter", "value", iJobNumber);
04254:                        vecJDBCSourceName = OctopusXMLUtil.importValue(doc,
04255:                                "jdbcSourceParameter", "name", iJobNumber);
04256:
04257:                        if (vecJDBCSourceValue.size() != 0) {
04258:                            for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
04259:                                if (vecJDBCSourceName.get(i).toString()
04260:                                        .equalsIgnoreCase("JdbcDriver"))
04261:                                    jdbcParametersElement
04262:                                            .setJDBCSourceParameterDriver(vecJDBCSourceValue
04263:                                                    .get(i).toString());
04264:                                else if (vecJDBCSourceName.get(i).toString()
04265:                                        .equalsIgnoreCase("Connection.Url")) {
04266:                                    // Testing SelectMethod parameter in microsoft MSSQL
04267:                                    // driver
04268:                                    if (vecJDBCSourceValue
04269:                                            .get(i)
04270:                                            .toString()
04271:                                            .indexOf("jdbc:microsoft:sqlserver") != -1) {
04272:                                        if (vecJDBCSourceValue.get(i)
04273:                                                .toString().indexOf(
04274:                                                        "SelectMethod") == -1) {
04275:                                            jdbcParametersElement
04276:                                                    .setJDBCSourceParameterConnection(vecJDBCSourceValue
04277:                                                            .get(i).toString()
04278:                                                            + ";SelectMethod=cursor");
04279:                                        } else if (vecJDBCSourceValue.get(i)
04280:                                                .toString().indexOf("cursor") != -1) {
04281:                                            jdbcParametersElement
04282:                                                    .setJDBCSourceParameterConnection(vecJDBCSourceValue
04283:                                                            .get(i).toString());
04284:                                        } else {
04285:                                            this .logger
04286:                                                    .write(
04287:                                                            "normal",
04288:                                                            "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor");
04289:                                            LoaderException le = new LoaderException(
04290:                                                    "Exception:",
04291:                                                    new Exception(
04292:                                                            "Value of Connection.Url perameter SelectMethod has to be cursor"));
04293:                                            this .logger.write("full", le
04294:                                                    .getStackTraceAsString());
04295:                                            throw le;
04296:                                        }
04297:                                    } else {
04298:                                        jdbcParametersElement
04299:                                                .setJDBCSourceParameterConnection(vecJDBCSourceValue
04300:                                                        .get(i).toString());
04301:                                    }
04302:                                } else if (vecJDBCSourceName.get(i).toString()
04303:                                        .equalsIgnoreCase("User"))
04304:                                    jdbcParametersElement
04305:                                            .setJDBCSourceParameterUser(vecJDBCSourceValue
04306:                                                    .get(i).toString());
04307:                                else if (vecJDBCSourceName.get(i).toString()
04308:                                        .equalsIgnoreCase("Password"))
04309:                                    jdbcParametersElement
04310:                                            .setJDBCSourceParameterPassword(vecJDBCSourceValue
04311:                                                    .get(i).toString());
04312:                            }
04313:                        }
04314:
04315:                        vecJDBCTargetValue = OctopusXMLUtil.importValue(doc,
04316:                                "jdbcTargetParameter", "value", iJobNumber);
04317:                        vecJDBCTargetName = OctopusXMLUtil.importValue(doc,
04318:                                "jdbcTargetParameter", "name", iJobNumber);
04319:
04320:                        if (vecJDBCTargetValue.size() != 0) {
04321:                            for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
04322:                                if (vecJDBCTargetName.get(i).toString()
04323:                                        .equalsIgnoreCase("JdbcDriver"))
04324:                                    jdbcParametersElement
04325:                                            .setJDBCTargetParameterDriver(vecJDBCTargetValue
04326:                                                    .get(i).toString());
04327:                                else if (vecJDBCTargetName.get(i).toString()
04328:                                        .equalsIgnoreCase("Connection.Url")) {
04329:                                    // Testing SelectMethod parameter in microsoft MSSQL
04330:                                    // driver
04331:                                    if (vecJDBCTargetValue
04332:                                            .get(i)
04333:                                            .toString()
04334:                                            .indexOf("jdbc:microsoft:sqlserver") != -1) {
04335:                                        if (vecJDBCTargetValue.get(i)
04336:                                                .toString().indexOf(
04337:                                                        "SelectMethod") == -1) {
04338:                                            jdbcParametersElement
04339:                                                    .setJDBCTargetParameterConnection(vecJDBCTargetValue
04340:                                                            .get(i).toString()
04341:                                                            + ";SelectMethod=cursor");
04342:                                        } else if (vecJDBCTargetValue.get(i)
04343:                                                .toString().indexOf("cursor") != -1) {
04344:                                            jdbcParametersElement
04345:                                                    .setJDBCTargetParameterConnection(vecJDBCTargetValue
04346:                                                            .get(i).toString());
04347:                                        } else {
04348:                                            this .logger
04349:                                                    .write(
04350:                                                            "normal",
04351:                                                            "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor");
04352:                                            LoaderException le = new LoaderException(
04353:                                                    "Exception:",
04354:                                                    new Exception(
04355:                                                            "value of Connection.Url parameter SelectMethod has to be cursor"));
04356:                                            this .logger.write("full", le
04357:                                                    .getStackTraceAsString());
04358:                                            throw le;
04359:                                        }
04360:                                    } else {
04361:                                        jdbcParametersElement
04362:                                                .setJDBCTargetParameterConnection(vecJDBCTargetValue
04363:                                                        .get(i).toString());
04364:                                    }
04365:                                } else if (vecJDBCTargetName.get(i).toString()
04366:                                        .equalsIgnoreCase("User"))
04367:                                    jdbcParametersElement
04368:                                            .setJDBCTargetParameterUser(vecJDBCTargetValue
04369:                                                    .get(i).toString());
04370:                                else if (vecJDBCTargetName.get(i).toString()
04371:                                        .equalsIgnoreCase("Password"))
04372:                                    jdbcParametersElement
04373:                                            .setJDBCTargetParameterPassword(vecJDBCTargetValue
04374:                                                    .get(i).toString());
04375:                            }
04376:                        }
04377:                        // to and form hex
04378:
04379:                        vecToHexTemp = OctopusXMLUtil.importValue(doc,
04380:                                "valueColumn", "toHex", iJobNumber);
04381:                        vecFromHexTemp = OctopusXMLUtil.importValue(doc,
04382:                                "valueColumn", "fromHex", iJobNumber);
04383:                        // defalut values
04384:                        vecDefaultValueTemp = OctopusXMLUtil.importValue(doc,
04385:                                "valueColumn", "defaultValue", iJobNumber);
04386:                        this .vecDefaultVariableValue = OctopusXMLUtil
04387:                                .importValue(doc, "variableColumn",
04388:                                        "defaultValue", iJobNumber);
04389:                        this .vecDefaultVariableName = OctopusXMLUtil
04390:                                .importValue(doc, "variableColumn", "name",
04391:                                        iJobNumber);
04392:                        this .vecDefaultRelationValue = OctopusXMLUtil
04393:                                .importValue(doc, "relationColumn",
04394:                                        "defaultValue", iJobNumber);
04395:                        this .vecTempUserID = OctopusXMLUtil.importValue(doc,
04396:                                "userIDColumn", "defaultValue", iJobNumber);
04397:                        vecValueColumnSourceColumnName = OctopusXMLUtil
04398:                                .importValue(doc, "valueColumn",
04399:                                        "sourceColumnName", iJobNumber);
04400:                        vecValueColumnTargetTableName = OctopusXMLUtil
04401:                                .importValue(doc, "valueColumn",
04402:                                        "targetTableName", iJobNumber);
04403:                        this .iValueColumns = vecValueColumnTargetTableName
04404:                                .size();
04405:                        vecValueColumnTargetColumnName = OctopusXMLUtil
04406:                                .importValue(doc, "valueColumn",
04407:                                        "targetColumnName", iJobNumber);
04408:                        vecValueColumnTargetTableID = OctopusXMLUtil
04409:                                .importValue(doc, "valueColumn",
04410:                                        "targetTableID", iJobNumber);
04411:                        vecValueColumnValueMode = OctopusXMLUtil.importValue(
04412:                                doc, "valueColumn", "valueMode", iJobNumber);
04413:                        this .vecVariableColumnName = OctopusXMLUtil
04414:                                .importValue(doc, "variableColumn", "name",
04415:                                        iJobNumber);
04416:                        this .vecVariableColumnTargetTableName = OctopusXMLUtil
04417:                                .importValue(doc, "variableColumn",
04418:                                        "targetTableName", iJobNumber);
04419:                        this .vecVariableColumnTargetColumnName = OctopusXMLUtil
04420:                                .importValue(doc, "variableColumn",
04421:                                        "targetColumnName", iJobNumber);
04422:                        this .vecVariableColumnTargetTableID = OctopusXMLUtil
04423:                                .importValue(doc, "variableColumn",
04424:                                        "targetTableID", iJobNumber);
04425:                        this .vecVariableColumnValueMode = OctopusXMLUtil
04426:                                .importValue(doc, "variableColumn",
04427:                                        "valueMode", iJobNumber);
04428:                        this .vecVariableUseIDTableName = OctopusXMLUtil
04429:                                .importValue(doc, "userIDColumn",
04430:                                        "targetTableName", iJobNumber);
04431:                        this .vecVariableUseIDColumnName = OctopusXMLUtil
04432:                                .importValue(doc, "userIDColumn",
04433:                                        "targetColumnName", iJobNumber);
04434:                        this .vecVariableUseIDTableID = OctopusXMLUtil
04435:                                .importValue(doc, "userIDColumn",
04436:                                        "targetTableID", iJobNumber);
04437:                        this .vecVariableUseIDValueMode = OctopusXMLUtil
04438:                                .importValue(doc, "userIDColumn", "valueMode",
04439:                                        iJobNumber);
04440:                        this .vecVariableTimesTableName = OctopusXMLUtil
04441:                                .importValue(doc, "timeStampColumn",
04442:                                        "targetTableName", iJobNumber);
04443:                        this .vecVariableTimesColumnName = OctopusXMLUtil
04444:                                .importValue(doc, "timeStampColumn",
04445:                                        "targetColumnName", iJobNumber);
04446:                        this .vecVariableTimesTableID = OctopusXMLUtil
04447:                                .importValue(doc, "timeStampColumn",
04448:                                        "targetTableID", iJobNumber);
04449:                        this .vecVariableTimesValueMode = OctopusXMLUtil
04450:                                .importValue(doc, "timeStampColumn",
04451:                                        "valueMode", iJobNumber);
04452:                        this .vecConstantColumnTargetTableName = OctopusXMLUtil
04453:                                .importValue(doc, "constantColumn",
04454:                                        "targetTableName", iJobNumber);
04455:                        this .iConstantColumns = this .vecConstantColumnTargetTableName
04456:                                .size();
04457:                        vecConstantColumnTargetColumnName = OctopusXMLUtil
04458:                                .importValue(doc, "constantColumn",
04459:                                        "targetColumnName", iJobNumber);
04460:                        this .vecConstantColumnTargetTableID = OctopusXMLUtil
04461:                                .importValue(doc, "constantColumn",
04462:                                        "targetTableID", iJobNumber);
04463:                        vecConstantColumnValueMode = OctopusXMLUtil
04464:                                .importValue(doc, "constantColumn",
04465:                                        "valueMode", iJobNumber);
04466:
04467:                        vecConstantColumnConstantValue = OctopusXMLUtil
04468:                                .importValue(doc, "constantColumn",
04469:                                        "constantValue", iJobNumber, null);
04470:                        this .vecRelationColumnSourceTableName = OctopusXMLUtil
04471:                                .importValue(doc, "relationColumn",
04472:                                        "relationSourceTableName", iJobNumber);
04473:                        this .iRelationColumns = this .vecRelationColumnSourceTableName
04474:                                .size();
04475:                        this .vecRelationColumnSourceTableID = OctopusXMLUtil
04476:                                .importValue(doc, "relationColumn",
04477:                                        "relationSourceTableID", iJobNumber);
04478:                        this .vecRelationColumnSourceColumnName = OctopusXMLUtil
04479:                                .importValue(doc, "relationColumn",
04480:                                        "relationSourceColumnName", iJobNumber);
04481:                        this .vecRelationColumnTargetTableName = OctopusXMLUtil
04482:                                .importValue(doc, "relationColumn",
04483:                                        "relationTargetTableName", iJobNumber);
04484:                        this .vecRelationColumnTargetColumnName = OctopusXMLUtil
04485:                                .importValue(doc, "relationColumn",
04486:                                        "relationTargetColumnName", iJobNumber);
04487:                        this .vecRelationColumnTargetTableID = OctopusXMLUtil
04488:                                .importValue(doc, "relationColumn",
04489:                                        "relationTargetTableID", iJobNumber);
04490:                        this .vecRelationColumnRelationMode = OctopusXMLUtil
04491:                                .importValue(doc, "relationColumn",
04492:                                        "relationMode", iJobNumber);
04493:                        // rale
04494:
04495:                        ImportDefinitionSourceColumnName = vecValueColumnSourceColumnName;
04496:                        ImportDefinitionTargetColumnName = vecValueColumnTargetColumnName;
04497:
04498:                        // sinisa 02.03.2003. Add counterColumns
04499:                        this .counterColumns = new CounterColumns();
04500:                        this .counterColumns.setLogger(this .logger);
04501:                        this .counterColumns.resetSubCounterCache();
04502:                        this .counterColumns.readConstantColumnAttributes(doc,
04503:                                iJobNumber);
04504:                        this .counterColumns.readConstantColumnsParameters(doc,
04505:                                iJobNumber);
04506:                        // end sinisa
04507:
04508:                        // sinisa 02.03.2003. Add transformations
04509:                        this .transformations = new Transformations(this .logger);
04510:                        // ArrayList transTableNamesIDs =
04511:                        // this.transformations.getTransformationsTableNamesAndIDs();
04512:                        this .transformations.createTransformationElements(doc,
04513:                                iJobNumber);
04514:                        ArrayList trans = this .transformations
04515:                                .getTransformations();
04516:                        Iterator iTrans = trans.iterator();
04517:
04518:                        while (iTrans.hasNext()) {
04519:                            Transformation temp = (Transformation) iTrans
04520:                                    .next();
04521:                            temp.setLogger(this .logger);
04522:
04523:                            // temp.readSourceColumns(doc, iJobNumber);
04524:                            // temp.readTargetColumns(doc, iJobNumber);
04525:                            // temp.readSourceColumns();
04526:                            // temp.readTargetColumns();
04527:
04528:                        }
04529:
04530:                        // end sinisa
04531:
04532:                        this .vecTableTableName = OctopusXMLUtil.importValue(
04533:                                doc, "table", "tableName", iJobNumber);
04534:                        this .iTables = this .vecTableTableName.size();
04535:                        this .vecTableTableID = OctopusXMLUtil.importValue(doc,
04536:                                "table", "tableID", iJobNumber);
04537:                        this .vecTableInsert = OctopusXMLUtil.importValue(doc,
04538:                                "table", "insert", iJobNumber);
04539:                        this .vecTableTableMode = OctopusXMLUtil.importValue(
04540:                                doc, "table", "tableMode", iJobNumber,
04541:                                loaderJobReader.getDefaultTableMode());
04542:                        this .vecTableOidLogic = OctopusXMLUtil.importValue(doc,
04543:                                "table", "oidLogic", iJobNumber, (new Boolean(
04544:                                        loaderJobReader.getDefaultOidLogic()))
04545:                                        .toString());
04546:
04547:                        this .vecCTAutoMapp = OctopusXMLUtil.importValue(doc,
04548:                                "table", "autoMapColumns", iJobNumber);
04549:                        this .vecCTDefaultMode = OctopusXMLUtil.importValue(doc,
04550:                                "table", "defaultMode", iJobNumber);
04551:                    } // senka added : end of if (isImportDefinition)
04552:                    if (this .vecRelationColumnSourceTableName.size() != 0) {
04553:                        this .changeRelationsOrder();
04554:                        this .changeTableOrder();
04555:                    }
04556:                    this .vecRelationKeyColumns.setSize(this .iTables);
04557:                    this .vecRelationKeyTypes.setSize(this .iTables);
04558:                    this .vecConstantTargetColumnName.setSize(this .iTables);
04559:                    // ZK added this
04560:                    // this.transformationsColumnNames.setSize(this.iTables);
04561:
04562:                    this .vecConstantValueMode.setSize(this .iTables);
04563:                    this .vecConstantConstantValue.setSize(this .iTables);
04564:                    this .vecConstantColumnType.setSize(this .iTables);
04565:                    for (int k = 0; k < vecValueColumnTargetTableName.size(); k++) {
04566:                        boolean isImportColumn = false;
04567:                        for (int l = 0; l < this .iTables; l++) {
04568:                            if (vecValueColumnTargetTableName.get(k).toString()
04569:                                    .equalsIgnoreCase(
04570:                                            this .vecTableTableName.get(l)
04571:                                                    .toString())
04572:                                    && vecValueColumnTargetTableID.get(k)
04573:                                            .toString().equalsIgnoreCase(
04574:                                                    this .vecTableTableID.get(l)
04575:                                                            .toString())) {
04576:                                isImportColumn = true;
04577:                            }
04578:                        }
04579:                        if (!isImportColumn) {
04580:                            this .logger
04581:                                    .write("normal",
04582:                                            "Incorrect XML import variables - TABLE ID");
04583:                            LoaderException le = new LoaderException(
04584:                                    "Exception: ",
04585:                                    (Throwable) (new Exception(
04586:                                            "Incorrect XML import variables - TABLE ID")));
04587:                            this .logger.write("full", le
04588:                                    .getStackTraceAsString());
04589:                            throw le;
04590:                        }
04591:                    }
04592:
04593:                    if (this .vecVariableUseIDTableName.size() != 0) {
04594:                        String tempUserID = this .vecTempUserID.get(0)
04595:                                .toString();
04596:                        if (userIDExists)
04597:                            this .strUserID = "";
04598:                        if (this .strUserID.equals("")) {
04599:                            if (!tempUserID.equalsIgnoreCase("")) {
04600:                                this .strUserID = tempUserID;
04601:                                this .userIDExists = true;
04602:                            } else {
04603:                                this .logger.write("normal",
04604:                                        "Error : User parametar missing");
04605:                                LoaderException le = new LoaderException(
04606:                                        "Exception: ",
04607:                                        (Throwable) (new Exception(
04608:                                                "Error : User parametar missing")));
04609:                                this .logger.write("full", le
04610:                                        .getStackTraceAsString());
04611:                                throw le;
04612:                            }
04613:                        }
04614:                    }
04615:                    for (int k = 0; k < this .iTables; k++) {
04616:                        iNumberOfColumns = 0;
04617:                        Vector vecTargetTable1 = new Vector();
04618:                        Vector vecTargetTable2 = new Vector();
04619:                        Vector vecTargetTable3 = new Vector();
04620:                        Vector vecTargetTable4 = new Vector();
04621:                        Vector vecTargetTable5 = new Vector();
04622:                        Vector vecTargetTable6 = new Vector();
04623:                        Vector vecTargetTable7 = new Vector();
04624:                        Vector vecTargetTable8 = new Vector();
04625:                        Vector vecTargetTable9 = new Vector();
04626:                        Vector vecTargetTable10 = new Vector();
04627:                        Vector vecTargetTable11 = new Vector();
04628:
04629:                        for (int l = 0; l < this .iValueColumns; l++) {
04630:                            if (this .vecTableTableName.get(k).toString()
04631:                                    .equalsIgnoreCase(
04632:                                            vecValueColumnTargetTableName
04633:                                                    .get(l).toString())
04634:                                    && vecValueColumnTargetTableID.get(l)
04635:                                            .toString().equalsIgnoreCase(
04636:                                                    this .vecTableTableID.get(k)
04637:                                                            .toString())) {
04638:                                iNumberOfColumns++;
04639:                                vecTargetTable1
04640:                                        .addElement(vecValueColumnSourceColumnName
04641:                                                .get(l).toString());
04642:                                vecTargetTable2
04643:                                        .addElement(vecValueColumnTargetColumnName
04644:                                                .get(l).toString());
04645:                                vecTargetTable4
04646:                                        .addElement(vecValueColumnValueMode
04647:                                                .get(l).toString());
04648:                                // rale
04649:                                vecTargetTable9.addElement(vecDefaultValueTemp
04650:                                        .get(l).toString());
04651:                                vecTargetTable10.addElement(vecToHexTemp.get(l)
04652:                                        .toString());
04653:                                vecTargetTable11.addElement(vecFromHexTemp.get(
04654:                                        l).toString());
04655:                                if (vecValueColumnValueMode.get(l).toString()
04656:                                        .equalsIgnoreCase("Key"))
04657:                                    vecTargetTable5
04658:                                            .addElement(vecValueColumnTargetColumnName
04659:                                                    .get(l).toString());
04660:                            }
04661:                        }
04662:                        for (int l = 0; l < this .vecVariableUseIDTableName
04663:                                .size(); l++) {
04664:                            if (this .vecTableTableName.get(k).toString()
04665:                                    .equalsIgnoreCase(
04666:                                            this .vecVariableUseIDTableName.get(
04667:                                                    l).toString())
04668:                                    && this .vecVariableUseIDTableID.get(l)
04669:                                            .toString().equalsIgnoreCase(
04670:                                                    this .vecTableTableID.get(k)
04671:                                                            .toString())) {
04672:                                vecTargetTable2
04673:                                        .addElement(this .vecVariableUseIDColumnName
04674:                                                .get(l).toString());
04675:                                vecTargetTable4
04676:                                        .addElement(this .vecVariableUseIDValueMode
04677:                                                .get(l).toString());
04678:                                // rale
04679:                                // vecTargetTable9.addElement(vecDefaultValueTemp.get(l).toString());
04680:                                // vecTargetTable10.addElement(vecToHexTemp.get(l).toString());
04681:                                // vecTargetTable11.addElement(vecFromHexTemp.get(l).toString());
04682:
04683:                                if (this .vecVariableUseIDValueMode.get(l)
04684:                                        .toString().equalsIgnoreCase("Key"))
04685:                                    vecTargetTable5
04686:                                            .addElement(this .vecVariableUseIDColumnName
04687:                                                    .get(l).toString());
04688:                            }
04689:                        }
04690:                        for (int l = 0; l < this .vecRelationColumnSourceColumnName
04691:                                .size(); l++) {
04692:                            if (this .vecTableTableName
04693:                                    .get(k)
04694:                                    .toString()
04695:                                    .equalsIgnoreCase(
04696:                                            this .vecRelationColumnTargetTableName
04697:                                                    .get(l).toString())
04698:                                    && this .vecRelationColumnTargetTableID.get(
04699:                                            l).toString().equalsIgnoreCase(
04700:                                            this .vecTableTableID.get(k)
04701:                                                    .toString())
04702:                                    && this .vecRelationColumnRelationMode
04703:                                            .get(l).toString()
04704:                                            .equalsIgnoreCase("Key")) {
04705:                                vecTargetTable3
04706:                                        .addElement(this .vecRelationColumnTargetColumnName
04707:                                                .get(l).toString());
04708:                            }
04709:                        }
04710:
04711:                        // rale
04712:                        this .vecToHex.addElement(vecToHexTemp);
04713:                        this .vecFromHex.addElement(vecFromHexTemp);
04714:                        this .vecDefaultValue.addElement(vecTargetTable9);
04715:                        this .vecSourceColumnName.addElement(vecTargetTable1);
04716:                        this .vecTargetColumnName.addElement(vecTargetTable2);
04717:                        this .vecRelationKeyColumns.setElementAt(
04718:                                vecTargetTable3, k);
04719:                        this .vecValueMode.addElement(vecTargetTable4);
04720:                        this .vecTargetKeyColumnName.addElement(vecTargetTable5);
04721:                        this .vecValueColumnsTargetTables
04722:                                .addElement(new Integer(iNumberOfColumns));
04723:                        for (int p = 0; p < this .iConstantColumns; p++) {
04724:                            if (this .vecTableTableName
04725:                                    .get(k)
04726:                                    .toString()
04727:                                    .equalsIgnoreCase(
04728:                                            this .vecConstantColumnTargetTableName
04729:                                                    .get(p).toString())
04730:                                    && this .vecConstantColumnTargetTableID.get(
04731:                                            p).toString().equalsIgnoreCase(
04732:                                            this .vecTableTableID.get(k)
04733:                                                    .toString())) {
04734:                                vecTargetTable6
04735:                                        .addElement(vecConstantColumnTargetColumnName
04736:                                                .get(p).toString());
04737:                                vecTargetTable7
04738:                                        .addElement(vecConstantColumnValueMode
04739:                                                .get(p).toString());
04740:                                if (vecConstantColumnConstantValue.get(p) == null)
04741:                                    vecTargetTable8.addElement(null);
04742:                                else
04743:                                    vecTargetTable8
04744:                                            .addElement(vecConstantColumnConstantValue
04745:                                                    .get(p).toString());
04746:                            }
04747:                        }
04748:                        this .vecConstantTargetColumnName.setElementAt(
04749:                                vecTargetTable6, k);
04750:                        this .vecConstantValueMode.setElementAt(vecTargetTable7,
04751:                                k);
04752:                        this .vecConstantConstantValue.setElementAt(
04753:                                vecTargetTable8, k);
04754:
04755:                        // sinisa 02.03.2003. Add counterColumns
04756:
04757:                        this .counterColumns.setConstantColumnsParameters(
04758:                                this .vecTableTableName.get(k).toString(),
04759:                                this .vecTableTableID.get(k).toString());
04760:                        // end sinisa
04761:                    }
04762:
04763:                    for (int i = 0; i < this .vecRelationColumnSourceColumnName
04764:                            .size(); i++) {
04765:                        if (this .vecRelationColumnSourceColumnName.get(i)
04766:                                .toString().equals("")) {
04767:                            for (int k = 0; k < this .vecTableTableName.size(); k++) {
04768:                                if (this .vecRelationColumnSourceTableName
04769:                                        .get(i).toString().equalsIgnoreCase(
04770:                                                this .vecTableTableName.get(k)
04771:                                                        .toString())
04772:                                        && this .vecRelationColumnSourceTableID
04773:                                                .get(i).toString()
04774:                                                .equalsIgnoreCase(
04775:                                                        this .vecTableTableID
04776:                                                                .get(k)
04777:                                                                .toString())) {
04778:                                    if (this .vecTableOidLogic.get(k).toString()
04779:                                            .equalsIgnoreCase("true"))
04780:                                        this .vecRelationColumnSourceColumnName
04781:                                                .setElementAt(
04782:                                                        this .currentOidColumnName,
04783:                                                        i);
04784:                                    // this.vecRelationColumnSourceColumnName.setElementAt("oid",i);
04785:                                }
04786:                            }
04787:                        }
04788:                    }
04789:                    this .vecRelationSourceValue.setSize(this .iRelationColumns);
04790:                    this .vecRelationSourceType.setSize(this .iRelationColumns);
04791:                } catch (NullPointerException ex) {
04792:                    throw ex;
04793:                } catch (Exception ex) {
04794:                    throw ex;
04795:                }
04796:                this .logger
04797:                        .write("full", "\timportXMLFile method is finished.");
04798:            }
04799:
04800:            /**
04801:             * Method updateCurrentTime write system time into timeStamp variable
04802:             * columns
04803:             * 
04804:             * @param c
04805:             *            Connection to the target table.
04806:             * @param iTable
04807:             *            Number of target table.
04808:             * @param strQueryWhereSQL
04809:             *            Part of SQL query - where clause.
04810:             * @param currentVersion
04811:             *            represents current version of insert/update
04812:             * @param oid
04813:             *            repersents if the oid logic is present
04814:             * @throws SQLException
04815:             * @throws NullPointerException
04816:             * @return true if something is written to database
04817:             */
04818:            private boolean updateCurrentTime(Connection c, int iTable,
04819:                    String strQueryWhereSQL, int currentVersion, boolean oid)
04820:                    throws SQLException, NullPointerException {
04821:                String strQueryInsertTime = "";
04822:                boolean bWriteData = false;
04823:                String oidVersion = "";
04824:                // if (oid)
04825:                // oidVersion = ", version=" + currentVersion;
04826:                if (oid)
04827:                    oidVersion = ", " + this .currentVersionColumnName + "="
04828:                            + currentVersion;
04829:                this .logger.write("full",
04830:                        "\t updateCurrentTime method is started.");
04831:                try {
04832:                    for (int i = 0; i < this .vecVariableTimesTableName.size(); i++) {
04833:                        if (this .vecVariableTimesTableName.get(i).toString()
04834:                                .equalsIgnoreCase(
04835:                                        this .vecTableTableName.get(iTable)
04836:                                                .toString())
04837:                                && this .vecVariableTimesTableID
04838:                                        .get(i)
04839:                                        .toString()
04840:                                        .equalsIgnoreCase(
04841:                                                this .vecTableTableID
04842:                                                        .get(iTable).toString())) {
04843:                            Statement stmtRelations = c.createStatement();
04844:                            strQueryInsertTime = "update "
04845:                                    + this .vecVariableTimesTableName.get(i)
04846:                                            .toString()
04847:                                    + " set "
04848:                                    + this .vecVariableTimesColumnName.get(i)
04849:                                            .toString() + " = ";
04850:                            if (this .vecVariableTimesValueMode.get(i)
04851:                                    .toString().equalsIgnoreCase("Overwrite"))
04852:
04853:                                // && bWriteData == true)
04854:                                strQueryInsertTime += " '"
04855:                                        + this .createCurrentDate() + "'"
04856:                                        + oidVersion + " where "
04857:                                        + strQueryWhereSQL;
04858:                            else
04859:                                strQueryInsertTime += " '"
04860:                                        + this .createCurrentDate()
04861:                                        + "'"
04862:                                        + oidVersion
04863:                                        + " where "
04864:                                        + this .vecVariableTimesColumnName
04865:                                                .get(i).toString()
04866:                                        + " is null and " + strQueryWhereSQL;
04867:                            this .logger
04868:                                    .write("full", "\tQuery '"
04869:                                            + strQueryInsertTime
04870:                                            + "' will be executed");
04871:                            if (bReplaceInData) {
04872:                                strQueryInsertTime = this 
04873:                                        .replaceInData(strQueryInsertTime);
04874:                            }
04875:                            int num = stmtRelations
04876:                                    .executeUpdate(strQueryInsertTime);
04877:                            if (num != 0) {
04878:                                bWriteData = true;
04879:                            }
04880:                            stmtRelations.close();
04881:                        }
04882:                    }
04883:                } catch (SQLException ex) {
04884:                    throw ex;
04885:                } catch (NullPointerException ex) {
04886:                    throw ex;
04887:                }
04888:                this .logger.write("full",
04889:                        "\tupdateCurrentTime method is finished.");
04890:                return bWriteData;
04891:            }
04892:
04893:            /**
04894:             * Method updateNameValue writes nameValue value (Loader's argument) into
04895:             * variable columns
04896:             * 
04897:             * @param c
04898:             *            Connection to the target table.
04899:             * @param iTable
04900:             *            Number of target table.
04901:             * @param strQueryWhereSQL
04902:             *            Part of SQL query - where clause.
04903:             * @param currentVersion
04904:             *            represents current version of insert/update
04905:             * @param oid
04906:             *            define if oid logic is present
04907:             * @throws SQLException
04908:             * @throws NullPointerException
04909:             * @throws LoaderException
04910:             * @return true if something is written to database
04911:             */
04912:            private boolean updateNameValue(Connection c, int iTable,
04913:                    String strQueryWhereSQL, int currentVersion, boolean oid)
04914:                    throws SQLException, NullPointerException, LoaderException {
04915:
04916:                String strQueryInsertName = "";
04917:                boolean bWriteData = false;
04918:                String oidVersion = "";
04919:                // if (oid)
04920:                // oidVersion = ", version=" + currentVersion;
04921:                if (oid)
04922:                    oidVersion = ", " + this .currentVersionColumnName + "="
04923:                            + currentVersion;
04924:
04925:                this .logger.write("full",
04926:                        "\t updateNameValue method is started.");
04927:                try {
04928:                    for (int i = 0; i < this .vecVariableColumnTargetTableName
04929:                            .size(); i++) {
04930:                        boolean bInsert = true;
04931:                        if (this .vecVariableColumnTargetTableName.get(i)
04932:                                .toString().equalsIgnoreCase(
04933:                                        this .vecTableTableName.get(iTable)
04934:                                                .toString())
04935:                                && this .vecVariableColumnTargetTableID
04936:                                        .get(i)
04937:                                        .toString()
04938:                                        .equalsIgnoreCase(
04939:                                                this .vecTableTableID
04940:                                                        .get(iTable).toString())) {
04941:                            int iPositionInVector = this .vecVariableName
04942:                                    .indexOf(this .vecVariableColumnName.get(i)
04943:                                            .toString());
04944:                            if (iPositionInVector != -1) {
04945:                                Statement stmtRelations = c.createStatement();
04946:                                strQueryInsertName = "update "
04947:                                        + this .vecVariableColumnTargetTableName
04948:                                                .get(i).toString()
04949:                                        + " set "
04950:                                        + this .vecVariableColumnTargetColumnName
04951:                                                .get(i).toString() + " = ";
04952:                                if (this .vecVariableColumnValueMode.get(i)
04953:                                        .toString().equalsIgnoreCase(
04954:                                                "Overwrite")) {
04955:                                    if (this .vecVariableValue
04956:                                            .get(iPositionInVector) == null) {
04957:                                        String variableName = this .vecVariableColumnName
04958:                                                .get(i).toString();
04959:                                        for (int k = 0; k < this .vecDefaultVariableName
04960:                                                .size(); k++) {
04961:                                            if (this .vecDefaultVariableName
04962:                                                    .get(k).toString()
04963:                                                    .equalsIgnoreCase(
04964:                                                            variableName)) {
04965:                                                if (!this .vecDefaultVariableValue
04966:                                                        .get(k).toString()
04967:                                                        .equalsIgnoreCase("")) {
04968:                                                    // if
04969:                                                    // (!CheckType.isNumber(this.vecVariableColumnTypes.get(i).
04970:                                                    // toString()))
04971:                                                    // ZK change this from CheckType to
04972:                                                    // configReaderTarget this 7.5.2004
04973:
04974:                                                    if (!configReaderTarget
04975:                                                            .isNumber(this .vecVariableColumnTypes
04976:                                                                    .get(i)
04977:                                                                    .toString()))
04978:
04979:                                                        strQueryInsertName += " '"
04980:                                                                + this .vecDefaultVariableValue
04981:                                                                        .get(k)
04982:                                                                        .toString()
04983:                                                                + "' "
04984:                                                                + oidVersion
04985:                                                                + " where "
04986:                                                                + strQueryWhereSQL;
04987:                                                    else
04988:                                                        strQueryInsertName += " "
04989:                                                                + this .vecDefaultVariableValue
04990:                                                                        .get(k)
04991:                                                                + " "
04992:                                                                + oidVersion
04993:                                                                + " where "
04994:                                                                + strQueryWhereSQL;
04995:
04996:                                                } else {
04997:                                                    strQueryInsertName += " null"
04998:                                                            + oidVersion
04999:                                                            + " where "
05000:                                                            + strQueryWhereSQL;
05001:                                                }
05002:                                                break;
05003:                                            }
05004:                                        }
05005:                                    } else {
05006:                                        // ZK change this from CheckType to
05007:                                        // configReaderTarget this 7.5.2004
05008:                                        if (!configReaderTarget
05009:                                                .isNumber(this .vecVariableColumnTypes
05010:                                                        .get(i).toString()))
05011:                                            strQueryInsertName += " '"
05012:                                                    + this .vecVariableValue
05013:                                                            .get(
05014:                                                                    iPositionInVector)
05015:                                                            .toString() + "'"
05016:                                                    + oidVersion + " where "
05017:                                                    + strQueryWhereSQL;
05018:                                        else
05019:                                            strQueryInsertName += this .vecVariableValue
05020:                                                    .get(iPositionInVector)
05021:                                                    .toString()
05022:                                                    + oidVersion
05023:                                                    + " where "
05024:                                                    + strQueryWhereSQL;
05025:                                    }
05026:                                } else if (this .vecVariableColumnValueMode.get(
05027:                                        i).toString().equalsIgnoreCase(
05028:                                        "SetNull")) {
05029:                                    if (this .vecVariableValue
05030:                                            .get(iPositionInVector) == null)
05031:                                        strQueryInsertName += " null"
05032:                                                + oidVersion + " where "
05033:                                                + strQueryWhereSQL;
05034:                                    else
05035:                                        bInsert = false;
05036:                                } else {
05037:                                    if (this .vecVariableValue
05038:                                            .get(iPositionInVector) == null) {
05039:                                        String variableName = this .vecVariableColumnName
05040:                                                .get(i).toString();
05041:                                        for (int k = 0; k < this .vecDefaultVariableName
05042:                                                .size(); k++) {
05043:                                            if (this .vecDefaultVariableName
05044:                                                    .get(k).toString()
05045:                                                    .equalsIgnoreCase(
05046:                                                            variableName)) {
05047:                                                if (!this .vecDefaultVariableValue
05048:                                                        .get(k).toString()
05049:                                                        .equalsIgnoreCase("")) {
05050:                                                    // ZK change this from CheckType to
05051:                                                    // configReaderTarget this 7.5.2004
05052:                                                    if (!configReaderTarget
05053:                                                            .isNumber(this .vecVariableColumnTypes
05054:                                                                    .get(i)
05055:                                                                    .toString()))
05056:                                                        strQueryInsertName += " '"
05057:                                                                + this .vecDefaultVariableValue
05058:                                                                        .get(k)
05059:                                                                        .toString()
05060:                                                                + "' "
05061:                                                                + oidVersion
05062:                                                                + " where "
05063:                                                                + this .vecVariableColumnTargetColumnName
05064:                                                                        .get(i)
05065:                                                                        .toString()
05066:                                                                + " is null and "
05067:                                                                + strQueryWhereSQL;
05068:                                                    else
05069:                                                        strQueryInsertName += " "
05070:                                                                + this .vecDefaultVariableValue
05071:                                                                        .get(k)
05072:                                                                + " "
05073:                                                                + oidVersion
05074:                                                                + " where "
05075:                                                                + this .vecVariableColumnTargetColumnName
05076:                                                                        .get(i)
05077:                                                                        .toString()
05078:                                                                + " is null and "
05079:                                                                + strQueryWhereSQL;
05080:                                                } else {
05081:                                                    strQueryInsertName += " null"
05082:                                                            + oidVersion
05083:                                                            + " where "
05084:                                                            + this .vecVariableColumnTargetColumnName
05085:                                                                    .get(i)
05086:                                                                    .toString()
05087:                                                            + " is null and "
05088:                                                            + strQueryWhereSQL;
05089:                                                }
05090:                                                break;
05091:                                            }
05092:                                        }
05093:                                    } else {
05094:                                        // ZK change this from CheckType to
05095:                                        // configReaderTarget this 7.5.2004
05096:                                        if (!configReaderTarget
05097:                                                .isNumber(this .vecVariableColumnTypes
05098:                                                        .get(i).toString()))
05099:                                            strQueryInsertName += " '"
05100:                                                    + this .vecVariableValue
05101:                                                            .get(
05102:                                                                    iPositionInVector)
05103:                                                            .toString()
05104:                                                    + "'"
05105:                                                    + oidVersion
05106:                                                    + " where "
05107:                                                    + this .vecVariableColumnTargetColumnName
05108:                                                            .get(i).toString()
05109:                                                    + " is null and "
05110:                                                    + strQueryWhereSQL;
05111:                                        else
05112:                                            strQueryInsertName += this .vecVariableValue
05113:                                                    .get(iPositionInVector)
05114:                                                    .toString()
05115:                                                    + oidVersion
05116:                                                    + " where "
05117:                                                    + this .vecVariableColumnTargetColumnName
05118:                                                            .get(i).toString()
05119:                                                    + " is null and "
05120:                                                    + strQueryWhereSQL;
05121:                                    }
05122:                                }
05123:                                if (bInsert)
05124:                                    this .logger.write("full", "\tQuery '"
05125:                                            + strQueryInsertName
05126:                                            + "' will be executed");
05127:
05128:                                if (bReplaceInData) {
05129:                                    strQueryInsertName = this 
05130:                                            .replaceInData(strQueryInsertName);
05131:                                }
05132:                                if (bInsert) {
05133:                                    int num = 0;
05134:                                    try {
05135:                                        num = stmtRelations
05136:                                                .executeUpdate(strQueryInsertName);
05137:                                    } catch (SQLException ex) {
05138:                                        stmtRelations.close();
05139:                                        stmtRelations = c.createStatement();
05140:                                        if ((importDefinitionElement.strDefaultCutOffData
05141:                                                .equalsIgnoreCase("true"))) {
05142:                                            dataCleaning
05143:                                                    .cutingDataLenghtUpdate(
05144:                                                            this .vecTableTableName
05145:                                                                    .get(iTable)
05146:                                                                    .toString(),
05147:                                                            c,
05148:                                                            "",
05149:                                                            currentRow,
05150:                                                            strQueryInsertName,
05151:                                                            importDefinitionElement.strOnErrorContinueXml,
05152:                                                            importDefinitionElement.strImportDefinitionName,
05153:                                                            strQueryInsertName);
05154:                                        } else
05155:                                            throw ex;
05156:                                    }
05157:                                }
05158:                                // stmtRelations.close();
05159:                            } else {
05160:                                this .logger.write("normal",
05161:                                        "\tError: Cannot find value for variable column :"
05162:                                                + this .vecVariableColumnName
05163:                                                        .get(i).toString());
05164:                                LoaderException le = new LoaderException(
05165:                                        "Exception: ",
05166:                                        (Throwable) (new Exception(
05167:                                                "Error: Cannot find value for variable column :")));
05168:                                this .logger.write("full", le
05169:                                        .getStackTraceAsString());
05170:                                throw le;
05171:                            }
05172:                        }
05173:                    }
05174:                } catch (SQLException ex) {
05175:                    throw ex;
05176:                } catch (NullPointerException ex) {
05177:                    throw ex;
05178:                }
05179:                this .logger.write("full",
05180:                        "\tupdateNameValue method is finished.");
05181:                return bWriteData;
05182:            }
05183:
05184:            /**
05185:             * Method queryRelations is used to make SQL query for reading source value
05186:             * for relations between target tables. It puts the value from the source
05187:             * column in source relation table to the target column in target relation
05188:             * table. If there is an error, Exception "SQLException" or
05189:             * NullPointerException is thrown.
05190:             * 
05191:             * @param iTableInt
05192:             *            Number of target table.
05193:             * @param iNumberOfRelationColumn
05194:             *            Number of relation tag.
05195:             * @param strQueryWhere
05196:             *            Part of SQL query - where clause.
05197:             * @param conn
05198:             *            represents connection to target database
05199:             * @param currentVersion
05200:             *            represents currnet version of insert/update
05201:             * @param oid
05202:             *            define if oid logic is present
05203:             * @return String which will be executed for update or insert relation
05204:             *         columns into target tables
05205:             * @throws NullPointerException
05206:             *             Constructs a NullPointerException with the specified detail
05207:             *             message.
05208:             * @throws LoaderException
05209:             */
05210:            private String queryRelations(int iTableInt,
05211:                    int iNumberOfRelationColumn, String strQueryWhere,
05212:                    Connection conn, int currentVersion, boolean oid)
05213:                    throws NullPointerException, LoaderException {
05214:                this .logger
05215:                        .write("full", "\tqueryRelations method is started.");
05216:                String strQueryRelations = "";
05217:                String oidVersion = "";
05218:                String selectValueInRel = "";
05219:                String currentValueInRel = "";
05220:                // if (oid)
05221:                // oidVersion = ", version=" + currentVersion;
05222:                if (oid)
05223:                    oidVersion = ", " + this .currentVersionColumnName + "="
05224:                            + currentVersion;
05225:
05226:                try {
05227:                    strQueryRelations = "update "
05228:                            + this .vecRelationColumnTargetTableName.get(
05229:                                    iNumberOfRelationColumn).toString()
05230:                            + " set "
05231:                            + this .vecRelationColumnTargetColumnName.get(
05232:                                    iNumberOfRelationColumn).toString();
05233:                    if (this .vecRelationSourceValue
05234:                            .get(iNumberOfRelationColumn) == null) {
05235:                        String replacementValueInRel = vecDefaultRelationValue
05236:                                .get(iNumberOfRelationColumn).toString();
05237:                        if (!replacementValueInRel.equalsIgnoreCase("")) {
05238:                            try {
05239:                                Statement stmt = conn.createStatement();
05240:                                ResultSet newRelationValue;
05241:                                String relationValue;
05242:                                boolean isFull = false;
05243:                                if (!replacementValueInRel
05244:                                        .equalsIgnoreCase(selectValueInRel)) {
05245:                                    selectValueInRel = replacementValueInRel;
05246:                                    newRelationValue = stmt
05247:                                            .executeQuery(replacementValueInRel);
05248:                                    isFull = newRelationValue.next();
05249:                                    if (isFull) {
05250:                                        relationValue = newRelationValue
05251:                                                .getString(1);
05252:                                        currentValueInRel = relationValue;
05253:                                    } else {
05254:                                        relationValue = "";
05255:                                        currentValueInRel = "";
05256:                                    }
05257:                                    newRelationValue.close();
05258:                                } else {
05259:                                    if (!currentValueInRel.equalsIgnoreCase("")
05260:                                            && currentValueInRel != null) {
05261:                                        relationValue = currentValueInRel;
05262:                                        isFull = true;
05263:                                    } else {
05264:                                        relationValue = "";
05265:                                    }
05266:                                }
05267:                                if (isFull) {
05268:                                    strQueryRelations += dataCleaning
05269:                                            .cleaningRelationValues(
05270:                                                    this .vecTableTableName.get(
05271:                                                            iTableInt)
05272:                                                            .toString(),
05273:                                                    this .vecRelationColumnTargetColumnName
05274:                                                            .get(
05275:                                                                    iNumberOfRelationColumn)
05276:                                                            .toString(),
05277:                                                    relationValue,
05278:                                                    this .vecRelationSourceType
05279:                                                            .get(
05280:                                                                    iNumberOfRelationColumn)
05281:                                                            .toString(),
05282:                                                    currentRow,
05283:                                                    conn,
05284:                                                    "UPDATE",
05285:                                                    currentVersion,
05286:                                                    oid,
05287:                                                    importDefinitionElement.strImportDefinitionName,
05288:                                                    this .currentVersionColumnName,
05289:                                                    replacementValueInRel);
05290:
05291:                                } else {
05292:                                    dataCleaning
05293:                                            .cleaningInsert(
05294:                                                    this .vecTableTableName.get(
05295:                                                            iTableInt)
05296:                                                            .toString(),
05297:                                                    conn,
05298:                                                    currentRow,
05299:                                                    "UPDATE",
05300:                                                    "Default value '"
05301:                                                            + replacementValueInRel
05302:                                                            + "' for relations is not valid.",
05303:                                                    importDefinitionElement.strImportDefinitionName,
05304:                                                    replacementValueInRel);
05305:                                    strQueryRelations += " = null "
05306:                                            + oidVersion + " where ";
05307:                                }
05308:                            } catch (SQLException ex) {
05309:                                String msg = "Default value for foreign key("
05310:                                        + replacementValueInRel
05311:                                        + ") is not valid. Import definition name: "
05312:                                        + importDefinitionElement.strImportDefinitionName;
05313:                                LoaderException le = new LoaderException(
05314:                                        "SQLException: " + msg, (Throwable) ex);
05315:                                this .logger.write("full", le
05316:                                        .getStackTraceAsString());
05317:                                throw le;
05318:                            }
05319:
05320:                        } else
05321:                            strQueryRelations += " = null " + oidVersion
05322:                                    + " where ";
05323:                    } else {
05324:                        // TODO Check this part of code. ZK change from
05325:                        // configReaderSource to configReaderTarget because of problems
05326:                        // with relation columns.
05327:                        if (configReaderTarget
05328:                                .isNumber(this .vecRelationSourceType.get(
05329:                                        iNumberOfRelationColumn).toString())) {
05330:                            strQueryRelations += " = "
05331:                                    + this .vecRelationSourceValue.get(
05332:                                            iNumberOfRelationColumn).toString()
05333:                                    + oidVersion + " where ";
05334:                        } else {
05335:                            strQueryRelations += " = ";
05336:                            if (configReaderTarget
05337:                                    .isWithN(this .vecRelationSourceType.get(
05338:                                            iNumberOfRelationColumn).toString())) {
05339:                                strQueryRelations += "N";
05340:                            }
05341:                            strQueryRelations += "'"
05342:                                    + this .vecRelationSourceValue.get(
05343:                                            iNumberOfRelationColumn).toString()
05344:                                    + "'" + oidVersion + " where ";
05345:                        }
05346:
05347:                    }
05348:                    strQueryRelations += strQueryWhere;
05349:                    if (strQueryRelations.trim().endsWith("where"))
05350:                        strQueryRelations = strQueryRelations.substring(0,
05351:                                strQueryRelations.length() - 6);
05352:                    else {
05353:                        if (!this .vecRelationColumnRelationMode.get(
05354:                                iNumberOfRelationColumn).toString()
05355:                                .equalsIgnoreCase("overwrite")) {
05356:                            // ||
05357:                            // !this.vecRelationColumnRelationMode.get(iNumberOfRelationColumn).toString().
05358:                            // equalsIgnoreCase("SetIfCreated")) {
05359:
05360:                            strQueryRelations += " and "
05361:                                    + this .vecRelationColumnTargetColumnName
05362:                                            .get(iNumberOfRelationColumn)
05363:                                            .toString() + " is null";
05364:                        }
05365:                    }
05366:                } catch (NullPointerException ex) {
05367:                    throw ex;
05368:                }
05369:                this .logger.write("full",
05370:                        "\tqueryRelations method is finished.");
05371:                return strQueryRelations;
05372:            }
05373:
05374:            /**
05375:             * Method insertTargetTable is used to put one row of data from columns of
05376:             * source tables into target table ordered by column modes. If there is an
05377:             * error, Exception "SQLException, "NullPointerException" or "Exception" is
05378:             * thrown.
05379:             * 
05380:             * @param iTableInt
05381:             *            Number of the target table which is processed.
05382:             * @param vecColumnValues
05383:             *            One row of values from the source table.
05384:             * @param vecColumnNames
05385:             *            Vector of column names in a target table.
05386:             * @param vecColumnMode
05387:             *            Modes of columns in the target table.
05388:             * @param vecColumnTypes
05389:             *            Types of columns in the target table.
05390:             * @param c
05391:             *            Connection to the target database.
05392:             * @throws SQLException
05393:             *             Constructs an SQLException object with a reason.
05394:             * @throws NullPointerException
05395:             *             Constructs a NullPointerException with the specified detail
05396:             *             message.
05397:             * @throws Exception
05398:             *             Constructs an Exception with the specified detail message.
05399:             */
05400:            private void insertTargetTable(int iTableInt,
05401:                    Vector vecColumnValues, Vector vecColumnNames,
05402:                    Vector vecColumnMode, Vector vecColumnTypes, Connection c,
05403:                    Vector vecTransformationValue, Vector transTargetColumnTypes)
05404:                    throws SQLException, NullPointerException, Exception {
05405:
05406:                this .logger.write("full",
05407:                        "\tinsertTargetTable method is started.");
05408:                boolean bInsertTable = false;
05409:                int iVersionValue = 0;
05410:                int iVersionMax = 0;
05411:                boolean bWriteData = false;
05412:                String strQueryWhere = "";
05413:                String strQuery = new String("select ");
05414:                // for handling exception in FK (data cleanining)
05415:                String exceptionInRelations = "";
05416:                String replacementValueInRel = "";
05417:                String replacementTable = "";
05418:                String replacementColumn = "";
05419:                // String replacementColumnType = "";
05420:                boolean relationIsOk = false;
05421:                boolean updateQueryIsOk = false;
05422:                boolean updateConstantIsOk = false;
05423:                String strQueryConstantApendix = "";
05424:
05425:                boolean bOidLogicCurrentTable = new Boolean(
05426:                        this .vecTableOidLogic.get(iTableInt).toString())
05427:                        .booleanValue();
05428:                boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
05429:                        .equals("") || importDefinitionElement.strObjectIDNameColumnValue
05430:                        .equals(""));
05431:                boolean oid = false;
05432:                if (bOidLogicCurrentTable && !isTOS)
05433:                    oid = true;
05434:
05435:                Vector vecTempKeyColumns = (Vector) this .vecTargetKeyColumnName
05436:                        .get(iTableInt);
05437:
05438:                String key = String.valueOf(iTableInt);
05439:                String query = (String) queryStatement.get(key);
05440:                // System.out.println("query="+query);
05441:                String update = (String) updateStatement.get(key);
05442:                String updateConstant = (String) updateConstantStatement
05443:                        .get(key);
05444:
05445:                String updateTransformation = (String) updateTransformationStatement
05446:                        .get(key);
05447:
05448:                // updateTransformation =
05449:                // (String)this.updateTransformationStatement.get(key);
05450:                Statement stmtTarget = null;
05451:                // ZK added this. If (select something from ... )is valid (contains oid,
05452:                // version and more) then do insert
05453:                // String query1 = (String)queryStatement.get(key);
05454:                // System.out.println("query="+query);
05455:                // boolean isValidStmt = validStmt.checkStatement(query);
05456:                // System.out.println("isValidStmt="+isValidStmt);
05457:                String logStatement = "";
05458:                try {
05459:                    // if (isValidStmt){
05460:                    if (query.indexOf(" where ") == -1) {
05461:                        this .insertRow(c, vecColumnValues, vecColumnTypes,
05462:                                vecColumnNames, vecColumnMode,
05463:                                bOidLogicCurrentTable, iTableInt,
05464:                                vecTransformationValue, transTargetColumnTypes);
05465:                        bInsertTable = true;
05466:                    } else {
05467:                        Vector dv = (Vector) indexDValue.get(key);
05468:                        Vector drv = (Vector) indexDRelationValue.get(key);
05469:                        Vector dcv = (Vector) indexConstantDValue.get(key);
05470:                        Vector dvv = (Vector) indexDVariableValue.get(key);
05471:                        Vector dtv = (Vector) indexDTransformationValue
05472:                                .get(key);
05473:
05474:                        if (dv.size() > 0) {
05475:                            for (int i = 0; i < dv.size(); i++) {
05476:                                int index = Integer.parseInt(dv.get(i)
05477:                                        .toString());
05478:                                if (vecColumnValues.get(index) == null) {
05479:                                    int str = query.indexOf("'dummyValue'");
05480:                                    int num = query.indexOf("dummyValue");
05481:                                    if (str != -1 && (num == -1 || str < num))
05482:                                        query = replaceFirst(query,
05483:                                                "= 'dummyValue'", " is null ");
05484:                                    else
05485:                                        query = replaceFirst(query,
05486:                                                "= dummyValue", " is null ");
05487:                                } else {
05488:                                    query = replaceFirst(query, "dummyValue",
05489:                                            vecColumnValues.get(index)
05490:                                                    .toString());
05491:                                }
05492:                            }
05493:                        }
05494:                        if (drv.size() > 0) {
05495:                            for (int i = 0; i < drv.size(); i++) {
05496:                                int index = Integer.parseInt(drv.get(i)
05497:                                        .toString());
05498:                                int str = query.indexOf("'dummyRelationValue'");
05499:                                int num = query.indexOf("dummyRelationValue");
05500:                                if ((this .vecRelationSourceValue.get(index) == null)
05501:                                        || (this .vecRelationSourceValue.get(
05502:                                                index).toString() == "null")) {
05503:                                    //  int str = query.indexOf("'dummyRelationValue'");
05504:                                    //  int num = query.indexOf("dummyRelationValue");
05505:                                    if (str != -1 && (num == -1 || str < num))
05506:                                        query = replaceFirst(query,
05507:                                                "= 'dummyRelationValue'",
05508:                                                " is null ");
05509:                                    else
05510:                                        query = replaceFirst(query,
05511:                                                "= dummyRelationValue",
05512:                                                " is null ");
05513:                                } else {
05514:                                    //query = replaceFirst(query, "dummyRelationValue",
05515:                                    //         this.vecRelationSourceValue.get(index)
05516:                                    //                 .toString());
05517:                                    //  senka change 
05518:                                    String relValues = this .vecRelationSourceValue
05519:                                            .get(index).toString();
05520:                                    if (relValues.startsWith(" IN")) {
05521:                                        if (str != -1
05522:                                                && (num == -1 || str < num))
05523:                                            query = replaceFirst(query,
05524:                                                    "= 'dummyRelationValue'",
05525:                                                    relValues);
05526:                                        else
05527:                                            query = replaceFirst(query,
05528:                                                    "= dummyRelationValue",
05529:                                                    relValues);
05530:                                    } else {
05531:                                        query = replaceFirst(query,
05532:                                                "dummyRelationValue", relValues);
05533:                                    }
05534:                                }
05535:                            }
05536:                        }
05537:
05538:                        Vector vecTempConstantColumns = (Vector) this .vecConstantTargetColumnName
05539:                                .get(iTableInt);
05540:                        Vector vecTempConstantValues = (Vector) this .vecConstantConstantValue
05541:                                .get(iTableInt);
05542:                        Vector vecTempConstantMode = (Vector) this .vecConstantValueMode
05543:                                .get(iTableInt);
05544:                        Vector vecTempConstantType = (Vector) this .vecConstantColumnType
05545:                                .get(iTableInt);
05546:                        // ZK added 19.4.2004
05547:
05548:                        // Vector vecTempTransformationValues = (Vector)
05549:                        // vecTransformationValue.get(iTableInt);
05550:
05551:                        if (dcv.size() > 0) {
05552:                            for (int i = 0; i < dcv.size(); i++) {
05553:                                int index = Integer.parseInt(dcv.get(i)
05554:                                        .toString());
05555:                                if (vecTempConstantValues.get(index) == null) {
05556:                                    int str = query
05557:                                            .indexOf("'dummyConstantValue'");
05558:                                    int num = query
05559:                                            .indexOf("dummyConstantValue");
05560:                                    if (str != -1 && (num == -1 || str < num))
05561:                                        query = replaceFirst(query,
05562:                                                "= 'dummyConstantValue'",
05563:                                                " is null ");
05564:                                    else
05565:                                        query = replaceFirst(query,
05566:                                                "= dummyConstantValue",
05567:                                                " is null ");
05568:                                } else {
05569:                                    query = replaceFirst(query,
05570:                                            "dummyConstantValue",
05571:                                            vecTempConstantValues.get(index)
05572:                                                    .toString());
05573:                                }
05574:                            }
05575:                        }
05576:
05577:                        if (dvv.size() > 0) {
05578:                            for (int i = 0; i < dvv.size(); i++) {
05579:                                int index = Integer.parseInt(dvv.get(i)
05580:                                        .toString());
05581:                                if (vecVariableValue.get(index) == null) {
05582:                                    int str = query
05583:                                            .indexOf("'dummyVariableValue'");
05584:                                    int num = query
05585:                                            .indexOf("dummyVariableValue");
05586:                                    if (str != -1 && (num == -1 || str < num))
05587:                                        query = replaceFirst(query,
05588:                                                "= 'dummyVariableValue'",
05589:                                                " is null ");
05590:                                    else
05591:                                        query = replaceFirst(query,
05592:                                                "= dummyVariableValue",
05593:                                                " is null ");
05594:                                } else {
05595:                                    query = replaceFirst(query,
05596:                                            "dummyVariableValue",
05597:                                            vecVariableValue.get(index)
05598:                                                    .toString());
05599:                                }
05600:                            }
05601:                        }
05602:                        // ZK added this for transformation. Key colona.
05603:                        if (dtv.size() > 0) {
05604:                            for (int i = 0; i < dtv.size(); i++) {
05605:                                int index = Integer.parseInt(dtv.get(i)
05606:                                        .toString());
05607:                                if (vecTransformationValue.get(index) == null) {
05608:                                    int str = query
05609:                                            .indexOf("'dummyTransformationValue'");
05610:                                    int num = query
05611:                                            .indexOf("dummyTransformationValue");
05612:                                    if (str != -1 && (num == -1 || str < num))
05613:                                        query = replaceFirst(query,
05614:                                                "= 'dummyTransformationValue'",
05615:                                                " is null ");
05616:                                    else
05617:                                        query = replaceFirst(query,
05618:                                                "= dummyTransformationValue",
05619:                                                " is null ");
05620:                                } else {
05621:                                    query = replaceFirst(query,
05622:                                            "dummyTransformationValue",
05623:                                            vecTransformationValue.get(index)
05624:                                                    .toString());
05625:                                }
05626:                            }
05627:                        }
05628:                        // ZK end
05629:                        if (query.indexOf("where") != -1)
05630:                            strQueryWhere = query.substring(query
05631:                                    .indexOf("where") + 5);
05632:
05633:                        stmtTarget = c.createStatement();
05634:                        boolean rowExist;
05635:                        if (bOidLogicCurrentTable && !isTOS)
05636:                            rowExist = this .checkRowCache.getCheckRowValue(
05637:                                    query, c, this .iTargetFirstColumnResult,
05638:                                    this .currentVersionColumnName);
05639:                        else
05640:                            rowExist = this .checkRowCache.getCheckRowValue(
05641:                                    query, c, this .iTargetFirstColumnResult,
05642:                                    null);
05643:
05644:                        if (!rowExist) {
05645:                            this .insertRow(c, vecColumnValues, vecColumnTypes,
05646:                                    vecColumnNames, vecColumnMode,
05647:                                    bOidLogicCurrentTable, iTableInt,
05648:                                    vecTransformationValue,
05649:                                    transTargetColumnTypes);
05650:                            bInsertTable = true;
05651:                        } else { // row exist = true
05652:                            if (bOidLogicCurrentTable && !isTOS) {
05653:                                iVersionValue = this .checkRowCache
05654:                                        .getCheckRowVersionValue();
05655:                                if (iVersionValue > iVersionMax)
05656:                                    iVersionMax = iVersionValue;
05657:                            }
05658:                            if (!bInsertTable) {
05659:                                Vector dOverwrite = (Vector) indexDOverwrite
05660:                                        .get(key);
05661:                                Vector dSetNull = (Vector) indexDSetNull
05662:                                        .get(key);
05663:
05664:                                if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
05665:                                        .indexOf("UPDATE") != -1)) {
05666:                                    if (dOverwrite.size() > 0) {
05667:                                        int start = 0;
05668:                                        for (int i = 0; i < dOverwrite.size(); i++) {
05669:                                            Vector replacedValue = (Vector) vecDefaultValue
05670:                                                    .get(iTableInt);
05671:                                            int index = Integer
05672:                                                    .parseInt(dOverwrite.get(i)
05673:                                                            .toString());
05674:                                            if (vecColumnValues.get(index) == null) {
05675:                                                int str = update
05676:                                                        .indexOf("'dummyOverwrite'");
05677:                                                int num = update
05678:                                                        .indexOf("dummyOverwrite");
05679:                                                if (replacedValue.get(index) != "") {
05680:                                                    if (str != -1
05681:                                                            && (num == -1 || str < num))
05682:                                                        update = replaceFirst(
05683:                                                                update,
05684:                                                                "'dummyOverwrite'",
05685:                                                                " '"
05686:                                                                        + replacedValue
05687:                                                                                .get(
05688:                                                                                        index)
05689:                                                                                .toString()
05690:                                                                        + "' ");
05691:                                                    else
05692:                                                        update = replaceFirst(
05693:                                                                update,
05694:                                                                "dummyOverwrite",
05695:                                                                " "
05696:                                                                        + replacedValue
05697:                                                                                .get(
05698:                                                                                        index)
05699:                                                                                .toString()
05700:                                                                        + " ");
05701:
05702:                                                    dataCleaning
05703:                                                            .cleaningColumnValues(
05704:                                                                    this .vecTableTableName
05705:                                                                            .get(
05706:                                                                                    iTableInt)
05707:                                                                            .toString(),
05708:                                                                    vecColumnNames
05709:                                                                            .get(
05710:                                                                                    index)
05711:                                                                            .toString(),
05712:                                                                    replacedValue
05713:                                                                            .get(
05714:                                                                                    index)
05715:                                                                            .toString(),
05716:                                                                    currentRow,
05717:                                                                    c,
05718:                                                                    "UPDATE",
05719:                                                                    importDefinitionElement.strImportDefinitionName);
05720:                                                } else {
05721:                                                    if (str != -1
05722:                                                            && (num == -1 || str < num)) {
05723:                                                        String forReplace = "'dummyOverwrite'";
05724:                                                        // patch from mail list
05725:                                                        // int thisIndex =
05726:                                                        // update.indexOf("N'dummyOverwrite'");
05727:                                                        // if (thisIndex != -1 &&
05728:                                                        // thisIndex < str)
05729:                                                        if (update
05730:                                                                .indexOf("N'dummyOverwrite'") != -1)
05731:                                                            forReplace = "N'dummyOverwrite'";
05732:                                                        update = replaceFirst(
05733:                                                                update,
05734:                                                                forReplace,
05735:                                                                " null ");
05736:                                                    } else {
05737:                                                        update = replaceFirst(
05738:                                                                update,
05739:                                                                "dummyOverwrite",
05740:                                                                " null ");
05741:                                                    }
05742:                                                }
05743:                                            } else {
05744:                                                String replacement = vecColumnValues
05745:                                                        .get(index).toString();
05746:                                                start = update
05747:                                                        .indexOf(
05748:                                                                "dummyOverwrite",
05749:                                                                start);
05750:                                                update = update.substring(0,
05751:                                                        start)
05752:                                                        + replacement
05753:                                                        + update
05754:                                                                .substring(start + 14);
05755:                                                start = replacement.length();
05756:                                            }
05757:                                        }
05758:                                    }
05759:                                    if (dSetNull.size() > 0) {
05760:                                        for (int j = 0; j < dSetNull.size(); j++) {
05761:                                            int index = Integer
05762:                                                    .parseInt(dSetNull.get(j)
05763:                                                            .toString());
05764:                                            if (vecColumnValues.get(index) == null) {
05765:                                                update = replaceFirst(update,
05766:                                                        "dummySetNull",
05767:                                                        vecColumnNames.get(
05768:                                                                index)
05769:                                                                .toString()
05770:                                                                + "="
05771:                                                                + " null ");
05772:                                            } else {
05773:                                                update = replaceFirst(update,
05774:                                                        "dummySetNull,", "");
05775:                                            }
05776:                                        }
05777:                                    }
05778:                                    if (dOverwrite.size() > 0
05779:                                            || dSetNull.size() > 0) {
05780:                                        if (bWriteData)
05781:                                            update = replaceFirst(update,
05782:                                                    "dummyVersionOverwrite",
05783:                                                    String.valueOf(iVersionMax));
05784:                                        else
05785:                                            update = replaceFirst(
05786:                                                    update,
05787:                                                    "dummyVersionOverwrite",
05788:                                                    String
05789:                                                            .valueOf(iVersionMax + 1));
05790:                                        if (bReplaceInData) {
05791:                                            update = this .replaceInData(update);
05792:                                            strQueryWhere = this 
05793:                                                    .replaceInData(strQueryWhere);
05794:                                        }
05795:                                        relationIsOk = true;
05796:                                        updateConstantIsOk = true;
05797:                                        updateQueryIsOk = false;
05798:                                        int iNumRowUp = 0;
05799:                                        // int ver = update.indexOf("version");
05800:                                        int ver = update
05801:                                                .indexOf(this .currentVersionColumnName);
05802:                                        int equals = update.indexOf("=");
05803:                                        try {
05804:                                            if (equals != ver + 8) { // update set
05805:                                                // version=1
05806:                                                // where x=x
05807:                                                this .logger
05808:                                                        .write(
05809:                                                                "full",
05810:                                                                "\tQuery '"
05811:                                                                        + update
05812:                                                                        + strQueryWhere
05813:                                                                        + "' will be executed");
05814:                                                logStatement = update
05815:                                                        + strQueryWhere;
05816:                                                iNumRowUp = stmtTarget
05817:                                                        .executeUpdate(update
05818:                                                                + strQueryWhere);
05819:                                            }
05820:                                            if (iNumRowUp != 0) {
05821:                                                if (!bWriteData)
05822:                                                    iVersionMax = iVersionMax + 1;
05823:                                                bWriteData = true;
05824:                                            }
05825:                                            String tableName = this .vecTableTableName
05826:                                                    .get(iTableInt).toString();
05827:                                            for (int i = 0; i < this .vecBlobVector
05828:                                                    .size(); i = i + 5) {
05829:                                                if (!this .vecBlobVector.get(
05830:                                                        i + 3).toString()
05831:                                                        .equalsIgnoreCase(
05832:                                                                "update")) {
05833:                                                    String version = "";
05834:                                                    if (oid) {
05835:                                                        if (bWriteData) {
05836:                                                            // version += ", version = "
05837:                                                            // + iVersionMax;
05838:                                                            version += ", "
05839:                                                                    + this .currentVersionColumnName
05840:                                                                    + " = "
05841:                                                                    + iVersionMax;
05842:                                                        } else {
05843:                                                            // version += ", version = "
05844:                                                            // + (iVersionMax + 1);
05845:                                                            version += ", "
05846:                                                                    + this .currentVersionColumnName
05847:                                                                    + "= "
05848:                                                                    + (iVersionMax + 1);
05849:                                                        }
05850:                                                    }
05851:                                                    String columnName = this .vecBlobVector
05852:                                                            .get(i).toString();
05853:                                                    byte[] isBlob = (byte[]) this .vecBlobVector
05854:                                                            .get(i + 1);
05855:                                                    if (isBlob != null) {
05856:                                                        ByteArrayInputStream bais = new ByteArrayInputStream(
05857:                                                                isBlob);
05858:                                                        logStatement = "update "
05859:                                                                + tableName
05860:                                                                + " set "
05861:                                                                + columnName
05862:                                                                + "=(?)"
05863:                                                                + version
05864:                                                                + " where "
05865:                                                                + columnName
05866:                                                                + " is null";
05867:                                                        PreparedStatement pstmt = c
05868:                                                                .prepareStatement("update "
05869:                                                                        + tableName
05870:                                                                        + " set "
05871:                                                                        + columnName
05872:                                                                        + "=(?)"
05873:                                                                        + version
05874:                                                                        + " where "
05875:                                                                        + columnName
05876:                                                                        + " is null");
05877:                                                        pstmt.setBytes(1,
05878:                                                                isBlob);
05879:                                                        int intRowStmt = pstmt
05880:                                                                .executeUpdate();
05881:                                                        pstmt.close();
05882:                                                        if (intRowStmt != 0) {
05883:                                                            if (!bWriteData)
05884:                                                                iVersionMax = iVersionMax + 1;
05885:                                                            bWriteData = true;
05886:                                                        }
05887:                                                    }
05888:                                                }
05889:                                            }
05890:                                        } catch (SQLException ex) {
05891:                                            stmtTarget.close();
05892:                                            stmtTarget = c.createStatement();
05893:
05894:                                            if ((importDefinitionElement.strDefaultCutOffData
05895:                                                    .equalsIgnoreCase("true"))) {
05896:                                                dataCleaning
05897:                                                        .cutingDataLenghtUpdate(
05898:                                                                this .vecTableTableName
05899:                                                                        .get(
05900:                                                                                iTableInt)
05901:                                                                        .toString(),
05902:                                                                c,
05903:                                                                strQueryWhere,
05904:                                                                currentRow,
05905:                                                                update,
05906:                                                                importDefinitionElement.strOnErrorContinueXml,
05907:                                                                importDefinitionElement.strImportDefinitionName,
05908:                                                                update
05909:                                                                        + strQueryWhere);
05910:                                            } else
05911:
05912:                                                throw ex;
05913:                                        }
05914:                                    }
05915:                                    for (int j = 0; j < vecColumnNames.size(); j++) {
05916:                                        if (vecColumnMode.get(j).toString()
05917:                                                .equalsIgnoreCase("Update")) {
05918:                                            // String javaType =
05919:                                            // configReaderTarget.getJavaTypeMapings()
05920:                                            // .get(vecColumnTypes.get(j).toString().toUpperCase()).toString();
05921:                                            // ZK change this 7.5.2004 from CheckType to
05922:                                            // configReaderSource
05923:                                            if (configReaderTarget
05924:                                                    .isBinaryObject(vecColumnTypes
05925:                                                            .get(j).toString())) {
05926:                                                // int
05927:                                                // javaTypeInt=Integer.parseInt(javaType);
05928:                                                // if (javaTypeInt==1) {
05929:                                                for (int i = 0; i < vecBlobVector
05930:                                                        .size(); i = i + 5) {
05931:                                                    if (vecBlobVector
05932:                                                            .get(i + 3)
05933:                                                            .toString()
05934:                                                            .equalsIgnoreCase(
05935:                                                                    "update")) {
05936:                                                        if (vecBlobVector
05937:                                                                .get(i)
05938:                                                                .toString()
05939:                                                                .equalsIgnoreCase(
05940:                                                                        vecColumnNames
05941:                                                                                .get(
05942:                                                                                        j)
05943:                                                                                .toString())) {
05944:                                                            String version = "";
05945:                                                            if (oid) {
05946:                                                                if (bWriteData) {
05947:                                                                    // version += ",
05948:                                                                    // version = " +
05949:                                                                    // (iVersionMax);
05950:                                                                    version += ", "
05951:                                                                            + this .currentVersionColumnName
05952:                                                                            + " = "
05953:                                                                            + (iVersionMax);
05954:                                                                } else {
05955:                                                                    // version += ",
05956:                                                                    // version = " +
05957:                                                                    // (iVersionMax +
05958:                                                                    // 1);
05959:                                                                    version += ", "
05960:                                                                            + this .currentVersionColumnName
05961:                                                                            + " = "
05962:                                                                            + (iVersionMax + 1);
05963:                                                                }
05964:                                                            }
05965:                                                            String tableName = this .vecTableTableName
05966:                                                                    .get(
05967:                                                                            iTableInt)
05968:                                                                    .toString();
05969:                                                            String columnName = this .vecBlobVector
05970:                                                                    .get(i)
05971:                                                                    .toString();
05972:                                                            byte[] isBlob = (byte[]) this .vecBlobVector
05973:                                                                    .get(i + 1);
05974:                                                            String condition = this .vecBlobVector
05975:                                                                    .get(i + 2)
05976:                                                                    .toString();
05977:                                                            if (isBlob != null) {
05978:                                                                ByteArrayInputStream bais = new ByteArrayInputStream(
05979:                                                                        isBlob);
05980:                                                                PreparedStatement pstmt = c
05981:                                                                        .prepareStatement("update "
05982:                                                                                + tableName
05983:                                                                                + " set "
05984:                                                                                + columnName
05985:                                                                                + "=(?)"
05986:                                                                                + version
05987:                                                                                + condition
05988:                                                                                + strQueryWhere);
05989:                                                                pstmt.setBytes(
05990:                                                                        1,
05991:                                                                        isBlob);
05992:                                                                this .logger
05993:                                                                        .write(
05994:                                                                                "full",
05995:                                                                                "\tQuery '"
05996:                                                                                        + "update "
05997:                                                                                        + tableName
05998:                                                                                        + " set "
05999:                                                                                        + columnName
06000:                                                                                        + "=BlobObject"
06001:                                                                                        + version
06002:                                                                                        + condition
06003:                                                                                        + " where "
06004:                                                                                        + strQueryWhere
06005:                                                                                        + "' will be executed");
06006:                                                                int intRowStmt = 0;
06007:                                                                logStatement = "update "
06008:                                                                        + tableName
06009:                                                                        + " set "
06010:                                                                        + columnName
06011:                                                                        + "=BlobObject"
06012:                                                                        + version
06013:                                                                        + condition
06014:                                                                        + " where "
06015:                                                                        + strQueryWhere;
06016:                                                                intRowStmt = pstmt
06017:                                                                        .executeUpdate();
06018:                                                                pstmt.close();
06019:                                                                if (intRowStmt != 0) {
06020:                                                                    if (!bWriteData)
06021:                                                                        iVersionMax = iVersionMax + 1;
06022:                                                                    bWriteData = true;
06023:                                                                }
06024:                                                            }
06025:                                                        }
06026:                                                    }
06027:                                                } // for petlja za blob
06028:                                            } else {
06029:                                                String strQueryUpdate = "update "
06030:                                                        + this .vecTableTableName
06031:                                                                .get(iTableInt)
06032:                                                                .toString()
06033:                                                        + " set ";
06034:                                                strQueryUpdate += vecColumnNames
06035:                                                        .get(j).toString()
06036:                                                        + "=";
06037:                                                if (vecColumnValues.get(j) == null)
06038:                                                    strQueryUpdate += " null ";
06039:                                                else {
06040:                                                    // ZK change this from CheckType to
06041:                                                    // configReaderTarget this 7.5.2004
06042:                                                    if (!configReaderTarget
06043:                                                            .isNumber(vecColumnTypes
06044:                                                                    .get(j)
06045:                                                                    .toString()))
06046:                                                        strQueryUpdate += "'"
06047:                                                                + vecColumnValues
06048:                                                                        .get(j)
06049:                                                                        .toString()
06050:                                                                + "' ";
06051:                                                    else
06052:                                                        strQueryUpdate += vecColumnValues
06053:                                                                .get(j)
06054:                                                                .toString()
06055:                                                                + " ";
06056:                                                }
06057:                                                if (oid) {
06058:                                                    if (bWriteData) {
06059:                                                        // strQueryUpdate += ", version
06060:                                                        // = " + (iVersionMax) + " where
06061:                                                        // ";
06062:                                                        strQueryUpdate += ", "
06063:                                                                + this .currentVersionColumnName
06064:                                                                + " = "
06065:                                                                + (iVersionMax)
06066:                                                                + " where ";
06067:                                                    } else {
06068:                                                        // strQueryUpdate += ", version
06069:                                                        // = " + (iVersionMax + 1) + "
06070:                                                        // where ";
06071:                                                        strQueryUpdate += ", "
06072:                                                                + this .currentVersionColumnName
06073:                                                                + " = "
06074:                                                                + (iVersionMax + 1)
06075:                                                                + " where ";
06076:                                                    }
06077:                                                } else
06078:                                                    strQueryUpdate += " where ";
06079:                                                strQueryUpdate += vecColumnNames
06080:                                                        .get(j).toString()
06081:                                                        + " is null and ";
06082:                                                if (bReplaceInData) {
06083:                                                    strQueryUpdate = this 
06084:                                                            .replaceInData(strQueryUpdate);
06085:                                                    strQueryWhere = this 
06086:                                                            .replaceInData(strQueryWhere);
06087:                                                }
06088:                                                this .logger
06089:                                                        .write(
06090:                                                                "full",
06091:                                                                "\tQuery '"
06092:                                                                        + strQueryUpdate
06093:                                                                        + strQueryWhere
06094:                                                                        + "' will be executed");
06095:                                                int iNumRow = 0;
06096:                                                try {
06097:                                                    iNumRow = stmtTarget
06098:                                                            .executeUpdate(strQueryUpdate
06099:                                                                    + strQueryWhere);
06100:                                                } catch (SQLException ex) {
06101:                                                    stmtTarget.close();
06102:                                                    stmtTarget = c
06103:                                                            .createStatement();
06104:                                                    if ((importDefinitionElement.strDefaultCutOffData
06105:                                                            .equalsIgnoreCase("true"))) {
06106:                                                        dataCleaning
06107:                                                                .cutingDataLenghtUpdate(
06108:                                                                        this .vecTableTableName
06109:                                                                                .get(
06110:                                                                                        iTableInt)
06111:                                                                                .toString(),
06112:                                                                        c,
06113:                                                                        strQueryWhere,
06114:                                                                        currentRow,
06115:                                                                        update,
06116:                                                                        importDefinitionElement.strOnErrorContinueXml,
06117:                                                                        importDefinitionElement.strImportDefinitionName,
06118:                                                                        strQueryUpdate
06119:                                                                                + strQueryWhere);
06120:                                                    } else
06121:                                                        throw ex;
06122:                                                }
06123:                                                if (iNumRow != 0) {
06124:                                                    if (!bWriteData)
06125:                                                        iVersionMax = iVersionMax + 1;
06126:                                                    bWriteData = true;
06127:                                                }
06128:                                            }
06129:                                        } // end of main if loop
06130:                                    }
06131:                                }
06132:                                for (int i = 0; i < this .iRelationColumns; i++) {
06133:                                    outLoop: if (this .vecRelationColumnSourceTableName
06134:                                            .get(i).toString()
06135:                                            .equalsIgnoreCase(
06136:                                                    this .vecTableTableName.get(
06137:                                                            iTableInt)
06138:                                                            .toString())
06139:                                            && this .vecRelationColumnSourceTableID
06140:                                                    .get(i)
06141:                                                    .toString()
06142:                                                    .equalsIgnoreCase(
06143:                                                            this .vecTableTableID
06144:                                                                    .get(
06145:                                                                            iTableInt)
06146:                                                                    .toString())) {
06147:                                        for (int m = 0; m < this .vecVariableUseIDTableName
06148:                                                .size(); m++) {
06149:                                            if (this .vecRelationColumnSourceTableName
06150:                                                    .get(i)
06151:                                                    .toString()
06152:                                                    .equalsIgnoreCase(
06153:                                                            this .vecVariableUseIDTableName
06154:                                                                    .get(m)
06155:                                                                    .toString())
06156:                                                    && this .vecRelationColumnSourceTableID
06157:                                                            .get(i)
06158:                                                            .toString()
06159:                                                            .equalsIgnoreCase(
06160:                                                                    this .vecVariableUseIDTableID
06161:                                                                            .get(
06162:                                                                                    m)
06163:                                                                            .toString())) {
06164:                                                String strQueryRelations = "select "
06165:                                                        + this .vecRelationColumnSourceColumnName
06166:                                                                .get(i)
06167:                                                                .toString()
06168:                                                        + " from "
06169:                                                        + this .vecRelationColumnSourceTableName
06170:                                                                .get(i)
06171:                                                                .toString()
06172:                                                        + " where ";
06173:                                                strQueryRelations += vecTempKeyColumns
06174:                                                        .get(0).toString()
06175:                                                        + " = ";
06176:                                                // ZK change this from CheckType to
06177:                                                // configReaderTarget this 7.5.2004
06178:                                                if (!configReaderTarget
06179:                                                        .isNumber(vecColumnTypes
06180:                                                                .get(0)
06181:                                                                .toString()))
06182:                                                    strQueryRelations += "'"
06183:                                                            + this .strUserID
06184:                                                            + "'";
06185:                                                else
06186:                                                    strQueryRelations += this .strUserID;
06187:
06188:                                                if (this .vecTableTableMode.get(
06189:                                                        iTableInt).toString()
06190:                                                        .equalsIgnoreCase(
06191:                                                                "cache")) {
06192:                                                    Object obj = relationsCache
06193:                                                            .getRelationsCacheValue(strQueryRelations);
06194:                                                    if (obj != null) {
06195:                                                        if (!obj
06196:                                                                .toString()
06197:                                                                .equalsIgnoreCase(
06198:                                                                        "#$Together#$")) {
06199:                                                            this .vecRelationSourceValue
06200:                                                                    .setElementAt(
06201:                                                                            obj,
06202:                                                                            i);
06203:                                                            String type = relationsCache
06204:                                                                    .getRelationsCachType(strQueryRelations);
06205:                                                            this .vecRelationSourceType
06206:                                                                    .setElementAt(
06207:                                                                            type,
06208:                                                                            i);
06209:                                                        }
06210:                                                    } else {
06211:                                                        Statement stmtForUserID1 = c
06212:                                                                .createStatement();
06213:                                                        ResultSet rsForUserID1 = null;
06214:                                                        try {
06215:                                                            this .logger
06216:                                                                    .write(
06217:                                                                            "full",
06218:                                                                            "\tQuery '"
06219:                                                                                    + strQueryRelations
06220:                                                                                    + "' will be executed");
06221:                                                            rsForUserID1 = stmtForUserID1
06222:                                                                    .executeQuery(strQueryRelations);
06223:                                                        } catch (SQLException ex) {
06224:                                                            rsForUserID1
06225:                                                                    .close();
06226:                                                            stmtForUserID1
06227:                                                                    .close();
06228:                                                            dataCleaning
06229:                                                                    .cutingDataLenghtUpdate(
06230:                                                                            this .vecTableTableName
06231:                                                                                    .get(
06232:                                                                                            iTableInt)
06233:                                                                                    .toString(),
06234:                                                                            c,
06235:                                                                            strQueryWhere,
06236:                                                                            currentRow,
06237:                                                                            update,
06238:                                                                            importDefinitionElement.strOnErrorContinueXml,
06239:                                                                            importDefinitionElement.strImportDefinitionName,
06240:                                                                            strQueryRelations);
06241:                                                        }
06242:                                                        if (rsForUserID1.next()) {
06243:                                                            if (this .iTargetFirstColumnResult == 1) {
06244:                                                                this .vecRelationSourceValue
06245:                                                                        .setElementAt(
06246:                                                                                rsForUserID1
06247:                                                                                        .getObject(1),
06248:                                                                                i);
06249:                                                                this .vecRelationSourceType
06250:                                                                        .setElementAt(
06251:                                                                                rsForUserID1
06252:                                                                                        .getMetaData()
06253:                                                                                        .getColumnTypeName(
06254:                                                                                                1),
06255:                                                                                i);
06256:                                                                relationsCache
06257:                                                                        .setRelationsCacheValue(
06258:                                                                                strQueryRelations,
06259:                                                                                rsForUserID1
06260:                                                                                        .getObject(1));
06261:                                                                relationsCache
06262:                                                                        .setRelationsCacheType(
06263:                                                                                strQueryRelations,
06264:                                                                                rsForUserID1
06265:                                                                                        .getMetaData()
06266:                                                                                        .getColumnTypeName(
06267:                                                                                                1));
06268:                                                            }
06269:                                                        } else {
06270:                                                            relationsCache
06271:                                                                    .setRelationsCacheValue(
06272:                                                                            strQueryRelations,
06273:                                                                            "#$Together#$");
06274:                                                            relationsCache
06275:                                                                    .setRelationsCacheType(
06276:                                                                            strQueryRelations,
06277:                                                                            "#$Together#$");
06278:                                                        }
06279:                                                        rsForUserID1.close();
06280:                                                        stmtForUserID1.close();
06281:                                                        break outLoop;
06282:                                                    }
06283:                                                } else { // tableMode=Query
06284:                                                    this .logger
06285:                                                            .write(
06286:                                                                    "full",
06287:                                                                    "\tQuery '"
06288:                                                                            + strQueryRelations
06289:                                                                            + "' will be executed");
06290:                                                    Statement stmtForUserID2 = c
06291:                                                            .createStatement();
06292:                                                    ResultSet rsForUserID2 = null;
06293:                                                    try {
06294:                                                        rsForUserID2 = stmtForUserID2
06295:                                                                .executeQuery(strQueryRelations);
06296:                                                    } catch (SQLException ex) {
06297:                                                        rsForUserID2.close();
06298:                                                        stmtForUserID2.close();
06299:                                                        dataCleaning
06300:                                                                .cutingDataLenghtUpdate(
06301:                                                                        this .vecTableTableName
06302:                                                                                .get(
06303:                                                                                        iTableInt)
06304:                                                                                .toString(),
06305:                                                                        c,
06306:                                                                        strQueryWhere,
06307:                                                                        currentRow,
06308:                                                                        update,
06309:                                                                        importDefinitionElement.strOnErrorContinueXml,
06310:                                                                        importDefinitionElement.strImportDefinitionName,
06311:                                                                        strQueryRelations);
06312:
06313:                                                    }
06314:                                                    if (rsForUserID2.next()) {
06315:
06316:                                                        if (this .iTargetFirstColumnResult == 1) {
06317:                                                            this .vecRelationSourceValue
06318:                                                                    .setElementAt(
06319:                                                                            rsForUserID2
06320:                                                                                    .getObject(1),
06321:                                                                            i);
06322:                                                            this .vecRelationSourceType
06323:                                                                    .setElementAt(
06324:                                                                            rsForUserID2
06325:                                                                                    .getMetaData()
06326:                                                                                    .getColumnTypeName(
06327:                                                                                            1),
06328:                                                                            i);
06329:
06330:                                                        } else {
06331:                                                            this .vecRelationSourceValue
06332:                                                                    .setElementAt(
06333:                                                                            rsForUserID2
06334:                                                                                    .getObject(0),
06335:                                                                            i);
06336:                                                            this .vecRelationSourceType
06337:                                                                    .setElementAt(
06338:                                                                            rsForUserID2
06339:                                                                                    .getMetaData()
06340:                                                                                    .getColumnTypeName(
06341:                                                                                            0),
06342:                                                                            i);
06343:                                                        }
06344:                                                    }
06345:                                                    rsForUserID2.close();
06346:                                                    stmtForUserID2.close();
06347:                                                    break outLoop;
06348:                                                }
06349:                                            }
06350:                                        } // end of vecVariableUseIDTableName loop
06351:                                        String strQueryRelations = "select "
06352:                                                + this .vecRelationColumnSourceColumnName
06353:                                                        .get(i).toString()
06354:                                                + " from "
06355:                                                + this .vecRelationColumnSourceTableName
06356:                                                        .get(i).toString()
06357:                                                + " where " + strQueryWhere;
06358:                                        if (this .vecTableTableMode.get(
06359:                                                iTableInt).toString()
06360:                                                .equalsIgnoreCase("cache")) {
06361:                                            Object obj = relationsCache
06362:                                                    .getRelationsCacheValue(strQueryRelations);
06363:                                            if (obj != null) {
06364:                                                if (!obj.toString()
06365:                                                        .equalsIgnoreCase(
06366:                                                                "#$Together#$")) {
06367:                                                    this .vecRelationSourceValue
06368:                                                            .setElementAt(obj,
06369:                                                                    i);
06370:                                                    String type = relationsCache
06371:                                                            .getRelationsCachType(strQueryRelations);
06372:                                                    this .vecRelationSourceType
06373:                                                            .setElementAt(type,
06374:                                                                    i);
06375:                                                }
06376:                                            } else {
06377:                                                Statement stmtForRel1 = c
06378:                                                        .createStatement();
06379:                                                ResultSet rsForRel1 = null;
06380:                                                try {
06381:                                                    this .logger
06382:                                                            .write(
06383:                                                                    "full",
06384:                                                                    "\tQuery '"
06385:                                                                            + strQueryRelations
06386:                                                                            + "' will be executed");
06387:                                                    rsForRel1 = stmtForRel1
06388:                                                            .executeQuery(strQueryRelations);
06389:                                                } catch (SQLException ex) {
06390:                                                    rsForRel1.close();
06391:                                                    stmtForRel1.close();
06392:                                                    dataCleaning
06393:                                                            .cutingDataLenghtUpdate(
06394:                                                                    this .vecTableTableName
06395:                                                                            .get(
06396:                                                                                    iTableInt)
06397:                                                                            .toString(),
06398:                                                                    c,
06399:                                                                    strQueryWhere,
06400:                                                                    currentRow,
06401:                                                                    update,
06402:                                                                    importDefinitionElement.strOnErrorContinueXml,
06403:                                                                    importDefinitionElement.strImportDefinitionName,
06404:                                                                    strQueryRelations);
06405:                                                }
06406:
06407:                                                if (rsForRel1.next()) {
06408:                                                    String relVal = getSQLRelationString(rsForRel1); //senka added
06409:                                                    if (this .iTargetFirstColumnResult == 1) {
06410:                                                        // this.vecRelationSourceValue
06411:                                                        //         .setElementAt(rsForRel1
06412:                                                        //                 .getObject(1),
06413:                                                        //                 i);
06414:                                                        // senka change
06415:                                                        this .vecRelationSourceValue
06416:                                                                .setElementAt(
06417:                                                                        relVal,
06418:                                                                        i);
06419:
06420:                                                        this .vecRelationSourceType
06421:                                                                .setElementAt(
06422:                                                                        rsForRel1
06423:                                                                                .getMetaData()
06424:                                                                                .getColumnTypeName(
06425:                                                                                        1),
06426:                                                                        i);
06427:                                                        //  relationsCache
06428:                                                        //          .setRelationsCacheValue(
06429:                                                        //                  strQueryRelations,
06430:                                                        //                  rsForRel1
06431:                                                        //                          .getObject(1));
06432:                                                        // senka change
06433:                                                        relationsCache
06434:                                                                .setRelationsCacheValue(
06435:                                                                        strQueryRelations,
06436:                                                                        relVal);
06437:                                                        relationsCache
06438:                                                                .setRelationsCacheType(
06439:                                                                        strQueryRelations,
06440:                                                                        rsForRel1
06441:                                                                                .getMetaData()
06442:                                                                                .getColumnTypeName(
06443:                                                                                        1));
06444:                                                    } else {
06445:                                                        // this.vecRelationSourceValue
06446:                                                        //         .setElementAt(rsForRel1
06447:                                                        //                  .getObject(0),
06448:                                                        //                  i);
06449:                                                        // senka change
06450:                                                        this .vecRelationSourceValue
06451:                                                                .setElementAt(
06452:                                                                        relVal,
06453:                                                                        i);
06454:                                                        this .vecRelationSourceType
06455:                                                                .setElementAt(
06456:                                                                        rsForRel1
06457:                                                                                .getMetaData()
06458:                                                                                .getColumnTypeName(
06459:                                                                                        0),
06460:                                                                        i);
06461:                                                        //  relationsCache
06462:                                                        //           .setRelationsCacheValue(
06463:                                                        //                    strQueryRelations,
06464:                                                        //                    rsForRel1
06465:                                                        //                            .getObject(0));
06466:                                                        // senka change
06467:                                                        relationsCache
06468:                                                                .setRelationsCacheValue(
06469:                                                                        strQueryRelations,
06470:                                                                        relVal);
06471:                                                        relationsCache
06472:                                                                .setRelationsCacheType(
06473:                                                                        strQueryRelations,
06474:                                                                        rsForRel1
06475:                                                                                .getMetaData()
06476:                                                                                .getColumnTypeName(
06477:                                                                                        0));
06478:                                                    }
06479:                                                } else {
06480:                                                    relationsCache
06481:                                                            .setRelationsCacheValue(
06482:                                                                    strQueryRelations,
06483:                                                                    "#$Together#$");
06484:                                                    relationsCache
06485:                                                            .setRelationsCacheType(
06486:                                                                    strQueryRelations,
06487:                                                                    "#$Together#$");
06488:                                                }
06489:                                                rsForRel1.close();
06490:                                                stmtForRel1.close();
06491:                                            }
06492:                                        } else { // tableMode=Query
06493:
06494:                                            Statement stmtForRel2 = c
06495:                                                    .createStatement();
06496:                                            ResultSet rsForRel2 = null;
06497:                                            try {
06498:                                                this .logger
06499:                                                        .write(
06500:                                                                "full",
06501:                                                                "\tQuery '"
06502:                                                                        + strQueryRelations
06503:                                                                        + "' will be executed");
06504:                                                rsForRel2 = stmtForRel2
06505:                                                        .executeQuery(strQueryRelations);
06506:                                            } catch (SQLException ex) {
06507:                                                rsForRel2.close();
06508:                                                stmtForRel2.close();
06509:                                                dataCleaning
06510:                                                        .cutingDataLenghtUpdate(
06511:                                                                this .vecTableTableName
06512:                                                                        .get(
06513:                                                                                iTableInt)
06514:                                                                        .toString(),
06515:                                                                c,
06516:                                                                strQueryWhere,
06517:                                                                currentRow,
06518:                                                                update,
06519:                                                                importDefinitionElement.strOnErrorContinueXml,
06520:                                                                importDefinitionElement.strImportDefinitionName,
06521:                                                                strQueryRelations);
06522:                                            }
06523:                                            if (rsForRel2.next()) {
06524:                                                String relVal2 = getSQLRelationString(rsForRel2); //senka added
06525:                                                if (this .iTargetFirstColumnResult == 1) {
06526:                                                    // this.vecRelationSourceValue
06527:                                                    //         .setElementAt(rsForRel2
06528:                                                    //                 .getObject(1), i);
06529:                                                    // senka 	
06530:                                                    this .vecRelationSourceValue
06531:                                                            .setElementAt(
06532:                                                                    relVal2, i);
06533:                                                    this .vecRelationSourceType
06534:                                                            .setElementAt(
06535:                                                                    rsForRel2
06536:                                                                            .getMetaData()
06537:                                                                            .getColumnTypeName(
06538:                                                                                    1),
06539:                                                                    i);
06540:                                                } else {
06541:                                                    //this.vecRelationSourceValue
06542:                                                    //        .setElementAt(rsForRel2
06543:                                                    //                .getObject(0), i);
06544:                                                    //                                        	 senka 	
06545:                                                    this .vecRelationSourceValue
06546:                                                            .setElementAt(
06547:                                                                    relVal2, i);
06548:                                                    this .vecRelationSourceType
06549:                                                            .setElementAt(
06550:                                                                    rsForRel2
06551:                                                                            .getMetaData()
06552:                                                                            .getColumnTypeName(
06553:                                                                                    0),
06554:                                                                    i);
06555:                                                }
06556:                                            }
06557:                                            rsForRel2.close();
06558:                                            stmtForRel2.close();
06559:                                        }
06560:                                    }
06561:                                }
06562:
06563:                                for (int i = 0; i < this .vecRelationColumnTargetColumnName
06564:                                        .size(); i++) {
06565:                                    if (this .vecRelationColumnTargetTableName
06566:                                            .get(i).toString()
06567:                                            .equalsIgnoreCase(
06568:                                                    this .vecTableTableName.get(
06569:                                                            iTableInt)
06570:                                                            .toString())
06571:                                            && this .vecRelationColumnTargetTableID
06572:                                                    .get(i)
06573:                                                    .toString()
06574:                                                    .equalsIgnoreCase(
06575:                                                            this .vecTableTableID
06576:                                                                    .get(
06577:                                                                            iTableInt)
06578:                                                                    .toString())) {
06579:                                        int currentVersion = 0;
06580:                                        if (bWriteData)
06581:                                            currentVersion = iVersionMax;
06582:                                        else
06583:                                            currentVersion = iVersionMax + 1;
06584:
06585:                                        if (this .vecRelationColumnRelationMode
06586:                                                .get(i).toString()
06587:                                                .equalsIgnoreCase("SetNull")) {
06588:                                            if (this .vecRelationSourceValue
06589:                                                    .get(i) == null) {
06590:                                                String strUpdateRelations = this 
06591:                                                        .queryRelations(
06592:                                                                iTableInt, i,
06593:                                                                strQueryWhere,
06594:                                                                c,
06595:                                                                currentVersion,
06596:                                                                oid);
06597:                                                this .logger
06598:                                                        .write(
06599:                                                                "full",
06600:                                                                "\tQuery '"
06601:                                                                        + strUpdateRelations
06602:                                                                        + "' will be executed");
06603:                                                if (bReplaceInData) {
06604:                                                    strUpdateRelations = this 
06605:                                                            .replaceInData(strUpdateRelations);
06606:                                                }
06607:                                                int iNumRow = 0;
06608:                                                logStatement = strUpdateRelations;
06609:                                                iNumRow = stmtTarget
06610:                                                        .executeUpdate(strUpdateRelations);
06611:                                                this .vecRelationSourceValue
06612:                                                        .setElementAt(null, i);
06613:                                                // this.vecRelationSourceType.setElementAt(null,i);
06614:                                                if (iNumRow != 0) {
06615:                                                    if (!bWriteData)
06616:                                                        iVersionMax = iVersionMax + 1;
06617:                                                    bWriteData = true;
06618:                                                }
06619:                                            }
06620:                                        } else if (this .vecRelationColumnRelationMode
06621:                                                .get(i).toString()
06622:                                                .equalsIgnoreCase("Overwrite")
06623:                                                || (this .vecRelationColumnRelationMode
06624:                                                        .get(i).toString()
06625:                                                        .equalsIgnoreCase("Update"))) {
06626:
06627:                                            // for handling exception in FK
06628:                                            replacementValueInRel = vecDefaultRelationValue
06629:                                                    .get(i).toString();
06630:                                            replacementTable = vecRelationColumnTargetTableName
06631:                                                    .get(i).toString();
06632:                                            replacementColumn = vecRelationColumnTargetColumnName
06633:                                                    .get(i).toString();
06634:                                            // replacementColumnType =
06635:                                            // this.vecRelationSourceType.get(i).toString();
06636:                                            String strUpdateRelations = this 
06637:                                                    .queryRelations(iTableInt,
06638:                                                            i, strQueryWhere,
06639:                                                            c, currentVersion,
06640:                                                            oid);
06641:                                            this .logger
06642:                                                    .write(
06643:                                                            "full",
06644:                                                            "\tQuery '"
06645:                                                                    + strUpdateRelations
06646:                                                                    + "' will be executed");
06647:                                            if (bReplaceInData) {
06648:                                                strUpdateRelations = this 
06649:                                                        .replaceInData(strUpdateRelations);
06650:                                            }
06651:                                            // only for catch exceptions in foreign keys
06652:                                            // statement
06653:                                            exceptionInRelations = strUpdateRelations;
06654:                                            updateQueryIsOk = true;
06655:                                            updateConstantIsOk = true;
06656:                                            relationIsOk = false;
06657:                                            int iNumRow = 0;
06658:                                            try {
06659:                                                logStatement = strUpdateRelations;
06660:                                                iNumRow = stmtTarget
06661:                                                        .executeUpdate(strUpdateRelations);
06662:                                                this .vecRelationSourceValue
06663:                                                        .setElementAt(null, i);
06664:                                                // this.vecRelationSourceType.setElementAt(null,i);
06665:                                            } catch (SQLException ex) {
06666:                                                stmtTarget.close();
06667:
06668:                                                stmtTarget = c
06669:                                                        .createStatement();
06670:                                                if ((importDefinitionElement.strDefaultCutOffData
06671:                                                        .equalsIgnoreCase("true"))) {
06672:                                                    dataCleaning
06673:                                                            .cutingDataLenghtUpdate(
06674:                                                                    this .vecTableTableName
06675:                                                                            .get(
06676:                                                                                    iTableInt)
06677:                                                                            .toString(),
06678:                                                                    c,
06679:                                                                    strQueryWhere,
06680:                                                                    currentRow,
06681:                                                                    update,
06682:                                                                    importDefinitionElement.strOnErrorContinueXml,
06683:                                                                    importDefinitionElement.strImportDefinitionName,
06684:                                                                    strUpdateRelations);
06685:                                                } else
06686:                                                    throw ex;
06687:                                            }
06688:                                            if (iNumRow != 0) {
06689:                                                if (!bWriteData)
06690:                                                    iVersionMax = iVersionMax + 1;
06691:                                                bWriteData = true;
06692:                                            }
06693:                                        }
06694:                                    }
06695:                                }
06696:
06697:                                if (this .vecTableInsert.get(iTableInt)
06698:                                        .toString().equalsIgnoreCase("true")) {
06699:                                    if (((update + strQueryWhere)
06700:                                            .indexOf("update") != -1 || (update + strQueryWhere)
06701:                                            .indexOf("UPDATE") != -1)) {
06702:                                        if (vecTempConstantColumns.size() > 0) {
06703:                                            if (updateConstant.indexOf(",") != -1)
06704:                                                updateConstant = updateConstant
06705:                                                        .substring(
06706:                                                                0,
06707:                                                                updateConstant
06708:                                                                        .lastIndexOf(","));
06709:
06710:                                            Vector cOverwrite = (Vector) indexDConstantOver
06711:                                                    .get(key);
06712:                                            Vector cNull = (Vector) indexDConstantNull
06713:                                                    .get(key);
06714:                                            strQueryConstantApendix = "";
06715:                                            if (cOverwrite.size() > 0) {
06716:                                                int startOver = 0;
06717:                                                for (int i = 0; i < cOverwrite
06718:                                                        .size(); i++) {
06719:                                                    int index = Integer
06720:                                                            .parseInt(cOverwrite
06721:                                                                    .get(i)
06722:                                                                    .toString());
06723:                                                    if (vecTempConstantValues
06724:                                                            .get(index) == null) {
06725:                                                        int str = updateConstant
06726:                                                                .indexOf("'dummyConstantOver'");
06727:                                                        int num = updateConstant
06728:                                                                .indexOf("dummyConstantOver");
06729:                                                        if (str != -1
06730:                                                                && (num == -1 || str < num))
06731:                                                            updateConstant = replaceFirst(
06732:                                                                    updateConstant,
06733:                                                                    "'dummyConstantOver'",
06734:                                                                    " null ");
06735:                                                        else
06736:                                                            updateConstant = replaceFirst(
06737:                                                                    updateConstant,
06738:                                                                    "dummyConstantOver",
06739:                                                                    " null ");
06740:                                                    } else {
06741:                                                        String replacement = vecTempConstantValues
06742:                                                                .get(index)
06743:                                                                .toString();
06744:                                                        startOver = updateConstant
06745:                                                                .indexOf(
06746:                                                                        "dummyConstantOver",
06747:                                                                        startOver);
06748:                                                        updateConstant = updateConstant
06749:                                                                .substring(0,
06750:                                                                        startOver)
06751:                                                                + replacement
06752:                                                                + updateConstant
06753:                                                                        .substring(startOver + 17);
06754:                                                        startOver = replacement
06755:                                                                .length();
06756:                                                    }
06757:                                                }
06758:                                            }
06759:                                            if (cNull.size() > 0) {
06760:                                                int startNull = 0;
06761:                                                for (int i = 0; i < cNull
06762:                                                        .size(); i++) {
06763:                                                    int index = Integer
06764:                                                            .parseInt(cNull
06765:                                                                    .get(i)
06766:                                                                    .toString());
06767:                                                    if (vecTempConstantValues
06768:                                                            .get(index) == null) {
06769:                                                        int str = updateConstant
06770:                                                                .indexOf("'dummyConstantNull'");
06771:                                                        int num = updateConstant
06772:                                                                .indexOf("dummyConstantNull");
06773:                                                        if (str != -1
06774:                                                                && (num == -1 || str < num))
06775:                                                            updateConstant = replaceFirst(
06776:                                                                    updateConstant,
06777:                                                                    "'dummyConstantNull'",
06778:                                                                    " null ");
06779:                                                        else
06780:                                                            updateConstant = replaceFirst(
06781:                                                                    updateConstant,
06782:                                                                    "dummyConstantNull",
06783:                                                                    " null ");
06784:
06785:                                                        strQueryConstantApendix += " and "
06786:                                                                + vecTempConstantColumns
06787:                                                                        .get(
06788:                                                                                index)
06789:                                                                        .toString()
06790:                                                                + " is null ";
06791:                                                    } else {
06792:                                                        String replacement = vecTempConstantValues
06793:                                                                .get(index)
06794:                                                                .toString();
06795:                                                        startNull = updateConstant
06796:                                                                .indexOf(
06797:                                                                        "dummyConstantNull",
06798:                                                                        startNull);
06799:                                                        updateConstant = updateConstant
06800:                                                                .substring(0,
06801:                                                                        startNull)
06802:                                                                + replacement
06803:                                                                + updateConstant
06804:                                                                        .substring(startNull + 17);
06805:                                                        startNull = replacement
06806:                                                                .length();
06807:                                                    }
06808:                                                }
06809:                                            }
06810:
06811:                                            if (bReplaceInData) {
06812:                                                // System.out.println("bReplaceInData: "
06813:                                                // + bReplaceInData);
06814:                                                updateConstant = this 
06815:                                                        .replaceInData(updateConstant);
06816:                                                strQueryWhere = this 
06817:                                                        .replaceInData(strQueryWhere);
06818:                                            }
06819:
06820:                                            if (oid) {
06821:                                                if (bWriteData) {
06822:                                                    // updateConstant += ", version = "
06823:                                                    // + (iVersionMax);
06824:                                                    updateConstant += ", "
06825:                                                            + this .currentVersionColumnName
06826:                                                            + " = "
06827:                                                            + (iVersionMax);
06828:                                                } else {
06829:                                                    // updateConstant += ", version = "
06830:                                                    // + (iVersionMax + 1);
06831:                                                    updateConstant += ", "
06832:                                                            + this .currentVersionColumnName
06833:                                                            + " = "
06834:                                                            + (iVersionMax + 1);
06835:                                                }
06836:                                            }
06837:                                            updateQueryIsOk = true;
06838:                                            relationIsOk = true;
06839:                                            updateConstantIsOk = false;
06840:                                            int iNumRow = 0;
06841:                                            try {
06842:                                                if (!updateConstant
06843:                                                        .endsWith(" set ")) {
06844:                                                    this .logger
06845:                                                            .write(
06846:                                                                    "full",
06847:                                                                    "\tQuery '"
06848:                                                                            + updateConstant
06849:                                                                            + " where "
06850:                                                                            + strQueryWhere
06851:                                                                            + strQueryConstantApendix
06852:                                                                            + "' will be executed");
06853:                                                    logStatement = updateConstant
06854:                                                            + " where "
06855:                                                            + strQueryWhere;
06856:                                                    iNumRow = stmtTarget
06857:                                                            .executeUpdate(updateConstant
06858:                                                                    + " where "
06859:                                                                    + strQueryWhere
06860:                                                                    + strQueryConstantApendix);
06861:                                                }
06862:                                            } catch (SQLException ex) {
06863:                                                stmtTarget.close();
06864:
06865:                                                stmtTarget = c
06866:                                                        .createStatement();
06867:                                                if ((importDefinitionElement.strDefaultCutOffData
06868:                                                        .equalsIgnoreCase("true"))) {
06869:                                                    dataCleaning
06870:                                                            .cutingDataLenghtUpdate(
06871:                                                                    this .vecTableTableName
06872:                                                                            .get(
06873:                                                                                    iTableInt)
06874:                                                                            .toString(),
06875:                                                                    c,
06876:                                                                    " where "
06877:                                                                            + strQueryWhere
06878:                                                                            + strQueryConstantApendix,
06879:                                                                    currentRow,
06880:                                                                    updateConstant,
06881:                                                                    importDefinitionElement.strOnErrorContinueXml,
06882:                                                                    importDefinitionElement.strImportDefinitionName,
06883:                                                                    updateConstant
06884:                                                                            + " where "
06885:                                                                            + strQueryWhere
06886:                                                                            + strQueryConstantApendix);
06887:                                                } else
06888:                                                    throw ex;
06889:                                            }
06890:                                            if (iNumRow != 0) {
06891:                                                if (!bWriteData)
06892:                                                    iVersionMax = iVersionMax + 1;
06893:                                                bWriteData = true;
06894:                                            }
06895:                                        }
06896:                                        if (this .vecVariableTimesTableName
06897:                                                .size() != 0) {
06898:                                            int currentVersion = 0;
06899:                                            boolean bool = false;
06900:                                            if (!bWriteData)
06901:                                                currentVersion = iVersionMax + 1;
06902:                                            else
06903:                                                currentVersion = iVersionMax;
06904:                                            bool = this .updateCurrentTime(c,
06905:                                                    iTableInt, strQueryWhere,
06906:                                                    currentVersion, oid);
06907:                                            if (bool) {
06908:                                                if (!bWriteData)
06909:                                                    iVersionMax = iVersionMax + 1;
06910:                                                bWriteData = true;
06911:                                            }
06912:                                        }
06913:                                        if (this .vecVariableColumnTargetTableName
06914:                                                .size() != 0) {
06915:                                            int currentVersion = 0;
06916:                                            boolean bool = false;
06917:                                            if (!bWriteData)
06918:                                                currentVersion = iVersionMax + 1;
06919:                                            else
06920:                                                currentVersion = iVersionMax;
06921:                                            try {
06922:                                                bool = this .updateNameValue(c,
06923:                                                        iTableInt,
06924:                                                        strQueryWhere,
06925:                                                        currentVersion, oid);
06926:                                            } catch (SQLException ex) {
06927:                                                throw ex;
06928:                                            }
06929:                                            if (bool) {
06930:                                                if (!bWriteData)
06931:                                                    iVersionMax = iVersionMax + 1;
06932:                                                bWriteData = true;
06933:                                            }
06934:                                        }
06935:                                    }
06936:                                } // insertTable=true
06937:                                // ZK added this 17.5.2004
06938:                                // System.out.println("iTableInt="+iTableInt);
06939:                                // System.out.println("update + strQueryWhere="+update +
06940:                                // strQueryWhere);
06941:
06942:                                if (this .vecTableInsert.get(iTableInt)
06943:                                        .toString().equalsIgnoreCase("true")) {
06944:                                    if (((update + strQueryWhere)
06945:                                            .indexOf("update") != -1 || (update + strQueryWhere)
06946:                                            .indexOf("UPDATE") != -1)) {
06947:
06948:                                        // if(((Vector)transformationsColumnNames.get(iTableInt)).size()
06949:                                        // > 0){
06950:
06951:                                        // System.out.println("updateTransformation =
06952:                                        // "+updateTransformation);
06953:                                        // System.out.println("transformedValues="+transformedValues);
06954:
06955:                                        Vector tOverwrite = (Vector) indexDTransformationOver
06956:                                                .get(key);
06957:                                        Vector tNull = (Vector) indexDTransformationNull
06958:                                                .get(key);
06959:
06960:                                        if ((updateTransformation.indexOf(",") != -1))
06961:                                            updateTransformation = updateTransformation
06962:                                                    .substring(
06963:                                                            0,
06964:                                                            updateTransformation
06965:                                                                    .lastIndexOf(","));
06966:
06967:                                        if (tOverwrite.size() > 0) {
06968:                                            int startOver = 0;
06969:                                            for (int i = 0; i < tOverwrite
06970:                                                    .size(); i++) {
06971:                                                int index = Integer
06972:                                                        .parseInt(tOverwrite
06973:                                                                .get(i)
06974:                                                                .toString());
06975:                                                if (vecTransformationValue
06976:                                                        .get(index) == null) {
06977:
06978:                                                    int str = updateTransformation
06979:                                                            .indexOf("'dummyTransformationOver'");
06980:                                                    int num = updateTransformation
06981:                                                            .indexOf("dummyTransformationOver");
06982:                                                    if (str != -1
06983:                                                            && (num == -1 || str < num))
06984:                                                        updateTransformation = replaceFirst(
06985:                                                                updateTransformation,
06986:                                                                "'dummyTransformationOver'",
06987:                                                                " null ");
06988:                                                    else
06989:                                                        updateTransformation = replaceFirst(
06990:                                                                updateTransformation,
06991:                                                                "dummyTransformationOver",
06992:                                                                " null ");
06993:                                                } else {
06994:                                                    String replacement = vecTransformationValue
06995:                                                            .get(index)
06996:                                                            .toString();
06997:                                                    startOver = updateTransformation
06998:                                                            .indexOf(
06999:                                                                    "dummyTransformationOver",
07000:                                                                    startOver);
07001:                                                    updateTransformation = updateTransformation
07002:                                                            .substring(0,
07003:                                                                    startOver)
07004:                                                            + replacement
07005:                                                            + updateTransformation
07006:                                                                    .substring(startOver + 23);
07007:                                                    startOver = replacement
07008:                                                            .length();
07009:
07010:                                                }
07011:
07012:                                            }
07013:                                        }
07014:
07015:                                        if (tNull.size() > 0) {
07016:                                            int startNull = 0;
07017:                                            for (int i = 0; i < tNull.size(); i++) {
07018:                                                int index = Integer
07019:                                                        .parseInt(tNull.get(i)
07020:                                                                .toString());
07021:                                                String colName = ((Vector) transformationsColumnNames
07022:                                                        .get(iTableInt)).get(
07023:                                                        index).toString();
07024:                                                if (vecTransformationValue
07025:                                                        .get(index) == null) {
07026:                                                    updateTransformation = replaceFirst(
07027:                                                            updateTransformation,
07028:                                                            "dummyTransformationNull",
07029:                                                            colName
07030:                                                                    + " = null ");
07031:                                                } else {
07032:                                                    updateTransformation = replaceFirst(
07033:                                                            updateTransformation,
07034:                                                            "dummyTransformationNull,",
07035:                                                            "  ");
07036:                                                }
07037:                                            }
07038:                                        }
07039:
07040:                                        if ((tOverwrite.size() > 0)
07041:                                                || (tNull.size() > 0)) {
07042:
07043:                                            if (bReplaceInData) {
07044:                                                updateTransformation = this 
07045:                                                        .replaceInData(updateTransformation);
07046:                                                strQueryWhere = this 
07047:                                                        .replaceInData(strQueryWhere);
07048:                                            }
07049:
07050:                                            if (oid) {
07051:                                                if (bWriteData) {
07052:                                                    updateTransformation += ", "
07053:                                                            + this .currentVersionColumnName
07054:                                                            + " = "
07055:                                                            + (iVersionMax);
07056:                                                } else {
07057:                                                    updateTransformation += ", "
07058:                                                            + this .currentVersionColumnName
07059:                                                            + " = "
07060:                                                            + (iVersionMax + 1);
07061:                                                }
07062:                                            }
07063:
07064:                                            int iNumRow = 0;
07065:                                            try {
07066:                                                if (!updateTransformation
07067:                                                        .endsWith(" set ")) {
07068:                                                    this .logger
07069:                                                            .write(
07070:                                                                    "full",
07071:                                                                    "\tQuery '"
07072:                                                                            + updateTransformation
07073:                                                                            + " where "
07074:                                                                            + strQueryWhere
07075:                                                                            + "' will be executed");
07076:                                                    logStatement = updateTransformation
07077:                                                            + " where "
07078:                                                            + strQueryWhere;
07079:                                                    iNumRow = stmtTarget
07080:                                                            .executeUpdate(updateTransformation
07081:                                                                    + " where "
07082:                                                                    + strQueryWhere);
07083:                                                }
07084:                                            } catch (SQLException ex) {
07085:                                                stmtTarget.close();
07086:                                                throw ex;
07087:                                            }
07088:
07089:                                            if (iNumRow != 0) {
07090:                                                if (!bWriteData)
07091:                                                    iVersionMax = iVersionMax + 1;
07092:                                                bWriteData = true;
07093:                                            }
07094:
07095:                                        }
07096:
07097:                                    }// this is my
07098:                                }// END IF
07099:                                // ZK added 20.5 2004 for "Update" mode
07100:                                if (this .vecTableInsert.get(iTableInt)
07101:                                        .toString().equalsIgnoreCase("true")) {
07102:                                    if (((update + strQueryWhere)
07103:                                            .indexOf("update") != -1 || (update + strQueryWhere)
07104:                                            .indexOf("UPDATE") != -1)) {
07105:
07106:                                        // if(((Vector)transformationsColumnNames.get(iTableInt)).size()
07107:                                        // > 0){
07108:                                        Vector tUpdate = (Vector) indexDTransformationUpdate
07109:                                                .get(key);
07110:                                        if (tUpdate.size() > 0) {
07111:                                            // int startUpdate = 0;
07112:                                            for (int j = 0; j < tUpdate.size(); j++) {
07113:                                                int index = Integer
07114:                                                        .parseInt(tUpdate
07115:                                                                .get(j)
07116:                                                                .toString());
07117:                                                Vector tempTransValueModes = (Vector) transformationsValueModes
07118:                                                        .get(iTableInt);
07119:                                                Vector tempTransColumnNames = (Vector) transformationsColumnNames
07120:                                                        .get(iTableInt);
07121:                                                Vector tempTransColumnTypes = (Vector) transformationsColumnTypes
07122:                                                        .get(iTableInt);
07123:                                                if (tempTransValueModes.get(
07124:                                                        index).toString()
07125:                                                        .equalsIgnoreCase(
07126:                                                                "Update")) {
07127:
07128:                                                    String strQueryUpdate = "update "
07129:                                                            + this .vecTableTableName
07130:                                                                    .get(
07131:                                                                            iTableInt)
07132:                                                                    .toString()
07133:                                                            + " set ";
07134:                                                    strQueryUpdate += tempTransColumnNames
07135:                                                            .get(index)
07136:                                                            .toString()
07137:                                                            + "=";
07138:                                                    if (vecTransformationValue
07139:                                                            .get(index) == null)
07140:                                                        strQueryUpdate += " null ";
07141:                                                    else {
07142:
07143:                                                        if (!configReaderTarget
07144:                                                                .isNumber(tempTransColumnTypes
07145:                                                                        .get(
07146:                                                                                index)
07147:                                                                        .toString()))
07148:                                                            strQueryUpdate += "'"
07149:                                                                    + vecTransformationValue
07150:                                                                            .get(
07151:                                                                                    index)
07152:                                                                            .toString()
07153:                                                                    + "' ";
07154:                                                        else
07155:                                                            strQueryUpdate += vecTransformationValue
07156:                                                                    .get(index)
07157:                                                                    .toString()
07158:                                                                    + " ";
07159:                                                    }
07160:                                                    if (oid) {
07161:                                                        if (bWriteData) {
07162:
07163:                                                            strQueryUpdate += ", "
07164:                                                                    + this .currentVersionColumnName
07165:                                                                    + " = "
07166:                                                                    + (iVersionMax)
07167:                                                                    + " where ";
07168:                                                        } else {
07169:
07170:                                                            strQueryUpdate += ", "
07171:                                                                    + this .currentVersionColumnName
07172:                                                                    + " = "
07173:                                                                    + (iVersionMax + 1)
07174:                                                                    + " where ";
07175:                                                        }
07176:                                                    }
07177:                                                    // strQueryUpdate += " where ";
07178:                                                    strQueryUpdate += tempTransColumnNames
07179:                                                            .get(j).toString()
07180:                                                            + " is null and ";
07181:
07182:                                                    if (bReplaceInData) {
07183:                                                        strQueryUpdate = this 
07184:                                                                .replaceInData(strQueryUpdate);
07185:                                                        strQueryWhere = this 
07186:                                                                .replaceInData(strQueryWhere);
07187:                                                    }
07188:                                                    this .logger
07189:                                                            .write(
07190:                                                                    "full",
07191:                                                                    "\tQuery '"
07192:                                                                            + strQueryUpdate
07193:                                                                            + strQueryWhere
07194:                                                                            + "' will be executed");
07195:                                                    int iNumRow = 0;
07196:                                                    try {
07197:                                                        logStatement = strQueryUpdate
07198:                                                                + strQueryWhere;
07199:                                                        iNumRow = stmtTarget
07200:                                                                .executeUpdate(strQueryUpdate
07201:                                                                        + strQueryWhere);
07202:                                                    } catch (SQLException ex) {
07203:                                                        stmtTarget.close();
07204:                                                        stmtTarget = c
07205:                                                                .createStatement();
07206:                                                        if ((importDefinitionElement.strDefaultCutOffData
07207:                                                                .equalsIgnoreCase("true"))) {
07208:                                                            dataCleaning
07209:                                                                    .cutingDataLenghtUpdate(
07210:                                                                            this .vecTableTableName
07211:                                                                                    .get(
07212:                                                                                            iTableInt)
07213:                                                                                    .toString(),
07214:                                                                            c,
07215:                                                                            strQueryWhere,
07216:                                                                            currentRow,
07217:                                                                            update,
07218:                                                                            importDefinitionElement.strOnErrorContinueXml,
07219:                                                                            importDefinitionElement.strImportDefinitionName,
07220:                                                                            strQueryUpdate
07221:                                                                                    + strQueryWhere);
07222:                                                        } else
07223:                                                            throw ex;
07224:                                                    }
07225:                                                    if (iNumRow != 0) {
07226:                                                        if (!bWriteData)
07227:                                                            iVersionMax = iVersionMax + 1;
07228:                                                        bWriteData = true;
07229:                                                    }
07230:
07231:                                                }
07232:                                                // }
07233:                                            }
07234:                                        }
07235:                                    }
07236:                                }
07237:
07238:                                // ZK END
07239:                            }
07240:
07241:                            // checkRowCache.setCheckRowVersionValue(String
07242:                            // .valueOf(iVersionMax - 1));
07243:                        }
07244:                        stmtTarget.close();
07245:
07246:                    }
07247:                }
07248:                // }
07249:                catch (SQLException ex) {
07250:
07251:                    if (stmtTarget != null)
07252:                        stmtTarget.close();
07253:                    if ((importDefinitionElement.strDefaultCutOffData
07254:                            .equalsIgnoreCase("true"))) {
07255:                        dataCleaning
07256:                                .cleaningInsert(
07257:                                        this .vecTableTableName.get(iTableInt)
07258:                                                .toString(),
07259:                                        c,
07260:                                        currentRow,
07261:                                        "UPDATE",
07262:                                        ex.getMessage(),
07263:                                        importDefinitionElement.strImportDefinitionName,
07264:                                        logStatement);
07265:                        // } else if (
07266:                        // (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("false")
07267:                        // ||
07268:                        // importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase(""))
07269:                        // &&
07270:                        // importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true"))
07271:                        // {
07272:                        // dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(),
07273:                        // c, currentRow, "UPDATE", ex.getMessage(),
07274:                        // importDefinitionElement.strImportDefinitionName);
07275:                    } else {
07276:                        this .logger.write("normal",
07277:                                "\tDataCleaning features is not turn on.");
07278:                        throw ex;
07279:                    }
07280:                } catch (NullPointerException ex) {
07281:                    throw ex;
07282:                } catch (Exception ex) {
07283:
07284:                    throw ex;
07285:                }
07286:                this .logger.write("full",
07287:                        "\tinsertTargetTable method is finished.");
07288:            }
07289:
07290:            /**
07291:             * Method insertRow is used to insert new row in the target table. Also
07292:             * includes inserting values into constant, variable and relation columns of
07293:             * the target table. If there is an error, Exception "SQLException" or
07294:             * "NullPointerException" or "Exception" is thrown.
07295:             * 
07296:             * @param c
07297:             *            Connection to the target database.
07298:             * @param vecColumnValues
07299:             *            One row of values from source table.
07300:             * @param vecColumnNamesTypes
07301:             *            Types of columns in a target table.
07302:             * @param vecColumnNames
07303:             *            Vector of column names in a target table.
07304:             * @param bOIDlogicValue
07305:             *            true if oid column exists in the target table.
07306:             * @param iTableInt
07307:             *            Number of target table which is processed.
07308:             * @param vecColumnMode
07309:             *            represents vector of table modes for currnet table
07310:             * @throws SQLException
07311:             *             Constructs an SQLException object with a reason.
07312:             * @throws NullPointerException
07313:             *             Constructs a NullPointerException with the specified detail
07314:             *             message.
07315:             * @throws Exception
07316:             *             Constructs an Exception with the specified detail message.
07317:             */
07318:            private void insertRow(Connection c, Vector vecColumnValues,
07319:                    Vector vecColumnNamesTypes, Vector vecColumnNames,
07320:                    Vector vecColumnMode, boolean bOIDlogicValue,
07321:                    int iTableInt, Vector vecTransformationValue,
07322:                    Vector transformationTargetColumnTypes)
07323:                    throws SQLException, NullPointerException, Exception {
07324:
07325:                String key = String.valueOf(iTableInt);
07326:                String strInsertRow = (String) queryInsertRow.get(key);
07327:                Vector indexOfNotRelationColumns = (Vector) indexIsNotRelationsColumns
07328:                        .get(key);
07329:
07330:                PreparedStatement pstmt = (PreparedStatement) pstmtForInsert
07331:                        .get(key);
07332:
07333:                Vector pstmtColNames = (Vector) pstmtColumnNames.get(key);
07334:                Vector pstmtValues = new Vector();
07335:                Vector pstmtTypes = new Vector();
07336:                // hendling select statement in relation tag!
07337:                String selectValueInRel = "";
07338:                String currentValueInRel = "";
07339:
07340:                this .logger.write("full", "\tinsertRow method is started.");
07341:                String strQuery = "";
07342:                boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
07343:                        .equals("") || importDefinitionElement.strObjectIDNameColumnValue
07344:                        .equals(""));
07345:                // sinisa 15.03.2003. Add subCouterColumns
07346:                Vector subCounterKeyColumns = this .counterColumns
07347:                        .getSubCounterKeyColumns(this .vecTableTableName.get(
07348:                                iTableInt).toString(), this .vecTableTableID
07349:                                .get(iTableInt).toString());
07350:
07351:                Hashtable subKeyValues = new Hashtable();
07352:                try {
07353:                    Vector vecTempConstantColumns = (Vector) this .vecConstantTargetColumnName
07354:                            .get(iTableInt);
07355:                    Vector vecTempConstantValues = (Vector) this .vecConstantConstantValue
07356:                            .get(iTableInt);
07357:                    strInsertRow = strInsertRow.trim();
07358:                    int comma = strInsertRow.lastIndexOf(",");
07359:                    if (comma == (strInsertRow.length() - 1))
07360:                        strQuery = strInsertRow.substring(0, strInsertRow
07361:                                .length() - 1);
07362:                    else
07363:                        strQuery = strInsertRow;
07364:                    if (bOIDlogicValue) {
07365:                        if (isTOS) {
07366:                            pstmtValues.add(this .bdecOidNumber);
07367:                            pstmtTypes.add("java.math.BigDecimal");
07368:                        } else {
07369:                            pstmtValues.add(this .bdecOidNumber);
07370:                            pstmtValues.add(String.valueOf(0));
07371:                            pstmtTypes.add("java.math.BigDecimal");
07372:                            pstmtTypes.add("java.lang.Integer");
07373:                        }
07374:                    }
07375:
07376:                    strQuery = strQuery + ") VALUES (";
07377:
07378:                    if (this .vecTableInsert.get(iTableInt).toString()
07379:                            .equalsIgnoreCase("true")) {
07380:                        if (indexOfNotRelationColumns.size() > 0) {
07381:                            for (int k = 0; k < indexOfNotRelationColumns
07382:                                    .size(); k++) {
07383:                                int index = Integer
07384:                                        .parseInt(indexOfNotRelationColumns
07385:                                                .get(k).toString());
07386:                                Vector replacedValue = (Vector) vecDefaultValue
07387:                                        .get(iTableInt);
07388:                                if (vecColumnValues.get(index) == null) {
07389:                                    if (replacedValue.get(index) != "") {
07390:                                        pstmtValues.add(replacedValue
07391:                                                .get(index)
07392:                                        // .toString()
07393:                                                );
07394:                                        pstmtTypes.add(vecColumnNamesTypes.get(
07395:                                                index).toString());
07396:                                        dataCleaning
07397:                                                .cleaningColumnValues(
07398:                                                        this .vecTableTableName
07399:                                                                .get(iTableInt)
07400:                                                                .toString(),
07401:                                                        vecColumnNames.get(
07402:                                                                index)
07403:                                                                .toString(),
07404:                                                        replacedValue
07405:                                                                .get(index)
07406:                                                                .toString(),
07407:                                                        currentRow,
07408:                                                        c,
07409:                                                        "INSERT",
07410:                                                        importDefinitionElement.strImportDefinitionName);
07411:                                    } else {
07412:                                        pstmtValues.add("null");
07413:                                        pstmtTypes.add(vecColumnNamesTypes.get(
07414:                                                index).toString());
07415:                                    }
07416:                                } else {
07417:                                    pstmtValues.add(vecColumnValues.get(index)
07418:                                    // .toString()
07419:                                            );
07420:                                    pstmtTypes.add(vecColumnNamesTypes.get(
07421:                                            index).toString());
07422:                                }
07423:
07424:                                // sinisa 15.03 Add subCounter columns
07425:                                for (int l = 0; l < subCounterKeyColumns.size(); l++) {
07426:                                    if (subCounterKeyColumns.get(l) != null
07427:                                            && ((Vector) subCounterKeyColumns
07428:                                                    .get(l)).size() != 0
07429:                                            && ((Vector) subCounterKeyColumns
07430:                                                    .get(l))
07431:                                                    .contains(vecColumnNames
07432:                                                            .get(index)
07433:                                                            .toString())) {
07434:                                        if (vecColumnValues.get(index) != null) {
07435:                                            subKeyValues.put(vecColumnNames
07436:                                                    .get(index).toString(),
07437:                                                    vecColumnValues.get(index)
07438:                                                            .toString());
07439:                                        }
07440:                                    }
07441:                                }
07442:                            }
07443:                        }
07444:                    }
07445:                    if (this .vecTableInsert.get(iTableInt).toString()
07446:                            .equalsIgnoreCase("true")) {
07447:                        for (int p = 0; p < vecTempConstantValues.size(); p++) {
07448:                            if (vecTempConstantValues.get(p) == null) {
07449:                                pstmtValues.add("null");
07450:                                pstmtTypes
07451:                                        .add(((Vector) this .vecConstantColumnType
07452:                                                .get(iTableInt)).get(p)
07453:                                                .toString());
07454:                            } else {
07455:                                pstmtValues.add(vecTempConstantValues.get(p)
07456:                                // .toString()
07457:                                        );
07458:                                pstmtTypes
07459:                                        .add(((Vector) this .vecConstantColumnType
07460:                                                .get(iTableInt)).get(p)
07461:                                                .toString());
07462:
07463:                            }
07464:                            // sinisa 15.03 Add subCounter columns
07465:                            for (int l = 0; l < subCounterKeyColumns.size(); l++) {
07466:                                if (subCounterKeyColumns.get(l) != null
07467:                                        && ((Vector) subCounterKeyColumns
07468:                                                .get(l)).size() != 0
07469:                                        && ((Vector) subCounterKeyColumns
07470:                                                .get(l))
07471:                                                .contains(vecTempConstantColumns
07472:                                                        .get(p))) {
07473:                                    if (vecTempConstantValues.get(p) != null)
07474:                                        subKeyValues.put(vecTempConstantColumns
07475:                                                .get(p).toString(),
07476:                                                vecTempConstantValues.get(p)
07477:                                                        .toString());
07478:                                }
07479:                            }
07480:                        }
07481:                    }
07482:                    if (this .vecTableInsert.get(iTableInt).toString()
07483:                            .equalsIgnoreCase("true")) {
07484:                        for (int i = 0; i < this .vecVariableTimesTableName
07485:                                .size(); i++) {
07486:                            if (this .vecVariableTimesTableName.get(i)
07487:                                    .toString().equalsIgnoreCase(
07488:                                            this .vecTableTableName.get(
07489:                                                    iTableInt).toString())
07490:                                    && this .vecVariableTimesTableID.get(i)
07491:                                            .toString().equalsIgnoreCase(
07492:                                                    this .vecTableTableID.get(
07493:                                                            iTableInt)
07494:                                                            .toString())) {
07495:                                pstmtValues.add(createCurrentDate());
07496:                                pstmtTypes.add("java.sql.Date");
07497:                            }
07498:                        }
07499:                        for (int i = 0; i < this .vecVariableColumnTargetTableName
07500:                                .size(); i++) {
07501:                            if (this .vecVariableColumnTargetTableName.get(i)
07502:                                    .toString().equalsIgnoreCase(
07503:                                            this .vecTableTableName.get(
07504:                                                    iTableInt).toString())
07505:                                    && this .vecVariableColumnTargetTableID.get(
07506:                                            i).toString().equalsIgnoreCase(
07507:                                            this .vecTableTableID.get(iTableInt)
07508:                                                    .toString())) {
07509:                                int iPositionInVector = this .vecVariableName
07510:                                        .indexOf(this .vecVariableColumnName
07511:                                                .get(i).toString());
07512:                                if (iPositionInVector != -1) {
07513:                                    if (this .vecVariableValue
07514:                                            .get(iPositionInVector) == null) {
07515:                                        String variableName = this .vecVariableColumnName
07516:                                                .get(i).toString();
07517:                                        for (int k = 0; k < this .vecDefaultVariableName
07518:                                                .size(); k++) {
07519:                                            if (this .vecDefaultVariableName
07520:                                                    .get(k).toString()
07521:                                                    .equalsIgnoreCase(
07522:                                                            variableName)) {
07523:                                                if (!this .vecDefaultVariableValue
07524:                                                        .get(k).toString()
07525:                                                        .equalsIgnoreCase("")) {
07526:                                                    pstmtValues
07527:                                                            .add(this .vecDefaultVariableValue
07528:                                                                    .get(k)
07529:                                                            // .toString()
07530:                                                            );
07531:                                                    pstmtTypes
07532:                                                            .add(this .vecVariableColumnTypes
07533:                                                                    .get(i)
07534:                                                                    .toString());
07535:                                                } else {
07536:                                                    pstmtValues.add("null");
07537:                                                    pstmtTypes
07538:                                                            .add(this .vecVariableColumnTypes
07539:                                                                    .get(i)
07540:                                                                    .toString());
07541:                                                }
07542:                                                break;
07543:                                            }
07544:                                        }
07545:                                    } else {
07546:                                        pstmtValues.add(this .vecVariableValue
07547:                                                .get(iPositionInVector)
07548:                                        // .toString()
07549:                                                );
07550:                                        pstmtTypes
07551:                                                .add(this .vecVariableColumnTypes
07552:                                                        .get(i).toString());
07553:                                    }
07554:                                } else {
07555:                                    this .logger
07556:                                            .write(
07557:                                                    "normal",
07558:                                                    "\tError: Cannot find value for variable column :"
07559:                                                            + this .vecVariableColumnName
07560:                                                                    .get(i)
07561:                                                                    .toString());
07562:                                    LoaderException le = new LoaderException(
07563:                                            "Exception: ",
07564:                                            (Throwable) (new Exception(
07565:                                                    "Error: Cannot find value for variable column :")));
07566:                                    this .logger.write("full", le
07567:                                            .getStackTraceAsString());
07568:                                    throw le;
07569:                                }
07570:                                // sinisa 15.03 Add subCounter columns
07571:                                for (int l = 0; l < subCounterKeyColumns.size(); l++) {
07572:                                    if (subCounterKeyColumns.get(l) != null
07573:                                            && ((Vector) subCounterKeyColumns
07574:                                                    .get(l)).size() != 0
07575:                                            && ((Vector) subCounterKeyColumns
07576:                                                    .get(l))
07577:                                                    .contains(this .vecVariableColumnName
07578:                                                            .get(iPositionInVector))) {
07579:                                        if (this .vecVariableValue
07580:                                                .get(iPositionInVector) != null)
07581:                                            subKeyValues
07582:                                                    .put(
07583:                                                            this .vecVariableColumnName
07584:                                                                    .get(
07585:                                                                            iPositionInVector)
07586:                                                                    .toString(),
07587:                                                            this .vecVariableValue
07588:                                                                    .get(
07589:                                                                            iPositionInVector)
07590:                                                                    .toString());
07591:                                    }
07592:                                }
07593:                            }
07594:                        }
07595:                    }
07596:                    // find value for relation column - userID
07597:                    for (int i = 0; i < this .iRelationColumns; i++) {
07598:                        outLoop1: if (this .vecRelationColumnSourceTableName
07599:                                .get(i).toString().equalsIgnoreCase(
07600:                                        this .vecTableTableName.get(iTableInt)
07601:                                                .toString())
07602:                                && this .vecRelationColumnSourceTableID.get(i)
07603:                                        .toString().equalsIgnoreCase(
07604:                                                this .vecTableTableID.get(
07605:                                                        iTableInt).toString())) {
07606:                            for (int m = 0; m < this .vecVariableUseIDTableName
07607:                                    .size(); m++) {
07608:                                if (this .vecRelationColumnSourceTableName
07609:                                        .get(i).toString().equalsIgnoreCase(
07610:                                                this .vecVariableUseIDTableName
07611:                                                        .get(m).toString())
07612:                                        && this .vecRelationColumnSourceTableID
07613:                                                .get(i)
07614:                                                .toString()
07615:                                                .equalsIgnoreCase(
07616:                                                        this .vecVariableUseIDTableID
07617:                                                                .get(m)
07618:                                                                .toString())) {
07619:                                    String strQueryRelations = "select "
07620:                                            + this .vecRelationColumnSourceColumnName
07621:                                                    .get(i).toString()
07622:                                            + " from "
07623:                                            + this .vecRelationColumnSourceTableName
07624:                                                    .get(i).toString()
07625:                                            + " where ";
07626:                                    strQueryRelations += ((Vector) this .vecTargetKeyColumnName
07627:                                            .get(iTableInt)).get(0).toString()
07628:                                            + " = ";
07629:                                    // ZK change this from CheckType to
07630:                                    // configReaderTarget this 7.5.2004
07631:                                    if (!configReaderTarget
07632:                                            .isNumber(vecColumnNamesTypes
07633:                                                    .get(0).toString()))
07634:                                        strQueryRelations += "'"
07635:                                                + this .strUserID + "'";
07636:                                    else
07637:                                        strQueryRelations += this .strUserID;
07638:                                    this .logger.write("full", "\tQuery '"
07639:                                            + strQueryRelations
07640:                                            + "' will be executed");
07641:                                    Statement stmt = c.createStatement();
07642:                                    ResultSet rsetTarget = stmt
07643:                                            .executeQuery(strQueryRelations);
07644:                                    if (rsetTarget.next()) {
07645:                                        if (this .iTargetFirstColumnResult == 1) {
07646:                                            this .vecRelationSourceValue
07647:                                                    .setElementAt(rsetTarget
07648:                                                            .getObject(1), i);
07649:                                            this .vecRelationSourceType
07650:                                                    .setElementAt(rsetTarget
07651:                                                            .getMetaData()
07652:                                                            .getColumnTypeName(
07653:                                                                    1), i);
07654:                                        } else {
07655:                                            this .vecRelationSourceValue
07656:                                                    .setElementAt(rsetTarget
07657:                                                            .getObject(0), i);
07658:                                            this .vecRelationSourceType
07659:                                                    .setElementAt(rsetTarget
07660:                                                            .getMetaData()
07661:                                                            .getColumnTypeName(
07662:                                                                    0), i);
07663:                                        }
07664:                                    }
07665:                                    rsetTarget.close();
07666:                                    stmt.close();
07667:                                    break outLoop1;
07668:                                }
07669:                            }
07670:                            if (bOIDlogicValue) {
07671:                                String oidType = configReaderTarget
07672:                                        .getOidDbType();
07673:                                int end = oidType.indexOf("(");
07674:                                if (end != -1)
07675:                                    oidType = (oidType.substring(0, end))
07676:                                            .trim();
07677:                                else
07678:                                    oidType = oidType.trim();
07679:                                if (this .vecTableInsert.get(iTableInt)
07680:                                        .toString().equalsIgnoreCase("true")) {
07681:                                    // insertTable=true
07682:                                    this .vecRelationSourceValue.setElementAt(
07683:                                            this .bdecOidNumber, i);
07684:                                    this .vecRelationSourceType.setElementAt(
07685:                                            oidType.toLowerCase(), i);
07686:
07687:                                } else {
07688:                                    // insertTable=false
07689:                                    this .vecRelationSourceValue.setElementAt(
07690:                                            null, i);
07691:                                    this .vecRelationSourceType.setElementAt(
07692:                                            oidType.toLowerCase(), i);
07693:
07694:                                }
07695:                            } else { // bOIDlogicValue=false
07696:                                if (this .iRelationColumns > 0) {
07697:                                    for (int j = 0; j < vecColumnNames.size(); j++) {
07698:                                        if (this .vecRelationColumnSourceColumnName
07699:                                                .get(i).toString()
07700:                                                .equalsIgnoreCase(
07701:                                                        vecColumnNames.get(j)
07702:                                                                .toString())) {
07703:                                            if (this .vecTableInsert.get(
07704:                                                    iTableInt).toString()
07705:                                                    .equalsIgnoreCase("true")) {
07706:                                                // insertTable=true
07707:                                                this .vecRelationSourceValue
07708:                                                        .setElementAt(
07709:                                                                vecColumnValues
07710:                                                                        .get(j)
07711:                                                                        .toString(),
07712:                                                                i);
07713:                                                this .vecRelationSourceType
07714:                                                        .setElementAt(
07715:                                                                vecColumnNamesTypes
07716:                                                                        .get(j)
07717:                                                                        .toString(),
07718:                                                                i);
07719:                                            } else {
07720:                                                // insertTable=false;
07721:                                                this .vecRelationSourceValue
07722:                                                        .setElementAt(null, i);
07723:                                                this .vecRelationSourceType
07724:                                                        .setElementAt(
07725:                                                                vecColumnNamesTypes
07726:                                                                        .get(j)
07727:                                                                        .toString(),
07728:                                                                i);
07729:                                            }
07730:                                        }
07731:                                    } // end vecColumnNames.size()
07732:                                }
07733:                            }
07734:                        }
07735:                    }
07736:
07737:                    for (int i = 0; i < this .vecRelationColumnTargetColumnName
07738:                            .size(); i++) {
07739:                        String tmpRelationForCount = "";
07740:                        if (this .vecRelationColumnTargetTableName.get(i)
07741:                                .toString().equalsIgnoreCase(
07742:                                        this .vecTableTableName.get(iTableInt)
07743:                                                .toString())
07744:                                && this .vecRelationColumnTargetTableID.get(i)
07745:                                        .toString().equalsIgnoreCase(
07746:                                                this .vecTableTableID.get(
07747:                                                        iTableInt).toString())) {
07748:                            if (this .vecRelationSourceValue.get(i) == null) {
07749:                                String replacementValueInRel = vecDefaultRelationValue
07750:                                        .get(i).toString();
07751:                                if (!replacementValueInRel.equalsIgnoreCase("")) {
07752:                                    // default value for relation exists
07753:                                    try {
07754:                                        Object obj = relationsCache
07755:                                                .getRelationsCacheValue(replacementValueInRel);
07756:                                        String relationValue;
07757:                                        String relationType;
07758:                                        if (obj != null) {
07759:                                            // relation (default value) is cached
07760:                                            relationValue = obj.toString();
07761:                                            relationType = relationsCache
07762:                                                    .getRelationsCachType(replacementValueInRel);
07763:                                            pstmtValues.add(relationValue);
07764:                                            pstmtTypes.add(relationType);
07765:                                        } else {
07766:                                            // relation (default value) isn't cached
07767:                                            ResultSet newRelationValue = null;
07768:                                            Statement newRelationsStmt = c
07769:                                                    .createStatement();
07770:                                            try {
07771:                                                this .logger
07772:                                                        .write(
07773:                                                                "full",
07774:                                                                "\tQuery '"
07775:                                                                        + replacementValueInRel
07776:                                                                        + "' will be executed");
07777:                                                newRelationValue = newRelationsStmt
07778:                                                        .executeQuery(replacementValueInRel);
07779:                                                if (newRelationValue.next()) {
07780:                                                    relationValue = newRelationValue
07781:                                                            .getString(1);
07782:                                                    relationsCache
07783:                                                            .setRelationsCacheValue(
07784:                                                                    replacementValueInRel,
07785:                                                                    relationValue);
07786:                                                    relationType = newRelationValue
07787:                                                            .getMetaData()
07788:                                                            .getColumnTypeName(
07789:                                                                    1);
07790:                                                    relationsCache
07791:                                                            .setRelationsCacheType(
07792:                                                                    replacementValueInRel,
07793:                                                                    relationType);
07794:
07795:                                                    newRelationValue.close();
07796:                                                    newRelationsStmt.close();
07797:
07798:                                                    String strDataCleaning = dataCleaning
07799:                                                            .cleaningRelationValues(
07800:                                                                    this .vecTableTableName
07801:                                                                            .get(
07802:                                                                                    iTableInt)
07803:                                                                            .toString(),
07804:                                                                    this .vecRelationColumnTargetColumnName
07805:                                                                            .get(
07806:                                                                                    i)
07807:                                                                            .toString(),
07808:                                                                    relationValue,
07809:                                                                    relationType,
07810:                                                                    currentRow,
07811:                                                                    c,
07812:                                                                    "INSERT",
07813:                                                                    0,
07814:                                                                    false,
07815:                                                                    importDefinitionElement.strImportDefinitionName,
07816:                                                                    this .currentVersionColumnName,
07817:                                                                    replacementValueInRel);
07818:                                                    pstmtValues
07819:                                                            .add(strDataCleaning);
07820:                                                    pstmtTypes
07821:                                                            .add(relationType);
07822:                                                } else { // newRelationValue.next()=false
07823:                                                    newRelationValue.close();
07824:                                                    newRelationsStmt.close();
07825:                                                    relationValue = "null";
07826:                                                    dataCleaning
07827:                                                            .cleaningInsert(
07828:                                                                    this .vecTableTableName
07829:                                                                            .get(
07830:                                                                                    iTableInt)
07831:                                                                            .toString(),
07832:                                                                    c,
07833:                                                                    currentRow,
07834:                                                                    "INSERT",
07835:                                                                    "Default value '"
07836:                                                                            + replacementValueInRel
07837:                                                                            + "' for relations is not valid.",
07838:                                                                    importDefinitionElement.strImportDefinitionName,
07839:                                                                    replacementValueInRel);
07840:
07841:                                                    pstmtValues.add("null");
07842:                                                    pstmtTypes
07843:                                                            .add(this .vecRelationSourceType
07844:                                                                    .get(i)
07845:                                                                    .toString());
07846:                                                }
07847:                                            } catch (SQLException ex) {
07848:                                                newRelationValue.close();
07849:                                                newRelationsStmt.close();
07850:                                                LoaderException le = new LoaderException(
07851:                                                        "\n"
07852:                                                                + "SQLException: "
07853:                                                                + ex
07854:                                                                        .getMessage(),
07855:                                                        (Throwable) ex);
07856:                                                this .logger
07857:                                                        .write(
07858:                                                                "full",
07859:                                                                le
07860:                                                                        .getStackTraceAsString());
07861:                                                throw le;
07862:                                            }
07863:                                        }
07864:
07865:                                    } catch (SQLException ex) {
07866:                                        String msg = "Default value for foreign key("
07867:                                                + replacementValueInRel
07868:                                                + ") is not valid. Import definition name: "
07869:                                                + importDefinitionElement.strImportDefinitionName;
07870:                                        LoaderException le = new LoaderException(
07871:                                                "SQLException: " + msg,
07872:                                                (Throwable) ex);
07873:                                        this .logger.write("full", le
07874:                                                .getStackTraceAsString());
07875:                                        throw le;
07876:                                    }
07877:
07878:                                } else { // default value for relations doesn't
07879:                                    // exsist
07880:                                    pstmtValues.add("null");
07881:                                    if (this .vecRelationSourceType.get(i) != null)
07882:                                        pstmtTypes
07883:                                                .add(this .vecRelationSourceType
07884:                                                        .get(i).toString());
07885:                                    else
07886:                                        pstmtTypes.add("java.lang.Object");
07887:                                }
07888:                            } else { // this.vecRelationSourceType.get(i)!=null
07889:                                pstmtValues.add(this .vecRelationSourceValue
07890:                                        .get(i).toString());
07891:                                pstmtTypes.add(this .vecRelationSourceType
07892:                                        .get(i).toString());
07893:
07894:                                tmpRelationForCount = this .vecRelationSourceValue
07895:                                        .get(i).toString();//
07896:                                this .vecRelationSourceValue.setElementAt(null,
07897:                                        i);
07898:
07899:                            }
07900:
07901:                            // sinisa 15.03 Add subCounter columns
07902:                            for (int l = 0; l < subCounterKeyColumns.size(); l++) {
07903:                                if (subCounterKeyColumns.get(l) != null
07904:                                        && ((Vector) subCounterKeyColumns
07905:                                                .get(l)).size() != 0
07906:                                        && ((Vector) subCounterKeyColumns
07907:                                                .get(l))
07908:                                                .contains(this .vecRelationColumnTargetColumnName
07909:                                                        .get(i))) {
07910:                                    if (tmpRelationForCount != null) {
07911:                                        subKeyValues
07912:                                                .put(
07913:                                                        this .vecRelationColumnTargetColumnName
07914:                                                                .get(i)
07915:                                                                .toString(),
07916:                                                        tmpRelationForCount);
07917:                                    }
07918:                                }
07919:                            }
07920:                        }
07921:                    }
07922:
07923:                    // sinisa 02.03.2003. Add couterColumns
07924:                    Vector counterColValues = this .counterColumns
07925:                            .getCounterValue(this .vecTableTableName.get(
07926:                                    iTableInt).toString(), this .vecTableTableID
07927:                                    .get(iTableInt).toString());
07928:                    for (int i = 0; i < counterColValues.size(); i++) {
07929:                        if (counterColValues.get(i) != null) {
07930:                            int strInt = new BigDecimal(counterColValues.get(i)
07931:                                    .toString()).intValue();
07932:                            pstmtValues.add(String.valueOf(strInt));
07933:                            pstmtTypes.add("java.lang.Integer");
07934:                        } else {
07935:                            pstmtValues.add("null");
07936:                            pstmtTypes.add("java.lang.Integer");
07937:                        }
07938:                    }
07939:                    this .counterColumns.setCounterValue(this .vecTableTableName
07940:                            .get(iTableInt).toString(), this .vecTableTableID
07941:                            .get(iTableInt).toString());
07942:                    // end sinisa
07943:
07944:                    // sinisa 15.03.2003. Add counterColumns
07945:                    if (this .vecTableInsert.get(iTableInt).toString()
07946:                            .equalsIgnoreCase("true")) {
07947:                        this .counterColumns.setSubCounterKeyValues(
07948:                                this .vecTableTableName.get(iTableInt)
07949:                                        .toString(), this .vecTableTableID.get(
07950:                                        iTableInt).toString(), subKeyValues);
07951:                        Vector subCounterColValues = this .counterColumns
07952:                                .readSubCounterValue(this .vecTableTableName
07953:                                        .get(iTableInt).toString(),
07954:                                        this .vecTableTableID.get(iTableInt)
07955:                                                .toString(), c,
07956:                                        this .iTargetFirstColumnResult,
07957:                                        this .vecTableTableMode.get(iTableInt)
07958:                                                .toString(), configReaderTarget);
07959:                        for (int i = 0; i < subCounterColValues.size(); i++) {
07960:                            if (subCounterColValues.get(i) != null) {
07961:                                pstmtValues.add(new BigDecimal(
07962:                                        subCounterColValues.get(i).toString()));
07963:                                pstmtTypes.add("java.math.BigDecimal");
07964:                            } else {
07965:                                pstmtValues.add("null");
07966:                                pstmtTypes.add("java.math.BigDecimal");
07967:                            }
07968:                        }
07969:                        if (bOIDlogicValue) {
07970:                            if (this .bdecOidNumber
07971:                                    .compareTo(this .bdecOidNumber2000) == 0) {
07972:                                this .checkOidLogic(c);
07973:                                this .bdecOidNumber = this .bdecOidNumber
07974:                                        .add(new BigDecimal(1));
07975:                            } else
07976:                                this .bdecOidNumber = this .bdecOidNumber
07977:                                        .add(new BigDecimal(1));
07978:                        }
07979:
07980:                        // ZK added this for transormations
07981:                        for (int i = 0; i < vecTransformationValue.size(); i++) {
07982:                            if ((vecTransformationValue.get(i)) == null) {
07983:                                String valueForPstmt = "null";
07984:                                pstmtValues.add(valueForPstmt);
07985:                            } else {
07986:                                pstmtValues.add(vecTransformationValue.get(i)
07987:                                // .toString()
07988:                                        );
07989:                            }
07990:
07991:                            pstmtTypes.add(transformationTargetColumnTypes.get(
07992:                                    i).toString());
07993:
07994:                        }
07995:
07996:                        // String tableNameId=
07997:                        // this.vecTableTableName.get(iTableInt).toString()+this.vecTableTableID.get(iTableInt).toString();
07998:                        // if (transTableNamesIDs.contains(tableNameId)){
07999:                        // for (int i=0; i < trans.size();i++){
08000:                        // Transformation pom = (Transformation)trans.get(i);
08001:                        // Vector sourceColumnNames = pom.getSourceColumnNames();
08002:                        // Vector targetColumnNames =
08003:                        // pom.getTargetColumnNames(this.vecTableTableName.get(iTableInt).toString(),
08004:                        // this.vecTableTableID.get(iTableInt).toString());
08005:                        //					
08006:                        // Vector resultVector =
08007:                        // pom.readTransformationValues(sourceColumnNames,
08008:                        // this.vecTableTableName.get(iTableInt).toString(),
08009:                        // this.vecTableTableID.get(iTableInt).toString());
08010:                        // Vector resultVectorTypes =
08011:                        // pom.getTargetColumnTypes(this.vecTableTableName.get(iTableInt).toString(),
08012:                        // this.vecTableTableID.get(iTableInt).toString());
08013:                        // for(int j=0;j < resultVector.size();j++) {
08014:                        // pstmtValues.add(resultVector.get(j));
08015:                        // pstmtTypes.add(resultVectorTypes.get(j));
08016:                        // }
08017:                        // }
08018:                        // }
08019:                        // end
08020:
08021:                        // handling blob object
08022:                        // strQuery = strQuery + ") VALUES (";
08023:                        String pstmtColumnValue;
08024:                        for (int i = 0; i < pstmtValues.size(); i++) {
08025:
08026:                            String javaType = pstmtTypes.get(i).toString()
08027:                                    .toUpperCase();
08028:                            if (javaType.indexOf("JAVA") == -1) {
08029:                                // //ZK Added next line because of DB2 type LONG VARCHAR
08030:                                // javaType = Utils.replaceAll(javaType," ","_");
08031:                                javaType = (String) configReaderTarget
08032:                                        .getJavaTypeMapings().get(
08033:                                                javaType.toUpperCase());
08034:                                if (javaType == null) {
08035:                                    LoaderException le = new LoaderException(
08036:                                            "Exception:",
08037:                                            new Exception(
08038:                                                    "This type of data "
08039:                                                            + pstmtTypes
08040:                                                                    .get(i)
08041:                                                                    .toString()
08042:                                                                    .toUpperCase()
08043:                                                            + "  doesn't exists in the target table conf file!"));
08044:                                    this .logger.write("full", le
08045:                                            .getStackTraceAsString());
08046:                                    throw le;
08047:                                }
08048:                            } else {
08049:                                if (javaType
08050:                                        .equalsIgnoreCase("java.math.BigDecimal"))
08051:                                    javaType = "2";
08052:                                else if (javaType
08053:                                        .equalsIgnoreCase("java.lang.Integer"))
08054:                                    javaType = "5";
08055:                                else if (javaType
08056:                                        .equalsIgnoreCase("java.sql.Date"))
08057:                                    javaType = "9";
08058:                                else if (javaType
08059:                                        .equalsIgnoreCase("java.lang.Object"))
08060:                                    javaType = "14";
08061:
08062:                            }
08063:
08064:                            int javaTypeInt = Integer.parseInt(javaType);
08065:                            pstmtColumnValue = pstmtValues.get(i).toString();
08066:                            Object pstmtColumnValueAsObject = pstmtValues
08067:                                    .get(i);
08068:                            // ZK changed this 17.6 2004 because of problems with null
08069:                            // binary object.
08070:                            // if (pstmtColumnValue.startsWith("binaryObject")) {
08071:                            if (javaTypeInt == 1) {
08072:                                if (!pstmtColumnValue.equalsIgnoreCase("null")) {
08073:                                    String binaryName = pstmtValues.get(i)
08074:                                            .toString();
08075:                                    for (int j = 0; j < vecBlobVector.size(); j = j + 5) {
08076:                                        if (binaryName
08077:                                                .equalsIgnoreCase(vecBlobVector
08078:                                                        .get(j + 4).toString())) {
08079:                                            byte[] isBlob = (byte[]) this .vecBlobVector
08080:                                                    .get(j + 1);
08081:                                            strQuery = strQuery + binaryName
08082:                                                    + ",";
08083:                                            pstmt.setBytes(i + 1, isBlob);
08084:                                            strQuery = strQuery + "BlobObject"
08085:                                                    + i + ",";
08086:                                            break;
08087:                                        }
08088:                                    }
08089:                                } else {
08090:                                    pstmt.setNull(i + 1, java.sql.Types.BINARY);
08091:                                    strQuery = strQuery + "null" + ",";
08092:                                }
08093:                            } else {
08094:                                if (javaTypeInt == 2) { // java.math.BigDecimal
08095:                                    if (!pstmtColumnValue
08096:                                            .equalsIgnoreCase("null")) {
08097:                                        BigDecimal number = new BigDecimal(0);
08098:                                        if (!pstmtColumnValue
08099:                                                .equalsIgnoreCase(""))
08100:                                            number = new BigDecimal(
08101:                                                    pstmtColumnValue);
08102:                                        strQuery = strQuery + pstmtColumnValue
08103:                                                + ",";
08104:                                        pstmt.setBigDecimal(i + 1, number);
08105:                                    } else {
08106:                                        pstmt.setNull(i + 1,
08107:                                                java.sql.Types.DECIMAL);
08108:                                        strQuery = strQuery + "null" + ",";
08109:                                    }
08110:                                } else if (javaTypeInt == 3) { // java.lang.Double
08111:                                    if (!pstmtColumnValue
08112:                                            .equalsIgnoreCase("null")) {
08113:                                        double number = 0;
08114:                                        if (!pstmtColumnValue
08115:                                                .equalsIgnoreCase(""))
08116:                                            number = Double
08117:                                                    .parseDouble(pstmtColumnValue);
08118:                                        strQuery = strQuery + pstmtColumnValue
08119:                                                + ",";
08120:                                        pstmt.setDouble(i + 1, number);
08121:                                    } else {
08122:                                        strQuery = strQuery + "null" + ",";
08123:                                        pstmt.setNull(i + 1,
08124:                                                java.sql.Types.DOUBLE);
08125:                                    }
08126:                                } else if (javaTypeInt == 4) { // java.lang.Float
08127:                                    if (!pstmtColumnValue
08128:                                            .equalsIgnoreCase("null")) {
08129:                                        float number = 0;
08130:                                        if (!pstmtColumnValue
08131:                                                .equalsIgnoreCase(""))
08132:                                            number = Float
08133:                                                    .parseFloat(pstmtColumnValue);
08134:                                        pstmt.setFloat(i + 1, number);
08135:                                        strQuery = strQuery + pstmtColumnValue
08136:                                                + ",";
08137:                                    } else {
08138:                                        pstmt.setNull(i + 1,
08139:                                                java.sql.Types.FLOAT);
08140:                                        strQuery = strQuery + "null" + ",";
08141:                                    }
08142:                                } else if (javaTypeInt == 5) { // java.lang.Integer
08143:                                    if (!pstmtColumnValue
08144:                                            .equalsIgnoreCase("null")) {
08145:                                        int number = 0;
08146:                                        if (!pstmtColumnValue
08147:                                                .equalsIgnoreCase(""))
08148:                                            number = Integer
08149:                                                    .parseInt(pstmtColumnValue);
08150:                                        pstmt.setInt(i + 1, number);
08151:                                        strQuery = strQuery + pstmtColumnValue
08152:                                                + ",";
08153:                                    } else {
08154:                                        pstmt.setNull(i + 1,
08155:                                                java.sql.Types.INTEGER);
08156:                                        strQuery = strQuery + "null" + ",";
08157:                                    }
08158:
08159:                                } else if (javaTypeInt == 6) { // java.lang.Long
08160:                                    if (!pstmtColumnValue
08161:                                            .equalsIgnoreCase("null")) {
08162:                                        long number = 0;
08163:                                        if (!pstmtColumnValue
08164:                                                .equalsIgnoreCase(""))
08165:                                            number = Long
08166:                                                    .parseLong(pstmtColumnValue);
08167:                                        pstmt.setLong(i + 1, number);
08168:                                        strQuery = strQuery + pstmtColumnValue
08169:                                                + ",";
08170:                                    } else {
08171:                                        pstmt.setNull(i + 1,
08172:                                                java.sql.Types.DOUBLE);
08173:                                        strQuery = strQuery + "null" + ",";
08174:                                    }
08175:                                } else if (javaTypeInt == 7) { // java.lang.Short
08176:                                    if (!pstmtColumnValue
08177:                                            .equalsIgnoreCase("null")) {
08178:                                        short number = 0;
08179:                                        if (!pstmtColumnValue
08180:                                                .equalsIgnoreCase(""))
08181:                                            number = Short
08182:                                                    .parseShort(pstmtColumnValue);
08183:                                        pstmt.setShort(i + 1, number);
08184:                                        strQuery = strQuery + pstmtColumnValue
08185:                                                + ",";
08186:                                    } else {
08187:                                        pstmt.setNull(i + 1,
08188:                                                java.sql.Types.SMALLINT);
08189:                                        strQuery = strQuery + "null" + ",";
08190:                                    }
08191:                                } else if (javaTypeInt == 8) { // java.lang.String
08192:                                    if (!pstmtColumnValue
08193:                                            .equalsIgnoreCase("null")) {
08194:                                        // all '' back to ' (original value)
08195:                                        if (pstmtColumnValue.indexOf("''") != -1) {
08196:                                            pstmtColumnValue = Utils
08197:                                                    .replaceAll(
08198:                                                            pstmtColumnValue,
08199:                                                            "''", "'");
08200:                                        }
08201:                                        pstmt
08202:                                                .setString(i + 1,
08203:                                                        pstmtColumnValue);
08204:                                        strQuery = strQuery + "'"
08205:                                                + pstmtColumnValue + "'" + ",";
08206:                                    } else {
08207:                                        pstmt.setNull(i + 1,
08208:                                                java.sql.Types.VARCHAR);
08209:                                        strQuery = strQuery + "null" + ",";
08210:
08211:                                    }
08212:                                } else if (javaTypeInt == 9) { // java.sql.Date
08213:                                    if (!pstmtColumnValue
08214:                                            .equalsIgnoreCase("null")) {
08215:                                        if (pstmtColumnValueAsObject instanceof  java.sql.Date)
08216:                                            pstmt
08217:                                                    .setDate(
08218:                                                            i + 1,
08219:                                                            (java.sql.Date) pstmtColumnValueAsObject);
08220:                                        else {
08221:                                            //try {
08222:                                            //    pstmt.setDate(i + 1, new java.sql.Date(getDateFromString(pstmtColumnValue).getTime()));
08223:                                            //} catch (Exception e) {
08224:                                            this .logger.write("full",
08225:                                                    "call setString on date: "
08226:                                                            + pstmtColumnValue);
08227:                                            pstmt.setString(i + 1,
08228:                                                    pstmtColumnValue);
08229:                                            //}
08230:                                        }
08231:                                        strQuery = strQuery + "'"
08232:                                                + pstmtColumnValue + "'" + ",";
08233:                                    } else {
08234:                                        pstmt.setNull(i + 1,
08235:                                                java.sql.Types.DATE);
08236:                                        strQuery = strQuery + "null" + ",";
08237:                                    }
08238:                                } else if (javaTypeInt == 10) { // java.sql.Time
08239:                                    if (!pstmtColumnValue
08240:                                            .equalsIgnoreCase("null")) {
08241:                                        if (pstmtColumnValueAsObject instanceof  Time)
08242:                                            pstmt
08243:                                                    .setTime(
08244:                                                            i + 1,
08245:                                                            (java.sql.Time) pstmtColumnValueAsObject);
08246:                                        else {
08247:                                            // String format =
08248:                                            // this.configReaderSource.getDateFormat();
08249:                                            // SimpleDateFormat formatDate = new
08250:                                            // SimpleDateFormat(format);
08251:                                            // Date tmpDate =
08252:                                            // formatDate.parse(pstmtColumnValue);
08253:                                            try {
08254:                                                pstmt
08255:                                                        .setTime(
08256:                                                                i + 1,
08257:                                                                new java.sql.Time(
08258:                                                                        getDateFromString(
08259:                                                                                pstmtColumnValue)
08260:                                                                                .getTime()));
08261:                                            } catch (Exception e) {
08262:                                                pstmt.setString(i + 1,
08263:                                                        pstmtColumnValue);
08264:                                            }
08265:                                        }
08266:                                        strQuery = strQuery + "'"
08267:                                                + pstmtColumnValue + "'" + ",";
08268:                                    } else {
08269:                                        pstmt.setNull(i + 1,
08270:                                                java.sql.Types.TIME);
08271:                                        strQuery = strQuery + "null" + ",";
08272:                                    }
08273:
08274:                                } else if (javaTypeInt == 11) { // java.sql.Timestamp
08275:                                    if (!pstmtColumnValue
08276:                                            .equalsIgnoreCase("null")) {
08277:                                        if (pstmtColumnValueAsObject instanceof  java.sql.Timestamp)
08278:                                            pstmt
08279:                                                    .setTimestamp(
08280:                                                            i + 1,
08281:                                                            (java.sql.Timestamp) pstmtColumnValueAsObject);
08282:                                        else {
08283:                                            // String format =
08284:                                            // this.configReaderSource.getDateFormat();
08285:                                            // SimpleDateFormat formatDate = new
08286:                                            // SimpleDateFormat(format);
08287:                                            // Date tmpDate =
08288:                                            // formatDate.parse(pstmtColumnValue);
08289:                                            try {
08290:                                                pstmt
08291:                                                        .setTimestamp(
08292:                                                                i + 1,
08293:                                                                new Timestamp(
08294:                                                                        getDateFromString(
08295:                                                                                pstmtColumnValue)
08296:                                                                                .getTime()));
08297:                                            } catch (Exception e) {
08298:                                                pstmt.setString(i + 1,
08299:                                                        pstmtColumnValue);
08300:                                            }
08301:                                        }
08302:                                        strQuery = strQuery + "'"
08303:                                                + pstmtColumnValue + "'" + ",";
08304:                                    } else {
08305:                                        pstmt.setNull(i + 1,
08306:                                                java.sql.Types.TIMESTAMP);
08307:                                        strQuery = strQuery + "null" + ",";
08308:                                    }
08309:
08310:                                } else if (javaTypeInt == 12) { // java.lang.Boolean
08311:                                    if (!pstmtColumnValue
08312:                                            .equalsIgnoreCase("null")) {
08313:                                        boolean bool = new Boolean(
08314:                                                pstmtColumnValue)
08315:                                                .booleanValue();
08316:                                        pstmt.setBoolean(i + 1, bool);
08317:                                        strQuery = strQuery + pstmtColumnValue
08318:                                                + ",";
08319:                                    } else {
08320:                                        pstmt
08321:                                                .setNull(i + 1,
08322:                                                        java.sql.Types.BIT);
08323:                                        strQuery = strQuery + "null" + ",";
08324:                                    }
08325:                                } else if (javaTypeInt == 13) { // java.lang.Byte
08326:                                    if (!pstmtColumnValue
08327:                                            .equalsIgnoreCase("null")) {
08328:                                        pstmt
08329:                                                .setString(i + 1,
08330:                                                        pstmtColumnValue);
08331:                                        strQuery = strQuery + "'"
08332:                                                + pstmtColumnValue + "'" + ",";
08333:                                    } else {
08334:                                        pstmt
08335:                                                .setNull(i + 1,
08336:                                                        java.sql.Types.BIT);
08337:                                        strQuery = strQuery + "null" + ",";
08338:                                    }
08339:                                } else if (javaTypeInt == 14) { // java.lang.Object
08340:                                    if (!pstmtColumnValue
08341:                                            .equalsIgnoreCase("null")) {
08342:                                        pstmt
08343:                                                .setString(i + 1,
08344:                                                        pstmtColumnValue);
08345:                                        strQuery = strQuery + "'"
08346:                                                + pstmtColumnValue + "'" + ",";
08347:                                    } else {
08348:                                        // TODO zoran pogledati ovo
08349:                                        try {
08350:                                            pstmt.setNull(i + 1,
08351:                                                    java.sql.Types.NULL);
08352:                                        } catch (Exception e) {
08353:                                            pstmt.setString(i + 1, null);
08354:                                        }
08355:                                        strQuery = strQuery + "null" + ",";
08356:                                    }
08357:                                } else {
08358:                                    LoaderException le = new LoaderException(
08359:                                            "Exception:",
08360:                                            new Exception(
08361:                                                    "This java type is not supported!"));
08362:                                    this .logger.write("full", le
08363:                                            .getStackTraceAsString());
08364:                                    throw le;
08365:                                }
08366:                            }// end of else (not blob)
08367:                            pstmtColumnValue = null;
08368:                        }
08369:                        strQuery = strQuery.substring(0, strQuery.length() - 1)
08370:                                + ")";
08371:                        this .logger.write("full", "\tQuery '" + strQuery
08372:                                + "' will be executed");
08373:
08374:                        int pstmtInsert = 0;
08375:                        pstmtInsert = pstmt.executeUpdate();
08376:                        // setting the cache value for inseted row
08377:                        // if (pstmtInsert != 0)
08378:                        // this.checkRowCache.setCheckRowValue();
08379:                        pstmt.clearParameters();
08380:                        pstmtValues.clear();
08381:                        pstmtTypes.clear();
08382:
08383:                        // TODO 14.6.2004 ZK Comented this because of problems with
08384:                        // update on counters table which are not needed.
08385:                        // this.counterColumns.updateCounter(this.vecTableTableName.get(iTableInt).toString(),
08386:                        // this.vecTableTableID.get(iTableInt).toString(), c);
08387:
08388:                    } else {
08389:                        // this.checkRowCache.setCheckRowValue();
08390:                    }
08391:                } catch (SQLException ex) {
08392:                    pstmt.clearParameters();
08393:                    pstmtValues.clear();
08394:                    pstmtTypes.clear();
08395:                    LoaderException le = new LoaderException("SQLException: ",
08396:                            (Throwable) ex);
08397:                    if (importDefinitionElement.strDefaultCutOffData
08398:                            .equalsIgnoreCase("true")) {
08399:                        dataCleaning
08400:                                .cutingDataLenght(
08401:                                        this .vecTableTableName.get(iTableInt)
08402:                                                .toString(),
08403:                                        c,
08404:                                        strQuery,
08405:                                        currentRow,
08406:                                        importDefinitionElement.strOnErrorContinueXml,
08407:                                        ex.getMessage(),
08408:                                        importDefinitionElement.strImportDefinitionName,
08409:                                        strQuery);
08410:                    } else if (importDefinitionElement.strOnErrorContinueXml
08411:                            .equalsIgnoreCase("true")) {
08412:                        pstmt.clearParameters();
08413:                        pstmtValues.clear();
08414:                        pstmtTypes.clear();
08415:                        // this.logger.write("full", "\tError in SQL statement: " +
08416:                        // le.getStackCause());
08417:                        this .logger.write("full", "\tError in SQL statement: "
08418:                                + le.getStackTraceAsString());
08419:                        dataCleaning
08420:                                .cleaningInsert(
08421:                                        this .vecTableTableName.get(iTableInt)
08422:                                                .toString(),
08423:                                        c,
08424:                                        currentRow,
08425:                                        "INSERT",
08426:                                        ex.getMessage(),
08427:                                        importDefinitionElement.strImportDefinitionName,
08428:                                        strQuery);
08429:                    } else {
08430:                        pstmt.clearParameters();
08431:                        pstmtValues.clear();
08432:                        pstmtTypes.clear();
08433:                        this .logger.write("normal",
08434:                                "\tError in SQL statement: " + le.getCause());
08435:                        this .logger.write("full", le.getStackTraceAsString());
08436:                        // throw ex;
08437:                        throw le;
08438:                    }
08439:                } catch (NullPointerException ex) {
08440:                    throw ex;
08441:                } catch (Exception ex) {
08442:                    throw ex;
08443:                }
08444:                this .logger.write("full", "\tinsertRow method is finished.");
08445:            }
08446:
08447:            /**
08448:             * Method isRelationColumn checkes if the column(strColumnName) in target
08449:             * table(iTable) is mentioned in relation tags (target column name). If it
08450:             * is, return true, else return false.
08451:             * 
08452:             * @param strColumnName -
08453:             *            Name of target column
08454:             * @param iTable -
08455:             *            Number of target table
08456:             * @return boolean - true if strColumnName is relation target column, false
08457:             *         if it is not.
08458:             */
08459:            private boolean isRelationColumn(String strColumnName, int iTable) {
08460:                boolean bFind = false;
08461:                endFor: for (int i = 0; i < this .vecRelationColumnTargetTableName
08462:                        .size(); i++) {
08463:                    if (this .vecRelationColumnTargetTableName.get(i).toString()
08464:                            .equalsIgnoreCase(
08465:                                    this .vecTableTableName.get(iTable)
08466:                                            .toString())
08467:                            && this .vecRelationColumnTargetTableID.get(i)
08468:                                    .toString().equalsIgnoreCase(
08469:                                            this .vecTableTableID.get(iTable)
08470:                                                    .toString())
08471:                            && this .vecRelationColumnTargetColumnName.get(i)
08472:                                    .toString().equalsIgnoreCase(strColumnName)) {
08473:                        bFind = true;
08474:                        break endFor;
08475:                    }
08476:                }
08477:                return bFind;
08478:            }
08479:
08480:            /**
08481:             * Method checkOidLogic is used to increase the ObjectID value with adding
08482:             * iObjectIDIncrement value. Method puts new value in ObjectID table for
08483:             * current importDefinition. If there is an error, Exception "SQLException"
08484:             * or NullPointerException is thrown.
08485:             * 
08486:             * @param c
08487:             *            Connection to target database.
08488:             * @throws SQLException
08489:             *             Constructs an SQLException object with a reason.
08490:             * @throws NullPointerException
08491:             *             Constructs a NullPointerException with the specified detail
08492:             *             message.
08493:             */
08494:            private void checkOidLogic(Connection c) throws SQLException,
08495:                    NullPointerException {
08496:                String strQuery = "";
08497:                this .logger.write("full", "\tcheckOidLogic method is started.");
08498:                Boolean bTemp = new Boolean("false");
08499:
08500:                if (currentJobName.equalsIgnoreCase("importDefinition")) {
08501:                    for (int i = 0; i < this .iTables; i++) {
08502:                        if (this .vecTableOidLogic.get(i).toString()
08503:                                .equalsIgnoreCase("true")) {
08504:                            bTemp = new Boolean("true");
08505:                        }
08506:                    }
08507:                } else if (currentJobName.equalsIgnoreCase("copyTable")) {
08508:                    if (importDefinitionElement.strCopyTableOidLogic
08509:                            .equalsIgnoreCase("true")) {
08510:                        bTemp = new Boolean("true");
08511:                    }
08512:                }
08513:
08514:                if (bTemp.booleanValue()) {
08515:                    try {
08516:                        if (!(importDefinitionElement.strObjectIDNameColumnName
08517:                                .equals("") || importDefinitionElement.strObjectIDNameColumnValue
08518:                                .equals(""))) {
08519:                            strQuery = new String(
08520:                                    "SELECT "
08521:                                            + importDefinitionElement.strObjectIDColumnName
08522:                                            + " FROM "
08523:                                            + importDefinitionElement.strObjectIDTableName
08524:                                            + " WHERE "
08525:                                            + importDefinitionElement.strObjectIDNameColumnName
08526:                                            + " = '"
08527:                                            + importDefinitionElement.strObjectIDNameColumnValue
08528:                                            + "'");
08529:                        } else {
08530:                            strQuery = new String(
08531:                                    "SELECT "
08532:                                            + importDefinitionElement.strObjectIDColumnName
08533:                                            + " FROM "
08534:                                            + importDefinitionElement.strObjectIDTableName);
08535:                        }
08536:                        this .logger.write("full", "\tQuery '" + strQuery
08537:                                + "' will be executed");
08538:                        Statement stmtOid = c.createStatement();
08539:                        ResultSet rsetOid = stmtOid.executeQuery(strQuery);
08540:                        if (rsetOid.next()) {
08541:                            if (this .iTargetFirstColumnResult == 1)
08542:                                this .bdecOidNumber = new BigDecimal(rsetOid
08543:                                        .getString(1));
08544:                            else
08545:                                this .bdecOidNumber = new BigDecimal(rsetOid
08546:                                        .getString(0));
08547:                        } else {
08548:                            if (!(importDefinitionElement.strObjectIDNameColumnName
08549:                                    .equals("") || importDefinitionElement.strObjectIDNameColumnValue
08550:                                    .equals(""))) {
08551:                                String insert = "insert into "
08552:                                        + importDefinitionElement.strObjectIDTableName
08553:                                        + " ("
08554:                                        + importDefinitionElement.strObjectIDNameColumnName
08555:                                        + ","
08556:                                        + importDefinitionElement.strObjectIDColumnName
08557:                                        + ") values ('"
08558:                                        + importDefinitionElement.strObjectIDNameColumnValue
08559:                                        + "','"
08560:                                        + importDefinitionElement.iObjectIDStartValue
08561:                                        + "');";
08562:                                stmtOid.execute(insert);
08563:                            }
08564:                        }
08565:                        rsetOid.close();
08566:                        stmtOid.close();
08567:
08568:                        if (currentJobName.equalsIgnoreCase("copyTable")) {
08569:                            this .bdecOidNumber2000 = this .bdecOidNumber
08570:                                    .add(new BigDecimal(
08571:                                            importDefinitionElement.iObjectIDCT));
08572:                        } else {
08573:                            this .bdecOidNumber2000 = this .bdecOidNumber
08574:                                    .add(new BigDecimal(
08575:                                            importDefinitionElement.iObjectID));
08576:                        }
08577:                        Statement stmtOid2 = c.createStatement();
08578:                        if (!(importDefinitionElement.strObjectIDNameColumnName
08579:                                .equals("") || importDefinitionElement.strObjectIDNameColumnValue
08580:                                .equals(""))) {
08581:                            this .logger
08582:                                    .write(
08583:                                            "full",
08584:                                            "\tQuery '"
08585:                                                    + "UPDATE "
08586:                                                    + importDefinitionElement.strObjectIDTableName
08587:                                                    + " SET "
08588:                                                    + importDefinitionElement.strObjectIDColumnName
08589:                                                    + " = "
08590:                                                    + this .bdecOidNumber2000
08591:                                                    + " where "
08592:                                                    + importDefinitionElement.strObjectIDNameColumnName
08593:                                                    + " = '"
08594:                                                    + importDefinitionElement.strObjectIDNameColumnValue
08595:                                                    + "'' will be executed");
08596:                            stmtOid2
08597:                                    .executeUpdate("UPDATE "
08598:                                            + importDefinitionElement.strObjectIDTableName
08599:                                            + " SET "
08600:                                            + importDefinitionElement.strObjectIDColumnName
08601:                                            + " = "
08602:                                            + this .bdecOidNumber2000
08603:                                            + " where "
08604:                                            + importDefinitionElement.strObjectIDNameColumnName
08605:                                            + " = '"
08606:                                            + importDefinitionElement.strObjectIDNameColumnValue
08607:                                            + "'");
08608:                        } else {
08609:                            this .logger
08610:                                    .write(
08611:                                            "full",
08612:                                            "\tQuery '"
08613:                                                    + "UPDATE "
08614:                                                    + importDefinitionElement.strObjectIDTableName
08615:                                                    + " SET "
08616:                                                    + importDefinitionElement.strObjectIDColumnName
08617:                                                    + " = "
08618:                                                    + this .bdecOidNumber2000
08619:                                                    + " where "
08620:                                                    + importDefinitionElement.strObjectIDColumnName
08621:                                                    + " = "
08622:                                                    + this .bdecOidNumber
08623:                                                    + "' will be executed");
08624:                            stmtOid2
08625:                                    .executeUpdate("UPDATE "
08626:                                            + importDefinitionElement.strObjectIDTableName
08627:                                            + " SET "
08628:                                            + importDefinitionElement.strObjectIDColumnName
08629:                                            + " = "
08630:                                            + this .bdecOidNumber2000
08631:                                            + " where "
08632:                                            + importDefinitionElement.strObjectIDColumnName
08633:                                            + " = " + this .bdecOidNumber);
08634:                        }
08635:                        stmtOid2.close();
08636:                    } catch (SQLException ex) {
08637:                        throw ex;
08638:                    } catch (NullPointerException ex) {
08639:                        throw ex;
08640:                    }
08641:                }
08642:                this .logger
08643:                        .write("full", "\tcheckOidLogic method is finished.");
08644:            }
08645:
08646:            /**
08647:             * Method querySource is used to make SQL query to source table and to sort
08648:             * columns from source table ordered by sortColumns.
08649:             * 
08650:             * @return SQL Query to source table.
08651:             * @throws LoaderException
08652:             */
08653:            private String querySource() throws LoaderException {
08654:                int i = 0;
08655:                int j = 0;
08656:                this .logger.write("full", "\tquerySource method is started.");
08657:                Vector vecVektor = new Vector();
08658:                String strQuery = "select ";
08659:                // this is pointer where transformations columns starts within result
08660:                // set
08661:                //        this.iOffsetForTransColumns = 0;
08662:                while (i < this .iTables) {
08663:                    vecVektor = (Vector) this .vecSourceColumnName.get(i);
08664:                    //            this.iOffsetForTransColumns += vecVektor.size();
08665:                    while (j < Integer
08666:                            .parseInt(this .vecValueColumnsTargetTables.get(i)
08667:                                    .toString())) {
08668:                        strQuery = strQuery + vecVektor.get(j).toString()
08669:                                + ", ";
08670:                        j++;
08671:                        this .iColumnsInSourceTable++;
08672:                    }
08673:                    j = 0;
08674:                    i++;
08675:                }
08676:                ArrayList trans = this .transformations.getTransformations();
08677:                // int numTransSourceColumns = 0;
08678:                // read all source columns for all transformations
08679:                // i = 0;
08680:                // while (i < this.iTables) {
08681:                for (int k = 0; k < trans.size(); k++) {
08682:                    Transformation transformation = (Transformation) trans
08683:                            .get(k);
08684:                    // if( i != Integer.parseInt( transformation.getTargetTableID() ) )
08685:                    // continue;
08686:                    Vector sourceColumnNames = transformation
08687:                            .getSourceColumnNames();
08688:                    for (int kk = 0; kk < sourceColumnNames.size(); kk++) {
08689:                        strQuery = strQuery
08690:                                + sourceColumnNames.get(kk).toString() + ", ";
08691:                        // numTransSourceColumns++;
08692:                    }
08693:                }
08694:                // this.vecTransformColumnsTargetTables.add(
08695:                // String.valueOf(numTransSourceColumns) );
08696:                // numTransSourceColumns=0;
08697:                // i++;
08698:                // }
08699:                strQuery = strQuery.substring(0, strQuery.length() - 2);
08700:                strQuery += " from "
08701:                        + importDefinitionElement.strImportDefinitionTableName;
08702:                if (importDefinitionElement.vecRestartCounterSortColumn.size() != 0) {
08703:                    if (configReaderSource.getEnableOrderBy()) {
08704:                        strQuery += " order by ";
08705:                        for (j = 0; j < importDefinitionElement.vecRestartCounterSortColumn
08706:                                .size(); j++) {
08707:                            strQuery += importDefinitionElement.vecRestartCounterSortColumn
08708:                                    .get(j).toString()
08709:                                    + ", ";
08710:                        }
08711:                        strQuery = strQuery.substring(0, strQuery.length() - 2);
08712:                    }
08713:                }
08714:
08715:                this .logger.write("full", "\tquerySource method is finished.");
08716:                return strQuery;
08717:            }
08718:
08719:            /**
08720:             * Method targetColumnTypes is used to put source table column types into
08721:             * Vector "vecSourceColumnType". This includes columns from the querySource
08722:             * method. If there is an error, Exception "SQLException" or
08723:             * NullPointerException is thrown.
08724:             * 
08725:             * @param connTarget
08726:             *            Connection to the target table.
08727:             * @throws SQLException
08728:             *             Constructs an SQLException object with a reason.
08729:             * @throws NullPointerException
08730:             *             Constructs a NullPointerException with the specified detail
08731:             *             message.
08732:             */
08733:            private void targetColumnTypes(Connection connTarget)
08734:                    throws SQLException, NullPointerException {
08735:                int iColumn;
08736:                String strQueryTypes = "";
08737:                this .logger.write("full",
08738:                        "\ttargetColumnTypes method is started.");
08739:                try {
08740:                    for (int i = 0; i < this .iTables; i++) {
08741:                        Vector vecKeyTypesRelations = new Vector();
08742:                        Vector vecVektor = new Vector();
08743:                        iColumn = 0;
08744:                        Statement stmtTypes = connTarget.createStatement();
08745:                        // ZK added 11.6.2004 because of new parameter
08746:                        // GetMaxRowsSupported
08747:                        if (this .configReaderTarget.getMaxRowsSupported()) {
08748:                            stmtTypes.setMaxRows(1);
08749:                        }
08750:
08751:                        strQueryTypes = "select ";
08752:                        for (int j = 0; j < ((Vector) this .vecTargetColumnName
08753:                                .get(i)).size(); j++) {
08754:                            strQueryTypes += (((Vector) this .vecTargetColumnName
08755:                                    .get(i)).get(j).toString())
08756:                                    + ",";
08757:                        }
08758:                        for (int j = 0; j < ((Vector) this .vecRelationKeyColumns
08759:                                .get(i)).size(); j++) {
08760:                            strQueryTypes += (((Vector) this .vecRelationKeyColumns
08761:                                    .get(i)).get(j).toString())
08762:                                    + ",";
08763:                        }
08764:                        strQueryTypes = strQueryTypes.substring(0,
08765:                                strQueryTypes.length() - 1);
08766:                        strQueryTypes += " from ";
08767:                        strQueryTypes += " "
08768:                                + this .vecTableTableName.get(i).toString();
08769:
08770:                        if (((Vector) this .vecTargetColumnName.get(i)).size() != 0
08771:                                || ((Vector) this .vecRelationKeyColumns.get(i))
08772:                                        .size() != 0) {
08773:
08774:                            this .logger.write("full", "\tQuery '"
08775:                                    + strQueryTypes + "' will be executed");
08776:                            ResultSet rsetTypes = stmtTypes
08777:                                    .executeQuery(strQueryTypes);
08778:                            for (int j = 0; j < ((Vector) this .vecValueMode
08779:                                    .get(i)).size(); j++) {
08780:                                iColumn++;
08781:                                if (this .iTargetFirstColumnResult == 1)
08782:                                    vecVektor.add(rsetTypes.getMetaData()
08783:                                            .getColumnTypeName(iColumn));
08784:                                else
08785:                                    vecVektor.add(rsetTypes.getMetaData()
08786:                                            .getColumnTypeName(iColumn - 1));
08787:                            }
08788:                            for (int j = 0; j < ((Vector) this .vecRelationKeyColumns
08789:                                    .get(i)).size(); j++) {
08790:                                iColumn++;
08791:                                if (this .iTargetFirstColumnResult == 1)
08792:                                    vecKeyTypesRelations.add(rsetTypes
08793:                                            .getMetaData().getColumnTypeName(
08794:                                                    iColumn));
08795:                                else
08796:                                    vecKeyTypesRelations.add(rsetTypes
08797:                                            .getMetaData().getColumnTypeName(
08798:                                                    iColumn - 1));
08799:                            }
08800:                            rsetTypes.close();
08801:                        }
08802:                        stmtTypes.close();
08803:                        this .vecRelationKeyTypes.setElementAt(
08804:                                vecKeyTypesRelations, i);
08805:                        this .vecTargetColumnType.add(vecVektor);
08806:                    }
08807:                    Statement stmtVariableTypes = connTarget.createStatement();
08808:                    if (this .configReaderTarget.getMaxRowsSupported()) {
08809:                        stmtVariableTypes.setMaxRows(1);
08810:                    }
08811:                    for (int j = 0; j < this .vecVariableColumnTargetTableName
08812:                            .size(); j++) {
08813:                        strQueryTypes = "select ";
08814:                        strQueryTypes += this .vecVariableColumnTargetColumnName
08815:                                .get(j).toString()
08816:                                + " from ";
08817:                        strQueryTypes += this .vecVariableColumnTargetTableName
08818:                                .get(j).toString();
08819:                        ResultSet rsetVariableTypes;
08820:                        this .logger.write("full", "\tQuery '" + strQueryTypes
08821:                                + "' will be executed");
08822:                        rsetVariableTypes = stmtVariableTypes
08823:                                .executeQuery(strQueryTypes);
08824:                        if (this .iTargetFirstColumnResult == 1)
08825:                            this .vecVariableColumnTypes.add(rsetVariableTypes
08826:                                    .getMetaData().getColumnTypeName(1));
08827:                        else
08828:                            this .vecVariableColumnTypes.add(rsetVariableTypes
08829:                                    .getMetaData().getColumnTypeName(0));
08830:                        rsetVariableTypes.close();
08831:                    }
08832:                    stmtVariableTypes.close();
08833:                } catch (SQLException ex) {
08834:                    throw ex;
08835:                } catch (NullPointerException ex) {
08836:                    throw ex;
08837:                }
08838:                this .logger.write("full",
08839:                        "\ttargetColumnTypes method is finished.");
08840:            }
08841:
08842:            /**
08843:             * Metod createCurrentDate is used to create current date and time in format
08844:             * that supported by SQL server.
08845:             * 
08846:             * @return String representation of current date and time.
08847:             */
08848:            private String createCurrentDate() {
08849:
08850:                // it is read from configReaderSource because before call to setDate on
08851:                // target database, it will be parsed using date format
08852:                // from source config and transformed into java.sql.Date
08853:                String strDateTimeFormat = this .configReaderSource
08854:                        .getDateFormat();
08855:                SimpleDateFormat tmpDate = new SimpleDateFormat(
08856:                        strDateTimeFormat);
08857:                String strDate = tmpDate.format(new Date(System
08858:                        .currentTimeMillis()));
08859:                return strDate;
08860:
08861:            }
08862:
08863:            /**
08864:             * Method constantColumnTypes is used to put types of constant columns into
08865:             * global vector sorted in target tables.If there is an error, Exception
08866:             * "SQLException" or "NullPointerException" is thrown.
08867:             * 
08868:             * @param c
08869:             *            Connection to target database.
08870:             * @throws SQLException
08871:             *             Constructs an SQLException object with a reason.
08872:             * @throws NullPointerException
08873:             *             Constructs a NullPointerException with the specified detail
08874:             *             message.
08875:             */
08876:            private void constantColumnTypes(Connection c) throws SQLException,
08877:                    NullPointerException {
08878:                int iCnt = 0;
08879:                this .logger.write("full",
08880:                        "\tconstantColumnTypes method is started.");
08881:                try {
08882:                    for (int i = 0; i < this .iTables; i++) {
08883:                        Vector vecTempConstantType = new Vector();
08884:                        Vector vecTempConstantName = new Vector();
08885:                        String strQuery = "select ";
08886:                        vecTempConstantName = (Vector) this .vecConstantTargetColumnName
08887:                                .get(i);
08888:                        if (vecTempConstantName.size() != 0) {
08889:                            Statement stmtConstant = c.createStatement();
08890:                            for (int j = 0; j < vecTempConstantName.size(); j++)
08891:                                strQuery += vecTempConstantName.get(j)
08892:                                        .toString()
08893:                                        + ", ";
08894:                            strQuery = strQuery.substring(0,
08895:                                    strQuery.length() - 2);
08896:                            strQuery += " from "
08897:                                    + this .vecTableTableName.get(i).toString();
08898:                            this .logger.write("full", "\tQuery '" + strQuery
08899:                                    + "' will be executed");
08900:                            ResultSet rsetConstant = stmtConstant
08901:                                    .executeQuery(strQuery);
08902:                            iCnt = vecTempConstantName.size();
08903:                            for (int k = 0; k < iCnt; k++) {
08904:                                if (this .iTargetFirstColumnResult == 1)
08905:                                    vecTempConstantType.add(rsetConstant
08906:                                            .getMetaData().getColumnTypeName(
08907:                                                    k + 1));
08908:                                else
08909:                                    vecTempConstantType
08910:                                            .add(rsetConstant.getMetaData()
08911:                                                    .getColumnTypeName(k));
08912:                            }
08913:                            rsetConstant.close();
08914:                            stmtConstant.close();
08915:                        }
08916:                        this .vecConstantColumnType.setElementAt(
08917:                                vecTempConstantType, i);
08918:                    }
08919:                } catch (SQLException ex) {
08920:                    throw ex;
08921:                } catch (NullPointerException ex) {
08922:                    throw ex;
08923:                }
08924:                this .logger.write("full",
08925:                        "\tconstantColumnTypes method is finished.");
08926:            }
08927:
08928:            /**
08929:             * Method inputUser is used to give a user the possibility to connect to
08930:             * Source and Target database using user name and password. If missing, user
08931:             * and password parameters for database in XML file, Loader asks user for
08932:             * these parameters. If there is an error, Exception "IOException" is
08933:             * thrown.
08934:             * 
08935:             * @param b
08936:             *            Boolean type. If b is true- source database, false- target
08937:             *            database
08938:             * @throws IOException
08939:             *             Constructs an IOException with the specified detail message.
08940:             */
08941:            private void inputUser(boolean b) throws java.io.IOException {
08942:                if (b) {
08943:                    if (BufferOctopusClass.getInstance().IsUsed())
08944:                        throw new IOException(
08945:                                "Missing user name and password for the Source DB. Check LoaderJob.olj file!");
08946:                    else
08947:                        this .logger
08948:                                .write("normal",
08949:                                        "Missing user name and password for the Source DB.");
08950:                } else {
08951:                    if (BufferOctopusClass.getInstance().IsUsed())
08952:                        throw new IOException(
08953:                                "Missing user name and password for the Target DB. Check LoaderJob.olj file!");
08954:                    else
08955:                        this .logger
08956:                                .write("normal",
08957:                                        "Missing user name and password for the Target DB.");
08958:                }
08959:                String strUserName;
08960:                String strPassword;
08961:                char cu;
08962:                char cp;
08963:                StringBuffer bufu = new StringBuffer();
08964:                StringBuffer bufp = new StringBuffer();
08965:                System.out.println("User name: ");
08966:                try {
08967:                    while ((cu = (char) System.in.read()) != '\n')
08968:                        bufu.append(cu);
08969:                    strUserName = bufu.toString();
08970:                    strUserName = strUserName.substring(0,
08971:                            strUserName.length() - 1);
08972:                    System.out.println("Password: ");
08973:                    while ((cp = (char) System.in.read()) != '\n')
08974:                        bufp.append(cp);
08975:                    strPassword = bufp.toString();
08976:                    if (strPassword.length() != 0)
08977:                        strPassword = strPassword.substring(0, strPassword
08978:                                .length() - 1);
08979:                    if (b) {
08980:                        jdbcParametersElement
08981:                                .setJDBCSourceParameterUser(strUserName);
08982:                        jdbcParametersElement
08983:                                .setJDBCSourceParameterPassword(strPassword);
08984:                    } else {
08985:                        jdbcParametersElement
08986:                                .setJDBCTargetParameterUser(strUserName);
08987:                        jdbcParametersElement
08988:                                .setJDBCTargetParameterPassword(strPassword);
08989:                    }
08990:                } catch (IOException ex) {
08991:                    throw ex;
08992:                }
08993:            }
08994:
08995:            /**
08996:             * Method changeTableOrder change order of Tables into public Vector
08997:             * vecTableTableName Relation source tables puts before the others target
08998:             * tables.
08999:             */
09000:            private void changeTableOrder() {
09001:                Vector vecTempTableTableName = new Vector();
09002:                Vector vecTempTableTableID = new Vector();
09003:                Vector vecTempTableInsert = new Vector();
09004:                Vector vecTempTableTableMode = new Vector();
09005:                Vector vecTempTableOidLogic = new Vector();
09006:                Vector vecNumberOfTable = new Vector();
09007:                for (int i = 0; i < this .vecRelationColumnSourceTableName
09008:                        .size(); i++) {
09009:                    int iNumberOfTable = 0;
09010:                    for (int j = 0; j < this .vecTableTableName.size(); j++) {
09011:                        if (this .vecTableTableName.get(j).toString()
09012:                                .equalsIgnoreCase(
09013:                                        this .vecRelationColumnSourceTableName
09014:                                                .get(i).toString())
09015:                                && this .vecTableTableID
09016:                                        .get(j)
09017:                                        .toString()
09018:                                        .equalsIgnoreCase(
09019:                                                this .vecRelationColumnSourceTableID
09020:                                                        .get(i).toString())) {
09021:                            iNumberOfTable = j;
09022:                            boolean bEqualsRelationSource = false;
09023:                            for (int k = 0; k < vecNumberOfTable.size(); k++) {
09024:                                if (j == (new Integer(vecNumberOfTable.get(k)
09025:                                        .toString())).intValue())
09026:                                    bEqualsRelationSource = true;
09027:                            }
09028:                            if (!bEqualsRelationSource) {
09029:                                vecTempTableTableName
09030:                                        .addElement(this .vecTableTableName.get(
09031:                                                j).toString());
09032:                                vecTempTableTableID
09033:                                        .addElement(this .vecTableTableID.get(j)
09034:                                                .toString());
09035:                                vecTempTableInsert
09036:                                        .addElement(this .vecTableInsert.get(j)
09037:                                                .toString());
09038:                                vecTempTableTableMode
09039:                                        .addElement(this .vecTableTableMode.get(
09040:                                                j).toString());
09041:                                vecTempTableOidLogic
09042:                                        .addElement(this .vecTableOidLogic
09043:                                                .get(j).toString());
09044:                                vecNumberOfTable.addElement(new Integer(
09045:                                        iNumberOfTable));
09046:                            }
09047:                        }
09048:                    }
09049:                }
09050:                if (this .vecRelationColumnSourceTableName.size() != 0) {
09051:                    for (int i = 0; i < this .vecTableTableName.size(); i++) {
09052:                        boolean bEquals = false;
09053:                        for (int j = 0; j < vecNumberOfTable.size(); j++) {
09054:                            if (i == (new Integer(vecNumberOfTable.get(j)
09055:                                    .toString())).intValue()) {
09056:                                bEquals = true;
09057:                            }
09058:                        }
09059:                        if (!bEquals) {
09060:                            vecTempTableTableName
09061:                                    .addElement(this .vecTableTableName.get(i)
09062:                                            .toString());
09063:                            vecTempTableTableID.addElement(this .vecTableTableID
09064:                                    .get(i).toString());
09065:                            vecTempTableInsert.addElement(this .vecTableInsert
09066:                                    .get(i).toString());
09067:                            vecTempTableTableMode
09068:                                    .addElement(this .vecTableTableMode.get(i)
09069:                                            .toString());
09070:                            vecTempTableOidLogic
09071:                                    .addElement(this .vecTableOidLogic.get(i)
09072:                                            .toString());
09073:                        }
09074:                    }
09075:                    this .vecTableTableName = new Vector();
09076:                    this .vecTableTableID = new Vector();
09077:                    this .vecTableInsert = new Vector();
09078:                    this .vecTableTableMode = new Vector();
09079:                    this .vecTableOidLogic = new Vector();
09080:                    for (int i = 0; i < vecTempTableTableName.size(); i++) {
09081:                        this .vecTableTableName.addElement(vecTempTableTableName
09082:                                .get(i).toString());
09083:                        this .vecTableTableID.addElement(vecTempTableTableID
09084:                                .get(i).toString());
09085:                        this .vecTableInsert.addElement(vecTempTableInsert
09086:                                .get(i).toString());
09087:                        this .vecTableTableMode.addElement(vecTempTableTableMode
09088:                                .get(i).toString());
09089:                        this .vecTableOidLogic.addElement(vecTempTableOidLogic
09090:                                .get(i).toString());
09091:                    }
09092:                }
09093:            }
09094:
09095:            /**
09096:             * Method changeRelationsOrder change order of relation tags. Order of
09097:             * relation tags depends of 'complex relations'. Method puts at the begining
09098:             * of relation global Vectors relations which is used only to read source
09099:             * values for another relation.
09100:             * 
09101:             */
09102:            private void changeRelationsOrder() {
09103:                Vector vecTempSourceTableName = new Vector();
09104:                Vector vecTempSourceTableID = new Vector();
09105:                Vector vecTempSourceColumnName = new Vector();
09106:                Vector vecTempTargetTableName = new Vector();
09107:                Vector vecTempTargetTableID = new Vector();
09108:                Vector vecTempTargetColumnName = new Vector();
09109:                Vector vecTempRelationMode = new Vector();
09110:                Vector vecRelationsOrder = new Vector();
09111:                vecRelationsOrder.setSize(this .vecRelationColumnSourceTableName
09112:                        .size());
09113:                for (int i = 0; i < vecRelationsOrder.size(); i++)
09114:                    vecRelationsOrder.setElementAt(new Integer(i), i);
09115:                for (int i = 0; i < this .vecRelationColumnSourceTableName
09116:                        .size(); i++) {
09117:                    if (this .vecRelationColumnRelationMode.get(i).toString()
09118:                            .equalsIgnoreCase("Key")) {
09119:                        for (int j = 0; j < this .vecRelationColumnSourceTableName
09120:                                .size(); j++) {
09121:                            if (this .vecRelationColumnSourceTableName
09122:                                    .get(i)
09123:                                    .toString()
09124:                                    .equalsIgnoreCase(
09125:                                            this .vecRelationColumnTargetTableName
09126:                                                    .get(j).toString())
09127:                                    && this .vecRelationColumnSourceTableID.get(
09128:                                            i).toString().equalsIgnoreCase(
09129:                                            this .vecRelationColumnTargetTableID
09130:                                                    .get(j).toString()))
09131:                                vecRelationsOrder = this .setAfter(
09132:                                        vecRelationsOrder, i, j);
09133:                        }
09134:                    } else {
09135:                        vecRelationsOrder = this .setLast(vecRelationsOrder, i);
09136:                    }
09137:                }
09138:                for (int i = 0; i < this .vecRelationColumnSourceTableName
09139:                        .size(); i++) {
09140:                    vecTempSourceTableName
09141:                            .add(this .vecRelationColumnSourceTableName.get(i));
09142:                    vecTempSourceTableID
09143:                            .add(this .vecRelationColumnSourceTableID.get(i));
09144:                    vecTempSourceColumnName
09145:                            .add(this .vecRelationColumnSourceColumnName.get(i));
09146:                    vecTempTargetTableName
09147:                            .add(this .vecRelationColumnTargetTableName.get(i));
09148:                    vecTempTargetTableID
09149:                            .add(this .vecRelationColumnTargetTableID.get(i));
09150:                    vecTempTargetColumnName
09151:                            .add(this .vecRelationColumnTargetColumnName.get(i));
09152:                    vecTempRelationMode.add(this .vecRelationColumnRelationMode
09153:                            .get(i));
09154:                }
09155:                for (int i = 0; i < this .vecRelationColumnSourceTableName
09156:                        .size(); i++) {
09157:                    this .vecRelationColumnSourceTableName.setElementAt(
09158:                            vecTempSourceTableName.get(Integer
09159:                                    .parseInt(vecRelationsOrder.get(i)
09160:                                            .toString())), i);
09161:                    this .vecRelationColumnSourceTableID.setElementAt(
09162:                            vecTempSourceTableID.get(Integer
09163:                                    .parseInt(vecRelationsOrder.get(i)
09164:                                            .toString())), i);
09165:                    this .vecRelationColumnSourceColumnName.setElementAt(
09166:                            vecTempSourceColumnName.get(Integer
09167:                                    .parseInt(vecRelationsOrder.get(i)
09168:                                            .toString())), i);
09169:                    this .vecRelationColumnTargetTableName.setElementAt(
09170:                            vecTempTargetTableName.get(Integer
09171:                                    .parseInt(vecRelationsOrder.get(i)
09172:                                            .toString())), i);
09173:                    this .vecRelationColumnTargetTableID.setElementAt(
09174:                            vecTempTargetTableID.get(Integer
09175:                                    .parseInt(vecRelationsOrder.get(i)
09176:                                            .toString())), i);
09177:                    this .vecRelationColumnTargetColumnName.setElementAt(
09178:                            vecTempTargetColumnName.get(Integer
09179:                                    .parseInt(vecRelationsOrder.get(i)
09180:                                            .toString())), i);
09181:                    this .vecRelationColumnRelationMode.setElementAt(
09182:                            vecTempRelationMode.get(Integer
09183:                                    .parseInt(vecRelationsOrder.get(i)
09184:                                            .toString())), i);
09185:                }
09186:            }
09187:
09188:            /**
09189:             * Method setLast changes order of vecOrder's elements. Element at
09190:             * iRelationTag position will be removed and inserted at the end of Vector.
09191:             * 
09192:             * @param vecOrder
09193:             *            Vector - order of relation tags
09194:             * @param iRelationTag
09195:             *            integer - position of element in Vector which changes its
09196:             *            position.
09197:             * @return Vector - order of relation tags after changing positions of
09198:             *         elements.
09199:             */
09200:            private Vector setLast(Vector vecOrder, int iRelationTag) {
09201:                int iLast = vecOrder.indexOf(new Integer(iRelationTag));
09202:                vecOrder.remove(iLast);
09203:                vecOrder.add(new Integer(iRelationTag));
09204:                return vecOrder;
09205:            }
09206:
09207:            /**
09208:             * Method setAfter changes order of vecOrder's elements. Element at
09209:             * iIndexCurrent position will be removed and inserted after element at
09210:             * iIndexTarget position.
09211:             * 
09212:             * @param vecOrder
09213:             *            Vector - order of relation tags
09214:             * @param iIndexCurrent
09215:             *            integer - position of element in Vector which changes its
09216:             *            position.
09217:             * @param iIndexTarget
09218:             *            integer - position of 'target' element in Vector .
09219:             * @return Vector - order of relation tags after changing element's
09220:             *         positions.
09221:             */
09222:            Vector setAfter(Vector vecOrder, int iIndexCurrent, int iIndexTarget) {
09223:                if (iIndexCurrent < iIndexTarget) {
09224:                    int iCurrent = vecOrder.indexOf(new Integer(iIndexCurrent));
09225:                    vecOrder.remove(iCurrent);
09226:                    int iTarget = vecOrder.indexOf(new Integer(iIndexTarget));
09227:                    vecOrder.insertElementAt(new Integer(iIndexCurrent),
09228:                            iTarget + 1);
09229:                }
09230:                return vecOrder;
09231:            }
09232:
09233:            /**
09234:             * Method executeSQLStatement is used to execute SQL statement. This method
09235:             * executes and commit changes immediately. JDBC parameters, Continue on
09236:             * Error parameters and SQL statements are set in XML file. If there is an
09237:             * error Exception "Exception" is thrown.
09238:             * 
09239:             * @throws Exception
09240:             */
09241:            private void executeSQLStatement() throws Exception {
09242:                Connection conn = null;
09243:                try {
09244:                    this .logger.write("full",
09245:                            "\tmethod executeSQLStatement is started");
09246:                    // this.logger.write("normal", "SQL statement " + this.strSqlName +
09247:                    // " is started");
09248:                    Class.forName(jdbcParametersElement
09249:                            .getJDBCTargetParameterDriver());
09250:                    conn = DriverManager.getConnection(jdbcParametersElement
09251:                            .getJDBCTargetParameterConnection(),
09252:                            jdbcParametersElement.getJDBCTargetParameterUser(),
09253:                            jdbcParametersElement
09254:                                    .getJDBCTargetParameterPassword());
09255:                    Statement stmtSeparate = conn.createStatement();
09256:                    for (int i = 0; i < this .vecSqlStmt.size(); i++) {
09257:                        this .logger.write("full", "\tSQL_stmt : '"
09258:                                + this .vecSqlStmt.get(i).toString()
09259:                                + "' will be executed");
09260:                        Vector vecSingleSqlStmt = sqlStringToVector(this .vecSqlStmt
09261:                                .get(i).toString());
09262:                        for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
09263:                            executeSql(stmtSeparate, vecSingleSqlStmt.get(j)
09264:                                    .toString(), 0);
09265:                        }
09266:                    }
09267:                    stmtSeparate.close();
09268:                    conn.close();
09269:                } catch (SQLException e) {
09270:                    throw e;
09271:                } finally {
09272:                    if (conn != null && !conn.isClosed())
09273:                        conn.close();
09274:                }
09275:            }
09276:
09277:            /**
09278:             * Method executeSQLStatement is used to execute SQL statement. This method
09279:             * commit changes immediately only if is commit paremeter true. If it is
09280:             * false commit changes after all aql stetements. JDBC parameters, Continue
09281:             * on Error parameters and SQL statements are set in XML file. If there is
09282:             * an error Exception "Exception" is thrown.
09283:             * 
09284:             * @param conn
09285:             *            represents connection to target table
09286:             * @throws Exception
09287:             */
09288:            private void executeSQLStatement(Connection conn) throws Exception {
09289:                try {
09290:                    this .timeCounter.setStartJobTime();
09291:                    this .logger.write("full",
09292:                            "\tmethod executeSQLStatement is started");
09293:                    this .logger.write("normal", "SQL statement "
09294:                            + sqlElement.getSqlName() + " is started");
09295:                    boolean isCreateDatabaseStatement = false;
09296:                    out: for (int i = 0; i < this .vecSqlStmt.size(); i++) {
09297:                        if (this .vecSqlStmt.get(i).toString().toUpperCase()
09298:                                .trim().startsWith("CREATE DATABASE")
09299:                                || this .vecSqlStmt.get(i).toString()
09300:                                        .toUpperCase().trim().startsWith(
09301:                                                "DROP DATABASE")) {
09302:                            isCreateDatabaseStatement = true;
09303:                            break out;
09304:                        }
09305:                    }
09306:                    if (isCreateDatabaseStatement) {
09307:                        executeSQLStatement();
09308:                    } else {
09309:
09310:                        Statement stmtSeparate = conn.createStatement();
09311:                        for (int i = 0; i < this .vecSqlStmt.size(); i++) {
09312:                            this .logger.write("full", "\tSQL_stmt : '"
09313:                                    + this .vecSqlStmt.get(i).toString()
09314:                                    + "' will be executed");
09315:                            Vector vecSingleSqlStmt = sqlStringToVector(this .vecSqlStmt
09316:                                    .get(i).toString());
09317:                            for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
09318:                                executeSql(stmtSeparate, vecSingleSqlStmt
09319:                                        .get(j).toString(), j + 1);
09320:                            }
09321:                        }
09322:                        if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) {
09323:                            if (!conn.getAutoCommit())
09324:                                conn.commit();
09325:                        }
09326:                        stmtSeparate.close();
09327:                    }
09328:
09329:                    this .logger.write("normal", "SQL statement "
09330:                            + sqlElement.getSqlName() + " is finished");
09331:                    this .logger.write("full",
09332:                            "\tmethod executeSQLStatement is finished");
09333:                    this .logger.write("normal", " Duration :"
09334:                            + this .timeCounter.getJobTime());
09335:                } catch (SQLException e) {
09336:                    throw e;
09337:                }
09338:            }
09339:
09340:            /**
09341:             * Method sqlStringToVector is used to cut Sql string with number of
09342:             * statements into vector whose elements are single Sql statemnets.
09343:             * 
09344:             * @param sql
09345:             *            Sql string with number of statements.
09346:             * @return vector of sql statemetns
09347:             */
09348:            private Vector sqlStringToVector(String sql) {
09349:                Vector vecSqlString = new Vector();
09350:                int i = sql.indexOf(";");
09351:                if (i != -1) {
09352:                    while (i != -1) {
09353:                        // vecSqlString.add(sql.substring(0, i + 1));
09354:                        vecSqlString.add(sql.substring(0, i));
09355:                        sql = sql.substring(i + 1);
09356:                        i = sql.indexOf(";");
09357:                    }
09358:                } else
09359:
09360:                    // vecSqlString.add(sql.trim() + ";");
09361:                    vecSqlString.add(sql.trim());
09362:                return vecSqlString;
09363:            }
09364:
09365:            /**
09366:             * Method executeSql is used to execute singl Sql statement. If there is an
09367:             * error depends on OnErrorContinue parameter throws exception or not. Error
09368:             * message is always shown. If there is an error, message with the error
09369:             * message, statement and number of statement is shown.
09370:             * 
09371:             * @param stmtSql
09372:             *            Statement.
09373:             * @param sqlStmt
09374:             *            Sql statement to execute.
09375:             * @param i
09376:             *            Number of the Sql statement.
09377:             * @throws SQLException
09378:             */
09379:            private void executeSql(Statement stmtSql, String sqlStmt, int i)
09380:                    throws SQLException {
09381:                try {
09382:                    if (bReplaceInData) {
09383:                        sqlStmt = this .replaceInData(sqlStmt);
09384:                    }
09385:                    sqlStmt.trim();
09386:                    if (sqlStmt.length() != 0)
09387:                        stmtSql.execute(sqlStmt);
09388:                } catch (SQLException e) {
09389:                    if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase(
09390:                            "true")) {
09391:                        if (sqlElement.getSqlCommit().equalsIgnoreCase("true"))
09392:                            this .logger
09393:                                    .write(
09394:                                            "normal",
09395:                                            "\t Error in SQL statement: "
09396:                                                    + sqlStmt
09397:                                                    + "  executing SQL statements continue...");
09398:                        else
09399:                            this .logger
09400:                                    .write(
09401:                                            "normal",
09402:                                            "\t Error in SQL statement: "
09403:                                                    + sqlStmt
09404:                                                    + "  \n\tStatement is number: "
09405:                                                    + i
09406:                                                    + " all statements before it is not commited, executing SQL statements continue...");
09407:                        LoaderException le = new LoaderException(
09408:                                "SQLException: ", (Throwable) e);
09409:                        this .logger.write("full", le.getStackTraceAsString());
09410:                        // this.logger.write("normal", "\t " + e.getMessage());
09411:                    } else {
09412:                        this .logger.write("normal",
09413:                                "\t Error in SQL statement: " + sqlStmt);
09414:                        throw e;
09415:                    }
09416:                }
09417:            }
09418:
09419:            /**
09420:             * Method checkSortColumns checks if sort columns in source table have
09421:             * unique values. If source table have more rows with equal values in sort
09422:             * columns return true, if not return false.
09423:             * 
09424:             * @param connSource -
09425:             *            Connection to the source table.
09426:             * @return boolean - true - source table has more rows with equal values in
09427:             *         sort columns, false - if source table has unique values in sort
09428:             *         columns.
09429:             * @throws LoaderException
09430:             *             with the specified detail message.
09431:             */
09432:            private boolean checkSortColumns(Connection connSource)
09433:                    throws LoaderException {
09434:                boolean isEqualValues = false;
09435:                String strQuery = "select ";
09436:                try {
09437:                    this .logger.write("full",
09438:                            "\tmethod checkSortColumns is started");
09439:                    for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
09440:                            .size(); i++)
09441:                        strQuery += importDefinitionElement.vecRestartCounterSortColumn
09442:                                .get(i).toString()
09443:                                + ",";
09444:                    strQuery = strQuery.substring(0, strQuery.length() - 1);
09445:                    strQuery += " from "
09446:                            + importDefinitionElement.strImportDefinitionTableName;
09447:                    strQuery += " order by ";
09448:                    for (int j = 0; j < importDefinitionElement.vecRestartCounterSortColumn
09449:                            .size(); j++)
09450:                        strQuery += importDefinitionElement.vecRestartCounterSortColumn
09451:                                .get(j).toString()
09452:                                + ", ";
09453:                    strQuery = strQuery.substring(0, strQuery.length() - 2);
09454:                    this .logger.write("full", "\tQuery '" + strQuery
09455:                            + "'  executes");
09456:                    Statement stmtSort = connSource.createStatement();
09457:                    ResultSet rsetSort = stmtSort.executeQuery(strQuery);
09458:                    endWhile: while (rsetSort.next()) {
09459:                        Vector vecSortNewValues = new Vector();
09460:                        for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
09461:                                .size(); i++)
09462:                            vecSortNewValues.add(rsetSort.getString(i + 1));
09463:                        if (vecSortNewValues.equals(this .vecSortValues)) {
09464:                            isEqualValues = true;
09465:                            break endWhile;
09466:                        } else {
09467:                            this .vecSortValues = new Vector();
09468:                            for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
09469:                                    .size(); i++)
09470:                                this .vecSortValues.add(vecSortNewValues.get(i));
09471:                        }
09472:                    }
09473:                    rsetSort.close();
09474:                    stmtSort.close();
09475:                } catch (SQLException e) {
09476:                    LoaderException le = new LoaderException("SQLException: ",
09477:                            (Throwable) e);
09478:                    // this.logger.write("normal", le.getCause().toString());
09479:                    this .logger.write("full", le.getStackTraceAsString());
09480:                    throw le;
09481:                }
09482:                this .logger.write("full",
09483:                        "\tmethod checkSortColumns is finished");
09484:                return isEqualValues;
09485:            }
09486:
09487:            /**
09488:             * put your documentation comment here
09489:             * 
09490:             * @param conn
09491:             *            represents connection
09492:             * @exception LoaderException
09493:             */
09494:            private void createObjectIDTable(Connection conn)
09495:                    throws LoaderException {
09496:                try {
09497:                    Statement stmt = conn.createStatement();
09498:                    String sqlStmt = "";
09499:                    if (!(importDefinitionElement.strObjectIDNameColumnName
09500:                            .equals("") || importDefinitionElement.strObjectIDNameColumnValue
09501:                            .equals(""))) {
09502:                        sqlStmt = "create table "
09503:                                + importDefinitionElement.strObjectIDTableName
09504:                                + " ("
09505:                                + importDefinitionElement.strObjectIDColumnName
09506:                                + " VARCHAR(30) ,"
09507:                                + importDefinitionElement.strObjectIDNameColumnName
09508:                                + " VARCHAR(30)) NOT NULL;";
09509:
09510:                    } else {
09511:                        sqlStmt = "create table "
09512:                                + importDefinitionElement.strObjectIDTableName
09513:                                + " ("
09514:                                + importDefinitionElement.strObjectIDColumnName
09515:                                + " DECIMAL(19,0) NOT NULL);";
09516:                    }
09517:                    stmt.execute(sqlStmt);
09518:                    String insert = "";
09519:                    if (!(importDefinitionElement.strObjectIDNameColumnName
09520:                            .equals("") || importDefinitionElement.strObjectIDNameColumnValue
09521:                            .equals(""))) {
09522:                        insert = "insert "
09523:                                + importDefinitionElement.strObjectIDTableName
09524:                                + " ("
09525:                                + importDefinitionElement.strObjectIDNameColumnName
09526:                                + ","
09527:                                + importDefinitionElement.strObjectIDColumnName
09528:                                + ") values ('"
09529:                                + importDefinitionElement.strObjectIDNameColumnValue
09530:                                + "','"
09531:                                + importDefinitionElement.iObjectIDStartValue
09532:                                + "');";
09533:                    } else {
09534:                        insert = "insert "
09535:                                + importDefinitionElement.strObjectIDTableName
09536:                                + " ("
09537:                                + importDefinitionElement.strObjectIDColumnName
09538:                                + ") values ("
09539:                                + importDefinitionElement.iObjectIDStartValue
09540:                                + ");";
09541:                    }
09542:                    if (bReplaceInData) {
09543:                        insert = this .replaceInData(insert);
09544:                    }
09545:                    stmt.execute(insert);
09546:                    conn.commit();
09547:                    stmt.close();
09548:                } catch (SQLException e) {
09549:                    LoaderException le = new LoaderException("SQLException: ",
09550:                            (Throwable) e);
09551:                    // this.logger.write("normal", le.getCause().toString());
09552:                    this .logger.write("full", le.getStackTraceAsString());
09553:                    throw le;
09554:                }
09555:            }
09556:
09557:            /**
09558:             * put your documentation comment here
09559:             * 
09560:             * @param values
09561:             *            represents map values
09562:             * @return those values
09563:             */
09564:            private static Map convertToMap(String values) {
09565:                Map mapValues = new HashMap();
09566:                int i = values.indexOf(";");
09567:                int k = 0;
09568:                String part = new String(values);
09569:                if (i != -1) {
09570:                    while (i != -1) {
09571:                        part = new String(values.substring(k, k + i));
09572:                        int j = part.indexOf("=");
09573:                        String strObject = part.substring(0, j);
09574:                        String strValue = part.substring(j + 1);
09575:                        if (strValue.equals(""))
09576:                            strValue = null;
09577:                        mapValues.put(strObject, strValue);
09578:                        k += i + 1;
09579:                        i = values.substring(k).indexOf(";");
09580:                    }
09581:                    if (!(values.substring(k).trim().equals("") || values
09582:                            .substring(k).trim().equals(";"))) {
09583:                        part = new String(values.substring(k));
09584:                        int j = part.indexOf("=");
09585:                        String strObject = part.substring(0, j);
09586:                        String strValue = part.substring(j + 1);
09587:                        if (strValue.equals(""))
09588:                            strValue = null;
09589:                        mapValues.put(strObject, strValue);
09590:                    }
09591:                } else {
09592:                    int j = values.indexOf("=");
09593:                    String strObject = values.substring(k, j);
09594:                    String strValue = values.substring(j + 1);
09595:                    if (strValue.equals(""))
09596:                        strValue = null;
09597:                    mapValues.put(strObject, strValue);
09598:                }
09599:                return mapValues;
09600:            }
09601:
09602:            /**
09603:             * Method replaceInData replace data in string if there is the same variable
09604:             * as in attribut prefix+name+suffix in variable tag.
09605:             * 
09606:             * @param s -
09607:             *            String to replace.
09608:             * @return s
09609:             */
09610:            private String replaceInData(String s) {
09611:                // going throw vector
09612:                for (int k = 0; k < this .vecReplaceInData.size(); k++) {
09613:                    // if this is to change...
09614:                    if (this .vecReplaceInData.get(k).toString()
09615:                            .equalsIgnoreCase("true")) {
09616:                        String sPreNameSu = this .vecVariablePrefix.get(k)
09617:                                .toString()
09618:                                + this .vecVariableName.get(k).toString()
09619:                                + this .vecVariableSufix.get(k).toString();
09620:                        int j = s.indexOf(sPreNameSu);
09621:                        // if costant is variable
09622:                        while (j != -1) {
09623:                            s = s.substring(0, j)
09624:                                    + this .vecVariableValue.get(k).toString()
09625:                                    + s.substring(j + sPreNameSu.length(), s
09626:                                            .length());
09627:                            j = s.indexOf(sPreNameSu);
09628:                        }
09629:                    }
09630:                }
09631:                return s;
09632:            }
09633:
09634:            /**
09635:             * Method replaceInSelectStatement replace data in string if there is the
09636:             * same variable as in attribut prefix+name+suffix in variable tag.
09637:             * 
09638:             * @param s -
09639:             *            String to replace.
09640:             * @return s
09641:             */
09642:            // private String replaceInSelectStatement(String s) {
09643:            // // going throw vector
09644:            // for (int k = 0; k < this.vecVariableValue.size(); k++) {
09645:            // if( this.vecReplaceInSQL.get(k).toString().equalsIgnoreCase("false"))
09646:            // continue;
09647:            // String sPreNameSu = this.vecVariablePrefix.get(k).toString()
09648:            // + this.vecVariableName.get(k).toString() +
09649:            // this.vecVariableSufix.get(k).toString();
09650:            // int j = s.indexOf(sPreNameSu);
09651:            //		  
09652:            // while (j != -1) {
09653:            // s = s.substring(0, j) + this.vecVariableValue.get(k).toString()
09654:            // + s.substring(j + sPreNameSu.length(), s.length());
09655:            // j = s.indexOf(sPreNameSu);
09656:            // }
09657:            // }
09658:            // return s;
09659:            // }
09660:            /**
09661:             * @param s -
09662:             *            String to replace.
09663:             * @param oldChar -
09664:             *            Char
09665:             * @param newValue -
09666:             *            String
09667:             * @return s
09668:             */
09669:            private String replaceChar(String s, char oldChar, String newValue) {
09670:
09671:                int j = s.indexOf(oldChar);
09672:                String replacedString = "";
09673:                while (j != -1) {
09674:                    replacedString = replacedString + s.substring(0, j)
09675:                            + newValue;
09676:                    s = s.substring(j + 1);
09677:                    j = s.indexOf(oldChar);
09678:                }
09679:                replacedString = replacedString + s;
09680:                return replacedString;
09681:            }
09682:
09683:            /**
09684:             * Method resetGlobalVariables reset all global variables to the start
09685:             * values after each importDefinition job.
09686:             */
09687:            private void resetGlobalVariables() {
09688:                importDefinitionElement.strImportDefinitionName = "";
09689:                importDefinitionElement.strImportDefinitionTableName = "";
09690:                importDefinitionElement.iImportDefinitionCommitCount = 0;
09691:                // importDefinitionElement.strImportDefinitionLogMode = "normal";
09692:                importDefinitionElement.strImportDefinitionSelectStatement = "";
09693:                importDefinitionElement.bObjectIDAutoCreate = loaderJobReader
09694:                        .getDefaultObjectIDAutoCreate();
09695:                importDefinitionElement.iObjectIDStartValue = loaderJobReader
09696:                        .getDefaultObjectIDStartValue();
09697:
09698:                importDefinitionElement.vecRestartCounterSortColumn = new Vector();
09699:                this .iValueColumns = 0;
09700:                this .vecValueColumnsTargetTables = new Vector();
09701:                // this.vecTransformColumnsTargetTables = new Vector();
09702:                this .vecSourceColumnName = new Vector();
09703:                this .vecTargetColumnName = new Vector();
09704:                this .vecValueMode = new Vector();
09705:                this .vecTargetColumnValue = new Vector();
09706:                this .vecTargetKeyColumnName = new Vector();
09707:                this .iConstantColumns = 0;
09708:                this .vecConstantTargetColumnName = new Vector();
09709:                this .vecConstantValueMode = new Vector();
09710:                this .vecConstantConstantValue = new Vector();
09711:                this .vecConstantColumnTargetTableName = new Vector();
09712:                this .vecConstantColumnTargetTableID = new Vector();
09713:                this .iRelationColumns = 0;
09714:                this .vecRelationColumnSourceTableName = new Vector();
09715:                this .vecRelationColumnSourceTableID = new Vector();
09716:                this .vecRelationColumnSourceColumnName = new Vector();
09717:                this .vecRelationColumnTargetTableName = new Vector();
09718:                this .vecRelationColumnTargetColumnName = new Vector();
09719:                this .vecRelationColumnTargetTableID = new Vector();
09720:                this .vecRelationColumnRelationMode = new Vector();
09721:                this .iTables = 0;
09722:                this .vecTableTableName = new Vector();
09723:                this .vecTableTableID = new Vector();
09724:                this .vecTableInsert = new Vector();
09725:                this .vecTableTableMode = new Vector();
09726:                this .vecTableOidLogic = new Vector();
09727:                this .vecRelationSourceValue = new Vector();
09728:                this .vecRelationSourceType = new Vector();
09729:                this .vecTargetColumnType = new Vector();
09730:                this .vecConstantColumnType = new Vector();
09731:                this .bdecOidNumber = new BigDecimal(0);
09732:                this .bdecOidNumber2000 = new BigDecimal(0);
09733:                importDefinitionElement.iObjectID = 0;
09734:                importDefinitionElement.iObjectIDCT = 0;
09735:                importDefinitionElement.strObjectIDTableName = "";
09736:                importDefinitionElement.strObjectIDColumnName = "";
09737:                // TOS
09738:                importDefinitionElement.strObjectIDNameColumnName = "";
09739:                importDefinitionElement.strObjectIDNameColumnValue = "";
09740:
09741:                this .vecVariableUseIDTableName = new Vector();
09742:                this .vecVariableUseIDTableID = new Vector();
09743:                this .vecVariableUseIDColumnName = new Vector();
09744:                this .vecVariableUseIDValueMode = new Vector();
09745:                this .vecVariableColumnName = new Vector();
09746:                this .vecVariableColumnTargetTableName = new Vector();
09747:                this .vecVariableColumnTargetTableID = new Vector();
09748:                this .vecVariableColumnTargetColumnName = new Vector();
09749:                this .vecVariableColumnValueMode = new Vector();
09750:                this .vecVariableColumnTypes = new Vector();
09751:                this .vecVariableTimesTableName = new Vector();
09752:                this .vecVariableTimesTableID = new Vector();
09753:                this .vecVariableTimesColumnName = new Vector();
09754:                this .vecVariableTimesValueMode = new Vector();
09755:                this .vecRelationKeyColumns = new Vector();
09756:                this .vecRelationKeyTypes = new Vector();
09757:                this .vecSortValues = new Vector();
09758:                this .vecSqlStmt = new Vector();
09759:                this .strSourceDriverName = "";
09760:                this .strTargetDriverName = "";
09761:                this .iFirstColumnResult = 1;
09762:                this .iTargetFirstColumnResult = 1;
09763:                this .iColumnsInSourceTable = 0;
09764:                // copy table
09765:                this .vecCTAutoMapp = new Vector();
09766:                this .vecCTDefaultMode = new Vector();
09767:                this .vecBlobVector = new Vector();
09768:                // added for transformations
09769:                this .transformationsColumnNames = new Vector();
09770:                this .indexDTransformationOver = new Hashtable();
09771:                this .indexDTransformationNull = new Hashtable();
09772:                this .transformationsValueModes = new Vector();
09773:                this .transformationsColumnTypes = new Vector();
09774:                this .transformationValues = new Vector();
09775:
09776:            }
09777:
09778:            private String replaceFirst(String input, String forReplace,
09779:                    String replaceWith) {
09780:                String retVal = input;
09781:                int start = input.indexOf(forReplace);
09782:                int end = start + forReplace.length();
09783:                if (start != -1) {
09784:                    retVal = input.substring(0, start) + replaceWith
09785:                            + input.substring(end);
09786:                }
09787:                return retVal;
09788:            }
09789:
09790:            /**
09791:             * This method write values for all input parameters to log file when log
09792:             * level is full
09793:             * 
09794:             * @throws LoaderException
09795:             */
09796:            public String inputToString() throws LoaderException {
09797:                String resString = "";
09798:                try {
09799:                    logger.write("full", "Log mode =" + getDefaultLogMode());
09800:                    logger.write("full", "Restart indicator ="
09801:                            + getRestartIndicator());
09802:                    logger.write("full", "UserID =" + getUserID());
09803:                    Hashtable resHashtable = new Hashtable();
09804:                    resHashtable = (Hashtable) getVariableValues();
09805:                    String pom2 = "";
09806:
09807:                    if (resHashtable != null) {
09808:                        logger.write("full", "Variables ="
09809:                                + resHashtable.toString());
09810:                        pom2 = "Variables =" + resHashtable.toString();
09811:                    } else {
09812:                        logger.write("full", "Variables = null");
09813:                        pom2 = "Variables = null";
09814:                    }
09815:                    logger.write("full", "Log directory =" + getLogDirName());
09816:                    logger.write("full", "Log file name =" + getLogFileName());
09817:                    logger.write("full", "LoadJob file name ="
09818:                            + getLoadJobFileName());
09819:                    logger.write("full", "On error continue ="
09820:                            + getOnErrorContinue());
09821:                    logger.write("full", "Commit count =" + getCommitCount());
09822:                    logger.write("full", "Return code ="
09823:                            + getDefaultReturnCode());
09824:                    logger.write("full", "Vendor conf file ="
09825:                            + getVendorFileName());
09826:
09827:                    logger.write("full", "Include list =");
09828:                    String pom1 = "";
09829:                    pom1 = "Include list =";
09830:                    String[] listOfJobs = getIncludedJobs();
09831:                    for (int j = 0; j < listOfJobs.length; j++) {
09832:                        logger.write("full", listOfJobs[j].toString());
09833:                        pom1 += listOfJobs[j].toString() + "\n";
09834:                    }
09835:                    logger.write("full", "Path to conf files in jar ="
09836:                            + getConfJarStructure());
09837:                    logger.write("full", "Additional paths ="
09838:                            + getAdditionalPaths());
09839:                    resString = "Log mode =" + getDefaultLogMode() + "\n"
09840:                            + "Restart indicator =" + getRestartIndicator()
09841:                            + "\n" + "UserID =" + getUserID() + "\n" + pom2
09842:                            + "\n" + "Log directory =" + getLogDirName() + "\n"
09843:                            + "Log file name =" + getLogFileName() + "\n"
09844:                            + "LoadJob file name =" + getLoadJobFileName()
09845:                            + "\n" + "On error continue ="
09846:                            + getOnErrorContinue() + "\n" + "Commit count ="
09847:                            + getCommitCount() + "\n" + "Return code ="
09848:                            + getDefaultReturnCode() + "\n"
09849:                            + "Vendor conf file =" + getVendorFileName() + "\n"
09850:                            + pom1 + "\n" + "Path to conf files in jar ="
09851:                            + getConfJarStructure() + "\n"
09852:                            + "Additional paths =" + getAdditionalPaths()
09853:                            + "\n";
09854:
09855:                    return resString;
09856:                } catch (Exception e) {
09857:
09858:                    LoaderException le = new LoaderException("Exception:"
09859:                            + e.getMessage(), e);
09860:                    this .logger.write("full", le.getStackTraceAsString());
09861:                    throw le;
09862:                }
09863:
09864:            }
09865:
09866:            protected java.util.Date getDateFromString(String date)
09867:                    throws Exception {
09868:                Date tmpDate = null;
09869:                try {
09870:                    this .logger.write("full",
09871:                            "Try to parse date with src config: " + date);
09872:                    String format = this .configReaderSource.getDateFormat();
09873:                    SimpleDateFormat formatDate = new SimpleDateFormat(format);
09874:                    tmpDate = formatDate.parse(date);
09875:                } catch (ParseException e) {
09876:                    try {
09877:                        this .logger
09878:                                .write("full",
09879:                                        "Try to parse date with target config: "
09880:                                                + date);
09881:                        String format = this .configReaderTarget.getDateFormat();
09882:                        SimpleDateFormat formatDate = new SimpleDateFormat(
09883:                                format);
09884:                        tmpDate = formatDate.parse(date);
09885:                    } catch (ParseException e1) {
09886:                    }
09887:                }
09888:                if (tmpDate != null) {
09889:                    return tmpDate;
09890:                } else {
09891:                    throw new LoaderException("Unable to parse date: " + date);
09892:                }
09893:            }
09894:
09895:            protected void setValueOnStatement(String value, int javaTypeInt,
09896:                    int i, PreparedStatement pstmt) throws Exception {
09897:                if (javaTypeInt == 2) { // java.math.BigDecimal
09898:                    if (!value.equalsIgnoreCase("null")) {
09899:                        BigDecimal number = new BigDecimal(0);
09900:                        if (!value.equalsIgnoreCase(""))
09901:                            number = new BigDecimal(value);
09902:                        pstmt.setBigDecimal(i, number);
09903:                    } else {
09904:                        pstmt.setNull(i, java.sql.Types.DECIMAL);
09905:                    }
09906:                } else if (javaTypeInt == 3) { // java.lang.Double
09907:                    if (!value.equalsIgnoreCase("null")) {
09908:                        double number = 0;
09909:                        if (!value.equalsIgnoreCase(""))
09910:                            number = Double.parseDouble(value);
09911:                        pstmt.setDouble(i, number);
09912:                    } else {
09913:                        pstmt.setNull(i, java.sql.Types.DOUBLE);
09914:                    }
09915:                } else if (javaTypeInt == 4) { // java.lang.Float
09916:                    if (!value.equalsIgnoreCase("null")) {
09917:                        float number = 0;
09918:                        if (!value.equalsIgnoreCase(""))
09919:                            number = Float.parseFloat(value);
09920:                        pstmt.setFloat(i, number);
09921:                    } else {
09922:                        pstmt.setNull(i, java.sql.Types.FLOAT);
09923:                    }
09924:                } else if (javaTypeInt == 5) { // java.lang.Integer
09925:                    if (!value.equalsIgnoreCase("null")) {
09926:                        int number = 0;
09927:                        if (!value.equalsIgnoreCase(""))
09928:                            number = Integer.parseInt(value);
09929:                        pstmt.setInt(i, number);
09930:                    } else {
09931:                        pstmt.setNull(i, java.sql.Types.INTEGER);
09932:                    }
09933:
09934:                } else if (javaTypeInt == 6) { // java.lang.Long
09935:                    if (!value.equalsIgnoreCase("null")) {
09936:                        long number = 0;
09937:                        if (!value.equalsIgnoreCase(""))
09938:                            number = Long.parseLong(value);
09939:                        pstmt.setLong(i, number);
09940:                    } else {
09941:                        pstmt.setNull(i, java.sql.Types.DOUBLE);
09942:                    }
09943:                } else if (javaTypeInt == 7) { // java.lang.Short
09944:                    if (!value.equalsIgnoreCase("null")) {
09945:                        short number = 0;
09946:                        if (!value.equalsIgnoreCase(""))
09947:                            number = Short.parseShort(value);
09948:                        pstmt.setShort(i, number);
09949:                    } else {
09950:                        pstmt.setNull(i, java.sql.Types.SMALLINT);
09951:                    }
09952:                } else if (javaTypeInt == 8) { // java.lang.String
09953:                    if (!value.equalsIgnoreCase("null")) {
09954:                        // all '' back to ' (original value)
09955:                        if (value.indexOf("''") != -1) {
09956:                            value = Utils.replaceAll(value, "''", "'");
09957:                        }
09958:                        pstmt.setString(i, value);
09959:                    } else {
09960:                        pstmt.setNull(i, java.sql.Types.VARCHAR);
09961:                    }
09962:                } else if (javaTypeInt == 9) { // java.sql.Date
09963:                    if (!value.equalsIgnoreCase("null")) {
09964:                        // String format = this.configReaderSource.getDateFormat();
09965:                        // SimpleDateFormat formatDate = new SimpleDateFormat(format);
09966:                        // Date tmpDate = formatDate.parse(value);
09967:                        try {
09968:                            pstmt.setDate(i, new java.sql.Date(
09969:                                    getDateFromString(value).getTime()));
09970:                        } catch (Exception e) {
09971:                            this .logger.write("normal",
09972:                                    "call setString on date: " + value);
09973:                            pstmt.setString(i, value);
09974:                        }
09975:                        // }
09976:
09977:                    } else {
09978:                        pstmt.setNull(i, java.sql.Types.DATE);
09979:                    }
09980:                } else if (javaTypeInt == 10) { // java.sql.Time
09981:                    if (!value.equalsIgnoreCase("null")) {
09982:                        // String format = this.configReaderSource.getDateFormat();
09983:                        // SimpleDateFormat formatDate = new SimpleDateFormat(format);
09984:                        // Date tmpDate = formatDate.parse(value);
09985:                        try {
09986:                            pstmt.setTime(i, new java.sql.Time(
09987:                                    getDateFromString(value).getTime()));
09988:                        } catch (Exception e) {
09989:                            pstmt.setString(i, value);
09990:                        }
09991:                    } else {
09992:                        pstmt.setNull(i, java.sql.Types.TIME);
09993:                    }
09994:
09995:                } else if (javaTypeInt == 11) { // java.sql.Timestamp
09996:                    if (!value.equalsIgnoreCase("null")) {
09997:                        // String format = this.configReaderSource.getDateFormat();
09998:                        // SimpleDateFormat formatDate = new SimpleDateFormat(format);
09999:                        // Date tmpDate = formatDate.parse(value);
10000:                        try {
10001:                            pstmt.setTimestamp(i, new Timestamp(
10002:                                    getDateFromString(value).getTime()));
10003:                        } catch (Exception e) {
10004:                            pstmt.setString(i, value);
10005:                        }
10006:                    } else {
10007:                        pstmt.setNull(i, java.sql.Types.TIMESTAMP);
10008:                    }
10009:
10010:                } else if (javaTypeInt == 12) { // java.lang.Boolean
10011:                    if (!value.equalsIgnoreCase("null")) {
10012:                        boolean bool = new Boolean(value).booleanValue();
10013:                        pstmt.setBoolean(i, bool);
10014:                    } else {
10015:                        // TODO test this peace of code
10016:                        pstmt.setNull(i, java.sql.Types.BIT);
10017:                    }
10018:                } else if (javaTypeInt == 13) { // java.lang.Byte
10019:                    if (!value.equalsIgnoreCase("null")) {
10020:                        pstmt.setString(i, value);
10021:                    } else {
10022:                        pstmt.setNull(i, java.sql.Types.BIT);
10023:                    }
10024:                } else if (javaTypeInt == 14) { // java.lang.Object
10025:                    if (!value.equalsIgnoreCase("null")) {
10026:                        pstmt.setString(i, value);
10027:                    } else {
10028:                        // TODO zoran pogledati ovo
10029:                        try {
10030:                            pstmt.setNull(i, java.sql.Types.NULL);
10031:                        } catch (Exception e) {
10032:                            pstmt.setString(i, null);
10033:                        }
10034:                    }
10035:                }
10036:            }
10037:
10038:            //senka added
10039:            protected String getSQLRelationString(ResultSet rs) {
10040:                String res = "";
10041:                String r = "";
10042:                String temp = "";
10043:                int col = 0;
10044:                int counter = 1;
10045:
10046:                if (this .iTargetFirstColumnResult == 1)
10047:                    col = 1;
10048:                try {
10049:                    try {
10050:                        if (!configReaderTarget.isNumber(rs.getMetaData()
10051:                                .getColumnTypeName(col)))
10052:                            temp = "'";
10053:                    } catch (LoaderException e) {
10054:                        e.printStackTrace();
10055:                    }
10056:                    Object obj = rs.getObject(col);
10057:                    if (obj != null) {
10058:                        res = res + temp + obj.toString() + temp + ",";
10059:                        while (rs.next()) {
10060:                            obj = rs.getObject(col);
10061:                            if (obj != null) {
10062:                                res = res + temp + obj.toString() + temp;
10063:                                res = res + ",";
10064:                                counter++;
10065:                            }
10066:                        }
10067:                    } else {
10068:                        res = res + temp + "null" + temp + ",";
10069:                    }
10070:
10071:                } catch (SQLException e) {
10072:                    e.printStackTrace();
10073:                }
10074:
10075:                if (counter == 1) {
10076:                    r = res.substring(temp.length(), res.length() - 1
10077:                            - temp.length());
10078:                } else {
10079:                    r = " IN (" + res.substring(0, res.length() - 1) + ")";
10080:                }
10081:                return r;
10082:            }
10083:
10084:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.