version 1.66, 2004/08/03 11:41:16
|
version 1.68, 2004/08/05 11:17:10
|
Line 1273 class Convert
|
Line 1273 class Convert
|
userDest = database.user; |
userDest = database.user; |
passwdDest = database.passwd; |
passwdDest = database.passwd; |
|
|
synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode); |
synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter); |
} |
} |
} |
} |
// printContents(node3); |
// printContents(node3); |
Line 1897 class Convert
|
Line 1897 class Convert
|
*/ |
*/ |
// TODO implement append,update and delete in one method |
// TODO implement append,update and delete in one method |
// TODO using id based algorithm |
// TODO using id based algorithm |
public static void synchronize(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode) throws Exception |
public static void synchronize(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception |
{ |
{ |
System.out.println(" bin in synchronize!!!"); |
System.out.println(" bin in synchronize!!!"); |
FM2SQL.ProgressDialog dialog = null; |
FM2SQL.ProgressDialog dialog = null; |
Line 2010 class Convert
|
Line 2010 class Convert
|
dialog.title.setText("Check if data is available"); |
dialog.title.setText("Check if data is available"); |
else if (dialog != null) |
else if (dialog != null) |
dialog.title.setText("Check if more data is available"); |
dialog.title.setText("Check if more data is available"); |
myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex), tempQuery, numHits); |
myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex), tempQuery, 0); |
myIdsDest = beanDest.getIDVector(convertText(idField), destTableName, tempQueryDest, numHits); |
myIdsDest = beanDest.getIDVector(convertText(idField), destTableName, tempQueryDest, 0); |
|
//System.out.println("status of remove "+myIds.remove("b015892")); |
if (myIds.isEmpty()) |
if (myIds.isEmpty()) |
break; |
break; |
vec = new Vector(myIds); |
vec = new Vector(myIds); |
Line 2019 class Convert
|
Line 2020 class Convert
|
rowCount = vec.size(); |
rowCount = vec.size(); |
// Deletion will work this way |
// Deletion will work this way |
Vector deleted = new Vector(vec); |
Vector deleted = new Vector(vec); |
linesToDelete = new TreeSet(vecDest); |
|
|
|
TreeSet linesToAppend = new TreeSet(vec); |
TreeSet linesToAppend = new TreeSet(vec); |
|
linesToAppend.addAll(vec); |
|
linesToDelete = new TreeSet(vecDest); |
// remove all lines that are already in dest database |
// remove all lines that are already in dest database |
linesToAppend.removeAll(vecDest); |
linesToAppend.removeAll(vecDest); |
// remove all lines that should not be deleted |
// remove all lines that should not be deleted |
linesToDelete.removeAll(deleted); |
linesToDelete.removeAll(deleted); |
System.out.println("linesToAppend " + linesToAppend + " " + vecDest + " " + destTableName); |
System.out.println("linesToAppend " + linesToAppend + " " + destTableName); |
System.out.println("linesToDelete " + linesToDelete + " " + vecDest + " " + destTableName); |
System.out.println("linesToDelete " + linesToDelete + " " + destTableName); |
System.out.println("ID LIST SIZE " + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIds.size()); |
System.out.println("ID LIST SIZE " + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIds.size()); |
deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls); |
deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls); |
ConversionProperties prop = getFieldNamesAndDestTableName(creates.get(tbIndex).toString(), query, names.get(tbIndex).toString()); |
ConversionProperties prop = getFieldNamesAndDestTableName(creates.get(tbIndex).toString(), query, names.get(tbIndex).toString()); |
StringBuffer insCommand = createInsertCommand(prop.destTableName, prop.fieldNames); |
StringBuffer insCommand = createInsertCommand(prop.destTableName, prop.fieldNames); |
StringBuffer updCommand = createUpdateCommand(prop.destTableName, prop.fieldNames, tempID); |
StringBuffer updCommand = createUpdateCommand(prop.destTableName, prop.fieldNames, tempIDdest); |
StringBuffer delCommand = createDeleteCommand(destTableName, tempID); |
StringBuffer delCommand = createDeleteCommand(destTableName, tempIDdest); |
PreparedStatement insPst = beanDest.getConnection().prepareStatement(insCommand.toString()); |
PreparedStatement insPst = beanDest.getConnection().prepareStatement(insCommand.toString()); |
PreparedStatement updPst = beanDest.getConnection().prepareStatement(updCommand.toString()); |
PreparedStatement updPst = beanDest.getConnection().prepareStatement(updCommand.toString()); |
delPSt = beanDest.getConnection().prepareStatement(delCommand.toString()); |
delPSt = beanDest.getConnection().prepareStatement(delCommand.toString()); |
|
// delPSt.setString(1,"b015892"); |
|
// delPSt.execute(); |
|
// if (true) |
|
// return; |
if (vec.size() <= numIntervalls) |
if (vec.size() <= numIntervalls) |
{ |
{ |
endIndex = 0; |
endIndex = 0; |
Line 2058 class Convert
|
Line 2063 class Convert
|
if (dialog != null) |
if (dialog != null) |
dialog.title.setText("Writing table data ..."); |
dialog.title.setText("Writing table data ..."); |
|
|
performSynchronize(idField, vec, tempQuery, linesToDelete, linesToAppend, insPst, updPst, delPSt, deltaID); |
performSynchronize(idField, vec, tempQuery, linesToDelete, linesToAppend, insPst, updPst, delPSt, deltaID, delimiter); |
// System.out.println("ID LIST SIZE " + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIdsDest.size()); |
// System.out.println("ID LIST SIZE " + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIdsDest.size()); |
endIndex = k + deltaID; |
endIndex = k + deltaID; |
} |
} |
Line 2077 class Convert
|
Line 2082 class Convert
|
System.out.println(tempQuery); |
System.out.println(tempQuery); |
if (dialog != null) |
if (dialog != null) |
dialog.title.setText("Reading table data ..."); |
dialog.title.setText("Reading table data ..."); |
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 ..."); |
performSynchronize(idField, vec, tempQuery, linesToDelete, linesToAppend, insPst, updPst, delPSt, deltaID); |
performSynchronize(idField, vec, tempQuery, linesToDelete, linesToAppend, insPst, updPst, delPSt, deltaID, delimiter); |
// System.out.println("ID LIST SIZE " + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIdsDest.size()); |
// System.out.println("ID LIST SIZE " + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIdsDest.size()); |
} |
} |
// prepare new query for next chunk |
// prepare new query for next chunk |
Line 2090 class Convert
|
Line 2095 class Convert
|
tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'"; |
tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'"; |
|
|
} |
} |
|
|
for (Iterator iter = linesToDelete.iterator(); iter.hasNext();) |
for (Iterator iter = linesToDelete.iterator(); iter.hasNext();) |
{ |
{ |
String id = (String) iter.next(); |
String id = (String) iter.next(); |
Line 2106 class Convert
|
Line 2112 class Convert
|
} catch (Exception e) |
} catch (Exception e) |
{ |
{ |
System.out.println("Error while connecting to database " + e); |
System.out.println("Error while connecting to database " + e); |
|
e.printStackTrace(); |
if (dialog != null) |
if (dialog != null) |
{ |
{ |
dialog.setVisible(false); |
dialog.setVisible(false); |
Line 2136 class Convert
|
Line 2143 class Convert
|
PreparedStatement insPst, |
PreparedStatement insPst, |
PreparedStatement updPst, |
PreparedStatement updPst, |
PreparedStatement delPSt, |
PreparedStatement delPSt, |
int deltaID) |
int deltaID, |
|
String delimiter) |
throws SQLException, ParseException |
throws SQLException, ParseException |
{ |
{ |
Vector[] vectors = bean.getQueryData(tempQuery, deltaID); |
Vector[] vectors = bean.getQueryData(tempQuery, deltaID); |
Line 2146 class Convert
|
Line 2154 class Convert
|
{ |
{ |
Vector line = (Vector) iter.next(); |
Vector line = (Vector) iter.next(); |
Object lineIDIndex = line.get(idIndex); |
Object lineIDIndex = line.get(idIndex); |
|
if (linesToAppend.contains(lineIDIndex)) |
System.out.println("line " + linesToAppend.contains(line.get(idIndex)) + " " + lineIDIndex); |
System.out.println("line " + linesToAppend.contains(line.get(idIndex)) + " " + lineIDIndex); |
if (linesToAppend.contains(lineIDIndex)) |
if (linesToAppend.contains(lineIDIndex)) |
{ |
{ |
for (int l = 0; l < line.size(); ++l) |
for (int l = 0; l < line.size(); ++l) |
{ |
{ |
Object obj = line.get(l); |
Object obj = line.get(l); |
|
if (obj instanceof ArrayList) |
|
obj = formatFileMakerArray((List) obj, delimiter); |
if (obj != null) |
if (obj != null) |
insPst.setString(l + 1, obj.toString()); |
insPst.setString(l + 1, obj.toString()); |
else |
else |
Line 2164 class Convert
|
Line 2175 class Convert
|
for (int l = 0; l < line.size(); ++l) |
for (int l = 0; l < line.size(); ++l) |
{ |
{ |
Object obj = line.get(l); |
Object obj = line.get(l); |
|
if (obj instanceof ArrayList) |
|
obj = formatFileMakerArray((List) obj, delimiter); |
if (obj != null) |
if (obj != null) |
updPst.setString(l + 1, obj.toString()); |
updPst.setString(l + 1, obj.toString()); |
else |
else |