version 1.6, 2005/03/24 12:50:19
|
version 1.10, 2005/04/19 10:49:05
|
Line 119 class Convert
|
Line 119 class Convert
|
|
|
final static int numIntervalls = 4; |
final static int numIntervalls = 4; |
|
|
static boolean debug = true; |
static boolean debug = !false; |
|
|
static boolean isGUI = true; |
static boolean isGUI = true; |
|
|
Line 133 class Convert
|
Line 133 class Convert
|
|
|
static Vector postSQLCommands = new Vector(); |
static Vector postSQLCommands = new Vector(); |
|
|
|
static final String versionID = new String("FM2SQL Version 0.9.1b\n"); |
|
|
|
private static boolean noError = false; |
|
|
public static void main(String args[]) throws IOException |
public static void main(String args[]) throws IOException |
{ |
{ |
/* |
/* |
Line 142 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.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 242 class Convert
|
Line 264 class Convert
|
String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); |
String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); |
query = (selects != null) ? selects.get(tbIndex).toString() : query; |
query = (selects != null) ? selects.get(tbIndex).toString() : query; |
// if vectors[1].get(i) != null) |
// if vectors[1].get(i) != null) |
if (layout != "") |
if (!layout.equals("")) |
{ |
{ |
|
|
query = addLayoutToQuery(names, query, tbIndex, layout); |
query = addLayoutToQuery(names, query, tbIndex, layout); |
|
|
} |
} |
Line 421 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 466 class Convert
|
Line 489 class Convert
|
String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); |
String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); |
query = (selects != null) ? selects.get(tbIndex).toString() : "select * from " |
query = (selects != null) ? selects.get(tbIndex).toString() : "select * from " |
+ bean.getQC() + names.get(tbIndex).toString() + bean.getQC(); |
+ bean.getQC() + names.get(tbIndex).toString() + bean.getQC(); |
if (layout != "") |
if (layout.intern() != "") |
{ |
{ |
query = addLayoutToQuery(names, query, tbIndex, layout); |
query = addLayoutToQuery(names, query, tbIndex, layout); |
|
|
Line 506 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 515 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 529 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 581 class Convert
|
Line 607 class Convert
|
command.append(") "); |
command.append(") "); |
|
|
command.append(" values ( "); |
command.append(" values ( "); |
|
|
// add a question marks for every field |
// add a question marks for every field |
for (int i = 0; i < bean.getColumnNames().size() - 1; ++i) |
for (int i = 0; i < bean.getColumnNames().size() - 1; ++i) |
command.append("?,"); |
command.append("?,"); |
Line 678 class Convert
|
Line 703 class Convert
|
long startTime = System.currentTimeMillis(); |
long startTime = System.currentTimeMillis(); |
|
|
bean.makeQuery(query, 0); |
bean.makeQuery(query, 0); |
|
System.err.println("query for whole table done"); |
command = writeDatainDestTable(dialog, command, j, pstm, rowCount, delimiter); |
command = writeDatainDestTable(dialog, command, j, pstm, rowCount, delimiter); |
long endTime = System.currentTimeMillis(); |
long endTime = System.currentTimeMillis(); |
System.out.println("Time for old convert elapsed " + (endTime - startTime)); |
System.out.println("Time for old convert elapsed " + (endTime - startTime)); |
Line 685 class Convert
|
Line 711 class Convert
|
} |
} |
if (isGUI) |
if (isGUI) |
resetGUI(dialog); |
resetGUI(dialog); |
|
noError = true; |
} |
} |
} catch (Exception e) |
} catch (Exception e) |
{ |
{ |
System.out.println("Error while connecting to database " + e); |
System.out.println("Error while connecting to database " + e.getMessage()); |
|
noError = false; |
if (isGUI) |
if (isGUI) |
{ |
{ |
showExceptionDialog(dialog, command, e); |
showExceptionDialog(dialog, command, e); |
Line 698 class Convert
|
Line 726 class Convert
|
e.printStackTrace(); |
e.printStackTrace(); |
|
|
} |
} |
|
} catch (Error e) |
|
{ |
|
System.out.println(e); |
|
e.printStackTrace(); |
} |
} |
|
|
} |
} |
Line 1008 class Convert
|
Line 1040 class Convert
|
sqlCommand.executeCommand(); |
sqlCommand.executeCommand(); |
} |
} |
int mode = db.mode; |
int mode = db.mode; |
|
if (mode == DataBase.CONVERT_TEMP_MODE) |
|
{ |
|
convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, |
|
mode, db.delimiter); |
|
if (noError) |
|
{ |
|
System.out.println("no Error occured "); |
|
// db.bean.setURL(database.url); |
|
// db.bean.setUserAndPasswd(database.user,database.passwd); |
|
// |
|
// Convert.user = db.bean.user; |
|
// Convert.passwd = db.bean.passwd; |
|
// userDest = database.user; |
|
// passwdDest = database.passwd; |
|
// synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, |
|
// db.ids, mode, db.delimiter, new Vector(db.htIndex.values())); |
|
} |
|
} |
if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE) |
if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_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); |
Line 1162 class Convert
|
Line 1212 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 1203 class Convert
|
Line 1256 class Convert
|
id = ""; |
id = ""; |
if (name.equals("")) |
if (name.equals("")) |
throw new Error("parse error table tag attribute must not be empty"); |
throw new Error("parse error table tag attribute must not be empty"); |
tables.add(name); |
tables.add(name.intern()); |
layouts.add(layout); |
layouts.add(layout.intern()); |
ids.add(id); |
ids.add(id.intern()); |
String query = (node5 == null) ? "" : node5.getCharacters(); |
String query = (node5 == null) ? "" : node5.getCharacters(); |
if (query.equals("")) |
if (query.equals("")) |
System.err.println("Warning empty select tag or select tag missing !!"); |
System.err.println("Warning empty select tag or select tag missing !!"); |
Line 1449 class Convert
|
Line 1502 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 1515 class Convert
|
Line 1570 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 1526 class Convert
|
Line 1582 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 3657 class Convert
|
Line 3714 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 3696 class Convert
|
Line 3753 class Convert
|
// retrieve field_names from select statement |
// retrieve field_names from select statement |
if (query.indexOf("*") < 0) |
if (query.indexOf("*") < 0) |
{ |
{ |
int selectEndIndex = query.indexOf("from"); |
int selectEndIndex = query.lastIndexOf("from"); |
StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ","); |
StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ","); |
int numFields = tokenizer.countTokens(); |
int numFields = tokenizer.countTokens(); |
fieldNames = new String[numFields]; |
fieldNames = new String[numFields]; |
Line 3704 class Convert
|
Line 3761 class Convert
|
while (tokenizer.hasMoreTokens()) |
while (tokenizer.hasMoreTokens()) |
{ |
{ |
String fieldName = tokenizer.nextToken().trim(); |
String fieldName = tokenizer.nextToken().trim(); |
|
String text = convertText(fieldName); |
|
if (text.indexOf("\"") >= 0) |
|
fieldNames[fieldIndex] = convertText(fieldName); |
|
else |
fieldNames[fieldIndex] = beanDest.getQC() + convertText(fieldName) + beanDest.getQC(); |
fieldNames[fieldIndex] = beanDest.getQC() + convertText(fieldName) + beanDest.getQC(); |
// System.out.println("field "+ fieldNames[fieldIndex]); |
// System.out.println("field "+ fieldNames[fieldIndex]); |
fieldIndex++; |
fieldIndex++; |
Line 3849 class Convert
|
Line 3910 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; |
|
} |
|
|
} |
} |
|
|