rendered paste bodypackage sqlquerygenerator;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;
public class DatabaseSchemaInterpreter {
public Hashtable<String, Hashtable<String, String>> readSchemaFile(
String fileName) {
Hashtable<String, Hashtable<String, String>> tableAndColumnNames = new Hashtable<String, Hashtable<String, String>>();
try {
String currentLine;
BufferedReader bReader = new BufferedReader(
new FileReader(fileName));
while ((currentLine = bReader.readLine()) != null) {
writeLineToHashtable(tableAndColumnNames, currentLine);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return tableAndColumnNames;
}
private void writeLineToHashtable(
Hashtable<String, Hashtable<String, String>> hashtable, String line) {
String[] lineFields = line.split(" ");
String table = lineFields[0];
String column = lineFields[1];
String type = lineFields[2];
if (!hashtable.containsKey(table)) {
hashtable.put(table, new Hashtable<String, String>());
}
hashtable.get(table).put(column, type);
}
}