Source Code Cross Referenced for CheckRowCache.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) 


001:        /*
002:          Loader - tool for transfering data from one JDBC source to another and
003:          doing transformations during copy.
004:            Copyright (C) 2002-2003  Together
005:            This library is free software; you can redistribute it and/or
006:            modify it under the terms of the GNU Lesser General Public
007:            License as published by the Free Software Foundation; either
008:            version 2.1 of the License, or (at your option) any later version.
009:            This library is distributed in the hope that it will be useful,
010:            but WITHOUT ANY WARRANTY; without even the implied warranty of
011:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:            Lesser General Public License for more details.
013:            You should have received a copy of the GNU Lesser General Public
014:            License along with this library; if not, write to the Free Software
015:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         Loader.java
017:         Date: 03.03.2003.
018:         @version 2.1 alpha
019:         @author:
020:         Radoslav Dutina rale@prozone.co.yu
021:         */
022:
023:        package org.webdocwf.util.loader;
024:
025:        import java.util.*;
026:        import java.sql.*;
027:        import org.webdocwf.util.loader.logging.*;
028:
029:        /**
030:         *
031:         * CheckRowCache class is used to cache queries which will be sent to target
032:         * database to check if some row exists
033:         * @author Radoslav Dutina
034:         * @version 1.0
035:         */
036:        public class CheckRowCache {
037:            private Hashtable rowExist = new Hashtable();
038:            private Hashtable rowVersionValue = new Hashtable();
039:
040:            private String currentKey = "";
041:            private Logger logger;
042:            private int currentVersion = 0;
043:
044:            /**
045:             * This method is use to mark row if he is cahced
046:             */
047:            //  public void setCheckRowValue() {
048:            //      new Throwable().printStackTrace();
049:            //    if (!this.currentKey.equalsIgnoreCase("")) {
050:            //        
051:            //      rowExist.put(this.currentKey, "true");
052:            //    }
053:            //  }
054:            /**
055:             * This method set value of cached row
056:             * @param val is value of cached row
057:             */
058:            //  public void setCheckRowVersionValue(String val) {
059:            //    if (!this.currentKey.equalsIgnoreCase("")) {
060:            //      rowVersionValue.put(this.currentKey, val);
061:            //    }
062:            //  }
063:            /**
064:             * This method is use to retrive value of cached row
065:             * @return value of cache row
066:             */
067:            public int getCheckRowVersionValue() {
068:                String ret = (String) rowVersionValue.get(this .currentKey);
069:                return Integer.parseInt(ret);
070:            }
071:
072:            /**
073:             * This method is use to retrive value of some sql query object
074:             * @param key defines string representation of query object
075:             * @param conn defines connection to target database
076:             * @param iTargetFirstColumnResult is configuration parameter
077:             * @return value of selected row
078:             * @throws java.lang.Exception
079:             */
080:            private int numOfChecks = 0;
081:            private int numCacheHits = 0;
082:
083:            public boolean getCheckRowValue(String key, Connection conn,
084:                    int iTargetFirstColumnResult, String versionColumnName)
085:                    throws Exception {
086:
087:                boolean retVal = false;
088:                this .currentKey = key;
089:                Object obj = rowExist.get(key);
090:
091:                numOfChecks++;
092:
093:                if (obj == null) {
094:                    this .logger.write("full", "\tQuery '" + key
095:                            + "' will be executed");
096:                    try {
097:                        Statement stmtCheckTarget = conn.createStatement();
098:                        ResultSet rsetCheckTarget = stmtCheckTarget
099:                                .executeQuery(key);
100:                        if (rsetCheckTarget.next()) { //update row mode
101:                        //          this.setCheckRowValue();
102:                            rowExist.put(this .currentKey, "true");
103:                            if (versionColumnName != null) {
104:                                currentVersion = rsetCheckTarget
105:                                        .getInt(versionColumnName);
106:                                rowVersionValue.put(this .currentKey, String
107:                                        .valueOf(currentVersion));
108:                                //            this.setCheckRowVersionValue(String.valueOf(this.currentVersion));
109:                            }
110:                            rsetCheckTarget.close();
111:                            stmtCheckTarget.close();
112:                            retVal = true;
113:                        } else {//insert row mode
114:                        //          this.setCheckRowVersionValue(String.valueOf(0));
115:                            rowVersionValue.put(currentKey, "0");
116:                            rsetCheckTarget.close();
117:                            stmtCheckTarget.close();
118:                            retVal = false;
119:                        }
120:                    } catch (Exception ex) {
121:                        this .logger.write("full", ex.getMessage());
122:                        throw ex;
123:                    }
124:                } else { //update row mode
125:                    numCacheHits++;
126:                    retVal = true;
127:                }
128:
129:                //this.logger.write("normal", "\t numOfCheck = '" + numOfChecks);
130:                //this.logger.write("normal", "\t numCacheHits = '" + numCacheHits);
131:                //this.logger.write("normal", "\t this.rowExist size = '" + this.rowExist.size());
132:
133:                return retVal;
134:            }
135:
136:            /**
137:             * This method is use to reset all parameters which are used in this class
138:             */
139:            public void resetCheckRowCache() {
140:                rowExist.clear();
141:                rowVersionValue.clear();
142:                currentKey = "";
143:            }
144:
145:            /**
146:             * This method is use to set logger object
147:             * @param logger is current logger
148:             */
149:            public void setLogger(Logger logger) {
150:                this .logger = logger;
151:            }
152:
153:            /**
154:             * This method is use to retrive value of currentVersion parameter
155:             * @return value of parameter
156:             */
157:            public int getCurrentVersion() {
158:                return this.currentVersion;
159:            }
160:
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.