--- FM2SQL/Attic/Convert.java 2004/04/06 10:34:15 1.54 +++ FM2SQL/Attic/Convert.java 2004/06/01 10:29:48 1.55 @@ -73,12 +73,13 @@ 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,String delimiter) 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,delimiter); - if(true) return; + convert(null, null, names, layouts, selects, creates, ids, mode, delimiter); + if (true) + return; StringBuffer command = null; try { @@ -204,7 +205,7 @@ class Convert { obj = row.get(k); if (obj instanceof ArrayList) - obj = formatFileMakerArray((List) obj,"\n"); + obj = formatFileMakerArray((List) obj, "\n"); String str = (obj == null) ? "NULL" : obj.toString(); if (!str.equals("NULL")) pstm.setString(k + 1, str); @@ -235,17 +236,17 @@ class Convert // dialog.setVisible(false); } - public static String formatFileMakerArray(List list, String delimiter) - { - StringBuffer formattedString = new StringBuffer(); - for(int i=0;i 0) - tempQuery = query + " and " + tempID + ">='" + vec.get(k) + "' and " + tempID + "<='" + vec.get(k + deltaID)+"'"; + tempQuery = query + " and " + tempID + ">='" + vec.get(k) + "' and " + tempID + "<='" + vec.get(k + deltaID) + "'"; else - tempQuery = query + " where " + tempID + ">='" + vec.get(k) + "' and " + tempID + "<='" + vec.get(k + deltaID)+"'"; + tempQuery = query + " where " + tempID + ">='" + vec.get(k) + "' and " + tempID + "<='" + vec.get(k + deltaID) + "'"; System.out.println(tempQuery); - if(dialog!=null) - dialog.title.setText("Reading table data ..."); + if (dialog != null) + dialog.title.setText("Reading table data ..."); bean.makeQuery(tempQuery, deltaID); - if(dialog!=null) - dialog.title.setText("Writing table data ..."); + if (dialog != null) + dialog.title.setText("Writing table data ..."); - command = writeDatainDestTable(dialog, command, k, pstm, rowCount,delimiter); + command = writeDatainDestTable(dialog, command, k, pstm, rowCount, delimiter); endIndex = k + deltaID; } System.out.println(endIndex); @@ -710,22 +781,22 @@ class Convert System.out.println(" last intervall from " + vec.get(endIndex) + " " + vec.lastElement()); if (query.indexOf("where") > 0) - tempQuery = query + " and " + tempID + ">='" + vec.get(endIndex) + "' and " + tempID + "<='" + vec.lastElement()+"'"; + tempQuery = query + " and " + tempID + ">='" + vec.get(endIndex) + "' and " + tempID + "<='" + vec.lastElement() + "'"; else - tempQuery = query + " where " + tempID + ">='" + vec.get(endIndex) + "' and " + tempID + "<='" + vec.lastElement()+"'"; + tempQuery = query + " where " + tempID + ">='" + vec.get(endIndex) + "' and " + tempID + "<='" + vec.lastElement() + "'"; System.out.println(tempQuery); - if(dialog!=null) - dialog.title.setText("Reading table data ..."); + if (dialog != null) + dialog.title.setText("Reading table data ..."); bean.makeQuery(tempQuery, 0); - if(dialog!=null) - dialog.title.setText("Writing table data ..."); - command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount,delimiter); + if (dialog != null) + dialog.title.setText("Writing table data ..."); + command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount, delimiter); } // prepare new query for next chunk if (query.indexOf("where") > 0) - tempQuery = query + " and " + tempID + ">'" + vec.lastElement()+"'"; + tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'"; else - tempQuery = query + " where " + tempID + ">'" + vec.lastElement()+"'"; + tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'"; } long endTime = System.currentTimeMillis(); @@ -734,9 +805,9 @@ class Convert { // read and write all in one big chunk long startTime = System.currentTimeMillis(); - + bean.makeQuery(query, 0); - command = writeDatainDestTable(dialog, command, j, pstm, rowCount,delimiter); + command = writeDatainDestTable(dialog, command, j, pstm, rowCount, delimiter); long endTime = System.currentTimeMillis(); System.out.println("Time for old convert elapsed " + (endTime - startTime)); @@ -779,7 +850,7 @@ class Convert * @throws Exception * @throws SQLException */ - private static StringBuffer writeDatainDestTable(FM2SQL.ProgressDialog dialog, StringBuffer command, int j, PreparedStatement pstm, int rowCount,String delimiter) 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) @@ -824,16 +895,15 @@ class Convert for (int k = 0; k < row.size(); ++k) { obj = row.get(k); - - if (obj instanceof ArrayList) - obj = formatFileMakerArray((List) obj,delimiter); - + + if (obj instanceof ArrayList) + obj = formatFileMakerArray((List) obj, delimiter); + String str = (obj == null) ? "NULL" : obj.toString(); - if(obj instanceof Double) - { - pstm.setDouble(k + 1, ((Double)obj).doubleValue()); - }else - if (!str.equals("NULL")) + if (obj instanceof Double) + { + pstm.setDouble(k + 1, ((Double) obj).doubleValue()); + } else if (!str.equals("NULL")) pstm.setString(k + 1, str); else pstm.setNull(k + 1, Types.NULL); @@ -1095,11 +1165,11 @@ class Convert } return alterMe.toString(); } -/** - * parses the input xml file for batch conversion - * called from readXMLFile - * * @param sb - */ + /** + * parses the input xml file for batch conversion + * called from readXMLFile + * * @param sb + */ public static void parseXMLConfig(StringBuffer sb) { boolean finished = false; @@ -1139,7 +1209,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 }); + 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) @@ -1148,7 +1218,8 @@ 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(); + if (delimiterNode != null) + delimiter = delimiterNode.getCharacters(); String url = node.getCharacters(); String user = node1.getCharacters(); String password = node2.getCharacters(); @@ -1239,7 +1310,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,db.delimiter); + 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); @@ -1248,7 +1319,7 @@ class Convert // FM2SQL.fmInstance=new FM2SQL(); } catch (Exception e) { - + e.printStackTrace(); } } @@ -1287,7 +1358,7 @@ class Convert Vector selects = new Vector(); Vector creates = new Vector(); Vector ids = new Vector(); - String delimiter = "|"; + String delimiter = "|"; int mode = -1; try { @@ -1311,8 +1382,8 @@ 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 }); - + Node delimiterNode = root.find("convert/source/database/delimiter", new int[] { 1, 1, i, 1, 1 }); + if (delimiterNode != null) delimiter = delimiterNode.getCharacters(); if (node3 == null) @@ -1394,8 +1465,8 @@ class Convert creates.add(""); } - DataBase dataBase=new DataBase(database, tables, layouts, selects, creates, ids, mode); - dataBase.delimiter=delimiter; + DataBase dataBase = new DataBase(database, tables, layouts, selects, creates, ids, mode); + dataBase.delimiter = delimiter; databases.add(dataBase); } DBBean database = new DBBean(); @@ -1487,7 +1558,7 @@ class Convert e.printStackTrace(); } } - + /** * Helper class for XML-File parsing * Holds the parsed data @@ -1533,7 +1604,7 @@ class Convert buffr.write(" " + bean.url + "\n"); buffr.write(" " + bean.user + "\n"); buffr.write(" " + bean.passwd + "\n"); - buffr.write(" "+delimiter+"\n"); + buffr.write(" " + delimiter + "\n"); String modeString = ""; if (mode == CONVERT_MODE) modeString = "convert"; @@ -1542,7 +1613,7 @@ class Convert else if (mode == UPDATE_MODE) modeString = "update"; else if (mode == DELETE_MODE) - modeString = "delete"; + modeString = "delete"; buffr.write(" " + modeString + "\n"); int index = 0; @@ -1608,7 +1679,7 @@ class Convert FM2SQL.ProgressDialog dialog = null; if (FM2SQL.fmInstance != null) { - dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance,bean); + dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean); dialog.setTitle("Conversion running ..."); dialog.title.setText("Getting table data ..."); dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2); @@ -1765,7 +1836,7 @@ class Convert //print rows pstm.setString(1, linesToDelete.get(j).toString()); System.out.println(pstm.toString()); - pstm.execute(); + pstm.execute(); if (dialog != null) dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0)); command = null; @@ -1781,28 +1852,28 @@ class Convert } // table loop } catch (Exception e) - { - System.out.println("Error while connecting to database " + e); - if (dialog != null) - { - dialog.setVisible(false); - dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream(); - java.io.PrintStream stream = new java.io.PrintStream(b); - stream.print(command + "\n\n"); - e.printStackTrace(stream); - FM2SQL.showErrorDialog(b.toString(), "Error occured !"); - - } + { + System.out.println("Error while connecting to database " + e); if (dialog != null) { + dialog.setVisible(false); dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - - dialog.setVisible(false); } - } // to method + java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream(); + java.io.PrintStream stream = new java.io.PrintStream(b); + stream.print(command + "\n\n"); + e.printStackTrace(stream); + FM2SQL.showErrorDialog(b.toString(), "Error occured !"); + + } + if (dialog != null) + { + dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + + dialog.setVisible(false); + } + } // to method - } \ No newline at end of file +} \ No newline at end of file