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