Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/engine/net/sf/jailer/datamodel/DataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -304,6 +306,18 @@ public Collection<Table> getTables() {
return tables.values();
}

/**
* When starting UI we need to pick a table to get selected at first, in a stable way.
* Alphabetically first table sounds good and deterministic.
*/
public Optional<Table> firstTable() {
if (MapUtils.isEmpty(tables)) {
return Optional.empty();
}

return tables.keySet().stream().sorted().findFirst().map(tables::get);
}

/**
* Reads in <code>table.csv</code> and <code>association.csv</code>
* and builds the relational data model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public boolean equals(Object obj) {
public ExtractionModel(DataModel dataModel, ExecutionContext executionContext) {
this.dataModel = dataModel;
this.version = null;
subject = dataModel.getTables().iterator().hasNext()? dataModel.getTables().iterator().next() : null;
Copy link
Author

@valters valters Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashMap.values().iterator() happens to select some entry that happens to have first hash value: I think it's not great that on startup the focus table is essentially randomly selected.

subject = dataModel.firstTable().orElse(null);
condition = "";
dataModel.setRestrictionModel(new RestrictionModel(dataModel, executionContext));
dataModel.deriveFilters();
Expand Down