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

convert Table Type to enum

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