Table table = null;
if (!line.isEmpty()) {
int indexOfFirstSpace = line.indexOf(' ');
if (indexOfFirstSpace < 0) {
throw new SyntaxException(getLine(), "Incorrect syntax.");
}
String firstWord = line.substring(0, indexOfFirstSpace).toLowerCase();
if (!firstWord.equals("using")) {
throw new SyntaxException(getLine(), "Unknown statement: " + firstWord);
}
String leftover = line.substring(indexOfFirstSpace);
String[] tableNames = leftover.split(",");
for (String tableName : tableNames) {
String trimmedTableName = tableName.trim();
if (!trimmedTableName.isEmpty()) {
Table contextTable = (Table) context.getValue(trimmedTableName);
if (contextTable == null) {
throw new SyntaxException(getLine(), format("Table with name \"%s\" does not exist", trimmedTableName));
}
if (table == null) {
table = contextTable;
}
else {
try {
table.mergeWith(contextTable);
}
catch (Exception ex) {
throw new SyntaxException(getLine(), format("Cannot merge table \"%s\". Perhaps it has different amount of columns", trimmedTableName));
}
}
}
}
try {
table.mergeWith(tableFromChild);
}
catch (Exception ex) {
throw new SyntaxException(getLine(), format("Cannot merge in-built table. It probably has different amount of columns then in \"%s\"", line));
}
}
else {
table = tableFromChild;