Annotation of FM2SQL/src/Convert.java, revision 1.6

1.1       rogo        1: /*
                      2:  * Convert.java -- Converter class - Filemaker to SQL Converter Copyright (C)
                      3:  * 2003 Robert Gordesch (rogo@mpiwg-berlin.mpg.de) This program is free
                      4:  * software; you can redistribute it and/or modify it under the terms of the GNU
                      5:  * General Public License as published by the Free Software Foundation; either
                      6:  * version 2 of the License, or (at your option) any later version. Please read
                      7:  * license.txt for the full details. A copy of the GPL may be found at
                      8:  * http://www.gnu.org/copyleft/lgpl.html You should have received a copy of the
                      9:  * GNU General Public License along with this program; if not, write to the Free
                     10:  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
                     11:  * USA Created on 15.09.2003 by rogo
                     12:  */
                     13: 
                     14: import java.awt.Cursor;
                     15: import java.io.BufferedReader;
                     16: import java.io.BufferedWriter;
                     17: import java.io.File;
                     18: import java.io.FileInputStream;
                     19: import java.io.FileNotFoundException;
                     20: import java.io.FileOutputStream;
                     21: import java.io.IOException;
                     22: import java.io.InputStream;
                     23: import java.io.InputStreamReader;
                     24: import java.io.OutputStreamWriter;
                     25: import java.io.PrintStream;
                     26: import java.net.URL;
                     27: import java.sql.PreparedStatement;
                     28: import java.sql.ResultSet;
                     29: import java.sql.SQLException;
                     30: import java.sql.Statement;
                     31: import java.sql.Types;
                     32: import java.text.ParseException;
                     33: import java.util.ArrayList;
                     34: import java.util.Hashtable;
                     35: import java.util.Iterator;
                     36: import java.util.List;
                     37: import java.util.StringTokenizer;
                     38: import java.util.TreeSet;
                     39: import java.util.Vector;
                     40: 
                     41: import javax.swing.JDialog;
                     42: import javax.swing.JLabel;
                     43: import javax.swing.JPanel;
                     44: 
                     45: import com.exploringxml.xml.Node;
                     46: import com.exploringxml.xml.Xparse;
                     47: 
                     48: class Convert
                     49: {
1.4       rogo       50:   /**
                     51:    * Helper class for index creation
                     52:    * 
                     53:    * @author rogo
                     54:    * 
                     55:    */
                     56:   public static class IndexList extends Vector
                     57:   {
                     58:     public String toString()
                     59:     {
                     60:       StringBuffer buff = new StringBuffer(1000);
                     61:       int count = 0;
                     62:       for (Iterator iter = this.iterator(); iter.hasNext();)
                     63:       {
                     64:         String element = (String) iter.next();
                     65:         if (count < elementCount - 1)
                     66:         {
                     67:           buff.append(element).append(", ");
                     68:           count++;
                     69:         } else
                     70:           buff.append(element);
                     71: 
                     72:       }
                     73: 
                     74:       return buff.toString();
                     75:     }
                     76:   }
                     77: 
                     78:   /**
                     79:    * Helper class for pre/or post execution of SQLCommands
                     80:    * @author rogo
                     81:    *
                     82:    */
                     83:   public static class SQLCommand
                     84:   {
                     85:     private DBBean bean;
                     86:     private String command;
                     87: 
                     88:     public SQLCommand(DBBean bean, String command)
                     89:     {
                     90:       this.bean = bean;
                     91:       this.command = command;
                     92:     }
                     93: 
                     94:     public void executeCommand() throws SQLException, Exception
                     95:     {
1.6     ! rogo       96:       System.out.println("Executing command: \n");
        !            97:       System.out.println(command);
        !            98: 
1.4       rogo       99:       java.sql.Connection con = bean.getConnection();
                    100:       Statement stm = con.createStatement();
                    101:       stm.execute(command);
1.6     ! rogo      102:       stm.close();
1.4       rogo      103:     }
                    104:   }
                    105: 
                    106:   static DBBean bean = new DBBean();
                    107: 
                    108:   static DBBean beanDest = new DBBean();
                    109: 
                    110:   static String user = "", passwd = "e1nste1n";
                    111: 
                    112:   static String userDest = "postgres", passwdDest = "rogo";
                    113: 
                    114:   static boolean batchRun = false;
                    115: 
                    116:   static Vector databases = new Vector();
                    117: 
                    118:   final static int numHits = 5000;
                    119: 
                    120:   final static int numIntervalls = 4;
                    121: 
1.6     ! rogo      122:   static boolean debug = true;
1.4       rogo      123: 
                    124:   static boolean isGUI = true;
                    125: 
                    126:   /**
                    127:    * Vector for all SQLCommands to executed before any conversion action is performed
                    128:    */
                    129:   static Vector preSQLCommands = new Vector();
                    130:   /**
                    131:    * Vector for all SQLCommands to executed after any conversion action has been performed
                    132:    */
                    133: 
                    134:   static Vector postSQLCommands = new Vector();
                    135: 
                    136:   public static void main(String args[]) throws IOException
                    137:   {
                    138:     /*
                    139:      * try { //byte[] b = "�".getBytes("UTF-8"); //
                    140:      * System.out.println("QueryString " +b[0]+" "+b[1]+(new
                    141:      * String(b).getBytes()[0])+" "+new String(b).getBytes()[1]);
                    142:      * //System.out.println(new String(b,"UTF-8")); } catch
                    143:      * (UnsupportedEncodingException e) { e.printStackTrace(); }
                    144:      */
                    145:     isGUI = false;
                    146:     FileOutputStream file = null;
                    147:     if (args.length != 1)
                    148:     {
                    149:       System.out.println("Usage: java Convert <xml config file>");
                    150:       System.exit(-1);
                    151:     }
                    152:     try
                    153:     {
                    154:       File temp = File.createTempFile("fm2sql", ".txt");
                    155:       file = new FileOutputStream(temp);
                    156:     } catch (FileNotFoundException e1)
                    157:     {
                    158:       e1.printStackTrace();
                    159:     }
                    160:     PrintStream stream = new PrintStream(file, true);
                    161:     if (!debug)
                    162:     {
                    163:       System.setOut(stream);
                    164:       System.setErr(stream);
                    165:     }
                    166:     StringBuffer sb = readXMLFile(args[0]);
                    167:     parseXMLConfig(sb);
                    168:     if (!(new File(args[0]).exists()))
                    169:       System.exit(0);
                    170: 
                    171:     System.out.println("Finished!");
                    172:     // convert("jdbc:fmpro:http://141.14.237.74:8050","jdbc:postgresql://erebos/test",null,null);
                    173:   }
                    174: 
                    175:   public static void convertBatch(DBBean source, DBBean destination, Vector names, Vector layouts,
                    176:       Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception
                    177:   {
                    178:     bean = source;
                    179:     beanDest = destination;
                    180:     convert(null, null, names, layouts, selects, creates, ids, mode, delimiter);
                    181:   }
                    182: 
                    183:   public static String formatFileMakerArray(List list, String delimiter)
                    184:   {
                    185:     StringBuffer formattedString = new StringBuffer();
                    186:     for (int i = 0; i < list.size(); ++i)
                    187:     {
                    188:       formattedString.append(list.get(i).toString());
                    189:       if (i < list.size() - 1)
                    190:         formattedString.append(delimiter);
                    191:     }
                    192:     return formattedString.toString();
                    193:   }
                    194: 
                    195:   /**
                    196:    * Method for SQL UPDATE
                    197:    * 
                    198:    * @param source
                    199:    * @param destination
                    200:    * @param names
                    201:    * @param layouts
                    202:    * @param selects
                    203:    * @param creates
                    204:    * @param ids
                    205:    * @param mode
                    206:    * @throws Exception
                    207:    */
                    208:   public static void update(String source, String destination, Vector names, Vector layouts,
                    209:       Vector selects, Vector creates, Vector ids, int mode) throws Exception
                    210:   {
                    211: 
                    212:     FM2SQL.ProgressDialog dialog = null;
                    213:     if (isGUI)
                    214:     {
                    215:       dialog = initDialog();
                    216:     }
                    217:     // setting user and passwd
                    218:     bean.setUserAndPasswd(user, passwd);
                    219:     // setting user and passwd
                    220:     beanDest.setUserAndPasswd(userDest, passwdDest);
                    221: 
                    222:     StringBuffer command = null;
                    223:     String query = null;
                    224:     try
                    225:     {
                    226: 
                    227:       bean.setConnection(source);
                    228: 
                    229:       if (names == null)
                    230:         names = bean.getTableNames();
                    231:       // Collections.sort(names);
                    232:       int tbIndex = 1;
                    233: 
                    234:       System.out.println("Start at table " + names.firstElement());
                    235:       for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
                    236:       {
                    237:         Vector[] result = null;
                    238:         String destTableName = "";
                    239:         try
                    240:         {
                    241:           query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
                    242:           String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                    243:           query = (selects != null) ? selects.get(tbIndex).toString() : query;
                    244:           // if vectors[1].get(i) != null)
                    245:           if (layout != "")
                    246:           {
                    247:             query = addLayoutToQuery(names, query, tbIndex, layout);
                    248: 
                    249:           }
                    250:           if (dialog != null)
                    251:           {
                    252:             prepareDialogforUse(names, dialog, tbIndex);
                    253:           }
                    254:           bean.getConnection();
                    255:           bean.makeQuery(query, 0);
                    256: 
                    257:         } catch (Exception e)
                    258:         {
                    259:           System.out.println("Warning exception occured \n " + e);
                    260: 
                    261:           continue;
                    262:         }
                    263:         // determine destTableName from createStatement or from source
                    264:         // table name
                    265:         if (!creates.get(tbIndex).equals(""))
                    266:         {
                    267:           String create = creates.get(tbIndex).toString().toLowerCase();
                    268:           int fromIndex = create.indexOf("table") + 5;
                    269:           int toIndex = create.indexOf("(");
                    270:           destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "")
                    271:               .trim();
                    272:           System.out.println("destTable " + destTableName);
                    273: 
                    274:         } else
                    275:           destTableName = convertText(names.get(tbIndex).toString());
                    276: 
                    277:         beanDest.setConnection(destination);
                    278: 
                    279:         Statement stm = beanDest.getConnection().createStatement();
                    280: 
                    281:         Vector tables = beanDest.getTableNames();
                    282: 
                    283:         System.out.println(names.get(tbIndex) + " "
                    284:             + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
                    285:         tables = beanDest.getTableNames();
                    286:         stm = beanDest.getConnection().createStatement();
                    287: 
                    288:         if (dialog != null)
                    289:           dialog.title.setText("Updating table data ...");
                    290:         else
                    291:           System.out.println("Updating table data ...");
                    292:         int j = -1;
                    293: 
                    294:         Vector row = null;
                    295:         command = new StringBuffer();
                    296: 
                    297:         command.append("UPDATE ");
                    298:         command.append(beanDest.getQC());
                    299:         command.append(destTableName);
                    300:         // command.append(convertText((String) names.get(tbIndex)));
                    301:         command.append(beanDest.getQC());
                    302:         command.append(" SET  ");
                    303: 
                    304:         int size = bean.getColumnNames().size();
                    305:         for (int i = 0; i < size - 1; ++i)
                    306:           command.append(beanDest.getQC() + convertText((String) bean.getColumnNames().get(i))
                    307:               + beanDest.getQC() + " = ? ,");
                    308:         command.append(convertText((String) bean.getColumnNames().get(size - 1)) + " = ? ");
                    309:         command.append("WHERE " + convertText(ids.get(tbIndex).toString()) + " =  ?");
                    310:         PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
                    311:         System.out.println(command + " " + tbIndex);
                    312:         int rowCount = bean.getRowCount(query);
                    313:         int idIndex = bean.getColumnNames().indexOf(ids.get(tbIndex));
                    314:         while ((row = bean.getNextRow()) != null)
                    315:         {
                    316:           j++;
                    317:           // print rows
                    318:           Object obj = null;
                    319:           for (int k = 0; k < row.size(); ++k)
                    320:           {
                    321:             obj = row.get(k);
                    322:             if (obj instanceof ArrayList)
                    323:               obj = ((List) obj).get(0);
                    324:             String str = (obj == null) ? "NULL" : obj.toString();
                    325:             if (!str.equals("NULL"))
                    326:               pstm.setString(k + 1, str);
                    327:             else
                    328:               pstm.setNull(k + 1, Types.NULL);
                    329:           }
                    330:           pstm.setString(row.size() + 1, row.get(idIndex).toString());
                    331:           pstm.execute();
                    332:           if (dialog != null)
                    333:             dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
                    334:           command = null;
                    335:         } // to for loop
                    336: 
                    337:       }
                    338:     } catch (Exception e)
                    339:     {
                    340:       System.out.println("Error while connecting to database " + e);
                    341:       if (isGUI)
                    342:       {
                    343:         showExceptionDialog(dialog, command, e);
                    344:       } else
                    345:       {
                    346:         e.printStackTrace();
                    347: 
                    348:       }
                    349:     } finally
                    350:     {
                    351:       if (isGUI)
                    352:       {
                    353:         resetGUI(dialog);
                    354:       }
                    355:     }
                    356:   }
                    357: 
                    358:   /**
                    359:    * @param dialog
                    360:    */
                    361:   private static void resetGUI(FM2SQL.ProgressDialog dialog)
                    362:   {
                    363:     dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    364:     FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    365:     dialog.setVisible(false);
                    366:   }
                    367: 
                    368:   /**
                    369:    * @param dialog
                    370:    * @param command
                    371:    * @param e
                    372:    */
                    373:   private static void showExceptionDialog(FM2SQL.ProgressDialog dialog, StringBuffer command,
                    374:       Exception e)
                    375:   {
                    376:     dialog.setVisible(false);
                    377:     dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    378:     FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    379:     java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
                    380:     java.io.PrintStream stream = new java.io.PrintStream(b);
                    381:     stream.print(command + "\n\n");
                    382:     e.printStackTrace(stream);
                    383:     FM2SQL.showErrorDialog(b.toString(), "Error occured !");
                    384:   }
                    385: 
                    386:   /**
                    387:    * @return
                    388:    */
                    389:   private static FM2SQL.ProgressDialog initDialog()
                    390:   {
                    391:     FM2SQL.ProgressDialog dialog;
                    392:     dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
                    393:     dialog.setTitle("Conversion running ...");
                    394:     dialog.title.setText("Getting table data ...");
                    395:     dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x
                    396:         + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y
                    397:         + (FM2SQL.fmInstance.getHeight() - 250) / 2);
                    398:     dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    399:     FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    400:     dialog.thread = Thread.currentThread();
                    401:     dialog.setSize(420, 250);
                    402:     return dialog;
                    403:   }
                    404: 
                    405:   /**
                    406:    * transfers the specified array of tables to the destination database and
                    407:    * creates the table if it does not exist if it exists and mode is not append
                    408:    * the table is dropped
                    409:    * 
                    410:    * @param source
                    411:    * @param destination
                    412:    * @param names
                    413:    * @param layouts
                    414:    * @param selects
                    415:    * @param creates
                    416:    * @param ids
                    417:    * @param mode
                    418:    * @throws Exception
                    419:    */
                    420: 
                    421:   public static void convert(String source, String destination, Vector names, Vector layouts,
                    422:       Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception
                    423:   {
                    424: 
                    425:     FM2SQL.ProgressDialog dialog = null;
                    426: 
                    427:     if (isGUI)
                    428:     {
                    429:       dialog = initDialog();
                    430:     }
                    431: 
                    432:     System.out.println("connection established " + source + " " + bean.url);
                    433: 
                    434:     java.util.TreeSet myIds = new TreeSet();
                    435:     int deltaID = 1;
                    436:     String idField = "";
                    437:     String destTableName = "";
                    438:     String[] fieldNames = null;
                    439: 
                    440:     if (source != null && destination != null)
                    441:     {
                    442:       // setting user and passwd
                    443:       bean.setUserAndPasswd(user, passwd);
                    444:       // setting user and passwd
                    445:       beanDest.setUserAndPasswd(userDest, passwdDest);
                    446:     }
                    447: 
                    448:     StringBuffer command = null;
                    449:     String query = null;
                    450:     try
                    451:     {
                    452: 
                    453:       if (source != null)
                    454:         bean.setConnection(source);
                    455:       else
                    456:         bean.setConnection(bean.url);
                    457:       if (names == null)
                    458:         names = bean.getTableNames();
                    459:       int tbIndex = 1;
                    460: 
                    461:       for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
                    462:       {
                    463:         Vector[] result = null;
                    464:         try
                    465:         {
                    466:           String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                    467:           query = (selects != null) ? selects.get(tbIndex).toString() : "select * from "
                    468:               + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
                    469:           if (layout != "")
                    470:           {
                    471:             query = addLayoutToQuery(names, query, tbIndex, layout);
                    472: 
                    473:           }
                    474:           if (dialog != null)
                    475:           {
                    476:             prepareDialogforUse(names, dialog, tbIndex);
                    477:           }
                    478: 
                    479:           bean.getConnection();
                    480:           bean.makeQuery(query, 50);
                    481:           idField = ids.get(tbIndex).toString();
                    482: 
                    483:         } catch (Exception e)
                    484:         {
                    485:           System.out.println("Warning exception occured \n " + e);
                    486: 
                    487:           continue;
                    488:         }
                    489:         if (destination != null)
                    490:           beanDest.setConnection(destination);
                    491:         else
                    492:           beanDest.setConnection(beanDest.url);
                    493:         Statement stm = beanDest.getConnection().createStatement();
                    494: 
                    495:         Vector tables = beanDest.getTableNames();
                    496:         // Collections.sort(tables);
                    497:         System.out.println(names.get(tbIndex) + " "
                    498:             + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
                    499:         tables = beanDest.getTableNames();
                    500:         // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
                    501:         stm = beanDest.getConnection().createStatement();
                    502:         // System.exit(0);
                    503: 
                    504:         // determine destTableName from createStatement or from source
                    505:         // table name
                    506:         ConversionProperties prop = getFieldNamesAndDestTableName(creates.get(tbIndex).toString(),
                    507:             query, names.get(tbIndex).toString());
                    508:         destTableName = prop.destTableName;
                    509:         fieldNames = prop.fieldNames;
                    510:         if (mode == Convert.DataBase.CONVERT_MODE)
                    511:         {
                    512: 
                    513:           if (tables.indexOf(destTableName) >= 0)
                    514:           {
                    515:             stm.executeUpdate("drop table " + beanDest.getQC() + destTableName + beanDest.getQC());
                    516:             tables.remove(destTableName);
                    517:             System.out.println("dropped table" + destTableName);
                    518: 
                    519:           }
                    520:           if ((tables.indexOf(destTableName) < 0))
                    521:           {
                    522: 
                    523:             if (creates.get(tbIndex).equals("")
                    524:                 || creates.get(tbIndex).toString().toLowerCase().indexOf("create") < 0)
                    525:             {
                    526:               System.out
                    527:                   .println("Warning empty or invalid create statement - creating one for you\n");
                    528: 
                    529:               command = new StringBuffer(50);
                    530:               command.append("CREATE TABLE ");
                    531:               command.append(beanDest.getQC());
                    532:               command.append(convertText((String) names.get(tbIndex)));
                    533:               command.append(beanDest.getQC());
                    534:               command.append("(");
                    535:               String type = null;
                    536:               Vector columnNames = bean.getColumnNames();
                    537:               for (int i = 0; i < columnNames.size() - 1; ++i)
                    538:               {
                    539:                 type = bean.metaData.getColumnTypeName(i + 1);
                    540:                 // System.out.println(i+" "+result[1].get(i)+"
                    541:                 // "+type);
                    542:                 type = (type.equals("NUMBER")) ? "INT4" : type;
                    543:                 type = (type.equals("CONTAINER")) ? "TEXT" : type;
                    544: 
                    545:                 command.append(beanDest.getQC() + convertText((String) columnNames.get(i))
                    546:                     + beanDest.getQC() + " " + type + ", ");
                    547:               }
                    548:               type = bean.metaData.getColumnTypeName(columnNames.size());
                    549:               type = (type.equals("NUMBER")) ? "INT4" : type;
                    550:               type = (type.equals("CONTAINER")) ? "TEXT" : type;
                    551:               command.append(beanDest.getQC()
                    552:                   + convertText((String) columnNames.get(columnNames.size() - 1))
                    553:                   + beanDest.getQC() + " " + type);
                    554:               command.append(" )");
                    555: 
                    556:             } else
                    557:               command = new StringBuffer().append(creates.get(tbIndex).toString().toLowerCase());
                    558:             stm.executeUpdate(command.toString());
                    559: 
                    560:           }
                    561:         }
                    562:         if (dialog != null)
                    563:           dialog.title.setText("Writing table data ...");
                    564: 
                    565:         // prepare the insert statement
                    566:         int j = -1;
                    567:         Vector row = null;
                    568:         command = new StringBuffer();
                    569: 
                    570:         command.append("INSERT  INTO ");
                    571:         command.append(beanDest.getQC());
                    572:         command.append(destTableName);
                    573:         command.append(beanDest.getQC());
                    574:         command.append(" (");
                    575:         for (int i = 0; i < fieldNames.length; i++)
                    576:         {
                    577:           command.append(fieldNames[i]);
                    578:           if (i < fieldNames.length - 1)
                    579:             command.append(",");
                    580:         }
                    581:         command.append(") ");
                    582: 
                    583:         command.append(" values ( ");
                    584: 
                    585:         // add a question marks for every field
                    586:         for (int i = 0; i < bean.getColumnNames().size() - 1; ++i)
                    587:           command.append("?,");
                    588:         command.append("?)");
                    589:         PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
                    590:         System.out.println(command);
                    591:         int rowCount = (idField != "") ? myIds.size() : bean.getRowCount(query);
                    592:         Vector vec = new Vector(myIds);
                    593:         int endIndex = -1;
                    594:         String tempQuery = query;
                    595:         String tempID = bean.getQC() + idField + bean.getQC();
                    596:         // if id_field not do incremental conversion else do it all at
                    597:         // once
                    598:         if (!idField.equals(""))
                    599:         {
                    600:           long startTime = System.currentTimeMillis();
                    601:           int counter = -1;
                    602:           while (true)
                    603:           {
                    604:             ++counter;
                    605:             if (counter == 0 && dialog != null)
                    606:               dialog.title.setText("Check if data  is available");
                    607:             else if (dialog != null)
                    608:               dialog.title.setText("Check if more  data  is available");
                    609:             myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex),
                    610:                 tempQuery, numHits);
                    611:             if (myIds.isEmpty())
                    612:               break;
                    613:             vec = new Vector(myIds);
                    614:             rowCount = vec.size();
                    615:             System.out.println("ID LIST SIZE "
                    616:                 + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIds.size());
                    617:             deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls);
                    618:             if (vec.size() <= numIntervalls)
                    619:             {
                    620:               endIndex = 0;
                    621:               deltaID = vec.size();
                    622:             }
                    623:             for (int k = 0; k < vec.size() - deltaID; k = k + deltaID)
                    624:             {
                    625:               System.out.println(vec.get(k) + " " + vec.get(k + deltaID) + " " + vec.lastElement());
                    626:               if (query.indexOf("where") > 0)
                    627:                 tempQuery = query + " and " + tempID + ">='" + vec.get(k) + "' and " + tempID
                    628:                     + "<='" + vec.get(k + deltaID) + "'";
                    629:               else
                    630:                 tempQuery = query + " where " + tempID + ">='" + vec.get(k) + "' and " + tempID
                    631:                     + "<='" + vec.get(k + deltaID) + "'";
                    632:               System.out.println(tempQuery);
                    633:               if (dialog != null)
                    634:                 dialog.title.setText("Reading table data ...");
                    635: 
                    636:               bean.makeQuery(tempQuery, deltaID);
                    637:               if (dialog != null)
                    638:                 dialog.title.setText("Writing table data ...");
                    639: 
                    640:               command = writeDatainDestTable(dialog, command, k, pstm, rowCount, delimiter);
                    641:               endIndex = k + deltaID;
                    642:             }
                    643:             System.out.println(endIndex);
                    644:             // all data written ? if not write last chunk of data
                    645:             if (endIndex == vec.size() - 1)
                    646:               System.out.println("fits");
                    647:             else
                    648:             {
                    649:               System.out.println(" last intervall from " + vec.get(endIndex) + " "
                    650:                   + vec.lastElement());
                    651: 
                    652:               if (query.indexOf("where") > 0)
                    653:                 tempQuery = query + " and " + tempID + ">='" + vec.get(endIndex) + "' and "
                    654:                     + tempID + "<='" + vec.lastElement() + "'";
                    655:               else
                    656:                 tempQuery = query + " where " + tempID + ">='" + vec.get(endIndex) + "' and "
                    657:                     + tempID + "<='" + vec.lastElement() + "'";
                    658:               System.out.println(tempQuery);
                    659:               if (dialog != null)
                    660:                 dialog.title.setText("Reading table data ...");
                    661:               bean.makeQuery(tempQuery, 0);
                    662:               if (dialog != null)
                    663:                 dialog.title.setText("Writing table data ...");
                    664:               command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount, delimiter);
                    665:             }
                    666:             // prepare new query for next chunk
                    667:             if (query.indexOf("where") > 0)
                    668:               tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'";
                    669:             else
                    670:               tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'";
                    671: 
                    672:           }
                    673:           long endTime = System.currentTimeMillis();
                    674:           System.out.println("Time for incremental convert elapsed " + (endTime - startTime));
                    675:         } else
                    676:         {
                    677:           // read and write all in one big chunk
                    678:           long startTime = System.currentTimeMillis();
                    679: 
                    680:           bean.makeQuery(query, 0);
                    681:           command = writeDatainDestTable(dialog, command, j, pstm, rowCount, delimiter);
                    682:           long endTime = System.currentTimeMillis();
                    683:           System.out.println("Time for old convert elapsed " + (endTime - startTime));
                    684: 
                    685:         }
                    686:         if (isGUI)
                    687:           resetGUI(dialog);
                    688:       }
                    689:     } catch (Exception e)
                    690:     {
                    691:       System.out.println("Error while connecting to database " + e);
                    692:       if (isGUI)
                    693:       {
                    694:         showExceptionDialog(dialog, command, e);
                    695:         resetGUI(dialog);
                    696:       } else
                    697:       {
                    698:         e.printStackTrace();
                    699: 
                    700:       }
                    701:     }
                    702: 
                    703:   }
                    704: 
                    705:   /**
                    706:    * @param names
                    707:    * @param dialog
                    708:    * @param tbIndex
                    709:    */
                    710:   private static void prepareDialogforUse(Vector names, FM2SQL.ProgressDialog dialog, int tbIndex)
                    711:   {
                    712:     dialog.title.setText("Reading table data ...");
                    713:     dialog.table.setText(names.get(tbIndex).toString());
                    714:     dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
                    715:     dialog.setVisible(true);
                    716:   }
                    717: 
                    718:   /**
                    719:    * @param names
                    720:    * @param query
                    721:    * @param tbIndex
                    722:    * @param layout
                    723:    * @return
                    724:    */
                    725:   private static String addLayoutToQuery(Vector names, String query, int tbIndex, String layout)
                    726:   {
                    727:     layout = " layout " + bean.getQC() + layout + bean.getQC();
                    728:     String name = names.get(tbIndex).toString();
                    729:     StringBuffer queryLayout = new StringBuffer(query);
                    730:     queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
                    731:     query = queryLayout.toString();
                    732:     System.out.println("added layout  " + query);
                    733:     return query;
                    734:   }
                    735: 
                    736:   /**
                    737:    * Writes data to the destination table
                    738:    * 
                    739:    * @param dialog
                    740:    *          progress dialog
                    741:    * @param command
                    742:    * @param j
                    743:    *          data index for progress bar
                    744:    * @param pstm
                    745:    *          prepared statement
                    746:    * @param rowCount
                    747:    *          number of datasets
                    748:    * @return command
                    749:    * @throws Exception
                    750:    * @throws SQLException
                    751:    */
                    752:   private static StringBuffer writeDatainDestTable(FM2SQL.ProgressDialog dialog,
                    753:       StringBuffer command, int j, PreparedStatement pstm, int rowCount, String delimiter)
                    754:       throws Exception, SQLException
                    755:   {
                    756:     Vector row;
                    757:     while ((row = bean.getNextRow()) != null)
                    758:     {
                    759:       j++;
                    760:       Object obj = null;
                    761:       for (int k = 0; k < row.size(); ++k)
                    762:       {
                    763:         obj = row.get(k);
                    764: 
                    765:         if (obj instanceof ArrayList)
                    766:           obj = formatFileMakerArray((List) obj, delimiter);
                    767: 
                    768:         String str = (obj == null) ? "NULL" : obj.toString();
                    769:         if (obj instanceof Double)
                    770:         {
                    771:           pstm.setDouble(k + 1, ((Double) obj).doubleValue());
                    772:         } else if (!str.equals("NULL"))
                    773:           pstm.setString(k + 1, str);
                    774:         else
                    775:           pstm.setNull(k + 1, Types.NULL);
                    776:       }
                    777:       pstm.execute();
                    778:       if (isGUI)
                    779:         dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
                    780:       command = null;
                    781:     } // to while loop
                    782:     return command;
                    783:   }
                    784: 
                    785:   /**
                    786:    * removes special characters from the input string as well as .fp5
                    787:    * 
                    788:    * @param newName
                    789:    *          String to change
                    790:    * @return
                    791:    */
                    792:   public static String convertText(String newName)
                    793:   {
                    794:     StringBuffer alterMe = new StringBuffer(newName.trim().toLowerCase());
                    795:     int length = alterMe.length();
                    796:     int j = 0;
                    797:     int index = alterMe.indexOf(".fp5");
                    798:     if (index >= 0)
                    799:     {
                    800:       alterMe.delete(index, index + 4);
                    801:       length = length - 4;
                    802:     }
                    803: 
                    804:     while (j < length)
                    805:     {
                    806:       if (alterMe.charAt(j) == ' ')
                    807:       {
                    808:         alterMe.setCharAt(j, '_');
                    809:         // if(j<length-1) j=j+1;
                    810:       } else if (alterMe.charAt(j) == '_')
                    811:       {
                    812: 
                    813:         if (alterMe.charAt(j + 1) == '_')
                    814:           alterMe.deleteCharAt(j);
                    815:         length = length - 1;
                    816:         // if(j<length-1) j=j+1;
                    817:       } else if (alterMe.charAt(j) == 'ä')
                    818:       {
                    819:         alterMe.setCharAt(j, 'a');
                    820:         alterMe.insert(j + 1, "e");
                    821:         length = length + 1;
                    822:         if (j < length - 1)
                    823:           j = j + 1;
                    824:       } else if (alterMe.charAt(j) == 'ö')
                    825:       {
                    826:         alterMe.setCharAt(j, 'o');
                    827:         alterMe.insert(j + 1, "e");
                    828:         length = length + 1;
                    829:         if (j < length - 1)
                    830:           j = j + 1;
                    831:       } else if (alterMe.charAt(j) == 'ü')
                    832:       {
                    833:         alterMe.setCharAt(j, 'u');
                    834:         alterMe.insert(j + 1, "e");
                    835:         length = length + 1;
                    836:         if (j < length - 1)
                    837:           j = j + 1;
                    838:       } else if (alterMe.charAt(j) == 'ß')
                    839:       {
                    840:         alterMe.setCharAt(j, 's');
                    841:         alterMe.insert(j + 1, "s");
                    842:         length = length + 1;
                    843:         if (j < length - 1)
                    844:           j = j + 1;
                    845:       } else if (alterMe.charAt(j) == ':')
                    846:       {
                    847:         if (j < length - 1)
                    848:         {
                    849:           if (alterMe.charAt(j + 1) == ':')
                    850:           {
                    851:             alterMe.setCharAt(j, '_');
                    852:             alterMe.delete(j + 1, j + 2);
                    853:             length = length - 1;
                    854: 
                    855:           }
                    856: 
                    857:           if (j < length - 1)
                    858:             j = j + 1;
                    859:         }
                    860:       } else if (alterMe.charAt(j) == '-')
                    861:       {
                    862:         alterMe.setCharAt(j, '_');
                    863: 
                    864:       } else if (alterMe.charAt(j) == '?')
                    865:       {
                    866:         // changed ? to _ because of update statement
                    867:         alterMe.setCharAt(j, '_');
                    868:         // length = length + 1;
                    869:         // j=j+1;
                    870:         System.out.println(alterMe);
                    871:       } else if (alterMe.charAt(j) == '.')
                    872:       {
                    873:         if (j == length - 1)
                    874:         {
                    875:           alterMe.delete(j, j);
                    876:           length--;
                    877:         } else
                    878:           alterMe.setCharAt(j, '_');
                    879:       }
                    880: 
                    881:       ++j;
                    882:     }
                    883:     return alterMe.toString();
                    884:   }
                    885: 
                    886:   /**
                    887:    * Converts > and < in an entity (&gt; or &lt;)
                    888:    * 
                    889:    * @param newName
                    890:    * @return
                    891:    */
                    892:   public static String convertToEntities(String newName)
                    893:   {
                    894:     StringBuffer alterMe = new StringBuffer(newName.trim());
                    895:     int length = alterMe.length();
                    896:     int j = 0;
                    897: 
                    898:     while (j < length)
                    899:     {
                    900: 
                    901:       if (alterMe.charAt(j) == '>')
                    902:       {
                    903:         alterMe.setCharAt(j, '&');
                    904:         alterMe.insert(j + 1, "gt;");
                    905:         length = length + 2;
                    906:         if (j < length - 1)
                    907:           j = j + 1;
                    908: 
                    909:       } else if (alterMe.charAt(j) == '<')
                    910:       {
                    911:         alterMe.setCharAt(j, '&');
                    912:         alterMe.insert(j + 1, "lt;");
                    913:         length = length + 2;
                    914:         if (j < length - 1)
                    915:           j = j + 1;
                    916: 
                    917:       }
                    918:       ++j;
                    919:     }
                    920:     return alterMe.toString();
                    921:   }
                    922: 
                    923:   /**
                    924:    * Masks the single quote character '-->\'
                    925:    * 
                    926:    * @param newName
                    927:    * @return
                    928:    */
                    929:   public static String convertUml(String newName)
                    930:   {
                    931:     StringBuffer alterMe = new StringBuffer(newName.trim());
                    932:     int length = alterMe.length();
                    933:     int j = 0;
                    934: 
                    935:     while (j < length)
                    936:     {
                    937: 
                    938:       if (alterMe.charAt(j) == '\'')
                    939:       {
                    940:         alterMe.setCharAt(j, '\\');
                    941:         alterMe.insert(j + 1, "'");
                    942:         length = length + 1;
                    943:         if (j < length - 1)
                    944:           j = j + 1;
                    945:       }
                    946:       /*
                    947:        * else if (alterMe.charAt(j) == '"') { alterMe.setCharAt(j, '\\');
                    948:        * alterMe.insert(j + 1, "\""); length = length + 1; if(j <length-1)
                    949:        * j=j+1; } else if (alterMe.charAt(j) == '>') { alterMe.setCharAt(j,
                    950:        * '\\'); alterMe.insert(j + 1, ">"); length = length + 1; if(j <length-1)
                    951:        * j=j+1; } else if (alterMe.charAt(j) == ' <') { alterMe.setCharAt(j,
                    952:        * '\\'); alterMe.insert(j + 1, " <"); length = length + 1; if(j
                    953:        * <length-1) j=j+1; } else if (alterMe.charAt(j) == '?') {
                    954:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "?"); length = length +
                    955:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '&') {
                    956:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "&"); length = length +
                    957:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '=') {
                    958:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "="); length = length +
                    959:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == ',') {
                    960:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, ","); length = length +
                    961:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '.') {
                    962:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "."); length = length +
                    963:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '[') {
                    964:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "."); length = length +
                    965:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == ']') {
                    966:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "."); length = length +
                    967:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '%') {
                    968:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "%"); length = length +
                    969:        * 1; if(j <length-1) j=j+1; }
                    970:        */
                    971:       ++j;
                    972:     }
                    973:     return alterMe.toString();
                    974:   }
                    975: 
                    976:   /**
                    977:    * parses the input xml file for batch conversion called from readXMLFile *
                    978:    * 
                    979:    * @param sb
                    980:    */
                    981:   public static void parseXMLConfig(StringBuffer sb)
                    982:   {
                    983:     // boolean finished = false;
                    984:     Vector databases = new Vector();
                    985:     try
                    986:     {
                    987:       databases = getXMLConfig(sb);
                    988:       
1.6     ! rogo      989:       // destination DataBase object
        !           990:       DataBase dbDest=((DataBase) databases.lastElement());
        !           991: 
1.4       rogo      992:       DBBean database = ((DataBase) databases.lastElement()).bean;
                    993:       databases.remove(databases.size() - 1);
1.6     ! rogo      994:       
        !           995:       for (Iterator iterator = dbDest.preCommands.iterator(); iterator.hasNext();)
        !           996:       {
        !           997:         SQLCommand sqlCommand = (SQLCommand) iterator.next();
        !           998:         sqlCommand.executeCommand();
        !           999:       }
        !          1000: 
1.4       rogo     1001:       // databases.add(database);
                   1002:       for (Iterator iter = databases.iterator(); iter.hasNext();)
                   1003:       {
                   1004:         DataBase db = (DataBase) iter.next();
                   1005:         for (Iterator iterator = db.preCommands.iterator(); iterator.hasNext();)
                   1006:         {
                   1007:           SQLCommand sqlCommand = (SQLCommand) iterator.next();
                   1008:           sqlCommand.executeCommand();
                   1009:         }
                   1010:         int mode = db.mode;
                   1011:         if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE)
                   1012:           convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids,
                   1013:               mode, db.delimiter);
                   1014:         else if (mode == DataBase.UPDATE_MODE)
                   1015:         {
                   1016: 
                   1017:           Convert.user = db.bean.user;
                   1018:           Convert.passwd = db.bean.passwd;
                   1019:           userDest = database.user;
                   1020:           passwdDest = database.passwd;
                   1021: 
                   1022:           update(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids,
                   1023:               mode);
                   1024:         } else if (mode == DataBase.SYNCHRONIZE_MODE)
                   1025:         {
                   1026:           Convert.user = db.bean.user;
                   1027:           Convert.passwd = db.bean.passwd;
                   1028:           userDest = database.user;
                   1029:           passwdDest = database.passwd;
                   1030: 
                   1031:           synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates,
                   1032:               db.ids, mode, db.delimiter, new Vector(db.htIndex.values()));
                   1033:         }
                   1034:         for (Iterator iterator = db.postCommands.iterator(); iterator.hasNext();)
                   1035:         {
                   1036:           SQLCommand sqlCommand = (SQLCommand) iterator.next();
                   1037:           sqlCommand.executeCommand();
                   1038:         }
                   1039: 
1.6     ! rogo     1040:       }
        !          1041:       for (Iterator iterator = dbDest.postCommands.iterator(); iterator.hasNext();)
        !          1042:       {
        !          1043:         SQLCommand sqlCommand = (SQLCommand) iterator.next();
        !          1044:         sqlCommand.executeCommand();
1.4       rogo     1045:       }
                   1046: 
                   1047:     } catch (Exception e)
                   1048:     {
                   1049: 
                   1050:       e.printStackTrace();
                   1051: 
                   1052:     } finally
                   1053:     {
                   1054:       bean.closeAllConnections();
                   1055:       beanDest.closeAllConnections();
                   1056:     }
                   1057:   }
                   1058: 
                   1059:   public static Vector getXMLConfig(StringBuffer sb)
                   1060:   {
                   1061: 
                   1062:     boolean finished = false;
                   1063:     // parse string and build document tree
                   1064:     Xparse parser = new Xparse();
                   1065:     parser.changeEntities = true;
                   1066:     Node root = parser.parse(sb.toString());
                   1067:     // printContents(root);
                   1068:     Vector databases = new Vector();
                   1069:     Vector tables = new Vector();
                   1070:     Vector layouts = new Vector();
                   1071:     Vector selects = new Vector();
                   1072:     Vector creates = new Vector();
                   1073:     Vector ids = new Vector();
                   1074:     Vector preSQLCommands = new Vector();
                   1075:     Vector postSQLCommands = new Vector();
                   1076: 
                   1077:     String delimiter = "|";
                   1078:     int mode = -1;
                   1079:     try
                   1080:     {
                   1081:       Node tempNode = root.find("convert/source", new int[]
                   1082:       { 1, 1 });
                   1083:       if (tempNode == null)
                   1084:         throw new Error("parse error source tag missing");
                   1085:       System.out.println(tempNode.name);
                   1086:       int length = countNodes(tempNode);
                   1087:       for (int i = 1; i <= length; i++)
                   1088:       {
                   1089: 
                   1090:         DBBean database = new DBBean();
                   1091:         tables = new Vector();
                   1092:         layouts = new Vector();
                   1093:         selects = new Vector();
                   1094:         creates = new Vector();
                   1095:         ids = new Vector();
                   1096:         preSQLCommands = new Vector();
                   1097:         postSQLCommands = new Vector();
                   1098: 
                   1099:         // parse dataBase
                   1100:         Node node = root.find("convert/source/database/url", new int[]
                   1101:         { 1, 1, i, 1 });
                   1102:         Node node1 = root.find("convert/source/database/user", new int[]
                   1103:         { 1, 1, i, 1, 1 });
                   1104:         Node node2 = root.find("convert/source/database/password", new int[]
                   1105:         { 1, 1, i, 1, 1 });
                   1106:         Node node3 = root.find("convert/source/database", new int[]
                   1107:         { 1, 1, i });
                   1108:         Node nodeMode = root.find("convert/source/database/mode", new int[]
                   1109:         { 1, 1, i, 1, 1 });
                   1110:         Node delimiterNode = root.find("convert/source/database/delimiter", new int[]
                   1111:         { 1, 1, i, 1, 1 });
                   1112: 
                   1113:         Node commandNodes = root.find("convert/source/database/sqlcommands", new int[]
                   1114:         { 1, 1, i, 1, 1 });
                   1115:         if (commandNodes != null)
                   1116:         {
                   1117:           parseCommandNode(commandNodes, database, preSQLCommands, postSQLCommands);
                   1118:         }
                   1119:         Node useNormanToUnicodeMapper = root.find(
                   1120:             "convert/source/database/usenormantounicodemapper", new int[]
                   1121:             { 1, 1, i, 1, 1 });
                   1122: 
                   1123:         if (delimiterNode != null)
                   1124:           delimiter = delimiterNode.getCharacters();
                   1125:         if (useNormanToUnicodeMapper != null)
                   1126:         {
                   1127:           database.setUseNormanToUnicodeMapper(Boolean.valueOf(
                   1128:               useNormanToUnicodeMapper.getCharacters()).booleanValue());
                   1129:           System.out.println("useMapper "
                   1130:               + Boolean.valueOf(useNormanToUnicodeMapper.getCharacters().trim()).booleanValue());
                   1131:         }
                   1132: 
                   1133:         if (node3 == null)
                   1134:           throw new Error("parse error database tag missing");
                   1135:         if (node == null)
                   1136:           throw new Error("parse error url tag missing");
                   1137:         if (node1 == null)
                   1138:           throw new Error("parse error user tag missing");
                   1139:         if (node2 == null)
                   1140:           throw new Error("parse error password tag missing");
                   1141:         String url = node.getCharacters();
                   1142:         String user = node1.getCharacters();
                   1143:         String password = node2.getCharacters();
                   1144:         database.setURL(url.trim());
                   1145:         database.setUserAndPasswd(user.trim(), password.trim());
                   1146:         System.out.println(node.name + " " + node.getCharacters());
                   1147:         System.out.println(node1.name + " " + node1.getCharacters());
                   1148:         System.out.println(node2.name + " " + node2.getCharacters());
                   1149:         String modeString = "";
                   1150:         if (nodeMode == null)
                   1151:           modeString = "convert";
                   1152:         else
                   1153:           modeString = nodeMode.getCharacters();
                   1154:         if (modeString.equals("convert"))
                   1155:           mode = DataBase.CONVERT_MODE;
                   1156:         else if (modeString.equals("append"))
                   1157:           mode = DataBase.APPEND_MODE;
                   1158:         else if (modeString.equals("update"))
                   1159:           mode = DataBase.UPDATE_MODE;
                   1160:         else if (modeString.equals("delete"))
                   1161:           mode = DataBase.DELETE_MODE;
                   1162: 
                   1163:         else if (modeString.equals("synchronize"))
                   1164:           mode = DataBase.SYNCHRONIZE_MODE;
                   1165:         // if(node3!=null)
                   1166:         // System.out.println(node3.name);
                   1167: 
                   1168:         int length2 = countNodes(node3);
                   1169: 
                   1170:         System.out.println("number of tables " + length2);
                   1171: 
                   1172:         for (int j = 1; j <= length2; ++j)
                   1173:         {
                   1174:           Node node4 = root.find("convert/source/database/table", new int[]
                   1175:           { 1, 1, i, j });
                   1176:           Node node5 = root.find("convert/source/database/table/select", new int[]
                   1177:           { 1, 1, i, j, 1 });
                   1178:           Node node6 = root.find("convert/source/database/table/create", new int[]
                   1179:           { 1, 1, i, j, 1 });
                   1180: 
                   1181:           if (node4 != null)
                   1182:             System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
                   1183:           if (node5 != null)
                   1184:             System.out.println(node5.name + " " + node5.getCharacters());
                   1185:           if (node6 != null)
                   1186:             System.out.println(node6.name + " " + node6.getCharacters());
                   1187:           if (node4 == null)
                   1188:             throw new Error("parse error table tag missing");
                   1189:           // if(node5==null) throw new Error("parse error select tag
                   1190:           // missing");
                   1191:           // if(node6==null) throw new Error("parse error create tag
                   1192:           // missing");
                   1193:           String name = (String) node4.attributes.get("name");
                   1194:           String layout = (String) node4.attributes.get("layout");
                   1195:           String id = (String) node4.attributes.get("id");
                   1196:           System.out.println("id was " + id);
                   1197: 
                   1198:           if (name == null)
                   1199:             throw new Error("parse error required table tag attribute name missing");
                   1200:           if (layout == null)
                   1201:             layout = "";
                   1202:           if (id == null)
                   1203:             id = "";
                   1204:           if (name.equals(""))
                   1205:             throw new Error("parse error table tag attribute must not be empty");
                   1206:           tables.add(name);
                   1207:           layouts.add(layout);
                   1208:           ids.add(id);
                   1209:           String query = (node5 == null) ? "" : node5.getCharacters();
                   1210:           if (query.equals(""))
                   1211:             System.err.println("Warning empty select tag or  select tag missing !!");
                   1212:           query = (query.equals("")) ? "select * from " + database.getQC() + name
                   1213:               + database.getQC() : query;
                   1214:           selects.add(query);
                   1215:           if (node6 != null)
                   1216:             creates.add(node6.getCharacters().trim());
                   1217:           else
                   1218:             creates.add("");
                   1219: 
                   1220:         }
                   1221:         DataBase dataBase = new DataBase(database, tables, layouts, selects, creates, ids, mode);
                   1222:         dataBase.delimiter = delimiter;
                   1223:         dataBase.preCommands = new Vector(preSQLCommands);
                   1224:         dataBase.postCommands = new Vector(postSQLCommands);
                   1225:         databases.add(dataBase);
                   1226:       }
                   1227:       DBBean database = new DBBean();
                   1228: 
                   1229:       preSQLCommands.clear();
                   1230:       postSQLCommands.clear();
                   1231: 
                   1232:       // parse dataBase
                   1233:       Node node = root.find("convert/destination/database/url", new int[]
                   1234:       { 1, 1, 1, 1 });
                   1235:       Node node1 = root.find("convert/destination/database/user", new int[]
                   1236:       { 1, 1, 1, 1, 1 });
                   1237:       Node node2 = root.find("convert/destination/database/password", new int[]
                   1238:       { 1, 1, 1, 1, 1 });
                   1239:       Node commandNodes = root.find("convert/destination/database/sqlcommands", new int[]
                   1240:       { 1, 1, 1, 1, 1 });
                   1241:       if (commandNodes != null)
                   1242:       {
                   1243:         parseCommandNode(commandNodes, database, preSQLCommands, postSQLCommands);
                   1244:       }
                   1245: 
                   1246:       String url = node.getCharacters();
                   1247:       String user = node1.getCharacters();
                   1248:       String password = node2.getCharacters();
                   1249:       System.out.println(url);
                   1250:       database.setURL(url.trim());
                   1251:       database.setUserAndPasswd(user.trim(), password.trim());
                   1252:       DataBase db = new DataBase(database, new Vector(), null, null, null, null, 0);
                   1253:       databases.add(db);
                   1254:       db.preCommands = new Vector(preSQLCommands);
                   1255:       db.postCommands = new Vector(postSQLCommands);
                   1256: 
                   1257:     } catch (Exception e)
                   1258:     {
                   1259:       e.printStackTrace();
                   1260:     }
                   1261:     return databases;
                   1262:   }
                   1263: 
                   1264:   /**
                   1265:    *
                   1266:    * @param commandNode
                   1267:    * @param database
                   1268:    * @param preSQLCommands 
                   1269:    * @param postSQLCommand 
                   1270:    */
                   1271:   private static void parseCommandNode(Node commandNode, DBBean database,
                   1272:       java.util.Vector preSQLCommands, java.util.Vector postSQLCommands)
                   1273:   {
                   1274:     // System.out.println(commandNode.name + " " + countNodes(commandNode));
                   1275:     int numCommands = commandNode.contents.length();
                   1276:     for (int j = 0; j < numCommands; ++j)
                   1277:     {
                   1278:       Node node = (Node) commandNode.contents.v.elementAt(j);
                   1279:       if (node.type.equals("element"))
                   1280:       {
                   1281:         // System.out.println(node.name + " " + node.getCharacters() + database);
                   1282:         String execute = node.attributes.get("execute").toString();
                   1283:         if (execute.equals("before"))
                   1284:         {
                   1285:           preSQLCommands.add(new SQLCommand(database, node.getCharacters()));
                   1286:         }
                   1287:         if (execute.equals("after"))
                   1288:         {
                   1289:           postSQLCommands.add(new SQLCommand(database, node.getCharacters()));
                   1290:         }
                   1291: 
                   1292:       }
                   1293: 
                   1294:     }
                   1295:   }
                   1296: 
                   1297:   private static int countNodes(Node tempNode)
                   1298:   {
                   1299:     int length = 0;
                   1300:     for (int i = 0; i < tempNode.contents.v.size(); ++i)
                   1301:     {
                   1302:       Node node = (Node) tempNode.contents.v.elementAt(i);
                   1303:       if (node.type.equals("element"))
                   1304:       {
                   1305:         if (node.name.equals("database"))
                   1306:           length++;
                   1307:         if (node.name.equals("table"))
                   1308:           length++;
                   1309:         if (node.name.equals("sqlcommand"))
                   1310:           length++;
                   1311: 
                   1312:       }
                   1313: 
                   1314:       // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+"
                   1315:       // "+i);
                   1316:     }
                   1317:     return length;
                   1318:   }
                   1319: 
                   1320:   private static void printContents(Node root)
                   1321:   {
                   1322: 
                   1323:     Vector contents = (root.index == null) ? root.contents.v : root.index.v;
                   1324:     for (int i = 0; i < contents.size(); ++i)
                   1325:     {
                   1326:       Node n = (Node) contents.elementAt(i);
                   1327:       if (n.type.equals("element"))
                   1328:       {
                   1329:         System.out.println("tag " + n.name);
                   1330:         System.out.println(n.getCharacters());
                   1331:         // contents=n.contents.v i=0;
                   1332:       }
                   1333:       // System.out.println(n.type);
                   1334:     }
                   1335:   }
                   1336: 
                   1337:   /**
                   1338:    * reads the specified xml file
                   1339:    * 
                   1340:    * @param xmlFile
                   1341:    */
                   1342:   public static StringBuffer readXMLFile(String xmlFile)
                   1343:   {
                   1344:     InputStream stream = null;
                   1345:     StringBuffer sb = new StringBuffer();
                   1346: 
                   1347:     try
                   1348:     {
                   1349: 
                   1350:       if (xmlFile.indexOf("file://") >= 0 || xmlFile.indexOf("http://") >= 0)
                   1351:       {
                   1352:         URL url = new URL(xmlFile);
                   1353:         stream = url.openStream();
                   1354:       } else
                   1355:         // read XML Metadata from a file
                   1356:         stream = new FileInputStream(xmlFile);
                   1357:       InputStreamReader isr = new InputStreamReader(stream, "UTF-8");
                   1358:       BufferedReader buffr = new BufferedReader(isr);
                   1359:       int c = 0;
                   1360:       while ((c = buffr.read()) != -1)
                   1361:       {
                   1362:         char ch = (char) c;
                   1363:         sb.append(ch);
                   1364:         // System.out.print((char)c);
                   1365:       }
                   1366:     } catch (Exception e)
                   1367:     {
                   1368:       e.printStackTrace();
                   1369:     } finally
                   1370:     {
                   1371: 
                   1372:       try
                   1373:       {
                   1374:         stream.close();
                   1375:       } catch (IOException e1)
                   1376:       {
                   1377:         // TODO Auto-generated catch block
                   1378:         e1.printStackTrace();
                   1379:       }
                   1380:     }
                   1381:     return sb;
                   1382:   }
                   1383: 
                   1384:   /**
                   1385:    * Helper class for Conversion etc. Contains data needed for the conversion
                   1386:    * 
                   1387:    * @author rogo
                   1388:    * 
                   1389:    */
                   1390: 
                   1391:   public static class ConversionProperties
                   1392:   {
                   1393:     String destTableName;
                   1394: 
                   1395:     String[] fieldNames;
                   1396: 
                   1397:     public ConversionProperties()
                   1398:     {
                   1399:     }
                   1400: 
                   1401:     public ConversionProperties(String destTableName, String[] fieldNames)
                   1402:     {
                   1403:       this.destTableName = destTableName;
                   1404:       this.fieldNames = fieldNames;
                   1405: 
                   1406:     }
                   1407: 
                   1408:   }
                   1409: 
                   1410:   /**
                   1411:    * Helper class for XML-File parsing Holds the parsed data
                   1412:    * 
                   1413:    * @author rogo
                   1414:    * 
                   1415:    */
                   1416:   public static class DataBase
                   1417:   {
                   1418:     DBBean bean;
                   1419: 
                   1420:     Vector creates;
                   1421: 
                   1422:     Vector selects;
                   1423: 
                   1424:     Vector layouts;
                   1425: 
                   1426:     Vector tables=new Vector();
                   1427: 
                   1428:     Vector ids;
                   1429: 
                   1430:     String delimiter = "//";
                   1431: 
                   1432:     Vector preCommands;
                   1433:     Vector postCommands;
                   1434: 
                   1435:     /**
                   1436:      * maps table name to index fields
                   1437:      */
                   1438:     Hashtable htIndex = new Hashtable();
                   1439: 
                   1440:     boolean useNormanToUnicodeMapper = false;
                   1441: 
                   1442:     final static int CONVERT_MODE = 1;
                   1443: 
                   1444:     final static int APPEND_MODE = 2;
                   1445: 
                   1446:     final static int UPDATE_MODE = 3;
                   1447: 
                   1448:     final static int DELETE_MODE = 4;
                   1449: 
                   1450:     final static int SYNCHRONIZE_MODE = 5;
                   1451: 
                   1452:     int mode = -1;
                   1453: 
                   1454:     public DataBase(DBBean bean, Vector tables, Vector layouts, Vector selects, Vector creates,
                   1455:         Vector ids, int mode)
                   1456:     {
                   1457:       this.bean = bean;
                   1458:       this.tables = tables;
                   1459:       this.layouts = layouts;
                   1460:       this.selects = selects;
                   1461:       this.creates = creates;
                   1462:       this.ids = ids;
                   1463:       this.mode = mode;
                   1464:       this.bean.setIDVector(ids);
                   1465:     }
                   1466: 
                   1467:     /**
                   1468:      * @param indexListVec
                   1469:      */
                   1470:     public void buildIndexTable(Vector indexListVec)
                   1471:     {
                   1472:       for (int i = 0; i < tables.size(); i++)
                   1473:       {
                   1474:         fillIndexList((String) tables.get(i), (String) indexListVec.get(i));
                   1475:       }
                   1476:     }
                   1477: 
                   1478:     /**
                   1479:      * writes the data contained in this object to the buffered writer *
                   1480:      * 
                   1481:      * @param buffr
                   1482:      * @throws Exception
                   1483:      */
                   1484:     public void exportToXML(BufferedWriter buffr) throws Exception
                   1485:     {
                   1486:       // ids=bean.getIDVector();
                   1487:       buffr.write("    <database>\n");
                   1488:       buffr.write("      <url>" + bean.url + "</url>\n");
                   1489:       buffr.write("      <user>" + bean.user + "</user>\n");
                   1490:       buffr.write("      <password>" + bean.passwd + "</password>\n");
                   1491:       buffr.write("      <delimiter>" + delimiter + "</delimiter>\n");
                   1492:       String modeString = "";
                   1493:       if (mode == CONVERT_MODE)
                   1494:         modeString = "convert";
                   1495:       else if (mode == APPEND_MODE)
                   1496:         modeString = "append";
                   1497:       else if (mode == UPDATE_MODE)
                   1498:         modeString = "update";
                   1499:       else if (mode == DELETE_MODE)
                   1500:         modeString = "delete";
                   1501:       else if (mode == SYNCHRONIZE_MODE)
                   1502:         modeString = "synchronize";
                   1503: 
                   1504:       buffr.write("      <mode>" + modeString + "</mode>\n");
                   1505:       buffr.write("      <usenormantounicodemapper>" + useNormanToUnicodeMapper
                   1506:           + "</usenormantounicodemapper>\n");
                   1507:       if (preCommands != null || postCommands != null)
                   1508:       {
                   1509:         int count = 0;
                   1510: 
                   1511:         buffr.write("      <sqlcommands> \n");
                   1512: 
                   1513:         if (preCommands != null)
                   1514:         {
                   1515:           while (count < preCommands.size())
                   1516:           {
                   1517:             SQLCommand sqlcommand=(SQLCommand)preCommands.get(count);
                   1518:             buffr.write("        <sqlcommand execute=\"before\">" + sqlcommand.command + "</sqlcommand>\n");
                   1519:             count++;
                   1520:           }
                   1521:         }
                   1522:         if (postCommands != null)
                   1523:         {
                   1524:           count = 0;
                   1525:           while (count < postCommands.size())
                   1526:           {
                   1527:             SQLCommand sqlcommand=(SQLCommand)postCommands.get(count);
                   1528:             
                   1529:             buffr.write("        <sqlcommand execute=\"after\">" + sqlcommand.command + "</sqlcommand>\n");
                   1530:             count++;
                   1531:           }
                   1532:         }
                   1533:         buffr.write("      </sqlcommands> \n");
                   1534: 
                   1535:       }
                   1536:       int index = 0;
                   1537:       while (index < tables.size())
                   1538:       {
                   1539:         String table = (String) tables.get(index);
                   1540:         String layout = (String) layouts.get(index);
                   1541:         String select = (String) selects.get(index);
                   1542:         String create = (String) creates.get(index);
                   1543:         String id = (String) ids.get(index);
                   1544:         IndexList indexList = (IndexList) htIndex.get(table);
                   1545:         if (indexList == null)
                   1546:           indexList = new IndexList();
                   1547:         buffr.write("      <table name = \"" + table + "\" layout = \"" + layout + "\" id = \""
                   1548:             + id + "\" indexList =\"" + indexList + "\">\n");
                   1549:         buffr.write("         <select>" + convertToEntities(select) + "</select>\n");
                   1550:         if (!create.equals(""))
                   1551:           buffr.write("         <create>" + create + "         </create>\n");
                   1552:         buffr.write("      </table>\n");
                   1553:         index++;
                   1554:       }
                   1555:       buffr.write("    </database>\n");
                   1556:     }
                   1557: 
                   1558:     public void fillIndexList(String table, String list)
                   1559:     {
                   1560:       IndexList indexList = new IndexList();
                   1561:       StringTokenizer tokenizer = new StringTokenizer(list, ",");
                   1562:       while (tokenizer.hasMoreTokens())
                   1563:       {
                   1564:         indexList.add(tokenizer.nextToken());
                   1565:       }
                   1566:       System.out.println(indexList);
                   1567: 
                   1568:       htIndex.put(table, indexList);
                   1569:     }
                   1570: 
                   1571:     public String toString()
                   1572:     {
                   1573:       return bean.url + " " + tables;
                   1574:     }
                   1575: 
                   1576:   }
                   1577: 
                   1578:   public static void writeConfig(String file, DataBase source, DataBase destination)
                   1579:       throws Exception
                   1580:   {
                   1581:     if (!file.toLowerCase().endsWith(".xml"))
                   1582:       file += ".xml";
                   1583:     File f = new File(file);
                   1584: 
                   1585:     FileOutputStream fout = new FileOutputStream(f);
                   1586:     OutputStreamWriter outsw = new OutputStreamWriter(fout, "UTF-8");
                   1587:     BufferedWriter buffw = new BufferedWriter(outsw);
                   1588:     buffw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                   1589:     buffw.newLine();
                   1590:     buffw.write("<convert>\n");
                   1591:     buffw.write("  <source>\n");
                   1592:     source.exportToXML(buffw);
                   1593:     buffw.write("  </source>\n");
                   1594:     buffw.write("\n  <destination>\n");
                   1595:     destination.exportToXML(buffw);
                   1596:     buffw.write("  </destination>\n");
                   1597:     buffw.write("</convert>\n");
                   1598:     buffw.close();
                   1599:   }
                   1600: 
                   1601:   public static void delete(String source, String destination, Vector names, Vector layouts,
                   1602:       Vector selects, Vector creates, Vector ids, int mode) throws Exception
                   1603:   {
                   1604:     FM2SQL.ProgressDialog dialog = null;
                   1605:     if (isGUI)
                   1606:     {
                   1607:       dialog = initDialog();
                   1608:     }
                   1609:     // setting user and passwd
                   1610:     bean.setUserAndPasswd(user, passwd);
                   1611:     // setting user and passwd
                   1612:     beanDest.setUserAndPasswd(userDest, passwdDest);
                   1613:     StringBuffer command = null;
                   1614:     String query = null;
                   1615:     try
                   1616:     {
                   1617:       // bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050");
                   1618:       // bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo");
                   1619:       bean.setConnection(source);
                   1620:       if (names == null)
                   1621:         names = bean.getTableNames();
                   1622:       // Collections.sort(names);
                   1623:       int tbIndex = 1;
                   1624: 
                   1625:       // System.out.println("Start at
                   1626:       // "+names.indexOf("archimedes_facsimiles"));
                   1627:       for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
                   1628:       {
                   1629:         Vector[] result = null;
                   1630:         java.util.TreeSet myIds = new TreeSet();
                   1631:         java.util.TreeSet myIdsDest = new TreeSet();
                   1632:         int deltaID = 1;
                   1633:         String idField = "";
                   1634:         String destTableName = "";
                   1635: 
                   1636:         try
                   1637:         {
                   1638:           query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
                   1639:           String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                   1640:           query = (selects != null) ? selects.get(tbIndex).toString() : query;
                   1641:           // if vectors[1].get(i) != null)
                   1642:           if (layout != "")
                   1643:           {
                   1644:             layout = " layout " + bean.getQC() + layout + bean.getQC();
                   1645:             String name = names.get(tbIndex).toString();
                   1646:             StringBuffer queryLayout = new StringBuffer(query);
                   1647:             queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
                   1648:             query = queryLayout.toString();
                   1649:             System.out.println("added layout  " + query);
                   1650: 
                   1651:           }
                   1652:           dialog.title.setText("Getting table data ...");
                   1653:           dialog.table.setText(names.get(tbIndex).toString());
                   1654:           dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
                   1655:           dialog.setVisible(true);
                   1656:           bean.getConnection();
                   1657:           bean.makeQuery(query, 50);
                   1658:           idField = ids.get(tbIndex).toString();
                   1659: 
                   1660:         } catch (Exception e)
                   1661:         {
                   1662:           continue;
                   1663:         }
                   1664:         // determine destTableName from createStatement or from source
                   1665:         // table name
                   1666:         if (!creates.get(tbIndex).equals(""))
                   1667:         {
                   1668:           String create = creates.get(tbIndex).toString().toLowerCase();
                   1669:           int fromIndex = create.indexOf("table") + 5;
                   1670:           int toIndex = create.indexOf("(");
                   1671:           destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "")
                   1672:               .trim();
                   1673:           System.out.println("destTable " + destTableName);
                   1674: 
                   1675:         } else
                   1676:           destTableName = convertText(names.get(tbIndex).toString());
                   1677: 
                   1678:         // for id kram
                   1679:         Vector vec = null;
                   1680:         Vector vecDest = null;
                   1681:         // tempo
                   1682:         beanDest.setConnection(destination);
                   1683:         int rowCount = (idField != "") ? myIds.size() : bean.getRowCount(query);
                   1684:         String tempID = bean.getQC() + idField + bean.getQC();
                   1685:         String tempIDdest = beanDest.getQC() + convertText(idField) + beanDest.getQC();
                   1686: 
                   1687:         int endIndex = -1;
                   1688:         String tempQuery = query;
                   1689:         String destQuery = query.replaceAll(names.get(tbIndex).toString(), destTableName);
                   1690:         String tempQueryDest = destQuery;
                   1691:         // remove extra query parts
                   1692:         // destQuery.substring(0,destQuery.lastIndexOf(destTableName)+destTableName.length()+1);
                   1693:         System.out.println("new Query " + tempQueryDest);
                   1694:         if (!idField.equals(""))
                   1695:         {
                   1696:           long startTime = System.currentTimeMillis();
                   1697:           int counter = -1;
                   1698:           while (true)
                   1699:           {
                   1700:             ++counter;
                   1701:             if (counter == 0 && dialog != null)
                   1702:               dialog.title.setText("Check if data  is available");
                   1703:             else if (dialog != null)
                   1704:               dialog.title.setText("Check if more  data  is available");
                   1705:             myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex),
                   1706:                 tempQuery, numHits);
                   1707:             myIdsDest = beanDest.getIDVector(convertText(idField), destTableName, tempQueryDest,
                   1708:                 numHits);
                   1709:             if (myIds.isEmpty())
                   1710:               break;
                   1711:             vec = new Vector(myIds);
                   1712:             vecDest = new Vector(myIdsDest);
                   1713:             rowCount = vec.size();
                   1714:             // Deletion will work this way
                   1715:             Vector deleted = new Vector(vec);
                   1716:             Vector linesToDelete = new Vector(vecDest);
                   1717:             // remove all lines that should not be deleted
                   1718:             linesToDelete.removeAll(deleted);
                   1719:             // System.out.println("ID LIST SIZE " +
                   1720:             // Math.round((double) myIds.size() / (double)
                   1721:             // numIntervalls) + " " + myIdsDest.size());
                   1722:             // / @TODO complete delete task remove query show lines
                   1723:             // to be deleted let user choose if he wants that
                   1724:             System.out.println("number of lines to  be deleted " + linesToDelete.size());
                   1725:             deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls);
                   1726:             beanDest.setConnection(destination);
                   1727: 
                   1728:             Statement stm = beanDest.getConnection().createStatement();
                   1729: 
                   1730:             Vector tables = beanDest.getTableNames();
                   1731:             // Collections.sort(tables);
                   1732:             System.out.println(names.get(tbIndex) + " "
                   1733:                 + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
                   1734:             tables = beanDest.getTableNames();
                   1735:             // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
                   1736:             stm = beanDest.getConnection().createStatement();
                   1737: 
                   1738:             if (dialog != null)
                   1739:               dialog.title.setText(" Deleting table data ...");
                   1740: 
                   1741:             int j = -1;
                   1742: 
                   1743:             Vector row = null;
                   1744:             command = new StringBuffer();
                   1745: 
                   1746:             command.append("DELETE FROM");
                   1747:             command.append(beanDest.getQC());
                   1748:             command.append(destTableName);
                   1749:             command.append(beanDest.getQC());
                   1750:             int size = bean.getColumnNames().size();
                   1751:             command.append("WHERE " + convertText(ids.get(tbIndex).toString()) + " =  ?");
                   1752:             PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
                   1753:             System.out.println(command + " " + tbIndex);
                   1754:             while (true)
                   1755:             {
                   1756: 
                   1757:               ++j;
                   1758:               if (j == linesToDelete.size())
                   1759:                 break;
                   1760:               // print rows
                   1761:               pstm.setString(1, linesToDelete.get(j).toString());
                   1762:               System.out.println(pstm.toString());
                   1763:               pstm.execute();
                   1764:               if (isGUI)
                   1765:                 dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
                   1766:               command = null;
                   1767:             }
                   1768:             // prepare new query for next chunk
                   1769:             if (query.indexOf("where") > 0)
                   1770:               tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'";
                   1771:             else
                   1772:               tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'";
                   1773: 
                   1774:           } // to outer while
                   1775:         } // to idfield if
                   1776:       } // table loop
                   1777: 
                   1778:     } catch (Exception e)
                   1779:     {
                   1780:       System.out.println("Error while connecting to database " + e);
                   1781:       if (isGUI)
                   1782:       {
                   1783:         showExceptionDialog(dialog, command, e);
                   1784:         resetGUI(dialog);
                   1785:       } else
                   1786:       {
                   1787:         e.printStackTrace();
                   1788:       }
                   1789:     }
                   1790:   } // to method
                   1791: 
                   1792:   /**
                   1793:    * synchronize method based on delete method code
                   1794:    * 
                   1795:    * @param source
                   1796:    * @param destination
                   1797:    * @param names
                   1798:    * @param layouts
                   1799:    * @param selects
                   1800:    * @param creates
                   1801:    * @param ids
                   1802:    * @param mode
                   1803:    * @throws Exception
                   1804:    */
                   1805:   // TODO implement append,update and delete in one method
                   1806:   // TODO using id based algorithm
                   1807:   public static void synchronize(String source, String destination, Vector names, Vector layouts,
                   1808:       Vector selects, Vector creates, Vector ids, int mode, String delimiter, Vector indexList)
                   1809:       throws Exception
                   1810:   {
                   1811:     System.out.println(" bin in synchronize!!!");
                   1812:     FM2SQL.ProgressDialog dialog = null;
                   1813:     if (isGUI)
                   1814:     {
                   1815:       dialog = initDialog();
                   1816:       dialog.setTitle("Synchronize running ...");
                   1817: 
                   1818:     }
                   1819:     // setting user and passwd
                   1820:     bean.setUserAndPasswd(user, passwd);
                   1821:     // setting user and passwd
                   1822:     beanDest.setUserAndPasswd(userDest, passwdDest);
                   1823:     StringBuffer command = null;
                   1824:     String query = null;
                   1825:     try
                   1826:     {
                   1827:       bean.setConnection(source);
                   1828:       if (names == null)
                   1829:         names = bean.getTableNames();
                   1830:       int tbIndex = 1;
                   1831: 
                   1832:       for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
                   1833:       {
                   1834:         Vector[] result = null;
                   1835:         java.util.TreeSet myIds = new TreeSet();
                   1836:         java.util.TreeSet myIdsDest = new TreeSet();
                   1837:         int deltaID = 1;
                   1838:         String idField = "";
                   1839:         String destTableName = "";
                   1840: 
                   1841:         try
                   1842:         {
                   1843:           query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
                   1844:           String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                   1845:           query = (selects != null) ? selects.get(tbIndex).toString() : query;
                   1846:           // if vectors[1].get(i) != null)
                   1847:           if (!layout.equals(""))
                   1848:           {
                   1849:             query = addLayoutToQuery(names, query, tbIndex, layout);
                   1850: 
                   1851:           }
                   1852:           if (dialog != null)
                   1853:           {
                   1854:             prepareDialogforUse(names, dialog, tbIndex);
                   1855:           }
                   1856:           bean.getConnection();
                   1857:           bean.makeQuery(query, 50);
                   1858:           idField = ids.get(tbIndex).toString();
                   1859: 
                   1860:         } catch (Exception e)
                   1861:         {
                   1862:           System.out.println("Warning exception occured \n " + e);
                   1863: 
                   1864:           continue;
                   1865:         }
                   1866:         // determine destTableName from createStatement or from source
                   1867:         // table name
                   1868:         if (!creates.get(tbIndex).equals(""))
                   1869:         {
                   1870:           String create = creates.get(tbIndex).toString().toLowerCase();
                   1871:           int fromIndex = create.indexOf("table") + 5;
                   1872:           int toIndex = create.indexOf("(");
                   1873:           destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "")
                   1874:               .trim();
                   1875:           System.out.println("destTable " + destTableName);
                   1876: 
                   1877:         } else
                   1878:           destTableName = convertText(names.get(tbIndex).toString());
                   1879: 
                   1880:         // for id kram
                   1881:         Vector vec = null;
                   1882:         Vector vecDest = null;
                   1883:         // tempo
                   1884:         beanDest.setConnection(destination);
                   1885:         int rowCount = (idField != "") ? myIds.size() : bean.getRowCount(query);
                   1886:         String tempID = bean.getQC() + idField + bean.getQC();
                   1887:         String tempIDdest = beanDest.getQC() + convertText(idField) + beanDest.getQC();
                   1888: 
                   1889:         int endIndex = -1;
                   1890:         String tempQuery = query;
                   1891:         String destQuery = query.replaceAll(names.get(tbIndex).toString(), destTableName);
                   1892:         destQuery = destQuery.replaceAll(bean.getQC(), beanDest.getQC());
                   1893:         destQuery = removeLayoutPartFromQuery(destQuery, layouts.get(tbIndex).toString());
                   1894:         // TODO remove layout part for destQuery
                   1895:         String tempQueryDest = destQuery;
                   1896:         // remove extra query parts
                   1897:         // destQuery.substring(0,destQuery.lastIndexOf(destTableName)+destTableName.length()+1);
                   1898:         System.out.println("new Query " + tempQueryDest);
                   1899:         System.out.println("idfield " + idField + " " + ids.get(tbIndex).toString());
                   1900:         if (!idField.equals(""))
                   1901:         {
                   1902:           long startTime = System.currentTimeMillis();
                   1903:           int counter = -1;
                   1904:           TreeSet linesToDelete = null;
                   1905:           PreparedStatement delPSt = null;
                   1906:           while (true)
                   1907:           {
                   1908:             ++counter;
                   1909:             if (counter == 0 && dialog != null)
                   1910:               dialog.title.setText("Check if data  is available");
                   1911:             else if (dialog != null)
                   1912:               dialog.title.setText("Check if more  data  is available");
                   1913: 
                   1914:             myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex),
                   1915:                 tempQuery, 0);
                   1916:             myIdsDest = beanDest.getIDVector(convertText(idField), destTableName, tempQueryDest, 0);
                   1917:             // System.out.println("status of remove
                   1918:             // "+myIds.remove("b015892"));
                   1919:             System.out.println("ids found for " + idField + " " + !myIds.isEmpty());
                   1920:             if (myIds.isEmpty())
                   1921:               break;
                   1922:             vec = new Vector(myIds);
                   1923:             vecDest = new Vector(myIdsDest);
                   1924:             rowCount = vec.size();
                   1925:             // Deletion will work this way
                   1926:             Vector deleted = new Vector(vec);
                   1927: 
                   1928:             TreeSet linesToAppend = new TreeSet(vec);
                   1929:             linesToAppend.addAll(vec);
                   1930:             linesToDelete = new TreeSet(vecDest);
                   1931:             // remove all lines that are already in dest database
                   1932:             linesToAppend.removeAll(vecDest);
                   1933:             // remove all lines that should not be deleted
                   1934:             linesToDelete.removeAll(deleted);
                   1935:             System.out.println("linesToAppend " + linesToAppend.size() + " " + destTableName);
                   1936:             System.out.println("linesToDelete " + linesToDelete.size() + " " + destTableName);
                   1937:             System.out.println("ID LIST SIZE "
                   1938:                 + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIds.size());
                   1939:             deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls);
                   1940:             ConversionProperties prop = getFieldNamesAndDestTableName(creates.get(tbIndex)
                   1941:                 .toString(), query, names.get(tbIndex).toString());
                   1942:             StringBuffer insCommand = createInsertCommand(prop.destTableName, prop.fieldNames);
                   1943:             StringBuffer updCommand = createUpdateCommand(prop.destTableName, prop.fieldNames,
                   1944:                 tempIDdest);
                   1945:             StringBuffer delCommand = createDeleteCommand(destTableName, tempIDdest);
                   1946:             PreparedStatement insPst = beanDest.getConnection().prepareStatement(
                   1947:                 insCommand.toString());
                   1948:             PreparedStatement updPst = beanDest.getConnection().prepareStatement(
                   1949:                 updCommand.toString());
                   1950:             delPSt = beanDest.getConnection().prepareStatement(delCommand.toString());
                   1951:             // delPSt.setString(1,"b015892");
                   1952:             // delPSt.execute();
                   1953:             // if (true)
                   1954:             // return;
                   1955:             if (vec.size() <= numIntervalls)
                   1956:             {
                   1957:               endIndex = 0;
                   1958:               deltaID = vec.size();
                   1959:             }
                   1960:             for (int k = 0; k < vec.size() - deltaID; k = k + deltaID)
                   1961:             {
                   1962:               System.out.println(vec.get(k) + " " + vec.get(k + deltaID) + " " + vec.lastElement());
                   1963:               if (query.indexOf("where") > 0)
                   1964:                 tempQuery = query + " and " + tempID + ">='" + vec.get(k) + "' and " + tempID
                   1965:                     + "<='" + vec.get(k + deltaID) + "'";
                   1966:               else
                   1967:                 tempQuery = query + " where " + tempID + ">='" + vec.get(k) + "' and " + tempID
                   1968:                     + "<='" + vec.get(k + deltaID) + "'";
                   1969:               System.out.println(tempQuery);
                   1970:               if (dialog != null)
                   1971:                 dialog.title.setText("Reading table data ...");
                   1972: 
                   1973:               // bean.makeQuery(tempQuery, deltaID);
                   1974:               if (dialog != null)
                   1975:                 dialog.title.setText("Writing table data ...");
                   1976: 
                   1977:               performSynchronize(idField, vec, tempQuery, linesToDelete, linesToAppend, insPst,
                   1978:                   updPst, delPSt, deltaID, delimiter, dialog);
                   1979:               // System.out.println("ID LIST SIZE " +
                   1980:               // Math.round((double) myIds.size() / (double)
                   1981:               // numIntervalls) + " " + myIdsDest.size());
                   1982:               endIndex = k + deltaID;
                   1983:             }
                   1984:             System.out.println(endIndex);
                   1985:             // all data written ? if not write last chunk of data
                   1986:             if (endIndex == vec.size() - 1)
                   1987:               System.out.println("fits");
                   1988:             else
                   1989:             {
                   1990:               System.out.println(" last intervall from " + vec.get(endIndex) + " "
                   1991:                   + vec.lastElement());
                   1992: 
                   1993:               if (query.indexOf("where") > 0)
                   1994:                 tempQuery = query + " and " + tempID + ">='" + vec.get(endIndex) + "' and "
                   1995:                     + tempID + "<='" + vec.lastElement() + "'";
                   1996:               else
                   1997:                 tempQuery = query + " where " + tempID + ">='" + vec.get(endIndex) + "' and "
                   1998:                     + tempID + "<='" + vec.lastElement() + "'";
                   1999:               System.out.println(tempQuery);
                   2000:               if (dialog != null)
                   2001:                 dialog.title.setText("Reading table data ...");
                   2002:               // bean.makeQuery(tempQuery, 0);
                   2003:               if (dialog != null)
                   2004:                 dialog.title.setText("Writing table data ...");
                   2005:               performSynchronize(idField, vec, tempQuery, linesToDelete, linesToAppend, insPst,
                   2006:                   updPst, delPSt, deltaID, delimiter, dialog);
                   2007:               // System.out.println("ID LIST SIZE " +
                   2008:               // Math.round((double) myIds.size() / (double)
                   2009:               // numIntervalls) + " " + myIdsDest.size());
                   2010:             }
                   2011:             // prepare new query for next chunk
                   2012:             if (query.indexOf("where") > 0)
                   2013:               tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'";
                   2014:             else
                   2015:               tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'";
                   2016: 
                   2017:           }
                   2018:           String tableName = names.get(tbIndex).toString();
                   2019:           if (!indexList.isEmpty())
                   2020:           {
                   2021:             IndexList idList = (IndexList) indexList.get(0);
                   2022:             System.out.println("found list " + idList);
                   2023:             Statement stm = beanDest.getConnection().createStatement();
                   2024:             Vector destTables = beanDest.getTableNames();
                   2025:             System.out.println("tempQueryDest" + tempQueryDest);
                   2026:             beanDest.makeQuery(tempQueryDest, 0);
                   2027:             for (Iterator iter = idList.iterator(); iter.hasNext();)
                   2028:             {
                   2029:               String indexField = (String) iter.next();
                   2030:               indexField = convertText(indexField);
                   2031:               String indexName = destTableName + "_" + indexField;
                   2032:               if (destTables.contains(indexName))
                   2033:               {
                   2034:                 stm.execute("DROP  INDEX " + destTableName + "_" + indexField);
                   2035:                 // continue;
                   2036:               }
                   2037:               // stm.execute("DROP INDEX
                   2038:               // "+destTableName+"_"+indexField);
                   2039: 
                   2040:               String type = beanDest.getColumnType(indexField).toLowerCase();
                   2041:               // System.out.println(indexField+" "+type+"
                   2042:               // "+(type.indexOf("text") >= 0 ||
                   2043:               // type.indexOf("varchar") >= 0 || type.indexOf("char")
                   2044:               // >= 0));
                   2045:               if (type.indexOf("text") >= 0 || type.indexOf("varchar") >= 0
                   2046:                   || type.indexOf("char") >= 0)
                   2047:               {
                   2048:                 if (beanDest.url.indexOf("mysql") >= 0)
                   2049:                 {
                   2050:                   // System.out.println("CREATE INDEX " +
                   2051:                   // indexName + " ON " + destTableName + " (" +
                   2052:                   // indexField + "(10))");
                   2053:                   // TODO problem if index exist !!!
                   2054:                   stm.execute("CREATE  INDEX " + indexName + " ON " + destTableName + " ("
                   2055:                       + indexField + "(10))");
                   2056:                 } else
                   2057:                 {
                   2058:                   stm.execute("CREATE  INDEX " + indexName + " ON " + destTableName + " (lower( "
                   2059:                       + indexField + "))");
                   2060: 
                   2061:                 }
                   2062: 
                   2063:               } else
                   2064:               {
                   2065:                 stm.execute("CREATE  INDEX " + destTableName + "_" + indexField + " ON "
                   2066:                     + destTableName + "(" + indexField + ")");
                   2067: 
                   2068:               }
                   2069: 
                   2070:               // stm.execute("DROP INDEX
                   2071:               // "+destTableName+"_"+indexField);
                   2072: 
                   2073:             }
                   2074:           }
                   2075:           // CREATE UNIQUE INDEX title_idx ON films (title);
                   2076:           for (Iterator iter = linesToDelete.iterator(); iter.hasNext();)
                   2077:           {
                   2078:             String id = (String) iter.next();
                   2079:             delPSt.setString(1, id);
                   2080:             delPSt.execute();
                   2081: 
                   2082:           }
                   2083: 
                   2084:           long endTime = System.currentTimeMillis();
                   2085:           System.out.println("Time for incremental synchronize  elapsed " + (endTime - startTime));
                   2086:         } // to idfield if
                   2087:       } // table loop
                   2088: 
                   2089:     } catch (Exception e)
                   2090:     {
                   2091:       System.out.println("Error while connecting to database " + e);
                   2092:       e.printStackTrace();
                   2093:       if (isGUI)
                   2094:         showExceptionDialog(dialog, command, e);
                   2095:     }
                   2096:     if (isGUI)
                   2097:     {
                   2098:       resetGUI(dialog);
                   2099:     }
                   2100:   }
                   2101: 
                   2102:   /**
                   2103:    * @param destQuery
                   2104:    * @param string
                   2105:    * @return
                   2106:    */
                   2107:   private static String removeLayoutPartFromQuery(String destQuery, String layoutName)
                   2108:   {
                   2109:     String removeString = "layout " + beanDest.getQC() + layoutName + beanDest.getQC();
                   2110:     destQuery = destQuery.replaceFirst(removeString, "");
                   2111:     System.out.println("destQuery change to " + destQuery);
                   2112:     return destQuery;
                   2113:   }
                   2114: 
                   2115:   private static void performSynchronize(String idField, Vector vec, String tempQuery,
                   2116:       TreeSet linesToDelete, TreeSet linesToAppend, PreparedStatement insPst,
                   2117:       PreparedStatement updPst, PreparedStatement delPSt, int deltaID, String delimiter,
                   2118:       FM2SQL.ProgressDialog dialog) throws SQLException, ParseException, Exception
                   2119:   {
                   2120:     if (dialog != null)
                   2121:     {
                   2122:       dialog.progress.setValue(0);
                   2123:       dialog.title.setText("Retrieving new data");
                   2124:     }
                   2125: 
                   2126:     Vector[] vectors = bean.getQueryData(tempQuery, deltaID);
                   2127:     int count = 0, size = vectors[0].size();
                   2128:     int idIndex = vectors[1].indexOf(idField);
                   2129:     // System.out.println(idIndex + " " + vectors[1] + " " + idField);
                   2130:     // todo arraylist code has to be added
                   2131:     if (dialog != null)
                   2132:       dialog.title.setText("Synchronize with new data");
                   2133: 
                   2134:     for (Iterator iter = vectors[0].iterator(); iter.hasNext();)
                   2135:     {
                   2136:       Vector line = (Vector) iter.next();
                   2137:       Object lineIDIndex = line.get(idIndex);
                   2138:       if (linesToAppend.contains(lineIDIndex))
                   2139:         System.out.println("line " + linesToAppend.contains(line.get(idIndex)) + " " + lineIDIndex);
                   2140:       if (linesToAppend.contains(lineIDIndex))
                   2141:       {
                   2142:         for (int l = 0; l < line.size(); ++l)
                   2143:         {
                   2144:           Object obj = line.get(l);
                   2145:           if (obj instanceof ArrayList)
                   2146:             obj = formatFileMakerArray((List) obj, delimiter);
                   2147:           if (obj != null)
                   2148:             insPst.setString(l + 1, obj.toString());
                   2149:           else
                   2150:             insPst.setNull(l + 1, Types.NULL);
                   2151:         }
                   2152:         insPst.execute();
                   2153: 
                   2154:       } else
                   2155:       // update
                   2156:       {
                   2157:         for (int l = 0; l < line.size(); ++l)
                   2158:         {
                   2159:           Object obj = line.get(l);
                   2160:           if (obj instanceof ArrayList)
                   2161:             obj = formatFileMakerArray((List) obj, delimiter);
                   2162:           if (obj != null)
                   2163:             updPst.setString(l + 1, obj.toString());
                   2164:           else
                   2165:             updPst.setNull(l + 1, Types.NULL);
                   2166:         }
                   2167:         updPst.setString(line.size() + 1, line.get(idIndex).toString());
                   2168:         // updPst.addBatch();
                   2169:         // updPst.execute();
                   2170:       }
                   2171:       if (dialog != null)
                   2172:       {
                   2173:         int value = (int) Math.round(((double) count / (double) size) * 100.0);
                   2174:         dialog.progress.setValue(value);
                   2175:         count++;
                   2176:       }
                   2177:     }
                   2178:     // updPst.executeBatch();
                   2179:   } // to method
                   2180: 
                   2181:   /**
                   2182:    * Converts input String in norman encoding to unicode
                   2183:    * 
                   2184:    * @param inp
                   2185:    * @return converted String
                   2186:    */
                   2187:   static public String normanToUnicode(String inp)
                   2188:   {
                   2189:     StringBuffer buf = new StringBuffer();
                   2190:     for (int i = 0; i < inp.length(); i++)
                   2191:     {
                   2192:       char c = inp.charAt(i);
                   2193:       // System.out.println("char "+c+" "+(int)c);
                   2194:       switch (c)
                   2195:       {
                   2196:         case 1:
                   2197:           buf.append("\u00d0");
                   2198:           break; // Eth
                   2199:         case 2:
                   2200:           buf.append("\u00f0");
                   2201:           break; // eth
                   2202:         case 3:
                   2203:           buf.append("\u0141");
                   2204:           break; // Lslash
                   2205:         case 4:
                   2206:           buf.append("\u0142");
                   2207:           break; // lslash
                   2208:         case 5:
                   2209:           buf.append("\u0160");
                   2210:           break; // S caron
                   2211:         case 6:
                   2212:           buf.append("\u0161");
                   2213:           break; // s caron
                   2214:         case 7:
                   2215:           buf.append("\u00dd");
                   2216:           break; // Y acute
                   2217:         case 8:
                   2218:           buf.append("\u00fd");
                   2219:           break; // y acute
                   2220:         case 11:
                   2221:           buf.append("\u00de");
                   2222:           break; // Thorn
                   2223:         case 12:
                   2224:           buf.append("\u00fe");
                   2225:           break; // thorn
                   2226:         case 14:
                   2227:           buf.append("\u017d");
                   2228:           break; // Z caron
                   2229:         case 15:
                   2230:           buf.append("\u017e");
                   2231:           break; // z caron
                   2232:         case 17:
                   2233:           buf.append("\u0073");
                   2234:           break; // asciitilde
                   2235:         case 18:
                   2236:           buf.append("j\u0305");
                   2237:           break; // j macron [does a single char exist?]
                   2238:         case 19:
                   2239:           buf.append("^");
                   2240:           break; // circumflex
                   2241:         case 20:
                   2242:           buf.append("\u0303");
                   2243:           break; // tilde
                   2244:         case 21:
                   2245:           buf.append("\u00bd");
                   2246:           break; // onehalf
                   2247:         case 22:
                   2248:           buf.append("\u00bc");
                   2249:           break; // onequarter
                   2250:         case 23:
                   2251:           buf.append("\u00b9");
                   2252:           break; // onesuperior
                   2253:         case 24:
                   2254:           buf.append("\u00be");
                   2255:           break; // threequarters
                   2256:         case 25:
                   2257:           buf.append("\u00b3");
                   2258:           break; // threesuperior
                   2259:         case 26:
                   2260:           buf.append("\u00b2");
                   2261:           break; // twosuperior
                   2262:         case 27:
                   2263:           buf.append("\u00a6");
                   2264:           break; // brokenbar
                   2265:         case 28:
                   2266:           buf.append("-");
                   2267:           break; // minus
                   2268:         case 29:
                   2269:           buf.append("\u00d7");
                   2270:           break; // multiply
                   2271:         case 39:
                   2272:           buf.append("'");
                   2273:           break; // quotesingle
                   2274:         case 94:
                   2275:           buf.append("\u0302");
                   2276:           break; // circumflex
                   2277:         case 96:
                   2278:           buf.append("\u0300");
                   2279:           break; // grave
                   2280:         case 196:
                   2281:           buf.append("\u00c4");
                   2282:           break; // A dieresis
                   2283:         case 197:
                   2284:           buf.append("\u00c5");
                   2285:           break; // A ring
                   2286:         case 201:
                   2287:           buf.append("\u00c9");
                   2288:           break; // E acute
                   2289:         case 209:
                   2290:           buf.append("\u00d1");
                   2291:           break; // N tilde
                   2292:         case 214:
                   2293:           buf.append("\u00d6");
                   2294:           break; // O dieresis
                   2295:         case 220:
                   2296:           buf.append("\u00dc");
                   2297:           break; // U dieresis
                   2298:         case 225:
                   2299:           buf.append("\u00e1");
                   2300:           break; // a acute
                   2301:         case 224:
                   2302:           buf.append("\u00e0");
                   2303:           break; // a grave
                   2304:         case 226:
                   2305:           buf.append("\u00e2");
                   2306:           break; // a circumflex
                   2307:         case 228:
                   2308:           buf.append("\u00e4");
                   2309:           break; // a dieresis
                   2310:         case 227:
                   2311:           buf.append("\u00e3");
                   2312:           break; // a tilde
                   2313:         case 229:
                   2314:           buf.append("\u0101");
                   2315:           break; // a macron
                   2316:         case 231:
                   2317:           buf.append("\u00e7");
                   2318:           break; // c cedilla
                   2319:         case 233:
                   2320:           buf.append("\u00e9");
                   2321:           break; // e acute
                   2322:         case 232:
                   2323:           buf.append("\u00e8");
                   2324:           break; // e grave
                   2325:         case 234:
                   2326:           buf.append("\u00ea");
                   2327:           break; // e circumflex
                   2328:         case 235:
                   2329:           buf.append("\u00eb");
                   2330:           break; // e dieresis
                   2331:         case 237:
                   2332:           buf.append("\u00ed");
                   2333:           break; // i acute
                   2334:         case 236:
                   2335:           buf.append("\u00ec");
                   2336:           break; // i grave
                   2337:         case 238:
                   2338:           buf.append("\u00ee");
                   2339:           break; // i circumflex
                   2340:         case 239:
                   2341:           buf.append("\u00ef");
                   2342:           break; // i dieresis
                   2343:         case 241:
                   2344:           buf.append("\u00f1");
                   2345:           break; // n tilde
                   2346:         case 243:
                   2347:           buf.append("\u00f3");
                   2348:           break; // o acute
                   2349:         case 242:
                   2350:           buf.append("\u00f2");
                   2351:           break; // o grave
                   2352:         case 244:
                   2353:           buf.append("\u00f4");
                   2354:           break; // o circumflex
                   2355:         case 246:
                   2356:           buf.append("\u00f6");
                   2357:           break; // o dieresis
                   2358:         case 245:
                   2359:           buf.append("\u00f5");
                   2360:           break; // o tilde
                   2361:         case 250:
                   2362:           buf.append("\u00fa");
                   2363:           break; // u acute
                   2364:         case 249:
                   2365:           buf.append("\u00f9");
                   2366:           break; // u grave
                   2367:         case 251:
                   2368:           buf.append("\u00fb");
                   2369:           break; // u circumflex
                   2370:         case 252:
                   2371:           buf.append("\u00fc");
                   2372:           break; // u dieresis
                   2373:         case 8224:
                   2374:           buf.append("\u1e6d");
                   2375:           break; // t underdot
                   2376:         case 176:
                   2377:           buf.append("\u00b0");
                   2378:           break; // degree
                   2379:         case 162:
                   2380:           buf.append("\u1ebd");
                   2381:           break; // e tilde
                   2382:         case 163:
                   2383:           buf.append("\u00a3");
                   2384:           break; // sterling
                   2385:         case 167:
                   2386:           buf.append("\u00a7");
                   2387:           break; // section
                   2388:         case 182:
                   2389:           buf.append("\u00b6");
                   2390:           break; // paragraph
                   2391:         case 223:
                   2392:           buf.append("\u015b");
                   2393:           break; // s acute
                   2394:         case 174:
                   2395:           buf.append("\u1e5b");
                   2396:           break; // r underdot
                   2397:         case 169:
                   2398:           buf.append("\u1e45");
                   2399:           break; // n overdot
                   2400:         case 353:
                   2401:           buf.append("\u1e45");
                   2402:           break; // n overdot
                   2403:         case 180:
                   2404:           buf.append("\u0301");
                   2405:           break; // acute
                   2406:         case 168:
                   2407:           buf.append("\u0308");
                   2408:           break; // dieresis
                   2409:         case 8800:
                   2410:           buf.append("\u1e6d");
                   2411:           break; // t underdot
                   2412:         case 198:
                   2413:           buf.append("\u00c6");
                   2414:           break; // AE
                   2415:         case 216:
                   2416:           buf.append("\u014d");
                   2417:           break; // o macron
                   2418:         case 8734:
                   2419:           buf.append("\u0129");
                   2420:           break; // i tilde
                   2421:         case 177:
                   2422:           buf.append("\u00b1");
                   2423:           break; // plusminus
                   2424:         case 165:
                   2425:           buf.append("\u012b");
                   2426:           break; // i macron
                   2427:         case 181:
                   2428:           buf.append("\u1e43");
                   2429:           break; // m underdot
                   2430:         case 8706:
                   2431:           buf.append("\u1e0d");
                   2432:           break; // d underdot
                   2433:         case 240:
                   2434:           buf.append("\u1e0d");
                   2435:           break; // d underdot
                   2436: 
                   2437:         case 8721:
                   2438:           buf.append("\u1e63");
                   2439:           break; // s underdot
                   2440:         case 960:
                   2441:           buf.append("\u017a");
                   2442:           break; // z acute
                   2443:         case 8747:
                   2444:           buf.append("\u1e45");
                   2445:           break; // n overdot
                   2446:         case 937:
                   2447:           buf.append("\u0169");
                   2448:           break; // u tilde
                   2449:         case 230:
                   2450:           buf.append("\u00e6");
                   2451:           break; // ae
                   2452:         case 248:
                   2453:           buf.append("\u00f8");
                   2454:           break; // oslash
                   2455:         case 191:
                   2456:           buf.append("\u0304\u0306");
                   2457:           break; // macron breve
                   2458:         case 172:
                   2459:           buf.append("\u1e37");
                   2460:           break; // 
                   2461:         case 8730:
                   2462:           buf.append("j\u0305");
                   2463:           break; // j macron [does a single char exist?]
                   2464:         case 402:
                   2465:           buf.append("\u0103");
                   2466:           break; // a breve
                   2467:         case 8776:
                   2468:           buf.append("\u016d");
                   2469:           break; // u breve
                   2470:         case 187:
                   2471:           buf.append("\u1e42");
                   2472:           break; // M underdot
                   2473:         case 8230:
                   2474:           buf.append("\u2026");
                   2475:           break; // ellipsis
                   2476:         case 192:
                   2477:           buf.append("\u00c0");
                   2478:           break; // A grave
                   2479:         case 195:
                   2480:           buf.append("\u00c3");
                   2481:           break; // A tilde
                   2482:         case 213:
                   2483:           buf.append("\u00d5");
                   2484:           break; // O tilde
                   2485:         case 338:
                   2486:           buf.append("m\u0306");
                   2487:           break; // m breve
                   2488:         case 339:
                   2489:           buf.append("\u0153");
                   2490:           break; // oe
                   2491:         case 8211:
                   2492:           buf.append("\u2013");
                   2493:           break; // endash
                   2494:         case 8212:
                   2495:           buf.append("\u2014");
                   2496:           break; // emdash
                   2497:         case 8220:
                   2498:           buf.append("\u201c");
                   2499:           break; // quotedblleft
                   2500:         case 8221:
                   2501:           buf.append("\u201d");
                   2502:           break; // quotedblright
                   2503:         case 8216:
                   2504:           buf.append("\u2018");
                   2505:           break; // quoteleft
                   2506:         case 8217:
                   2507:           buf.append("\u2019");
                   2508:           break; // quoteright
                   2509:         case 247:
                   2510:           buf.append("\u1e37");
                   2511:           break; // l underring [actually underdot]
                   2512:         case 9674:
                   2513:           buf.append("\u1e41");
                   2514:           break; // m overdot
                   2515:         case 255:
                   2516:           buf.append("n\u0306");
                   2517:           break; // n breve
                   2518:         case 376:
                   2519:           buf.append("\u00d7");
                   2520:           break; // multiply
                   2521:         case 8364:
                   2522:           buf.append("\u1e5b");
                   2523:           break; // r underring [actually underdot]
                   2524:         case 8249:
                   2525:           buf.append("\u1e44");
                   2526:           break; // N overdot
                   2527:         case 8250:
                   2528:           buf.append("\u1e62");
                   2529:           break; // S underdot
                   2530:         case 64257:
                   2531:           buf.append("\u1e24");
                   2532:           break; // H underdot
                   2533:         case 64258:
                   2534:           buf.append("\u1e0c");
                   2535:           break; // D underdot
                   2536:         case 8225:
                   2537:           buf.append("\u2021");
                   2538:           break; // daggerdbl
                   2539:         case 8218:
                   2540:           buf.append("\u1e36");
                   2541:           break; // L underdot
                   2542:         case 8222:
                   2543:           buf.append("\u0113");
                   2544:           break; // e macron
                   2545:         case 194:
                   2546:           buf.append("\u1e5f");
                   2547:           break; // r underbar
                   2548:         case 202:
                   2549:           buf.append("r\u0324");
                   2550:           break; // r underdieresis
                   2551:         case 193:
                   2552:           buf.append("\u012a");
                   2553:           break; // I macron
                   2554:         case 8486:
                   2555:         case 203:
                   2556:           buf.append("\u016b");
                   2557:           break; // u macron
                   2558:         case 200:
                   2559:           buf.append("\u1e6c");
                   2560:           break; // T underdot
                   2561:         case 205:
                   2562:           buf.append("\u1e64");
                   2563:           break; // S acute
                   2564:         case 206:
                   2565:           buf.append("\u2020");
                   2566:           break; // dagger
                   2567:         case 207:
                   2568:           buf.append("\u0115");
                   2569:           break; // e breve
                   2570:         case 204:
                   2571:           buf.append("\u014f");
                   2572:           break; // o breve
                   2573:         case 211:
                   2574:           buf.append("\u0100");
                   2575:           break; // A macron
                   2576:         case 212:
                   2577:           buf.append("\u1e46");
                   2578:           break; // N underdot
                   2579:         case 210:
                   2580:           buf.append("\u1e3b");
                   2581:           break; // l underbar
                   2582:         case 218:
                   2583:           buf.append("\u016a");
                   2584:           break; // U macron
                   2585:         case 219:
                   2586:           buf.append("\u0179");
                   2587:           break; // Z acute
                   2588:         case 217:
                   2589:           buf.append("\u1e5a");
                   2590:           break; // R underdot
                   2591:         case 305:
                   2592:           buf.append("\u0131");
                   2593:           break; // dotlessi
                   2594:         case 710:
                   2595:           buf.append("\u1e47");
                   2596:           break; // n underdot
                   2597:         case 732:
                   2598:           buf.append("\u1e49");
                   2599:           break; // n underbar
                   2600:         case 175:
                   2601:           buf.append("\u0304");
                   2602:           break; // macron
                   2603:         case 728:
                   2604:           buf.append("\u0306");
                   2605:           break; // breve
                   2606:         case 729:
                   2607:         case 215:
                   2608:           buf.append("\u1e25");
                   2609:           break; // h underdot
                   2610:         case 730:
                   2611:           buf.append("\u012d");
                   2612:           break; // i breve
                   2613:         case 184:
                   2614:           buf.append("\u0327");
                   2615:           break; // cedilla
                   2616:         case 733:
                   2617:           buf.append("\u030b");
                   2618:           break; // hungarumlaut
                   2619:         case 731:
                   2620:           buf.append("\u0328");
                   2621:           break; // ogonek
                   2622:         case 711:
                   2623:           buf.append("\u030c");
                   2624:           break; // caron
                   2625:         case 199:
                   2626:           buf.append("\u012b\u0303");
                   2627:           break; // imacron tilde
                   2628:         case 8226:
                   2629:           buf.append("\u1e5d");
                   2630:           break; // runderdot macron
                   2631:         case 8482:
                   2632:           buf.append("\u016b\0306");
                   2633:           break; // umacron breve
                   2634:         case 8804:
                   2635:           buf.append("\u0101\u0301");
                   2636:           break; // amacron acute
                   2637:         case 8805:
                   2638:           buf.append("\u016b\u0301");
                   2639:           break; // umacron acute
                   2640:         case 8719:
                   2641:           buf.append("\u0113\u0301");
                   2642:           break; // emacron acute
                   2643:         case 170:
                   2644:           buf.append("\u0113\u0300");
                   2645:           break; // emacron breve
                   2646:         case 186:
                   2647:           buf.append("\u014d\u0300");
                   2648:           break; // omacron breve
                   2649:         case 161:
                   2650:           buf.append("\u0101\u0306");
                   2651:           break; // amacron breve
                   2652:         case 8710:
                   2653:           buf.append("\u0101\u0303");
                   2654:           break; // amacron tilde
                   2655:         case 171:
                   2656:           buf.append("\u012b\u0301");
                   2657:           break; // imacron acute
                   2658:         case 8260:
                   2659:           buf.append("\u1e00");
                   2660:           break; // runderdotmacron acute
                   2661:         case 183:
                   2662:           buf.append("\u1e5b\u0301");
                   2663:           break; // runderdot acute
                   2664:         case 8240:
                   2665:           buf.append("\u012b\u0306");
                   2666:           break; // imacron breve
                   2667:         case 63743:
                   2668:           buf.append("\u016b\u0303");
                   2669:           break; // umacron tilde
                   2670:         default:
                   2671:           buf.append(c);
                   2672:           if ((int) c > 127)
                   2673:             System.out.println("char " + c + " " + (int) c);
                   2674:           break;
                   2675:       }
                   2676:     }
                   2677:     return buf.toString();
                   2678:   }
                   2679: 
                   2680:   static public String normanToUnicodeOld(String inp)
                   2681:   {
                   2682:     StringBuffer buf = new StringBuffer();
                   2683:     for (int i = 0; i < inp.length(); i++)
                   2684:     {
                   2685:       char c = inp.charAt(i);
                   2686:       switch (c)
                   2687:       {
                   2688:         case 1:
                   2689:           buf.append("\u00d0");
                   2690:           break; // Eth
                   2691:         case 2:
                   2692:           buf.append("\u00f0");
                   2693:           break; // eth
                   2694:         case 3:
                   2695:           buf.append("\u0141");
                   2696:           break; // Lslash
                   2697:         case 4:
                   2698:           buf.append("\u0142");
                   2699:           break; // lslash
                   2700:         case 5:
                   2701:           buf.append("\u0160");
                   2702:           break; // S caron
                   2703:         case 6:
                   2704:           buf.append("\u0161");
                   2705:           break; // s caron
                   2706:         case 7:
                   2707:           buf.append("\u00dd");
                   2708:           break; // Y acute
                   2709:         case 8:
                   2710:           buf.append("\u00fd");
                   2711:           break; // y acute
                   2712:         case 11:
                   2713:           buf.append("\u00de");
                   2714:           break; // Thorn
                   2715:         case 12:
                   2716:           buf.append("\u00fe");
                   2717:           break; // thorn
                   2718:         case 14:
                   2719:           buf.append("\u017d");
                   2720:           break; // Z caron
                   2721:         case 15:
                   2722:           buf.append("\u017e");
                   2723:           break; // z caron
                   2724:         case 17:
                   2725:           buf.append("\u0073");
                   2726:           break; // asciitilde
                   2727:         case 18:
                   2728:           buf.append("j\u0305");
                   2729:           break; // j macron [does a single char exist?]
                   2730:         case 19:
                   2731:           buf.append("^");
                   2732:           break; // circumflex
                   2733:         case 20:
                   2734:           buf.append("\u0303");
                   2735:           break; // tilde
                   2736:         case 21:
                   2737:           buf.append("\u00bd");
                   2738:           break; // onehalf
                   2739:         case 22:
                   2740:           buf.append("\u00bc");
                   2741:           break; // onequarter
                   2742:         case 23:
                   2743:           buf.append("\u00b9");
                   2744:           break; // onesuperior
                   2745:         case 24:
                   2746:           buf.append("\u00be");
                   2747:           break; // threequarters
                   2748:         case 25:
                   2749:           buf.append("\u00b3");
                   2750:           break; // threesuperior
                   2751:         case 26:
                   2752:           buf.append("\u00b2");
                   2753:           break; // twosuperior
                   2754:         case 27:
                   2755:           buf.append("\u00a6");
                   2756:           break; // brokenbar
                   2757:         case 28:
                   2758:           buf.append("-");
                   2759:           break; // minus
                   2760:         case 29:
                   2761:           buf.append("\u00d7");
                   2762:           break; // multiply
                   2763:         case 39:
                   2764:           buf.append("'");
                   2765:           break; // quotesingle
                   2766:         case 94:
                   2767:           buf.append("\u0302");
                   2768:           break; // circumflex
                   2769:         case 96:
                   2770:           buf.append("\u0300");
                   2771:           break; // grave
                   2772:         case 128:
                   2773:           buf.append("\u00c4");
                   2774:           break; // A dieresis
                   2775:         case 129:
                   2776:           buf.append("\u00c5");
                   2777:           break; // A ring
                   2778:         case 131:
                   2779:           buf.append("\u00c9");
                   2780:           break; // E acute
                   2781:         case 132:
                   2782:           buf.append("\u00d1");
                   2783:           break; // N tilde
                   2784:         case 133:
                   2785:           buf.append("\u00d6");
                   2786:           break; // O dieresis
                   2787:         case 134:
                   2788:           buf.append("\u00dc");
                   2789:           break; // U dieresis
                   2790:         case 135:
                   2791:           buf.append("\u00e1");
                   2792:           break; // a acute
                   2793:         case 136:
                   2794:           buf.append("\u00e0");
                   2795:           break; // a grave
                   2796:         case 137:
                   2797:           buf.append("\u00e2");
                   2798:           break; // a circumflex
                   2799:         case 138:
                   2800:           buf.append("\u00e4");
                   2801:           break; // a dieresis
                   2802:         case 139:
                   2803:           buf.append("\u00e3");
                   2804:           break; // a tilde
                   2805:         case 140:
                   2806:           buf.append("\u0101");
                   2807:           break; // a macron
                   2808:         case 141:
                   2809:           buf.append("\u00e7");
                   2810:           break; // c cedilla
                   2811:         case 142:
                   2812:           buf.append("\u00e9");
                   2813:           break; // e acute
                   2814:         case 143:
                   2815:           buf.append("\u00e8");
                   2816:           break; // e grave
                   2817:         case 144:
                   2818:           buf.append("\u00ea");
                   2819:           break; // e circumflex
                   2820:         case 145:
                   2821:           buf.append("\u00eb");
                   2822:           break; // e dieresis
                   2823:         case 146:
                   2824:           buf.append("\u00ed");
                   2825:           break; // i acute
                   2826:         case 147:
                   2827:           buf.append("\u00ec");
                   2828:           break; // i grave
                   2829:         case 148:
                   2830:           buf.append("\u00ee");
                   2831:           break; // i circumflex
                   2832:         case 149:
                   2833:           buf.append("\u00ef");
                   2834:           break; // i dieresis
                   2835:         case 150:
                   2836:           buf.append("\u00f1");
                   2837:           break; // n tilde
                   2838:         case 151:
                   2839:           buf.append("\u00f3");
                   2840:           break; // o acute
                   2841:         case 152:
                   2842:           buf.append("\u00f2");
                   2843:           break; // o grave
                   2844:         case 153:
                   2845:           buf.append("\u00f4");
                   2846:           break; // o circumflex
                   2847:         case 154:
                   2848:           buf.append("\u00f6");
                   2849:           break; // o dieresis
                   2850:         case 155:
                   2851:           buf.append("\u00f5");
                   2852:           break; // o tilde
                   2853:         case 156:
                   2854:           buf.append("\u00fa");
                   2855:           break; // u acute
                   2856:         case 157:
                   2857:           buf.append("\u00f9");
                   2858:           break; // u grave
                   2859:         case 158:
                   2860:           buf.append("\u00fb");
                   2861:           break; // u circumflex
                   2862:         case 159:
                   2863:           buf.append("\u00fc");
                   2864:           break; // u dieresis
                   2865:         case 160:
                   2866:           buf.append("\u1e6d");
                   2867:           break; // t underdot
                   2868:         case 161:
                   2869:           buf.append("\u00b0");
                   2870:           break; // degree
                   2871:         case 162:
                   2872:           buf.append("\u1ebd");
                   2873:           break; // e tilde
                   2874:         case 163:
                   2875:           buf.append("\u00a3");
                   2876:           break; // sterling
                   2877:         case 164:
                   2878:           buf.append("\u00a7");
                   2879:           break; // section
                   2880:         case 166:
                   2881:           buf.append("\u00b6");
                   2882:           break; // paragraph
                   2883:         case 167:
                   2884:           buf.append("\u015b");
                   2885:           break; // s acute
                   2886:         case 168:
                   2887:           buf.append("\u1e5b");
                   2888:           break; // r underdot
                   2889:         case 169:
                   2890:           buf.append("\u1e67");
                   2891:           break; // s caron
                   2892:         case 171:
                   2893:           buf.append("\u0301");
                   2894:           break; // acute
                   2895:         case 172:
                   2896:           buf.append("\u0308");
                   2897:           break; // dieresis
                   2898:         case 173:
                   2899:           buf.append("\u1e6d");
                   2900:           break; // t underdot
                   2901:         case 174:
                   2902:           buf.append("\u00c6");
                   2903:           break; // AE
                   2904:         case 175:
                   2905:           buf.append("\u014d");
                   2906:           break; // o macron
                   2907:         case 176:
                   2908:           buf.append("\u0129");
                   2909:           break; // i tilde
                   2910:         case 177:
                   2911:           buf.append("\u00b1");
                   2912:           break; // plusminus
                   2913:         case 180:
                   2914:           buf.append("\u012b");
                   2915:           break; // i macron
                   2916:         case 181:
                   2917:           buf.append("\u1e43");
                   2918:           break; // m underdot
                   2919:         case 182:
                   2920:           buf.append("\u1e0d");
                   2921:           break; // d underdot
                   2922:         case 183:
                   2923:           buf.append("\u1e63");
                   2924:           break; // s underdot
                   2925:         case 185:
                   2926:           buf.append("\u017a");
                   2927:           break; // z acute
                   2928:         case 186:
                   2929:           buf.append("\u1e45");
                   2930:           break; // n overdot
                   2931:         case 189:
                   2932:           buf.append("\u0169");
                   2933:           break; // u tilde
                   2934:         case 190:
                   2935:           buf.append("\u00e6");
                   2936:           break; // ae
                   2937:         case 191:
                   2938:           buf.append("\u00f8");
                   2939:           break; // oslash
                   2940:         case 192:
                   2941:           buf.append("\u0304\u0306");
                   2942:           break; // macron breve
                   2943:         case 194:
                   2944:           buf.append("\u1e37");
                   2945:           break; // 
                   2946:         case 195:
                   2947:           buf.append("j\u0305");
                   2948:           break; // j macron [does a single char exist?]
                   2949:         case 196:
                   2950:           buf.append("\u0103");
                   2951:           break; // a breve
                   2952:         case 197:
                   2953:           buf.append("\u016d");
                   2954:           break; // u breve
                   2955:         case 200:
                   2956:           buf.append("\u1e42");
                   2957:           break; // M underdot
                   2958:         case 201:
                   2959:           buf.append("\u2026");
                   2960:           break; // ellipsis
                   2961:         case 203:
                   2962:           buf.append("\u00c0");
                   2963:           break; // A grave
                   2964:         case 204:
                   2965:           buf.append("\u00c3");
                   2966:           break; // A tilde
                   2967:         case 205:
                   2968:           buf.append("\u00d5");
                   2969:           break; // O tilde
                   2970:         case 206:
                   2971:           buf.append("m\u0306");
                   2972:           break; // m breve
                   2973:         case 207:
                   2974:           buf.append("\u0153");
                   2975:           break; // oe
                   2976:         case 208:
                   2977:           buf.append("\u2013");
                   2978:           break; // endash
                   2979:         case 209:
                   2980:           buf.append("\u2014");
                   2981:           break; // emdash
                   2982:         case 210:
                   2983:           buf.append("\u201c");
                   2984:           break; // quotedblleft
                   2985:         case 211:
                   2986:           buf.append("\u201d");
                   2987:           break; // quotedblright
                   2988:         case 212:
                   2989:           buf.append("\u2018");
                   2990:           break; // quoteleft
                   2991:         case 213:
                   2992:           buf.append("\u2019");
                   2993:           break; // quoteright
                   2994:         case 214:
                   2995:           buf.append("\u1e37");
                   2996:           break; // l underring [actually underdot]
                   2997:         case 215:
                   2998:           buf.append("\u1e41");
                   2999:           break; // m overdot
                   3000:         case 216:
                   3001:           buf.append("n\u0306");
                   3002:           break; // n breve
                   3003:         case 217:
                   3004:           buf.append("\u00d7");
                   3005:           break; // multiply
                   3006:         case 219:
                   3007:           buf.append("\u1e5b");
                   3008:           break; // r underring [actually underdot]
                   3009:         case 220:
                   3010:           buf.append("\u1e44");
                   3011:           break; // N overdot
                   3012:         case 221:
                   3013:           buf.append("\u1e62");
                   3014:           break; // S underdot
                   3015:         case 222:
                   3016:           buf.append("\u1e24");
                   3017:           break; // H underdot
                   3018:         case 223:
                   3019:           buf.append("\u1e0c");
                   3020:           break; // D underdot
                   3021:         case 224:
                   3022:           buf.append("\u2021");
                   3023:           break; // daggerdbl
                   3024:         case 226:
                   3025:           buf.append("\u1e36");
                   3026:           break; // L underdot
                   3027:         case 227:
                   3028:           buf.append("\u0113");
                   3029:           break; // e macron
                   3030:         case 229:
                   3031:           buf.append("\u1e5f");
                   3032:           break; // r underbar
                   3033:         case 230:
                   3034:           buf.append("r\u0324");
                   3035:           break; // r underdieresis
                   3036:         case 231:
                   3037:           buf.append("\u012a");
                   3038:           break; // I macron
                   3039:         case 232:
                   3040:           buf.append("\u016b");
                   3041:           break; // u macron
                   3042:         case 233:
                   3043:           buf.append("\u01e6c");
                   3044:           break; // T underdot
                   3045:         case 234:
                   3046:           buf.append("\u1e64");
                   3047:           break; // S acute
                   3048:         case 235:
                   3049:           buf.append("\u2020");
                   3050:           break; // dagger
                   3051:         case 236:
                   3052:           buf.append("\u0115");
                   3053:           break; // e breve
                   3054:         case 237:
                   3055:           buf.append("\u014f");
                   3056:           break; // o breve
                   3057:         case 238:
                   3058:           buf.append("\u0100");
                   3059:           break; // A macron
                   3060:         case 239:
                   3061:           buf.append("\u1e46");
                   3062:           break; // N underdot
                   3063:         case 241:
                   3064:           buf.append("\u1e3b");
                   3065:           break; // l underbar
                   3066:         case 242:
                   3067:           buf.append("\u016a");
                   3068:           break; // U macron
                   3069:         case 243:
                   3070:           buf.append("\u0179");
                   3071:           break; // Z acute
                   3072:         case 244:
                   3073:           buf.append("\u1e5a");
                   3074:           break; // R underdot
                   3075:         case 245:
                   3076:           buf.append("\u0131");
                   3077:           break; // dotlessi
                   3078:         case 246:
                   3079:           buf.append("\u1e47");
                   3080:           break; // n underdot
                   3081:         case 247:
                   3082:           buf.append("\u1e49");
                   3083:           break; // n underbar
                   3084:         case 248:
                   3085:           buf.append("\u0304");
                   3086:           break; // macron
                   3087:         case 249:
                   3088:           buf.append("\u0306");
                   3089:           break; // breve
                   3090:         case 250:
                   3091:           buf.append("\u1e25");
                   3092:           break; // h underdot
                   3093:         case 251:
                   3094:           buf.append("\u012d");
                   3095:           break; // i breve
                   3096:         case 252:
                   3097:           buf.append("\u0327");
                   3098:           break; // cedilla
                   3099:         case 253:
                   3100:           buf.append("\u030b");
                   3101:           break; // hungarumlaut
                   3102:         case 254:
                   3103:           buf.append("\u0328");
                   3104:           break; // ogonek
                   3105:         case 255:
                   3106:           buf.append("\u030c");
                   3107:           break; // caron
                   3108:         case 130:
                   3109:           buf.append("\u012b\u0303");
                   3110:           break; // imacron tilde
                   3111:         case 165:
                   3112:           buf.append("\u1e5d");
                   3113:           break; // runderdot macron
                   3114:         case 170:
                   3115:           buf.append("\u016b\0306");
                   3116:           break; // umacron breve
                   3117:         case 178:
                   3118:           buf.append("\u0101\u0301");
                   3119:           break; // amacron acute
                   3120:         case 179:
                   3121:           buf.append("\u016b\u0301");
                   3122:           break; // umacron acute
                   3123:         case 184:
                   3124:           buf.append("\u0113\u0301");
                   3125:           break; // emacron acute
                   3126:         case 187:
                   3127:           buf.append("\u0113\u0300");
                   3128:           break; // emacron breve
                   3129:         case 188:
                   3130:           buf.append("\u014d\u0300");
                   3131:           break; // omacron breve
                   3132:         case 193:
                   3133:           buf.append("\u0101\u0306");
                   3134:           break; // amacron breve
                   3135:         case 198:
                   3136:           buf.append("\u0101\u0303");
                   3137:           break; // amacron tilde
                   3138:         case 199:
                   3139:           buf.append("\u012b\u0301");
                   3140:           break; // imacron acute
                   3141:         case 218:
                   3142:           buf.append("\u1e00");
                   3143:           break; // runderdotmacron acute
                   3144:         case 225:
                   3145:           buf.append("\u1e5b\u0301");
                   3146:           break; // runderdot acute
                   3147:         case 228:
                   3148:           buf.append("\u012b\u0306");
                   3149:           break; // imacron breve
                   3150:         case 240:
                   3151:           buf.append("\u016b\u0303");
                   3152:           break; // umacron tilde
                   3153:         default:
                   3154:           buf.append(c);
                   3155:           break;
                   3156:       }
                   3157:     }
                   3158:     return buf.toString();
                   3159:   }
                   3160: 
                   3161:   static public String normanToUnicodeNew(String inp)
                   3162:   {
                   3163:     StringBuffer buf = new StringBuffer();
                   3164:     for (int i = 0; i < inp.length(); i++)
                   3165:     {
                   3166:       char c = inp.charAt(i);
                   3167:       switch (c)
                   3168:       {
                   3169:         case 1:
                   3170:           buf.append("\u00d0");
                   3171:           break; // Eth
                   3172:         case 2:
                   3173:           buf.append("\u00f0");
                   3174:           break; // eth
                   3175:         case 3:
                   3176:           buf.append("\u0141");
                   3177:           break; // Lslash
                   3178:         case 4:
                   3179:           buf.append("\u0142");
                   3180:           break; // lslash
                   3181:         case 5:
                   3182:           buf.append("\u0160");
                   3183:           break; // S caron
                   3184:         case 6:
                   3185:           buf.append("\u0161");
                   3186:           break; // s caron
                   3187:         case 7:
                   3188:           buf.append("\u00dd");
                   3189:           break; // Y acute
                   3190:         case 8:
                   3191:           buf.append("\u00fd");
                   3192:           break; // y acute
                   3193:         case 11:
                   3194:           buf.append("\u00de");
                   3195:           break; // Thorn
                   3196:         case 12:
                   3197:           buf.append("\u00fe");
                   3198:           break; // thorn
                   3199:         case 14:
                   3200:           buf.append("\u017d");
                   3201:           break; // Z caron
                   3202:         case 15:
                   3203:           buf.append("\u017e");
                   3204:           break; // z caron
                   3205:         case 17:
                   3206:           buf.append("\u0073");
                   3207:           break; // asciitilde
                   3208:         case 18:
                   3209:           buf.append("j\u0305");
                   3210:           break; // j macron [does a single char exist?]
                   3211:         case 19:
                   3212:           buf.append("^");
                   3213:           break; // circumflex
                   3214:         case 20:
                   3215:           buf.append("\u0303");
                   3216:           break; // tilde
                   3217:         case 21:
                   3218:           buf.append("\u00bd");
                   3219:           break; // onehalf
                   3220:         case 22:
                   3221:           buf.append("\u00bc");
                   3222:           break; // onequarter
                   3223:         case 23:
                   3224:           buf.append("\u00b9");
                   3225:           break; // onesuperior
                   3226:         case 24:
                   3227:           buf.append("\u00be");
                   3228:           break; // threequarters
                   3229:         case 25:
                   3230:           buf.append("\u00b3");
                   3231:           break; // threesuperior
                   3232:         case 26:
                   3233:           buf.append("\u00b2");
                   3234:           break; // twosuperior
                   3235:         case 27:
                   3236:           buf.append("\u00a6");
                   3237:           break; // brokenbar
                   3238:         case 28:
                   3239:           buf.append("-");
                   3240:           break; // minus
                   3241:         case 29:
                   3242:           buf.append("\u00d7");
                   3243:           break; // multiply
                   3244:         case 39:
                   3245:           buf.append("'");
                   3246:           break; // quotesingle
                   3247:         case 94:
                   3248:           buf.append("\u0302");
                   3249:           break; // circumflex
                   3250:         case 96:
                   3251:           buf.append("\u0300");
                   3252:           break; // grave
                   3253:         case 196:
                   3254:           buf.append("\u00c4");
                   3255:           break; // A dieresis
                   3256:         case 197:
                   3257:           buf.append("\u00c5");
                   3258:           break; // A ring
                   3259:         case 201:
                   3260:           buf.append("\u00c9");
                   3261:           break; // E acute
                   3262:         case 209:
                   3263:           buf.append("\u00d1");
                   3264:           break; // N tilde
                   3265:         case 214:
                   3266:           buf.append("\u00d6");
                   3267:           break; // O dieresis
                   3268:         case 220:
                   3269:           buf.append("\u00dc");
                   3270:           break; // U dieresis
                   3271:         case 225:
                   3272:           buf.append("\u00e1");
                   3273:           break; // a acute
                   3274:         case 224:
                   3275:           buf.append("\u00e0");
                   3276:           break; // a grave
                   3277:         case 226:
                   3278:           buf.append("\u00e2");
                   3279:           break; // a circumflex
                   3280:         case 228:
                   3281:           buf.append("\u00e4");
                   3282:           break; // a dieresis
                   3283:         case 227:
                   3284:           buf.append("\u00e3");
                   3285:           break; // a tilde
                   3286:         case 229:
                   3287:           buf.append("\u0101");
                   3288:           break; // a macron
                   3289:         case 231:
                   3290:           buf.append("\u00e7");
                   3291:           break; // c cedilla
                   3292:         case 233:
                   3293:           buf.append("\u00e9");
                   3294:           break; // e acute
                   3295:         case 232:
                   3296:           buf.append("\u00e8");
                   3297:           break; // e grave
                   3298:         case 234:
                   3299:           buf.append("\u00ea");
                   3300:           break; // e circumflex
                   3301:         case 235:
                   3302:           buf.append("\u00eb");
                   3303:           break; // e dieresis
                   3304:         case 237:
                   3305:           buf.append("\u00ed");
                   3306:           break; // i acute
                   3307:         case 236:
                   3308:           buf.append("\u00ec");
                   3309:           break; // i grave
                   3310:         case 238:
                   3311:           buf.append("\u00ee");
                   3312:           break; // i circumflex
                   3313:         case 239:
                   3314:           buf.append("\u00ef");
                   3315:           break; // i dieresis
                   3316:         case 241:
                   3317:           buf.append("\u00f1");
                   3318:           break; // n tilde
                   3319:         case 243:
                   3320:           buf.append("\u00f3");
                   3321:           break; // o acute
                   3322:         case 242:
                   3323:           buf.append("\u00f2");
                   3324:           break; // o grave
                   3325:         case 244:
                   3326:           buf.append("\u00f4");
                   3327:           break; // o circumflex
                   3328:         case 246:
                   3329:           buf.append("\u00f6");
                   3330:           break; // o dieresis
                   3331:         case 245:
                   3332:           buf.append("\u00f5");
                   3333:           break; // o tilde
                   3334:         case 250:
                   3335:           buf.append("\u00fa");
                   3336:           break; // u acute
                   3337:         case 249:
                   3338:           buf.append("\u00f9");
                   3339:           break; // u grave
                   3340:         case 251:
                   3341:           buf.append("\u00fb");
                   3342:           break; // u circumflex
                   3343:         case 252:
                   3344:           buf.append("\u00fc");
                   3345:           break; // u dieresis
                   3346:         case 8224:
                   3347:           buf.append("\u1e6d");
                   3348:           break; // t underdot
                   3349:         case 176:
                   3350:           buf.append("\u00b0");
                   3351:           break; // degree
                   3352:         case 162:
                   3353:           buf.append("\u1ebd");
                   3354:           break; // e tilde
                   3355:         case 163:
                   3356:           buf.append("\u00a3");
                   3357:           break; // sterling
                   3358:         case 167:
                   3359:           buf.append("\u00a7");
                   3360:           break; // section
                   3361:         case 182:
                   3362:           buf.append("\u00b6");
                   3363:           break; // paragraph
                   3364:         case 223:
                   3365:           buf.append("\u015b");
                   3366:           break; // s acute
                   3367:         case 174:
                   3368:           buf.append("\u1e5b");
                   3369:           break; // r underdot
                   3370:         case 169:
                   3371:           buf.append("\u1e45");
                   3372:           break; // n overdot
                   3373:         case 180:
                   3374:           buf.append("\u0301");
                   3375:           break; // acute
                   3376:         case 168:
                   3377:           buf.append("\u0308");
                   3378:           break; // dieresis
                   3379:         case 8800:
                   3380:           buf.append("\u1e6d");
                   3381:           break; // t underdot
                   3382:         case 198:
                   3383:           buf.append("\u00c6");
                   3384:           break; // AE
                   3385:         case 216:
                   3386:           buf.append("\u014d");
                   3387:           break; // o macron
                   3388:         case 8734:
                   3389:           buf.append("\u0129");
                   3390:           break; // i tilde
                   3391:         case 177:
                   3392:           buf.append("\u00b1");
                   3393:           break; // plusminus
                   3394:         case 165:
                   3395:           buf.append("\u012b");
                   3396:           break; // i macron
                   3397:         case 181:
                   3398:           buf.append("\u1e43");
                   3399:           break; // m underdot
                   3400:         case 8706:
                   3401:           buf.append("\u1e0d");
                   3402:           break; // d underdot
                   3403:         case 8721:
                   3404:           buf.append("\u1e63");
                   3405:           break; // s underdot
                   3406:         case 960:
                   3407:           buf.append("\u017a");
                   3408:           break; // z acute
                   3409:         case 8747:
                   3410:           buf.append("\u1e45");
                   3411:           break; // n overdot
                   3412:         case 937:
                   3413:           buf.append("\u0169");
                   3414:           break; // u tilde
                   3415:         case 230:
                   3416:           buf.append("\u00e6");
                   3417:           break; // ae
                   3418:         case 248:
                   3419:           buf.append("\u00f8");
                   3420:           break; // oslash
                   3421:         case 191:
                   3422:           buf.append("\u0304\u0306");
                   3423:           break; // macron breve
                   3424:         case 172:
                   3425:           buf.append("\u1e37");
                   3426:           break; // 
                   3427:         case 8730:
                   3428:           buf.append("j\u0305");
                   3429:           break; // j macron [does a single char exist?]
                   3430:         case 402:
                   3431:           buf.append("\u0103");
                   3432:           break; // a breve
                   3433:         case 8776:
                   3434:           buf.append("\u016d");
                   3435:           break; // u breve
                   3436:         case 187:
                   3437:           buf.append("\u1e42");
                   3438:           break; // M underdot
                   3439:         case 8230:
                   3440:           buf.append("\u2026");
                   3441:           break; // ellipsis
                   3442:         case 192:
                   3443:           buf.append("\u00c0");
                   3444:           break; // A grave
                   3445:         case 195:
                   3446:           buf.append("\u00c3");
                   3447:           break; // A tilde
                   3448:         case 213:
                   3449:           buf.append("\u00d5");
                   3450:           break; // O tilde
                   3451:         case 338:
                   3452:           buf.append("m\u0306");
                   3453:           break; // m breve
                   3454:         case 339:
                   3455:           buf.append("\u0153");
                   3456:           break; // oe
                   3457:         case 8211:
                   3458:           buf.append("\u2013");
                   3459:           break; // endash
                   3460:         case 8212:
                   3461:           buf.append("\u2014");
                   3462:           break; // emdash
                   3463:         case 8220:
                   3464:           buf.append("\u201c");
                   3465:           break; // quotedblleft
                   3466:         case 8221:
                   3467:           buf.append("\u201d");
                   3468:           break; // quotedblright
                   3469:         case 8216:
                   3470:           buf.append("\u2018");
                   3471:           break; // quoteleft
                   3472:         case 8217:
                   3473:           buf.append("\u2019");
                   3474:           break; // quoteright
                   3475:         case 247:
                   3476:           buf.append("\u1e37");
                   3477:           break; // l underring [actually underdot]
                   3478:         case 9674:
                   3479:           buf.append("\u1e41");
                   3480:           break; // m overdot
                   3481:         case 255:
                   3482:           buf.append("n\u0306");
                   3483:           break; // n breve
                   3484:         case 376:
                   3485:           buf.append("\u00d7");
                   3486:           break; // multiply
                   3487:         case 8364:
                   3488:           buf.append("\u1e5b");
                   3489:           break; // r underring [actually underdot]
                   3490:         case 8249:
                   3491:           buf.append("\u1e44");
                   3492:           break; // N overdot
                   3493:         case 8250:
                   3494:           buf.append("\u1e62");
                   3495:           break; // S underdot
                   3496:         case 64257:
                   3497:           buf.append("\u1e24");
                   3498:           break; // H underdot
                   3499:         case 64258:
                   3500:           buf.append("\u1e0c");
                   3501:           break; // D underdot
                   3502:         case 8225:
                   3503:           buf.append("\u2021");
                   3504:           break; // daggerdbl
                   3505:         case 8218:
                   3506:           buf.append("\u1e36");
                   3507:           break; // L underdot
                   3508:         case 8222:
                   3509:           buf.append("\u0113");
                   3510:           break; // e macron
                   3511:         case 194:
                   3512:           buf.append("\u1e5f");
                   3513:           break; // r underbar
                   3514:         case 202:
                   3515:           buf.append("r\u0324");
                   3516:           break; // r underdieresis
                   3517:         case 193:
                   3518:           buf.append("\u012a");
                   3519:           break; // I macron
                   3520:         case 203:
                   3521:           buf.append("\u016b");
                   3522:           break; // u macron
                   3523:         case 200:
                   3524:           buf.append("\u1e6c");
                   3525:           break; // T underdot
                   3526:         case 205:
                   3527:           buf.append("\u1e64");
                   3528:           break; // S acute
                   3529:         case 206:
                   3530:           buf.append("\u2020");
                   3531:           break; // dagger
                   3532:         case 207:
                   3533:           buf.append("\u0115");
                   3534:           break; // e breve
                   3535:         case 204:
                   3536:           buf.append("\u014f");
                   3537:           break; // o breve
                   3538:         case 211:
                   3539:           buf.append("\u0100");
                   3540:           break; // A macron
                   3541:         case 212:
                   3542:           buf.append("\u1e46");
                   3543:           break; // N underdot
                   3544:         case 210:
                   3545:           buf.append("\u1e3b");
                   3546:           break; // l underbar
                   3547:         case 218:
                   3548:           buf.append("\u016a");
                   3549:           break; // U macron
                   3550:         case 219:
                   3551:           buf.append("\u0179");
                   3552:           break; // Z acute
                   3553:         case 217:
                   3554:           buf.append("\u1e5a");
                   3555:           break; // R underdot
                   3556:         case 305:
                   3557:           buf.append("\u0131");
                   3558:           break; // dotlessi
                   3559:         case 710:
                   3560:           buf.append("\u1e47");
                   3561:           break; // n underdot
                   3562:         case 732:
                   3563:           buf.append("\u1e49");
                   3564:           break; // n underbar
                   3565:         case 175:
                   3566:           buf.append("\u0304");
                   3567:           break; // macron
                   3568:         case 728:
                   3569:           buf.append("\u0306");
                   3570:           break; // breve
                   3571:         case 729:
                   3572:           buf.append("\u1e25");
                   3573:           break; // h underdot
                   3574:         case 730:
                   3575:           buf.append("\u012d");
                   3576:           break; // i breve
                   3577:         case 184:
                   3578:           buf.append("\u0327");
                   3579:           break; // cedilla
                   3580:         case 733:
                   3581:           buf.append("\u030b");
                   3582:           break; // hungarumlaut
                   3583:         case 731:
                   3584:           buf.append("\u0328");
                   3585:           break; // ogonek
                   3586:         case 711:
                   3587:           buf.append("\u030c");
                   3588:           break; // caron
                   3589:         case 199:
                   3590:           buf.append("\u012b\u0303");
                   3591:           break; // imacron tilde
                   3592:         case 8226:
                   3593:           buf.append("\u1e5d");
                   3594:           break; // runderdot macron
                   3595:         case 8482:
                   3596:           buf.append("\u016b\0306");
                   3597:           break; // umacron breve
                   3598:         case 8804:
                   3599:           buf.append("\u0101\u0301");
                   3600:           break; // amacron acute
                   3601:         case 8805:
                   3602:           buf.append("\u016b\u0301");
                   3603:           break; // umacron acute
                   3604:         case 8719:
                   3605:           buf.append("\u0113\u0301");
                   3606:           break; // emacron acute
                   3607:         case 170:
                   3608:           buf.append("\u0113\u0300");
                   3609:           break; // emacron breve
                   3610:         case 186:
                   3611:           buf.append("\u014d\u0300");
                   3612:           break; // omacron breve
                   3613:         case 161:
                   3614:           buf.append("\u0101\u0306");
                   3615:           break; // amacron breve
                   3616:         case 8710:
                   3617:           buf.append("\u0101\u0303");
                   3618:           break; // amacron tilde
                   3619:         case 171:
                   3620:           buf.append("\u012b\u0301");
                   3621:           break; // imacron acute
                   3622:         case 8260:
                   3623:           buf.append("\u1e00");
                   3624:           break; // runderdotmacron acute
                   3625:         case 183:
                   3626:           buf.append("\u1e5b\u0301");
                   3627:           break; // runderdot acute
                   3628:         case 8240:
                   3629:           buf.append("\u012b\u0306");
                   3630:           break; // imacron breve
                   3631:         case 63743:
                   3632:           buf.append("\u016b\u0303");
                   3633:           break; // umacron tilde
                   3634:         default:
                   3635:           buf.append(c);
                   3636:           break;
                   3637:       }
                   3638:     }
                   3639:     return buf.toString();
                   3640:   }
                   3641: 
                   3642:   public static ConversionProperties getFieldNamesAndDestTableName(String create, String query,
                   3643:       String tableName)
                   3644:   {
                   3645:     String[] fieldNames = null;
                   3646:     String destTableName = null;
                   3647:     // determine destTableName from createStatement or from source table
                   3648:     // name
                   3649:     if (!create.equals(""))
                   3650:     {
                   3651:       int fromIndex = create.toLowerCase().indexOf("table") + 5;
                   3652:       int toIndex = create.indexOf("(");
                   3653:       int endIndex = create.indexOf(")", toIndex);
                   3654: 
                   3655:       destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "").trim();
                   3656:       System.out.println("destTable " + destTableName);
                   3657:       // retrieve field_names from select statement
                   3658:       // TODO problem with different fieldNames in create statement will
                   3659:       // overwrite them
                   3660:       if (query.indexOf("*") < 0)
                   3661:       {
                   3662:         int selectEndIndex = query.indexOf("from");
                   3663:         StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ",");
                   3664:         int numFields = tokenizer.countTokens();
                   3665:         fieldNames = new String[numFields];
                   3666:         int fieldIndex = 0;
                   3667:         while (tokenizer.hasMoreTokens())
                   3668:         {
                   3669:           String fieldName = tokenizer.nextToken().trim();
                   3670:           fieldNames[fieldIndex] = convertText(fieldName);
                   3671:           System.out.println(fieldNames[fieldIndex]);
                   3672:           fieldIndex++;
                   3673:         }
                   3674: 
                   3675:       } else
                   3676:       {
                   3677:         // use create statement for field names
                   3678:         StringTokenizer tokenizer = new StringTokenizer(create.substring(toIndex + 1, endIndex),
                   3679:             ",");
                   3680:         int numFields = tokenizer.countTokens();
                   3681:         fieldNames = new String[numFields];
                   3682:         int fieldIndex = 0;
                   3683:         while (tokenizer.hasMoreTokens())
                   3684:         {
                   3685:           String fieldName = tokenizer.nextToken().trim();
                   3686:           int index = fieldName.lastIndexOf(" ");
                   3687:           fieldNames[fieldIndex] = fieldName.substring(0, index);
                   3688:           System.out.println(fieldNames[fieldIndex]);
                   3689:           fieldIndex++;
                   3690:         }
                   3691:       }
                   3692:     } else
                   3693:     {
                   3694:       destTableName = convertText(tableName);
                   3695: 
                   3696:       // retrieve field_names from select statement
                   3697:       if (query.indexOf("*") < 0)
                   3698:       {
                   3699:         int selectEndIndex = query.indexOf("from");
                   3700:         StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ",");
                   3701:         int numFields = tokenizer.countTokens();
                   3702:         fieldNames = new String[numFields];
                   3703:         int fieldIndex = 0;
                   3704:         while (tokenizer.hasMoreTokens())
                   3705:         {
                   3706:           String fieldName = tokenizer.nextToken().trim();
                   3707:           fieldNames[fieldIndex] = beanDest.getQC() + convertText(fieldName) + beanDest.getQC();
                   3708:           // System.out.println("field "+ fieldNames[fieldIndex]);
                   3709:           fieldIndex++;
                   3710:         }
                   3711: 
                   3712:       } else
                   3713:       {
                   3714:         Vector fieldNamesVec = bean.getColumnNames();
                   3715:         fieldNames = new String[fieldNamesVec.size()];
                   3716:         int fieldIndex = -1;
                   3717:         for (Iterator iter = fieldNamesVec.iterator(); iter.hasNext();)
                   3718:         {
                   3719:           String element = (String) iter.next();
                   3720:           fieldNames[++fieldIndex] = beanDest.getQC() + convertText(element) + beanDest.getQC();
                   3721:           // System.out.println("field " + fieldNames[fieldIndex]);
                   3722:         }
                   3723:       }
                   3724:     }
                   3725:     return new ConversionProperties(destTableName, fieldNames);
                   3726:   }
                   3727: 
                   3728:   /**
                   3729:    * creates an insert into statement for the specified table and given field
                   3730:    * names
                   3731:    * 
                   3732:    * @param destTableName
                   3733:    * @param fieldNames
                   3734:    * @return
                   3735:    */
                   3736:   public static StringBuffer createInsertCommand(String destTableName, String[] fieldNames)
                   3737:   {
                   3738:     StringBuffer command = new StringBuffer();
                   3739:     command.append("INSERT  INTO ");
                   3740:     command.append(beanDest.getQC());
                   3741:     command.append(destTableName); // convertText((String)
                   3742:     // names.get(tbIndex)));
                   3743:     command.append(beanDest.getQC());
                   3744:     command.append(" (");
                   3745:     for (int i = 0; i < fieldNames.length; i++)
                   3746:     {
                   3747:       command.append(fieldNames[i]);
                   3748:       if (i < fieldNames.length - 1)
                   3749:         command.append(",");
                   3750:     }
                   3751:     command.append(") ");
                   3752: 
                   3753:     command.append(" values ( ");
                   3754:     // add a question marks for every field
                   3755:     for (int i = 0; i < fieldNames.length - 1; ++i)
                   3756:       command.append("?,");
                   3757:     command.append("?)");
                   3758:     return command;
                   3759:   }
                   3760: 
                   3761:   public static StringBuffer createUpdateCommand(String destTableName, String[] fieldNames,
                   3762:       String id)
                   3763:   {
                   3764:     StringBuffer command = new StringBuffer();
                   3765: 
                   3766:     command.append("UPDATE ");
                   3767:     command.append(beanDest.getQC());
                   3768:     command.append(destTableName);
                   3769:     command.append(beanDest.getQC());
                   3770:     command.append(" SET  ");
                   3771: 
                   3772:     int size = bean.getColumnNames().size();
                   3773:     for (int i = 0; i < size - 1; ++i)
                   3774:       command.append(fieldNames[i] + " = ? ,");
                   3775:     command.append(fieldNames[size - 1] + " = ? ");
                   3776:     command.append("WHERE " + id + " =  ?");
                   3777:     return command;
                   3778:   }
                   3779: 
                   3780:   public static StringBuffer createDeleteCommand(String destTableName, String idField)
                   3781:   {
                   3782:     StringBuffer command = new StringBuffer();
                   3783: 
                   3784:     command.append("DELETE FROM");
                   3785:     command.append(beanDest.getQC());
                   3786:     command.append(destTableName);
                   3787:     // command.append(convertText((String) names.get(tbIndex)));
                   3788:     command.append(beanDest.getQC());
                   3789:     command.append("WHERE " + idField + " =  ?");
                   3790:     return command;
                   3791:   }
                   3792: 
                   3793:   public void makeTest(String table, String idField, String tempQuery) throws Exception
                   3794:   {
                   3795:     int counter = 0;
                   3796: 
                   3797:     // ****** test code *****
                   3798: 
                   3799:     bean.getConnection();
                   3800:     ResultSet resultSet = null;
                   3801:     String lastResult = "P227634.11";// "P227625.79554";//"P227625.77391";//"P116034.970998";
                   3802:     String myQuery = "select " + bean.getQC() + idField + bean.getQC() + ",serial " + " from "
                   3803:         + bean.getQC() + table + bean.getQC();
                   3804:     System.out.println("Query is now " + myQuery);
                   3805:     JDialog statusDialog = new JDialog();
                   3806:     statusDialog.setTitle("Status Information");
                   3807:     JLabel status = new JLabel("actual DataSet : ");
                   3808:     JLabel status2 = new JLabel(Integer.toString(++counter));
                   3809:     JLabel status3 = new JLabel(lastResult);
                   3810: 
                   3811:     JPanel statusPanel = new JPanel();
                   3812:     JPanel statusPanel2 = new JPanel();
                   3813:     statusPanel.add(status);
                   3814:     statusPanel.add(status2);
                   3815:     statusPanel2.add(status3);
                   3816:     statusDialog.getContentPane().add(statusPanel, "North");
                   3817:     statusDialog.getContentPane().add(statusPanel2, "Center");
                   3818:     statusDialog.setLocation(400, 500);
                   3819:     statusDialog.setSize(300, 150);
                   3820:     statusDialog.setVisible(true);
                   3821:     while (true)
                   3822:     {
                   3823:       if (!statusDialog.isVisible())
                   3824:         statusDialog.setVisible(true);
                   3825:       tempQuery = myQuery + " where " + bean.getQC() + idField + bean.getQC() + ">'" + lastResult
                   3826:           + "'";
                   3827:       resultSet = bean.makeQuery(tempQuery, 1);
                   3828:       if (resultSet == null)
                   3829:       {
                   3830:         System.out.println("lastResult was " + lastResult + " counter was " + counter);
                   3831:         break;
                   3832:       } else
                   3833:       {
                   3834:         resultSet.next();
                   3835:         lastResult = resultSet.getString(1);
                   3836:         counter++;
                   3837:         status2.setText(Integer.toString(counter));
                   3838:         status3.setText(lastResult + " " + resultSet.getString(2));
                   3839:         if (counter % 100 == 0)
                   3840:         {
                   3841:           System.out.println("actual Result was " + lastResult + " counter was " + counter);
                   3842:           // break;
                   3843:         }
                   3844:       }
                   3845:       resultSet = null;
                   3846:     }
                   3847:     System.exit(0);
1.1       rogo     3848: 
1.4       rogo     3849:     // ****** end Test ******
1.1       rogo     3850: 
1.4       rogo     3851:   }
1.1       rogo     3852: }

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