Source Code Cross Referenced for I18nStatement.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.sql.*;
021:        import java.io.File;
022:        import java.io.FileInputStream;
023:        import java.util.Enumeration;
024:
025:        import java.util.Vector;
026:
027:        /**
028:         * This class implements the Statement interface for the I18nJdbc driver.
029:         *
030:         * @author     Zoran Milakovic
031:         * @author		 Zeljko Kovacevic
032:         */
033:
034:        public class I18nStatement implements  Statement {
035:
036:            private I18nConnection connection;
037:            private Vector resultSets = new Vector();
038:            private String sql;
039:
040:            /**
041:             *Constructor for the I18nStatement object
042:             *
043:             * @param  connection  Description of Parameter
044:             * @since
045:             */
046:            protected I18nStatement(I18nConnection connection) {
047:                try {
048:                    DriverManager
049:                            .println("I18nJdbc - I18Statement() - connection="
050:                                    + connection);
051:                    this .connection = connection;
052:                } catch (Exception ex) {
053:                    ex.printStackTrace();
054:                }
055:
056:            }
057:
058:            /**
059:             *Sets the maxFieldSize attribute of the I18nStatement object
060:             *
061:             * @param  p0                The new maxFieldSize value
062:             * @exception  SQLException  Description of Exception
063:             * @since
064:             */
065:            public void setMaxFieldSize(int p0) throws SQLException {
066:                throw new SQLException("Not Supported !");
067:            }
068:
069:            /**
070:             *Sets the maxRows attribute of the I18nStatement object
071:             *
072:             * @param  p0                The new maxRows value
073:             * @exception  SQLException  Description of Exception
074:             * @since
075:             */
076:            public void setMaxRows(int p0) throws SQLException {
077:                throw new SQLException("Not Supported !");
078:            }
079:
080:            /**
081:             *Sets the escapeProcessing attribute of the I18nStatement object
082:             *
083:             * @param  p0                The new escapeProcessing value
084:             * @exception  SQLException  Description of Exception
085:             * @since
086:             */
087:            public void setEscapeProcessing(boolean p0) throws SQLException {
088:                throw new SQLException("Not Supported !");
089:            }
090:
091:            /**
092:             *Sets the queryTimeout attribute of the I18nStatement object
093:             *
094:             * @param  p0                The new queryTimeout value
095:             * @exception  SQLException  Description of Exception
096:             * @since
097:             */
098:            public void setQueryTimeout(int p0) throws SQLException {
099:                throw new SQLException("Not Supported !");
100:            }
101:
102:            /**
103:             *Sets the cursorName attribute of the I18nStatement object
104:             *
105:             * @param  p0                The new cursorName value
106:             * @exception  SQLException  Description of Exception
107:             * @since
108:             */
109:            public void setCursorName(String p0) throws SQLException {
110:                throw new SQLException("Not Supported !");
111:            }
112:
113:            /**
114:             *Sets the fetchDirection attribute of the I18nStatement object
115:             *
116:             * @param  p0                The new fetchDirection value
117:             * @exception  SQLException  Description of Exception
118:             * @since
119:             */
120:            public void setFetchDirection(int p0) throws SQLException {
121:                throw new SQLException("Not Supported !");
122:            }
123:
124:            /**
125:             *Sets the fetchSize attribute of the I18nStatement object
126:             *
127:             * @param  p0                The new fetchSize value
128:             * @exception  SQLException  Description of Exception
129:             * @since
130:             */
131:            public void setFetchSize(int p0) throws SQLException {
132:                throw new SQLException("Not Supported !");
133:            }
134:
135:            /**
136:             *Gets the maxFieldSize attribute of the I18nStatement object
137:             *
138:             * @return                   The maxFieldSize value
139:             * @exception  SQLException  Description of Exception
140:             * @since
141:             */
142:            public int getMaxFieldSize() throws SQLException {
143:                throw new SQLException("Not Supported !");
144:            }
145:
146:            /**
147:             *Gets the maxRows attribute of the I18nStatement object
148:             *
149:             * @return                   The maxRows value
150:             * @exception  SQLException  Description of Exception
151:             * @since
152:             */
153:            public int getMaxRows() throws SQLException {
154:                throw new SQLException("Not Supported !");
155:            }
156:
157:            /**
158:             *Gets the queryTimeout attribute of the I18nStatement object
159:             *
160:             * @return                   The queryTimeout value
161:             * @exception  SQLException  Description of Exception
162:             * @since
163:             */
164:            public int getQueryTimeout() throws SQLException {
165:                throw new SQLException("Not Supported !");
166:            }
167:
168:            /**
169:             *Gets the warnings attribute of the I18nStatement object
170:             *
171:             * @return                   The warnings value
172:             * @exception  SQLException  Description of Exception
173:             * @since
174:             */
175:            public SQLWarning getWarnings() throws SQLException {
176:                throw new SQLException("Not Supported !");
177:            }
178:
179:            /**
180:             *Gets the resultSet attribute of the I18nStatement object
181:             *
182:             * @return                   The resultSet value
183:             * @exception  SQLException  Description of Exception
184:             * @since
185:             */
186:            public ResultSet getResultSet() throws SQLException {
187:                throw new SQLException("Not Supported !");
188:            }
189:
190:            /**
191:             *Gets the updateCount attribute of the I18nStatement object
192:             *
193:             * @return                   The updateCount value
194:             * @exception  SQLException  Description of Exception
195:             * @since
196:             */
197:            public int getUpdateCount() throws SQLException {
198:                throw new SQLException("Not Supported !");
199:            }
200:
201:            /**
202:             *Gets the moreResults attribute of the I18nStatement object
203:             *
204:             * @return                   The moreResults value
205:             * @exception  SQLException  Description of Exception
206:             * @since
207:             */
208:            public boolean getMoreResults() throws SQLException {
209:                throw new SQLException("Not Supported !");
210:            }
211:
212:            /**
213:             *Gets the fetchDirection attribute of the I18nStatement object
214:             *
215:             * @return                   The fetchDirection value
216:             * @exception  SQLException  Description of Exception
217:             * @since
218:             */
219:            public int getFetchDirection() throws SQLException {
220:                throw new SQLException("Not Supported !");
221:            }
222:
223:            /**
224:             *Gets the fetchSize attribute of the I18nStatement object
225:             *
226:             * @return                   The fetchSize value
227:             * @exception  SQLException  Description of Exception
228:             * @since
229:             */
230:            public int getFetchSize() throws SQLException {
231:                throw new SQLException("Not Supported !");
232:            }
233:
234:            /**
235:             *Gets the resultSetConcurrency attribute of the I18nStatement object
236:             *
237:             * @return                   The resultSetConcurrency value
238:             * @exception  SQLException  Description of Exception
239:             * @since
240:             */
241:            public int getResultSetConcurrency() throws SQLException {
242:                throw new SQLException("Not Supported !");
243:            }
244:
245:            /**
246:             *Gets the resultSetType attribute of the I18nStatement object
247:             *
248:             * @return                   The resultSetType value
249:             * @exception  SQLException  Description of Exception
250:             * @since
251:             */
252:            public int getResultSetType() throws SQLException {
253:                throw new SQLException("Not Supported !");
254:            }
255:
256:            /**
257:             *Gets the connection attribute of the I18nStatement object
258:             *
259:             * @return                   The connection value
260:             * @exception  SQLException  Description of Exception
261:             * @since
262:             */
263:            public Connection getConnection() throws SQLException {
264:                return connection;
265:            }
266:
267:            /**
268:             *Description of the Method
269:             *
270:             * @param  sql               Description of Parameter
271:             * @return                   Description of the Returned Value
272:             * @exception  SQLException  Description of Exception
273:             * @since
274:             */
275:            public ResultSet executeQuery(String sql) throws SQLException {
276:                DriverManager
277:                        .println("I18nJdbc - I18nStatement:executeQuery() - sql= "
278:                                + sql);
279:                I18nSqlParser parser = new I18nSqlParser();
280:                this .sql = sql;
281:                try {
282:                    parser.parse(this );
283:                } catch (Exception e) {
284:                    throw new SQLException("Syntax Error. " + e.getMessage());
285:                }
286:
287:                String fileName = connection.getPath() + parser.getTableName()
288:                        + connection.getExtension();
289:                File checkFile = new File(fileName);
290:                if (!checkFile.exists()) {
291:                    throw new SQLException("Cannot open data file '" + fileName
292:                            + "'  !");
293:                }
294:
295:                if (!checkFile.canRead()) {
296:                    throw new SQLException("Data file '" + fileName
297:                            + "'  not readable !");
298:                }
299:
300:                try {
301:
302:                    String[] xxx = parser.getColumnNames();
303:                    String[] yyy = connection.getColumnNames();
304:                    boolean isOK = true;
305:                    for (int i = 0; i < xxx.length; i++) {
306:                        if (!xxx[i].endsWith("*")) {
307:                            out: for (int j = 0; j < yyy.length; j++) {
308:                                if (xxx[i].equalsIgnoreCase(yyy[j])) {
309:                                    isOK = true;
310:                                    break out;
311:                                } else
312:                                    isOK = false;
313:                            }
314:                            if (!isOK)
315:                                throw new SQLException("Column '" + xxx[i]
316:                                        + "' not found.");
317:                        }
318:                    }
319:                } catch (Exception e) {
320:                    if (I18nDriver.DEBUG)
321:                        e.printStackTrace();
322:                    throw new SQLException(
323:                            "Error reading data file. Message was: " + e);
324:                }
325:
326:                this .connection.setCurrentTableName(parser.getTableName());
327:
328:                //load properties file
329:                try {
330:                    if (this .connection.getAutoCommit()) {
331:                        this .connection.getProperties().load(
332:                                new FileInputStream(checkFile));
333:                    }
334:                } catch (Exception e) {
335:                    throw new SQLException("Error while loading properties");
336:                }
337:
338:                I18nResultSet resultSet = new I18nResultSet(this , parser
339:                        .getTableName(), parser.getColumnNames(), parser
340:                        .getWhereColumnNames(), parser.getWhereColumnValues());
341:                resultSets.add(resultSet);
342:                return resultSet;
343:            }
344:
345:            /**
346:             *Description of the Method
347:             *
348:             * @param  sql               Description of Parameter
349:             * @return                   Description of the Returned Value
350:             * @exception  SQLException  Description of Exception
351:             * @since
352:             */
353:            public int executeUpdate(String sql) throws SQLException {
354:                int updated = 0;
355:                DriverManager
356:                        .println("I18nJdbc - I18nStatement:executeUpdate() - sql= "
357:                                + sql);
358:                I18nSqlParser parser = new I18nSqlParser();
359:                this .sql = sql;
360:                try {
361:                    parser.parse(this );
362:                } catch (Exception e) {
363:                    throw new SQLException("Syntax Error. " + e.getMessage());
364:                }
365:                if (parser.sqlType.equals(I18nSqlParser.SELECT))
366:                    throw new SQLException(
367:                            "Not supported SELECT statement - use executeQuery method");
368:                else if (parser.sqlType.equals(I18nSqlParser.CREATE_TABLE)) {
369:                    throw new SQLException(
370:                            "Not supported CREATE TABLE statement - use execute method");
371:                } else if (parser.sqlType.equals(I18nSqlParser.INSERT)) {
372:                    String fileName = connection.getPath()
373:                            + parser.getTableName() + connection.getExtension();
374:                    File checkFile = new File(fileName);
375:
376:                    if (!checkFile.exists()) {
377:                        throw new SQLException("Cannot open data file '"
378:                                + fileName + "'  !");
379:                    }
380:
381:                    if (!checkFile.canWrite()) {
382:                        throw new SQLException("Data file '" + fileName
383:                                + "'  is read only !");
384:                    }
385:                    try {
386:                        String[] xxx = parser.getColumnNames();
387:                        String[] yyy = connection.getColumnNames();
388:                        boolean isOK = true;
389:                        for (int i = 0; i < xxx.length; i++) {
390:                            if (!xxx[i].endsWith("*")) {
391:                                out: for (int j = 0; j < yyy.length; j++) {
392:                                    if (xxx[i].equalsIgnoreCase(yyy[j])) {
393:                                        isOK = true;
394:                                        break out;
395:                                    } else
396:                                        isOK = false;
397:                                }
398:                                if (!isOK)
399:                                    throw new SQLException("Column '" + xxx[i]
400:                                            + "' not found.");
401:                            }
402:                        }
403:                        try {
404:                            String[] colValues = parser.columnValues;
405:                            String[] colNames = parser.columnNames;
406:                            String keyColumn = connection.getNameColumn();
407:                            String key;
408:                            String value;
409:                            if (colNames.length != colValues.length) {
410:                                throw new Exception(
411:                                        "Number of columns and number of values are different!");
412:                            }
413:
414:                            if (colNames[0].equalsIgnoreCase(keyColumn)) {
415:                                key = colValues[0];
416:                                value = colValues[1];
417:                            } else {
418:                                key = colValues[1];
419:                                value = colValues[0];
420:                            }
421:
422:                            this .connection.setCurrentTableName(parser
423:                                    .getTableName());
424:
425:                            if (this .connection.getAutoCommit()) {
426:                                this .connection.getProperties().load(
427:                                        new FileInputStream(checkFile));
428:                            }
429:                            if (this .connection.getProperties()
430:                                    .containsKey(key) == true) {
431:                                throw new Exception(
432:                                        "Key already exist in the property file. Key must be unique!");
433:                            } else {
434:                                this .connection.getProperties().put(key, value);
435:                                if (this .connection.getAutoCommit()) {
436:                                    this .connection.getProperties().store(
437:                                            checkFile);
438:                                }
439:                                updated++;
440:                            }
441:
442:                        } catch (Exception e) {
443:                            throw new SQLException(
444:                                    "Error writing data to property file."
445:                                            + e.getMessage());
446:                        }
447:                    } catch (Exception e) {
448:                        throw new SQLException(
449:                                "Error writing data file. Message was: " + e);
450:                    }
451:
452:                } else if (parser.sqlType.equals(I18nSqlParser.UPDATE)) {
453:
454:                    String fileName = connection.getPath()
455:                            + parser.getTableName() + connection.getExtension();
456:                    File checkFile = new File(fileName);
457:
458:                    if (!checkFile.exists()) {
459:                        throw new SQLException("Cannot open data file '"
460:                                + fileName + "'  !");
461:                    }
462:
463:                    if (!checkFile.canWrite()) {
464:                        throw new SQLException("Data file '" + fileName
465:                                + "'  is read only !");
466:                    }
467:
468:                    try {
469:                        String[] xxx = parser.getColumnNames();
470:                        String[] yyy = connection.getColumnNames();
471:                        boolean isOK = true;
472:                        for (int i = 0; i < xxx.length; i++) {
473:                            if (!xxx[i].endsWith("*")) {
474:                                out: for (int j = 0; j < yyy.length; j++) {
475:                                    if (xxx[i].equalsIgnoreCase(yyy[j])) {
476:                                        isOK = true;
477:                                        break out;
478:                                    } else
479:                                        isOK = false;
480:                                }
481:                                if (!isOK)
482:                                    throw new SQLException("Column '" + xxx[i]
483:                                            + "' not found.");
484:                            }
485:                        }
486:
487:                        try {
488:                            String[] colValues = parser.columnValues;
489:                            String[] colNames = parser.columnNames;
490:                            String[] colWhereNames = parser.columnWhereNames;
491:                            String[] colWhereValues = parser.columnWhereValues;
492:                            String keyColumn = connection.getNameColumn();
493:                            String valueColumn = connection.getValueColumn();
494:                            String key = "";
495:                            String value = "";
496:                            boolean paramsOK = true;
497:                            //pick up values which will be updated.This block is used if firs column is 
498:                            // key column
499:                            if (colNames[0].equalsIgnoreCase(keyColumn)) {
500:                                if (colValues.length == 1) {
501:                                    key = colValues[0];
502:                                } else if (colValues.length == 2) {
503:                                    key = colValues[0];
504:                                    value = colValues[1];
505:                                }
506:                                //pick up values which will be updated.This block is used if first column is 
507:                                //value column
508:                            } else if (colNames[0]
509:                                    .equalsIgnoreCase(valueColumn)) {
510:                                if (colValues.length == 1) {
511:                                    value = colValues[0];
512:                                } else if (colValues.length == 2) {
513:                                    value = colValues[0];
514:                                    key = colValues[1];
515:
516:                                }
517:
518:                            }
519:                            //if number of columns for update is (1 or 2) then paramsOK=true 
520:                            this .connection.setCurrentTableName(parser
521:                                    .getTableName());
522:                            if (this .connection.getAutoCommit()) {
523:                                this .connection.getProperties().load(
524:                                        new FileInputStream(checkFile));
525:                            }
526:                            //column name in where claus is wrong
527:                            if (!(colWhereNames[0].equalsIgnoreCase(keyColumn) || colWhereNames[0]
528:                                    .equalsIgnoreCase(valueColumn))) {
529:                                throw new SQLException(
530:                                        "Error in sql statement. Wrong column name!");
531:                            }
532:                            if ((!key.equalsIgnoreCase(""))
533:                                    && (!value.equalsIgnoreCase(""))) {
534:                                Enumeration en = this .connection
535:                                        .getProperties().keys();
536:                                while (en.hasMoreElements()) {
537:                                    String oldKey = en.nextElement().toString();
538:                                    String oldValue = this .connection
539:                                            .getProperties()
540:                                            .getProperty(oldKey);
541:                                    //update key and value if this key is equal with key from where claus and also column name from where claus is equal with key column
542:                                    //or update key and value if this value is equal with value from where claus and also column name from where claus is equal with value column
543:                                    if ((colWhereValues[0]
544:                                            .equalsIgnoreCase(oldKey) && keyColumn
545:                                            .equals(colWhereNames[0]))
546:                                            || (colWhereValues[0]
547:                                                    .equalsIgnoreCase(oldValue) && valueColumn
548:                                                    .equals(colWhereNames[0]))) {
549:                                        this .connection.getProperties().remove(
550:                                                oldKey);
551:                                        this .connection.getProperties().put(
552:                                                key, value);
553:                                        updated++;
554:                                    }
555:                                }
556:
557:                            } else if (!value.equalsIgnoreCase("")) {
558:
559:                                Enumeration en = this .connection
560:                                        .getProperties().keys();
561:                                while (en.hasMoreElements()) {
562:                                    String oldKey = en.nextElement().toString();
563:                                    String oldValue = this .connection
564:                                            .getProperties()
565:                                            .getProperty(oldKey);
566:                                    //update value if this key is equal with key from where claus and also column name from where claus is equal with key column
567:                                    //or update value if this value is equal with value from where claus and also column name from where claus is equal with value column                                             
568:                                    if ((colWhereValues[0]
569:                                            .equalsIgnoreCase(oldKey) && keyColumn
570:                                            .equals(colWhereNames[0]))
571:                                            || (colWhereValues[0]
572:                                                    .equalsIgnoreCase(oldValue) && valueColumn
573:                                                    .equals(colWhereNames[0]))) {
574:                                        this .connection.getProperties().put(
575:                                                oldKey, value);
576:                                        updated++;
577:                                    }
578:                                }
579:                            } else if (!key.equalsIgnoreCase("")) {
580:
581:                                Enumeration en = this .connection
582:                                        .getProperties().keys();
583:                                while (en.hasMoreElements()) {
584:                                    String oldKey = en.nextElement().toString();
585:                                    String oldValue = this .connection
586:                                            .getProperties()
587:                                            .getProperty(oldKey);
588:                                    //update key if this key is equal with key from where claus and also column name from where claus is equal with key column
589:                                    //or update key if this value is equal with value from where claus and also column name from where claus is equal with value column
590:
591:                                    if ((colWhereValues[0]
592:                                            .equalsIgnoreCase(oldKey) && keyColumn
593:                                            .equals(colWhereNames[0]))
594:                                            || (colWhereValues[0]
595:                                                    .equalsIgnoreCase(oldValue) && valueColumn
596:                                                    .equals(colWhereNames[0]))) {
597:                                        this .connection.getProperties().remove(
598:                                                oldKey);
599:                                        this .connection.getProperties().put(
600:                                                key, oldValue);
601:                                        updated++;
602:                                    }
603:                                }
604:                            }
605:                            if (this .connection.getAutoCommit()) {
606:                                this .connection.getProperties()
607:                                        .store(checkFile);
608:                            }
609:
610:                        } catch (Exception e) {
611:                            throw new SQLException(
612:                                    "Error writing data to property file."
613:                                            + e.getMessage());
614:                        }
615:
616:                    } catch (Exception e) {
617:                        throw new SQLException(
618:                                "Error writing data file. Message was: " + e);
619:                    }
620:
621:                } else if (parser.sqlType.equals(I18nSqlParser.DELETE)) {
622:                    String fileName = connection.getPath()
623:                            + parser.getTableName() + connection.getExtension();
624:                    File checkFile = new File(fileName);
625:
626:                    if (!checkFile.exists()) {
627:                        throw new SQLException("Cannot open data file '"
628:                                + fileName + "'  !");
629:                    }
630:
631:                    if (!checkFile.canWrite()) {
632:                        throw new SQLException("Data file '" + fileName
633:                                + "'  is read only !");
634:                    }
635:                    try {
636:
637:                        boolean deleteAll = false;
638:                        String[] colWhereNames = parser.columnWhereNames;
639:                        String[] colWhereValues = parser.columnWhereValues;
640:                        String keyColumn = connection.getNameColumn();
641:                        String valueColumn = connection.getValueColumn();
642:
643:                        this .connection.setCurrentTableName(parser
644:                                .getTableName());
645:                        if (this .connection.getAutoCommit()) {
646:                            this .connection.getProperties().load(
647:                                    new FileInputStream(checkFile));
648:                        }
649:                        if (!(colWhereNames[0].equalsIgnoreCase(keyColumn) || colWhereNames[0]
650:                                .equalsIgnoreCase(valueColumn))) {
651:                            throw new SQLException(
652:                                    "Error in sql statement. Wrong column name!");
653:                        }
654:                        Enumeration en = this .connection.getProperties().keys();
655:                        if (colWhereNames.length == 0) {
656:                            deleteAll = true;
657:                        }
658:                        if (!deleteAll) {
659:                            while (en.hasMoreElements()) {
660:                                String oldKey = en.nextElement().toString();
661:                                String oldValue = this .connection
662:                                        .getProperties().getProperty(oldKey);
663:
664:                                if ((colWhereValues[0].equalsIgnoreCase(oldKey) && keyColumn
665:                                        .equals(colWhereNames[0]))
666:                                        || (colWhereValues[0]
667:                                                .equalsIgnoreCase(oldValue) && valueColumn
668:                                                .equals(colWhereNames[0]))) {
669:                                    this .connection.getProperties().remove(
670:                                            oldKey);
671:                                    if (this .connection.getAutoCommit()) {
672:                                        this .connection.getProperties().store(
673:                                                checkFile);
674:                                    }
675:                                    updated++;
676:                                }
677:
678:                            }
679:                        } else {
680:                            this .connection.getProperties().clear();
681:                            if (this .connection.getAutoCommit()) {
682:                                this .connection.getProperties()
683:                                        .store(checkFile);
684:                            }
685:                        }
686:                    } catch (Exception e) {
687:                        throw new SQLException(
688:                                "Error deleting data from property file."
689:                                        + e.getMessage());
690:                    }
691:
692:                }
693:                return updated;
694:
695:            }
696:
697:            /**
698:             * Releases this <code>Statement</code> object's database
699:             * and JDBC resources immediately instead of waiting for
700:             * this to happen when it is automatically closed.
701:             * It is generally good practice to release resources as soon as
702:             * you are finished with them to avoid tying up database
703:             * resources.
704:             * <P>
705:             * Calling the method <code>close</code> on a <code>Statement</code>
706:             * object that is already closed has no effect.
707:             * <P>
708:             * <B>Note:</B> A <code>Statement</code> object is automatically closed
709:             * when it is garbage collected. When a <code>Statement</code> object is
710:             * closed, its current <code>ResultSet</code> object, if one exists, is
711:             * also closed.
712:             *
713:             * @exception SQLException if a database access error occurs
714:             */
715:            public void close() throws SQLException {
716:                // close all result sets
717:                for (Enumeration i = resultSets.elements(); i.hasMoreElements();) {
718:                    I18nResultSet resultSet = (I18nResultSet) i.nextElement();
719:                    resultSet.close();
720:                }
721:
722:            }
723:
724:            /**
725:             *Description of the Method
726:             *
727:             * @exception  SQLException  Description of Exception
728:             * @since
729:             */
730:            public void cancel() throws SQLException {
731:                throw new SQLException("Not Supported !");
732:            }
733:
734:            /**
735:             *Description of the Method
736:             *
737:             * @exception  SQLException  Description of Exception
738:             * @since
739:             */
740:            public void clearWarnings() throws SQLException {
741:                throw new SQLException("Not Supported !");
742:            }
743:
744:            /**
745:             *Description of the Method
746:             *
747:             * @param  sql               Description of Parameter
748:             * @return                   Description of the Returned Value
749:             * @exception  SQLException  Description of Exception
750:             * @since
751:             */
752:            public boolean execute(String sql) throws SQLException {
753:
754:                I18nSqlParser parser = new I18nSqlParser();
755:                this .sql = sql;
756:                try {
757:                    parser.parse(this );
758:                } catch (Exception e) {
759:                    throw new SQLException("Syntax Error. " + e.getMessage());
760:                }
761:                if (parser.sqlType.equals(I18nSqlParser.SELECT))
762:                    throw new SQLException(
763:                            "Not supported SELECT statement - use executeQuery method");
764:                else if (parser.sqlType.equals(I18nSqlParser.INSERT))
765:                    executeUpdate(sql);
766:                else if (parser.sqlType.equals(I18nSqlParser.CREATE_TABLE)) {
767:                    String fileName = connection.getPath()
768:                            + parser.getTableName() + connection.getExtension();
769:                    File checkFile = new File(fileName);
770:
771:                    if (checkFile.exists()) {
772:                        throw new SQLException("Data file '" + fileName
773:                                + "'already exists  !");
774:                    }
775:
776:                    try {
777:                        checkFile.createNewFile();
778:
779:                    } catch (Exception e) {
780:                        throw new SQLException(
781:                                "Error reading data file. Message was: " + e);
782:                    }
783:                }
784:                return true;
785:
786:            }
787:
788:            /**
789:             *Adds a feature to the Batch attribute of the I18nStatement object
790:             *
791:             * @param  p0                The feature to be added to the Batch attribute
792:             * @exception  SQLException  Description of Exception
793:             * @since
794:             */
795:            public void addBatch(String p0) throws SQLException {
796:                throw new SQLException("Not Supported !");
797:            }
798:
799:            /**
800:             *Description of the Method
801:             *
802:             * @exception  SQLException  Description of Exception
803:             * @since
804:             */
805:            public void clearBatch() throws SQLException {
806:                throw new SQLException("Not Supported !");
807:            }
808:
809:            /**
810:             *Description of the Method
811:             *
812:             * @return                   Description of the Returned Value
813:             * @exception  SQLException  Description of Exception
814:             * @since
815:             */
816:            public int[] executeBatch() throws SQLException {
817:                throw new SQLException("Not Supported !");
818:            }
819:
820:            //---------------------------------------------------------------------
821:            // JDBC 3.0
822:            //---------------------------------------------------------------------
823:
824:            public boolean getMoreResults(int current) throws SQLException {
825:                throw new UnsupportedOperationException(
826:                        "Statement.getMoreResults(int) unsupported");
827:            }
828:
829:            public ResultSet getGeneratedKeys() throws SQLException {
830:                throw new UnsupportedOperationException(
831:                        "Statement.getGeneratedKeys() unsupported");
832:            }
833:
834:            public int executeUpdate(String sql, int autoGeneratedKeys)
835:                    throws SQLException {
836:                throw new UnsupportedOperationException(
837:                        "Statement.executeUpdate(String,int) unsupported");
838:            }
839:
840:            public int executeUpdate(String sql, int[] columnIndexes)
841:                    throws SQLException {
842:                throw new UnsupportedOperationException(
843:                        "Statement.executeUpdate(String,int[]) unsupported");
844:            }
845:
846:            public int executeUpdate(String sql, String[] columnNames)
847:                    throws SQLException {
848:                throw new UnsupportedOperationException(
849:                        "Statement.executeUpdate(String,String[]) unsupported");
850:            }
851:
852:            public boolean execute(String sql, int autoGeneratedKeys)
853:                    throws SQLException {
854:                throw new UnsupportedOperationException(
855:                        "Statement.execute(String,int) unsupported");
856:            }
857:
858:            public boolean execute(String sql, int[] columnIndexes)
859:                    throws SQLException {
860:                throw new UnsupportedOperationException(
861:                        "Statement.execute(String,int[]) unsupported");
862:            }
863:
864:            public boolean execute(String sql, String[] columnNames)
865:                    throws SQLException {
866:                throw new UnsupportedOperationException(
867:                        "Statement.execute(String,String[]) unsupported");
868:            }
869:
870:            public int getResultSetHoldability() throws SQLException {
871:                throw new UnsupportedOperationException(
872:                        "Statement.getResultSetHoldability() unsupported");
873:            }
874:
875:            /**
876:             * This method returns string which represents sql statement
877:             * @return string 
878:             */
879:            public String getSqlStatement() {
880:                return sql;
881:            }
882:
883:            /**
884:             * This method returns properties object
885:             * @return properties object
886:             */
887:            public I18nProperties getProperties() {
888:                return this .connection.getProperties();
889:            }
890:
891:            public boolean isClosed() throws SQLException {
892:                // TODO Auto-generated method stub
893:                return false;
894:            }
895:
896:            public boolean isPoolable() throws SQLException {
897:                // TODO Auto-generated method stub
898:                return false;
899:            }
900:
901:            public void setPoolable(boolean poolable) throws SQLException {
902:                // TODO Auto-generated method stub
903:                throw new UnsupportedOperationException(
904:                        "I18nStatement.setPoolable(boolean) unsupported");
905:            }
906:
907:            public boolean isWrapperFor(Class<?> iface) throws SQLException {
908:                // TODO Auto-generated method stub
909:                return false;
910:            }
911:
912:            public <T> T unwrap(Class<T> iface) throws SQLException {
913:                // TODO Auto-generated method stub
914:                return null;
915:            }
916:
917:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.