Skip to content

Commit

Permalink
Merge branch '3.9' of https://github.com/JumpMind/symmetric-ds.git in…
Browse files Browse the repository at this point in the history
…to 3.9
  • Loading branch information
chenson42 committed Aug 24, 2018
2 parents 6fc60f2 + c42f0e0 commit 3a8082d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Expand Up @@ -39,6 +39,7 @@
import bsh.Interpreter;
import bsh.ParseException;
import bsh.TargetError;
import bsh.Variable;

public class BshDatabaseWriterFilter extends DynamicDatabaseWriterFilter {

Expand Down Expand Up @@ -153,6 +154,8 @@ protected Interpreter getInterpreter(Context context) {

protected void bind(Interpreter interpreter, DataContext context, Table table, CsvData data, Exception error)
throws EvalError {

resetInterpreter(interpreter);

interpreter.set(LOG, log);
interpreter.set(ENGINE, this.engine);
Expand Down Expand Up @@ -188,6 +191,12 @@ protected void bind(Interpreter interpreter, DataContext context, Table table, C

}

protected void resetInterpreter(Interpreter interpreter) throws EvalError {
for (Variable variable : interpreter.getNameSpace().getDeclaredVariables()) {
interpreter.unset(variable.getName());
}
}

protected void processError(LoadFilter currentFilter, Table table, Throwable ex) {
if (ex instanceof TargetError) {
ex = ((TargetError) ex).getTarget();
Expand Down
18 changes: 17 additions & 1 deletion symmetric-db/src/main/java/org/jumpmind/db/model/Table.java
Expand Up @@ -22,12 +22,14 @@
import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
Expand Down Expand Up @@ -1231,7 +1233,7 @@ public Table copyAndFilterColumns(String[] orderedColumnNames, String[] pkColumn
boolean setPrimaryKeys) {
Table table = copy();
table.orderColumns(orderedColumnNames);

if (setPrimaryKeys && columns != null) {
for (Column column : table.columns) {
if (column != null) {
Expand All @@ -1250,6 +1252,20 @@ public Table copyAndFilterColumns(String[] orderedColumnNames, String[] pkColumn
}
}
}

if (table.getForeignKeys() != null && table.getForeignKeys().length > 0) {
List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
Set<String> columnsSet = new HashSet<String>(Arrays.asList(orderedColumnNames));
for (ForeignKey fk : table.getForeignKeys()) {
for (Reference ref : fk.getReferences()) {
if (ref != null && ref.getLocalColumn() != null && columnsSet.contains(ref.getLocalColumnName())) {
foreignKeys.add(fk);
}
}
}
table.removeAllForeignKeys();
table.addForeignKeys(foreignKeys);
}
}

return table;
Expand Down

0 comments on commit 3a8082d

Please sign in to comment.