Source Code Cross Referenced for InsertRowQuerySet.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:         CounterColumns - insert auto increment values in target counter columns.
003:
004:         Copyright (C) 2002-2003  Together
005:
006:         This library is free software; you can redistribute it and/or
007:         modify it under the terms of the GNU Lesser General Public
008:         License as published by the Free Software Foundation; either
009:         version 2.1 of the License, or (at your option) any later version.
010:
011:         This library is distributed in the hope that it will be useful,
012:         but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         Lesser General Public License for more details.
015:
016:         You should have received a copy of the GNU Lesser General Public
017:         License along with this library; if not, write to the Free Software
018:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:
020:         CounterColumns.java
021:         Date: 11.03.2003.
022:         @version 1.1.0
023:         @author: Milosevic Sinisa sinisa@prozone.co.yu
024:         */package org.webdocwf.util.loader;
025:
026:        import java.sql.Connection;
027:        import java.sql.PreparedStatement;
028:        import java.sql.SQLException;
029:        import java.util.ArrayList;
030:        import java.util.Iterator;
031:        import java.util.Vector;
032:
033:        import org.webdocwf.util.loader.transformation.Transformation;
034:        import org.webdocwf.util.loader.transformation.Transformations;
035:
036:        /**
037:         *
038:         * InsertRowQuerySet class creates insert in to statement for one import definition
039:         * @author Radoslav Dutina
040:         * @version 1.0
041:         */
042:        public class InsertRowQuerySet {
043:            private String strQuery = null;
044:            private String tableName = null;
045:            private String tableID = null;
046:            private Vector vecRelationColumnTargetTableName = null;
047:            private Vector vecRelationColumnTargetTableID = null;
048:            private Vector vecRelationColumnTargetColumnName = null;
049:            private Vector indexDummyInsertNull = new Vector();
050:            private Vector indexDummyInsertRelation = new Vector();
051:            private Vector indexDummyIsNotRelationsColumn = new Vector();
052:            private Vector columnNamesPstmt = new Vector();
053:            //  private Vector columnTypesPstmt=new Vector();
054:            private Connection conn;
055:            private String oidColumnName = "oid";
056:            private String versionColumnName = "version";
057:
058:            //  private Hashtable sqlToJavaMap=new Hashtable();
059:
060:            /**
061:             * Construct object InsertRowQuerySet with associated parameters.
062:             * @param c Connetion to source tables
063:             * @param vecColumnNames is Vector of column names in a target table.
064:             * @param vecColumnMode is Vector of column modes in a target table.
065:             * @param tableName is current table name
066:             * @param tableID is current table id
067:             * @param iTableInt is the number of target table
068:             * @param vecTempConstantColumns is Vector of column names for target table.
069:             * @param vecVariableTimesTableName is Vector of variable times, for target table.
070:             * @param vecVariableTimesTableID is Vector of variable times id, for target table.
071:             * @param vecVariableTimesColumnName is Vector of variable (times) column names, for target table.
072:             * @param vecVariableColumnTargetTableName is Vector of variable table names.
073:             * @param vecVariableColumnTargetTableID is Vector of variable table id.
074:             * @param vecVariableColumnTargetColumnName is Vector of variable column names, for target table.
075:             * @param vecRelationColumnTargetColumnName is Vector of relations column names, for target table.
076:             * @param vecRelationColumnTargetTableName is Vector of relations table names, for target table.
077:             * @param vecRelationColumnTargetTableID is Vector of relations table id's, for target table.
078:             * @param vecRelationColumnRelationMode is Vector of relations modes, for target table.
079:             * @param counterColumns defines Vector of number of columns
080:             * @param bOidLogicValue is boolean object, which decide is oid logic true or false
081:             * @param isTOS is boolean object, which decide is oid logic true or false
082:             * @throws SQLException
083:             * @throws NullPointerException
084:             * @throws Exception
085:             */
086:            public InsertRowQuerySet(Connection c, Vector vecColumnNames,
087:                    Vector vecColumnMode, String tableName, String tableID,
088:                    int iTableInt, Vector vecTempConstantColumns,
089:                    Vector vecVariableTimesTableName,
090:                    Vector vecVariableTimesTableID,
091:                    Vector vecVariableTimesColumnName,
092:                    Vector vecVariableColumnTargetTableName,
093:                    Vector vecVariableColumnTargetTableID,
094:                    Vector vecVariableColumnTargetColumnName,
095:                    Vector vecRelationColumnTargetColumnName,
096:                    Vector vecRelationColumnTargetTableName,
097:                    Vector vecRelationColumnTargetTableID,
098:                    Vector vecRelationColumnRelationMode,
099:                    CounterColumns counterColumns,
100:                    Transformations transformations, boolean bOidLogicValue,
101:                    boolean isTOS, String oidColumnName,
102:                    String versionColumnName) throws SQLException,
103:                    NullPointerException, Exception {
104:
105:                this .conn = c;
106:                //    if(this.sqlToJavaMap.size()>0)
107:                //      this.sqlToJavaMap.clear();
108:                //    this.sqlToJavaMap=sqlToJavaMap;
109:
110:                this .oidColumnName = oidColumnName;
111:                this .versionColumnName = versionColumnName;
112:                this .tableName = tableName;
113:                this .tableID = tableID;
114:                this .vecRelationColumnTargetTableName = vecRelationColumnTargetTableName;
115:                this .vecRelationColumnTargetTableID = vecRelationColumnTargetTableID;
116:                this .vecRelationColumnTargetColumnName = vecRelationColumnTargetColumnName;
117:                strQuery = "insert into " + tableName;
118:
119:                if (bOidLogicValue) {
120:                    if (isTOS) {
121:                        strQuery += "(" + this .oidColumnName + ", ";
122:                        columnNamesPstmt.add(this .oidColumnName);
123:
124:                    } else {
125:                        strQuery += "(" + this .oidColumnName + ","
126:                                + this .versionColumnName + ", ";
127:                        columnNamesPstmt.add(this .oidColumnName);
128:                        columnNamesPstmt.add(this .versionColumnName);
129:
130:                    }
131:                } else
132:                    strQuery += "(";
133:
134:                for (int j = 0; j < vecColumnNames.size(); j++) {
135:                    if (!this .isRelationColumn(
136:                            vecColumnNames.get(j).toString(), iTableInt)) {
137:                        strQuery += vecColumnNames.get(j).toString() + ", ";
138:                        columnNamesPstmt.add(vecColumnNames.get(j).toString());
139:                        indexDummyIsNotRelationsColumn.add(String.valueOf(j));
140:                    }
141:                }
142:
143:                for (int p = 0; p < vecTempConstantColumns.size(); p++) {
144:                    strQuery += vecTempConstantColumns.get(p).toString() + ", ";
145:                    columnNamesPstmt.add(vecTempConstantColumns.get(p)
146:                            .toString());
147:                }
148:
149:                for (int i = 0; i < vecVariableTimesTableName.size(); i++) {
150:                    if (vecVariableTimesTableName.get(i).toString()
151:                            .equalsIgnoreCase(tableName)
152:                            && vecVariableTimesTableID.get(i).toString()
153:                                    .equalsIgnoreCase(tableID)) {
154:                        strQuery += vecVariableTimesColumnName.get(i)
155:                                .toString()
156:                                + ", ";
157:                        columnNamesPstmt.add(vecVariableTimesColumnName.get(i)
158:                                .toString());
159:                    }
160:                }
161:                for (int i = 0; i < vecVariableColumnTargetTableName.size(); i++) {
162:                    if (vecVariableColumnTargetTableName.get(i).toString()
163:                            .equalsIgnoreCase(tableName)
164:                            && vecVariableColumnTargetTableID.get(i).toString()
165:                                    .equalsIgnoreCase(tableID)) {
166:                        strQuery += vecVariableColumnTargetColumnName.get(i)
167:                                .toString()
168:                                + ", ";
169:                        columnNamesPstmt.add(vecVariableColumnTargetColumnName
170:                                .get(i).toString());
171:                    }
172:                }
173:                for (int i = 0; i < vecRelationColumnTargetColumnName.size(); i++) {
174:                    if (vecRelationColumnTargetTableName.get(i).toString()
175:                            .equalsIgnoreCase(tableName)
176:                            && vecRelationColumnTargetTableID.get(i).toString()
177:                                    .equalsIgnoreCase(tableID)) {
178:                        strQuery += vecRelationColumnTargetColumnName.get(i)
179:                                .toString()
180:                                + ", ";
181:                        columnNamesPstmt.add(vecRelationColumnTargetColumnName
182:                                .get(i).toString());
183:                    }
184:                }
185:
186:                Vector counterColNames = counterColumns.getTargetColumnName(
187:                        tableName, tableID);
188:
189:                for (int i = 0; i < counterColNames.size(); i++) {
190:                    if (counterColNames.get(i) != null)
191:                        strQuery += counterColNames.get(i).toString() + ", ";
192:                    columnNamesPstmt.add(counterColNames.get(i).toString());
193:                }
194:                Vector subCounterColNames = counterColumns
195:                        .getSubTargetColumnName(tableName, tableID);
196:                for (int i = 0; i < subCounterColNames.size(); i++) {
197:                    if (subCounterColNames.get(i) != null)
198:                        strQuery += subCounterColNames.get(i).toString() + ", ";
199:                    columnNamesPstmt.add(subCounterColNames.get(i).toString());
200:                }
201:                //sinisa add transformations
202:                ArrayList trans = transformations.getTransformations();
203:                Iterator iTrans = trans.iterator();
204:
205:                while (iTrans.hasNext()) {
206:                    Transformation transformation = (Transformation) iTrans
207:                            .next();
208:                    //		   String transTableID = transformation.getTargetTableID();
209:                    //		   if( !transTableID.equals(tableID) )
210:                    //		   	continue;
211:                    Vector transColNames = transformation
212:                            .getTargetColumnNames(Integer.parseInt(tableID));
213:                    for (int i = 0; i < transColNames.size(); i++) {
214:                        if (transColNames.get(i) != null)
215:                            strQuery += transColNames.get(i).toString() + ", ";
216:                        columnNamesPstmt.add(transColNames.get(i).toString());
217:                    }
218:                }
219:
220:            }
221:
222:            /**
223:             * This method read the value of strQuery parameter
224:             * @return value of paramter
225:             */
226:            public String getStrQuery() {
227:                strQuery = strQuery.substring(0, strQuery.length() - 2);
228:                return strQuery;
229:            }
230:
231:            /**
232:             * This method read the value of indexDummyIsNotRelationsColumn parameter
233:             * @return value of paramter
234:             */
235:            public Vector getIndexDummyIsNotRelationsColumn() {
236:                return indexDummyIsNotRelationsColumn;
237:            }
238:
239:            /**
240:             * This method construct prepare statement
241:             * @return string representation of prepareStatement
242:             * @throws Exception
243:             */
244:            public PreparedStatement getPreparedStatementForInsert()
245:                    throws Exception {
246:
247:                String strPstmt = "insert into " + this .tableName + " (";
248:                int count = columnNamesPstmt.size();
249:                for (int i = 0; i < count; i++) {
250:                    if (i != count - 1)
251:                        strPstmt += columnNamesPstmt.get(i).toString() + ",";
252:                    else
253:                        strPstmt += columnNamesPstmt.get(i).toString() + ")";
254:                }
255:                strPstmt += " VALUES (";
256:                for (int i = 0; i < count; i++) {
257:                    if (i != count - 1)
258:                        strPstmt += "?,";
259:                    else
260:                        strPstmt += "?)";
261:                }
262:                PreparedStatement pstmt;
263:                try {
264:                    pstmt = this .conn.prepareStatement(strPstmt);
265:                } catch (Exception e) {
266:                    throw e;
267:                }
268:                return pstmt;
269:            }
270:
271:            //  public Hashtable getPreparedStatemetTypes() throws LoaderException{
272:            //    Hashtable pstmtTypes=new Hashtable();
273:            //    try {
274:            //      Statement stmt=conn.createStatement();
275:            //      ResultSet rs=stmt.executeQuery("select * from "+this.tableName);
276:            //      int columnCount=rs.getMetaData().getColumnCount();
277:            //      for (int i = 1; i < columnCount+1; i++) {
278:            //        String columnName=rs.getMetaData().getColumnName(i).toUpperCase();
279:            //        String columnType=rs.getMetaData().getColumnTypeName(i).toUpperCase();
280:            //        String javaType=(String)sqlToJavaMap.get(columnType);
281:            //        pstmtTypes.put(columnName,javaType);
282:            //      }
283:            //
284:            //      stmt.close();
285:            //      rs.close();
286:            //    }
287:            //    catch (Exception ex) {
288:            //      throw new LoaderException(ex.getMessage());
289:            //    }
290:            //    return pstmtTypes;
291:            //  }
292:
293:            /**
294:             * This method read value form columnNamesPstmt parameter
295:             * @return value of parameter
296:             */
297:            public Vector getColumnNames() {
298:                return this .columnNamesPstmt;
299:            }
300:
301:            private boolean isRelationColumn(String strColumnName, int iTable) {
302:                boolean bFind = false;
303:                endFor: for (int i = 0; i < this .vecRelationColumnTargetTableName
304:                        .size(); i++) {
305:                    if (this .vecRelationColumnTargetTableName.get(i).toString()
306:                            .equalsIgnoreCase(tableName)
307:                            && this .vecRelationColumnTargetTableID.get(i)
308:                                    .toString().equalsIgnoreCase(tableID)
309:                            && this .vecRelationColumnTargetColumnName.get(i)
310:                                    .toString().equalsIgnoreCase(strColumnName)) {
311:                        bFind = true;
312:                        break endFor;
313:                    }
314:                }
315:                return bFind;
316:            }
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.