提交 cbf6b4c8 authored 作者: Niklas Mehner's avatar Niklas Mehner

Refactor synonym implementation

Remove most of the abstract methods in AbstractTable. Instead add abstract resolve()/asTable() method, that return the backing table.
上级 810a0771
......@@ -556,7 +556,7 @@ public class Parser {
Analyze command = new Analyze(session);
if (readIf("TABLE")) {
AbstractTable table = readTableOrView();
command.setTable(table);
command.setTable(table.resolve());
}
if (readIf("SAMPLE_SIZE")) {
command.setTop(readPositiveInt());
......@@ -731,7 +731,7 @@ public class Parser {
return filter.getRowIdColumn();
}
}
return filter.getTable().getColumn(columnName);
return filter.getTable().resolve().getColumn(columnName);
}
private Update parseUpdate() {
......@@ -884,9 +884,9 @@ public class Parser {
private Column parseColumn(AbstractTable table) {
String id = readColumnIdentifier();
if (database.getSettings().rowId && Column.ROWID.equals(id)) {
return table.getRowIdColumn();
return table.resolve().getRowIdColumn();
}
return table.getColumn(id);
return table.resolve().getColumn(id);
}
private boolean readIfMore() {
......@@ -1021,7 +1021,7 @@ public class Parser {
currentPrepared = command;
read("INTO");
AbstractTable table = readTableOrView();
command.setTable(table);
command.setTable(table.resolve());
if (readIf("(")) {
if (isSelect()) {
command.setQuery(parseSelect());
......@@ -1062,7 +1062,7 @@ public class Parser {
currentPrepared = command;
read("INTO");
AbstractTable table = readTableOrView();
command.setTable(table);
command.setTable(table.resolve());
Column[] columns = null;
if (readIf("(")) {
if (isSelect()) {
......@@ -1153,7 +1153,7 @@ public class Parser {
currentPrepared = command;
read("INTO");
AbstractTable table = readTableOrView();
command.setTable(table);
command.setTable(table.resolve());
if (readIf("(")) {
if (isSelect()) {
command.setQuery(parseSelect());
......@@ -1299,7 +1299,7 @@ public class Parser {
if (!readIf(")")) {
do {
String indexName = readIdentifierWithSchema();
Index index = table.getIndex(indexName);
Index index = table.resolve().getIndex(indexName);
indexNames.add(index.getName());
} while (readIf(","));
read(")");
......@@ -1324,7 +1324,7 @@ public class Parser {
read("TABLE");
AbstractTable table = readTableOrView();
TruncateTable command = new TruncateTable(session);
command.setTable(table);
command.setTable(table.resolve());
return command;
}
......@@ -1639,8 +1639,8 @@ public class Parser {
read("JOIN");
joined = true;
TableFilter join = readTableFilter(fromOuter);
Column[] tableCols = last.getTable().getColumns();
Column[] joinCols = join.getTable().getColumns();
Column[] tableCols = last.getTable().resolve().getColumns();
Column[] joinCols = join.getTable().resolve().getColumns();
String tableSchema = last.getTable().getSchema().getName();
String joinSchema = join.getTable().getSchema().getName();
Expression on = null;
......@@ -5065,7 +5065,7 @@ public class Parser {
boolean ifExists = readIfExists(false);
command.setIfExists(ifExists);
String viewName = readIdentifierWithSchema();
AbstractTable tableView = getSchema().findTableOrView(session, viewName);
AbstractTable tableView = getSchema().findTableViewOrSynonym(session, viewName);
if (!(tableView instanceof TableView) && !ifExists) {
throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
}
......@@ -5554,7 +5554,7 @@ public class Parser {
return getSchema().getTableOrView(session, tableName);
}
AbstractTable table = database.getSchema(session.getCurrentSchemaName())
.findTableOrView(session, tableName);
.findTableViewOrSynonym(session, tableName);
if (table != null) {
return table;
}
......@@ -5562,7 +5562,7 @@ public class Parser {
if (schemaNames != null) {
for (String name : schemaNames) {
Schema s = database.getSchema(name);
table = s.findTableOrView(session, tableName);
table = s.findTableViewOrSynonym(session, tableName);
if (table != null) {
return table;
}
......@@ -5712,7 +5712,7 @@ public class Parser {
if (table == null) {
return new NoOperation(session);
}
Index idx = table.getPrimaryKey();
Index idx = table.resolve().getPrimaryKey();
DropIndex command = new DropIndex(session, schema);
command.setIndexName(idx.getName());
return command;
......@@ -5729,10 +5729,10 @@ public class Parser {
if (table == null) {
return new NoOperation(session);
}
if (ifExists && !table.doesColumnExist(columnName)) {
if (ifExists && !table.resolve().doesColumnExist(columnName)) {
return new NoOperation(session);
}
Column column = table.getColumn(columnName);
Column column = table.resolve().getColumn(columnName);
columnsToRemove.add(column);
} while (readIf(","));
command.setTableName(tableName);
......@@ -5858,7 +5858,7 @@ public class Parser {
}
private AbstractTable tableIfTableExists(Schema schema, String tableName, boolean ifTableExists) {
AbstractTable table = schema.findTableOrView(session, tableName);
AbstractTable table = schema.findTableViewOrSynonym(session, tableName);
if (table == null && !ifTableExists) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableName);
}
......@@ -5868,7 +5868,7 @@ public class Parser {
private Column columnIfTableExists(Schema schema, String tableName,
String columnName, boolean ifTableExists) {
AbstractTable table = tableIfTableExists(schema, tableName, ifTableExists);
return table == null ? null : table.getColumn(columnName);
return table == null ? null : table.resolve().getColumn(columnName);
}
private Prepared commandIfTableExists(Schema schema, String tableName,
......
......@@ -25,6 +25,7 @@ import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.New;
......@@ -94,7 +95,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
session.commit(true);
}
Database db = session.getDatabase();
AbstractTable table = getSchema().findTableOrView(session, tableName);
Table table = getSchema().findTableOrView(session, tableName);
if (table == null) {
if (ifTableExists) {
return 0;
......@@ -197,7 +198,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
break;
}
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL: {
AbstractTable refTable = refSchema.getTableOrView(session, refTableName);
Table refTable = refSchema.resolveTableOrView(session, refTableName);
session.getUser().checkRight(refTable, Right.ALL);
if (!refTable.canReference()) {
throw DbException.getUnsupportedException("Reference " +
......@@ -271,7 +272,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
return 0;
}
private Index createIndex(AbstractTable t, IndexColumn[] cols, boolean unique) {
private Index createIndex(Table t, IndexColumn[] cols, boolean unique) {
int indexId = getObjectId();
IndexType indexType;
if (unique) {
......@@ -303,7 +304,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
this.updateAction = action;
}
private static Index getUniqueIndex(AbstractTable t, IndexColumn[] cols) {
private static Index getUniqueIndex(Table t, IndexColumn[] cols) {
if (t.getIndexes() == null) {
return null;
}
......@@ -315,7 +316,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
return null;
}
private static Index getIndex(AbstractTable t, IndexColumn[] cols, boolean moreColumnOk) {
private static Index getIndex(Table t, IndexColumn[] cols, boolean moreColumnOk) {
if (t.getIndexes() == null) {
return null;
}
......
......@@ -31,6 +31,7 @@ import org.h2.schema.Sequence;
import org.h2.schema.TriggerObject;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.table.TableView;
import org.h2.util.New;
......@@ -92,7 +93,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
public int update() {
session.commit(true);
Database db = session.getDatabase();
AbstractTable table = getSchema().findTableOrView(session, tableName);
Table table = getSchema().resolveTableOrView(session, tableName);
if (table == null) {
if (ifTableExists) {
return 0;
......@@ -246,7 +247,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void removeSequence(AbstractTable table, Sequence sequence) {
private void removeSequence(Table table, Sequence sequence) {
if (sequence != null) {
table.removeSequence(sequence);
sequence.setBelongsToTable(false);
......@@ -255,7 +256,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void copyData(AbstractTable table) {
private void copyData(Table table) {
if (table.isTemporary()) {
throw DbException.getUnsupportedException("TEMP TABLE");
}
......@@ -314,7 +315,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private AbstractTable cloneTableStructure(AbstractTable table, Column[] columns, Database db,
private AbstractTable cloneTableStructure(Table table, Column[] columns, Database db,
String tempName, ArrayList<Column> newColumns) {
for (Column col : columns) {
newColumns.add(col.getClone());
......@@ -504,7 +505,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void checkNullable(AbstractTable table) {
private void checkNullable(Table table) {
for (Index index : table.getIndexes()) {
if (index.getColumnIndex(oldColumn) < 0) {
continue;
......
......@@ -12,7 +12,7 @@ import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* This class represents the statement
......@@ -45,7 +45,7 @@ public class AlterTableRename extends SchemaCommand {
public int update() {
session.commit(true);
Database db = session.getDatabase();
AbstractTable oldTable = getSchema().findTableOrView(session, oldTableName);
Table oldTable = getSchema().findTableOrView(session, oldTableName);
if (oldTable == null) {
if (ifTableExists) {
return 0;
......@@ -53,7 +53,7 @@ public class AlterTableRename extends SchemaCommand {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, oldTableName);
}
session.getUser().checkRight(oldTable, Right.ALL);
AbstractTable t = getSchema().findTableOrView(session, newTableName);
Table t = getSchema().findTableOrView(session, newTableName);
if (t != null && hidden && newTableName.equals(oldTable.getName())) {
if (!t.isHidden()) {
t.setHidden(hidden);
......
......@@ -14,8 +14,8 @@ import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
/**
* This class represents the statement
......@@ -52,7 +52,7 @@ public class AlterTableRenameColumn extends SchemaCommand {
public int update() {
session.commit(true);
Database db = session.getDatabase();
AbstractTable table = getSchema().findTableOrView(session, tableName);
Table table = getSchema().findTableOrView(session, tableName);
if (table == null) {
if (ifTableExists) {
return 0;
......
......@@ -15,6 +15,7 @@ import org.h2.expression.Parameter;
import org.h2.result.ResultInterface;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.util.StatementBuilder;
import org.h2.value.Value;
......@@ -34,14 +35,14 @@ public class Analyze extends DefineCommand {
/**
* used in ANALYZE TABLE...
*/
private AbstractTable table;
private Table table;
public Analyze(Session session) {
super(session);
sampleRows = session.getDatabase().getSettings().analyzeSample;
}
public void setTable(AbstractTable table) {
public void setTable(Table table) {
this.table = table;
}
......@@ -54,7 +55,7 @@ public class Analyze extends DefineCommand {
analyzeTable(session, table, sampleRows, true);
} else {
for (AbstractTable table : db.getAllTablesAndViews(false)) {
analyzeTable(session, table, sampleRows, true);
analyzeTable(session, table.resolve(), sampleRows, true);
}
}
return 0;
......@@ -68,8 +69,8 @@ public class Analyze extends DefineCommand {
* @param sample the number of sample rows
* @param manual whether the command was called by the user
*/
public static void analyzeTable(Session session, AbstractTable table, int sample,
boolean manual) {
public static void analyzeTable(Session session, Table table, int sample,
boolean manual) {
if (table.getTableType() != TableType.TABLE ||
table.isHidden() || session == null) {
return;
......
......@@ -16,6 +16,7 @@ import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.IndexColumn;
import org.h2.table.Table;
/**
* This class represents the statement
......@@ -62,7 +63,7 @@ public class CreateIndex extends SchemaCommand {
}
Database db = session.getDatabase();
boolean persistent = db.isPersistent();
AbstractTable table = getSchema().findTableOrView(session, tableName);
Table table = getSchema().findTableOrView(session, tableName);
if (table == null) {
if (ifTableExists) {
return 0;
......
......@@ -66,7 +66,7 @@ public class CreateLinkedTable extends SchemaCommand {
session.commit(true);
Database db = session.getDatabase();
session.getUser().checkAdmin();
if (getSchema().findTableOrView(session, tableName) != null) {
if (getSchema().findTableViewOrSynonym(session, tableName) != null) {
if (ifNotExists) {
return 0;
}
......
......@@ -56,7 +56,7 @@ public class CreateSynonym extends SchemaCommand {
data.session = session;
db.lockMeta(session);
if (data.synonymForSchema.findTableOrView(session, data.synonymFor) != null) {
if (data.synonymForSchema.findTableViewOrSynonym(session, data.synonymFor) != null) {
return createTableSynonym(db);
}
......@@ -66,7 +66,7 @@ public class CreateSynonym extends SchemaCommand {
}
private int createTableSynonym(Database db) {
AbstractTable old = getSchema().findTableOrView(session, data.synonymName);
AbstractTable old = getSchema().findTableViewOrSynonym(session, data.synonymName);
if (old != null) {
if (orReplace && old instanceof TableSynonym) {
// ok, we replacing the existing synonym
......
......@@ -110,7 +110,7 @@ public class CreateTable extends SchemaCommand {
if (!isSessionTemporary) {
db.lockMeta(session);
}
if (getSchema().findTableOrView(session, data.tableName) != null) {
if (getSchema().findTableViewOrSynonym(session, data.tableName) != null) {
if (ifNotExists) {
return 0;
}
......
......@@ -117,7 +117,7 @@ public class CreateTrigger extends SchemaCommand {
trigger.setTriggerSource(triggerSource, force);
}
db.addSchemaObject(session, trigger);
table.addTrigger(trigger);
table.resolve().addTrigger(trigger);
return 0;
}
......
......@@ -78,7 +78,7 @@ public class CreateView extends SchemaCommand {
session.getUser().checkAdmin();
Database db = session.getDatabase();
TableView view = null;
AbstractTable old = getSchema().findTableOrView(session, viewName);
AbstractTable old = getSchema().findTableViewOrSynonym(session, viewName);
if (old != null) {
if (ifNotExists) {
return 0;
......
......@@ -34,7 +34,7 @@ public class DropSynonym extends SchemaCommand {
@Override
public int update() {
session.commit(true);
AbstractTable synonym = getSchema().findTableOrView(session, synonymName);
AbstractTable synonym = getSchema().findTableViewOrSynonym(session, synonymName);
if (synonym == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, synonymName);
......@@ -44,7 +44,7 @@ public class DropSynonym extends SchemaCommand {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, synonymName);
}
session.getUser().checkRight(synonym, Right.ALL);
synonym.lock(session, true, true);
synonym.resolve().lock(session, true, true);
session.getDatabase().removeSchemaObject(session, synonym);
}
return 0;
......
......@@ -15,7 +15,7 @@ import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.table.TableView;
import org.h2.util.StatementBuilder;
......@@ -27,7 +27,7 @@ public class DropTable extends SchemaCommand {
private boolean ifExists;
private String tableName;
private AbstractTable table;
private Table table;
private DropTable next;
private int dropAction;
......
......@@ -14,6 +14,7 @@ import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.table.TableView;
......@@ -49,7 +50,7 @@ public class DropView extends SchemaCommand {
@Override
public int update() {
session.commit(true);
AbstractTable view = getSchema().findTableOrView(session, viewName);
Table view = getSchema().findTableOrView(session, viewName);
if (view == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
......
......@@ -11,6 +11,7 @@ import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* This class represents the statement
......@@ -18,13 +19,13 @@ import org.h2.table.AbstractTable;
*/
public class TruncateTable extends DefineCommand {
private AbstractTable table;
private Table table;
public TruncateTable(Session session) {
super(session);
}
public void setTable(AbstractTable table) {
public void setTable(Table table) {
this.table = table;
}
......
......@@ -13,6 +13,7 @@ import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* This class represents the statement
......@@ -52,7 +53,7 @@ public class AlterTableSet extends SchemaCommand {
@Override
public int update() {
AbstractTable table = getSchema().findTableOrView(session, tableName);
Table table = getSchema().resolveTableOrView(session, tableName);
if (table == null) {
if (ifTableExists) {
return 0;
......
......@@ -18,6 +18,7 @@ import org.h2.result.Row;
import org.h2.result.RowList;
import org.h2.table.AbstractTable;
import org.h2.table.PlanItem;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.StringUtils;
import org.h2.value.Value;
......@@ -55,8 +56,9 @@ public class Delete extends Prepared {
tableFilter.reset();
AbstractTable table = tableFilter.getTable();
session.getUser().checkRight(table, Right.DELETE);
table.fire(session, Trigger.DELETE, true);
table.lock(session, true, false);
Table resolvedTable = table.resolve();
resolvedTable.fire(session, Trigger.DELETE, true);
resolvedTable.lock(session, true, false);
RowList rows = new RowList(session);
int limitRows = -1;
if (limitExpr != null) {
......@@ -74,8 +76,8 @@ public class Delete extends Prepared {
condition.getBooleanValue(session))) {
Row row = tableFilter.get();
boolean done = false;
if (table.fireRow()) {
done = table.fireBeforeRow(session, row, null);
if (resolvedTable.fireRow()) {
done = resolvedTable.fireBeforeRow(session, row, null);
}
if (!done) {
rows.add(row);
......@@ -92,16 +94,16 @@ public class Delete extends Prepared {
checkCanceled();
}
Row row = rows.next();
table.removeRow(session, row);
resolvedTable.removeRow(session, row);
session.log(table, UndoLogRecord.DELETE, row);
}
if (table.fireRow()) {
if (resolvedTable.fireRow()) {
for (rows.reset(); rows.hasNext();) {
Row row = rows.next();
table.fireAfterRow(session, row, null, false);
resolvedTable.fireAfterRow(session, row, null, false);
}
}
table.fire(session, Trigger.DELETE, false);
resolvedTable.fire(session, Trigger.DELETE, false);
return count;
} finally {
rows.close();
......
......@@ -28,6 +28,7 @@ import org.h2.result.ResultTarget;
import org.h2.result.Row;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.util.New;
import org.h2.util.StatementBuilder;
import org.h2.value.Value;
......@@ -39,7 +40,7 @@ import org.h2.value.ValueNull;
*/
public class Insert extends Prepared implements ResultTarget {
private AbstractTable table;
private Table table;
private Column[] columns;
private final ArrayList<Expression[]> list = New.arrayList();
private Query query;
......@@ -64,7 +65,7 @@ public class Insert extends Prepared implements ResultTarget {
}
}
public void setTable(AbstractTable table) {
public void setTable(Table table) {
this.table = table;
}
......
......@@ -23,6 +23,7 @@ import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.util.New;
import org.h2.util.StatementBuilder;
import org.h2.value.Value;
......@@ -33,7 +34,7 @@ import org.h2.value.Value;
*/
public class Merge extends Prepared {
private AbstractTable table;
private Table table;
private Column[] columns;
private Column[] keys;
private final ArrayList<Expression[]> list = New.arrayList();
......@@ -52,7 +53,7 @@ public class Merge extends Prepared {
}
}
public void setTable(AbstractTable table) {
public void setTable(Table table) {
this.table = table;
}
......
......@@ -21,6 +21,7 @@ import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.util.New;
import org.h2.util.StatementBuilder;
import org.h2.value.Value;
......@@ -32,7 +33,7 @@ import java.util.ArrayList;
*/
public class Replace extends Prepared {
private AbstractTable table;
private Table table;
private Column[] columns;
private Column[] keys;
private final ArrayList<Expression[]> list = New.arrayList();
......@@ -51,7 +52,7 @@ public class Replace extends Prepared {
}
}
public void setTable(AbstractTable table) {
public void setTable(Table table) {
this.table = table;
}
......@@ -82,12 +83,13 @@ public class Replace extends Prepared {
session.getUser().checkRight(table, Right.INSERT);
session.getUser().checkRight(table, Right.UPDATE);
setCurrentRowNumber(0);
Table resolvedTable = table;
if (list.size() > 0) {
count = 0;
for (int x = 0, size = list.size(); x < size; x++) {
setCurrentRowNumber(x + 1);
Expression[] expr = list.get(x);
Row newRow = table.getTemplateRow();
Row newRow = resolvedTable.getTemplateRow();
for (int i = 0, len = columns.length; i < len; i++) {
Column c = columns[i];
int index = c.getColumnId();
......@@ -108,12 +110,12 @@ public class Replace extends Prepared {
} else {
ResultInterface rows = query.query(0);
count = 0;
table.fire(session, Trigger.UPDATE | Trigger.INSERT, true);
table.lock(session, true, false);
resolvedTable.fire(session, Trigger.UPDATE | Trigger.INSERT, true);
resolvedTable.lock(session, true, false);
while (rows.next()) {
count++;
Value[] r = rows.currentRow();
Row newRow = table.getTemplateRow();
Row newRow = resolvedTable.getTemplateRow();
setCurrentRowNumber(count);
for (int j = 0; j < columns.length; j++) {
Column c = columns[j];
......@@ -128,7 +130,7 @@ public class Replace extends Prepared {
replace(newRow);
}
rows.close();
table.fire(session, Trigger.UPDATE | Trigger.INSERT, false);
resolvedTable.fire(session, Trigger.UPDATE | Trigger.INSERT, false);
}
return count;
}
......
......@@ -223,7 +223,7 @@ public class ScriptCommand extends ScriptBase {
if (table.isHidden()) {
continue;
}
table.lock(session, false, false);
table.resolve().lock(session, false, false);
String sql = table.getCreateSQL();
if (sql == null) {
// null for metadata tables
......@@ -273,7 +273,7 @@ public class ScriptCommand extends ScriptBase {
if (table.isHidden()) {
continue;
}
table.lock(session, false, false);
table.resolve().lock(session, false, false);
String createTableSql = table.getCreateSQL();
if (createTableSql == null) {
// null for metadata tables
......@@ -281,7 +281,7 @@ public class ScriptCommand extends ScriptBase {
}
final TableType tableType = table.getTableType();
add(createTableSql, false);
final ArrayList<Constraint> constraints = table.getConstraints();
final ArrayList<Constraint> constraints = table.resolve().getConstraints();
if (constraints != null) {
for (Constraint constraint : constraints) {
if (Constraint.PRIMARY_KEY.equals(
......@@ -291,9 +291,9 @@ public class ScriptCommand extends ScriptBase {
}
}
if (TableType.TABLE == tableType) {
if (table.canGetRowCount()) {
if (table.resolve().canGetRowCount()) {
String rowcount = "-- " +
table.getRowCountApproximation() +
table.resolve().getRowCountApproximation() +
" +/- SELECT COUNT(*) FROM " + table.getSQL();
add(rowcount, false);
}
......@@ -301,7 +301,7 @@ public class ScriptCommand extends ScriptBase {
count = generateInsertValues(count, table);
}
}
final ArrayList<Index> indexes = table.getIndexes();
final ArrayList<Index> indexes = table.resolve().getIndexes();
for (int j = 0; indexes != null && j < indexes.size(); j++) {
Index index = indexes.get(j);
if (!index.getIndexType().getBelongsToConstraint()) {
......@@ -390,10 +390,10 @@ public class ScriptCommand extends ScriptBase {
}
private int generateInsertValues(int count, AbstractTable table) throws IOException {
PlanItem plan = table.getBestPlanItem(session, null, null, -1, null, null);
PlanItem plan = table.resolve().getBestPlanItem(session, null, null, -1, null, null);
Index index = plan.getIndex();
Cursor cursor = index.find(session, null, null);
Column[] columns = table.getColumns();
Column[] columns = table.resolve().getColumns();
StatementBuilder buff = new StatementBuilder("INSERT INTO ");
buff.append(table.getSQL()).append('(');
for (Column col : columns) {
......
......@@ -225,7 +225,7 @@ public class Select extends Query {
if (groupIndex == null || groupByExpression == null) {
return null;
}
ArrayList<Index> indexes = topTableFilter.getTable().getIndexes();
ArrayList<Index> indexes = topTableFilter.getTable().resolve().getIndexes();
if (indexes != null) {
for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
......@@ -406,9 +406,9 @@ public class Select extends Query {
int[] sortTypes = sort.getSortTypes();
if (sortCols.length == 0) {
// sort just on constants - can use scan index
return topTableFilter.getTable().getScanIndex(session);
return topTableFilter.getTable().resolve().getScanIndex(session);
}
ArrayList<Index> list = topTableFilter.getTable().getIndexes();
ArrayList<Index> list = topTableFilter.getTable().resolve().getIndexes();
if (list != null) {
for (int i = 0, size = list.size(); i < size; i++) {
Index index = list.get(i);
......@@ -447,7 +447,7 @@ public class Select extends Query {
}
if (sortCols.length == 1 && sortCols[0].getColumnId() == -1) {
// special case: order by _ROWID_
Index index = topTableFilter.getTable().getScanIndex(session);
Index index = topTableFilter.getTable().resolve().getScanIndex(session);
if (index.isRowIdIndex()) {
return index;
}
......@@ -480,7 +480,7 @@ public class Select extends Query {
SearchRow found = cursor.getSearchRow();
Value value = found.getValue(columnIndex);
if (first == null) {
first = topTableFilter.getTable().getTemplateSimpleRow(true);
first = topTableFilter.getTable().resolve().getTemplateSimpleRow(true);
}
first.setValue(columnIndex, value);
Value[] row = { value };
......@@ -712,7 +712,7 @@ public class Select extends Query {
private int expandColumnList(TableFilter filter, int index) {
AbstractTable t = filter.getTable();
String alias = filter.getTableAlias();
Column[] columns = t.getColumns();
Column[] columns = t.resolve().getColumns();
for (Column c : columns) {
if (!c.getVisible()) {
continue;
......@@ -871,7 +871,7 @@ public class Select extends Query {
if (expr instanceof ExpressionColumn) {
Column column = ((ExpressionColumn) expr).getColumn();
int selectivity = column.getSelectivity();
Index columnIndex = topTableFilter.getTable().
Index columnIndex = topTableFilter.getTable().resolve().
getIndexForColumn(column, false, true);
if (columnIndex != null &&
selectivity != Constants.SELECTIVITY_DEFAULT &&
......@@ -987,7 +987,7 @@ public class Select extends Query {
public void fireBeforeSelectTriggers() {
for (int i = 0, size = filters.size(); i < size; i++) {
TableFilter filter = filters.get(i);
filter.getTable().fire(session, Trigger.SELECT, true);
filter.getTable().resolve().fire(session, Trigger.SELECT, true);
}
}
......@@ -1073,10 +1073,10 @@ public class Select extends Query {
StatementBuilder buff = new StatementBuilder();
for (TableFilter f : topFilters) {
AbstractTable t = f.getTable();
if (t.isView() && ((TableView) t).isRecursive()) {
if (t.resolve().isView() && ((TableView) t).isRecursive()) {
buff.append("WITH RECURSIVE ").append(t.getName()).append('(');
buff.resetCount();
for (Column c : t.getColumns()) {
for (Column c : t.resolve().getColumns()) {
buff.appendExceptFirst(",");
buff.append(c.getName());
}
......@@ -1321,7 +1321,7 @@ public class Select extends Query {
}
for (int i = 0, size = filters.size(); i < size; i++) {
TableFilter f = filters.get(i);
if (!f.getTable().isDeterministic()) {
if (!f.getTable().resolve().isDeterministic()) {
return false;
}
}
......@@ -1330,7 +1330,7 @@ public class Select extends Query {
case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID: {
for (int i = 0, size = filters.size(); i < size; i++) {
TableFilter f = filters.get(i);
long m = f.getTable().getMaxDataModificationId();
long m = f.getTable().resolve().getMaxDataModificationId();
visitor.addDataModificationId(m);
}
break;
......@@ -1346,7 +1346,7 @@ public class Select extends Query {
TableFilter f = filters.get(i);
AbstractTable table = f.getTable();
visitor.addDependency(table);
table.addDependencies(visitor.getDependencies());
table.resolve().addDependencies(visitor.getDependencies());
}
break;
}
......
......@@ -24,6 +24,7 @@ import org.h2.result.RowList;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.PlanItem;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.New;
import org.h2.util.StatementBuilder;
......@@ -85,13 +86,14 @@ public class Update extends Prepared {
try {
AbstractTable table = tableFilter.getTable();
session.getUser().checkRight(table, Right.UPDATE);
table.fire(session, Trigger.UPDATE, true);
table.lock(session, true, false);
int columnCount = table.getColumns().length;
Table resolvedTable = table.resolve();
resolvedTable.fire(session, Trigger.UPDATE, true);
resolvedTable.lock(session, true, false);
int columnCount = resolvedTable.getColumns().length;
// get the old rows, compute the new rows
setCurrentRowNumber(0);
int count = 0;
Column[] columns = table.getColumns();
Column[] columns = resolvedTable.getColumns();
int limitRows = -1;
if (limitExpr != null) {
Value v = limitExpr.getValue(session);
......@@ -107,25 +109,25 @@ public class Update extends Prepared {
if (condition == null ||
Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Row oldRow = tableFilter.get();
Row newRow = table.getTemplateRow();
Row newRow = resolvedTable.getTemplateRow();
for (int i = 0; i < columnCount; i++) {
Expression newExpr = expressionMap.get(columns[i]);
Value newValue;
if (newExpr == null) {
newValue = oldRow.getValue(i);
} else if (newExpr == ValueExpression.getDefault()) {
Column column = table.getColumn(i);
newValue = table.getDefaultValue(session, column);
Column column = resolvedTable.getColumn(i);
newValue = resolvedTable.getDefaultValue(session, column);
} else {
Column column = table.getColumn(i);
Column column = resolvedTable.getColumn(i);
newValue = column.convert(newExpr.getValue(session));
}
newRow.setValue(i, newValue);
}
table.validateConvertUpdateSequence(session, newRow);
resolvedTable.validateConvertUpdateSequence(session, newRow);
boolean done = false;
if (table.fireRow()) {
done = table.fireBeforeRow(session, oldRow, newRow);
if (resolvedTable.fireRow()) {
done = resolvedTable.fireBeforeRow(session, oldRow, newRow);
}
if (!done) {
rows.add(oldRow);
......@@ -142,16 +144,16 @@ public class Update extends Prepared {
// we need to update all indexes) before row triggers
// the cached row is already updated - we need the old values
table.updateRows(this, session, rows);
if (table.fireRow()) {
resolvedTable.updateRows(this, session, rows);
if (resolvedTable.fireRow()) {
rows.invalidateCache();
for (rows.reset(); rows.hasNext();) {
Row o = rows.next();
Row n = rows.next();
table.fireAfterRow(session, o, n, false);
resolvedTable.fireAfterRow(session, o, n, false);
}
}
table.fire(session, Trigger.UPDATE, false);
resolvedTable.fire(session, Trigger.UPDATE, false);
return count;
} finally {
rows.close();
......
......@@ -17,6 +17,7 @@ import org.h2.schema.Schema;
import org.h2.schema.SchemaObjectBase;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
/**
* The base class for constraint checking.
......@@ -47,9 +48,9 @@ public abstract class Constraint extends SchemaObjectBase implements
/**
* The table for which this constraint is defined.
*/
protected AbstractTable table;
protected Table table;
Constraint(Schema schema, int id, String name, AbstractTable table) {
Constraint(Schema schema, int id, String name, Table table) {
initSchemaObjectBase(schema, id, name, Trace.CONSTRAINT);
this.table = table;
this.setTemporary(table.isTemporary());
......
......@@ -18,6 +18,7 @@ import org.h2.result.Row;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.New;
import org.h2.util.StringUtils;
......@@ -30,7 +31,7 @@ public class ConstraintCheck extends Constraint {
private TableFilter filter;
private Expression expr;
public ConstraintCheck(Schema schema, int id, String name, AbstractTable table) {
public ConstraintCheck(Schema schema, int id, String name, Table table) {
super(schema, id, name, table);
}
......
......@@ -59,7 +59,7 @@ public class ConstraintReferential extends Constraint {
private IndexColumn[] refColumns;
private int deleteAction;
private int updateAction;
private AbstractTable refTable;
private Table refTable;
private Index index;
private Index refIndex;
private boolean indexOwner;
......@@ -67,7 +67,7 @@ public class ConstraintReferential extends Constraint {
private String deleteSQL, updateSQL;
private boolean skipOwnTable;
public ConstraintReferential(Schema schema, int id, String name, AbstractTable table) {
public ConstraintReferential(Schema schema, int id, String name, Table table) {
super(schema, id, name, table);
}
......@@ -247,7 +247,7 @@ public class ConstraintReferential extends Constraint {
return refColumns;
}
public void setRefTable(AbstractTable refTable) {
public void setRefTable(Table refTable) {
this.refTable = refTable;
if (refTable.isTemporary()) {
setTemporary(true);
......
......@@ -14,6 +14,7 @@ import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.Table;
import org.h2.util.New;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
......@@ -28,7 +29,7 @@ public class ConstraintUnique extends Constraint {
private IndexColumn[] columns;
private final boolean primaryKey;
public ConstraintUnique(Schema schema, int id, String name, AbstractTable table,
public ConstraintUnique(Schema schema, int id, String name, Table table,
boolean primaryKey) {
super(schema, id, name, table);
this.primaryKey = primaryKey;
......
......@@ -1265,10 +1265,10 @@ public class Database implements DataHandler {
if (systemSession != null) {
if (powerOffCount != -1) {
for (AbstractTable table : getAllTablesAndViews(false)) {
if (table.isGlobalTemporary()) {
if (table.resolve().isGlobalTemporary()) {
table.removeChildrenAndResources(systemSession);
} else {
table.close(systemSession);
table.resolve().close(systemSession);
}
}
for (SchemaObject obj : getAllSchemaObjects(
......@@ -1331,7 +1331,7 @@ public class Database implements DataHandler {
if (!persistent) {
return;
}
boolean lobStorageIsUsed = infoSchema.findTableOrView(
boolean lobStorageIsUsed = infoSchema.findTableViewOrSynonym(
systemSession, LobStorageBackend.LOB_DATA_TABLE) != null;
lobStorageIsUsed |= mvStore != null;
if (!lobStorageIsUsed) {
......@@ -1806,11 +1806,11 @@ public class Database implements DataHandler {
for (AbstractTable t : getAllTablesAndViews(false)) {
if (except == t) {
continue;
} else if (TableType.VIEW == t.getTableType()) {
} else if (TableType.VIEW == t.getTableType() || TableType.SYNONYM == t.getTableType()) {
continue;
}
set.clear();
t.addDependencies(set);
t.resolve().addDependencies(set);
if (set.contains(obj)) {
return t;
}
......@@ -1829,7 +1829,7 @@ public class Database implements DataHandler {
int type = obj.getType();
if (type == DbObject.TABLE_OR_VIEW) {
AbstractTable table = (AbstractTable) obj;
if (table.isTemporary() && !table.isGlobalTemporary()) {
if (table.isTemporary() && !table.resolve().isGlobalTemporary()) {
session.removeLocalTempTable(table);
return;
}
......@@ -1843,7 +1843,7 @@ public class Database implements DataHandler {
} else if (type == DbObject.CONSTRAINT) {
Constraint constraint = (Constraint) obj;
AbstractTable table = constraint.getTable();
if (table.isTemporary() && !table.isGlobalTemporary()) {
if (table.isTemporary() && !table.resolve().isGlobalTemporary()) {
session.removeLocalTempTableConstraint(constraint);
return;
}
......@@ -1919,7 +1919,7 @@ public class Database implements DataHandler {
do {
tempName = baseName + "_COPY_" + session.getId() +
"_" + nextTempTableId++;
} while (mainSchema.findTableOrView(session, tempName) != null);
} while (mainSchema.findTableViewOrSynonym(session, tempName) != null);
return tempName;
}
......
......@@ -879,7 +879,7 @@ public class Session extends SessionWithState {
* @param row the row
*/
public void log(AbstractTable table, short operation, Row row) {
if (table.isMVStore()) {
if (table.resolve().isMVStore()) {
return;
}
if (undoLogEnabled) {
......@@ -890,7 +890,7 @@ public class Session extends SessionWithState {
int lockMode = database.getLockMode();
if (lockMode != Constants.LOCK_MODE_OFF &&
!database.isMultiVersion()) {
TableType tableType = log.getTable().getTableType();
TableType tableType = log.getTable().resolve().getTableType();
if (locks.indexOf(log.getTable()) < 0
&& TableType.TABLE_LINK != tableType
&& TableType.EXTERNAL_TABLE_ENGINE != tableType) {
......@@ -902,7 +902,7 @@ public class Session extends SessionWithState {
} else {
if (database.isMultiVersion()) {
// see also UndoLogRecord.commit
ArrayList<Index> indexes = table.getIndexes();
ArrayList<Index> indexes = table.resolve().getIndexes();
for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
index.commit(operation, row);
......
......@@ -66,7 +66,7 @@ public class UndoLogRecord {
*/
boolean canStore() {
// if large transactions are enabled, this method is not called
if (table.getUniqueIndex() != null) {
if (table.resolve().getUniqueIndex() != null) {
return true;
}
return false;
......@@ -93,8 +93,8 @@ public class UndoLogRecord {
}
try {
row.setDeleted(false);
table.removeRow(session, row);
table.fireAfterRow(session, row, null, true);
table.resolve().removeRow(session, row);
table.resolve().fireAfterRow(session, row, null, true);
} catch (DbException e) {
if (session.getDatabase().getLockMode() == Constants.LOCK_MODE_OFF
&& e.getErrorCode() == ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1) {
......@@ -107,8 +107,8 @@ public class UndoLogRecord {
break;
case DELETE:
try {
table.addRow(session, row);
table.fireAfterRow(session, null, row, true);
table.resolve().addRow(session, row);
table.resolve().fireAfterRow(session, null, row, true);
// reset session id, otherwise other sessions think
// that this row was inserted by this session
row.commit();
......@@ -251,7 +251,7 @@ public class UndoLogRecord {
* It commits the change to the indexes.
*/
void commit() {
table.commit(operation, row);
table.resolve().commit(operation, row);
}
/**
......
......@@ -111,7 +111,7 @@ public class User extends RightOwner {
*/
public boolean hasRight(AbstractTable table, int rightMask) {
if (rightMask != Right.SELECT && !systemUser && table != null) {
table.checkWritingAllowed();
table.resolve().checkWritingAllowed();
}
if (admin) {
return true;
......@@ -128,7 +128,7 @@ public class User extends RightOwner {
if (hasRight(null, Right.ALTER_ANY_SCHEMA)) {
return true;
}
TableType tableType = table.getTableType();
TableType tableType = table.resolve().getTableType();
if (TableType.VIEW == tableType) {
TableView v = (TableView) table;
if (v.getOwner() == this) {
......@@ -140,7 +140,7 @@ public class User extends RightOwner {
// function table
return true;
}
if (table.isTemporary() && !table.isGlobalTemporary()) {
if (table.isTemporary() && !table.resolve().isGlobalTemporary()) {
// the owner has all rights on local temporary tables
return true;
}
......
......@@ -282,7 +282,7 @@ public class Aggregate extends Expression {
case COUNT:
case COUNT_ALL:
AbstractTable table = select.getTopTableFilter().getTable();
return ValueLong.get(table.getRowCount(session));
return ValueLong.get(table.resolve().getRowCount(session));
case MIN:
case MAX:
boolean first = type == MIN;
......@@ -581,7 +581,7 @@ public class Aggregate extends Expression {
TableFilter filter = col.getTableFilter();
if (filter != null) {
AbstractTable table = filter.getTable();
Index index = table.getIndexForColumn(column, true, false);
Index index = table.resolve().getIndexForColumn(column, true, false);
return index;
}
}
......@@ -594,11 +594,11 @@ public class Aggregate extends Expression {
switch (type) {
case COUNT:
if (!distinct && on.getNullable() == Column.NOT_NULLABLE) {
return visitor.getTable().canGetRowCount();
return visitor.getTable().resolve().canGetRowCount();
}
return false;
case COUNT_ALL:
return visitor.getTable().canGetRowCount();
return visitor.getTable().resolve().canGetRowCount();
case MIN:
case MAX:
Index index = getMinMaxColumnIndex();
......
......@@ -373,7 +373,7 @@ public class Comparison extends Condition {
@Override
public void createIndexConditions(Session session, TableFilter filter) {
if (!filter.getTable().isQueryComparable()) {
if (!filter.getTable().resolve().isQueryComparable()) {
return;
}
ExpressionColumn l = null;
......
......@@ -297,7 +297,7 @@ public class ExpressionColumn extends Expression {
}
return evaluatable || visitor.getQueryLevel() < this.queryLevel;
case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID:
visitor.addDataModificationId(column.getTable().getMaxDataModificationId());
visitor.addDataModificationId(column.getTable().resolve().getMaxDataModificationId());
return true;
case ExpressionVisitor.NOT_FROM_RESOLVER:
return columnResolver != visitor.getResolver();
......
......@@ -1161,7 +1161,7 @@ public class Function extends Expression implements FunctionCall {
Parser p = new Parser(session);
String sql = v0.getString();
AbstractTable table = p.parseTableName(sql);
return table.getDiskSpaceUsed();
return table.resolve().getDiskSpaceUsed();
}
private static Value getNullOrValue(Session session, Expression[] args,
......
......@@ -282,7 +282,7 @@ public class Schema extends DbObjectBase {
* @param name the object name
* @return the object or null
*/
public AbstractTable findTableOrView(Session session, String name) {
public AbstractTable findTableViewOrSynonym(Session session, String name) {
AbstractTable table = tablesAndViews.get(name);
if (table == null && session != null) {
table = session.findLocalTempTable(name);
......@@ -290,6 +290,22 @@ public class Schema extends DbObjectBase {
return table;
}
public Table resolveTableOrView(Session session, String name) {
AbstractTable table = findTableViewOrSynonym(session, name);
if (table == null) {
return null;
}
return table.resolve();
}
public Table findTableOrView(Session session, String name) {
AbstractTable table = findTableViewOrSynonym(session, name);
if (table == null) {
return null;
}
return table.asTable();
}
/**
* Try to find an index with this name. This method returns null if
* no object with this name exists.
......@@ -414,7 +430,7 @@ public class Schema extends DbObjectBase {
*/
public String getUniqueConstraintName(Session session, AbstractTable table) {
Map<String, Constraint> tableConstraints;
if (table.isTemporary() && !table.isGlobalTemporary()) {
if (table.isTemporary() && !table.resolve().isGlobalTemporary()) {
tableConstraints = session.getLocalTempTableConstraints();
} else {
tableConstraints = constraints;
......@@ -432,7 +448,7 @@ public class Schema extends DbObjectBase {
*/
public String getUniqueIndexName(Session session, AbstractTable table, String prefix) {
Map<String, Index> tableIndexes;
if (table.isTemporary() && !table.isGlobalTemporary()) {
if (table.isTemporary() && !table.resolve().isGlobalTemporary()) {
tableIndexes = session.getLocalTempTableIndexes();
} else {
tableIndexes = indexes;
......
......@@ -383,7 +383,7 @@ public class TriggerObject extends SchemaObjectBase {
@Override
public void removeChildrenAndResources(Session session) {
table.removeTrigger(this);
table.resolve().removeTrigger(this);
database.removeMeta(session, getId());
if (triggerCallback != null) {
try {
......
......@@ -559,13 +559,13 @@ public class PageStore implements CacheWriter {
recordPageReads = true;
Session sysSession = database.getSystemSession();
for (AbstractTable table : tables) {
if (!table.isTemporary() && TableType.TABLE == table.getTableType()) {
Index scanIndex = table.getScanIndex(sysSession);
if (!table.isTemporary() && TableType.TABLE == table.resolve().getTableType()) {
Index scanIndex = table.resolve().getScanIndex(sysSession);
Cursor cursor = scanIndex.find(sysSession, null, null);
while (cursor.next()) {
cursor.get();
}
for (Index index : table.getIndexes()) {
for (Index index : table.resolve().getIndexes()) {
if (index != scanIndex && index.canScan()) {
cursor = index.find(sysSession, null, null);
while (cursor.next()) {
......
......@@ -71,7 +71,7 @@ public class IndexColumn {
*/
public static void mapColumns(IndexColumn[] indexColumns, AbstractTable table) {
for (IndexColumn col : indexColumns) {
col.column = table.getColumn(col.columnName);
col.column = table.resolve().getColumn(col.columnName);
}
}
......
......@@ -469,7 +469,7 @@ public final class JoinBatch {
}
Row getNullRow() {
return filter.getTable().getNullRow();
return filter.getTable().resolve().getNullRow();
}
boolean isOuterJoin() {
......
......@@ -710,13 +710,13 @@ public class MetaTable extends Table {
}
String storageType;
if (table.isTemporary()) {
if (table.isGlobalTemporary()) {
if (table.resolve().isGlobalTemporary()) {
storageType = "GLOBAL TEMPORARY";
} else {
storageType = "LOCAL TEMPORARY";
}
} else {
storageType = table.isPersistIndexes() ?
storageType = table.resolve().isPersistIndexes() ?
"CACHED" : "MEMORY";
}
String sql = table.getCreateSQL();
......@@ -742,7 +742,7 @@ public class MetaTable extends Table {
// REMARKS
replaceNullWithEmpty(table.getComment()),
// LAST_MODIFICATION
"" + table.getMaxDataModificationId(),
"" + table.resolve().getMaxDataModificationId(),
// ID
"" + table.getId(),
// TYPE_NAME
......@@ -750,7 +750,7 @@ public class MetaTable extends Table {
// TABLE_CLASS
table.getClass().getName(),
// ROW_COUNT_ESTIMATE
"" + table.getRowCountApproximation()
"" + table.resolve().getRowCountApproximation()
);
}
break;
......@@ -773,7 +773,7 @@ public class MetaTable extends Table {
if (hideTable(table, session)) {
continue;
}
Column[] cols = table.getColumns();
Column[] cols = table.resolve().getColumns();
String collation = database.getCompareMode().getName();
for (int j = 0; j < cols.length; j++) {
Column c = cols[j];
......@@ -850,8 +850,8 @@ public class MetaTable extends Table {
if (hideTable(table, session)) {
continue;
}
ArrayList<Index> indexes = table.getIndexes();
ArrayList<Constraint> constraints = table.getConstraints();
ArrayList<Index> indexes = table.resolve().getIndexes();
ArrayList<Constraint> constraints = table.resolve().getConstraints();
for (int j = 0; indexes != null && j < indexes.size(); j++) {
Index index = indexes.get(j);
if (index.getCreateSQL() == null) {
......@@ -1894,7 +1894,7 @@ public class MetaTable extends Table {
// SYNONYM_FOR
synonym.getSynonymForName(),
// STATUS
synonym.isInvalid() ? "INVALID" : "VALID",
"VALID",
// REMARKS
replaceNullWithEmpty(synonym.getComment()),
// ID
......
......@@ -174,7 +174,7 @@ public class TableFilter implements ColumnResolver {
* @param forceLockEvenInMvcc lock even in the MVCC mode
*/
public void lock(Session s, boolean exclusive, boolean forceLockEvenInMvcc) {
table.lock(s, exclusive, forceLockEvenInMvcc);
table.resolve().lock(s, exclusive, forceLockEvenInMvcc);
if (join != null) {
join.lock(s, exclusive, forceLockEvenInMvcc);
}
......@@ -199,12 +199,12 @@ public class TableFilter implements ColumnResolver {
}
if (indexConditions.size() == 0) {
item1 = new PlanItem();
item1.setIndex(table.getScanIndex(s, null, filters, filter,
item1.setIndex(table.resolve().getScanIndex(s, null, filters, filter,
sortOrder, allColumnsSet));
item1.cost = item1.getIndex().getCost(s, null, filters, filter,
sortOrder, allColumnsSet);
}
int len = table.getColumns().length;
int len = table.resolve().getColumns().length;
int[] masks = new int[len];
for (IndexCondition condition : indexConditions) {
if (condition.isEvaluatable()) {
......@@ -218,7 +218,7 @@ public class TableFilter implements ColumnResolver {
}
}
}
PlanItem item = table.getBestPlanItem(s, masks, filters, filter, sortOrder, allColumnsSet);
PlanItem item = table.resolve().getBestPlanItem(s, masks, filters, filter, sortOrder, allColumnsSet);
item.setMasks(masks);
// The more index conditions, the earlier the table.
// This is to ensure joins without indexes run quickly:
......@@ -397,7 +397,7 @@ public class TableFilter implements ColumnResolver {
assert filters[filter] == this;
joinBatch = null;
joinFilterId = -1;
if (getTable().isView()) {
if (getTable().resolve().isView()) {
session.pushSubQueryInfo(masks, filters, filter, select.getSortOrder());
try {
((ViewIndex) index).getQuery().prepareJoinBatch();
......@@ -553,7 +553,7 @@ public class TableFilter implements ColumnResolver {
*/
protected void setNullRow() {
state = NULL_ROW;
current = table.getNullRow();
current = table.resolve().getNullRow();
currentSearchRow = current;
if (nestedJoin != null) {
nestedJoin.visit(new TableFilterVisitor() {
......@@ -818,12 +818,12 @@ public class TableFilter implements ColumnResolver {
}
return buff.toString();
}
if (table.isView() && ((TableView) table).isRecursive()) {
if (table.resolve().isView() && ((TableView) table).isRecursive()) {
buff.append(table.getName());
} else {
buff.append(table.getSQL());
}
if (table.isView() && ((TableView) table).isInvalid()) {
if (table.resolve().isView() && ((TableView) table).isInvalid()) {
throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, table.getName(), "not compiled");
}
if (alias != null) {
......@@ -1034,7 +1034,7 @@ public class TableFilter implements ColumnResolver {
@Override
public Column[] getColumns() {
return table.getColumns();
return table.resolve().getColumns();
}
/**
......@@ -1062,7 +1062,7 @@ public class TableFilter implements ColumnResolver {
@Override
public Column getRowIdColumn() {
if (session.getDatabase().getSettings().rowId) {
return table.getRowIdColumn();
return table.resolve().getRowIdColumn();
}
return null;
}
......@@ -1172,9 +1172,9 @@ public class TableFilter implements ColumnResolver {
public void lockRows(ArrayList<Row> forUpdateRows) {
for (Row row : forUpdateRows) {
Row newRow = row.getCopy();
table.removeRow(session, row);
table.resolve().removeRow(session, row);
session.log(table, UndoLogRecord.DELETE, row);
table.addRow(session, newRow);
table.resolve().addRow(session, newRow);
session.log(table, UndoLogRecord.INSERT, newRow);
}
}
......
......@@ -266,7 +266,7 @@ public class TableView extends Table {
return false;
}
for (AbstractTable t : tables) {
if (!t.isQueryComparable()) {
if (!t.resolve().isQueryComparable()) {
return false;
}
}
......@@ -503,7 +503,7 @@ public class TableView extends Table {
private void removeViewFromTables() {
if (tables != null) {
for (AbstractTable t : tables) {
t.removeView(this);
t.resolve().removeView(this);
}
tables.clear();
}
......@@ -511,7 +511,7 @@ public class TableView extends Table {
private void addViewToTables() {
for (AbstractTable t : tables) {
t.addView(this);
t.resolve().addView(this);
}
}
......@@ -622,7 +622,7 @@ public class TableView extends Table {
if (tables != null) {
for (AbstractTable t : tables) {
if (TableType.VIEW != t.getTableType()) {
t.addDependencies(dependencies);
t.resolve().addDependencies(dependencies);
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论