version 1.5, 2005/03/21 10:32:03
|
version 1.8, 2005/04/12 10:58:54
|
Line 31 import java.sql.Statement;
|
Line 31 import java.sql.Statement;
|
import java.sql.Types; |
import java.sql.Types; |
import java.text.ParseException; |
import java.text.ParseException; |
import java.util.ArrayList; |
import java.util.ArrayList; |
|
import java.util.Enumeration; |
import java.util.Hashtable; |
import java.util.Hashtable; |
import java.util.Iterator; |
import java.util.Iterator; |
import java.util.List; |
import java.util.List; |
|
import java.util.Properties; |
import java.util.StringTokenizer; |
import java.util.StringTokenizer; |
import java.util.TreeSet; |
import java.util.TreeSet; |
import java.util.Vector; |
import java.util.Vector; |
Line 93 class Convert
|
Line 95 class Convert
|
|
|
public void executeCommand() throws SQLException, Exception |
public void executeCommand() throws SQLException, Exception |
{ |
{ |
|
System.out.println("Executing command: \n"); |
|
System.out.println(command); |
|
|
java.sql.Connection con = bean.getConnection(); |
java.sql.Connection con = bean.getConnection(); |
Statement stm = con.createStatement(); |
Statement stm = con.createStatement(); |
stm.execute(command); |
stm.execute(command); |
|
stm.close(); |
} |
} |
} |
} |
|
|
Line 129 class Convert
|
Line 135 class Convert
|
|
|
static Vector postSQLCommands = new Vector(); |
static Vector postSQLCommands = new Vector(); |
|
|
|
static final String versionID = new String("FM2SQL Version 0.9.0b\n"); |
|
|
public static void main(String args[]) throws IOException |
public static void main(String args[]) throws IOException |
{ |
{ |
/* |
/* |
Line 138 class Convert
|
Line 146 class Convert
|
* //System.out.println(new String(b,"UTF-8")); } catch |
* //System.out.println(new String(b,"UTF-8")); } catch |
* (UnsupportedEncodingException e) { e.printStackTrace(); } |
* (UnsupportedEncodingException e) { e.printStackTrace(); } |
*/ |
*/ |
|
File tmpPath = new File(System.getProperty("java.io.tmpdir")); |
isGUI = false; |
isGUI = false; |
FileOutputStream file = null; |
FileOutputStream file = null; |
if (args.length != 1) |
if (args.length != 1) |
{ |
{ |
|
System.out.println(versionID); |
System.out.println("Usage: java Convert <xml config file>"); |
System.out.println("Usage: java Convert <xml config file>"); |
|
System.out.println("Log file will be written in "+tmpPath.getCanonicalPath()+" folder "); |
System.exit(-1); |
System.exit(-1); |
} |
} |
|
File temp = null; |
try |
try |
{ |
{ |
File temp = File.createTempFile("fm2sql", ".txt"); |
temp = new File(tmpPath, "fm2sql.txt"); |
|
int count = 1; |
|
while (temp.exists()) |
|
{ |
|
temp = new File(tmpPath, "fm2sql" + generateSuffix(count++) + ".txt"); |
|
} |
file = new FileOutputStream(temp); |
file = new FileOutputStream(temp); |
} catch (FileNotFoundException e1) |
} catch (FileNotFoundException e1) |
{ |
{ |
e1.printStackTrace(); |
e1.printStackTrace(); |
} |
} |
PrintStream stream = new PrintStream(file, true); |
PrintStream stream = new PrintStream(file, true); |
|
// write info for user to stdout |
|
System.out.println(versionID); |
|
System.out.println("Loading "+args[0]+"...."); |
|
System.out.println("Log will be written to "+temp.getCanonicalPath()); |
|
|
if (!debug) |
if (!debug) |
{ |
{ |
System.setOut(stream); |
System.setOut(stream); |
System.setErr(stream); |
System.setErr(stream); |
} |
} |
|
System.out.println(versionID); |
|
System.out.println("Using config file : "+args[0]+"...."); |
|
|
StringBuffer sb = readXMLFile(args[0]); |
StringBuffer sb = readXMLFile(args[0]); |
parseXMLConfig(sb); |
parseXMLConfig(sb); |
if (!(new File(args[0]).exists())) |
if (!(new File(args[0]).exists())) |
System.exit(0); |
{ |
|
|
|
System.exit(0); |
|
} |
System.out.println("Finished!"); |
System.out.println("Finished!"); |
// convert("jdbc:fmpro:http://141.14.237.74:8050","jdbc:postgresql://erebos/test",null,null); |
// convert("jdbc:fmpro:http://141.14.237.74:8050","jdbc:postgresql://erebos/test",null,null); |
} |
} |
Line 417 class Convert
|
Line 444 class Convert
|
public static void convert(String source, String destination, Vector names, Vector layouts, |
public static void convert(String source, String destination, Vector names, Vector layouts, |
Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception |
Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception |
{ |
{ |
|
// TODO implement convert_temp mode!!! |
FM2SQL.ProgressDialog dialog = null; |
FM2SQL.ProgressDialog dialog = null; |
|
|
if (isGUI) |
if (isGUI) |
Line 502 class Convert
|
Line 529 class Convert
|
ConversionProperties prop = getFieldNamesAndDestTableName(creates.get(tbIndex).toString(), |
ConversionProperties prop = getFieldNamesAndDestTableName(creates.get(tbIndex).toString(), |
query, names.get(tbIndex).toString()); |
query, names.get(tbIndex).toString()); |
destTableName = prop.destTableName; |
destTableName = prop.destTableName; |
|
if (mode == Convert.DataBase.CONVERT_TEMP_MODE) |
|
{ |
|
destTableName += "_temp"; |
|
} |
fieldNames = prop.fieldNames; |
fieldNames = prop.fieldNames; |
if (mode == Convert.DataBase.CONVERT_MODE) |
if (mode == Convert.DataBase.CONVERT_MODE || mode == Convert.DataBase.CONVERT_TEMP_MODE) |
{ |
{ |
|
|
if (tables.indexOf(destTableName) >= 0) |
if (tables.indexOf(destTableName) >= 0) |
Line 511 class Convert
|
Line 542 class Convert
|
stm.executeUpdate("drop table " + beanDest.getQC() + destTableName + beanDest.getQC()); |
stm.executeUpdate("drop table " + beanDest.getQC() + destTableName + beanDest.getQC()); |
tables.remove(destTableName); |
tables.remove(destTableName); |
System.out.println("dropped table" + destTableName); |
System.out.println("dropped table" + destTableName); |
|
|
} |
} |
if ((tables.indexOf(destTableName) < 0)) |
if ((tables.indexOf(destTableName) < 0)) |
{ |
{ |
Line 525 class Convert
|
Line 555 class Convert
|
command = new StringBuffer(50); |
command = new StringBuffer(50); |
command.append("CREATE TABLE "); |
command.append("CREATE TABLE "); |
command.append(beanDest.getQC()); |
command.append(beanDest.getQC()); |
command.append(convertText((String) names.get(tbIndex))); |
command.append(destTableName);//convertText((String) names.get(tbIndex))); |
command.append(beanDest.getQC()); |
command.append(beanDest.getQC()); |
command.append("("); |
command.append("("); |
String type = null; |
String type = null; |
Line 982 class Convert
|
Line 1012 class Convert
|
{ |
{ |
databases = getXMLConfig(sb); |
databases = getXMLConfig(sb); |
|
|
|
// destination DataBase object |
|
DataBase dbDest = ((DataBase) databases.lastElement()); |
|
|
DBBean database = ((DataBase) databases.lastElement()).bean; |
DBBean database = ((DataBase) databases.lastElement()).bean; |
databases.remove(databases.size() - 1); |
databases.remove(databases.size() - 1); |
|
|
|
for (Iterator iterator = dbDest.preCommands.iterator(); iterator.hasNext();) |
|
{ |
|
SQLCommand sqlCommand = (SQLCommand) iterator.next(); |
|
sqlCommand.executeCommand(); |
|
} |
|
|
// databases.add(database); |
// databases.add(database); |
for (Iterator iter = databases.iterator(); iter.hasNext();) |
for (Iterator iter = databases.iterator(); iter.hasNext();) |
{ |
{ |
Line 994 class Convert
|
Line 1034 class Convert
|
sqlCommand.executeCommand(); |
sqlCommand.executeCommand(); |
} |
} |
int mode = db.mode; |
int mode = db.mode; |
if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE) |
if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE |
|
|| mode == DataBase.CONVERT_TEMP_MODE) |
convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, |
convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, |
mode, db.delimiter); |
mode, db.delimiter); |
else if (mode == DataBase.UPDATE_MODE) |
else if (mode == DataBase.UPDATE_MODE) |
Line 1024 class Convert
|
Line 1065 class Convert
|
} |
} |
|
|
} |
} |
|
for (Iterator iterator = dbDest.postCommands.iterator(); iterator.hasNext();) |
|
{ |
|
SQLCommand sqlCommand = (SQLCommand) iterator.next(); |
|
sqlCommand.executeCommand(); |
|
} |
|
|
} catch (Exception e) |
} catch (Exception e) |
{ |
{ |
Line 1143 class Convert
|
Line 1189 class Convert
|
|
|
else if (modeString.equals("synchronize")) |
else if (modeString.equals("synchronize")) |
mode = DataBase.SYNCHRONIZE_MODE; |
mode = DataBase.SYNCHRONIZE_MODE; |
|
else if (modeString.equals("convert_temp")) |
|
mode = DataBase.CONVERT_TEMP_MODE; |
|
|
// if(node3!=null) |
// if(node3!=null) |
// System.out.println(node3.name); |
// System.out.println(node3.name); |
|
|
Line 1430 class Convert
|
Line 1479 class Convert
|
|
|
final static int SYNCHRONIZE_MODE = 5; |
final static int SYNCHRONIZE_MODE = 5; |
|
|
|
final static int CONVERT_TEMP_MODE = 6; |
|
|
int mode = -1; |
int mode = -1; |
|
|
public DataBase(DBBean bean, Vector tables, Vector layouts, Vector selects, Vector creates, |
public DataBase(DBBean bean, Vector tables, Vector layouts, Vector selects, Vector creates, |
Line 1496 class Convert
|
Line 1547 class Convert
|
while (count < preCommands.size()) |
while (count < preCommands.size()) |
{ |
{ |
SQLCommand sqlcommand=(SQLCommand)preCommands.get(count); |
SQLCommand sqlcommand=(SQLCommand)preCommands.get(count); |
buffr.write(" <sqlcommand execute=\"before\">" + sqlcommand.command + "</sqlcommand>\n"); |
buffr.write(" <sqlcommand execute=\"before\">" + sqlcommand.command |
|
+ "</sqlcommand>\n"); |
count++; |
count++; |
} |
} |
} |
} |
Line 1507 class Convert
|
Line 1559 class Convert
|
{ |
{ |
SQLCommand sqlcommand=(SQLCommand)postCommands.get(count); |
SQLCommand sqlcommand=(SQLCommand)postCommands.get(count); |
|
|
buffr.write(" <sqlcommand execute=\"after\">" + sqlcommand.command + "</sqlcommand>\n"); |
buffr.write(" <sqlcommand execute=\"after\">" + sqlcommand.command |
|
+ "</sqlcommand>\n"); |
count++; |
count++; |
} |
} |
} |
} |
Line 3638 class Convert
|
Line 3691 class Convert
|
// retrieve field_names from select statement |
// retrieve field_names from select statement |
// TODO problem with different fieldNames in create statement will |
// TODO problem with different fieldNames in create statement will |
// overwrite them |
// overwrite them |
if (query.indexOf("*") < 0) |
if (query.indexOf("*") < 0 && create.equals(""))// quick hack for hartmut |
{ |
{ |
int selectEndIndex = query.indexOf("from"); |
int selectEndIndex = query.indexOf("from"); |
StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ","); |
StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ","); |
Line 3830 class Convert
|
Line 3883 class Convert
|
// ****** end Test ****** |
// ****** end Test ****** |
|
|
} |
} |
|
|
|
public final static String generateSuffix(final int step) |
|
{ |
|
String fileString = null; |
|
if (step < 10) |
|
fileString = "00" + step; |
|
else if (step < 100) |
|
fileString = "0" + step; |
|
else |
|
fileString = step + ""; |
|
return fileString; |
|
} |
|
|
} |
} |
|
|