Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
0004123: Excluded columns that are part of an index the index remains…
… in table object (#95)
  • Loading branch information
woehrl01 authored and erilong committed Oct 28, 2019
1 parent 5abdf4a commit b39330a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions symmetric-db/src/main/java/org/jumpmind/db/model/Table.java
Expand Up @@ -30,6 +30,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
Expand Down Expand Up @@ -1245,6 +1246,25 @@ public Table copyAndFilterColumns(String[] orderedColumnNames, String[] pkColumn
Table table = copy();
table.orderColumns(orderedColumnNames);

Set<String> columnNameSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
columnNameSet.addAll(Arrays.asList(orderedColumnNames));

List<IIndex> indices = new ArrayList<IIndex>();
for(IIndex index : table.getIndices()){
boolean keepIndex = true;
for(IndexColumn columnInIndex : index.getColumns()){
if(columnInIndex == null || !columnNameSet.contains(columnInIndex.getName())){
keepIndex = false;
break;
}
}
if(keepIndex){
indices.add(index);
}
}
table.removeAllIndices();
table.addIndices(indices);

if (setPrimaryKeys && columns != null) {
for (Column column : table.columns) {
if (column != null) {
Expand Down

0 comments on commit b39330a

Please sign in to comment.