提交 ff7d9f9a authored 作者: Noel Grandin's avatar Noel Grandin

convert Table Type to enum

上级 e4440728
...@@ -15,6 +15,7 @@ import org.h2.expression.Parameter; ...@@ -15,6 +15,7 @@ import org.h2.expression.Parameter;
import org.h2.result.ResultInterface; import org.h2.result.ResultInterface;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
...@@ -57,7 +58,7 @@ public class Analyze extends DefineCommand { ...@@ -57,7 +58,7 @@ public class Analyze extends DefineCommand {
*/ */
public static void analyzeTable(Session session, Table table, int sample, public static void analyzeTable(Session session, Table table, int sample,
boolean manual) { boolean manual) {
if (!(table.getTableType().equals(Table.TABLE)) || if (table.getTableType() != TableType.TABLE ||
table.isHidden() || session == null) { table.isHidden() || session == null) {
return; return;
} }
......
...@@ -17,6 +17,7 @@ import org.h2.message.DbException; ...@@ -17,6 +17,7 @@ import org.h2.message.DbException;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.table.TableView; import org.h2.table.TableView;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -82,7 +83,7 @@ public class CreateView extends SchemaCommand { ...@@ -82,7 +83,7 @@ public class CreateView extends SchemaCommand {
if (ifNotExists) { if (ifNotExists) {
return 0; return 0;
} }
if (!orReplace || !Table.VIEW.equals(old.getTableType())) { if (!orReplace || TableType.VIEW != old.getTableType()) {
throw DbException.get(ErrorCode.VIEW_ALREADY_EXISTS_1, viewName); throw DbException.get(ErrorCode.VIEW_ALREADY_EXISTS_1, viewName);
} }
view = (TableView) old; view = (TableView) old;
......
...@@ -15,6 +15,7 @@ import org.h2.engine.User; ...@@ -15,6 +15,7 @@ import org.h2.engine.User;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.schema.SchemaObject; import org.h2.schema.SchemaObject;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.util.New; import org.h2.util.New;
/** /**
...@@ -55,26 +56,26 @@ public class DropDatabase extends DefineCommand { ...@@ -55,26 +56,26 @@ public class DropDatabase extends DefineCommand {
ArrayList<Table> toRemove = New.arrayList(); ArrayList<Table> toRemove = New.arrayList();
for (Table t : tables) { for (Table t : tables) {
if (t.getName() != null && if (t.getName() != null &&
Table.VIEW.equals(t.getTableType())) { TableType.VIEW == t.getTableType()) {
toRemove.add(t); toRemove.add(t);
} }
} }
for (Table t : tables) { for (Table t : tables) {
if (t.getName() != null && if (t.getName() != null &&
Table.TABLE_LINK.equals(t.getTableType())) { TableType.TABLE_LINK == t.getTableType()) {
toRemove.add(t); toRemove.add(t);
} }
} }
for (Table t : tables) { for (Table t : tables) {
if (t.getName() != null && if (t.getName() != null &&
Table.TABLE.equals(t.getTableType()) && TableType.TABLE == t.getTableType() &&
!t.isHidden()) { !t.isHidden()) {
toRemove.add(t); toRemove.add(t);
} }
} }
for (Table t : tables) { for (Table t : tables) {
if (t.getName() != null && if (t.getName() != null &&
Table.EXTERNAL_TABLE_ENGINE.equals(t.getTableType()) && TableType.EXTERNAL_TABLE_ENGINE == t.getTableType() &&
!t.isHidden()) { !t.isHidden()) {
toRemove.add(t); toRemove.add(t);
} }
......
...@@ -14,6 +14,7 @@ import org.h2.engine.Session; ...@@ -14,6 +14,7 @@ import org.h2.engine.Session;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.table.TableView; import org.h2.table.TableView;
/** /**
...@@ -54,7 +55,7 @@ public class DropView extends SchemaCommand { ...@@ -54,7 +55,7 @@ public class DropView extends SchemaCommand {
throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName); throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
} }
} else { } else {
if (!Table.VIEW.equals(view.getTableType())) { if (TableType.VIEW != view.getTableType()) {
throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName); throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
} }
session.getUser().checkRight(view, Right.ALL); session.getUser().checkRight(view, Right.ALL);
......
...@@ -52,6 +52,7 @@ import org.h2.schema.TriggerObject; ...@@ -52,6 +52,7 @@ import org.h2.schema.TriggerObject;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.PlanItem; import org.h2.table.PlanItem;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
...@@ -277,7 +278,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -277,7 +278,7 @@ public class ScriptCommand extends ScriptBase {
// null for metadata tables // null for metadata tables
continue; continue;
} }
final String tableType = table.getTableType(); final TableType tableType = table.getTableType();
add(createTableSql, false); add(createTableSql, false);
final ArrayList<Constraint> constraints = table.getConstraints(); final ArrayList<Constraint> constraints = table.getConstraints();
if (constraints != null) { if (constraints != null) {
...@@ -288,7 +289,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -288,7 +289,7 @@ public class ScriptCommand extends ScriptBase {
} }
} }
} }
if (Table.TABLE.equals(tableType)) { if (TableType.TABLE == tableType) {
if (table.canGetRowCount()) { if (table.canGetRowCount()) {
String rowcount = "-- " + String rowcount = "-- " +
table.getRowCountApproximation() + table.getRowCountApproximation() +
......
...@@ -54,6 +54,7 @@ import org.h2.table.IndexColumn; ...@@ -54,6 +54,7 @@ import org.h2.table.IndexColumn;
import org.h2.table.MetaTable; import org.h2.table.MetaTable;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableLinkConnection; import org.h2.table.TableLinkConnection;
import org.h2.table.TableType;
import org.h2.table.TableView; import org.h2.table.TableView;
import org.h2.tools.DeleteDbFiles; import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Server; import org.h2.tools.Server;
...@@ -1798,7 +1799,7 @@ public class Database implements DataHandler { ...@@ -1798,7 +1799,7 @@ public class Database implements DataHandler {
for (Table t : getAllTablesAndViews(false)) { for (Table t : getAllTablesAndViews(false)) {
if (except == t) { if (except == t) {
continue; continue;
} else if (Table.VIEW.equals(t.getTableType())) { } else if (TableType.VIEW == t.getTableType()) {
continue; continue;
} }
set.clear(); set.clear();
......
...@@ -39,6 +39,7 @@ import org.h2.store.LobStorageFrontend; ...@@ -39,6 +39,7 @@ import org.h2.store.LobStorageFrontend;
import org.h2.table.SubQueryInfo; import org.h2.table.SubQueryInfo;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.table.TableType;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -864,10 +865,10 @@ public class Session extends SessionWithState { ...@@ -864,10 +865,10 @@ public class Session extends SessionWithState {
int lockMode = database.getLockMode(); int lockMode = database.getLockMode();
if (lockMode != Constants.LOCK_MODE_OFF && if (lockMode != Constants.LOCK_MODE_OFF &&
!database.isMultiVersion()) { !database.isMultiVersion()) {
String tableType = log.getTable().getTableType(); TableType tableType = log.getTable().getTableType();
if (locks.indexOf(log.getTable()) < 0 if (locks.indexOf(log.getTable()) < 0
&& !Table.TABLE_LINK.equals(tableType) && TableType.TABLE_LINK != tableType
&& !Table.EXTERNAL_TABLE_ENGINE.equals(tableType)) { && TableType.EXTERNAL_TABLE_ENGINE != tableType) {
DbException.throwInternalError(); DbException.throwInternalError();
} }
} }
......
...@@ -7,7 +7,6 @@ package org.h2.engine; ...@@ -7,7 +7,6 @@ package org.h2.engine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.message.Trace; import org.h2.message.Trace;
...@@ -16,6 +15,7 @@ import org.h2.security.SHA256; ...@@ -16,6 +15,7 @@ import org.h2.security.SHA256;
import org.h2.table.MetaTable; import org.h2.table.MetaTable;
import org.h2.table.RangeTable; import org.h2.table.RangeTable;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.table.TableView; import org.h2.table.TableView;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.New; import org.h2.util.New;
...@@ -128,8 +128,8 @@ public class User extends RightOwner { ...@@ -128,8 +128,8 @@ public class User extends RightOwner {
if (hasRight(null, Right.ALTER_ANY_SCHEMA)) { if (hasRight(null, Right.ALTER_ANY_SCHEMA)) {
return true; return true;
} }
String tableType = table.getTableType(); TableType tableType = table.getTableType();
if (Table.VIEW.equals(tableType)) { if (TableType.VIEW == tableType) {
TableView v = (TableView) table; TableView v = (TableView) table;
if (v.getOwner() == this) { if (v.getOwner() == this) {
// the owner of a view has access: // the owner of a view has access:
......
...@@ -19,7 +19,7 @@ import org.h2.expression.ExpressionVisitor; ...@@ -19,7 +19,7 @@ import org.h2.expression.ExpressionVisitor;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.ResultInterface; import org.h2.result.ResultInterface;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.TableType;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.value.CompareMode; import org.h2.value.CompareMode;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -248,7 +248,7 @@ public class IndexCondition { ...@@ -248,7 +248,7 @@ public class IndexCondition {
case Comparison.IN_LIST: case Comparison.IN_LIST:
case Comparison.IN_QUERY: case Comparison.IN_QUERY:
if (indexConditions.size() > 1) { if (indexConditions.size() > 1) {
if (!Table.TABLE.equals(column.getTable().getTableType())) { if (TableType.TABLE != column.getTable().getTableType()) {
// if combined with other conditions, // if combined with other conditions,
// IN(..) can only be used for regular tables // IN(..) can only be used for regular tables
// test case: // test case:
......
...@@ -11,7 +11,6 @@ import java.util.Collections; ...@@ -11,7 +11,6 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.h2.api.DatabaseEventListener; import org.h2.api.DatabaseEventListener;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.ddl.Analyze; import org.h2.command.ddl.Analyze;
...@@ -38,6 +37,7 @@ import org.h2.table.Column; ...@@ -38,6 +37,7 @@ import org.h2.table.Column;
import org.h2.table.IndexColumn; import org.h2.table.IndexColumn;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableBase; import org.h2.table.TableBase;
import org.h2.table.TableType;
import org.h2.util.DebuggingThreadLocal; import org.h2.util.DebuggingThreadLocal;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.New; import org.h2.util.New;
...@@ -744,8 +744,8 @@ public class MVTable extends TableBase { ...@@ -744,8 +744,8 @@ public class MVTable extends TableBase {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
return Table.TABLE; return TableType.TABLE;
} }
@Override @Override
......
...@@ -11,7 +11,6 @@ import java.util.ArrayList; ...@@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
...@@ -41,6 +40,7 @@ import org.h2.table.Column; ...@@ -41,6 +40,7 @@ import org.h2.table.Column;
import org.h2.table.IndexColumn; import org.h2.table.IndexColumn;
import org.h2.table.RegularTable; import org.h2.table.RegularTable;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.util.BitField; import org.h2.util.BitField;
import org.h2.util.Cache; import org.h2.util.Cache;
import org.h2.util.CacheLRU; import org.h2.util.CacheLRU;
...@@ -557,7 +557,7 @@ public class PageStore implements CacheWriter { ...@@ -557,7 +557,7 @@ public class PageStore implements CacheWriter {
recordPageReads = true; recordPageReads = true;
Session sysSession = database.getSystemSession(); Session sysSession = database.getSystemSession();
for (Table table : tables) { for (Table table : tables) {
if (!table.isTemporary() && Table.TABLE.equals(table.getTableType())) { if (!table.isTemporary() && TableType.TABLE == table.getTableType()) {
Index scanIndex = table.getScanIndex(sysSession); Index scanIndex = table.getScanIndex(sysSession);
Cursor cursor = scanIndex.find(sysSession, null, null); Cursor cursor = scanIndex.find(sysSession, null, null);
while (cursor.next()) { while (cursor.next()) {
......
...@@ -9,7 +9,6 @@ import java.sql.ResultSet; ...@@ -9,7 +9,6 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
...@@ -140,7 +139,7 @@ public class FunctionTable extends Table { ...@@ -140,7 +139,7 @@ public class FunctionTable extends Table {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
return null; return null;
} }
......
...@@ -718,7 +718,7 @@ public class MetaTable extends Table { ...@@ -718,7 +718,7 @@ public class MetaTable extends Table {
// TABLE_NAME // TABLE_NAME
tableName, tableName,
// TABLE_TYPE // TABLE_TYPE
table.getTableType(), table.getTableType().toString(),
// STORAGE_TYPE // STORAGE_TYPE
storageType, storageType,
// SQL // SQL
...@@ -920,11 +920,11 @@ public class MetaTable extends Table { ...@@ -920,11 +920,11 @@ public class MetaTable extends Table {
break; break;
} }
case TABLE_TYPES: { case TABLE_TYPES: {
add(rows, Table.TABLE); add(rows, TableType.TABLE.toString());
add(rows, Table.TABLE_LINK); add(rows, TableType.TABLE_LINK.toString());
add(rows, Table.SYSTEM_TABLE); add(rows, TableType.SYSTEM_TABLE.toString());
add(rows, Table.VIEW); add(rows, TableType.VIEW.toString());
add(rows, Table.EXTERNAL_TABLE_ENGINE); add(rows, TableType.EXTERNAL_TABLE_ENGINE.toString());
break; break;
} }
case CATALOGS: { case CATALOGS: {
...@@ -1470,7 +1470,7 @@ public class MetaTable extends Table { ...@@ -1470,7 +1470,7 @@ public class MetaTable extends Table {
} }
case VIEWS: { case VIEWS: {
for (Table table : getAllTables(session)) { for (Table table : getAllTables(session)) {
if (!table.getTableType().equals(Table.VIEW)) { if (table.getTableType() != TableType.VIEW) {
continue; continue;
} }
String tableName = identifier(table.getName()); String tableName = identifier(table.getName());
...@@ -2014,8 +2014,8 @@ public class MetaTable extends Table { ...@@ -2014,8 +2014,8 @@ public class MetaTable extends Table {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
return Table.SYSTEM_TABLE; return TableType.SYSTEM_TABLE;
} }
@Override @Override
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
package org.h2.table; package org.h2.table;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
...@@ -144,7 +143,7 @@ public class RangeTable extends Table { ...@@ -144,7 +143,7 @@ public class RangeTable extends Table {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
throw DbException.throwInternalError(); throw DbException.throwInternalError();
} }
......
...@@ -760,8 +760,8 @@ public class RegularTable extends TableBase { ...@@ -760,8 +760,8 @@ public class RegularTable extends TableBase {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
return Table.TABLE; return TableType.TABLE;
} }
@Override @Override
......
...@@ -55,31 +55,6 @@ public abstract class Table extends SchemaObjectBase { ...@@ -55,31 +55,6 @@ public abstract class Table extends SchemaObjectBase {
*/ */
public static final int TYPE_MEMORY = 1; public static final int TYPE_MEMORY = 1;
/**
* The table type name for linked tables.
*/
public static final String TABLE_LINK = "TABLE LINK";
/**
* The table type name for system tables.
*/
public static final String SYSTEM_TABLE = "SYSTEM TABLE";
/**
* The table type name for regular data tables.
*/
public static final String TABLE = "TABLE";
/**
* The table type name for views.
*/
public static final String VIEW = "VIEW";
/**
* The table type name for external table engines.
*/
public static final String EXTERNAL_TABLE_ENGINE = "EXTERNAL";
/** /**
* The columns of this table. * The columns of this table.
*/ */
...@@ -230,7 +205,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -230,7 +205,7 @@ public abstract class Table extends SchemaObjectBase {
* *
* @return the table type name * @return the table type name
*/ */
public abstract String getTableType(); public abstract TableType getTableType();
/** /**
* Get the scan index to iterate through all rows. * Get the scan index to iterate through all rows.
......
...@@ -566,8 +566,8 @@ public class TableLink extends Table { ...@@ -566,8 +566,8 @@ public class TableLink extends Table {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
return Table.TABLE_LINK; return TableType.TABLE_LINK;
} }
@Override @Override
......
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.table;
public enum TableType {
/**
* The table type name for linked tables.
*/
TABLE_LINK,
/**
* The table type name for system tables. (aka. MetaTable)
*/
SYSTEM_TABLE,
/**
* The table type name for regular data tables.
*/
TABLE,
/**
* The table type name for views.
*/
VIEW,
/**
* The table type name for external table engines.
*/
EXTERNAL_TABLE_ENGINE;
@Override
public String toString() {
if (this == EXTERNAL_TABLE_ENGINE) {
return "EXTERNAL";
} else if (this == SYSTEM_TABLE) {
return "SYSTEM TABLE";
} else if (this == TABLE_LINK) {
return "TABLE LINK";
} else {
return super.toString();
}
}
}
...@@ -404,8 +404,8 @@ public class TableView extends Table { ...@@ -404,8 +404,8 @@ public class TableView extends Table {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
return Table.VIEW; return TableType.VIEW;
} }
@Override @Override
...@@ -615,7 +615,7 @@ public class TableView extends Table { ...@@ -615,7 +615,7 @@ public class TableView extends Table {
super.addDependencies(dependencies); super.addDependencies(dependencies);
if (tables != null) { if (tables != null) {
for (Table t : tables) { for (Table t : tables) {
if (!Table.VIEW.equals(t.getTableType())) { if (TableType.VIEW != t.getTableType()) {
t.addDependencies(dependencies); t.addDependencies(dependencies);
} }
} }
......
...@@ -47,6 +47,7 @@ import org.h2.table.SubQueryInfo; ...@@ -47,6 +47,7 @@ import org.h2.table.SubQueryInfo;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableBase; import org.h2.table.TableBase;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.table.TableType;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.DoneFuture; import org.h2.util.DoneFuture;
import org.h2.util.New; import org.h2.util.New;
...@@ -1009,8 +1010,8 @@ public class TestTableEngines extends TestBase { ...@@ -1009,8 +1010,8 @@ public class TestTableEngines extends TestBase {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
return EXTERNAL_TABLE_ENGINE; return TableType.EXTERNAL_TABLE_ENGINE;
} }
@Override @Override
...@@ -1260,8 +1261,8 @@ public class TestTableEngines extends TestBase { ...@@ -1260,8 +1261,8 @@ public class TestTableEngines extends TestBase {
} }
@Override @Override
public String getTableType() { public TableType getTableType() {
return EXTERNAL_TABLE_ENGINE; return TableType.EXTERNAL_TABLE_ENGINE;
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论