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

Incorporate "easy to fix" review comments

上级 c7be5be2
......@@ -82,6 +82,7 @@ public class CreateSynonym extends SchemaCommand {
table = (TableSynonym) old;
data.schema = table.getSchema();
table.updateData(data);
table.setComment(comment);
table.setModified();
} else {
data.id = getObjectId();
......
package org.h2.engine;
/**
* Created by jiriki on 24.04.16.
*/
public class FunctionSynonym {
}
......@@ -236,12 +236,12 @@ public class Schema extends DbObjectBase {
*/
public void add(SchemaObject obj) {
if (SysProperties.CHECK && obj.getSchema() != this) {
throw DbException.throwInternalError("wrong schema");
DbException.throwInternalError("wrong schema");
}
String name = obj.getName();
Map<String, SchemaObject> map = getMap(obj.getType());
if (SysProperties.CHECK && map.get(name) != null) {
throw DbException.throwInternalError("object already exists: " + name);
DbException.throwInternalError("object already exists: " + name);
}
map.put(name, obj);
freeUniqueName(name);
......@@ -258,10 +258,10 @@ public class Schema extends DbObjectBase {
Map<String, SchemaObject> map = getMap(type);
if (SysProperties.CHECK) {
if (!map.containsKey(obj.getName())) {
throw DbException.throwInternalError("not found: " + obj.getName());
DbException.throwInternalError("not found: " + obj.getName());
}
if (obj.getName().equals(newName) || map.containsKey(newName)) {
throw DbException.throwInternalError("object already exists: " + newName);
DbException.throwInternalError("object already exists: " + newName);
}
}
obj.checkRename();
......
......@@ -12,7 +12,7 @@ import java.util.ArrayList;
import java.util.HashSet;
/**
* Sysonym for an existing table or view. All DML requests are forwarded to the backing table. Adding indices
* Synonym for an existing table or view. All DML requests are forwarded to the backing table. Adding indices
* to a synonym or altering the table is not supported.
*/
public class TableSynonym extends Table {
......@@ -182,12 +182,7 @@ public class TableSynonym extends Table {
}
public boolean isInvalid() {
try {
getSynonymFor();
return false;
} catch (DbException e) {
return true;
}
return data.synonymForSchema.findTableOrView(data.session, data.synonymFor) != null;
}
}
......@@ -72,6 +72,7 @@ import org.h2.test.db.TestShow;
import org.h2.test.db.TestSpaceReuse;
import org.h2.test.db.TestSpatial;
import org.h2.test.db.TestSpeed;
import org.h2.test.db.TestSynonymForTable;
import org.h2.test.db.TestTableEngines;
import org.h2.test.db.TestTempTables;
import org.h2.test.db.TestTransaction;
......@@ -761,6 +762,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestViewAlterTable());
addTest(new TestViewDropView());
addTest(new TestReplace());
addTest(new TestSynonymForTable());
// jaqu
addTest(new AliasMapTest());
......
......@@ -91,7 +91,7 @@ public class TestSynonymForTable extends TestBase {
assertEquals("INVALID", synonyms.getString("STATUS"));
conn.close();
// Reopending should work with invalid synonym
// Reopening should work with invalid synonym
Connection conn2 = getConnection("synonym");
assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
conn2.close();
......@@ -110,7 +110,7 @@ public class TestSynonymForTable extends TestBase {
// Dropping with "if exists" should succeed even if the synonym does not exist anymore.
stat.execute("DROP SYNONYM IF EXISTS testsynonym");
// Without "if exists" the command should fail.
// Without "if exists" the command should fail if the synonym does not exist.
assertThrows(JdbcSQLException.class, stat).execute("DROP SYNONYM testsynonym");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论