version 1.8, 2005/04/12 10:58:54
|
version 1.12, 2005/04/22 11:03:53
|
Line 29 import java.sql.ResultSet;
|
Line 29 import java.sql.ResultSet;
|
import java.sql.SQLException; |
import java.sql.SQLException; |
import java.sql.Statement; |
import java.sql.Statement; |
import java.sql.Types; |
import java.sql.Types; |
|
import java.text.DateFormat; |
import java.text.ParseException; |
import java.text.ParseException; |
import java.util.ArrayList; |
import java.util.ArrayList; |
import java.util.Enumeration; |
import java.util.Date; |
import java.util.Hashtable; |
import java.util.Hashtable; |
import java.util.Iterator; |
import java.util.Iterator; |
import java.util.List; |
import java.util.List; |
import java.util.Properties; |
import java.util.Locale; |
import java.util.StringTokenizer; |
import java.util.StringTokenizer; |
import java.util.TreeSet; |
import java.util.TreeSet; |
import java.util.Vector; |
import java.util.Vector; |
Line 49 import com.exploringxml.xml.Xparse;
|
Line 50 import com.exploringxml.xml.Xparse;
|
|
|
class Convert |
class Convert |
{ |
{ |
|
private static final String _TEMP = "_temp"; |
|
|
/** |
/** |
* Helper class for index creation |
* Helper class for index creation |
* |
* |
Line 135 class Convert
|
Line 138 class Convert
|
|
|
static Vector postSQLCommands = new Vector(); |
static Vector postSQLCommands = new Vector(); |
|
|
static final String versionID = new String("FM2SQL Version 0.9.0b\n"); |
static final String versionID = new String("FM2SQL Version 0.9.5b\n"); |
|
|
|
private static boolean noError = false; |
|
|
public static void main(String args[]) throws IOException |
public static void main(String args[]) throws IOException |
{ |
{ |
|
// DateFormat d = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, |
|
// Locale.GERMANY); |
|
// System.out.println(convertText("rogoistSuper" + "_" + d.format(new Date()).replace(':', '_'))); |
|
|
/* |
/* |
* try { //byte[] b = "�".getBytes("UTF-8"); // |
* try { //byte[] b = "�".getBytes("UTF-8"); // |
* System.out.println("QueryString " +b[0]+" "+b[1]+(new |
* System.out.println("QueryString " +b[0]+" "+b[1]+(new |
Line 153 class Convert
|
Line 162 class Convert
|
{ |
{ |
System.out.println(versionID); |
System.out.println(versionID); |
System.out.println("Usage: java Convert <xml config file>"); |
System.out.println("Usage: java Convert <xml config file>"); |
System.out.println("Log file will be written in "+tmpPath.getCanonicalPath()+" folder "); |
|
System.exit(-1); |
System.exit(-1); |
} |
} |
File temp = null; |
File temp = null; |
Line 265 class Convert
|
Line 273 class Convert
|
String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); |
String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); |
query = (selects != null) ? selects.get(tbIndex).toString() : query; |
query = (selects != null) ? selects.get(tbIndex).toString() : query; |
// if vectors[1].get(i) != null) |
// if vectors[1].get(i) != null) |
if (layout != "") |
if (!layout.equals("")) |
{ |
{ |
|
|
query = addLayoutToQuery(names, query, tbIndex, layout); |
query = addLayoutToQuery(names, query, tbIndex, layout); |
|
|
} |
} |
Line 489 class Convert
|
Line 498 class Convert
|
String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); |
String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); |
query = (selects != null) ? selects.get(tbIndex).toString() : "select * from " |
query = (selects != null) ? selects.get(tbIndex).toString() : "select * from " |
+ bean.getQC() + names.get(tbIndex).toString() + bean.getQC(); |
+ bean.getQC() + names.get(tbIndex).toString() + bean.getQC(); |
if (layout != "") |
if (layout.intern() != "") |
{ |
{ |
query = addLayoutToQuery(names, query, tbIndex, layout); |
query = addLayoutToQuery(names, query, tbIndex, layout); |
|
|
Line 531 class Convert
|
Line 540 class Convert
|
destTableName = prop.destTableName; |
destTableName = prop.destTableName; |
if (mode == Convert.DataBase.CONVERT_TEMP_MODE) |
if (mode == Convert.DataBase.CONVERT_TEMP_MODE) |
{ |
{ |
destTableName += "_temp"; |
destTableName += _TEMP; |
} |
} |
fieldNames = prop.fieldNames; |
fieldNames = prop.fieldNames; |
if (mode == Convert.DataBase.CONVERT_MODE || mode == Convert.DataBase.CONVERT_TEMP_MODE) |
if (mode == Convert.DataBase.CONVERT_MODE || mode == Convert.DataBase.CONVERT_TEMP_MODE) |
Line 607 class Convert
|
Line 616 class Convert
|
command.append(") "); |
command.append(") "); |
|
|
command.append(" values ( "); |
command.append(" values ( "); |
|
|
// add a question marks for every field |
// add a question marks for every field |
for (int i = 0; i < bean.getColumnNames().size() - 1; ++i) |
for (int i = 0; i < bean.getColumnNames().size() - 1; ++i) |
command.append("?,"); |
command.append("?,"); |
Line 704 class Convert
|
Line 712 class Convert
|
long startTime = System.currentTimeMillis(); |
long startTime = System.currentTimeMillis(); |
|
|
bean.makeQuery(query, 0); |
bean.makeQuery(query, 0); |
|
System.err.println("query for whole table done"); |
command = writeDatainDestTable(dialog, command, j, pstm, rowCount, delimiter); |
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 711 class Convert
|
Line 720 class Convert
|
} |
} |
if (isGUI) |
if (isGUI) |
resetGUI(dialog); |
resetGUI(dialog); |
|
noError = true; |
|
if (mode == Convert.DataBase.CONVERT_TEMP_MODE) |
|
{ |
|
String originalName = destTableName.split(_TEMP)[0]; |
|
// TODO |
|
if (beanDest.getTableNames().contains(originalName)) |
|
{ |
|
DateFormat d = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
|
d.setTimeZone(java.util.TimeZone.getTimeZone("CET")); |
|
|
|
String date = d.format(new Date()); |
|
date = date.replace(':', '_'); |
|
renameTable(beanDest, addQuotes(beanDest, originalName), addQuotes(beanDest, |
|
convertText(originalName + "_" + date))); |
|
} |
|
renameTable(beanDest, addQuotes(beanDest, destTableName), addQuotes(beanDest, |
|
originalName)); |
|
} |
} |
} |
} catch (Exception e) |
} catch (Exception e) |
{ |
{ |
System.out.println("Error while connecting to database " + e); |
System.out.println("Error while connecting to database " + e.getMessage()); |
|
noError = false; |
if (isGUI) |
if (isGUI) |
{ |
{ |
showExceptionDialog(dialog, command, e); |
showExceptionDialog(dialog, command, e); |
Line 724 class Convert
|
Line 752 class Convert
|
e.printStackTrace(); |
e.printStackTrace(); |
|
|
} |
} |
|
} catch (Error e) |
|
{ |
|
noError = false; |
|
|
|
System.out.println(e); |
|
e.printStackTrace(); |
|
} |
|
|
} |
} |
|
|
|
/** |
|
* |
|
* @param beanDest2 |
|
* @param originalName |
|
* @return |
|
*/ |
|
private static String addQuotes(DBBean bean, String originalName) |
|
{ |
|
return bean.getQC() + originalName + bean.getQC(); |
} |
} |
|
|
/** |
/** |
Line 1034 class Convert
|
Line 1079 class Convert
|
sqlCommand.executeCommand(); |
sqlCommand.executeCommand(); |
} |
} |
int mode = db.mode; |
int mode = db.mode; |
if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE |
if (mode == DataBase.CONVERT_TEMP_MODE) |
|| mode == DataBase.CONVERT_TEMP_MODE) |
{ |
|
convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, |
|
mode, db.delimiter); |
|
if (noError) |
|
{ |
|
System.out.println("no Error occured "); |
|
// db.bean.setURL(database.url); |
|
// db.bean.setUserAndPasswd(database.user,database.passwd); |
|
// |
|
// Convert.user = db.bean.user; |
|
// Convert.passwd = db.bean.passwd; |
|
// 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, new Vector(db.htIndex.values())); |
|
} |
|
} |
|
if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE) |
convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, |
convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, |
mode, db.delimiter); |
mode, db.delimiter); |
else if (mode == DataBase.UPDATE_MODE) |
else if (mode == DataBase.UPDATE_MODE) |
Line 1083 class Convert
|
Line 1145 class Convert
|
} |
} |
} |
} |
|
|
|
/** |
|
* |
|
* @param database |
|
* @param db |
|
* @throws Exception |
|
* @throws SQLException |
|
*/ |
|
private static void renameTable(DBBean database, String sourceTable, String destTable) |
|
throws SQLException, Exception |
|
{ |
|
String command = "alter table " + sourceTable + " rename " + " to " + destTable; |
|
SQLCommand sqlCommand = new SQLCommand(database, command); |
|
sqlCommand.executeCommand(); |
|
} |
|
|
public static Vector getXMLConfig(StringBuffer sb) |
public static Vector getXMLConfig(StringBuffer sb) |
{ |
{ |
|
|
Line 1233 class Convert
|
Line 1310 class Convert
|
id = ""; |
id = ""; |
if (name.equals("")) |
if (name.equals("")) |
throw new Error("parse error table tag attribute must not be empty"); |
throw new Error("parse error table tag attribute must not be empty"); |
tables.add(name); |
tables.add(name.intern()); |
layouts.add(layout); |
layouts.add(layout.intern()); |
ids.add(id); |
ids.add(id.intern()); |
String query = (node5 == null) ? "" : node5.getCharacters(); |
String query = (node5 == null) ? "" : node5.getCharacters(); |
if (query.equals("")) |
if (query.equals("")) |
System.err.println("Warning empty select tag or select tag missing !!"); |
System.err.println("Warning empty select tag or select tag missing !!"); |
Line 3730 class Convert
|
Line 3807 class Convert
|
// retrieve field_names from select statement |
// retrieve field_names from select statement |
if (query.indexOf("*") < 0) |
if (query.indexOf("*") < 0) |
{ |
{ |
int selectEndIndex = query.indexOf("from"); |
int selectEndIndex = query.lastIndexOf("from"); |
StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ","); |
StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ","); |
int numFields = tokenizer.countTokens(); |
int numFields = tokenizer.countTokens(); |
fieldNames = new String[numFields]; |
fieldNames = new String[numFields]; |
Line 3738 class Convert
|
Line 3815 class Convert
|
while (tokenizer.hasMoreTokens()) |
while (tokenizer.hasMoreTokens()) |
{ |
{ |
String fieldName = tokenizer.nextToken().trim(); |
String fieldName = tokenizer.nextToken().trim(); |
|
String text = convertText(fieldName); |
|
if (text.indexOf("\"") >= 0) |
|
fieldNames[fieldIndex] = convertText(fieldName); |
|
else |
fieldNames[fieldIndex] = beanDest.getQC() + convertText(fieldName) + beanDest.getQC(); |
fieldNames[fieldIndex] = beanDest.getQC() + convertText(fieldName) + beanDest.getQC(); |
// System.out.println("field "+ fieldNames[fieldIndex]); |
// System.out.println("field "+ fieldNames[fieldIndex]); |
fieldIndex++; |
fieldIndex++; |