Validation fixes

This commit is contained in:
crschnick 2024-09-22 14:30:01 +00:00
parent 39f32af927
commit acb2583100
4 changed files with 12 additions and 10 deletions

View file

@ -15,7 +15,7 @@ public class ConnectionRefreshExchangeImpl extends ConnectionRefreshExchange {
.getStoreEntryIfPresent(msg.getConnection()) .getStoreEntryIfPresent(msg.getConnection())
.orElseThrow(() -> new BeaconClientException("Unknown connection: " + msg.getConnection())); .orElseThrow(() -> new BeaconClientException("Unknown connection: " + msg.getConnection()));
if (e.getStore() instanceof FixedHierarchyStore) { if (e.getStore() instanceof FixedHierarchyStore) {
DataStorage.get().refreshChildren(e, true); DataStorage.get().refreshChildren(e, null, true);
} else { } else {
e.validateOrThrowAndClose(null); e.validateOrThrowAndClose(null);
} }

View file

@ -216,7 +216,7 @@ public class StoreEntryWrapper {
} }
public void refreshChildren() { public void refreshChildren() {
var hasChildren = DataStorage.get().refreshChildren(entry); var hasChildren = DataStorage.get().refreshChildren(entry, null);
PlatformThread.runLaterIfNeeded(() -> { PlatformThread.runLaterIfNeeded(() -> {
expanded.set(hasChildren); expanded.set(hasChildren);
}); });

View file

@ -353,24 +353,26 @@ public abstract class DataStorage {
} }
@SneakyThrows @SneakyThrows
public boolean refreshChildren(DataStoreEntry e) { public boolean refreshChildren(DataStoreEntry e, ValidationContext<?> context) {
return refreshChildren(e, false); return refreshChildren(e, context, false);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends ValidationContext<?>> boolean refreshChildren(DataStoreEntry e, boolean throwOnFail) throws Exception { public <T extends ValidationContext<?>> boolean refreshChildren(DataStoreEntry e, T context, boolean throwOnFail) throws Exception {
if (!(e.getStore() instanceof FixedHierarchyStore<?> h)) { if (!(e.getStore() instanceof FixedHierarchyStore<?> h)) {
return false; return false;
} }
e.incrementBusyCounter(); e.incrementBusyCounter();
List<? extends DataStoreEntryRef<? extends FixedChildStore>> newChildren; List<? extends DataStoreEntryRef<? extends FixedChildStore>> newChildren;
T context = null; var hadContext = context != null;
try { try {
if (context == null) {
context = (T) h.createContext(); context = (T) h.createContext();
if (context == null) { if (context == null) {
return false; return false;
} }
}
newChildren = ((FixedHierarchyStore<T>)h).listChildren(context).stream() newChildren = ((FixedHierarchyStore<T>)h).listChildren(context).stream()
.filter(dataStoreEntryRef -> dataStoreEntryRef != null && dataStoreEntryRef.get() != null) .filter(dataStoreEntryRef -> dataStoreEntryRef != null && dataStoreEntryRef.get() != null)
@ -383,7 +385,7 @@ public abstract class DataStorage {
return false; return false;
} }
} finally { } finally {
if (context != null) { if (context != null && !hadContext) {
context.close(); context.close();
} }
e.decrementBusyCounter(); e.decrementBusyCounter();

View file

@ -72,7 +72,7 @@ public class RefreshChildrenStoreAction implements ActionProvider {
@Override @Override
public void execute() { public void execute() {
DataStorage.get().refreshChildren(store); DataStorage.get().refreshChildren(store, null);
} }
} }
} }