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

Incorporate "easy to fix" review comments

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