version 1.41, 2004/03/01 12:37:10
|
version 1.45, 2004/03/09 12:34:09
|
Line 59 class Convert
|
Line 59 class Convert
|
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); |
} |
} |
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; |
bean = source; |
beanDest = destination; |
beanDest = destination; |
convert(null,null,names,layouts,selects,creates,ids,mode); |
convert(null,null,names,layouts,selects,creates,ids,mode,delimiter); |
if(true) return; |
if(true) return; |
StringBuffer command = null; |
StringBuffer command = null; |
try |
try |
Line 279 class Convert
|
Line 279 class Convert
|
for (tbIndex = 0; tbIndex < names.size(); ++tbIndex) |
for (tbIndex = 0; tbIndex < names.size(); ++tbIndex) |
{ |
{ |
Vector[] result = null; |
Vector[] result = null; |
|
String destTableName = ""; |
try |
try |
{ |
{ |
query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC(); |
query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC(); |
Line 305 class Convert
|
Line 306 class Convert
|
{ |
{ |
continue; |
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("jdbc:postgresql://erebos/test3"); |
beanDest.setConnection(destination); |
beanDest.setConnection(destination); |
|
|
Line 328 class Convert
|
Line 341 class Convert
|
|
|
command.append("UPDATE "); |
command.append("UPDATE "); |
command.append(beanDest.getQC()); |
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(beanDest.getQC()); |
command.append(" SET "); |
command.append(" SET "); |
|
|
Line 435 class Convert
|
Line 449 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; |
FM2SQL.ProgressDialog dialog = null; |
Line 528 class Convert
|
Line 542 class Convert
|
// System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString())); |
// System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString())); |
stm = beanDest.getConnection().createStatement(); |
stm = beanDest.getConnection().createStatement(); |
// System.exit(0); |
// 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(); |
String create =creates.get(tbIndex).toString().toLowerCase(); |
Line 541 class Convert
|
Line 555 class Convert
|
} else |
} else |
destTableName = convertText(names.get(tbIndex).toString()); |
destTableName = convertText(names.get(tbIndex).toString()); |
|
|
|
if (mode == Convert.DataBase.CONVERT_MODE) |
|
{ |
|
|
if (tables.indexOf(destTableName) >= 0) |
if (tables.indexOf(destTableName) >= 0) |
{ |
{ |
stm.executeUpdate("drop table " + beanDest.getQC() + destTableName + beanDest.getQC()); |
stm.executeUpdate("drop table " + beanDest.getQC() + destTableName + beanDest.getQC()); |
Line 667 class Convert
|
Line 684 class Convert
|
if(dialog!=null) |
if(dialog!=null) |
dialog.title.setText("Writing table data ..."); |
dialog.title.setText("Writing table data ..."); |
|
|
command = writeDatainDestTable(dialog, command, k, pstm, rowCount); |
command = writeDatainDestTable(dialog, command, k, pstm, rowCount,delimiter); |
endIndex = k + deltaID; |
endIndex = k + deltaID; |
} |
} |
System.out.println(endIndex); |
System.out.println(endIndex); |
Line 688 class Convert
|
Line 705 class Convert
|
bean.makeQuery(tempQuery, 0); |
bean.makeQuery(tempQuery, 0); |
if(dialog!=null) |
if(dialog!=null) |
dialog.title.setText("Writing table data ..."); |
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 |
// prepare new query for next chunk |
if (query.indexOf("where") > 0) |
if (query.indexOf("where") > 0) |
Line 705 class Convert
|
Line 722 class Convert
|
long startTime = System.currentTimeMillis(); |
long startTime = System.currentTimeMillis(); |
|
|
bean.makeQuery(query, 0); |
bean.makeQuery(query, 0); |
command = writeDatainDestTable(dialog, command, j, pstm, rowCount); |
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 748 class Convert
|
Line 765 class Convert
|
* @throws Exception |
* @throws Exception |
* @throws SQLException |
* @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; |
Vector row; |
while ((row = bean.getNextRow()) != null) |
while ((row = bean.getNextRow()) != null) |
Line 795 class Convert
|
Line 812 class Convert
|
obj = row.get(k); |
obj = row.get(k); |
if (obj instanceof ArrayList) |
if (obj instanceof ArrayList) |
if (obj instanceof ArrayList) |
if (obj instanceof ArrayList) |
obj = formatFileMakerArray((List) obj," | "); |
obj = formatFileMakerArray((List) obj,delimiter); |
|
|
String str = (obj == null) ? "NULL" : obj.toString(); |
String str = (obj == null) ? "NULL" : obj.toString(); |
if (!str.equals("NULL")) |
if (!str.equals("NULL")) |
Line 1079 class Convert
|
Line 1096 class Convert
|
Vector selects = new Vector(); |
Vector selects = new Vector(); |
Vector creates = new Vector(); |
Vector creates = new Vector(); |
Vector ids = new Vector(); |
Vector ids = new Vector(); |
|
String delimiter = "|"; |
int mode = -1; |
int mode = -1; |
|
|
try |
try |
Line 1103 class Convert
|
Line 1121 class Convert
|
Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 }); |
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 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 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) |
if (node3 == null) |
throw new Error("parse error database tag missing"); |
throw new Error("parse error database tag missing"); |
if (node == null) |
if (node == null) |
Line 1112 class Convert
|
Line 1130 class Convert
|
throw new Error("parse error user tag missing"); |
throw new Error("parse error user tag missing"); |
if (node2 == null) |
if (node2 == null) |
throw new Error("parse error password tag missing"); |
throw new Error("parse error password tag missing"); |
|
if(delimiterNode!=null) delimiter = delimiterNode.getCharacters(); |
String url = node.getCharacters(); |
String url = node.getCharacters(); |
String user = node1.getCharacters(); |
String user = node1.getCharacters(); |
String password = node2.getCharacters(); |
String password = node2.getCharacters(); |
Line 1179 class Convert
|
Line 1198 class Convert
|
creates.add(""); |
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(); |
DBBean database = new DBBean(); |
// parse dataBase |
// parse dataBase |
Line 1197 class Convert
|
Line 1218 class Convert
|
{ |
{ |
DataBase db = (DataBase) iter.next(); |
DataBase db = (DataBase) iter.next(); |
if (mode != DataBase.UPDATE_MODE) |
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 |
else |
update(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode); |
update(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode); |
|
|
Line 1245 class Convert
|
Line 1266 class Convert
|
Vector selects = new Vector(); |
Vector selects = new Vector(); |
Vector creates = new Vector(); |
Vector creates = new Vector(); |
Vector ids = new Vector(); |
Vector ids = new Vector(); |
|
String delimiter = "|"; |
int mode = -1; |
int mode = -1; |
try |
try |
{ |
{ |
Line 1269 class Convert
|
Line 1290 class Convert
|
Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 }); |
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 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 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) |
if (node3 == null) |
throw new Error("parse error database tag missing"); |
throw new Error("parse error database tag missing"); |
if (node == null) |
if (node == null) |
Line 1297 class Convert
|
Line 1321 class Convert
|
mode = DataBase.APPEND_MODE; |
mode = DataBase.APPEND_MODE; |
else if (modeString.equals("update")) |
else if (modeString.equals("update")) |
mode = DataBase.UPDATE_MODE; |
mode = DataBase.UPDATE_MODE; |
|
|
// if(node3!=null) |
// if(node3!=null) |
// System.out.println(node3.name); |
// System.out.println(node3.name); |
|
|
Line 1347 class Convert
|
Line 1370 class Convert
|
creates.add(""); |
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(); |
DBBean database = new DBBean(); |
// parse dataBase |
// parse dataBase |
Line 1454 class Convert
|
Line 1479 class Convert
|
Vector layouts; |
Vector layouts; |
Vector tables; |
Vector tables; |
Vector ids; |
Vector ids; |
|
String delimiter = "//"; |
final static int CONVERT_MODE = 1; |
final static int CONVERT_MODE = 1; |
final static int APPEND_MODE = 2; |
final static int APPEND_MODE = 2; |
final static int UPDATE_MODE = 3; |
final static int UPDATE_MODE = 3; |
Line 1473 class Convert
|
Line 1499 class Convert
|
this.bean.setIDVector(ids); |
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 |
* * @param buffr |
* @throws Exception |
* @throws Exception |
*/ |
*/ |
Line 1484 class Convert
|
Line 1510 class Convert
|
buffr.write(" <url>" + bean.url + "</url>\n"); |
buffr.write(" <url>" + bean.url + "</url>\n"); |
buffr.write(" <user>" + bean.user + "</user>\n"); |
buffr.write(" <user>" + bean.user + "</user>\n"); |
buffr.write(" <password>" + bean.passwd + "</password>\n"); |
buffr.write(" <password>" + bean.passwd + "</password>\n"); |
|
buffr.write(" <delimiter>"+delimiter+"</delimiter>\n"); |
String modeString = ""; |
String modeString = ""; |
if (mode == CONVERT_MODE) |
if (mode == CONVERT_MODE) |
modeString = "convert"; |
modeString = "convert"; |