提交 f5d37007 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #565 from NiklasMehner/master

Refactor synonym implementation
......@@ -22,9 +22,9 @@ import org.h2.index.Index;
import org.h2.index.IndexType;
import org.h2.message.DbException;
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;
......@@ -62,7 +62,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
ifTableExists = b;
}
private String generateConstraintName(AbstractTable table) {
private String generateConstraintName(Table table) {
if (constraintName == null) {
constraintName = getSchema().getUniqueConstraintName(
session, table);
......@@ -94,7 +94,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 +197,10 @@ 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);
if (refTable == null) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, refTableName);
}
session.getUser().checkRight(refTable, Right.ALL);
if (!refTable.canReference()) {
throw DbException.getUnsupportedException("Reference " +
......@@ -271,7 +274,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 +306,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 +318,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;
}
......@@ -327,7 +330,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
return null;
}
private static boolean canUseUniqueIndex(Index idx, AbstractTable table,
private static boolean canUseUniqueIndex(Index idx, Table table,
IndexColumn[] cols) {
if (idx.getTable() != table || !idx.getIndexType().isUnique()) {
return false;
......@@ -350,7 +353,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
return true;
}
private static boolean canUseIndex(Index existingIndex, AbstractTable table,
private static boolean canUseIndex(Index existingIndex, Table table,
IndexColumn[] cols, boolean moreColumnsOk) {
if (existingIndex.getTable() != table || existingIndex.getCreateSQL() == null) {
// can't use the scan index or index of another table
......
......@@ -29,8 +29,8 @@ import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
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 +92,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;
......@@ -211,7 +211,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
return 0;
}
private static void checkDefaultReferencesTable(AbstractTable table, Expression defaultExpression) {
private static void checkDefaultReferencesTable(Table table, Expression defaultExpression) {
if (defaultExpression == null) {
return;
}
......@@ -234,7 +234,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void convertAutoIncrementColumn(AbstractTable table, Column c) {
private void convertAutoIncrementColumn(Table table, Column c) {
if (c.isAutoIncrement()) {
if (c.isPrimaryKey()) {
c.setOriginalSQL("IDENTITY");
......@@ -246,7 +246,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 +255,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void copyData(AbstractTable table) {
private void copyData(Table table) {
if (table.isTemporary()) {
throw DbException.getUnsupportedException("TEMP TABLE");
}
......@@ -264,7 +264,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
String tempName = db.getTempTableName(baseName, session);
Column[] columns = table.getColumns();
ArrayList<Column> newColumns = New.arrayList();
AbstractTable newTable = cloneTableStructure(table, columns, db, tempName, newColumns);
Table newTable = cloneTableStructure(table, columns, db, tempName, newColumns);
try {
// check if a view would become invalid
// (because the column to drop is referenced or so)
......@@ -314,7 +314,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private AbstractTable cloneTableStructure(AbstractTable table, Column[] columns, Database db,
private Table cloneTableStructure(Table table, Column[] columns, Database db,
String tempName, ArrayList<Column> newColumns) {
for (Column col : columns) {
newColumns.add(col.getClone());
......@@ -368,7 +368,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
data.isHidden = table.isHidden();
data.create = true;
data.session = session;
AbstractTable newTable = getSchema().createTable(data);
Table newTable = getSchema().createTable(data);
newTable.setComment(table.getComment());
StringBuilder buff = new StringBuilder();
buff.append(newTable.getCreateSQL());
......@@ -504,7 +504,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;
......@@ -517,7 +517,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void checkNoNullValues(AbstractTable table) {
private void checkNoNullValues(Table table) {
String sql = "SELECT COUNT(*) FROM " +
table.getSQL() + " WHERE " +
oldColumn.getSQL() + " IS NULL";
......
......@@ -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;
......
......@@ -13,8 +13,8 @@ import org.h2.engine.Right;
import org.h2.engine.Session;
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 +34,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;
}
......@@ -53,7 +53,7 @@ public class Analyze extends DefineCommand {
if (table != null) {
analyzeTable(session, table, sampleRows, true);
} else {
for (AbstractTable table : db.getAllTablesAndViews(false)) {
for (Table table : db.getAllTablesAndViews(false)) {
analyzeTable(session, table, sampleRows, true);
}
}
......@@ -68,8 +68,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;
......
......@@ -14,8 +14,8 @@ import org.h2.engine.Session;
import org.h2.index.IndexType;
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 +62,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().resolveTableOrView(session, tableName) != null) {
if (ifNotExists) {
return 0;
}
......
......@@ -11,7 +11,6 @@ import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.TableSynonym;
/**
......@@ -52,10 +51,15 @@ public class CreateSynonym extends SchemaCommand {
if (!transactional) {
session.commit(true);
}
session.getUser().checkAdmin();
Database db = session.getDatabase();
data.session = session;
db.lockMeta(session);
if (data.synonymForSchema.findTableOrView(session, data.synonymName) != null) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, data.synonymName);
}
if (data.synonymForSchema.findTableOrView(session, data.synonymFor) != null) {
return createTableSynonym(db);
}
......@@ -66,11 +70,12 @@ public class CreateSynonym extends SchemaCommand {
}
private int createTableSynonym(Database db) {
AbstractTable old = getSchema().findTableOrView(session, data.synonymName);
TableSynonym old = getSchema().getSynonym(data.synonymName);
if (old != null) {
if (orReplace && old instanceof TableSynonym) {
if (orReplace) {
// ok, we replacing the existing synonym
} else if (ifNotExists && old instanceof TableSynonym) {
} else if (ifNotExists) {
return 0;
} else {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, data.synonymName);
......@@ -79,7 +84,7 @@ public class CreateSynonym extends SchemaCommand {
TableSynonym table;
if (old != null) {
table = (TableSynonym) old;
table = old;
data.schema = table.getSchema();
table.updateData(data);
table.setComment(comment);
......
......@@ -110,7 +110,7 @@ public class CreateTable extends SchemaCommand {
if (!isSessionTemporary) {
db.lockMeta(session);
}
if (getSchema().findTableOrView(session, data.tableName) != null) {
if (getSchema().resolveTableOrView(session, data.tableName) != null) {
if (ifNotExists) {
return 0;
}
......
......@@ -13,7 +13,7 @@ import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.TriggerObject;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* This class represents the statement
......@@ -102,7 +102,7 @@ public class CreateTrigger extends SchemaCommand {
triggerName);
}
int id = getObjectId();
AbstractTable table = getSchema().getTableOrView(session, tableName);
Table table = getSchema().getTableOrView(session, tableName);
TriggerObject trigger = new TriggerObject(getSchema(), id, triggerName, table);
trigger.setInsteadOf(insteadOf);
trigger.setBefore(before);
......
......@@ -11,8 +11,8 @@ import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.engine.UserDataType;
import org.h2.message.DbException;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.value.DataType;
/**
......@@ -62,7 +62,7 @@ public class CreateUserDataType extends DefineCommand {
ErrorCode.USER_DATA_TYPE_ALREADY_EXISTS_1,
typeName);
}
AbstractTable table = session.getDatabase().getFirstUserTable();
Table table = session.getDatabase().getFirstUserTable();
if (table != null) {
throw DbException.get(
ErrorCode.USER_DATA_TYPE_ALREADY_EXISTS_1,
......
......@@ -15,8 +15,8 @@ import org.h2.engine.Session;
import org.h2.expression.Parameter;
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;
import org.h2.table.TableType;
import org.h2.table.TableView;
import org.h2.value.Value;
......@@ -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);
Table old = getSchema().findTableOrView(session, viewName);
if (old != null) {
if (ifNotExists) {
return 0;
......
......@@ -15,7 +15,7 @@ import org.h2.engine.User;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import org.h2.schema.Sequence;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.util.New;
......@@ -53,28 +53,28 @@ public class DropDatabase extends DefineCommand {
// so we might need to loop over them multiple times.
boolean runLoopAgain;
do {
ArrayList<AbstractTable> tables = db.getAllTablesAndViews(false);
ArrayList<AbstractTable> toRemove = New.arrayList();
for (AbstractTable t : tables) {
ArrayList<Table> tables = db.getAllTablesAndViews(false);
ArrayList<Table> toRemove = New.arrayList();
for (Table t : tables) {
if (t.getName() != null &&
TableType.VIEW == t.getTableType()) {
toRemove.add(t);
}
}
for (AbstractTable t : tables) {
for (Table t : tables) {
if (t.getName() != null &&
TableType.TABLE_LINK == t.getTableType()) {
toRemove.add(t);
}
}
for (AbstractTable t : tables) {
for (Table t : tables) {
if (t.getName() != null &&
TableType.TABLE == t.getTableType() &&
!t.isHidden()) {
toRemove.add(t);
}
}
for (AbstractTable t : tables) {
for (Table t : tables) {
if (t.getName() != null &&
TableType.EXTERNAL_TABLE_ENGINE == t.getTableType() &&
!t.isHidden()) {
......@@ -82,7 +82,7 @@ public class DropDatabase extends DefineCommand {
}
}
runLoopAgain = false;
for (AbstractTable t : toRemove) {
for (Table t : toRemove) {
if (t.getName() == null) {
// ignore, already dead
} else if (db.getDependentTable(t, t) == null) {
......
......@@ -11,7 +11,8 @@ 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.TableSynonym;
import org.h2.table.TableType;
/**
......@@ -34,17 +35,14 @@ public class DropSynonym extends SchemaCommand {
@Override
public int update() {
session.commit(true);
AbstractTable synonym = getSchema().findTableOrView(session, synonymName);
session.getUser().checkAdmin();
TableSynonym synonym = getSchema().getSynonym(synonymName);
if (synonym == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, synonymName);
}
} else {
if (!TableType.SYNONYM.equals(synonym.getTableType())) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, synonymName);
}
session.getUser().checkRight(synonym, Right.ALL);
synonym.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;
......
......@@ -13,7 +13,7 @@ import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.TriggerObject;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* This class represents the statement
......@@ -46,7 +46,7 @@ public class DropTrigger extends SchemaCommand {
throw DbException.get(ErrorCode.TRIGGER_NOT_FOUND_1, triggerName);
}
} else {
AbstractTable table = trigger.getTable();
Table table = trigger.getTable();
session.getUser().checkRight(table, Right.ALL);
db.removeSchemaObject(session, trigger);
}
......
......@@ -13,7 +13,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.TableType;
import org.h2.table.TableView;
......@@ -49,7 +49,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);
......
......@@ -17,7 +17,7 @@ import org.h2.engine.Role;
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.util.New;
/**
......@@ -32,7 +32,7 @@ public class GrantRevoke extends DefineCommand {
private ArrayList<String> roleNames;
private int operationType;
private int rightMask;
private final ArrayList<AbstractTable> tables = New.arrayList();
private final ArrayList<Table> tables = New.arrayList();
private Schema schema;
private RightOwner grantee;
......@@ -111,7 +111,7 @@ public class GrantRevoke extends DefineCommand {
if (schema != null) {
grantRight(schema);
}
for (AbstractTable table : tables) {
for (Table table : tables) {
grantRight(table);
}
}
......@@ -152,7 +152,7 @@ public class GrantRevoke extends DefineCommand {
if (schema != null) {
revokeRight(schema);
}
for (AbstractTable table : tables) {
for (Table table : tables) {
revokeRight(table);
}
}
......@@ -193,7 +193,7 @@ public class GrantRevoke extends DefineCommand {
*
* @param table the table
*/
public void addTable(AbstractTable table) {
public void addTable(Table table) {
tables.add(table);
}
......
......@@ -10,7 +10,7 @@ import org.h2.command.CommandInterface;
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 +18,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;
}
......
......@@ -15,8 +15,8 @@ import org.h2.expression.Expression;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.Sequence;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
/**
* This class represents the statement
......@@ -25,7 +25,7 @@ import org.h2.table.Column;
public class AlterSequence extends SchemaCommand {
private boolean ifExists;
private AbstractTable table;
private Table table;
private String sequenceName;
private Sequence sequence;
private Expression start;
......
......@@ -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
......@@ -52,7 +52,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;
......
......@@ -16,8 +16,8 @@ import org.h2.expression.ExpressionVisitor;
import org.h2.result.ResultInterface;
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;
......@@ -53,7 +53,7 @@ public class Delete extends Prepared {
public int update() {
tableFilter.startQuery(session);
tableFilter.reset();
AbstractTable table = tableFilter.getTable();
Table table = tableFilter.getTable();
session.getUser().checkRight(table, Right.DELETE);
table.fire(session, Trigger.DELETE, true);
table.lock(session, true, false);
......
......@@ -26,8 +26,8 @@ import org.h2.mvstore.db.MVPrimaryIndex;
import org.h2.result.ResultInterface;
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 +39,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 +64,7 @@ public class Insert extends Prepared implements ResultTarget {
}
}
public void setTable(AbstractTable table) {
public void setTable(Table table) {
this.table = table;
}
......
......@@ -21,8 +21,8 @@ import org.h2.index.Index;
import org.h2.message.DbException;
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 +33,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 +52,7 @@ public class Merge extends Prepared {
}
}
public void setTable(AbstractTable table) {
public void setTable(Table table) {
this.table = table;
}
......
......@@ -22,8 +22,8 @@ import org.h2.message.DbException;
import org.h2.result.ResultInterface;
import org.h2.result.ResultTarget;
import org.h2.result.SortOrder;
import org.h2.table.AbstractTable;
import org.h2.table.ColumnResolver;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.New;
import org.h2.value.Value;
......@@ -157,7 +157,7 @@ public abstract class Query extends Prepared {
*
* @return the set of tables
*/
public abstract HashSet<AbstractTable> getTables();
public abstract HashSet<Table> getTables();
/**
* Set the order by list.
......
......@@ -19,8 +19,8 @@ import org.h2.index.Index;
import org.h2.message.DbException;
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 +32,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 +51,7 @@ public class Replace extends Prepared {
}
}
public void setTable(AbstractTable table) {
public void setTable(Table table) {
this.table = table;
}
......
......@@ -49,7 +49,6 @@ import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import org.h2.schema.Sequence;
import org.h2.schema.TriggerObject;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.PlanItem;
import org.h2.table.Table;
......@@ -70,7 +69,7 @@ public class ScriptCommand extends ScriptBase {
private Charset charset = Constants.UTF8;
private Set<String> schemaNames;
private Collection<AbstractTable> tables;
private Collection<Table> tables;
private boolean passwords;
// true if we're generating the INSERT..VALUES statements for row values
......@@ -103,7 +102,7 @@ public class ScriptCommand extends ScriptBase {
this.schemaNames = schemaNames;
}
public void setTables(Collection<AbstractTable> tables) {
public void setTables(Collection<Table> tables) {
this.tables = tables;
}
......@@ -202,18 +201,18 @@ public class ScriptCommand extends ScriptBase {
add(constant.getCreateSQL(), false);
}
final ArrayList<AbstractTable> tables = db.getAllTablesAndViews(false);
final ArrayList<Table> tables = db.getAllTablesAndViews(false);
// sort by id, so that views are after tables and views on views
// after the base views
Collections.sort(tables, new Comparator<AbstractTable>() {
Collections.sort(tables, new Comparator<Table>() {
@Override
public int compare(AbstractTable t1, AbstractTable t2) {
public int compare(Table t1, Table t2) {
return t1.getId() - t2.getId();
}
});
// Generate the DROP XXX ... IF EXISTS
for (AbstractTable table : tables) {
for (Table table : tables) {
if (excludeSchema(table.getSchema())) {
continue;
}
......@@ -263,7 +262,7 @@ public class ScriptCommand extends ScriptBase {
// Generate CREATE TABLE and INSERT...VALUES
int count = 0;
for (AbstractTable table : tables) {
for (Table table : tables) {
if (excludeSchema(table.getSchema())) {
continue;
}
......@@ -389,7 +388,7 @@ public class ScriptCommand extends ScriptBase {
return r;
}
private int generateInsertValues(int count, AbstractTable table) throws IOException {
private int generateInsertValues(int count, Table table) throws IOException {
PlanItem plan = table.getBestPlanItem(session, null, null, -1, null, null);
Index index = plan.getIndex();
Cursor cursor = index.find(session, null, null);
......@@ -664,7 +663,7 @@ public class ScriptCommand extends ScriptBase {
}
if (tables != null) {
// if filtering on specific tables, only include those schemas
for (AbstractTable table : schema.getAllTablesAndViews()) {
for (Table table : schema.getAllTablesAndViews()) {
if (tables.contains(table)) {
return false;
}
......@@ -674,7 +673,7 @@ public class ScriptCommand extends ScriptBase {
return false;
}
private boolean excludeTable(AbstractTable table) {
private boolean excludeTable(Table table) {
return tables != null && !tables.contains(table);
}
......
......@@ -33,11 +33,11 @@ import org.h2.result.ResultTarget;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.IndexColumn;
import org.h2.table.JoinBatch;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.table.TableView;
import org.h2.util.New;
......@@ -710,7 +710,7 @@ public class Select extends Query {
}
private int expandColumnList(TableFilter filter, int index) {
AbstractTable t = filter.getTable();
Table t = filter.getTable();
String alias = filter.getTableAlias();
Column[] columns = t.getColumns();
for (Column c : columns) {
......@@ -856,7 +856,7 @@ public class Select extends Query {
if (isGroupQuery && groupIndex == null &&
havingIndex < 0 && filters.size() == 1) {
if (condition == null) {
AbstractTable t = filters.get(0).getTable();
Table t = filters.get(0).getTable();
ExpressionVisitor optimizable = ExpressionVisitor.
getOptimizableVisitor(t);
isQuickAggregateQuery = isEverything(optimizable);
......@@ -975,8 +975,8 @@ public class Select extends Query {
}
@Override
public HashSet<AbstractTable> getTables() {
HashSet<AbstractTable> set = New.hashSet();
public HashSet<Table> getTables() {
HashSet<Table> set = New.hashSet();
for (TableFilter filter : filters) {
set.add(filter.getTable());
}
......@@ -1072,7 +1072,7 @@ public class Select extends Query {
new Expression[expressions.size()]);
StatementBuilder buff = new StatementBuilder();
for (TableFilter f : topFilters) {
AbstractTable t = f.getTable();
Table t = f.getTable();
if (t.isView() && ((TableView) t).isRecursive()) {
buff.append("WITH RECURSIVE ").append(t.getName()).append('(');
buff.resetCount();
......@@ -1344,7 +1344,7 @@ public class Select extends Query {
case ExpressionVisitor.GET_DEPENDENCIES: {
for (int i = 0, size = filters.size(); i < size; i++) {
TableFilter f = filters.get(i);
AbstractTable table = f.getTable();
Table table = f.getTable();
visitor.addDependency(table);
table.addDependencies(visitor.getDependencies());
}
......
......@@ -22,9 +22,9 @@ import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.ResultTarget;
import org.h2.result.SortOrder;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.New;
import org.h2.util.StringUtils;
......@@ -355,8 +355,8 @@ public class SelectUnion extends Query {
}
@Override
public HashSet<AbstractTable> getTables() {
HashSet<AbstractTable> set = left.getTables();
public HashSet<Table> getTables() {
HashSet<Table> set = left.getTables();
set.addAll(right.getTables());
return set;
}
......
......@@ -21,7 +21,7 @@ import org.h2.message.DbException;
import org.h2.result.ResultInterface;
import org.h2.result.RowFactory;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.tools.CompressTool;
import org.h2.util.JdbcUtils;
import org.h2.util.StringUtils;
......@@ -145,7 +145,7 @@ public class Set extends Prepared {
if (old.equals(compareMode)) {
break;
}
AbstractTable table = database.getFirstUserTable();
Table table = database.getFirstUserTable();
if (table != null) {
throw DbException.get(
ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1,
......@@ -157,7 +157,7 @@ public class Set extends Prepared {
}
case SetTypes.BINARY_COLLATION: {
session.getUser().checkAdmin();
AbstractTable table = database.getFirstUserTable();
Table table = database.getFirstUserTable();
if (table != null) {
throw DbException.get(
ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1,
......@@ -249,7 +249,7 @@ public class Set extends Prepared {
}
case SetTypes.JAVA_OBJECT_SERIALIZER: {
session.getUser().checkAdmin();
AbstractTable table = database.getFirstUserTable();
Table table = database.getFirstUserTable();
if (table != null) {
throw DbException.get(ErrorCode.
JAVA_OBJECT_SERIALIZER_CHANGE_WITH_DATA_TABLE,
......
......@@ -21,9 +21,9 @@ import org.h2.message.DbException;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
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;
......@@ -83,7 +83,7 @@ public class Update extends Prepared {
tableFilter.reset();
RowList rows = new RowList(session);
try {
AbstractTable table = tableFilter.getTable();
Table table = tableFilter.getTable();
session.getUser().checkRight(table, Right.UPDATE);
table.fire(session, Trigger.UPDATE, true);
table.lock(session, true, false);
......
......@@ -15,8 +15,8 @@ import org.h2.message.Trace;
import org.h2.result.Row;
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 +47,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());
......@@ -71,7 +71,7 @@ public abstract class Constraint extends SchemaObjectBase implements
* @param oldRow the old row
* @param newRow the new row
*/
public abstract void checkRow(Session session, AbstractTable t, Row oldRow, Row newRow);
public abstract void checkRow(Session session, Table t, Row oldRow, Row newRow);
/**
* Check if this constraint needs the specified index.
......@@ -94,7 +94,7 @@ public abstract class Constraint extends SchemaObjectBase implements
* @param table the table
* @return the set of referenced columns
*/
public abstract HashSet<Column> getReferencedColumns(AbstractTable table);
public abstract HashSet<Column> getReferencedColumns(Table table);
/**
* Get the SQL statement to create this constraint.
......@@ -142,11 +142,11 @@ public abstract class Constraint extends SchemaObjectBase implements
return DbObject.CONSTRAINT;
}
public AbstractTable getTable() {
public Table getTable() {
return table;
}
public AbstractTable getRefTable() {
public Table getRefTable() {
return table;
}
......
......@@ -16,8 +16,8 @@ import org.h2.message.DbException;
import org.h2.result.ResultInterface;
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 +30,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);
}
......@@ -48,7 +48,7 @@ public class ConstraintCheck extends Constraint {
}
@Override
public String getCreateSQLForCopy(AbstractTable forTable, String quotedName) {
public String getCreateSQLForCopy(Table forTable, String quotedName) {
StringBuilder buff = new StringBuilder("ALTER TABLE ");
buff.append(forTable.getSQL()).append(" ADD CONSTRAINT ");
if (forTable.isHidden()) {
......@@ -88,7 +88,7 @@ public class ConstraintCheck extends Constraint {
}
@Override
public void checkRow(Session session, AbstractTable t, Row oldRow, Row newRow) {
public void checkRow(Session session, Table t, Row oldRow, Row newRow) {
if (newRow == null) {
return;
}
......@@ -118,7 +118,7 @@ public class ConstraintCheck extends Constraint {
}
@Override
public HashSet<Column> getReferencedColumns(AbstractTable table) {
public HashSet<Column> getReferencedColumns(Table table) {
HashSet<Column> columns = New.hashSet();
expr.isEverything(ExpressionVisitor.getColumnsVisitor(columns));
for (Iterator<Column> it = columns.iterator(); it.hasNext();) {
......
......@@ -20,7 +20,6 @@ import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow;
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;
......@@ -59,7 +58,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 +66,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);
}
......@@ -101,7 +100,7 @@ public class ConstraintReferential extends Constraint {
* @return the SQL statement
*/
@Override
public String getCreateSQLForCopy(AbstractTable forTable, String quotedName) {
public String getCreateSQLForCopy(Table forTable, String quotedName) {
return getCreateSQLForCopy(forTable, refTable, quotedName, true);
}
......@@ -115,7 +114,7 @@ public class ConstraintReferential extends Constraint {
* @param internalIndex add the index name to the statement
* @return the SQL statement
*/
public String getCreateSQLForCopy(AbstractTable forTable, AbstractTable forRefTable,
public String getCreateSQLForCopy(Table forTable, Table forRefTable,
String quotedName, boolean internalIndex) {
StatementBuilder buff = new StatementBuilder("ALTER TABLE ");
String mainTable = forTable.getSQL();
......@@ -225,7 +224,7 @@ public class ConstraintReferential extends Constraint {
}
@Override
public HashSet<Column> getReferencedColumns(AbstractTable table) {
public HashSet<Column> getReferencedColumns(Table table) {
HashSet<Column> result = New.hashSet();
if (table == this.table) {
for (IndexColumn c : columns) {
......@@ -247,7 +246,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);
......@@ -301,7 +300,7 @@ public class ConstraintReferential extends Constraint {
}
@Override
public void checkRow(Session session, AbstractTable t, Row oldRow, Row newRow) {
public void checkRow(Session session, Table t, Row oldRow, Row newRow) {
if (!database.getReferentialIntegrity()) {
return;
}
......@@ -610,7 +609,7 @@ public class ConstraintReferential extends Constraint {
}
@Override
public AbstractTable getRefTable() {
public Table getRefTable() {
return refTable;
}
......
......@@ -11,9 +11,9 @@ import org.h2.engine.Session;
import org.h2.index.Index;
import org.h2.result.Row;
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 +28,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;
......@@ -40,11 +40,11 @@ public class ConstraintUnique extends Constraint {
}
@Override
public String getCreateSQLForCopy(AbstractTable forTable, String quotedName) {
public String getCreateSQLForCopy(Table forTable, String quotedName) {
return getCreateSQLForCopy(forTable, quotedName, true);
}
private String getCreateSQLForCopy(AbstractTable forTable, String quotedName,
private String getCreateSQLForCopy(Table forTable, String quotedName,
boolean internalIndex) {
StatementBuilder buff = new StatementBuilder("ALTER TABLE ");
buff.append(forTable.getSQL()).append(" ADD CONSTRAINT ");
......@@ -118,7 +118,7 @@ public class ConstraintUnique extends Constraint {
}
@Override
public void checkRow(Session session, AbstractTable t, Row oldRow, Row newRow) {
public void checkRow(Session session, Table t, Row oldRow, Row newRow) {
// unique index check is enough
}
......@@ -133,7 +133,7 @@ public class ConstraintUnique extends Constraint {
}
@Override
public HashSet<Column> getReferencedColumns(AbstractTable table) {
public HashSet<Column> getReferencedColumns(Table table) {
HashSet<Column> result = New.hashSet();
for (IndexColumn c : columns) {
result.add(c.column);
......
......@@ -7,7 +7,7 @@ package org.h2.engine;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.util.StringUtils;
/**
......@@ -26,7 +26,7 @@ public class Comment extends DbObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......
......@@ -50,12 +50,12 @@ import org.h2.store.LobStorageMap;
import org.h2.store.PageStore;
import org.h2.store.WriterThread;
import org.h2.store.fs.FileUtils;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.MetaTable;
import org.h2.table.Table;
import org.h2.table.TableLinkConnection;
import org.h2.table.TableSynonym;
import org.h2.table.TableType;
import org.h2.table.TableView;
import org.h2.tools.DeleteDbFiles;
......@@ -834,7 +834,7 @@ public class Database implements DataHandler {
boolean atLeastOneRecompiledSuccessfully;
do {
atLeastOneRecompiledSuccessfully = false;
for (AbstractTable obj : getAllTablesAndViews(false)) {
for (Table obj : getAllTablesAndViews(false)) {
if (obj instanceof TableView) {
TableView view = (TableView) obj;
if (view.isInvalid()) {
......@@ -1264,7 +1264,7 @@ public class Database implements DataHandler {
try {
if (systemSession != null) {
if (powerOffCount != -1) {
for (AbstractTable table : getAllTablesAndViews(false)) {
for (Table table : getAllTablesAndViews(false)) {
if (table.isGlobalTemporary()) {
table.removeChildrenAndResources(systemSession);
} else {
......@@ -1532,27 +1532,40 @@ public class Database implements DataHandler {
* tables are only included if they are already initialized)
* @return all objects of that type
*/
public ArrayList<AbstractTable> getAllTablesAndViews(boolean includeMeta) {
public ArrayList<Table> getAllTablesAndViews(boolean includeMeta) {
if (includeMeta) {
initMetaTables();
}
ArrayList<AbstractTable> list = New.arrayList();
ArrayList<Table> list = New.arrayList();
for (Schema schema : schemas.values()) {
list.addAll(schema.getAllTablesAndViews());
}
return list;
}
/**
* Get all synonyms.
*
* @return all objects of that type
*/
public ArrayList<TableSynonym> getAllSynonyms() {
ArrayList<TableSynonym> list = New.arrayList();
for (Schema schema : schemas.values()) {
list.addAll(schema.getAllSynonyms());
}
return list;
}
/**
* Get the tables with the given name, if any.
*
* @param name the table name
* @return the list
*/
public ArrayList<AbstractTable> getTableOrViewByName(String name) {
ArrayList<AbstractTable> list = New.arrayList();
public ArrayList<Table> getTableOrViewByName(String name) {
ArrayList<Table> list = New.arrayList();
for (Schema schema : schemas.values()) {
AbstractTable table = schema.getTableOrViewByName(name);
Table table = schema.getTableOrViewByName(name);
if (table != null) {
list.add(table);
}
......@@ -1791,7 +1804,7 @@ public class Database implements DataHandler {
* @param except the table to exclude (or null)
* @return the first dependent table, or null
*/
public AbstractTable getDependentTable(SchemaObject obj, AbstractTable except) {
public Table getDependentTable(SchemaObject obj, Table except) {
switch (obj.getType()) {
case DbObject.COMMENT:
case DbObject.CONSTRAINT:
......@@ -1803,7 +1816,7 @@ public class Database implements DataHandler {
default:
}
HashSet<DbObject> set = New.hashSet();
for (AbstractTable t : getAllTablesAndViews(false)) {
for (Table t : getAllTablesAndViews(false)) {
if (except == t) {
continue;
} else if (TableType.VIEW == t.getTableType()) {
......@@ -1828,7 +1841,7 @@ public class Database implements DataHandler {
SchemaObject obj) {
int type = obj.getType();
if (type == DbObject.TABLE_OR_VIEW) {
AbstractTable table = (AbstractTable) obj;
Table table = (Table) obj;
if (table.isTemporary() && !table.isGlobalTemporary()) {
session.removeLocalTempTable(table);
return;
......@@ -1842,7 +1855,7 @@ public class Database implements DataHandler {
}
} else if (type == DbObject.CONSTRAINT) {
Constraint constraint = (Constraint) obj;
AbstractTable table = constraint.getTable();
Table table = constraint.getTable();
if (table.isTemporary() && !table.isGlobalTemporary()) {
session.removeLocalTempTableConstraint(constraint);
return;
......@@ -1858,7 +1871,7 @@ public class Database implements DataHandler {
obj.getSchema().remove(obj);
int id = obj.getId();
if (!starting) {
AbstractTable t = getDependentTable(obj, null);
Table t = getDependentTable(obj, null);
if (t != null) {
obj.getSchema().add(obj);
throw DbException.get(ErrorCode.CANNOT_DROP_2, obj.getSQL(),
......@@ -2499,8 +2512,8 @@ public class Database implements DataHandler {
*
* @return the table or null if no table is defined
*/
public AbstractTable getFirstUserTable() {
for (AbstractTable table : getAllTablesAndViews(false)) {
public Table getFirstUserTable() {
for (Table table : getAllTablesAndViews(false)) {
if (table.getCreateSQL() != null) {
if (table.isHidden()) {
// LOB tables
......
......@@ -6,8 +6,7 @@
package org.h2.engine;
import java.util.ArrayList;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* A database object such as a table, an index, or a user.
......@@ -90,6 +89,11 @@ public interface DbObject {
*/
int AGGREGATE = 14;
/**
* This object is a synonym.
*/
int SYNONYM = 15;
/**
* Get the SQL name of this object (may be quoted).
*
......@@ -134,7 +138,7 @@ public interface DbObject {
* @param quotedName the quoted name
* @return the SQL statement
*/
String getCreateSQLForCopy(AbstractTable table, String quotedName);
String getCreateSQLForCopy(Table table, String quotedName);
/**
* Construct the original CREATE ... SQL statement for this object.
......
......@@ -20,7 +20,7 @@ import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObjectBase;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.util.JdbcUtils;
import org.h2.util.New;
import org.h2.util.SourceCompiler;
......@@ -194,7 +194,7 @@ public class FunctionAlias extends SchemaObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......
......@@ -127,14 +127,16 @@ public class MetaRecord implements Comparable<MetaRecord> {
return 9;
case DbObject.TRIGGER:
return 10;
case DbObject.ROLE:
case DbObject.SYNONYM:
return 11;
case DbObject.RIGHT:
case DbObject.ROLE:
return 12;
case DbObject.AGGREGATE:
case DbObject.RIGHT:
return 13;
case DbObject.COMMENT:
case DbObject.AGGREGATE:
return 14;
case DbObject.COMMENT:
return 15;
default:
throw DbException.throwInternalError("type="+objectType);
}
......
......@@ -8,7 +8,6 @@ package org.h2.engine;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
......@@ -128,7 +127,7 @@ public class Right extends DbObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
return getCreateSQLForCopy(table);
}
......
......@@ -7,7 +7,7 @@ package org.h2.engine;
import java.util.HashMap;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.util.New;
/**
......@@ -63,7 +63,7 @@ public abstract class RightOwner extends DbObjectBase {
* @param rightMask the right mask to check
* @return true if the right was already granted
*/
boolean isRightGrantedRecursive(AbstractTable table, int rightMask) {
boolean isRightGrantedRecursive(Table table, int rightMask) {
Right right;
if (grantedRights != null) {
if (table != null) {
......
......@@ -7,7 +7,7 @@ package org.h2.engine;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* Represents a role. Roles can be granted to users, and to other roles.
......@@ -22,7 +22,7 @@ public class Role extends RightOwner {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......
......@@ -38,7 +38,6 @@ import org.h2.schema.Schema;
import org.h2.store.DataHandler;
import org.h2.store.InDoubtTransaction;
import org.h2.store.LobStorageFrontend;
import org.h2.table.AbstractTable;
import org.h2.table.SubQueryInfo;
import org.h2.table.Table;
import org.h2.table.TableFilter;
......@@ -373,7 +372,7 @@ public class Session extends SessionWithState {
*
* @param table the table
*/
public void removeLocalTempTable(AbstractTable table) {
public void removeLocalTempTable(Table table) {
modificationId++;
localTempTables.remove(table.getName());
synchronized (database) {
......@@ -878,7 +877,7 @@ public class Session extends SessionWithState {
* @param operation the operation type (see {@link UndoLogRecord})
* @param row the row
*/
public void log(AbstractTable table, short operation, Row row) {
public void log(Table table, short operation, Row row) {
if (table.isMVStore()) {
return;
}
......
......@@ -7,7 +7,7 @@ package org.h2.engine;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* A persistent database setting.
......@@ -38,7 +38,7 @@ public class Setting extends DbObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......
......@@ -10,7 +10,7 @@ import java.util.HashMap;
import org.h2.message.DbException;
import org.h2.store.Data;
import org.h2.store.FileStore;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.util.New;
/**
......@@ -25,7 +25,7 @@ public class UndoLog {
private Data rowBuff;
private int memoryUndo;
private int storedEntries;
private HashMap<Integer, AbstractTable> tables;
private HashMap<Integer, Table> tables;
private final boolean largeTransactions;
/**
......@@ -220,7 +220,7 @@ public class UndoLog {
* @param table the table
* @return the id
*/
int getTableId(AbstractTable table) {
int getTableId(Table table) {
int id = table.getId();
if (tables == null) {
tables = New.hashMap();
......@@ -238,7 +238,7 @@ public class UndoLog {
* @param id the table id
* @return the table object
*/
AbstractTable getTable(int id) {
Table getTable(int id) {
return tables.get(id);
}
......
......@@ -10,7 +10,7 @@ import org.h2.message.DbException;
import org.h2.result.Row;
import org.h2.store.Data;
import org.h2.store.FileStore;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.value.Value;
/**
......@@ -29,7 +29,7 @@ public class UndoLogRecord {
public static final short DELETE = 1;
private static final int IN_MEMORY = 0, STORED = 1, IN_MEMORY_INVALID = 2;
private AbstractTable table;
private Table table;
private Row row;
private short operation;
private short state;
......@@ -42,7 +42,7 @@ public class UndoLogRecord {
* @param op the operation type
* @param row the row that was deleted or inserted
*/
UndoLogRecord(AbstractTable table, short op, Row row) {
UndoLogRecord(Table table, short op, Row row) {
this.table = table;
this.row = row;
this.operation = op;
......@@ -233,7 +233,7 @@ public class UndoLogRecord {
*
* @return the table
*/
public AbstractTable getTable() {
public Table getTable() {
return table;
}
......
......@@ -12,9 +12,9 @@ import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.schema.Schema;
import org.h2.security.SHA256;
import org.h2.table.AbstractTable;
import org.h2.table.MetaTable;
import org.h2.table.RangeTable;
import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.table.TableView;
import org.h2.util.MathUtils;
......@@ -75,7 +75,7 @@ public class User extends RightOwner {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......@@ -96,7 +96,7 @@ public class User extends RightOwner {
* @param rightMask the rights required
* @throws DbException if this user does not have the required rights
*/
public void checkRight(AbstractTable table, int rightMask) {
public void checkRight(Table table, int rightMask) {
if (!hasRight(table, rightMask)) {
throw DbException.get(ErrorCode.NOT_ENOUGH_RIGHTS_FOR_1, table.getSQL());
}
......@@ -109,7 +109,7 @@ public class User extends RightOwner {
* @param rightMask the rights required
* @return true if the user has the rights
*/
public boolean hasRight(AbstractTable table, int rightMask) {
public boolean hasRight(Table table, int rightMask) {
if (rightMask != Right.SELECT && !systemUser && table != null) {
table.checkWritingAllowed();
}
......
......@@ -12,7 +12,7 @@ import org.h2.api.AggregateFunction;
import org.h2.command.Parser;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.util.JdbcUtils;
import org.h2.value.DataType;
......@@ -53,7 +53,7 @@ public class UserAggregate extends DbObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......
......@@ -7,8 +7,8 @@ package org.h2.engine;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.Table;
/**
* Represents a domain (user-defined data type).
......@@ -22,7 +22,7 @@ public class UserDataType extends DbObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......
......@@ -18,9 +18,9 @@ import org.h2.index.Index;
import org.h2.message.DbException;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.New;
import org.h2.util.StatementBuilder;
......@@ -281,7 +281,7 @@ public class Aggregate extends Expression {
switch (type) {
case COUNT:
case COUNT_ALL:
AbstractTable table = select.getTopTableFilter().getTable();
Table table = select.getTopTableFilter().getTable();
return ValueLong.get(table.getRowCount(session));
case MIN:
case MAX:
......@@ -580,7 +580,7 @@ public class Aggregate extends Expression {
Column column = col.getColumn();
TableFilter filter = col.getTableFilter();
if (filter != null) {
AbstractTable table = filter.getTable();
Table table = filter.getTable();
Index index = table.getIndexForColumn(column, true, false);
return index;
}
......
......@@ -16,9 +16,9 @@ import org.h2.index.IndexCondition;
import org.h2.message.DbException;
import org.h2.schema.Constant;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueBoolean;
......@@ -240,13 +240,13 @@ public class ExpressionColumn extends Expression {
@Override
public String getSchemaName() {
AbstractTable table = column.getTable();
Table table = column.getTable();
return table == null ? null : table.getSchema().getName();
}
@Override
public String getTableName() {
AbstractTable table = column.getTable();
Table table = column.getTable();
return table == null ? null : table.getName();
}
......
......@@ -7,9 +7,9 @@ package org.h2.expression;
import java.util.HashSet;
import org.h2.engine.DbObject;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.New;
......@@ -111,14 +111,14 @@ public class ExpressionVisitor {
private final int queryLevel;
private final HashSet<DbObject> dependencies;
private final HashSet<Column> columns;
private final AbstractTable table;
private final Table table;
private final long[] maxDataModificationId;
private final ColumnResolver resolver;
private ExpressionVisitor(int type,
int queryLevel,
HashSet<DbObject> dependencies,
HashSet<Column> columns, AbstractTable table, ColumnResolver resolver,
HashSet<Column> columns, Table table, ColumnResolver resolver,
long[] maxDataModificationId) {
this.type = type;
this.queryLevel = queryLevel;
......@@ -157,7 +157,7 @@ public class ExpressionVisitor {
* @param table the table
* @return the new visitor
*/
public static ExpressionVisitor getOptimizableVisitor(AbstractTable table) {
public static ExpressionVisitor getOptimizableVisitor(Table table) {
return new ExpressionVisitor(OPTIMIZABLE_MIN_MAX_COUNT_ALL, 0, null,
null, table, null, null);
}
......@@ -274,7 +274,7 @@ public class ExpressionVisitor {
*
* @return the table
*/
public AbstractTable getTable() {
public Table getTable() {
return table;
}
......
......@@ -37,10 +37,10 @@ import org.h2.security.BlockCipher;
import org.h2.security.CipherFactory;
import org.h2.security.SHA256;
import org.h2.store.fs.FileUtils;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.LinkSchema;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.tools.CompressTool;
import org.h2.tools.Csv;
......@@ -1160,7 +1160,7 @@ public class Function extends Expression implements FunctionCall {
private static long getDiskSpaceUsed(Session session, Value v0) {
Parser p = new Parser(session);
String sql = v0.getString();
AbstractTable table = p.parseTableName(sql);
Table table = p.parseTableName(sql);
return table.getDiskSpaceUsed();
}
......
......@@ -17,7 +17,6 @@ import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
import org.h2.schema.SchemaObjectBase;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.Table;
......@@ -397,7 +396,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
}
@Override
public String getCreateSQLForCopy(AbstractTable targetTable, String quotedName) {
public String getCreateSQLForCopy(Table targetTable, String quotedName) {
StringBuilder buff = new StringBuilder("CREATE ");
buff.append(indexType.getSQL());
buff.append(' ');
......
......@@ -16,7 +16,6 @@ import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
import org.h2.schema.Schema;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.RegularTable;
......@@ -252,7 +251,7 @@ public class MultiVersionIndex implements Index {
}
@Override
public String getCreateSQLForCopy(AbstractTable forTable, String quotedName) {
public String getCreateSQLForCopy(Table forTable, String quotedName) {
return base.getCreateSQLForCopy(forTable, quotedName);
}
......
......@@ -12,6 +12,7 @@ import java.sql.ResultSet;
import java.sql.RowIdLifetime;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import java.util.Properties;
import org.h2.engine.Constants;
import org.h2.engine.SysProperties;
......@@ -153,7 +154,8 @@ public class JdbcDatabaseMetaData extends TraceObject implements
} else {
tableType = "TRUE";
}
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
String tableSelect = "SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
......@@ -169,16 +171,55 @@ public class JdbcDatabaseMetaData extends TraceObject implements
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME LIKE ? ESCAPE ? "
+ "AND (" + tableType + ") "
+ "ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME");
+ "AND (" + tableType + ") ";
boolean includeSynonyms = types == null || Arrays.asList(types).contains("SYNONYM");
String synonymSelect = "SELECT "
+ "SYNONYM_CATALOG TABLE_CAT, "
+ "SYNONYM_SCHEMA TABLE_SCHEM, "
+ "SYNONYM_NAME as TABLE_NAME, "
+ "TYPE_NAME AS TABLE_TYPE, "
+ "REMARKS, "
+ "TYPE_NAME TYPE_CAT, "
+ "TYPE_NAME TYPE_SCHEM, "
+ "TYPE_NAME AS TYPE_NAME, "
+ "TYPE_NAME SELF_REFERENCING_COL_NAME, "
+ "TYPE_NAME REF_GENERATION, "
+ "NULL AS SQL "
+ "FROM INFORMATION_SCHEMA.SYNONYMS "
+ "WHERE SYNONYM_CATALOG LIKE ? ESCAPE ? "
+ "AND SYNONYM_SCHEMA LIKE ? ESCAPE ? "
+ "AND SYNONYM_NAME LIKE ? ESCAPE ? "
+ "AND (" + includeSynonyms + ") ";
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CAT, "
+ "TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "TABLE_TYPE, "
+ "REMARKS, "
+ "TYPE_CAT, "
+ "TYPE_SCHEM, "
+ "TYPE_NAME, "
+ "SELF_REFERENCING_COL_NAME, "
+ "REF_GENERATION, "
+ "SQL "
+ "FROM (" + synonymSelect + " UNION " + tableSelect + ") "
+ "ORDER BY TABLE_TYPE, TABLE_SCHEM, TABLE_NAME");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, getPattern(tableNamePattern));
prep.setString(6, "\\");
prep.setString(7, getCatalogPattern(catalogPattern));
prep.setString(8, "\\");
prep.setString(9, getSchemaPattern(schemaPattern));
prep.setString(10, "\\");
prep.setString(11, getPattern(tableNamePattern));
prep.setString(12, "\\");
for (int i = 0; types != null && i < types.length; i++) {
prep.setString(7 + i, types[i]);
prep.setString(13 + i, types[i]);
}
return prep.executeQuery();
} catch (Exception e) {
......
......@@ -10,7 +10,7 @@ import org.h2.engine.Session;
import org.h2.expression.ValueExpression;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.value.Value;
/**
......@@ -27,7 +27,7 @@ public class Constant extends SchemaObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......
......@@ -25,7 +25,6 @@ import org.h2.index.Index;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.mvstore.db.MVTableEngine;
import org.h2.table.AbstractTable;
import org.h2.table.RegularTable;
import org.h2.table.Table;
import org.h2.table.TableLink;
......@@ -43,7 +42,8 @@ public class Schema extends DbObjectBase {
private final boolean system;
private ArrayList<String> tableEngineParams;
private final ConcurrentHashMap<String, AbstractTable> tablesAndViews;
private final ConcurrentHashMap<String, Table> tablesAndViews;
private final ConcurrentHashMap<String, TableSynonym> synonyms;
private final ConcurrentHashMap<String, Index> indexes;
private final ConcurrentHashMap<String, Sequence> sequences;
private final ConcurrentHashMap<String, TriggerObject> triggers;
......@@ -71,6 +71,7 @@ public class Schema extends DbObjectBase {
public Schema(Database database, int id, String schemaName, User owner,
boolean system) {
tablesAndViews = database.newConcurrentStringMap();
synonyms = database.newConcurrentStringMap();
indexes = database.newConcurrentStringMap();
sequences = database.newConcurrentStringMap();
triggers = database.newConcurrentStringMap();
......@@ -92,7 +93,7 @@ public class Schema extends DbObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......@@ -132,7 +133,7 @@ public class Schema extends DbObjectBase {
runLoopAgain = false;
if (tablesAndViews != null) {
// Loop over a copy because the map is modified underneath us.
for (AbstractTable obj : New.arrayList(tablesAndViews.values())) {
for (Table obj : New.arrayList(tablesAndViews.values())) {
// Check for null because multiple tables might be deleted
// in one go underneath us.
if (obj.getName() != null) {
......@@ -204,6 +205,9 @@ public class Schema extends DbObjectBase {
case DbObject.TABLE_OR_VIEW:
result = tablesAndViews;
break;
case DbObject.SYNONYM:
result = synonyms;
break;
case DbObject.SEQUENCE:
result = sequences;
break;
......@@ -276,20 +280,53 @@ public class Schema extends DbObjectBase {
/**
* Try to find a table or view with this name. This method returns null if
* no object with this name exists. Local temporary tables are also
* returned.
* returned. Synonyms are not returned or resolved.
*
* @param session the session
* @param name the object name
* @return the object or null
*/
public AbstractTable findTableOrView(Session session, String name) {
AbstractTable table = tablesAndViews.get(name);
public Table findTableOrView(Session session, String name) {
Table table = tablesAndViews.get(name);
if (table == null && session != null) {
table = session.findLocalTempTable(name);
}
return table;
}
/**
* Try to find a table or view with this name. This method returns null if
* no object with this name exists. Local temporary tables are also
* returned. If a synonym with this name exists, the backing table of the
* synonym is returned
*
* @param session the session
* @param name the object name
* @return the object or null
*/
public Table resolveTableOrView(Session session, String name) {
Table table = findTableOrView(session, name);
if (table == null) {
TableSynonym synonym = synonyms.get(name);
if (synonym != null) {
return synonym.getSynonymFor();
}
return null;
}
return table;
}
/**
* Try to find a synonym with this name. This method returns null if
* no object with this name exists.
*
* @param name the object name
* @return the object or null
*/
public TableSynonym getSynonym(String name) {
return synonyms.get(name);
}
/**
* Try to find an index with this name. This method returns null if
* no object with this name exists.
......@@ -412,7 +449,7 @@ public class Schema extends DbObjectBase {
* @param table the constraint table
* @return the unique name
*/
public String getUniqueConstraintName(Session session, AbstractTable table) {
public String getUniqueConstraintName(Session session, Table table) {
Map<String, Constraint> tableConstraints;
if (table.isTemporary() && !table.isGlobalTemporary()) {
tableConstraints = session.getLocalTempTableConstraints();
......@@ -430,7 +467,7 @@ public class Schema extends DbObjectBase {
* @param prefix the index name prefix
* @return the unique name
*/
public String getUniqueIndexName(Session session, AbstractTable table, String prefix) {
public String getUniqueIndexName(Session session, Table table, String prefix) {
Map<String, Index> tableIndexes;
if (table.isTemporary() && !table.isGlobalTemporary()) {
tableIndexes = session.getLocalTempTableIndexes();
......@@ -449,8 +486,8 @@ public class Schema extends DbObjectBase {
* @return the table or view
* @throws DbException if no such object exists
*/
public AbstractTable getTableOrView(Session session, String name) {
AbstractTable table = tablesAndViews.get(name);
public Table getTableOrView(Session session, String name) {
Table table = tablesAndViews.get(name);
if (table == null) {
if (session != null) {
table = session.findLocalTempTable(name);
......@@ -555,19 +592,26 @@ public class Schema extends DbObjectBase {
*
* @return a (possible empty) list of all objects
*/
public ArrayList<AbstractTable> getAllTablesAndViews() {
public ArrayList<Table> getAllTablesAndViews() {
synchronized (database) {
return New.arrayList(tablesAndViews.values());
}
}
public ArrayList<TableSynonym> getAllSynonyms() {
synchronized (database) {
return New.arrayList(synonyms.values());
}
}
/**
* Get the table with the given name, if any.
*
* @param name the table name
* @return the table or null if not found
*/
public AbstractTable getTableOrViewByName(String name) {
public Table getTableOrViewByName(String name) {
synchronized (database) {
return tablesAndViews.get(name);
}
......
......@@ -11,7 +11,7 @@ import org.h2.engine.DbObject;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
/**
* A sequence is created using the statement
......@@ -206,7 +206,7 @@ public class Sequence extends SchemaObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError(toString());
}
......
......@@ -18,7 +18,7 @@ import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.result.Row;
import org.h2.table.AbstractTable;
import org.h2.table.Table;
import org.h2.util.JdbcUtils;
import org.h2.util.SourceCompiler;
import org.h2.util.StatementBuilder;
......@@ -45,12 +45,12 @@ public class TriggerObject extends SchemaObjectBase {
// TODO trigger: support queue and noWait = false as well
private int queueSize = DEFAULT_QUEUE_SIZE;
private boolean noWait;
private AbstractTable table;
private Table table;
private String triggerClassName;
private String triggerSource;
private Trigger triggerCallback;
public TriggerObject(Schema schema, int id, String name, AbstractTable table) {
public TriggerObject(Schema schema, int id, String name, Table table) {
initSchemaObjectBase(schema, id, name, Trace.TRIGGER);
this.table = table;
setTemporary(table.isTemporary());
......@@ -318,7 +318,7 @@ public class TriggerObject extends SchemaObjectBase {
}
@Override
public String getCreateSQLForCopy(AbstractTable targetTable, String quotedName) {
public String getCreateSQLForCopy(Table targetTable, String quotedName) {
StringBuilder buff = new StringBuilder("CREATE FORCE TRIGGER ");
buff.append(quotedName);
if (insteadOf) {
......@@ -409,7 +409,7 @@ public class TriggerObject extends SchemaObjectBase {
*
* @return the table
*/
public AbstractTable getTable() {
public Table getTable() {
return table;
}
......
......@@ -37,7 +37,6 @@ import org.h2.message.Trace;
import org.h2.result.Row;
import org.h2.schema.Schema;
import org.h2.store.fs.FileUtils;
import org.h2.table.AbstractTable;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.RegularTable;
......@@ -553,12 +552,12 @@ public class PageStore implements CacheWriter {
log.checkpoint();
writeBack();
cache.clear();
ArrayList<AbstractTable> tables = database.getAllTablesAndViews(false);
ArrayList<Table> tables = database.getAllTablesAndViews(false);
recordedPagesList = New.arrayList();
recordedPagesIndex = new IntIntHashMap();
recordPageReads = true;
Session sysSession = database.getSystemSession();
for (AbstractTable table : tables) {
for (Table table : tables) {
if (!table.isTemporary() && TableType.TABLE == table.getTableType()) {
Index scanIndex = table.getScanIndex(sysSession);
Cursor cursor = scanIndex.find(sysSession, null, null);
......
......@@ -70,7 +70,7 @@ public class Column {
private int scale;
private String[] enumerators;
private int displaySize;
private AbstractTable table;
private Table table;
private String name;
private int columnId;
private boolean nullable = true;
......@@ -224,12 +224,12 @@ public class Column {
* @param table the table
* @param columnId the column index
*/
public void setTable(AbstractTable table, int columnId) {
public void setTable(Table table, int columnId) {
this.table = table;
this.columnId = columnId;
}
public AbstractTable getTable() {
public Table getTable() {
return table;
}
......
......@@ -69,7 +69,7 @@ public class IndexColumn {
* @param indexColumns the column list with column names set
* @param table the table from where to map the column names to columns
*/
public static void mapColumns(IndexColumn[] indexColumns, AbstractTable table) {
public static void mapColumns(IndexColumn[] indexColumns, Table table) {
for (IndexColumn col : indexColumns) {
col.column = table.getColumn(col.columnName);
}
......
......@@ -546,6 +546,7 @@ public class MetaTable extends Table {
"SYNONYM_SCHEMA",
"SYNONYM_NAME",
"SYNONYM_FOR",
"TYPE_NAME",
"STATUS",
"REMARKS",
"ID INT"
......@@ -624,18 +625,18 @@ public class MetaTable extends Table {
return s;
}
private ArrayList<AbstractTable> getAllTables(Session session) {
ArrayList<AbstractTable> tables = database.getAllTablesAndViews(true);
private ArrayList<Table> getAllTables(Session session) {
ArrayList<Table> tables = database.getAllTablesAndViews(true);
ArrayList<Table> tempTables = session.getLocalTempTables();
tables.addAll(tempTables);
return tables;
}
private ArrayList<AbstractTable> getTablesByName(Session session, String tableName) {
private ArrayList<Table> getTablesByName(Session session, String tableName) {
if (database.getMode().lowerCaseIdentifiers) {
tableName = StringUtils.toUpperEnglish(tableName);
}
ArrayList<AbstractTable> tables = database.getTableOrViewByName(tableName);
ArrayList<Table> tables = database.getTableOrViewByName(tableName);
for (Table temp : session.getLocalTempTables()) {
if (temp.getName().equals(tableName)) {
tables.add(temp);
......@@ -669,7 +670,7 @@ public class MetaTable extends Table {
return s == null ? "" : s;
}
private boolean hideTable(AbstractTable table, Session session) {
private boolean hideTable(Table table, Session session) {
return table.isHidden() && session != database.getSystemSession();
}
......@@ -700,7 +701,7 @@ public class MetaTable extends Table {
boolean admin = session.getUser().isAdmin();
switch (type) {
case TABLES: {
for (AbstractTable table : getAllTables(session)) {
for (Table table : getAllTables(session)) {
String tableName = identifier(table.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
......@@ -758,14 +759,14 @@ public class MetaTable extends Table {
case COLUMNS: {
// reduce the number of tables to scan - makes some metadata queries
// 10x faster
final ArrayList<AbstractTable> tablesToList;
final ArrayList<Table> tablesToList;
if (indexFrom != null && indexTo != null && indexFrom.equals(indexTo)) {
String tableName = identifier(indexFrom.getString());
tablesToList = getTablesByName(session, tableName);
} else {
tablesToList = getAllTables(session);
}
for (AbstractTable table : tablesToList) {
for (Table table : tablesToList) {
String tableName = identifier(table.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
......@@ -835,14 +836,14 @@ public class MetaTable extends Table {
case INDEXES: {
// reduce the number of tables to scan - makes some metadata queries
// 10x faster
final ArrayList<AbstractTable> tablesToList;
final ArrayList<Table> tablesToList;
if (indexFrom != null && indexTo != null && indexFrom.equals(indexTo)) {
String tableName = identifier(indexFrom.getString());
tablesToList = getTablesByName(session, tableName);
} else {
tablesToList = getAllTables(session);
}
for (AbstractTable table : tablesToList) {
for (Table table : tablesToList) {
String tableName = identifier(table.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
......@@ -1488,7 +1489,7 @@ public class MetaTable extends Table {
break;
}
case VIEWS: {
for (AbstractTable table : getAllTables(session)) {
for (Table table : getAllTables(session)) {
if (table.getTableType() != TableType.VIEW) {
continue;
}
......@@ -1544,8 +1545,8 @@ public class MetaTable extends Table {
ConstraintReferential ref = (ConstraintReferential) constraint;
IndexColumn[] cols = ref.getColumns();
IndexColumn[] refCols = ref.getRefColumns();
AbstractTable tab = ref.getTable();
AbstractTable refTab = ref.getRefTable();
Table tab = ref.getTable();
Table refTab = ref.getRefTable();
String tableName = identifier(refTab.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
......@@ -1594,7 +1595,7 @@ public class MetaTable extends Table {
String constraintType = constraint.getConstraintType();
String checkExpression = null;
IndexColumn[] indexColumns = null;
AbstractTable table = constraint.getTable();
Table table = constraint.getTable();
if (hideTable(table, session)) {
continue;
}
......@@ -1719,7 +1720,7 @@ public class MetaTable extends Table {
for (SchemaObject obj : database.getAllSchemaObjects(
DbObject.TRIGGER)) {
TriggerObject trigger = (TriggerObject) obj;
AbstractTable table = trigger.getTable();
Table table = trigger.getTable();
add(rows,
// TRIGGER_CATALOG
catalog,
......@@ -1878,23 +1879,20 @@ public class MetaTable extends Table {
break;
}
case SYNONYMS: {
for (AbstractTable table : getAllTables(session)) {
if (!table.getTableType().equals(TableType.SYNONYM)) {
continue;
}
String synonymName = identifier(table.getName());
TableSynonym synonym = (TableSynonym) table;
for (TableSynonym synonym : database.getAllSynonyms()) {
add(rows,
// SYNONYM_CATALOG
catalog,
// SYNONYM_SCHEMA
identifier(table.getSchema().getName()),
identifier(synonym.getSchema().getName()),
// SYNONYM_NAME
synonymName,
identifier(synonym.getName()),
// SYNONYM_FOR
synonym.getSynonymForName(),
// TYPE NAME
"SYNONYM",
// STATUS
synonym.isInvalid() ? "INVALID" : "VALID",
"VALID",
// REMARKS
replaceNullWithEmpty(synonym.getComment()),
// ID
......
......@@ -51,7 +51,7 @@ public class TableFilter implements ColumnResolver {
private Session session;
private final AbstractTable table;
private final Table table;
private final Select select;
private String alias;
private Index index;
......@@ -128,7 +128,7 @@ public class TableFilter implements ColumnResolver {
* @param orderInFrom original order number (index) of this table filter in
* @param indexHints the index hints to be used by the query planner
*/
public TableFilter(Session session, AbstractTable table, String alias,
public TableFilter(Session session, Table table, String alias,
boolean rightsChecked, Select select, int orderInFrom, IndexHints indexHints) {
this.session = session;
this.table = table;
......@@ -162,7 +162,7 @@ public class TableFilter implements ColumnResolver {
return select;
}
public AbstractTable getTable() {
public Table getTable() {
return table;
}
......
......@@ -33,12 +33,7 @@ public enum TableType {
/**
* The table type name for external table engines.
*/
EXTERNAL_TABLE_ENGINE,
/**
* The table type name for synonyms.
*/
SYNONYM;
EXTERNAL_TABLE_ENGINE;
@Override
public String toString() {
......
......@@ -45,7 +45,7 @@ public class TableView extends Table {
private static final long ROW_COUNT_APPROXIMATION = 100;
private String querySQL;
private ArrayList<AbstractTable> tables;
private ArrayList<Table> tables;
private Column[] columnTemplates;
private Query viewQuery;
private ViewIndex index;
......@@ -265,7 +265,7 @@ public class TableView extends Table {
if (!super.isQueryComparable()) {
return false;
}
for (AbstractTable t : tables) {
for (Table t : tables) {
if (!t.isQueryComparable()) {
return false;
}
......@@ -287,7 +287,7 @@ public class TableView extends Table {
}
@Override
public String getCreateSQLForCopy(AbstractTable table, String quotedName) {
public String getCreateSQLForCopy(Table table, String quotedName) {
return getCreateSQL(false, true, quotedName);
}
......@@ -502,7 +502,7 @@ public class TableView extends Table {
private void removeViewFromTables() {
if (tables != null) {
for (AbstractTable t : tables) {
for (Table t : tables) {
t.removeView(this);
}
tables.clear();
......@@ -510,7 +510,7 @@ public class TableView extends Table {
}
private void addViewToTables() {
for (AbstractTable t : tables) {
for (Table t : tables) {
t.addView(this);
}
}
......@@ -620,7 +620,7 @@ public class TableView extends Table {
public void addDependencies(HashSet<DbObject> dependencies) {
super.addDependencies(dependencies);
if (tables != null) {
for (AbstractTable t : tables) {
for (Table t : tables) {
if (TableType.VIEW != t.getTableType()) {
t.addDependencies(dependencies);
}
......
......@@ -95,6 +95,7 @@ public class TestPreparedStatement extends TestBase {
testColumnMetaDataWithIn(conn);
conn.close();
testPreparedStatementWithLiteralsNone();
testPreparedStatementWithIndexedParameterAndLiteralsNone();
deleteDb("preparedStatement");
}
......@@ -1420,6 +1421,27 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement");
}
private void testPreparedStatementWithIndexedParameterAndLiteralsNone() throws SQLException {
// make sure that when the analyze table kicks in,
// it works with ALLOW_LITERALS=NONE
deleteDb("preparedStatement");
Connection conn = getConnection(
"preparedStatement;ANALYZE_AUTO=100");
conn.createStatement().execute(
"SET ALLOW_LITERALS NONE");
conn.prepareStatement("CREATE TABLE test (id INT)").execute();
PreparedStatement ps = conn.prepareStatement(
"INSERT INTO test (id) VALUES (?1)");
ps.setInt(1, 1);
ps.executeUpdate();
conn.close();
deleteDb("preparedStatement");
}
private void checkBigDecimal(ResultSet rs, String[] value) throws SQLException {
for (String v : value) {
assertTrue(rs.next());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论