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

more fixes

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