version 1.40, 2004/02/27 11:34:53
|
version 1.44, 2004/03/03 12:14:47
|
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 190 class Convert
|
Line 190 class Convert
|
{ |
{ |
obj = row.get(k); |
obj = row.get(k); |
if (obj instanceof ArrayList) |
if (obj instanceof ArrayList) |
obj = ((List) obj).get(0); |
obj = formatFileMakerArray((List) obj,"\n"); |
String str = (obj == null) ? "NULL" : obj.toString(); |
String str = (obj == null) ? "NULL" : obj.toString(); |
if (!str.equals("NULL")) |
if (!str.equals("NULL")) |
pstm.setString(k + 1, str); |
pstm.setString(k + 1, str); |
Line 221 class Convert
|
Line 221 class Convert
|
|
|
// dialog.setVisible(false); |
// dialog.setVisible(false); |
} |
} |
|
public static String formatFileMakerArray(List list, String delimiter) |
|
{ |
|
StringBuffer formattedString = new StringBuffer(); |
|
for(int i=0;i<list.size();++i) |
|
{ |
|
formattedString.append(list.get(i).toString()); |
|
if(i<list.size()-1) |
|
formattedString.append(delimiter); |
|
} |
|
return formattedString.toString(); |
|
} |
/** |
/** |
* Method for SQL UPDATE |
* Method for SQL UPDATE |
* @param source |
* @param source |
Line 425 class Convert
|
Line 435 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 657 class Convert
|
Line 667 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 678 class Convert
|
Line 688 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 695 class Convert
|
Line 705 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 738 class Convert
|
Line 748 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 784 class Convert
|
Line 794 class Convert
|
{ |
{ |
obj = row.get(k); |
obj = row.get(k); |
if (obj instanceof ArrayList) |
if (obj instanceof ArrayList) |
obj = ((List) obj).get(0); |
if (obj instanceof ArrayList) |
|
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")) |
pstm.setString(k + 1, str); |
pstm.setString(k + 1, str); |
Line 1067 class Convert
|
Line 1079 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 1091 class Convert
|
Line 1104 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 1100 class Convert
|
Line 1113 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 1167 class Convert
|
Line 1181 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 1185 class Convert
|
Line 1201 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 1233 class Convert
|
Line 1249 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 1257 class Convert
|
Line 1273 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 1285 class Convert
|
Line 1304 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 1335 class Convert
|
Line 1353 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 1442 class Convert
|
Line 1462 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 1461 class Convert
|
Line 1482 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 1472 class Convert
|
Line 1493 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"; |