Diff for /FM2SQL/Attic/Convert.java between versions 1.83 and 1.86

version 1.83, 2004/10/26 08:37:10 version 1.86, 2004/11/18 11:17:43
Line 113  class Convert Line 113  class Convert
             System.exit(-1);              System.exit(-1);
         }          }
         try          try
         {   File temp=File.createTempFile("fm2sql",".txt");          {
               File temp = File.createTempFile("fm2sql", ".txt");
             file = new FileOutputStream(temp);              file = new FileOutputStream(temp);
         }          }
         catch (FileNotFoundException e1)          catch (FileNotFoundException e1)
Line 139  class Convert Line 140  class Convert
         bean = source;          bean = source;
         beanDest = destination;          beanDest = destination;
         convert(null, null, names, layouts, selects, creates, ids, mode, delimiter);          convert(null, null, names, layouts, selects, creates, ids, mode, delimiter);
         if (true)  
             return;  
         StringBuffer command = null;  
         try  
         {  
             bean.setConnection(source.url);  
             if (names == null)  
                 names = bean.getTableNames();  
             //Collections.sort(names);  
             int tbIndex = 1;  
   
             for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)  
             {  
                 Vector[] result = null;  
                 try  
                 {  
                     String query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();  
                     String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();  
                     query = (selects != null) ? selects.get(tbIndex).toString() : query;  
                     //if vectors[1].get(i) != null)  
                     if (!layout.equals(""))  
                     {  
                         System.out.println("before " + query + " table" + names.get(tbIndex));  
                         layout = " layout " + bean.getQC() + layout + bean.getQC();  
                         String name = names.get(tbIndex).toString();  
                         StringBuffer queryLayout = new StringBuffer(query);  
                         queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);  
                         query = queryLayout.toString();  
                         System.out.println("added layout " + query);  
   
                     }  
                     System.out.println(" performing query " + query);  
                     //result = bean.getQueryData(query, null, 0);  
                     bean.getConnection();  
                     bean.makeQuery(query, 0);  
                 }  
                 catch (Exception e)  
                 {  
                     System.out.println(e.getMessage());  
                     e.printStackTrace();  
                     continue;  
                 }  
                 //beanDest.setConnection("jdbc:postgresql://erebos/test3");  
                 beanDest.setConnection(destination.url);  
   
                 Statement stm = beanDest.getConnection().createStatement();  
   
                 Vector tables = beanDest.getTableNames();  
                 //   Collections.sort(tables);  
                 System.out.println("converting table " + names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());  
                 tables = beanDest.getTableNames();  
                 // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));  
                 stm = beanDest.getConnection().createStatement();  
                 // System.exit(0);  
                 if (mode == Convert.DataBase.CONVERT_MODE)  
                 {  
                     if (tables.indexOf(names.get(tbIndex)) >= 0)  
                     {  
                         stm.executeUpdate("drop table " + beanDest.getQC() + names.get(tbIndex) + beanDest.getQC());  
                         tables.remove((String) names.get(tbIndex));  
                         System.out.println("dropped table " + names.get(tbIndex));  
                     }  
                     else if (tables.indexOf(convertText(names.get(tbIndex).toString())) >= 0)  
                     {  
                         stm.executeUpdate("drop table " + beanDest.getQC() + convertText((String) names.get(tbIndex)) + beanDest.getQC());  
                         tables.remove(convertText((String) names.get(tbIndex)));  
                         System.out.println("dropped table " + names.get(tbIndex));  
                     }  
   
                     if (tables.indexOf(names.get(tbIndex)) < 0 && tables.indexOf(convertText(names.get(tbIndex).toString())) < 0)  
                     {  
                         if (creates.get(tbIndex).equals("") || creates.get(tbIndex).toString().toLowerCase().indexOf("create") < 0)  
                         {  
                             System.out.println("Warning empty or invalid create statement - creating one for you\n");  
   
                             command = new StringBuffer(50);  
                             command.append("CREATE TABLE ");  
                             command.append(beanDest.getQC());  
                             command.append(convertText((String) names.get(tbIndex)));  
                             command.append(beanDest.getQC());  
                             command.append("(");  
                             String type = null;  
                             Vector columnNames = bean.getColumnNames();  
                             for (int i = 0; i < columnNames.size() - 1; ++i)  
                             {  
                                 type = bean.metaData.getColumnTypeName(i + 1);  
                                 //   System.out.println(i+" "+result[1].get(i)+"  
                                 // "+type);  
                                 type = (type.equals("NUMBER")) ? "INT4" : type;  
                                 type = (type.equals("CONTAINER")) ? "TEXT" : type;  
   
                                 command.append(beanDest.getQC() + convertText((String) columnNames.get(i)) + beanDest.getQC() + " " + type + ", ");  
                             }  
                             type = bean.metaData.getColumnTypeName(columnNames.size());  
                             type = (type.equals("NUMBER")) ? "INT4" : type;  
                             type = (type.equals("CONTAINER")) ? "TEXT" : type;  
                             command.append(beanDest.getQC() + convertText((String) columnNames.get(columnNames.size() - 1)) + beanDest.getQC() + " " + type);  
                             command.append(" )");  
                         }  
                         else  
                             command = new StringBuffer().append(creates.get(tbIndex).toString());  
   
                         System.out.println(command);  
                         //  System.exit(0);  
                         //command.append(DBBean.getQC());  
                         stm.executeUpdate(command.toString());  
   
                     }  
                 }  
                 Vector row = null;  
                 command = new StringBuffer();  
   
                 command.append("INSERT  INTO ");  
                 command.append(beanDest.getQC());  
                 command.append(convertText((String) names.get(tbIndex)));  
                 command.append(beanDest.getQC());  
                 command.append(" values ( ");  
   
                 for (int i = 0; i < bean.getColumnNames().size() - 1; ++i)  
                     command.append("?,");  
                 command.append("?)");  
                 PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());  
                 System.out.println(command);  
                 while ((row = bean.getNextRow()) != null)  
                 {  
                     //print rows  
                     Object obj = null;  
                     for (int k = 0; k < row.size(); ++k)  
                     {  
                         obj = row.get(k);  
                         if (obj instanceof ArrayList)  
                             obj = formatFileMakerArray((List) obj, "\n");  
                         String str = (obj == null) ? "NULL" : obj.toString();  
                         if (!str.equals("NULL"))  
                             pstm.setString(k + 1, str);  
                         else  
                             pstm.setNull(k + 1, Types.NULL);  
                     }  
                     pstm.execute();  
   
                 } // to for loop  
   
             }  
         }  
         catch (Exception e)  
         {  
             System.out.println("Error while connecting to database " + e);  
             //dialog.setVisible(false);  
             //dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
             //FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
             java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();  
             java.io.PrintStream stream = new java.io.PrintStream(b);  
             stream.print(command + "\n\n");  
             e.printStackTrace(stream);  
             System.err.println(b);  
             //FM2SQL.showErrorDialog(b.toString(), "Error occured !");  
   
         }  
         //  dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
         //FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
   
         //  dialog.setVisible(false);  
     }      }
   
     public static String formatFileMakerArray(List list, String delimiter)      public static String formatFileMakerArray(List list, String delimiter)
Line 334  class Convert Line 173  class Convert
         FM2SQL.ProgressDialog dialog = null;          FM2SQL.ProgressDialog dialog = null;
         if (isGUI)          if (isGUI)
         {          {
             dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);              dialog = initDialog();
             dialog.setTitle("Conversion running ...");  
             dialog.title.setText("Getting table data ...");  
             dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);  
             dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  
             FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  
             dialog.thread = Thread.currentThread();  
         }          }
         // setting user and passwd          // setting user and passwd
         bean.setUserAndPasswd(user, passwd);          bean.setUserAndPasswd(user, passwd);
         // setting user and passwd          // setting user and passwd
         beanDest.setUserAndPasswd(userDest, passwdDest);          beanDest.setUserAndPasswd(userDest, passwdDest);
         if (dialog != null)  
             dialog.setSize(400, 250);  
         StringBuffer command = null;          StringBuffer command = null;
         String query = null;          String query = null;
         try          try
         {          {
             //bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050");  
             //bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo");  
                System.out.println("before getConnection");  
                                   
             bean.setConnection(source);              bean.setConnection(source);
                System.out.println("after getConnection");  
                                   
             if (names == null)              if (names == null)
                 names = bean.getTableNames();                  names = bean.getTableNames();
Line 377  class Convert Line 205  class Convert
                     //if vectors[1].get(i) != null)                      //if vectors[1].get(i) != null)
                     if (layout != "")                      if (layout != "")
                     {                      {
                         layout = " layout " + bean.getQC() + layout + bean.getQC();                          query = addLayoutToQuery(names, query, tbIndex, layout);
                         String name = names.get(tbIndex).toString();  
                         StringBuffer queryLayout = new StringBuffer(query);  
                         queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);  
                         query = queryLayout.toString();  
                         System.out.println("added layout  " + query);  
   
                     }                      }
                     if (dialog != null)                      if (dialog != null)
                     {                      {
                         dialog.title.setText("Getting table data ...");                          prepareDialogforUse(names, dialog, tbIndex);
                         dialog.table.setText(names.get(tbIndex).toString());  
                         dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());  
                         dialog.show();  
                     }                      }
                     bean.getConnection();                      bean.getConnection();
                     bean.makeQuery(query, 0);                      bean.makeQuery(query, 0);
Line 398  class Convert Line 218  class Convert
                 }                  }
                 catch (Exception e)                  catch (Exception e)
                 {                  {
                       System.out.println("Warning exception occured \n " + e);
   
                     continue;                      continue;
                 }                  }
                 // determine destTableName from createStatement or from source                  // determine destTableName from createStatement or from source
Line 414  class Convert Line 236  class Convert
                 else                  else
                     destTableName = convertText(names.get(tbIndex).toString());                      destTableName = convertText(names.get(tbIndex).toString());
   
                 //beanDest.setConnection("jdbc:postgresql://erebos/test3");  
                 beanDest.setConnection(destination);                  beanDest.setConnection(destination);
   
                 Statement stm = beanDest.getConnection().createStatement();                  Statement stm = beanDest.getConnection().createStatement();
   
                 Vector tables = beanDest.getTableNames();                  Vector tables = beanDest.getTableNames();
                 // Collections.sort(tables);  
                 System.out.println(names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());                  System.out.println(names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
                 tables = beanDest.getTableNames();                  tables = beanDest.getTableNames();
                 // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));  
                 stm = beanDest.getConnection().createStatement();                  stm = beanDest.getConnection().createStatement();
                 // System.exit(0);  
   
                 if (dialog != null)                  if (dialog != null)
                     dialog.title.setText("Updating table data ...");                      dialog.title.setText("Updating table data ...");
                   else System.out.println("Updating table data ...");                  else
                       System.out.println("Updating table data ...");
                 int j = -1;                  int j = -1;
   
                 Vector row = null;                  Vector row = null;
Line 456  class Convert Line 276  class Convert
                     j++;                      j++;
                     //print rows                      //print rows
                     Object obj = null;                      Object obj = null;
                     /*  
                      * for(int k=0;k <row.size()-1;++k) { obj = row.get(k);  
                      * //System.out.println("row "+obj+" "+k); if(obj!=null&&!(obj  
                      * instanceof ArrayList))  
                      * command.append("'"+convertUml(obj.toString())+"',"); else  
                      * if(obj!=null&& obj instanceof ArrayList)  
                      * command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"',");  
                      * else command.append("NULL,"); } obj = row.get(row.size() - 1); if  
                      * (obj != null && !(obj instanceof ArrayList))  
                      * command.append("'"+convertUml(obj.toString())+"')"); else  
                      * if(obj!=null&& obj instanceof ArrayList)  
                      * command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"')");  
                      * //command.append(obj.toString()+")"); else command.append("NULL)");  
                      */  
                     //command.append("'"+row.get(row.size()-1)+"')");  
                     //command.append(" )");  
                     //  for(int k=0;k<row.size();++k)  
                     // System.out.println();  
                     //   System.out.println(command+" "+j+" "+row.size()+" "+  
                     // ((Vector)result2[0].get(j)).size());  
                     // System.out.println(command);  
                     for (int k = 0; k < row.size(); ++k)                      for (int k = 0; k < row.size(); ++k)
                     {                      {
                         obj = row.get(k);                          obj = row.get(k);
Line 489  class Convert Line 288  class Convert
                             pstm.setNull(k + 1, Types.NULL);                              pstm.setNull(k + 1, Types.NULL);
                     }                      }
                     pstm.setString(row.size() + 1, row.get(idIndex).toString());                      pstm.setString(row.size() + 1, row.get(idIndex).toString());
                     //System.out.println(pstm.toString());  
                     // System.exit(0);  
                     pstm.execute();                      pstm.execute();
                     //stm.executeUpdate(command.toString());  
                     if (dialog != null)                      if (dialog != null)
                         dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));                          dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
                     // System.out.println(  
                     // (int)(((double)(j+1)/(double)result[0].size())*100.0)+"  
                     // "+result[0].size()+" "+j);  
                     command = null;                      command = null;
                 } // to for loop                  } // to for loop
   
Line 506  class Convert Line 299  class Convert
         catch (Exception e)          catch (Exception e)
         {          {
             System.out.println("Error while connecting to database " + e);              System.out.println("Error while connecting to database " + e);
             if (dialog != null)              if (isGUI)
             {              {
                 dialog.setVisible(false);                  showExceptionDialog(dialog, command, e);
                 dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
                 FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
             }              }
             java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();              else
             java.io.PrintStream stream = new java.io.PrintStream(b);              {
             stream.print(command + "\n\n");                  e.printStackTrace();
             e.printStackTrace(stream);  
             if(dialog!=null)  
             FM2SQL.showErrorDialog(b.toString(), "Error occured !");  
   
         }          }
         if (dialog != null)          } finally
           {
               if (isGUI)
               {
                   resetGUI(dialog);
               }
           }
       }
   
       /**
        * @param dialog
        */
       private static void resetGUI(FM2SQL.ProgressDialog dialog)
         {          {
             dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));              dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
             FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));              FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
           dialog.setVisible(false);
       }
   
       /**
        * @param dialog
        * @param command
        * @param e
        */
       private static void showExceptionDialog(FM2SQL.ProgressDialog dialog, StringBuffer command, Exception e)
       {
             dialog.setVisible(false);              dialog.setVisible(false);
           dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
           FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
           java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
           java.io.PrintStream stream = new java.io.PrintStream(b);
           stream.print(command + "\n\n");
           e.printStackTrace(stream);
           FM2SQL.showErrorDialog(b.toString(), "Error occured !");
         }          }
   
       /**
        * @return
        */
       private static FM2SQL.ProgressDialog initDialog()
       {
           FM2SQL.ProgressDialog dialog;
           dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
           dialog.setTitle("Conversion running ...");
           dialog.title.setText("Getting table data ...");
           dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);
           dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
           FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
           dialog.thread = Thread.currentThread();
           dialog.setSize(420, 250);
           return dialog;
     }      }
   
     /**      /**
Line 553  class Convert Line 384  class Convert
   
         if (isGUI)          if (isGUI)
         {          {
             dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);              dialog = initDialog();
             dialog.setTitle("Conversion running ...");  
             dialog.title.setText("Getting table data ...");  
             dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);  
             dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  
             FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  
             dialog.thread = Thread.currentThread();  
             dialog.setSize(400, 250);  
         }          }
           
                System.out.println("connection established "+source+" "+bean.url);                 System.out.println("connection established "+source+" "+bean.url);
Line 590  class Convert Line 414  class Convert
                 bean.setConnection(bean.url);                  bean.setConnection(bean.url);
             if (names == null)              if (names == null)
                 names = bean.getTableNames();                  names = bean.getTableNames();
             // Collections.sort(names);  
             int tbIndex = 1;              int tbIndex = 1;
   
             // System.out.println("Start at  
             // "+names.indexOf("archimedes_facsimiles"));  
             for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)              for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
             {              {
                 Vector[] result = null;                  Vector[] result = null;
                 try                  try
                 {                  {
                     query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();  
                     String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();                      String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                     query = (selects != null) ? selects.get(tbIndex).toString() : query;                      query = (selects != null) ? selects.get(tbIndex).toString() : "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
                     //if vectors[1].get(i) != null)  
                     if (layout != "")                      if (layout != "")
                     {                      {
                         layout = " layout " + bean.getQC() + layout + bean.getQC();                          query = addLayoutToQuery(names, query, tbIndex, layout);
                         String name = names.get(tbIndex).toString();  
                         StringBuffer queryLayout = new StringBuffer(query);  
                         queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);  
                         query = queryLayout.toString();  
                         System.out.println("added layout  " + query);  
   
                     }                      }
                     //  if ( layout!= "")  
                     //   query += " layout " + bean.getQC() + layout +  
                     // bean.getQC();  
                     if (dialog != null)                      if (dialog != null)
                     {                      {
                         dialog.title.setText("Reading table data ...");                          prepareDialogforUse(names, dialog, tbIndex);
                         dialog.table.setText(names.get(tbIndex).toString());  
                         dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());  
                         dialog.show();  
                     }                      }
                     //result = bean.getQueryData(query, dialog, 0);  
                     bean.getConnection();                      bean.getConnection();
                     bean.makeQuery(query, 50);                      bean.makeQuery(query, 50);
                     idField = ids.get(tbIndex).toString();                      idField = ids.get(tbIndex).toString();
Line 632  class Convert Line 440  class Convert
                 }                  }
                 catch (Exception e)                  catch (Exception e)
                 {                  {
                     System.out.println(e);                      System.out.println("Warning exception occured \n " + e);
   
                     continue;                      continue;
                 }                  }
                 if (destination != null)                  if (destination != null)
Line 664  class Convert Line 473  class Convert
                         System.out.println("dropped table" + destTableName);                          System.out.println("dropped table" + destTableName);
   
                     }                      }
                     /*                      if ((tables.indexOf(destTableName) < 0))
                      * if(destTableName.equals("")) if (tables.indexOf(names.get(tbIndex)) >=  
                      * 0) { stm.executeUpdate("drop table " + beanDest.getQC() +  
                      * names.get(tbIndex) + beanDest.getQC()); tables.remove((String)  
                      * names.get(tbIndex)); System.out.println("dropped table" +  
                      * names.get(tbIndex)); } else if  
                      * (tables.indexOf(convertText(names.get(tbIndex).toString())) >= 0) {  
                      * stm.executeUpdate("drop table " + beanDest.getQC() +  
                      * convertText((String) names.get(tbIndex)) + beanDest.getQC());  
                      * tables.remove(convertText((String) names.get(tbIndex)));  
                      * System.out.println("dropped table" + names.get(tbIndex)); }  
                      */  
                     if ((tables.indexOf(destTableName) < 0)) //&&  
                     // tables.indexOf(names.get(tbIndex))  
                     // < 0 &&  
                     // tables.indexOf(convertText(names.get(tbIndex).toString()))  
                     // < 0 )  
                     {                      {
   
                         if (creates.get(tbIndex).equals("") || creates.get(tbIndex).toString().toLowerCase().indexOf("create") < 0)                          if (creates.get(tbIndex).equals("") || creates.get(tbIndex).toString().toLowerCase().indexOf("create") < 0)
Line 711  class Convert Line 504  class Convert
                             command.append(beanDest.getQC() + convertText((String) columnNames.get(columnNames.size() - 1)) + beanDest.getQC() + " " + type);                              command.append(beanDest.getQC() + convertText((String) columnNames.get(columnNames.size() - 1)) + beanDest.getQC() + " " + type);
                             command.append(" )");                              command.append(" )");
   
                             // System.out.println(command);  
                             //  System.exit(0);  
                             //command.append(DBBean.getQC());  
                         }                          }
                         else                          else
                             command = new StringBuffer().append(creates.get(tbIndex).toString().toLowerCase());                              command = new StringBuffer().append(creates.get(tbIndex).toString().toLowerCase());
Line 731  class Convert Line 521  class Convert
   
                 command.append("INSERT  INTO ");                  command.append("INSERT  INTO ");
                 command.append(beanDest.getQC());                  command.append(beanDest.getQC());
                 command.append(destTableName); //convertText((String)                  command.append(destTableName);
                 // names.get(tbIndex)));  
                 command.append(beanDest.getQC());                  command.append(beanDest.getQC());
                 command.append(" (");                  command.append(" (");
                 for (int i = 0; i < fieldNames.length; i++)                  for (int i = 0; i < fieldNames.length; i++)
Line 840  class Convert Line 629  class Convert
                     System.out.println("Time for old convert elapsed " + (endTime - startTime));                      System.out.println("Time for old convert elapsed " + (endTime - startTime));
   
                 }                  }
                   if (isGUI)
                       resetGUI(dialog);
             }              }
         }          }
         catch (Exception e)          catch (Exception e)
         {          {
             System.out.println("Error while connecting to database " + e);              System.out.println("Error while connecting to database " + e);
             if (dialog != null)              if (isGUI)
             {              {
                 dialog.setVisible(false);                  showExceptionDialog(dialog, command, e);
                 dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));                  resetGUI(dialog);
                 FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
                 java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();  
                 java.io.PrintStream stream = new java.io.PrintStream(b);  
                 stream.print(command + "\n\n");  
                 e.printStackTrace(stream);  
                 FM2SQL.showErrorDialog(b.toString(), "Error occured !");  
             }              }
             else              else
             {              {
Line 862  class Convert Line 647  class Convert
   
             }              }
         }          }
         if (dialog != null)  
       }
   
       /**
        * @param names
        * @param dialog
        * @param tbIndex
        */
       private static void prepareDialogforUse(Vector names, FM2SQL.ProgressDialog dialog, int tbIndex)
         {          {
             dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));          dialog.title.setText("Reading table data ...");
             FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));          dialog.table.setText(names.get(tbIndex).toString());
             dialog.setVisible(false);          dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
           dialog.show();
         }          }
   
       /**
        * @param names
        * @param query
        * @param tbIndex
        * @param layout
        * @return
        */
       private static String addLayoutToQuery(Vector names, String query, int tbIndex, String layout)
       {
           layout = " layout " + bean.getQC() + layout + bean.getQC();
           String name = names.get(tbIndex).toString();
           StringBuffer queryLayout = new StringBuffer(query);
           queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
           query = queryLayout.toString();
           System.out.println("added layout  " + query);
           return query;
     }      }
   
     /**      /**
Line 892  class Convert Line 703  class Convert
         while ((row = bean.getNextRow()) != null)          while ((row = bean.getNextRow()) != null)
         {          {
             j++;              j++;
             // row = (Vector) result[0].get(j);  
             /*  
              * command = new StringBuffer();  
              *   
              * command.append("INSERT INTO "); command.append(beanDest.getQC());  
              * command.append(convertText((String) names.get(tbIndex)));  
              * command.append(beanDest.getQC()); command.append(" values ( ");  
              */  
             //print rows  
             Object obj = null;              Object obj = null;
             /*  
              * for(int k=0;k <row.size()-1;++k) { obj = row.get(k);  
              * //System.out.println("row "+obj+" "+k); if(obj!=null&&!(obj instanceof  
              * ArrayList)) command.append("'"+convertUml(obj.toString())+"',"); else  
              * if(obj!=null&& obj instanceof ArrayList)  
              * command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"',");  
              * else command.append("NULL,"); } obj = row.get(row.size() - 1); if (obj !=  
              * null && !(obj instanceof ArrayList))  
              * command.append("'"+convertUml(obj.toString())+"')"); else  
              * if(obj!=null&& obj instanceof ArrayList)  
              * command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"')");  
              * //command.append(obj.toString()+")"); else command.append("NULL)");  
              */  
             //command.append("'"+row.get(row.size()-1)+"')");  
             //command.append(" )");  
             //  for(int k=0;k<row.size();++k)  
             // System.out.println();  
             //   System.out.println(command+" "+j+" "+row.size()+" "+  
             // ((Vector)result2[0].get(j)).size());  
             // System.out.println(command);  
             for (int k = 0; k < row.size(); ++k)              for (int k = 0; k < row.size(); ++k)
             {              {
                 obj = row.get(k);                  obj = row.get(k);
Line 940  class Convert Line 722  class Convert
                     pstm.setNull(k + 1, Types.NULL);                      pstm.setNull(k + 1, Types.NULL);
             }              }
             pstm.execute();              pstm.execute();
             //stm.executeUpdate(command.toString());              if (isGUI)
             if (dialog != null)  
                 dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));                  dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
             // System.out.println(  
             // (int)(((double)(j+1)/(double)result[0].size())*100.0)+"  
             // "+result[0].size()+" "+j);  
             command = null;              command = null;
         } // to while loop          } // to while loop
         return command;          return command;
Line 1328  class Convert Line 1106  class Convert
             System.out.println(" The url is "+url);              System.out.println(" The url is "+url);
             database.setURL(url.trim());              database.setURL(url.trim());
             database.setUserAndPasswd(user.trim(), password.trim());              database.setUserAndPasswd(user.trim(), password.trim());
             System.out.println("huhu");  
             //databases.add(database);              //databases.add(database);
             for (Iterator iter = databases.iterator(); iter.hasNext();)              for (Iterator iter = databases.iterator(); iter.hasNext();)
             {              {
                 System.out.println("huhu argghhhh"+(mode == DataBase.CONVERT_MODE)+" mode is "+mode);  
                   
                 DataBase db = (DataBase) iter.next();                  DataBase db = (DataBase) iter.next();
                 if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE)                  if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE)
                     convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter);                      convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter);
                 else if (mode == DataBase.UPDATE_MODE)                  else if (mode == DataBase.UPDATE_MODE)
                 {                  {
                     System.out.println("huhu arghhh arghhh arghhh");  
                                           
                     Convert.user = db.bean.user;                      Convert.user = db.bean.user;
                     Convert.passwd = db.bean.passwd;                      Convert.passwd = db.bean.passwd;
Line 1358  class Convert Line 1132  class Convert
                     synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter, new Vector(db.htIndex.values()));                      synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter, new Vector(db.htIndex.values()));
                 }                  }
             }              }
             // printContents(node3);  
             //   FM2SQL.fmInstance=new FM2SQL();  
         }          }
         catch (Exception e)          catch (Exception e)
         {          {
Line 1557  class Convert Line 1330  class Convert
             database.setURL(url.trim());              database.setURL(url.trim());
             database.setUserAndPasswd(user.trim(), password.trim());              database.setUserAndPasswd(user.trim(), password.trim());
             databases.add(new DataBase(database, null, null, null, null, null, 0));              databases.add(new DataBase(database, null, null, null, null, null, 0));
             //databases.add(database);  
             /*  
              * for (Iterator iter = databases.iterator(); iter.hasNext();) { DataBase  
              * db = (DataBase) iter.next();  
              * convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates); }  
              */  
             // printContents(node3);  
             //   FM2SQL.fmInstance=new FM2SQL();  
         }          }
         catch (Exception e)          catch (Exception e)
         {          {
Line 1850  class Convert Line 1615  class Convert
         FM2SQL.ProgressDialog dialog = null;          FM2SQL.ProgressDialog dialog = null;
         if (isGUI)          if (isGUI)
         {          {
             dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);              dialog = initDialog();
             dialog.setTitle("Conversion running ...");  
             dialog.title.setText("Getting table data ...");  
             dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);  
             dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  
             FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  
             dialog.thread = Thread.currentThread();  
         }          }
         // setting user and passwd          // setting user and passwd
         bean.setUserAndPasswd(user, passwd);          bean.setUserAndPasswd(user, passwd);
         // setting user and passwd          // setting user and passwd
         beanDest.setUserAndPasswd(userDest, passwdDest);          beanDest.setUserAndPasswd(userDest, passwdDest);
         if (dialog != null)  
             dialog.setSize(400, 250);  
         StringBuffer command = null;          StringBuffer command = null;
         String query = null;          String query = null;
         try          try
Line 1998  class Convert Line 1755  class Convert
                         command.append("DELETE FROM");                          command.append("DELETE FROM");
                         command.append(beanDest.getQC());                          command.append(beanDest.getQC());
                         command.append(destTableName);                          command.append(destTableName);
                         //command.append(convertText((String)  
                         // names.get(tbIndex)));  
                         command.append(beanDest.getQC());                          command.append(beanDest.getQC());
                         int size = bean.getColumnNames().size();                          int size = bean.getColumnNames().size();
                         command.append("WHERE " + convertText(ids.get(tbIndex).toString()) + " =  ?");                          command.append("WHERE " + convertText(ids.get(tbIndex).toString()) + " =  ?");
                         PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());                          PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
                         System.out.println(command + " " + tbIndex);                          System.out.println(command + " " + tbIndex);
                         //int rowCount = bean.getRowCount(query);  
                         //        int idIndex =  
                         // bean.getColumnNames().indexOf(ids.get(tbIndex));  
                         while (true)                          while (true)
                         {                          {
   
Line 2018  class Convert Line 1770  class Convert
                             pstm.setString(1, linesToDelete.get(j).toString());                              pstm.setString(1, linesToDelete.get(j).toString());
                             System.out.println(pstm.toString());                              System.out.println(pstm.toString());
                             pstm.execute();                              pstm.execute();
                             if (dialog != null)                              if (isGUI)
                                 dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));                                  dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
                             command = null;                              command = null;
                         }                          }
Line 2036  class Convert Line 1788  class Convert
         catch (Exception e)          catch (Exception e)
         {          {
             System.out.println("Error while connecting to database " + e);              System.out.println("Error while connecting to database " + e);
             if (dialog != null)              if (isGUI)
             {              {
                 dialog.setVisible(false);                  showExceptionDialog(dialog, command, e);
                 dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));                  resetGUI(dialog);
                 FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
             }              }
             java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();              else
             java.io.PrintStream stream = new java.io.PrintStream(b);  
             stream.print(command + "\n\n");  
             e.printStackTrace(stream);  
             FM2SQL.showErrorDialog(b.toString(), "Error occured !");  
   
         }  
         if (dialog != null)  
         {          {
             dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));                  e.printStackTrace();
             FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));              }
   
             dialog.setVisible(false);  
         }          }
     } // to method      } // to method
   
Line 2080  class Convert Line 1822  class Convert
         FM2SQL.ProgressDialog dialog = null;          FM2SQL.ProgressDialog dialog = null;
         if (isGUI)          if (isGUI)
         {          {
             dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);              dialog = initDialog();
             dialog.setTitle("Synchronize running ...");              dialog.setTitle("Synchronize running ...");
             dialog.title.setText("Getting table data ...");  
             dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);  
             dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  
             FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  
             dialog.thread = Thread.currentThread();  
         }          }
         // setting user and passwd          // setting user and passwd
         bean.setUserAndPasswd(user, passwd);          bean.setUserAndPasswd(user, passwd);
         // setting user and passwd          // setting user and passwd
         beanDest.setUserAndPasswd(userDest, passwdDest);          beanDest.setUserAndPasswd(userDest, passwdDest);
         if (dialog != null)  
             dialog.setSize(400, 250);  
         StringBuffer command = null;          StringBuffer command = null;
         String query = null;          String query = null;
         try          try
         {          {
             //bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050");  
             //bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo");  
             bean.setConnection(source);              bean.setConnection(source);
             if (names == null)              if (names == null)
                 names = bean.getTableNames();                  names = bean.getTableNames();
             // Collections.sort(names);  
             int tbIndex = 1;              int tbIndex = 1;
   
             // System.out.println("Start at  
             // "+names.indexOf("archimedes_facsimiles"));  
             for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)              for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
             {              {
                 Vector[] result = null;                  Vector[] result = null;
Line 2125  class Convert Line 1856  class Convert
                     //if vectors[1].get(i) != null)                      //if vectors[1].get(i) != null)
                     if (!layout.equals(""))                      if (!layout.equals(""))
                     {                      {
                         layout = " layout " + bean.getQC() + layout + bean.getQC();                          query = addLayoutToQuery(names, query, tbIndex, layout);
                         String name = names.get(tbIndex).toString();  
                         StringBuffer queryLayout = new StringBuffer(query);  
                         queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);  
                         query = queryLayout.toString();  
                         System.out.println("added layout  " + query);  
   
                     }                      }
                     if (dialog != null)                      if (dialog != null)
                     {                      {
                         dialog.title.setText("Getting table data ...");                          prepareDialogforUse(names, dialog, tbIndex);
                         dialog.table.setText(names.get(tbIndex).toString());  
                         dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());  
                         dialog.show();  
                     }                      }
                     bean.getConnection();                      bean.getConnection();
                     bean.makeQuery(query, 50);                      bean.makeQuery(query, 50);
Line 2147  class Convert Line 1870  class Convert
                 }                  }
                 catch (Exception e)                  catch (Exception e)
                 {                  {
                       System.out.println("Warning exception occured \n " + e);
   
                     continue;                      continue;
                 }                  }
                 // determine destTableName from createStatement or from source                  // determine destTableName from createStatement or from source
Line 2362  class Convert Line 2087  class Convert
         {          {
             System.out.println("Error while connecting to database " + e);              System.out.println("Error while connecting to database " + e);
             e.printStackTrace();              e.printStackTrace();
             if (dialog != null)              if (isGUI)
             {                  showExceptionDialog(dialog, command, e);
                 dialog.setVisible(false);  
                 dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
                 FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
             }  
             java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();  
             java.io.PrintStream stream = new java.io.PrintStream(b);  
             stream.print(command + "\n\n");  
             e.printStackTrace(stream);  
             if(dialog != null)  
             FM2SQL.showErrorDialog(b.toString(), "Error occured !");  
   
         }          }
         if (dialog != null)          if (isGUI)
         {          {
             dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));              resetGUI(dialog);
             FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
   
             dialog.setVisible(false);  
         }          }
     }      }
   
Line 2399  class Convert Line 2110  class Convert
     }      }
   
     private static void performSynchronize(String idField, Vector vec, String tempQuery, TreeSet linesToDelete, TreeSet linesToAppend, PreparedStatement insPst, PreparedStatement updPst,      private static void performSynchronize(String idField, Vector vec, String tempQuery, TreeSet linesToDelete, TreeSet linesToAppend, PreparedStatement insPst, PreparedStatement updPst,
             PreparedStatement delPSt, int deltaID, String delimiter, FM2SQL.ProgressDialog dialog) throws SQLException, ParseException              PreparedStatement delPSt, int deltaID, String delimiter, FM2SQL.ProgressDialog dialog) throws SQLException, ParseException, Exception
     {      {
         if (dialog != null)          if (dialog != null)
         {          {
Line 4051  class Convert Line 3762  class Convert
         command.append("UPDATE ");          command.append("UPDATE ");
         command.append(beanDest.getQC());          command.append(beanDest.getQC());
         command.append(destTableName);          command.append(destTableName);
         //command.append(convertText((String) names.get(tbIndex)));  
         command.append(beanDest.getQC());          command.append(beanDest.getQC());
         command.append(" SET  ");          command.append(" SET  ");
   

Removed from v.1.83  
changed lines
  Added in v.1.86


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>