提交 dac00f9d authored 作者: Noel Grandin's avatar Noel Grandin

more fixes

上级 4ca9b99b
......@@ -8,7 +8,6 @@ package org.h2.command.ddl;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;
import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface;
import org.h2.command.Parser;
......@@ -275,11 +274,9 @@ public class AlterTableAlterColumn extends SchemaCommand {
throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, e, getSQL(), e.getMessage());
}
String tableName = table.getName();
CopyOnWriteArrayList<TableView> dependentViews = table.getDependentViews();
if (dependentViews != null) {
for (TableView view : dependentViews) {
table.removeDependentView(view);
}
ArrayList<TableView> dependentViews = new ArrayList<>(table.getDependentViews());
for (TableView view : dependentViews) {
table.removeDependentView(view);
}
execute("DROP TABLE " + table.getSQL() + " IGNORE", true);
db.renameSchemaObject(session, newTable, tableName);
......@@ -306,11 +303,9 @@ public class AlterTableAlterColumn extends SchemaCommand {
db.renameSchemaObject(session, so, name);
}
}
if (dependentViews != null) {
for (TableView view : dependentViews) {
String sql = view.getCreateSQL(true, true);
execute(sql, true);
}
for (TableView view : dependentViews) {
String sql = view.getCreateSQL(true, true);
execute(sql, true);
}
}
......
......@@ -11,7 +11,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
import org.h2.api.ErrorCode;
import org.h2.command.Prepared;
import org.h2.constraint.Constraint;
......@@ -82,7 +81,7 @@ public abstract class Table extends SchemaObjectBase {
/**
* views that depend on this table
*/
private final AtomicReference<CopyOnWriteArrayList<TableView>> dependentViews = new AtomicReference<>();
private final CopyOnWriteArrayList<TableView> dependentViews = new CopyOnWriteArrayList<>();
private ArrayList<TableSynonym> synonyms;
private boolean checkForeignKeyConstraints = true;
private boolean onCommitDrop, onCommitTruncate;
......@@ -403,9 +402,7 @@ public abstract class Table extends SchemaObjectBase {
if (sequences != null) {
children.addAll(sequences);
}
if (dependentViews.get() != null) {
children.addAll(dependentViews.get());
}
children.addAll(dependentViews);
if (synonyms != null) {
children.addAll(synonyms);
}
......@@ -525,14 +522,14 @@ public abstract class Table extends SchemaObjectBase {
}
public CopyOnWriteArrayList<TableView> getDependentViews() {
return dependentViews.get();
return dependentViews;
}
@Override
public void removeChildrenAndResources(Session session) {
while (dependentViews.get() != null && dependentViews.get().size() > 0) {
TableView view = dependentViews.get().get(0);
dependentViews.get().remove(0);
while (dependentViews.size() > 0) {
TableView view = dependentViews.get(0);
dependentViews.remove(0);
database.removeSchemaObject(session, view);
}
while (synonyms != null && synonyms.size() > 0) {
......@@ -820,12 +817,6 @@ public abstract class Table extends SchemaObjectBase {
}
}
private static <T> void remove(AtomicReference<CopyOnWriteArrayList<T>> list, T obj) {
if (list.get() != null) {
list.get().remove(obj);
}
}
/**
* Remove the given index from the list.
*
......@@ -849,7 +840,7 @@ public abstract class Table extends SchemaObjectBase {
* @param view the view to remove
*/
public void removeDependentView(TableView view) {
remove(dependentViews, view);
dependentViews.remove(view);
}
/**
......@@ -894,7 +885,7 @@ public abstract class Table extends SchemaObjectBase {
* @param view the view to add
*/
public void addDependentView(TableView view) {
add(dependentViews, view);
dependentViews.add(view);
}
/**
......@@ -948,14 +939,6 @@ public abstract class Table extends SchemaObjectBase {
return list;
}
private static <T> void add(AtomicReference<CopyOnWriteArrayList<T>> list, T obj) {
if (list.get() == null) {
list.compareAndSet(null, new CopyOnWriteArrayList<T>());
}
// self constraints are two entries in the list
list.get().add(obj);
}
/**
* Fire the triggers for this table.
*
......
......@@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import org.h2.api.ErrorCode;
import org.h2.command.Prepared;
import org.h2.command.dml.Query;
......@@ -136,14 +135,12 @@ public class TableView extends Table {
return e;
}
}
CopyOnWriteArrayList<TableView> dependentViews = getDependentViews();
ArrayList<TableView> dependentViews = new ArrayList<>(getDependentViews());
initColumnsAndTables(session, false);
if (dependentViews != null) {
for (TableView v : dependentViews) {
DbException e = v.recompile(session, force, false);
if (e != null && !force) {
return e;
}
for (TableView v : dependentViews) {
DbException e = v.recompile(session, force, false);
if (e != null && !force) {
return e;
}
}
if (clearIndexCache) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论