KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > i18njdbc > I18nStatement


1 /**
2     Copyright (C) 2002-2003 Together
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     Lesser General Public License for more details.
13
14     You should have received a copy of the GNU Lesser General Public
15     License along with this library; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 */

19
20 package org.webdocwf.util.i18njdbc;
21
22 import java.sql.*;
23 import java.io.File JavaDoc;
24 import java.io.FileInputStream JavaDoc;
25 import java.util.Enumeration JavaDoc;
26
27 import java.util.Vector JavaDoc;
28
29
30
31
32 /**
33  * This class implements the Statement interface for the I18nJdbc driver.
34  *
35  * @author Zoran Milakovic
36  * @author Zeljko Kovacevic
37  */

38
39 public class I18nStatement implements Statement
40 {
41
42     private I18nConnection connection;
43     private Vector JavaDoc resultSets = new Vector JavaDoc();
44     private String JavaDoc sql;
45     
46     /**
47      *Constructor for the I18nStatement object
48      *
49      * @param connection Description of Parameter
50      * @since
51      */

52     protected I18nStatement(I18nConnection connection)
53     {
54         try {
55         DriverManager.println("I18nJdbc - I18Statement() - connection=" + connection);
56         this.connection = connection;
57         }
58         catch(Exception JavaDoc ex) {
59           ex.printStackTrace();
60         }
61
62       }
63
64
65     /**
66      *Sets the maxFieldSize attribute of the I18nStatement object
67      *
68      * @param p0 The new maxFieldSize value
69      * @exception SQLException Description of Exception
70      * @since
71      */

72     public void setMaxFieldSize(int p0) throws SQLException
73     {
74         throw new SQLException("Not Supported !");
75     }
76
77
78     /**
79      *Sets the maxRows attribute of the I18nStatement object
80      *
81      * @param p0 The new maxRows value
82      * @exception SQLException Description of Exception
83      * @since
84      */

85     public void setMaxRows(int p0) throws SQLException
86     {
87         throw new SQLException("Not Supported !");
88     }
89
90
91     /**
92      *Sets the escapeProcessing attribute of the I18nStatement object
93      *
94      * @param p0 The new escapeProcessing value
95      * @exception SQLException Description of Exception
96      * @since
97      */

98     public void setEscapeProcessing(boolean p0) throws SQLException
99     {
100         throw new SQLException("Not Supported !");
101     }
102
103
104     /**
105      *Sets the queryTimeout attribute of the I18nStatement object
106      *
107      * @param p0 The new queryTimeout value
108      * @exception SQLException Description of Exception
109      * @since
110      */

111     public void setQueryTimeout(int p0) throws SQLException
112     {
113         throw new SQLException("Not Supported !");
114     }
115
116
117     /**
118      *Sets the cursorName attribute of the I18nStatement object
119      *
120      * @param p0 The new cursorName value
121      * @exception SQLException Description of Exception
122      * @since
123      */

124     public void setCursorName(String JavaDoc p0) throws SQLException
125     {
126         throw new SQLException("Not Supported !");
127     }
128
129
130     /**
131      *Sets the fetchDirection attribute of the I18nStatement object
132      *
133      * @param p0 The new fetchDirection value
134      * @exception SQLException Description of Exception
135      * @since
136      */

137     public void setFetchDirection(int p0) throws SQLException
138     {
139         throw new SQLException("Not Supported !");
140     }
141
142
143     /**
144      *Sets the fetchSize attribute of the I18nStatement object
145      *
146      * @param p0 The new fetchSize value
147      * @exception SQLException Description of Exception
148      * @since
149      */

150     public void setFetchSize(int p0) throws SQLException
151     {
152         throw new SQLException("Not Supported !");
153     }
154
155
156     /**
157      *Gets the maxFieldSize attribute of the I18nStatement object
158      *
159      * @return The maxFieldSize value
160      * @exception SQLException Description of Exception
161      * @since
162      */

163     public int getMaxFieldSize() throws SQLException
164     {
165         throw new SQLException("Not Supported !");
166     }
167
168
169     /**
170      *Gets the maxRows attribute of the I18nStatement object
171      *
172      * @return The maxRows value
173      * @exception SQLException Description of Exception
174      * @since
175      */

176     public int getMaxRows() throws SQLException
177     {
178         throw new SQLException("Not Supported !");
179     }
180
181
182     /**
183      *Gets the queryTimeout attribute of the I18nStatement object
184      *
185      * @return The queryTimeout value
186      * @exception SQLException Description of Exception
187      * @since
188      */

189     public int getQueryTimeout() throws SQLException
190     {
191         throw new SQLException("Not Supported !");
192     }
193
194
195     /**
196      *Gets the warnings attribute of the I18nStatement object
197      *
198      * @return The warnings value
199      * @exception SQLException Description of Exception
200      * @since
201      */

202     public SQLWarning getWarnings() throws SQLException
203     {
204         throw new SQLException("Not Supported !");
205     }
206
207
208     /**
209      *Gets the resultSet attribute of the I18nStatement object
210      *
211      * @return The resultSet value
212      * @exception SQLException Description of Exception
213      * @since
214      */

215     public ResultSet getResultSet() throws SQLException
216     {
217         throw new SQLException("Not Supported !");
218     }
219
220
221     /**
222      *Gets the updateCount attribute of the I18nStatement object
223      *
224      * @return The updateCount value
225      * @exception SQLException Description of Exception
226      * @since
227      */

228     public int getUpdateCount() throws SQLException
229     {
230         throw new SQLException("Not Supported !");
231     }
232
233
234     /**
235      *Gets the moreResults attribute of the I18nStatement object
236      *
237      * @return The moreResults value
238      * @exception SQLException Description of Exception
239      * @since
240      */

241     public boolean getMoreResults() throws SQLException
242     {
243         throw new SQLException("Not Supported !");
244     }
245
246
247     /**
248      *Gets the fetchDirection attribute of the I18nStatement object
249      *
250      * @return The fetchDirection value
251      * @exception SQLException Description of Exception
252      * @since
253      */

254     public int getFetchDirection() throws SQLException
255     {
256         throw new SQLException("Not Supported !");
257     }
258
259
260     /**
261      *Gets the fetchSize attribute of the I18nStatement object
262      *
263      * @return The fetchSize value
264      * @exception SQLException Description of Exception
265      * @since
266      */

267     public int getFetchSize() throws SQLException
268     {
269         throw new SQLException("Not Supported !");
270     }
271
272
273     /**
274      *Gets the resultSetConcurrency attribute of the I18nStatement object
275      *
276      * @return The resultSetConcurrency value
277      * @exception SQLException Description of Exception
278      * @since
279      */

280     public int getResultSetConcurrency() throws SQLException
281     {
282         throw new SQLException("Not Supported !");
283     }
284
285
286     /**
287      *Gets the resultSetType attribute of the I18nStatement object
288      *
289      * @return The resultSetType value
290      * @exception SQLException Description of Exception
291      * @since
292      */

293     public int getResultSetType() throws SQLException
294     {
295         throw new SQLException("Not Supported !");
296     }
297
298
299     /**
300      *Gets the connection attribute of the I18nStatement object
301      *
302      * @return The connection value
303      * @exception SQLException Description of Exception
304      * @since
305      */

306     public Connection getConnection() throws SQLException
307     {
308         return connection;
309     }
310
311
312     /**
313      *Description of the Method
314      *
315      * @param sql Description of Parameter
316      * @return Description of the Returned Value
317      * @exception SQLException Description of Exception
318      * @since
319      */

320     public ResultSet executeQuery(String JavaDoc sql) throws SQLException
321     {
322         DriverManager.println("I18nJdbc - I18nStatement:executeQuery() - sql= " + sql);
323         I18nSqlParser parser = new I18nSqlParser();
324         this.sql = sql;
325         try
326             {
327                 parser.parse(this);
328             }
329         catch (Exception JavaDoc e)
330             {
331                 throw new SQLException("Syntax Error. " + e.getMessage());
332             }
333
334     String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
335     File JavaDoc checkFile = new File JavaDoc(fileName);
336     if (!checkFile.exists())
337     {
338       throw new SQLException("Cannot open data file '" + fileName + "' !");
339     }
340
341     if (!checkFile.canRead())
342     {
343       throw new SQLException("Data file '" + fileName + "' not readable !");
344     }
345    
346     try
347     {
348
349                 String JavaDoc[] xxx = parser.getColumnNames();
350               String JavaDoc[] yyy = connection.getColumnNames();
351               boolean isOK = true;
352               for(int i=0; i< xxx.length; i++) {
353               if(!xxx[i].endsWith("*")) {
354                out:
355               for(int j=0; j< yyy.length; j++) {
356                  if(xxx[i].equalsIgnoreCase(yyy[j])) {
357                     isOK=true;
358                     break out;
359                   }
360                   else
361                     isOK=false;
362                 }
363                if(!isOK)
364                 throw new SQLException("Column '" + xxx[i] + "' not found.");
365               }
366               }
367     }
368     catch (Exception JavaDoc e)
369     {
370         if( I18nDriver.DEBUG )
371             e.printStackTrace();
372       throw new SQLException("Error reading data file. Message was: " + e);
373     }
374     
375     this.connection.setCurrentTableName(parser.getTableName());
376     
377     //load properties file
378
try {
379         if(this.connection.getAutoCommit()) {
380             this.connection.getProperties().load(new FileInputStream JavaDoc(checkFile));
381         }
382     } catch (Exception JavaDoc e) {
383         throw new SQLException("Error while loading properties");
384     }
385
386         I18nResultSet resultSet = new I18nResultSet(this,
387                     parser.getTableName(), parser.getColumnNames(), parser.getWhereColumnNames(),
388                     parser.getWhereColumnValues());
389     resultSets.add(resultSet);
390     return resultSet;
391   }
392
393
394
395     /**
396      *Description of the Method
397      *
398      * @param sql Description of Parameter
399      * @return Description of the Returned Value
400      * @exception SQLException Description of Exception
401      * @since
402      */

403     public int executeUpdate(String JavaDoc sql) throws SQLException
404     {
405     int updated=0;
406     DriverManager.println("I18nJdbc - I18nStatement:executeUpdate() - sql= " + sql);
407     I18nSqlParser parser = new I18nSqlParser();
408     this.sql = sql;
409     try
410     {
411       parser.parse(this);
412     }
413     catch (Exception JavaDoc e)
414     {
415       throw new SQLException("Syntax Error. " + e.getMessage());
416     }
417       if(parser.sqlType.equals(I18nSqlParser.SELECT))
418             throw new SQLException("Not supported SELECT statement - use executeQuery method");
419       else if (parser.sqlType.equals(I18nSqlParser.CREATE_TABLE)) {
420                 throw new SQLException("Not supported CREATE TABLE statement - use execute method");
421       }
422       else if (parser.sqlType.equals(I18nSqlParser.INSERT)) {
423            String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
424             File JavaDoc checkFile = new File JavaDoc(fileName);
425
426             if (!checkFile.exists())
427             {
428             throw new SQLException("Cannot open data file '" + fileName + "' !");
429             }
430
431             if (!checkFile.canWrite())
432             {
433             throw new SQLException("Data file '" + fileName + "' is read only !");
434             }
435               try
436               {
437                 String JavaDoc[] xxx = parser.getColumnNames();
438                                 String JavaDoc[] yyy = connection.getColumnNames();
439                 boolean isOK = true;
440                 for(int i=0; i< xxx.length; i++) {
441                   if(!xxx[i].endsWith("*")) {
442                   out:
443                   for(int j=0; j< yyy.length; j++) {
444                     if(xxx[i].equalsIgnoreCase(yyy[j])) {
445                       isOK=true;
446                       break out;
447                     }
448                   else
449                     isOK=false;
450                   }
451                 if(!isOK)
452                   throw new SQLException("Column '" + xxx[i] + "' not found.");
453                 }
454               }
455                  try {
456                                         String JavaDoc[] colValues = parser.columnValues;
457                                         String JavaDoc[] colNames = parser.columnNames;
458                                         String JavaDoc keyColumn=connection.getNameColumn();
459                                         String JavaDoc key;
460                                         String JavaDoc value;
461                                         if (colNames.length!=colValues.length){
462                                             throw new Exception JavaDoc("Number of columns and number of values are different!");
463                                         }
464                                         
465                                         if (colNames[0].equalsIgnoreCase(keyColumn)){
466                                             key = colValues[0];
467                                             value = colValues[1];
468                                         }else{
469                                           key = colValues[1];
470                                           value = colValues[0];
471                                         }
472                                         
473                                         this.connection.setCurrentTableName(parser.getTableName());
474                                         
475                                         if(this.connection.getAutoCommit()) {
476                                             this.connection.getProperties().load(new FileInputStream JavaDoc(checkFile));
477                                         }
478                                         if (this.connection.getProperties().containsKey(key)==true){
479                                                 throw new Exception JavaDoc("Key already exist in the property file. Key must be unique!");
480                                         }else{
481                                             this.connection.getProperties().put(key,value);
482                                             if(this.connection.getAutoCommit()) {
483                                                 this.connection.getProperties().store(checkFile);
484                                             }
485                                             updated++;
486                                         }
487                                         
488                         } catch (Exception JavaDoc e) {
489                            throw new SQLException("Error writing data to property file."+e.getMessage());
490                         }
491             }
492             catch (Exception JavaDoc e)
493             {
494             throw new SQLException("Error writing data file. Message was: " + e);
495             }
496
497       }
498       else if (parser.sqlType.equals(I18nSqlParser.UPDATE)) {
499
500                 String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
501             File JavaDoc checkFile = new File JavaDoc(fileName);
502
503             if (!checkFile.exists())
504             {
505             throw new SQLException("Cannot open data file '" + fileName + "' !");
506             }
507
508             if (!checkFile.canWrite())
509             {
510             throw new SQLException("Data file '" + fileName + "' is read only !");
511             }
512
513             try
514             {
515             String JavaDoc[] xxx = parser.getColumnNames();
516             String JavaDoc[] yyy = connection.getColumnNames();
517             boolean isOK = true;
518             for(int i=0; i< xxx.length; i++) {
519               if(!xxx[i].endsWith("*")) {
520                 out:
521               for(int j=0; j< yyy.length; j++) {
522                 if(xxx[i].equalsIgnoreCase(yyy[j])) {
523                   isOK=true;
524                   break out;
525                 }
526               else
527                 isOK=false;
528             }
529             if(!isOK)
530               throw new SQLException("Column '" + xxx[i] + "' not found.");
531               }
532             }
533            
534                     try {
535                            String JavaDoc[] colValues = parser.columnValues;
536                            String JavaDoc[] colNames = parser.columnNames;
537                            String JavaDoc[] colWhereNames = parser.columnWhereNames;
538                            String JavaDoc[] colWhereValues = parser.columnWhereValues;
539                            String JavaDoc keyColumn=connection.getNameColumn();
540                              String JavaDoc valueColumn=connection.getValueColumn();
541                            String JavaDoc key = "";
542                            String JavaDoc value = "";
543                            boolean paramsOK = true;
544                            //pick up values which will be updated.This block is used if firs column is
545
// key column
546
if (colNames[0].equalsIgnoreCase(keyColumn)){
547                                    if (colValues.length==1){
548                                     key = colValues[0];
549                                    }else if (colValues.length==2){
550                                         key = colValues[0];
551                                         value = colValues[1];
552                                    }
553                             //pick up values which will be updated.This block is used if first column is
554
//value column
555
}else if (colNames[0].equalsIgnoreCase(valueColumn)){
556                                         if (colValues.length==1){
557                                             value = colValues[0];
558                                         }else if (colValues.length==2){
559                                             value = colValues[0];
560                                             key = colValues[1];
561                                     
562                                         }
563
564                                }
565                                //if number of columns for update is (1 or 2) then paramsOK=true
566
this.connection.setCurrentTableName(parser.getTableName());
567                                if(this.connection.getAutoCommit()) {
568                                    this.connection.getProperties().load(new FileInputStream JavaDoc(checkFile));
569                                }
570                                //column name in where claus is wrong
571
if (!(colWhereNames[0].equalsIgnoreCase(keyColumn) || colWhereNames[0].equalsIgnoreCase(valueColumn))){
572                                     throw new SQLException("Error in sql statement. Wrong column name!");
573                                }
574                                 if ((!key.equalsIgnoreCase("")) && (!value.equalsIgnoreCase(""))){
575                                     Enumeration JavaDoc en = this.connection.getProperties().keys();
576                                         while(en.hasMoreElements()){
577                                                 String JavaDoc oldKey = en.nextElement().toString();
578                                                 String JavaDoc oldValue = this.connection.getProperties().getProperty(oldKey);
579                                                 //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
580
//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
581
if ((colWhereValues[0].equalsIgnoreCase(oldKey) && keyColumn.equals(colWhereNames[0]))
582                                                         ||(colWhereValues[0].equalsIgnoreCase(oldValue) && valueColumn.equals(colWhereNames[0]))){
583                                                     this.connection.getProperties().remove(oldKey);
584                                                     this.connection.getProperties().put(key, value);
585                                                     updated++;
586                                             }
587                                         }
588                                     
589                                     }else if (!value.equalsIgnoreCase("")){
590                             
591                                         Enumeration JavaDoc en = this.connection.getProperties().keys();
592                                             while(en.hasMoreElements()){
593                                                 String JavaDoc oldKey = en.nextElement().toString();
594                                                 String JavaDoc oldValue = this.connection.getProperties().getProperty(oldKey);
595                                                 //update value if this key is equal with key from where claus and also column name from where claus is equal with key column
596
//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
597
if ((colWhereValues[0].equalsIgnoreCase(oldKey) && keyColumn.equals(colWhereNames[0]))
598                                                          ||(colWhereValues[0].equalsIgnoreCase(oldValue) && valueColumn.equals(colWhereNames[0]))){
599                                                         this.connection.getProperties().put(oldKey,value);
600                                                         updated++;
601                                                     }
602                                             }
603                                 }else if (!key.equalsIgnoreCase("")){
604                                     
605                                             Enumeration JavaDoc en = this.connection.getProperties().keys();
606                                             while(en.hasMoreElements()){
607                                                 String JavaDoc oldKey = en.nextElement().toString();
608                                                 String JavaDoc oldValue = this.connection.getProperties().getProperty(oldKey);
609                                                 //update key if this key is equal with key from where claus and also column name from where claus is equal with key column
610
//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
611

612                                                 if ((colWhereValues[0].equalsIgnoreCase(oldKey) && keyColumn.equals(colWhereNames[0]))
613                                                             ||(colWhereValues[0].equalsIgnoreCase(oldValue) && valueColumn.equals(colWhereNames[0]))){
614                                                     this.connection.getProperties().remove(oldKey);
615                                                     this.connection.getProperties().put(key, oldValue);
616                                                     updated++;
617                                                 }
618                                             }
619                                 }
620                                 if(this.connection.getAutoCommit()) {
621                                     this.connection.getProperties().store(checkFile);
622                                 }
623                         
624                        } catch (Exception JavaDoc e) {
625                           throw new SQLException("Error writing data to property file."+e.getMessage());
626                        }
627                                 
628             }
629             catch (Exception JavaDoc e)
630             {
631             throw new SQLException("Error writing data file. Message was: " + e);
632             }
633
634         }else if (parser.sqlType.equals(I18nSqlParser.DELETE)){
635                      String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
636                      File JavaDoc checkFile = new File JavaDoc(fileName);
637             
638                      if (!checkFile.exists())
639                      {
640                      throw new SQLException("Cannot open data file '" + fileName + "' !");
641                      }
642             
643                      if (!checkFile.canWrite())
644                      {
645                      throw new SQLException("Data file '" + fileName + "' is read only !");
646                      }
647                         try
648                             {
649                              
650
651                                 boolean deleteAll=false;
652                                 String JavaDoc[] colWhereNames = parser.columnWhereNames;
653                                 String JavaDoc[] colWhereValues = parser.columnWhereValues;
654                               String JavaDoc keyColumn=connection.getNameColumn();
655                                 String JavaDoc valueColumn=connection.getValueColumn();
656                                 
657                                 this.connection.setCurrentTableName(parser.getTableName());
658                                 if(this.connection.getAutoCommit()) {
659                                     this.connection.getProperties().load(new FileInputStream JavaDoc(checkFile));
660                                 }
661                                 if (!(colWhereNames[0].equalsIgnoreCase(keyColumn) || colWhereNames[0].equalsIgnoreCase(valueColumn))){
662                                         throw new SQLException("Error in sql statement. Wrong column name!");
663                                 }
664                                 Enumeration JavaDoc en = this.connection.getProperties().keys();
665                                 if (colWhereNames.length==0){
666                                     deleteAll=true;
667                                 }
668                                 if (!deleteAll){
669                                     while(en.hasMoreElements()){
670                                         String JavaDoc oldKey = en.nextElement().toString();
671                                         String JavaDoc oldValue = this.connection.getProperties().getProperty(oldKey);
672                                                             
673                                                 if ((colWhereValues[0].equalsIgnoreCase(oldKey) && keyColumn.equals(colWhereNames[0]))
674                                                      ||(colWhereValues[0].equalsIgnoreCase(oldValue) && valueColumn.equals(colWhereNames[0]))){
675                                                     this.connection.getProperties().remove(oldKey);
676                                                     if(this.connection.getAutoCommit()) {
677                                                         this.connection.getProperties().store(checkFile);
678                                                     }
679                                                     updated++;
680                                                 }
681                                             
682                                     }
683                                 }else{
684                                         this.connection.getProperties().clear();
685                                         if(this.connection.getAutoCommit()) {
686                                             this.connection.getProperties().store(checkFile);
687                                         }
688                                 }
689                            } catch (Exception JavaDoc e) {
690                               throw new SQLException("Error deleting data from property file."+e.getMessage());
691                         }
692
693         }
694       return updated;
695
696   }
697
698
699     /**
700      * Releases this <code>Statement</code> object's database
701      * and JDBC resources immediately instead of waiting for
702      * this to happen when it is automatically closed.
703      * It is generally good practice to release resources as soon as
704      * you are finished with them to avoid tying up database
705      * resources.
706      * <P>
707      * Calling the method <code>close</code> on a <code>Statement</code>
708      * object that is already closed has no effect.
709      * <P>
710      * <B>Note:</B> A <code>Statement</code> object is automatically closed
711      * when it is garbage collected. When a <code>Statement</code> object is
712      * closed, its current <code>ResultSet</code> object, if one exists, is
713      * also closed.
714      *
715      * @exception SQLException if a database access error occurs
716      */

717     public void close() throws SQLException {
718       // close all result sets
719
for(Enumeration JavaDoc i = resultSets.elements(); i.hasMoreElements(); ) {
720         I18nResultSet resultSet = (I18nResultSet) i.nextElement();
721         resultSet.close();
722       }
723
724
725     }
726
727     /**
728      *Description of the Method
729      *
730      * @exception SQLException Description of Exception
731      * @since
732      */

733     public void cancel() throws SQLException
734     {
735         throw new SQLException("Not Supported !");
736     }
737
738
739     /**
740      *Description of the Method
741      *
742      * @exception SQLException Description of Exception
743      * @since
744      */

745     public void clearWarnings() throws SQLException
746     {
747         throw new SQLException("Not Supported !");
748     }
749
750
751     /**
752      *Description of the Method
753      *
754      * @param sql Description of Parameter
755      * @return Description of the Returned Value
756      * @exception SQLException Description of Exception
757      * @since
758      */

759     public boolean execute(String JavaDoc sql) throws SQLException
760   {
761
762     I18nSqlParser parser = new I18nSqlParser();
763     this.sql = sql;
764     try
765     {
766       parser.parse(this);
767     }
768     catch (Exception JavaDoc e)
769     {
770       throw new SQLException("Syntax Error. " + e.getMessage());
771     }
772       if(parser.sqlType.equals(I18nSqlParser.SELECT))
773             throw new SQLException("Not supported SELECT statement - use executeQuery method");
774       else if (parser.sqlType.equals(I18nSqlParser.INSERT))
775             executeUpdate(sql);
776       else if (parser.sqlType.equals(I18nSqlParser.CREATE_TABLE)) {
777            String JavaDoc fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
778             File JavaDoc checkFile = new File JavaDoc(fileName);
779
780             if (checkFile.exists())
781                     {
782                       throw new SQLException("Data file '" + fileName + "'already exists !");
783                     }
784
785                     try {
786                         checkFile.createNewFile();
787
788             }
789             catch (Exception JavaDoc e)
790             {
791             throw new SQLException("Error reading data file. Message was: " + e);
792             }
793         }
794         return true;
795
796   }
797
798
799
800     /**
801      *Adds a feature to the Batch attribute of the I18nStatement object
802      *
803      * @param p0 The feature to be added to the Batch attribute
804      * @exception SQLException Description of Exception
805      * @since
806      */

807     public void addBatch(String JavaDoc p0) throws SQLException
808     {
809         throw new SQLException("Not Supported !");
810     }
811
812
813     /**
814      *Description of the Method
815      *
816      * @exception SQLException Description of Exception
817      * @since
818      */

819     public void clearBatch() throws SQLException
820     {
821         throw new SQLException("Not Supported !");
822     }
823
824
825     /**
826      *Description of the Method
827      *
828      * @return Description of the Returned Value
829      * @exception SQLException Description of Exception
830      * @since
831      */

832     public int[] executeBatch() throws SQLException
833     {
834         throw new SQLException("Not Supported !");
835     }
836
837     //---------------------------------------------------------------------
838
// JDBC 3.0
839
//---------------------------------------------------------------------
840

841     public boolean getMoreResults(int current) throws SQLException {
842         throw new UnsupportedOperationException JavaDoc("Statement.getMoreResults(int) unsupported");
843     }
844
845     public ResultSet getGeneratedKeys() throws SQLException {
846         throw new UnsupportedOperationException JavaDoc("Statement.getGeneratedKeys() unsupported");
847     }
848
849     public int executeUpdate(String JavaDoc sql, int autoGeneratedKeys) throws SQLException {
850         throw new UnsupportedOperationException JavaDoc("Statement.executeUpdate(String,int) unsupported");
851     }
852
853     public int executeUpdate(String JavaDoc sql, int[] columnIndexes) throws SQLException {
854         throw new UnsupportedOperationException JavaDoc("Statement.executeUpdate(String,int[]) unsupported");
855     }
856
857     public int executeUpdate(String JavaDoc sql, String JavaDoc[] columnNames) throws SQLException {
858         throw new UnsupportedOperationException JavaDoc("Statement.executeUpdate(String,String[]) unsupported");
859     }
860
861     public boolean execute(String JavaDoc sql, int autoGeneratedKeys) throws SQLException {
862         throw new UnsupportedOperationException JavaDoc("Statement.execute(String,int) unsupported");
863     }
864
865     public boolean execute(String JavaDoc sql, int[] columnIndexes) throws SQLException {
866         throw new UnsupportedOperationException JavaDoc("Statement.execute(String,int[]) unsupported");
867     }
868
869     public boolean execute(String JavaDoc sql, String JavaDoc[] columnNames) throws SQLException {
870         throw new UnsupportedOperationException JavaDoc("Statement.execute(String,String[]) unsupported");
871     }
872
873     public int getResultSetHoldability() throws SQLException {
874         throw new UnsupportedOperationException JavaDoc("Statement.getResultSetHoldability() unsupported");
875     }
876         /**
877          * This method returns string which represents sql statement
878          * @return string
879          */

880     public String JavaDoc getSqlStatement() {
881       return sql;
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 }
892
893
Popular Tags