Source Code Cross Referenced for I18nSqlParser.java in  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » i18njdbc » 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.i18njdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:            Copyright (C) 2002-2003  Together
003:
004:            This library is free software; you can redistribute it and/or
005:            modify it under the terms of the GNU Lesser General Public
006:            License as published by the Free Software Foundation; either
007:            version 2.1 of the License, or (at your option) any later version.
008:
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:
014:            You should have received a copy of the GNU Lesser General Public
015:            License along with this library; if not, write to the Free Software
016:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:
018:         */package org.webdocwf.util.i18njdbc;
019:
020:        import java.util.*;
021:        import java.sql.Statement;
022:
023:        /**
024:         * Class is used for parsing sql statements.
025:         *
026:         * @author     Zoran Milakovic
027:         * @author		 Zeljko Kovacevic
028:         */
029:        public class I18nSqlParser {
030:
031:            public static final String CREATE_TABLE = "create_table";
032:            public static final String INSERT = "insert";
033:            public static final String UPDATE = "update";
034:            public static final String SELECT = "select";
035:            public static final String DELETE = "delete";
036:
037:            public static final String QUOTE_ESCAPE = "''";
038:            private static final String DOUBLE_QUOTE_ESCAPE = "\"";
039:            private static final String COMMA_ESCAPE = "~#####1~";
040:
041:            public static final String BINARY_STREAM_OBJECT = "I18nDriverBinaryStreamObject";
042:
043:            private ArrayList binaryStreamObjectList = new ArrayList();
044:
045:            private HashMap oldValues = new HashMap();
046:
047:            public String tableName;
048:
049:            public String whereStatement;
050:
051:            public String sqlType;
052:
053:            public String[] columnNames;
054:
055:            public String[] columnValues;
056:
057:            public String[] columnWhereNames;
058:
059:            public String[] columnWhereValues;
060:
061:            /**
062:             *Gets the tableName attribute of the SqlParser object
063:             *
064:             * @return    The tableName value
065:             * @since
066:             */
067:            public String getTableName() {
068:                return tableName;
069:            }
070:
071:            /**
072:             * Gets the columnNames attribute of the SqlParser object
073:             *
074:             * @return    The columnNames value
075:             * @since
076:             */
077:            public String[] getColumnNames() {
078:                return columnNames;
079:            }
080:
081:            public String[] getWhereColumnNames() {
082:                return columnWhereNames;
083:            }
084:
085:            public String[] getWhereColumnValues() {
086:                return columnWhereValues;
087:            }
088:
089:            public String[] getColumnValues() {
090:                return columnValues;
091:            }
092:
093:            /**
094:             * Parse sql statement.
095:             *
096:             * @param  statement Statement object which wrap sql statement
097:             * @exception  Exception  Description of Exception
098:             * @since
099:             */
100:            public void parse(Statement statement) throws Exception {
101:                String sql = "";
102:                if (statement instanceof  I18nStatement)
103:                    sql = ((I18nStatement) statement).getSqlStatement();
104:                else if (statement instanceof  I18nPreparedStatement)
105:                    sql = ((I18nPreparedStatement) statement).getSqlStatement();
106:                tableName = null;
107:                columnNames = new String[0];
108:                columnValues = new String[0];
109:                columnWhereNames = new String[0];
110:                columnWhereValues = new String[0];
111:                whereStatement = null;
112:                sqlType = null;
113:
114:                //removing comments
115:                if (sql.indexOf("/*") != -1) {
116:                    StringBuffer buf = new StringBuffer(sql);
117:                    buf.delete(sql.indexOf("/*"), sql.indexOf("*/") + 2);
118:                    sql = buf.toString();
119:                }
120:                sql = sql.trim();
121:
122:                I18nDriver.log("sql = " + sql);
123:
124:                oldValues.clear();
125:                //	int startIndex = 0;
126:                //replace comma(,) in values between quotes(')
127:                StringTokenizer tokQuote = new StringTokenizer(sql.toString(),
128:                        "'", true);
129:                StringBuffer sb = new StringBuffer();
130:                boolean openParent1 = false;
131:                while (tokQuote.hasMoreTokens()) {
132:                    //	  startIndex++;
133:                    String next = tokQuote.nextToken();
134:                    if (openParent1) {
135:                        next = Utils.replaceAll(next, ",", COMMA_ESCAPE);
136:                        next = Utils.replaceKeywords(next, oldValues);
137:                    }
138:                    sb.append(next);
139:                    if (next.equalsIgnoreCase("'")) {
140:                        if (openParent1 == true)
141:                            openParent1 = false;
142:                        else
143:                            openParent1 = true;
144:                    }
145:                }
146:                //END replacement
147:                sql = sb.toString();
148:                String upperSql = sql.toUpperCase();
149:
150:                //handle unsupported statements
151:                if (upperSql.startsWith("ALTER "))
152:                    throw new Exception(
153:                            "ALTER TABLE statements are not supported.");
154:                if (upperSql.startsWith("DROP "))
155:                    throw new Exception("DROP statements are not supported.");
156:
157:                //SELECT
158:                if (upperSql.startsWith("SELECT ")) {
159:                    if (upperSql.lastIndexOf(" FROM ") == -1) {
160:                        throw new Exception(
161:                                "Malformed SQL. Missing FROM statement.");
162:                    }
163:
164:                    sqlType = SELECT;
165:                    int fromPos = upperSql.lastIndexOf(" FROM ");
166:                    int wherePos = upperSql.lastIndexOf(" WHERE ");
167:                    if (wherePos == -1)
168:                        tableName = sql.substring(fromPos + 6).trim();
169:                    else
170:                        tableName = sql.substring(fromPos + 6, wherePos).trim();
171:
172:                    Vector cols = new Vector();
173:                    StringTokenizer tokenizer = new StringTokenizer(upperSql
174:                            .substring(7, fromPos), ",");
175:
176:                    while (tokenizer.hasMoreTokens()) {
177:                        cols.add(tokenizer.nextToken().trim());
178:                    }
179:
180:                    columnNames = new String[cols.size()];
181:                    cols.copyInto(columnNames);
182:                    if (wherePos != -1) {
183:                        String strWhere = sql.substring(wherePos + 7);
184:                        Vector whereCols = new Vector();
185:                        Vector whereValues = new Vector();
186:                        StringTokenizer tokenizerWhere = new StringTokenizer(
187:                                strWhere, ",");
188:
189:                        while (tokenizerWhere.hasMoreTokens()) {
190:                            String strToken = tokenizerWhere.nextToken();
191:                            if (strToken.toLowerCase().indexOf(" and ") != -1) {
192:                                String temp = strToken;
193:                                int andPos = 0;
194:                                out: do {
195:                                    andPos = temp.toLowerCase()
196:                                            .indexOf(" and ");
197:                                    String strTokenAdd;
198:                                    if (andPos != -1)
199:                                        strTokenAdd = temp.substring(0, andPos)
200:                                                .trim();
201:                                    else
202:                                        strTokenAdd = temp.trim();
203:                                    int delimiter2 = strTokenAdd.indexOf("=");
204:                                    if (delimiter2 != -1) {
205:                                        String valueAdd = strTokenAdd
206:                                                .substring(delimiter2 + 1)
207:                                                .trim();
208:                                        valueAdd = Utils
209:                                                .handleQuotedString(valueAdd);
210:                                        whereCols.add(strTokenAdd.substring(0,
211:                                                delimiter2).trim());
212:                                        valueAdd = Utils.replaceAll(valueAdd,
213:                                                COMMA_ESCAPE, ",");
214:                                        valueAdd = Utils.replaceAll(valueAdd,
215:                                                QUOTE_ESCAPE, "'");
216:                                        valueAdd = Utils.replaceKeywordsBack(
217:                                                valueAdd, oldValues);
218:                                        whereValues.add(valueAdd);
219:                                    } else {
220:                                        int delimiter3 = strTokenAdd
221:                                                .toLowerCase().indexOf(" is ");
222:                                        whereCols.add(strTokenAdd.substring(0,
223:                                                delimiter3).trim());
224:                                        whereValues.add(null);
225:                                    }
226:                                    temp = temp.substring(andPos + 5);
227:                                    if (temp.toLowerCase().indexOf(" and ") == -1) {
228:                                        strTokenAdd = temp.trim();
229:                                        int delimiter4 = strTokenAdd
230:                                                .indexOf("=");
231:                                        if (delimiter4 != -1) {
232:                                            String valueAdd = strTokenAdd
233:                                                    .substring(delimiter4 + 1)
234:                                                    .trim();
235:                                            valueAdd = Utils
236:                                                    .handleQuotedString(valueAdd);
237:                                            whereCols.add(strTokenAdd
238:                                                    .substring(0, delimiter4)
239:                                                    .trim());
240:                                            valueAdd = Utils
241:                                                    .replaceAll(valueAdd,
242:                                                            COMMA_ESCAPE, ",");
243:                                            valueAdd = Utils
244:                                                    .replaceAll(valueAdd,
245:                                                            QUOTE_ESCAPE, "'");
246:                                            valueAdd = Utils
247:                                                    .replaceKeywordsBack(
248:                                                            valueAdd, oldValues);
249:                                            whereValues.add(valueAdd);
250:                                        } else {
251:                                            int delimiter3 = strTokenAdd
252:                                                    .toLowerCase().indexOf(
253:                                                            " is ");
254:                                            whereCols.add(strTokenAdd
255:                                                    .substring(0, delimiter3)
256:                                                    .trim());
257:                                            whereValues.add(null);
258:                                        }
259:                                        break out;
260:                                    }
261:
262:                                } while (true);
263:
264:                            } else {
265:                                int delimiter = strToken.indexOf("=");
266:                                if (delimiter != -1) {
267:                                    String value = strToken.substring(
268:                                            delimiter + 1).trim();
269:                                    value = Utils.handleQuotedString(value);
270:                                    whereCols.add(strToken.substring(0,
271:                                            delimiter).trim());
272:                                    value = Utils.replaceAll(value,
273:                                            COMMA_ESCAPE, ",");
274:                                    value = Utils.replaceAll(value,
275:                                            QUOTE_ESCAPE, "'");
276:                                    value = Utils.replaceKeywordsBack(value,
277:                                            oldValues);
278:                                    whereValues.add(value);
279:                                } else {
280:                                    int delimiter1 = strToken.toLowerCase()
281:                                            .indexOf(" is ");
282:                                    whereCols.add(strToken.substring(0,
283:                                            delimiter1).trim());
284:                                    whereValues.add(null);
285:                                }
286:                            }
287:                        }
288:                        columnWhereNames = new String[whereCols.size()];
289:                        columnWhereValues = new String[whereValues.size()];
290:                        whereCols.copyInto(columnWhereNames);
291:                        whereValues.copyInto(columnWhereValues);
292:                    }
293:                }
294:                //DELETE
295:                else if (upperSql.startsWith("DELETE ")) {
296:                    if (upperSql.lastIndexOf(" FROM ") == -1) {
297:                        throw new Exception(
298:                                "Malformed SQL. Missing FROM statement.");
299:                    }
300:
301:                    sqlType = DELETE;
302:                    int fromPos = upperSql.lastIndexOf(" FROM ");
303:                    int wherePos = upperSql.lastIndexOf(" WHERE ");
304:                    if (wherePos == -1)
305:                        tableName = sql.substring(fromPos + 6).trim();
306:                    else
307:                        tableName = sql.substring(fromPos + 6, wherePos).trim();
308:
309:                    //	  Vector cols = new Vector();
310:                    //	  StringTokenizer tokenizer = new StringTokenizer(upperSql.substring(7,
311:                    //		  fromPos), ",");
312:                    //
313:                    //	  while (tokenizer.hasMoreTokens()) {
314:                    //		cols.add(tokenizer.nextToken().trim());
315:                    //	  }
316:
317:                    //	  columnNames = new String[cols.size()];
318:                    //	  cols.copyInto(columnNames);
319:                    if (wherePos != -1) {
320:                        String strWhere = sql.substring(wherePos + 7);
321:                        Vector whereCols = new Vector();
322:                        Vector whereValues = new Vector();
323:                        StringTokenizer tokenizerWhere = new StringTokenizer(
324:                                strWhere, ",");
325:
326:                        while (tokenizerWhere.hasMoreTokens()) {
327:                            String strToken = tokenizerWhere.nextToken();
328:                            if (strToken.toLowerCase().indexOf(" and ") != -1) {
329:                                String temp = strToken;
330:                                int andPos = 0;
331:                                out1: do {
332:                                    andPos = temp.toLowerCase()
333:                                            .indexOf(" and ");
334:                                    String strTokenAdd;
335:                                    if (andPos != -1)
336:                                        strTokenAdd = temp.substring(0, andPos)
337:                                                .trim();
338:                                    else
339:                                        strTokenAdd = temp.trim();
340:                                    int delimiter2 = strTokenAdd.indexOf("=");
341:                                    if (delimiter2 != -1) {
342:                                        String valueAdd = strTokenAdd
343:                                                .substring(delimiter2 + 1)
344:                                                .trim();
345:                                        valueAdd = Utils
346:                                                .handleQuotedString(valueAdd);
347:                                        whereCols.add(strTokenAdd.substring(0,
348:                                                delimiter2).trim());
349:                                        valueAdd = Utils.replaceAll(valueAdd,
350:                                                COMMA_ESCAPE, ",");
351:                                        valueAdd = Utils.replaceAll(valueAdd,
352:                                                QUOTE_ESCAPE, "'");
353:                                        valueAdd = Utils.replaceKeywordsBack(
354:                                                valueAdd, oldValues);
355:                                        whereValues.add(valueAdd);
356:                                    } else {
357:                                        int delimiter3 = strTokenAdd
358:                                                .toLowerCase().indexOf(" is ");
359:                                        whereCols.add(strTokenAdd.substring(0,
360:                                                delimiter3).trim());
361:                                        whereValues.add(null);
362:                                    }
363:                                    temp = temp.substring(andPos + 5);
364:                                    if (temp.toLowerCase().indexOf(" and ") == -1) {
365:                                        strTokenAdd = temp.trim();
366:                                        int delimiter4 = strTokenAdd
367:                                                .indexOf("=");
368:                                        if (delimiter4 != -1) {
369:                                            String valueAdd = strTokenAdd
370:                                                    .substring(delimiter4 + 1)
371:                                                    .trim();
372:                                            valueAdd = Utils
373:                                                    .handleQuotedString(valueAdd);
374:                                            whereCols.add(strTokenAdd
375:                                                    .substring(0, delimiter4)
376:                                                    .trim());
377:                                            valueAdd = Utils
378:                                                    .replaceAll(valueAdd,
379:                                                            COMMA_ESCAPE, ",");
380:                                            valueAdd = Utils
381:                                                    .replaceAll(valueAdd,
382:                                                            QUOTE_ESCAPE, "'");
383:                                            valueAdd = Utils
384:                                                    .replaceKeywordsBack(
385:                                                            valueAdd, oldValues);
386:                                            whereValues.add(valueAdd);
387:                                        } else {
388:                                            int delimiter3 = strTokenAdd
389:                                                    .toLowerCase().indexOf(
390:                                                            " is ");
391:                                            whereCols.add(strTokenAdd
392:                                                    .substring(0, delimiter3)
393:                                                    .trim());
394:                                            whereValues.add(null);
395:                                        }
396:                                        break out1;
397:                                    }
398:
399:                                } while (true);
400:
401:                            } else {
402:                                int delimiter = strToken.indexOf("=");
403:                                if (delimiter != -1) {
404:                                    String value = strToken.substring(
405:                                            delimiter + 1).trim();
406:                                    value = Utils.handleQuotedString(value);
407:                                    whereCols.add(strToken.substring(0,
408:                                            delimiter).trim());
409:                                    value = Utils.replaceAll(value,
410:                                            COMMA_ESCAPE, ",");
411:                                    value = Utils.replaceAll(value,
412:                                            QUOTE_ESCAPE, "'");
413:                                    value = Utils.replaceKeywordsBack(value,
414:                                            oldValues);
415:                                    whereValues.add(value);
416:                                } else {
417:                                    int delimiter1 = strToken.toLowerCase()
418:                                            .indexOf(" is ");
419:                                    whereCols.add(strToken.substring(0,
420:                                            delimiter1).trim());
421:                                    whereValues.add(null);
422:                                }
423:                            }
424:                        }
425:                        columnWhereNames = new String[whereCols.size()];
426:                        columnWhereValues = new String[whereValues.size()];
427:                        whereCols.copyInto(columnWhereNames);
428:                        whereValues.copyInto(columnWhereValues);
429:                    }
430:                }
431:
432:                //INSERT
433:                else if (upperSql.startsWith("INSERT ")) {
434:                    if (upperSql.lastIndexOf(" VALUES") == -1) {
435:                        throw new Exception(
436:                                "Malformed SQL. Missing VALUES statement.");
437:                    }
438:                    sqlType = INSERT;
439:                    int intoPos = 0;
440:                    if (upperSql.indexOf(" INTO ") != -1)
441:                        intoPos = upperSql.indexOf(" INTO ") + 6;
442:                    else
443:                        intoPos = upperSql.indexOf("INSERT ") + 7;
444:                    int bracketPos = upperSql.indexOf("(");
445:                    int lastBracketPos = upperSql.indexOf(")");
446:                    tableName = sql.substring(intoPos, bracketPos).trim();
447:
448:                    Vector cols = new Vector();
449:                    StringTokenizer tokenizer = new StringTokenizer(upperSql
450:                            .substring(bracketPos + 1, lastBracketPos), ",");
451:                    while (tokenizer.hasMoreTokens()) {
452:                        cols.add(tokenizer.nextToken().trim());
453:                    }
454:                    columnNames = new String[cols.size()];
455:                    cols.copyInto(columnNames);
456:
457:                    int valuesPos = upperSql.indexOf("VALUES");
458:                    String endStatement = sql.substring(valuesPos + 6).trim();
459:                    bracketPos = endStatement.indexOf("(");
460:                    lastBracketPos = endStatement.lastIndexOf(")");
461:                    Vector values = new Vector();
462:                    StringTokenizer tokenizer2 = new StringTokenizer(
463:                            endStatement.substring(bracketPos + 1,
464:                                    lastBracketPos), ",");
465:                    while (tokenizer2.hasMoreTokens()) {
466:                        String value = tokenizer2.nextToken().trim();
467:                        value = Utils.handleQuotedString(value);
468:                        value = Utils.replaceAll(value, COMMA_ESCAPE, ",");
469:                        value = Utils.replaceAll(value, QUOTE_ESCAPE, "'");
470:                        value = Utils.replaceAll(value, "\"",
471:                                DOUBLE_QUOTE_ESCAPE);
472:                        value = Utils.replaceKeywordsBack(value, oldValues);
473:                        value = Utils.handleBinaryString(value,
474:                                this .binaryStreamObjectList);
475:                        values.add(value);
476:                    }
477:                    columnValues = new String[values.size()];
478:                    values.copyInto(columnValues);
479:                    //replace all line brakes
480:
481:                    //        columnValues = Utils.replaceLineBrakesAndCarrReturn(
482:                    //            columnValues,
483:                    //              ((I18nConnection) statement.getConnection()).getLineBreakEscape(),
484:                    //              ((I18nConnection) statement.getConnection()).getCarriageReturnEscape()
485:                    //              );
486:                }
487:
488:                //UPDATE
489:                else if (upperSql.startsWith("UPDATE ")) {
490:                    if (upperSql.lastIndexOf(" SET ") == -1)
491:                        throw new Exception(
492:                                "Malformed SQL. Missing SET statement.");
493:                    sqlType = UPDATE;
494:                    int updatePos = upperSql.indexOf("UPDATE");
495:                    int setPos = upperSql.indexOf(" SET ");
496:                    int equalPos = upperSql.indexOf("=");
497:                    int wherePos = upperSql.indexOf(" WHERE ");
498:                    tableName = sql.substring(updatePos + 6, setPos).trim();
499:
500:                    String setString = "";
501:                    if (wherePos != -1)
502:                        setString = sql.substring(setPos + 5, wherePos);
503:                    else
504:                        setString = sql.substring(setPos + 5, sql.length());
505:                    StringTokenizer tokenizerSet = new StringTokenizer(
506:                            setString, ",");
507:                    Vector setNames = new Vector();
508:                    Vector setValues = new Vector();
509:
510:                    while (tokenizerSet.hasMoreTokens()) {
511:                        String strToken = tokenizerSet.nextToken();
512:                        int delimiter = strToken.indexOf("=");
513:                        setNames.add(strToken.substring(0, delimiter).trim());
514:                        String value = strToken.substring(delimiter + 1).trim();
515:                        value = Utils.handleQuotedString(value);
516:                        value = Utils.replaceAll(value, COMMA_ESCAPE, ",");
517:                        value = Utils.replaceAll(value, QUOTE_ESCAPE, "'");
518:                        value = Utils.replaceAll(value, "\"",
519:                                DOUBLE_QUOTE_ESCAPE);
520:                        value = Utils.replaceKeywordsBack(value, oldValues);
521:                        value = Utils.handleBinaryString(value,
522:                                this .binaryStreamObjectList);
523:                        setValues.add(value);
524:                    }
525:
526:                    columnNames = new String[setNames.size()];
527:                    columnValues = new String[setValues.size()];
528:                    setNames.copyInto(columnNames);
529:                    setValues.copyInto(columnValues);
530:                    //replace all line brakes
531:
532:                    //          columnValues = Utils.replaceLineBrakesAndCarrReturn(
533:                    //              columnValues,
534:                    //              ((I18nConnection) statement.getConnection()).getLineBreakEscape(),
535:                    //              ((I18nConnection) statement.getConnection()).getCarriageReturnEscape()
536:                    //              );
537:                    if (wherePos != -1) {
538:                        String strWhere = sql.substring(wherePos + 6).trim();
539:                        Vector whereCols = new Vector();
540:                        Vector whereValues = new Vector();
541:                        StringTokenizer tokenizerWhere = new StringTokenizer(
542:                                strWhere, ",");
543:
544:                        while (tokenizerWhere.hasMoreTokens()) {
545:                            String strToken = tokenizerWhere.nextToken();
546:                            if (strToken.toLowerCase().indexOf(" and ") != -1) {
547:                                String temp = strToken;
548:                                int andPos = 0;
549:                                out: do {
550:                                    andPos = temp.toLowerCase()
551:                                            .indexOf(" and ");
552:                                    String strTokenAdd;
553:                                    if (andPos != -1)
554:                                        strTokenAdd = temp.substring(0, andPos)
555:                                                .trim();
556:                                    else
557:                                        strTokenAdd = temp.trim();
558:                                    int delimiter2 = strTokenAdd.indexOf("=");
559:                                    if (delimiter2 != -1) {
560:                                        String valueAdd = strTokenAdd
561:                                                .substring(delimiter2 + 1)
562:                                                .trim();
563:                                        valueAdd = Utils
564:                                                .handleQuotedString(valueAdd);
565:                                        whereCols.add(strTokenAdd.substring(0,
566:                                                delimiter2).trim());
567:                                        valueAdd = Utils.replaceAll(valueAdd,
568:                                                COMMA_ESCAPE, ",");
569:                                        valueAdd = Utils.replaceAll(valueAdd,
570:                                                QUOTE_ESCAPE, "'");
571:                                        valueAdd = Utils.replaceKeywordsBack(
572:                                                valueAdd, oldValues);
573:                                        whereValues.add(valueAdd);
574:                                    } else {
575:                                        int delimiter3 = strTokenAdd
576:                                                .toLowerCase().indexOf(" is ");
577:                                        whereCols.add(strTokenAdd.substring(0,
578:                                                delimiter3).trim());
579:                                        whereValues.add(null);
580:                                    }
581:                                    temp = temp.substring(andPos + 5);
582:                                    if (temp.toLowerCase().indexOf(" and ") == -1) {
583:                                        strTokenAdd = temp.trim();
584:                                        int delimiter4 = strTokenAdd
585:                                                .indexOf("=");
586:                                        if (delimiter4 != -1) {
587:                                            String valueAdd = strTokenAdd
588:                                                    .substring(delimiter4 + 1)
589:                                                    .trim();
590:                                            valueAdd = Utils
591:                                                    .handleQuotedString(valueAdd);
592:                                            whereCols.add(strTokenAdd
593:                                                    .substring(0, delimiter4)
594:                                                    .trim());
595:                                            valueAdd = Utils
596:                                                    .replaceAll(valueAdd,
597:                                                            COMMA_ESCAPE, ",");
598:                                            valueAdd = Utils
599:                                                    .replaceAll(valueAdd,
600:                                                            QUOTE_ESCAPE, "'");
601:                                            valueAdd = Utils
602:                                                    .replaceKeywordsBack(
603:                                                            valueAdd, oldValues);
604:                                            whereValues.add(valueAdd);
605:                                        } else {
606:                                            int delimiter3 = strTokenAdd
607:                                                    .toLowerCase().indexOf(
608:                                                            " is ");
609:                                            whereCols.add(strTokenAdd
610:                                                    .substring(0, delimiter3)
611:                                                    .trim());
612:                                            whereValues.add(null);
613:                                        }
614:                                        break out;
615:                                    }
616:
617:                                } while (true);
618:
619:                            } else {
620:                                int delimiter = strToken.indexOf("=");
621:                                if (delimiter != -1) {
622:                                    String value = strToken.substring(
623:                                            delimiter + 1).trim();
624:                                    value = Utils.handleQuotedString(value);
625:                                    whereCols.add(strToken.substring(0,
626:                                            delimiter).trim());
627:                                    value = Utils.replaceAll(value,
628:                                            COMMA_ESCAPE, ",");
629:                                    value = Utils.replaceAll(value,
630:                                            QUOTE_ESCAPE, "'");
631:                                    value = Utils.replaceKeywordsBack(value,
632:                                            oldValues);
633:                                    whereValues.add(value);
634:                                } else {
635:                                    int delimiter1 = strToken.toLowerCase()
636:                                            .indexOf(" is ");
637:                                    whereCols.add(strToken.substring(0,
638:                                            delimiter1).trim());
639:                                    whereValues.add(null);
640:                                }
641:                            }
642:                        }
643:                        columnWhereNames = new String[whereCols.size()];
644:                        columnWhereValues = new String[whereValues.size()];
645:                        whereCols.copyInto(columnWhereNames);
646:                        whereValues.copyInto(columnWhereValues);
647:                    }
648:                }
649:
650:                //CREATE TABLE
651:                else if (upperSql.startsWith("CREATE TABLE ")) {
652:                    sqlType = CREATE_TABLE;
653:                    int createPos = upperSql.indexOf("CREATE TABLE");
654:                    int tableStartPos = upperSql.indexOf("(");
655:                    int tableEndPos = upperSql.lastIndexOf(")");
656:                    tableName = sql.substring(createPos + 12, tableStartPos)
657:                            .trim();
658:                    String createString = sql.substring(tableStartPos + 1,
659:                            tableEndPos).trim();
660:                    StringTokenizer tokenizerCreate = new StringTokenizer(
661:                            createString.toUpperCase(), "\n");
662:                    Vector setColumnNames = new Vector();
663:                    while (tokenizerCreate.hasMoreTokens()) {
664:                        String strToken = tokenizerCreate.nextToken().trim();
665:                        int delimiter = strToken.indexOf(" ");
666:                        //find out type of column
667:                        String typeOfColumn = "";
668:                        StringTokenizer stSpace = new StringTokenizer(strToken,
669:                                " ");
670:                        while (stSpace.hasMoreTokens()) {
671:                            String nextStSpace = stSpace.nextToken();
672:                            //ZK commented next 2 lines
673:                            //                if (nextStSpace.equalsIgnoreCase(CsvDriver.BINARY_TYPE))
674:                            //                  typeOfColumn = "-BINARY";
675:                        }
676:                        if (strToken.toUpperCase().indexOf("CONSTRAINT") == -1) {
677:                            String columnName = strToken
678:                                    .substring(0, delimiter).trim();
679:                            setColumnNames.add(columnName + typeOfColumn);
680:                        }
681:                    }
682:                    columnNames = new String[setColumnNames.size()];
683:                    setColumnNames.copyInto(columnNames);
684:
685:                } else {
686:                    throw new Exception("Malformed SQL. Wrong SQL statement.");
687:                }
688:
689:            }
690:
691:            /**
692:             * Set setBinaryStreamList.
693:             * @param list
694:             */
695:            public void setBinaryStreamList(ArrayList list) {
696:                this.binaryStreamObjectList = list;
697:            }
698:
699:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.