📄 databasemigration.java
字号:
pushObject = targetValues_HT.get(fromId);
else if (fromId_ht.equals("temporary"))
pushObject = temporaryValues_HT.get(fromId);
// push data
if (pushObject != null)
{
if (toId_ht.equals("source"))
sourceValues_HT.put(toId, pushObject);
else if (toId_ht.equals("target"))
targetValues_HT.put(toId, pushObject);
else if (toId_ht.equals("temporary"))
temporaryValues_HT.put(toId, pushObject);
}
}
else
{
System.out.println("Bad Field ID");
}
}
else if (type.equals("STRING MERGE"))
{
String[] junk = new String[1];
String[] fromIds = (String[])((StringMerge)action).getFromIds().toArray(junk);
String toId = ((StringMerge)action).getToId();
String delimiter = ((StringMerge)action).getDelimiter();
// find Ids
boolean validIds = true;
int[] fromIds_i = new int[fromIds.length];
Arrays.fill(fromIds_i, -1);
int toId_i = -1;
String[] fromIds_ht = new String[fromIds.length];
Arrays.fill(fromIds_ht, "");
String toId_ht = "";
for (int x=0; x<fromIds.length; x++)
{
fromIds_i[x] = sourceFieldIds.indexOf(fromIds[x]);
if (fromIds_i[x] != -1)
fromIds_ht[x] = "source";
else
{
fromIds_i[x] = targetFieldIds.indexOf(fromIds[x]);
if (fromIds_i[x] != -1)
fromIds_ht[x] ="target";
else
{
fromIds_i[x] = temporaryVariableIds.indexOf(fromIds[x]);
if (fromIds_i[x] != -1)
fromIds_ht[x] ="temporary";
else
validIds = false;
}
}
}
toId_i = sourceFieldIds.indexOf(toId);
if (toId_i != -1)
toId_ht = "source";
else
{
toId_i = targetFieldIds.indexOf(toId);
if (toId_i != -1)
toId_ht ="target";
else
{
toId_i = temporaryVariableIds.indexOf(toId);
if (toId_i != -1)
toId_ht ="temporary";
else
validIds = false;
}
}
if (validIds)
{
String[] mergeStrings = new String[fromIds.length];
// pull data
for (int x=0; x<fromIds.length; x++)
{
if (fromIds_ht[x].equals("source"))
mergeStrings[x] = (String)sourceValues_HT.get(fromIds[x]);
else if (fromIds_ht[x].equals("target"))
mergeStrings[x] = (String)targetValues_HT.get(fromIds[x]);
else if (fromIds_ht[x].equals("temporary"))
mergeStrings[x] = (String)temporaryValues_HT.get(fromIds[x]);
if (mergeStrings[x] == null) mergeStrings[x] = "";
}
// do merge
String mergedString = "";
for (int x=0; x<fromIds.length; x++)
{
if (x>0) mergedString = mergedString + delimiter;
mergedString = mergedString + mergeStrings[x];
}
System.out.println("MergedStringResult = " + mergedString);
// push data
if (toId_ht.equals("source"))
sourceValues_HT.put(toId, mergedString);
else if (toId_ht.equals("target"))
targetValues_HT.put(toId, mergedString);
else if (toId_ht.equals("temporary"))
temporaryValues_HT.put(toId, mergedString);
}
else
{
System.out.println("Bad Field ID");
}
}
else if (type.equals("STRING SPLIT"))
{
String[] junk = new String[1];
String fromId = ((StringSplit)action).getFromId();
String[] toIds = (String[])((StringSplit)action).getToIds().toArray(junk);
String delimiter = ((StringSplit)action).getDelimiter();
// find Ids
boolean validIds = true;
int fromId_i = -1;
int[] toIds_i = new int[toIds.length];
Arrays.fill(toIds_i, -1);
String fromId_ht = "";
String[] toIds_ht = new String[toIds.length];
Arrays.fill(toIds_ht, "");
fromId_i = sourceFieldIds.indexOf(fromId);
if (fromId_i != -1)
fromId_ht = "source";
else
{
fromId_i = targetFieldIds.indexOf(fromId);
if (fromId_i != -1)
fromId_ht ="target";
else
{
fromId_i = temporaryVariableIds.indexOf(fromId);
if (fromId_i != -1)
fromId_ht ="temporary";
else
validIds = false;
}
}
for (int x=0; x<toIds.length; x++)
{
toIds_i[x] = sourceFieldIds.indexOf(toIds[x]);
if (toIds_i[x] != -1)
toIds_ht[x] = "source";
else
{
toIds_i[x] = targetFieldIds.indexOf(toIds[x]);
if (toIds_i[x] != -1)
toIds_ht[x] ="target";
else
{
toIds_i[x] = temporaryVariableIds.indexOf(toIds[x]);
if (toIds_i[x] != -1)
toIds_ht[x] ="temporary";
else
validIds = false;
}
}
}
if (validIds)
{
String splitString = "";
// pull data
if (fromId_ht.equals("source"))
splitString = (String)sourceValues_HT.get(fromId);
else if (fromId_ht.equals("target"))
splitString = (String)targetValues_HT.get(fromId);
else if (fromId_ht.equals("temporary"))
splitString = (String)temporaryValues_HT.get(fromId);
if (splitString == null) splitString = "";
// do split
ArrayList splitStrings = new ArrayList();
StringTokenizer st = new StringTokenizer(splitString, delimiter);
while (st.hasMoreTokens())
{
splitStrings.add(st.nextToken());
}
// push data
for (int x=0; x<toIds.length; x++)
{
if (x<splitStrings.size())
{
if (toIds_ht[x].equals("source"))
sourceValues_HT.put(toIds[x], (String)splitStrings.get(x));
else if (toIds_ht[x].equals("target"))
targetValues_HT.put(toIds[x], (String)splitStrings.get(x));
else if (toIds_ht[x].equals("temporary"))
temporaryValues_HT.put(toIds[x], (String)splitStrings.get(x));
}
}
}
else
{
System.out.println("Bad Field ID during SPLIT");
}
}
else if (type.equals("STRING REPLACE"))
{
String fromId = ((StringReplace)action).getFromId();
String toId = ((StringReplace)action).getToId();
String searchString = ((StringReplace)action).getFromText();
String replaceString = ((StringReplace)action).getToText();
// find Ids
boolean validIds = true;
int fromId_i = -1;
int toId_i = -1;
String fromId_ht = "";
String toId_ht = "";
fromId_i = sourceFieldIds.indexOf(fromId);
if (fromId_i != -1)
fromId_ht = "source";
else
{
fromId_i = targetFieldIds.indexOf(fromId);
if (fromId_i != -1)
fromId_ht ="target";
else
{
fromId_i = temporaryVariableIds.indexOf(fromId);
if (fromId_i != -1)
fromId_ht ="temporary";
else
validIds = false;
}
}
toId_i = sourceFieldIds.indexOf(toId);
if (toId_i != -1)
toId_ht = "source";
else
{
toId_i = targetFieldIds.indexOf(toId);
if (toId_i != -1)
toId_ht ="target";
else
{
toId_i = temporaryVariableIds.indexOf(toId);
if (toId_i != -1)
toId_ht ="temporary";
else
validIds = false;
}
}
if (validIds)
{
String replaceStringBefore = "";
String replaceStringAfter = "";
// pull data
if (fromId_ht.equals("source"))
replaceStringBefore = (String)sourceValues_HT.get(fromId);
else if (fromId_ht.equals("target"))
replaceStringBefore = (String)targetValues_HT.get(fromId);
else if (fromId_ht.equals("temporary"))
replaceStringBefore = (String)temporaryValues_HT.get(fromId);
if (replaceStringBefore == null) replaceStringBefore = "";
// do replace
replaceStringAfter = Tools.replace(replaceStringBefore, searchString, replaceString);
// push data
if (toId_ht.equals("source"))
sourceValues_HT.put(toId, replaceStringAfter);
else if (toId_ht.equals("target"))
targetValues_HT.put(toId, replaceStringAfter);
else if (toId_ht.equals("temporary"))
temporaryValues_HT.put(toId, replaceStringAfter);
}
else
{
System.out.println("Bad Field ID in REPLACE");
}
}
else if (type.equals("METHOD")) // NOT IMPLEMENTED
{
System.out.println("METHOD Actions are not implemented.");
}
else if (type.equals("CONVERT"))
{
String fromId = ((Convert)action).getFromId();
String toId = ((Convert)action).getToId();
// find Ids
boolean validIds = true;
boolean supportedTypes = false;
int fromId_i = -1;
int toId_i = -1;
String fromId_ht = "";
String toId_ht = "";
String fromId_type = "";
String toId_type = "";
fromId_i = sourceFieldIds.indexOf(fromId);
if (fromId_i != -1)
{
fromId_ht = "source"; fromId_ht = "source";
fromId_type = (String)sourceFieldTypes.get(fromId_i);
}
else
{
fromId_i = targetFieldIds.indexOf(fromId);
if (fromId_i != -1)
{
fromId_ht ="target"; fromId_ht ="target";
fromId_type = (String)targetFieldTypes.get(fromId_i);
}
else
{
fromId_i = temporaryVariableIds.indexOf(fromId);
if (fromId_i != -1)
{
fromId_ht ="temporary"; fromId_ht ="temporary";
fromId_type = (String)temporaryVariableTypes.get(fromId_i);
}
else
validIds = false;
}
}
toId_i = sourceFieldIds.indexOf(toId);
if (toId_i != -1)
{
toId_ht = "source";
toId_type = (String)sourceFieldTypes.get(toId_i);
}
else
{
toId_i = targetFieldIds.indexOf(toId);
if (toId_i != -1)
{
toId_ht ="target"; toId_ht ="target";
toId_type = (String)targetFieldTypes.get(toId_i);
}
else
{
toId_i = temporaryVariableIds.indexOf(toId);
if (toId_i != -1)
{
toId_ht ="temporary"; toId_ht ="temporary";
toId_type = (String)temporaryVariableTypes.get(toId_i);
}
else
validIds = false;
}
}
System.out.println("fromId_type = " + fromId_type);
System.out.println("toId_type = " + toId_type);
// determine supported conversions
if (!fromId_type.equals("BLOB") && (toId_type.equals("CHAR") || toId_type.equals("VARCHAR") || toId_type.equals("LONGVARCHAR"))) supportedTypes = true;
if ((fromId_type.equals("CHAR") || fromId_type.equals("VARCHAR") || fromId_type.equals("LONGVARCHAR")) && (toId_type.equals("DATE") || toId_type.equals("TIME") || (toId_type.equals("TIMESTAMP") || toId_type.equals("DATETIME")))) supportedTypes = true;
if (fromId_type.equals("CHAR") && toId_type.equals("VARCHAR")) supportedTypes = true;
if (fromId_type.equals("VARCHAR") && toId_type.equals("LONGVARCHAR")) supportedTypes = true;
if (fromId_type.equals("CHAR") && toId_type.equals("LONGVARCHAR")) supportedTypes = true;
if (!fromId_type.endsWith("CHAR") && (toId_type.equals("BIT") || toId_type.equals("TINYINT") || toId_type.equals("SMALLINT") || toId_type.equals("INTEGER") || toId_type.equals("BIGINT") || toId_type.equals("REAL") || toId_type.equals("DOUBLE"))) supportedTypes = true;
System.out.println("supportedTypes = " + supportedTypes);
if (supportedTypes)
{
if (validIds)
{
Object convertObjectBefore = null;
Object convertObjectAfter = null;
// pull data
if (fromId_ht.equals("source"))
convertObjectBefore = sourceValues_HT.get(fromId);
else if (fromId_ht.equals("target"))
convertObjectBefore = targetValues_HT.get(fromId);
else if (fromId_ht.equals("temporary"))
convertObjectBefore = temporaryValues_HT.get(fromId);
System.out.println("ObjectBeforeConversion = " + convertObjectBefore);
// do conversion
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -