--- FM2SQL/Attic/Convert.java 2004/10/19 11:57:26 1.82 +++ FM2SQL/Attic/Convert.java 2004/10/26 08:37:10 1.83 @@ -18,6 +18,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; @@ -93,8 +94,9 @@ class Convert final static int numIntervalls = 4; static boolean debug = false; - - public static void main(String args[]) + + static boolean isGUI = true; + public static void main(String args[]) throws IOException { /* * try { //byte[] b = "ö".getBytes("UTF-8"); // @@ -103,6 +105,7 @@ class Convert * //System.out.println(new String(b,"UTF-8")); } catch * (UnsupportedEncodingException e) { e.printStackTrace(); } */ + isGUI = false; FileOutputStream file = null; if (args.length != 1) { @@ -110,14 +113,14 @@ class Convert System.exit(-1); } try - { - file = new FileOutputStream("./log.txt"); + { File temp=File.createTempFile("fm2sql",".txt"); + file = new FileOutputStream(temp); } catch (FileNotFoundException e1) { e1.printStackTrace(); } - PrintStream stream = new PrintStream(file, false); + PrintStream stream = new PrintStream(file, true); if (!debug) { System.setOut(stream); @@ -329,7 +332,7 @@ class Convert { FM2SQL.ProgressDialog dialog = null; - if (FM2SQL.fmInstance != null) + if (isGUI) { dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean); dialog.setTitle("Conversion running ..."); @@ -351,14 +354,17 @@ class Convert { //bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050"); //bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo"); + System.out.println("before getConnection"); + bean.setConnection(source); + System.out.println("after getConnection"); + if (names == null) names = bean.getTableNames(); // Collections.sort(names); int tbIndex = 1; - // System.out.println("Start at - // "+names.indexOf("archimedes_facsimiles")); + System.out.println("Start at table "+names.firstElement()); for (tbIndex = 0; tbIndex < names.size(); ++tbIndex) { Vector[] result = null; @@ -423,7 +429,7 @@ class Convert if (dialog != null) dialog.title.setText("Updating table data ..."); - + else System.out.println("Updating table data ..."); int j = -1; Vector row = null; @@ -510,6 +516,7 @@ class Convert java.io.PrintStream stream = new java.io.PrintStream(b); stream.print(command + "\n\n"); e.printStackTrace(stream); + if(dialog!=null) FM2SQL.showErrorDialog(b.toString(), "Error occured !"); } @@ -541,10 +548,10 @@ class Convert 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; - if (FM2SQL.fmInstance != null) + if (isGUI) { dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean); dialog.setTitle("Conversion running ..."); @@ -555,11 +562,15 @@ class Convert dialog.thread = Thread.currentThread(); dialog.setSize(400, 250); } + + System.out.println("connection established "+source+" "+bean.url); + java.util.TreeSet myIds = new TreeSet(); int deltaID = 1; String idField = ""; String destTableName = ""; String[] fieldNames = null; + if (source != null && destination != null) { // setting user and passwd @@ -567,16 +578,17 @@ class Convert // setting user and passwd beanDest.setUserAndPasswd(userDest, passwdDest); } + StringBuffer command = null; String query = null; try { + if (source != null) bean.setConnection(source); else bean.setConnection(bean.url); - - if (names == null) + if (names == null) names = bean.getTableNames(); // Collections.sort(names); int tbIndex = 1; @@ -1313,17 +1325,22 @@ class Convert String url = node.getCharacters(); String user = node1.getCharacters(); String password = node2.getCharacters(); - System.out.println(url); + System.out.println(" The url is "+url); database.setURL(url.trim()); database.setUserAndPasswd(user.trim(), password.trim()); + System.out.println("huhu"); //databases.add(database); for (Iterator iter = databases.iterator(); iter.hasNext();) { + System.out.println("huhu argghhhh"+(mode == DataBase.CONVERT_MODE)+" mode is "+mode); + DataBase db = (DataBase) iter.next(); if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE) convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter); else if (mode == DataBase.UPDATE_MODE) { + System.out.println("huhu arghhh arghhh arghhh"); + Convert.user = db.bean.user; Convert.passwd = db.bean.passwd; userDest = database.user; @@ -1831,7 +1848,7 @@ class Convert public static void delete(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode) throws Exception { FM2SQL.ProgressDialog dialog = null; - if (FM2SQL.fmInstance != null) + if (isGUI) { dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean); dialog.setTitle("Conversion running ..."); @@ -2061,7 +2078,7 @@ class Convert { System.out.println(" bin in synchronize!!!"); FM2SQL.ProgressDialog dialog = null; - if (FM2SQL.fmInstance != null) + if (isGUI) { dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean); dialog.setTitle("Synchronize running ..."); @@ -2355,6 +2372,7 @@ class Convert java.io.PrintStream stream = new java.io.PrintStream(b); stream.print(command + "\n\n"); e.printStackTrace(stream); + if(dialog != null) FM2SQL.showErrorDialog(b.toString(), "Error occured !"); }