version 1.69, 2004/08/06 11:15:41
|
version 1.75, 2004/08/17 09:12:22
|
Line 41 import java.util.Vector;
|
Line 41 import java.util.Vector;
|
import com.exploringxml.xml.Node; |
import com.exploringxml.xml.Node; |
import com.exploringxml.xml.Xparse; |
import com.exploringxml.xml.Xparse; |
|
|
|
|
class Convert |
class Convert |
{ |
{ |
/**Helper class for index creation |
/**Helper class for index creation |
Line 77 class Convert
|
Line 76 class Convert
|
static boolean batchRun = false; |
static boolean batchRun = false; |
static Vector databases = new Vector(); |
static Vector databases = new Vector(); |
final static int numHits = 5000; |
final static int numHits = 5000; |
final static int numIntervalls = 2; |
final static int numIntervalls = 4; |
|
static boolean debug = true; |
public static void main(String args[]) |
public static void main(String args[]) |
{ |
{ |
/* try |
/* try |
Line 102 class Convert
|
Line 102 class Convert
|
{ |
{ |
e1.printStackTrace(); |
e1.printStackTrace(); |
} |
} |
PrintStream stream = new PrintStream(file); |
PrintStream stream = new PrintStream(file,false); |
// System.setOut(stream); |
if(!debug) |
//System.setErr(stream); |
{ |
|
System.setOut(stream); |
|
System.setErr(stream); |
|
} |
readXMLFile(args[0]); |
readXMLFile(args[0]); |
if (!(new File(args[0]).exists())) |
if (!(new File(args[0]).exists())) |
System.exit(0); |
System.exit(0); |
Line 1308 class Convert
|
Line 1310 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, db.delimiter); |
synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter, new Vector(db.htIndex.values())); |
} |
} |
} |
} |
// printContents(node3); |
// printContents(node3); |
Line 1961 class Convert
|
Line 1963 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, String delimiter) throws Exception |
public static void synchronize(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode, String delimiter, Vector indexList) |
|
throws Exception |
{ |
{ |
System.out.println(" bin in synchronize!!!"); |
System.out.println(" bin in synchronize!!!"); |
FM2SQL.ProgressDialog dialog = null; |
FM2SQL.ProgressDialog dialog = null; |
Line 2058 class Convert
|
Line 2061 class Convert
|
int endIndex = -1; |
int endIndex = -1; |
String tempQuery = query; |
String tempQuery = query; |
String destQuery = query.replaceAll(names.get(tbIndex).toString(), destTableName); |
String destQuery = query.replaceAll(names.get(tbIndex).toString(), destTableName); |
|
destQuery = removeLayoutPartFromQuery(destQuery,layouts.get(tbIndex).toString()); |
|
// TODO remove layout part for destQuery |
String tempQueryDest = destQuery; |
String tempQueryDest = destQuery; |
// remove extra query parts destQuery.substring(0,destQuery.lastIndexOf(destTableName)+destTableName.length()+1); |
// remove extra query parts destQuery.substring(0,destQuery.lastIndexOf(destTableName)+destTableName.length()+1); |
System.out.println("new Query " + tempQueryDest); |
System.out.println("new Query " + tempQueryDest); |
Line 2159 class Convert
|
Line 2164 class Convert
|
tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'"; |
tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'"; |
|
|
} |
} |
|
String tableName = names.get(tbIndex).toString(); |
|
IndexList idList = (IndexList) indexList.get(0); |
|
System.out.println("found list " + idList); |
|
Statement stm = beanDest.getConnection().createStatement(); |
|
Vector destTables = beanDest.getTableNames(); |
|
System.out.println("tempQueryDest"+tempQueryDest); |
|
beanDest.makeQuery(tempQueryDest,0); |
|
for (Iterator iter = idList.iterator(); iter.hasNext();) |
|
{ |
|
String indexField = (String) iter.next(); |
|
indexField = convertText(indexField); |
|
String indexName = destTableName + "_" + indexField; |
|
if (destTables.contains(indexName)) |
|
{ |
|
stm.execute("DROP INDEX "+destTableName+"_"+indexField); |
|
// continue; |
|
} |
|
|
|
String type = beanDest.getColumnType(indexField).toLowerCase(); |
|
// System.out.println(indexField+" "+type+" "+(type.indexOf("text") >= 0 || type.indexOf("varchar") >= 0 || type.indexOf("char") >= 0)); |
|
if (type.indexOf("text") >= 0 || type.indexOf("varchar") >= 0 || type.indexOf("char") >= 0) |
|
stm.execute("CREATE INDEX " + indexName + " ON " + destTableName + "(LOWER(" + indexField + "))"); |
|
else |
|
stm.execute("CREATE INDEX " + destTableName + "_" + indexField + " ON " + destTableName + "(" + indexField + ")"); |
|
|
|
// stm.execute("DROP INDEX "+destTableName+"_"+indexField); |
|
|
|
} |
|
// CREATE UNIQUE INDEX title_idx ON films (title); |
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 2198 class Convert
|
Line 2231 class Convert
|
dialog.setVisible(false); |
dialog.setVisible(false); |
} |
} |
} |
} |
|
/** |
|
* @param destQuery |
|
* @param string |
|
* @return |
|
*/ |
|
private static String removeLayoutPartFromQuery(String destQuery, String layoutName) |
|
{ |
|
String removeString ="layout "+bean.getQC()+layoutName+bean.getQC(); |
|
destQuery =destQuery.replaceFirst(removeString,""); |
|
System.out.println("destQuery change to "+destQuery); |
|
return destQuery; |
|
} |
private static void performSynchronize( |
private static void performSynchronize( |
String idField, |
String idField, |
Vector vec, |
Vector vec, |
Line 2247 class Convert
|
Line 2292 class Convert
|
updPst.setNull(l + 1, Types.NULL); |
updPst.setNull(l + 1, Types.NULL); |
} |
} |
updPst.setString(line.size() + 1, line.get(idIndex).toString()); |
updPst.setString(line.size() + 1, line.get(idIndex).toString()); |
|
//updPst.addBatch(); |
updPst.execute(); |
updPst.execute(); |
|
|
} |
} |
} |
} |
|
//updPst.executeBatch(); |
} // to method |
} // to method |
|
|
/** |
/** |
Line 3773 class Convert
|
Line 3818 class Convert
|
while (tokenizer.hasMoreTokens()) |
while (tokenizer.hasMoreTokens()) |
{ |
{ |
String fieldName = tokenizer.nextToken().trim(); |
String fieldName = tokenizer.nextToken().trim(); |
fieldNames[fieldIndex] = convertText(fieldName); |
fieldNames[fieldIndex] =beanDest.getQC() + convertText(fieldName)+beanDest.getQC(); |
// System.out.println("field "+ fieldNames[fieldIndex]); |
// System.out.println("field "+ fieldNames[fieldIndex]); |
fieldIndex++; |
fieldIndex++; |
} |
} |
Line 3786 class Convert
|
Line 3831 class Convert
|
for (Iterator iter = fieldNamesVec.iterator(); iter.hasNext();) |
for (Iterator iter = fieldNamesVec.iterator(); iter.hasNext();) |
{ |
{ |
String element = (String) iter.next(); |
String element = (String) iter.next(); |
fieldNames[++fieldIndex] = bean.getQC() + convertText(element) + bean.getQC(); |
fieldNames[++fieldIndex] = beanDest.getQC() + convertText(element) + beanDest.getQC(); |
// System.out.println("field " + fieldNames[fieldIndex]); |
// System.out.println("field " + fieldNames[fieldIndex]); |
} |
} |
} |
} |