--- FM2SQL/Attic/Convert.java 2004/03/01 12:37:10 1.41 +++ FM2SQL/Attic/Convert.java 2004/03/09 12:34:09 1.45 @@ -59,11 +59,11 @@ class Convert System.out.println("Finished!"); //convert("jdbc:fmpro:http://141.14.237.74:8050","jdbc:postgresql://erebos/test",null,null); } - public static void convertBatch(DBBean source, DBBean destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids,int mode) throws Exception + public static void convertBatch(DBBean source, DBBean destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids,int mode,String delimiter) throws Exception { bean = source; beanDest = destination; - convert(null,null,names,layouts,selects,creates,ids,mode); + convert(null,null,names,layouts,selects,creates,ids,mode,delimiter); if(true) return; StringBuffer command = null; try @@ -274,11 +274,12 @@ class Convert names = bean.getTableNames(); // Collections.sort(names); int tbIndex = 1; - + // System.out.println("Start at "+names.indexOf("archimedes_facsimiles")); for (tbIndex = 0; tbIndex < names.size(); ++tbIndex) { Vector[] result = null; + String destTableName = ""; try { query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC(); @@ -305,6 +306,18 @@ class Convert { continue; } + // determine destTableName from createStatement or from source table name + if(!creates.get(tbIndex).equals("")) + { + String create =creates.get(tbIndex).toString().toLowerCase(); + int fromIndex = create.indexOf("table")+5; + int toIndex = create.indexOf("("); + destTableName = create.substring(fromIndex,toIndex).replaceAll(beanDest.getQC(),"").trim(); + System.out.println("destTable "+destTableName); + + } else + destTableName = convertText(names.get(tbIndex).toString()); + //beanDest.setConnection("jdbc:postgresql://erebos/test3"); beanDest.setConnection(destination); @@ -328,7 +341,8 @@ class Convert command.append("UPDATE "); command.append(beanDest.getQC()); - command.append(convertText((String) names.get(tbIndex))); + command.append(destTableName); + //command.append(convertText((String) names.get(tbIndex))); command.append(beanDest.getQC()); command.append(" SET "); @@ -435,7 +449,7 @@ class Convert */ - public static void convert(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode) throws Exception + public static void convert(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode,String delimiter) throws Exception { FM2SQL.ProgressDialog dialog = null; @@ -528,18 +542,21 @@ class Convert // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString())); stm = beanDest.getConnection().createStatement(); // System.exit(0); - if (mode == Convert.DataBase.CONVERT_MODE) + + // determine destTableName from createStatement or from source table name + if(!creates.get(tbIndex).equals("")) { - if(!creates.get(tbIndex).equals("")) - { - String create =creates.get(tbIndex).toString().toLowerCase(); - int fromIndex = create.indexOf("table")+5; - int toIndex = create.indexOf("("); - destTableName = create.substring(fromIndex,toIndex).replaceAll(beanDest.getQC(),"").trim(); - System.out.println("destTable "+destTableName); + String create =creates.get(tbIndex).toString().toLowerCase(); + int fromIndex = create.indexOf("table")+5; + int toIndex = create.indexOf("("); + destTableName = create.substring(fromIndex,toIndex).replaceAll(beanDest.getQC(),"").trim(); + System.out.println("destTable "+destTableName); - } else - destTableName = convertText(names.get(tbIndex).toString()); + } else + destTableName = convertText(names.get(tbIndex).toString()); + + if (mode == Convert.DataBase.CONVERT_MODE) + { if (tables.indexOf(destTableName) >= 0) { @@ -667,7 +684,7 @@ class Convert if(dialog!=null) dialog.title.setText("Writing table data ..."); - command = writeDatainDestTable(dialog, command, k, pstm, rowCount); + command = writeDatainDestTable(dialog, command, k, pstm, rowCount,delimiter); endIndex = k + deltaID; } System.out.println(endIndex); @@ -688,7 +705,7 @@ class Convert bean.makeQuery(tempQuery, 0); if(dialog!=null) dialog.title.setText("Writing table data ..."); - command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount); + command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount,delimiter); } // prepare new query for next chunk if (query.indexOf("where") > 0) @@ -705,7 +722,7 @@ class Convert long startTime = System.currentTimeMillis(); bean.makeQuery(query, 0); - command = writeDatainDestTable(dialog, command, j, pstm, rowCount); + command = writeDatainDestTable(dialog, command, j, pstm, rowCount,delimiter); long endTime = System.currentTimeMillis(); System.out.println("Time for old convert elapsed " + (endTime - startTime)); @@ -748,7 +765,7 @@ class Convert * @throws Exception * @throws SQLException */ - private static StringBuffer writeDatainDestTable(FM2SQL.ProgressDialog dialog, StringBuffer command, int j, PreparedStatement pstm, int rowCount) throws Exception, SQLException + private static StringBuffer writeDatainDestTable(FM2SQL.ProgressDialog dialog, StringBuffer command, int j, PreparedStatement pstm, int rowCount,String delimiter) throws Exception, SQLException { Vector row; while ((row = bean.getNextRow()) != null) @@ -795,7 +812,7 @@ class Convert obj = row.get(k); if (obj instanceof ArrayList) if (obj instanceof ArrayList) - obj = formatFileMakerArray((List) obj," | "); + obj = formatFileMakerArray((List) obj,delimiter); String str = (obj == null) ? "NULL" : obj.toString(); if (!str.equals("NULL")) @@ -1079,6 +1096,7 @@ class Convert Vector selects = new Vector(); Vector creates = new Vector(); Vector ids = new Vector(); + String delimiter = "|"; int mode = -1; try @@ -1103,7 +1121,7 @@ class Convert Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 }); Node node3 = root.find("convert/source/database", new int[] { 1, 1, i }); Node nodeMode = root.find("convert/source/database/mode", new int[] { 1, 1, i, 1, 1 }); - + Node delimiterNode =root.find("convert/source/database/delimiter", new int[] { 1, 1, i, 1, 1 }); if (node3 == null) throw new Error("parse error database tag missing"); if (node == null) @@ -1112,6 +1130,7 @@ class Convert throw new Error("parse error user tag missing"); if (node2 == null) throw new Error("parse error password tag missing"); + if(delimiterNode!=null) delimiter = delimiterNode.getCharacters(); String url = node.getCharacters(); String user = node1.getCharacters(); String password = node2.getCharacters(); @@ -1179,7 +1198,9 @@ class Convert creates.add(""); } - databases.add(new DataBase(database, tables, layouts, selects, creates, ids, mode)); + DataBase dataBase = new DataBase(database, tables, layouts, selects, creates, ids, mode); + dataBase.delimiter = delimiter; + databases.add(dataBase); } DBBean database = new DBBean(); // parse dataBase @@ -1197,7 +1218,7 @@ class Convert { DataBase db = (DataBase) iter.next(); if (mode != DataBase.UPDATE_MODE) - convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids,mode); + convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids,mode,db.delimiter); else update(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode); @@ -1245,7 +1266,7 @@ class Convert Vector selects = new Vector(); Vector creates = new Vector(); Vector ids = new Vector(); - + String delimiter = "|"; int mode = -1; try { @@ -1269,7 +1290,10 @@ class Convert Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 }); Node node3 = root.find("convert/source/database", new int[] { 1, 1, i }); Node nodeMode = root.find("convert/source/database/mode", new int[] { 1, 1, i, 1, 1 }); - + Node delimiterNode =root.find("convert/source/database/delimiter", new int[] { 1, 1, i, 1, 1 }); + + if (delimiterNode != null) + delimiter = delimiterNode.getCharacters(); if (node3 == null) throw new Error("parse error database tag missing"); if (node == null) @@ -1297,7 +1321,6 @@ class Convert mode = DataBase.APPEND_MODE; else if (modeString.equals("update")) mode = DataBase.UPDATE_MODE; - // if(node3!=null) // System.out.println(node3.name); @@ -1347,7 +1370,9 @@ class Convert creates.add(""); } - databases.add(new DataBase(database, tables, layouts, selects, creates, ids, mode)); + DataBase dataBase=new DataBase(database, tables, layouts, selects, creates, ids, mode); + dataBase.delimiter=delimiter; + databases.add(dataBase); } DBBean database = new DBBean(); // parse dataBase @@ -1454,6 +1479,7 @@ class Convert Vector layouts; Vector tables; Vector ids; + String delimiter = "//"; final static int CONVERT_MODE = 1; final static int APPEND_MODE = 2; final static int UPDATE_MODE = 3; @@ -1473,7 +1499,7 @@ class Convert this.bean.setIDVector(ids); } /** - * writes the data contained in this object th the buffered writer + * writes the data contained in this object to the buffered writer * * @param buffr * @throws Exception */ @@ -1484,6 +1510,7 @@ class Convert buffr.write(" " + bean.url + "\n"); buffr.write(" " + bean.user + "\n"); buffr.write(" " + bean.passwd + "\n"); + buffr.write(" "+delimiter+"\n"); String modeString = ""; if (mode == CONVERT_MODE) modeString = "convert";