--- FM2SQL/Attic/Convert.java 2004/08/08 12:01:41 1.70 +++ FM2SQL/Attic/Convert.java 2004/08/09 11:36:18 1.71 @@ -41,7 +41,6 @@ import java.util.Vector; import com.exploringxml.xml.Node; import com.exploringxml.xml.Xparse; - class Convert { /**Helper class for index creation @@ -57,7 +56,7 @@ class Convert for (Iterator iter = this.iterator(); iter.hasNext();) { String element = (String) iter.next(); - if (count < elementCount-1) + if (count < elementCount - 1) { buff.append(element).append(", "); count++; @@ -1153,7 +1152,7 @@ class Convert Vector selects = new Vector(); Vector creates = new Vector(); Vector ids = new Vector(); - Vector indexListVec= new Vector(); + Vector indexListVec = new Vector(); String delimiter = "|"; int mode = -1; @@ -1173,7 +1172,7 @@ class Convert selects = new Vector(); creates = new Vector(); ids = new Vector(); - indexListVec= new Vector(); + indexListVec = new Vector(); // parse dataBase Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 }); Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 }); @@ -1249,7 +1248,7 @@ class Convert String layout = (String) node4.attributes.get("layout"); String id = (String) node4.attributes.get("id"); String indexList = (String) node4.attributes.get("indexList"); - + System.out.println("id was " + id); if (name == null) throw new Error("parse error required table tag attribute name missing"); @@ -1257,13 +1256,13 @@ class Convert layout = ""; if (id == null) id = ""; - if(indexList==null) - indexList=""; + if (indexList == null) + indexList = ""; if (name.equals("")) throw new Error("parse error table tag attribute must not be empty"); tables.add(name); layouts.add(layout); - + ids.add(id); indexListVec.add(indexList); String query = (node5 == null) ? "" : node5.getCharacters(); @@ -1308,7 +1307,7 @@ class Convert 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); + 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); @@ -1640,10 +1639,10 @@ class Convert */ public void buildIndexTable(Vector indexListVec) { - for (int i = 0; i < tables.size(); i++) + for (int i = 0; i < tables.size(); i++) { - fillIndexList((String)tables.get(i),(String)indexListVec.get(i)); - } + fillIndexList((String) tables.get(i), (String) indexListVec.get(i)); + } } /** * writes the data contained in this object to the buffered writer @@ -1701,8 +1700,8 @@ class Convert indexList.add(tokenizer.nextToken()); } System.out.println(indexList); - - htIndex.put(table, indexList); + + htIndex.put(table, indexList); } public String toString() { @@ -1961,7 +1960,8 @@ class Convert */ // TODO implement append,update and delete in one method // 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!!!"); FM2SQL.ProgressDialog dialog = null; @@ -2159,7 +2159,34 @@ class Convert 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(); + 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();) { String id = (String) iter.next();