提交 3fdc3e0a authored 作者: Niklas Mehner's avatar Niklas Mehner

Implemented:

* Add missing file
* prepare for function/sequence aliases.
上级 3a4a3dbf
......@@ -8,15 +8,11 @@ package org.h2.command.ddl;
import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.TableSynonym;
import org.h2.table.Table;
import org.h2.util.New;
import java.util.HashSet;
/**
* This class represents the statement
......@@ -61,6 +57,21 @@ public class CreateSynonym extends SchemaCommand {
// TODO: Check when/if meta data is unlocked...
db.lockMeta(session);
// This call throws an exception if the table does not exist.
if (data.synonymForSchema.findTableOrView(session, data.synonymFor) != null) {
return createTableSynonym(db);
} else if (data.synonymForSchema.findFunction(data.synonymFor) != null) {
// TODO Implement function synonym
} else if (data.synonymForSchema.findSequence(data.synonymFor) != null) {
// TODO Implement sequence synonym
}
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1,
data.synonymForSchema.getName() + "." + data.synonymFor);
}
private int createTableSynonym(Database db) {
Table old = getSchema().findTableOrView(session, data.synonymName);
if (old != null) {
if (orReplace && old instanceof TableSynonym) {
......@@ -72,8 +83,6 @@ public class CreateSynonym extends SchemaCommand {
}
}
validateBackingTableExists();
TableSynonym table;
if (old != null) {
......@@ -88,15 +97,8 @@ public class CreateSynonym extends SchemaCommand {
db.addSchemaObject(session, table);
}
return 0;
}
private void validateBackingTableExists() {
// This call throws an exception if the table does not exist.
if (data.synonymForSchema.findTableOrView(session, data.synonymFor) == null) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1,
data.synonymForSchema.getName() + "." + data.synonymFor);
}
return 0;
}
public void setComment(String comment) {
......
/*
* 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.command.ddl;
import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface;
import org.h2.constraint.ConstraintReferential;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.Table;
import org.h2.table.TableView;
/**
* This class represents the statement
* DROP SYNONYM
*/
public class DropSynonym extends SchemaCommand {
private String synonymName;
private boolean ifExists;
public DropSynonym(Session session, Schema schema) {
super(session, schema);
}
public void setSynonymName(String name) {
this.synonymName = name;
}
@Override
public int update() {
session.commit(true);
Table synonym = getSchema().findTableOrView(session, synonymName);
if (synonym == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, synonymName);
}
} else {
if (!Table.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;
}
public void setIfExists(boolean ifExists) {
this.ifExists = ifExists;
}
@Override
public int getType() {
return CommandInterface.DROP_SYNONYM;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论