Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/hsqldb/util/TransferDb.java


1   /* Copyright (c) 2001-2002, The HSQL Development Group
2    * All rights reserved.
3    *
4    * Redistribution and use in source and binary forms, with or without
5    * modification, are permitted provided that the following conditions are met:
6    *
7    * Redistributions of source code must retain the above copyright notice, this
8    * list of conditions and the following disclaimer.
9    *
10   * Redistributions in binary form must reproduce the above copyright notice,
11   * this list of conditions and the following disclaimer in the documentation
12   * and/or other materials provided with the distribution.
13   *
14   * Neither the name of the HSQL Development Group nor the names of its
15   * contributors may be used to endorse or promote products derived from this
16   * software without specific prior written permission.
17   *
18   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21   * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, 
22   * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
23   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
24   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29   */
30  
31  
32  package org.hsqldb.util;
33  
34  import java.sql.*;
35  import java.util.*;
36  import java.io.*;
37  
38  // fredt@users 20020215 - patch 516309 by Nicolas Bazin - enhancements
39  // sqlbob@users 20020401 - patch 1.7.0 - reengineering
40  // nicolas BAZIN 20020430 - add support of Catalog and mckoi db helper
41  
42  /**
43   * Conversions between different databases
44   *
45   * @version 1.7.0
46   */
47  class TransferDb extends DataAccessPoint {
48  
49      Connection          conn;
50      DatabaseMetaData    meta;
51      protected Statement srcStatement = null;
52  
53      TransferDb(Connection c, Traceable t) throws DataAccessPointException {
54  
55          super(t);
56  
57          conn = c;
58  
59          if (c != null) {
60              String productLowerName;
61  
62              try {
63                  meta              = c.getMetaData();
64                  databaseToConvert = c.getCatalog();
65                  productLowerName  = meta.getDatabaseProductName();
66  
67                  if (productLowerName == null) {
68                      productLowerName = "";
69                  } else {
70                      productLowerName = productLowerName.toLowerCase();
71                  }
72  
73                  helper = HelperFactory.getHelper(productLowerName);
74  
75                  helper.set(this, t, meta.getIdentifierQuoteString());
76              } catch (SQLException e) {
77                  throw new DataAccessPointException(e.getMessage());
78              }
79          }
80      }
81  
82      boolean isConnected() {
83          return (conn != null);
84      }
85  
86      boolean getAutoCommit() throws DataAccessPointException {
87  
88          boolean result = false;
89  
90          try {
91              result = conn.getAutoCommit();
92          } catch (SQLException e) {
93              throw new DataAccessPointException(e.getMessage());
94          }
95  
96          return result;
97      }
98  
99      void commit() throws DataAccessPointException {
100 
101         if (srcStatement != null) {
102             try {
103                 srcStatement.close();
104             } catch (SQLException e) {}
105 
106             srcStatement = null;
107         }
108 
109         try {
110             conn.commit();
111         } catch (SQLException e) {
112             throw new DataAccessPointException(e.getMessage());
113         }
114     }
115 
116     void rollback() throws DataAccessPointException {
117 
118         if (srcStatement != null) {
119             try {
120                 srcStatement.close();
121             } catch (SQLException e) {}
122 
123             srcStatement = null;
124         }
125 
126         try {
127             conn.rollback();
128         } catch (SQLException e) {
129             throw new DataAccessPointException(e.getMessage());
130         }
131     }
132 
133     void setAutoCommit(boolean flag) throws DataAccessPointException {
134 
135         try {
136             conn.setAutoCommit(flag);
137         } catch (SQLException e) {
138             throw new DataAccessPointException(e.getMessage());
139         }
140     }
141 
142     boolean execute(String statement) throws DataAccessPointException {
143 
144         boolean   result = false;
145         Statement stmt   = null;
146 
147         try {
148             stmt   = conn.createStatement();
149             result = stmt.execute(statement);
150         } catch (SQLException e) {
151             throw new DataAccessPointException(e.getMessage());
152         } finally {
153             if (stmt != null) {
154                 try {
155                     stmt.close();
156                 } catch (SQLException e) {}
157             }
158         }
159 
160         return result;
161     }
162 
163     TransferResultSet getData(String statement)
164     throws DataAccessPointException {
165 
166         ResultSet rsData = null;
167 
168         try {
169             if (srcStatement != null) {
170                 srcStatement.close();
171             }
172 
173             srcStatement = conn.createStatement();
174             rsData       = srcStatement.executeQuery(statement);
175         } catch (SQLException e) {
176             try {
177                 srcStatement.close();
178             } catch (Exception e1) {}
179 
180             srcStatement = null;
181             rsData       = null;
182 
183             throw new DataAccessPointException(e.getMessage());
184         }
185 
186         return new TransferResultSet(rsData);
187     }
188 
189     void putData(String statement, TransferResultSet r,
190                  int iMaxRows) throws DataAccessPointException {
191 
192         if ((statement == null) || statement.equals("") || (r == null)) {
193             return;
194         }
195 
196         PreparedStatement destPrep = null;
197 
198         try {
199             destPrep = conn.prepareStatement(statement);
200 
201             int i = 0;
202 
203             while (r.next()) {
204                 transferRow(r, destPrep);
205 
206                 if (iMaxRows != 0 && i == iMaxRows) {
207                     break;
208                 }
209 
210                 i++;
211 
212                 if (iMaxRows != 0 || i % 100 == 0) {
213                     tracer.trace("Transfered " + i + " rows");
214                 }
215             }
216         } catch (SQLException e) {
217             throw new DataAccessPointException(e.getMessage());
218         } finally {
219             if (destPrep != null) {
220                 try {
221                     destPrep.close();
222                 } catch (SQLException e) {}
223             }
224         }
225     }
226 
227     /**
228      * Method declaration
229      *
230      *
231      * @param type
232      * @param r
233      * @param p
234      *
235      * @throws SQLException
236      */
237     private void transferRow(TransferResultSet r,
238                              PreparedStatement p)
239                              throws DataAccessPointException, SQLException {
240 
241         String sLast = "";
242 
243         if (p != null) {
244             p.clearParameters();
245         }
246 
247         int len = r.getColumnCount();
248 
249         for (int i = 0; i < len; i++) {
250             int t = r.getColumnType(i + 1);
251 
252             sLast = "column=" + r.getColumnName(i + 1) + " datatype="
253                     + (String) helper.getSupportedTypes().get(new Integer(t));
254 
255             Object o = r.getObject(i + 1);
256 
257             if (o == null) {
258                 if (p != null) {
259                     p.setNull(i + 1, t);
260                 }
261 
262                 sLast += " value=<null>";
263             } else {
264                 o = helper.convertColumnValue(o, i + 1, t);
265 
266                 p.setObject(i + 1, o);
267 
268                 sLast += " value=\'" + o.toString() + "\'";
269             }
270         }
271 
272         if (p != null) {
273             p.execute();
274         }
275 
276         sLast = "";
277     }
278 
279     Vector getSchemas() throws DataAccessPointException {
280 
281         Vector    ret    = new Vector();
282         ResultSet result = null;
283 
284         try {
285             result = meta.getSchemas();
286         } catch (SQLException e) {
287             result = null;
288         }
289 
290         try {
291             if (result != null) {
292                 while (result.next()) {
293                     ret.addElement(result.getString(1));
294                 }
295 
296                 result.close();
297             }
298         } catch (SQLException e) {
299             throw new DataAccessPointException(e.getMessage());
300         }
301 
302         return (ret);
303     }
304 
305     Vector getCatalog() throws DataAccessPointException {
306 
307         Vector    ret    = new Vector();
308         ResultSet result = null;
309 
310         if (databaseToConvert != null && databaseToConvert.length() > 0) {
311             ret.addElement(databaseToConvert);
312 
313             return (ret);
314         }
315 
316         try {
317             result = meta.getCatalogs();
318         } catch (SQLException e) {
319             result = null;
320         }
321 
322         try {
323             if (result != null) {
324                 while (result.next()) {
325                     ret.addElement(result.getString(1));
326                 }
327 
328                 result.close();
329             }
330         } catch (SQLException e) {
331             throw new DataAccessPointException(e.getMessage());
332         }
333 
334         return (ret);
335     }
336 
337     void setCatalog(String sCatalog) throws DataAccessPointException {
338 
339         if (sCatalog != null && sCatalog.length() > 0) {
340             try {
341                 conn.setCatalog(sCatalog);
342             } catch (SQLException e) {
343                 throw new DataAccessPointException(e.getMessage());
344             }
345         }
346     }
347 
348     Vector getTables(String sCatalog,
349                      String sSchemas[]) throws DataAccessPointException {
350 
351         Vector    tTable = new Vector();
352         ResultSet result = null;
353 
354         tracer.trace("Reading source tables");
355 
356         int nbloops = 1;
357 
358         if (sSchemas != null) {
359             nbloops = sSchemas.length;
360         }
361 
362         try {
363 
364 // variations return null or emtpy result sets with informix JDBC driver 2.2
365             for (int SchemaIdx = 0; SchemaIdx < nbloops; SchemaIdx++) {
366                 if (sSchemas != null && sSchemas[SchemaIdx] != null) {
367                     result = meta.getTables(sCatalog, sSchemas[SchemaIdx],
368                                             null, null);
369                 } else {
370                     try {
371                         result = meta.getTables(sCatalog, "", null, null);
372                     } catch (SQLException e) {
373                         result = meta.getTables(sCatalog, null, null, null);
374                     }
375                 }
376 
377                 while (result.next()) {
378                     String name   = result.getString(3);
379                     String type   = result.getString(4);
380                     String schema = "";
381 
382                     if (sSchemas != null && sSchemas[SchemaIdx] != null) {
383                         schema = sSchemas[SchemaIdx];
384                     }
385 
386                     /*
387                     ** we ignore the following table types:
388                     **    "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY"
389                     **    "ALIAS", "SYNONYM"
390                     */
391                     if ((type.compareTo("TABLE") == 0)
392                             || (type.compareTo("VIEW") == 0)) {
393                         TransferTable t = new TransferTable(this, name,
394                                                             schema, type,
395                                                             tracer);
396 
397                         tTable.addElement(t);
398                     } else {
399                         tracer.trace("Found table of type :" + type
400                                      + " - this type is ignored");
401                     }
402                 }
403             }
404         } catch (SQLException e) {
405             throw new DataAccessPointException(e.getMessage());
406         } finally {
407             if (result != null) {
408                 try {
409                     result.close();
410                 } catch (SQLException e) {}
411             }
412         }
413 
414         return (tTable);
415     }
416 
417     void getTableStructure(TransferTable TTable,
418                            DataAccessPoint Dest)
419                            throws DataAccessPointException {
420 
421         String create = "CREATE " + TTable.Stmts.sType + " "
422                         + Dest.helper.formatName(TTable.Stmts.sDestTable);
423         String    insert         = "";
424         ResultSet ImportedKeys   = null;
425         boolean   importedkeys   = false;
426         String    alterCreate    = new String("");
427         String    alterDrop      = new String("");
428         String    ConstraintName = new String("");
429         String    RefTableName   = new String("");
430         String    foreignKeyName = new String("");
431         String    columnName     = new String("");
432 
433         TTable.Stmts.sDestDrop =
434             "DROP " + TTable.Stmts.sType + " "
435             + Dest.helper.formatName(TTable.Stmts.sDestTable) + ";";
436 
437         if (TTable.Stmts.sType.compareTo("TABLE") == 0) {
438             TTable.Stmts.sDestDelete =
439                 "DELETE FROM "
440                 + Dest.helper.formatName(TTable.Stmts.sDestTable) + ";";
441             create += "(";
442         } else if (TTable.Stmts.sType.compareTo("VIEW") == 0) {
443             TTable.Stmts.bDelete     = false;
444             TTable.Stmts.sDestDelete = "";
445             create                   += " AS SELECT ";
446         }
447 
448         if (TTable.Stmts.sType.compareTo("TABLE") == 0) {
449             insert = "INSERT INTO "
450                      + Dest.helper.formatName(TTable.Stmts.sDestTable)
451                      + " VALUES(";
452         } else if (TTable.Stmts.sType.compareTo("VIEW") == 0) {
453             TTable.Stmts.bInsert = false;
454             insert               = "";
455         }
456 
457         if (TTable.Stmts.sType.compareTo("VIEW") == 0) {
458             /*
459             ** Don't know how to retrieve the underlying select so we leave here.
460             ** The user will have to edit the rest of the create statement.
461             */
462             TTable.Stmts.bTransfer    = false;
463             TTable.Stmts.bCreate      = true;
464             TTable.Stmts.bDelete      = false;
465             TTable.Stmts.bDrop        = true;
466             TTable.Stmts.bCreateIndex = false;
467             TTable.Stmts.bDropIndex   = false;
468             TTable.Stmts.bInsert      = false;
469             TTable.Stmts.bAlter       = false;
470 
471             return;
472         }
473 
474         ImportedKeys = null;
475 
476         try {
477             ImportedKeys =
478                 meta.getImportedKeys(TTable.Stmts.sDatabaseToConvert,
479                                      TTable.Stmts.sSchema,
480                                      TTable.Stmts.sSourceTable);
481         } catch (SQLException e) {
482             ImportedKeys = null;
483         }
484 
485         try {
486             if (ImportedKeys != null) {
487                 while (ImportedKeys.next()) {
488                     importedkeys = true;
489 
490                     if (!ImportedKeys.getString(12).equals(ConstraintName)) {
491                         if (!ConstraintName.equals("")) {
492                             alterCreate +=
493                                 Dest.helper
494                                     .formatIdentifier(columnName
495                                         .substring(0, columnName
496                                             .length() - 1)) + ") REFERENCES "
497                                                             + Dest.helper
498                                                                 .formatName(RefTableName);
499 
500                             if (foreignKeyName.length() > 0) {
501                                 alterCreate +=
502                                     " ("
503                                     + Dest.helper.formatIdentifier(
504                                         foreignKeyName.substring(
505                                             0, foreignKeyName.length()
506                                             - 1)) + ")";
507                             }
508 
509                             alterCreate += ";";
510                             alterDrop =
511                                 alterDrop.substring(0, alterDrop.length() - 1)
512                                 + ";";
513                             foreignKeyName = "";
514                             columnName     = "";
515                         }
516 
517                         RefTableName   = ImportedKeys.getString(3);
518                         ConstraintName = ImportedKeys.getString(12);
519                         alterCreate +=
520                             "ALTER TABLE "
521                             + Dest.helper.formatName(TTable.Stmts.sDestTable)
522                             + " ADD CONSTRAINT ";
523 
524                         if ((TTable.Stmts.bFKForced)
525                                 && (!ConstraintName.startsWith("FK_"))) {
526                             alterCreate +=
527                                 Dest.helper.formatIdentifier(
528                                     "FK_" + ConstraintName) + " ";
529                         } else {
530                             alterCreate +=
531                                 Dest.helper.formatIdentifier(ConstraintName)
532                                 + " ";
533                         }
534 
535                         alterCreate += "FOREIGN KEY (";
536                         alterDrop +=
537                             "ALTER TABLE "
538                             + Dest.helper.formatName(TTable.Stmts.sDestTable)
539                             + " DROP CONSTRAINT ";
540 
541                         if ((TTable.Stmts.bFKForced)
542                                 && (!ConstraintName.startsWith("FK_"))) {
543                             alterDrop +=
544                                 Dest.helper.formatIdentifier(
545                                     "FK_" + ConstraintName) + " ";
546                         } else {
547                             alterDrop +=
548                                 Dest.helper.formatIdentifier(ConstraintName)
549                                 + " ";
550                         }
551                     }
552 
553                     columnName     += ImportedKeys.getString(8) + ",";
554                     foreignKeyName += ImportedKeys.getString(4) + ",";
555                 }
556 
557                 ImportedKeys.close();
558             }
559 
560             if (importedkeys) {
561                 alterCreate +=
562                     columnName.substring(0, columnName.length() - 1)
563                     + ") REFERENCES " + Dest.helper.formatName(RefTableName);
564 
565                 if (foreignKeyName.length() > 0) {
566                     alterCreate +=
567                         " ("
568                         + Dest.helper.formatIdentifier(
569                             foreignKeyName.substring(
570                                 0, foreignKeyName.length() - 1)) + ")";
571                 }
572 
573                 alterCreate += ";";
574                 alterDrop = alterDrop.substring(0, alterDrop.length() - 1)
575                             + ";";
576                 TTable.Stmts.sDestDrop = alterDrop + TTable.Stmts.sDestDrop;
577             }
578         } catch (SQLException e) {
579             throw new DataAccessPointException(e.getMessage());
580         }
581 
582         boolean primarykeys           = false;
583         String  PrimaryKeysConstraint = new String();
584 
585         PrimaryKeysConstraint = "";
586 
587         ResultSet PrimaryKeys = null;
588 
589         try {
590             PrimaryKeys = meta.getPrimaryKeys(TTable.Stmts.sDatabaseToConvert,
591                                               TTable.Stmts.sSchema,
592                                               TTable.Stmts.sSourceTable);
593         } catch (SQLException e) {
594             PrimaryKeys = null;
595         }
596 
597         try {
598             if (PrimaryKeys != null) {
599                 while (PrimaryKeys.next()) {
600                     if (primarykeys) {
601                         PrimaryKeysConstraint += ", ";
602                     } else {
603                         if (PrimaryKeys.getString(6) != null) {
604                             PrimaryKeysConstraint =
605                                 " CONSTRAINT "
606                                 + Dest.helper.formatIdentifier(
607                                     PrimaryKeys.getString(6));
608                         }
609 
610                         PrimaryKeysConstraint += " PRIMARY KEY (";
611                     }
612 
613                     PrimaryKeysConstraint += Dest.helper.formatIdentifier(
614                         PrimaryKeys.getString(4));
615                     primarykeys = true;
616                 }
617 
618                 PrimaryKeys.close();
619 
620                 if (primarykeys) {
621                     PrimaryKeysConstraint += ") ";
622                 }
623             }
624         } catch (SQLException e) {
625             throw new DataAccessPointException(e.getMessage());
626         }
627 
628         boolean   indices     = false;
629         ResultSet Indices     = null;
630         String    IndiceName  = new String("");
631         String    CreateIndex = new String("");
632         String    DropIndex   = new String("");
633 
634         try {
635             Indices = meta.getIndexInfo(TTable.Stmts.sDatabaseToConvert,
636                                         TTable.Stmts.sSchema,
637                                         TTable.Stmts.sSourceTable, false,
638                                         false);
639         } catch (SQLException e) {
640             Indices = null;
641         }
642 
643         try {
644             if (Indices != null) {
645                 while (Indices.next()) {
646                     String tmpIndexName = null;
647 
648                     try {
649                         tmpIndexName = Indices.getString(6);
650                     } catch (SQLException e) {
651                         tmpIndexName = null;
652                     }
653 
654                     if (tmpIndexName == null) {
655                         continue;
656                     }
657 
658                     if (!tmpIndexName.equals(IndiceName)) {
659                         if (!IndiceName.equals("")) {
660                             CreateIndex =
661                                 CreateIndex.substring(
662                                     0, CreateIndex.length() - 1) + ");";
663                             DropIndex += ";";
664                         }
665 
666                         IndiceName = tmpIndexName;
667                         DropIndex  += "DROP INDEX ";
668 
669                         if ((TTable.Stmts.bIdxForced)
670                                 && (!IndiceName.startsWith("Idx_"))) {
671                             DropIndex += Dest.helper.formatIdentifier("Idx_"
672                                     + IndiceName);
673                         } else {
674                             DropIndex +=
675                                 Dest.helper.formatIdentifier(IndiceName);
676                         }
677 
678                         CreateIndex += "CREATE ";
679 
680                         if (!Indices.getBoolean(4)) {
681                             CreateIndex += "UNIQUE ";
682                         }
683 
684                         CreateIndex += "INDEX ";
685 
686                         if ((TTable.Stmts.bIdxForced)
687                                 && (!IndiceName.startsWith("Idx_"))) {
688                             CreateIndex += Dest.helper.formatIdentifier("Idx_"
689                                     + IndiceName);
690                         } else {
691                             CreateIndex +=
692                                 Dest.helper.formatIdentifier(IndiceName);
693                         }
694 
695                         CreateIndex +=
696                             " ON "
697                             + Dest.helper.formatName(TTable.Stmts.sDestTable)
698                             + "(";
699                     }
700 
701                     CreateIndex +=
702                         Dest.helper.formatIdentifier(Indices.getString(9))
703                         + ",";
704                     indices = true;
705                 }
706 
707                 Indices.close();
708 
709                 if (indices) {
710                     CreateIndex =
711                         CreateIndex.substring(0, CreateIndex.length() - 1)
712                         + ");";
713                     DropIndex += ";";
714                 }
715             }
716         } catch (SQLException e) {
717             throw new DataAccessPointException(e.getMessage());
718         }
719 
720         Vector v = new Vector();
721 
722         tracer.trace("Reading source columns for table "
723                      + TTable.Stmts.sSourceTable);
724 
725         ResultSet         col            = null;
726         int               colnum         = 1;
727         Statement         stmt           = null;
728         ResultSet         select_rs      = null;
729         ResultSetMetaData select_rsmdata = null;
730 
731         try {
732             stmt           = conn.createStatement();
733             select_rs      = stmt.executeQuery(TTable.Stmts.sSourceSelect);
734             select_rsmdata = select_rs.getMetaData();
735             col = meta.getColumns(TTable.Stmts.sDatabaseToConvert,
736                                   TTable.Stmts.sSchema,
737                                   TTable.Stmts.sSourceTable, null);
738         } catch (SQLException eSchema) {
739 
740             // fredt - second try with null schema
741             if (TTable.Stmts.sSchema.equals("")) {
742                 try {
743                     col = meta.getColumns(TTable.Stmts.sDatabaseToConvert,
744                                           null, TTable.Stmts.sSourceTable,
745                                           null);
746                 } catch (SQLException eSchema1) {}
747             }
748         }
749 
750         try {
751             while (col.next()) {
752                 String name = Dest.helper.formatIdentifier(col.getString(4));
753                 int    type        = col.getShort(5);
754                 String source      = col.getString(6);
755                 int    column_size = col.getShort(7);
756                 String DefaultVal  = col.getString(13);
757                 boolean rsmdata_NoNulls =
758                     (select_rsmdata.isNullable(colnum)
759                      == java.sql.DatabaseMetaData.columnNoNulls);
760                 boolean rsmdata_isAutoIncrement = false;
761 
762                 try {
763                     rsmdata_isAutoIncrement =
764                         select_rsmdata.isAutoIncrement(colnum);
765                 } catch (SQLException e) {
766                     rsmdata_isAutoIncrement = false;
767                 }
768 
769                 int rsmdata_precision = select_rsmdata.getPrecision(colnum);
770                 int rsmdata_scale     = select_rsmdata.getScale(colnum);
771 
772                 type = helper.convertFromType(type);
773                 type = Dest.helper.convertToType(type);
774 
775                 Integer inttype  = new Integer(type);
776                 String  datatype = (String) TTable.hTypes.get(inttype);
777 
778                 if (datatype == null) {
779                     datatype = source;
780 
781                     tracer.trace("No mapping for type: " + name + " type: "
782                                  + type + " source: " + source);
783                 }
784 
785                 if (type == Types.NUMERIC) {
786                     datatype += "(" + Integer.toString(rsmdata_precision);
787 
788                     if (rsmdata_scale > 0) {
789                         datatype += "," + Integer.toString(rsmdata_scale);
790                     }
791 
792                     datatype += ")";
793                 } else if (type == Types.CHAR) {
794                     datatype += "(" + Integer.toString(column_size) + ")";
795                 } else if (rsmdata_isAutoIncrement) {
796                     datatype = "SERIAL";
797                 }
798 
799                 if (DefaultVal != null) {
800                     if ((type == Types.CHAR) || (type == Types.LONGVARCHAR)) {
801                         DefaultVal = "\'" + DefaultVal + "\'";
802                     }
803 
804                     datatype += " Default " + DefaultVal;
805                 }
806 
807                 if (rsmdata_NoNulls) {
808                     datatype += " NOT NULL ";
809                 }
810 
811                 v.addElement(inttype);
812 
813                 datatype = helper.fixupColumnDefRead(TTable, select_rsmdata,
814                                                      datatype, col, colnum);
815                 datatype = Dest.helper.fixupColumnDefWrite(TTable,
816                         select_rsmdata, datatype, col, colnum);
817                 create += name + " " + datatype + ",";
818                 insert += "?,";
819 
820                 colnum++;
821             }
822 
823             select_rs.close();
824             stmt.close();
825             col.close();
826         } catch (SQLException e) {
827             throw new DataAccessPointException(e.getMessage());
828         }
829 
830         if (primarykeys) {
831             create += PrimaryKeysConstraint + ",";
832         }
833 
834         TTable.Stmts.sDestCreate = create.substring(0, create.length() - 1)
835                                    + ")";
836         TTable.Stmts.sDestInsert = insert.substring(0, insert.length() - 1)
837                                    + ")";
838 
839         if (importedkeys) {
840             TTable.Stmts.bAlter     = true;
841             TTable.Stmts.sDestAlter = alterCreate;
842         } else {
843             TTable.Stmts.bAlter = false;
844         }
845 
846         if (indices) {
847             TTable.Stmts.bCreateIndex     = true;
848             TTable.Stmts.bDropIndex       = true;
849             TTable.Stmts.sDestCreateIndex = CreateIndex;
850             TTable.Stmts.sDestDropIndex   = DropIndex;
851         } else {
852             TTable.Stmts.bCreateIndex = false;
853             TTable.Stmts.bDropIndex   = false;
854         }
855 
856         //iColumnType = new int[v.size()];
857         //for (int j = 0; j < v.size(); j++) {
858         //    iColumnType[j] = ((Integer) v.elementAt(j)).intValue();
859         //}
860     }
861 
862     void close() throws DataAccessPointException {
863 
864         if (srcStatement != null) {
865             try {
866                 srcStatement.close();
867             } catch (SQLException e) {}
868 
869             srcStatement = null;
870         }
871 
872         if (conn != null) {
873             try {
874                 conn.close();
875             } catch (SQLException e) {}
876 
877             conn = null;
878         }
879     }
880 }