提交 401e069b authored 作者: Noel Grandin's avatar Noel Grandin

more dependent views field and method naming more obvious

上级 c2b4d9db
...@@ -275,10 +275,10 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -275,10 +275,10 @@ public class AlterTableAlterColumn extends SchemaCommand {
throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, e, getSQL(), e.getMessage()); throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, e, getSQL(), e.getMessage());
} }
String tableName = table.getName(); String tableName = table.getName();
CopyOnWriteArrayList<TableView> views = table.getViews(); CopyOnWriteArrayList<TableView> dependentViews = table.getDependentViews();
if (views != null) { if (dependentViews != null) {
for (TableView view : views) { for (TableView view : dependentViews) {
table.removeView(view); table.removeDependentView(view);
} }
} }
execute("DROP TABLE " + table.getSQL() + " IGNORE", true); execute("DROP TABLE " + table.getSQL() + " IGNORE", true);
...@@ -306,8 +306,8 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -306,8 +306,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
db.renameSchemaObject(session, so, name); db.renameSchemaObject(session, so, name);
} }
} }
if (views != null) { if (dependentViews != null) {
for (TableView view : views) { for (TableView view : dependentViews) {
String sql = view.getCreateSQL(true, true); String sql = view.getCreateSQL(true, true);
execute(sql, true); execute(sql, true);
} }
......
...@@ -73,10 +73,10 @@ public class DropTable extends SchemaCommand { ...@@ -73,10 +73,10 @@ public class DropTable extends SchemaCommand {
throw DbException.get(ErrorCode.CANNOT_DROP_TABLE_1, tableName); throw DbException.get(ErrorCode.CANNOT_DROP_TABLE_1, tableName);
} }
if (dropAction == ConstraintReferential.RESTRICT) { if (dropAction == ConstraintReferential.RESTRICT) {
CopyOnWriteArrayList<TableView> views = table.getViews(); CopyOnWriteArrayList<TableView> dependentViews = table.getDependentViews();
if (views != null && views.size() > 0) { if (dependentViews != null && dependentViews.size() > 0) {
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
for (TableView v : views) { for (TableView v : dependentViews) {
buff.appendExceptFirst(", "); buff.appendExceptFirst(", ");
buff.append(v.getName()); buff.append(v.getName());
} }
......
...@@ -79,7 +79,10 @@ public abstract class Table extends SchemaObjectBase { ...@@ -79,7 +79,10 @@ public abstract class Table extends SchemaObjectBase {
private ArrayList<TriggerObject> triggers; private ArrayList<TriggerObject> triggers;
private ArrayList<Constraint> constraints; private ArrayList<Constraint> constraints;
private ArrayList<Sequence> sequences; private ArrayList<Sequence> sequences;
private AtomicReference<CopyOnWriteArrayList<TableView>> views; /**
* views that depend on this table
*/
private AtomicReference<CopyOnWriteArrayList<TableView>> dependentViews;
private ArrayList<TableSynonym> synonyms; private ArrayList<TableSynonym> synonyms;
private boolean checkForeignKeyConstraints = true; private boolean checkForeignKeyConstraints = true;
private boolean onCommitDrop, onCommitTruncate; private boolean onCommitDrop, onCommitTruncate;
...@@ -400,8 +403,8 @@ public abstract class Table extends SchemaObjectBase { ...@@ -400,8 +403,8 @@ public abstract class Table extends SchemaObjectBase {
if (sequences != null) { if (sequences != null) {
children.addAll(sequences); children.addAll(sequences);
} }
if (views.get() != null) { if (dependentViews.get() != null) {
children.addAll(views.get()); children.addAll(dependentViews.get());
} }
if (synonyms != null) { if (synonyms != null) {
children.addAll(synonyms); children.addAll(synonyms);
...@@ -521,15 +524,15 @@ public abstract class Table extends SchemaObjectBase { ...@@ -521,15 +524,15 @@ public abstract class Table extends SchemaObjectBase {
} }
} }
public CopyOnWriteArrayList<TableView> getViews() { public CopyOnWriteArrayList<TableView> getDependentViews() {
return views.get(); return dependentViews.get();
} }
@Override @Override
public void removeChildrenAndResources(Session session) { public void removeChildrenAndResources(Session session) {
while (views.get() != null && views.get().size() > 0) { while (dependentViews.get() != null && dependentViews.get().size() > 0) {
TableView view = views.get().get(0); TableView view = dependentViews.get().get(0);
views.get().remove(0); dependentViews.get().remove(0);
database.removeSchemaObject(session, view); database.removeSchemaObject(session, view);
} }
while (synonyms != null && synonyms.size() > 0) { while (synonyms != null && synonyms.size() > 0) {
...@@ -845,8 +848,8 @@ public abstract class Table extends SchemaObjectBase { ...@@ -845,8 +848,8 @@ public abstract class Table extends SchemaObjectBase {
* *
* @param view the view to remove * @param view the view to remove
*/ */
public void removeView(TableView view) { public void removeDependentView(TableView view) {
remove(views, view); remove(dependentViews, view);
} }
/** /**
...@@ -890,8 +893,8 @@ public abstract class Table extends SchemaObjectBase { ...@@ -890,8 +893,8 @@ public abstract class Table extends SchemaObjectBase {
* *
* @param view the view to add * @param view the view to add
*/ */
public void addView(TableView view) { public void addDependentView(TableView view) {
add(views, view); add(dependentViews, view);
} }
/** /**
......
...@@ -136,10 +136,10 @@ public class TableView extends Table { ...@@ -136,10 +136,10 @@ public class TableView extends Table {
return e; return e;
} }
} }
CopyOnWriteArrayList<TableView> views = getViews(); CopyOnWriteArrayList<TableView> dependentViews = getDependentViews();
initColumnsAndTables(session, false); initColumnsAndTables(session, false);
if (views != null) { if (dependentViews != null) {
for (TableView v : views) { for (TableView v : dependentViews) {
DbException e = v.recompile(session, force, false); DbException e = v.recompile(session, force, false);
if (e != null && !force) { if (e != null && !force) {
return e; return e;
...@@ -154,7 +154,7 @@ public class TableView extends Table { ...@@ -154,7 +154,7 @@ public class TableView extends Table {
private void initColumnsAndTables(Session session, boolean literalsChecked) { private void initColumnsAndTables(Session session, boolean literalsChecked) {
Column[] cols; Column[] cols;
removeViewFromTables(); removeDependentViewFromTables();
try { try {
Query query = compileViewQuery(session, querySQL, literalsChecked); Query query = compileViewQuery(session, querySQL, literalsChecked);
this.querySQL = query.getPlanSQL(); this.querySQL = query.getPlanSQL();
...@@ -229,7 +229,7 @@ public class TableView extends Table { ...@@ -229,7 +229,7 @@ public class TableView extends Table {
} }
setColumns(cols); setColumns(cols);
if (getId() != 0) { if (getId() != 0) {
addViewToTables(); addDependentViewToTables();
} }
} }
...@@ -420,7 +420,7 @@ public class TableView extends Table { ...@@ -420,7 +420,7 @@ public class TableView extends Table {
@Override @Override
public void removeChildrenAndResources(Session session) { public void removeChildrenAndResources(Session session) {
removeViewFromTables(); removeDependentViewFromTables();
super.removeChildrenAndResources(session); super.removeChildrenAndResources(session);
database.removeMeta(session, getId()); database.removeMeta(session, getId());
querySQL = null; querySQL = null;
...@@ -504,18 +504,18 @@ public class TableView extends Table { ...@@ -504,18 +504,18 @@ public class TableView extends Table {
return null; return null;
} }
private void removeViewFromTables() { private void removeDependentViewFromTables() {
if (tables != null) { if (tables != null) {
for (Table t : tables) { for (Table t : tables) {
t.removeView(this); t.removeDependentView(this);
} }
tables.clear(); tables.clear();
} }
} }
private void addViewToTables() { private void addDependentViewToTables() {
for (Table t : tables) { for (Table t : tables) {
t.addView(this); t.addDependentView(this);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论