}
@Override
- public void finished(AsyncReadGraph graph) {
- user.finished(graph);
+ public void finished(AsyncReadGraph graph, C context) {
+ user.finished(graph, context);
}
@Override
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(AsyncReadGraph graph, Resource parent) {
}
@Override
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.simantics.db.procedure.Procedure;
import org.simantics.db.service.DirectQuerySupport;
import org.simantics.layer0.Layer0;
+import org.simantics.utils.datastructures.Pair;
class ConsistsOfProcess {
final List<InternalEntry> result;
+ final Set<Resource> childrenWithNoName;
final AsyncContextMultiProcedure<InternalEntry, Resource> structure;
final AsyncContextMultiProcedure<InternalEntry, Resource> names;
- public static List<InternalEntry> walk(ReadGraph graph, ResourceMap<ExtentStatus> status, Collection<Resource> resources, Set<Resource> exclusions, boolean ignoreVirtual) throws DatabaseException {
+ public static Pair<List<InternalEntry>,Set<Resource>> walk(ReadGraph graph, ResourceMap<ExtentStatus> status, Collection<Resource> resources, Set<Resource> exclusions, boolean ignoreVirtual) throws DatabaseException {
ConsistsOfProcess process = new ConsistsOfProcess(graph, status, resources, exclusions, ignoreVirtual);
- return process.result;
+ return Pair.make(process.result, process.childrenWithNoName);
}
static class InternalEntry {
public InternalEntry parent;
public Resource resource;
public String name;
+ public boolean valid = true;
InternalEntry(InternalEntry parent, Resource resource, String name) {
this.parent = parent;
this.resource = resource;
final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
result = new ArrayList<InternalEntry>();
-
+ childrenWithNoName = new HashSet<>();
names = dqs.compileForEachObject(graph, L0.HasName, new AsyncContextMultiProcedure<InternalEntry, Resource>() {
@Override
graph.forPossibleValue(nameResource, new Procedure<String>() {
@Override
- public void execute(String result) {
- entry.name = result;
+ public void execute(String name) {
+ if(!entry.valid) return;
+
+ if(name == null) {
+ entry.valid = false;
+ } else if (entry.name != null) {
+ entry.valid = false;
+ } else {
+ entry.name = name;
+ }
}
@Override
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(AsyncReadGraph graph, InternalEntry entry) {
+ if(entry.valid) {
+ if(entry.name != null) {
+ result.add(entry);
+ } else {
+ // This one did not have a name - not a valid internal
+ childrenWithNoName.add(entry.resource);
+ }
+ } else {
+ // Something wrong has happened. Do not treat as valid internal
+ childrenWithNoName.add(entry.resource);
+ }
}
-
});
structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure<InternalEntry, Resource>() {
if(!ignoreVirtual || child.isPersistent()) {
InternalEntry entry = new InternalEntry(parent, child, null);
- if(result.add(entry)) {
- dqs.forEachObjectCompiled(graph, child, entry, structure);
- dqs.forEachObjectCompiled(graph, child, entry, names);
- }
+ dqs.forEachObjectCompiled(graph, child, entry, structure);
+ dqs.forEachObjectCompiled(graph, child, entry, names);
}
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(AsyncReadGraph graph, InternalEntry parent) {
}
@Override
import org.simantics.graph.db.TransferableGraphSource;
import org.simantics.layer0.Layer0;
import org.simantics.scl.runtime.function.Function1;
+import org.simantics.utils.datastructures.Pair;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.TIntIntHashMap;
this.datatypeBinding = Bindings.getBindingUnchecked(Datatype.class);
this.datatypeSerializer = graph.getService(Databoard.class).getSerializerUnchecked(this.datatypeBinding);
- state.internalEntries = ConsistsOfProcess.walk(graph, status, fringe, exclusions, ignoreVirtual);
+ Pair<List<InternalEntry>,Set<Resource>> pair = ConsistsOfProcess.walk(graph, status, fringe, exclusions, ignoreVirtual);
+ state.internalEntries = pair.first;
for(InternalEntry entry : state.internalEntries) {
Resource r = entry.resource;
}
}
+ for(Resource unnamedChild : pair.second) {
+ if (status.put(unnamedChild, ExtentStatus.INTERNAL) == null) {
+ fringe.add(unnamedChild);
+ }
+ }
+
if (state.monitor.isCanceled())
throw new CancelTransactionException();
if(state.internalEntries != null) {
for(InternalEntry ie : state.internalEntries) {
- if(ie.parent != null && ie.name != null) {
- procedure.execute(resolveInternal(graph, support, ie, internalMap));
+ if(ie.parent != null) {
+ if(ie.name != null) {
+ procedure.execute(resolveInternal(graph, support, ie, internalMap));
+ } else {
+ // In this case there is a child that has no HasName => this should be treated as a blank
+ }
} else {
throw new DatabaseException("Invalid internal entry " + ie);
}
* � All o are internal
* � All stm are included
*/
- List<InternalEntry> entries = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true);
+ Pair<List<InternalEntry>,Set<Resource>> pair = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true);
+ List<InternalEntry> entries = pair.first;
for(InternalEntry entry : entries) {
Resource r = entry.resource;
if (status.put(r, ExtentStatus.INTERNAL) == null) {
}
}
+ for(Resource unnamedChild : pair.second) {
+ if (status.put(unnamedChild, ExtentStatus.INTERNAL) == null) {
+ fringe.add(unnamedChild);
+ }
+ }
+
/*
* This loop resolves the transitive closure of all p < IsRelatedTo such that p does not contain the SharedRange tag.
* Such resources are guaranteed to be internal.
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.simantics.datatypes.literal.GUID;
import org.simantics.db.ReadGraph;
import org.simantics.db.layer0.util.DomainProcessor3.ExclusionDecision;
import org.simantics.layer0.Layer0;
import org.simantics.scl.runtime.function.Function1;
+import org.simantics.utils.datastructures.Pair;
/**
* @author Antti Villberg
return new GUIDExclusionFunction(graph);
// The root is OK - check everything beneath
- List<InternalEntry> entries = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true);
+ Pair<List<InternalEntry>,Set<Resource>> pair = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true);
+ List<InternalEntry> entries = pair.first;
for(InternalEntry entry : entries) {
if(findByIdentifier(graph, targetRoot, entry.resource))
return new GUIDExclusionFunction(graph);
}
}
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.dec();
return;
}
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.dec();
assert(size == count);
if (ClusterTraits.statementIndexIsDirect(objectIndex)) {
int key = modifier.execute(objectIndex);
procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), key));
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.dec();
return;
}
if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
int completeRef = getCompleteObjectRef(table, index);
if (0 == completeRef) {
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // no objects for given complete type
}
} else { // One complete type element. CompleteRef is resource reference.
ClusterI.CompleteTypeEnum rCompleteType = ResourceElementSmall.getCompleteType(table, index);
if (pCompleteType != rCompleteType) {
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // Complete predicate does not match.
}
procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(completeRef)));
}
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // loop finished
}
short p1 = getStm1Predicate(table, index);
if (0 == p1) {
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // loop finished, no statements
}
}
short p2 = getStm2Predicate(table, index);
if (0 == p2 || pRef != p2) {
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // loop finished, one statements
}
// return true; // loop broken by procedure
// return false; // loop finished
procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(o2)));
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
}
if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) {
int completeRef = getCompleteObjectRef(table, index);
if (0 == completeRef) {
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // no objects for given complete type
}
ForeachObject t = new ForeachObject();
// CompleteRef is complete object set index.
ct.foreachComplete(completeRef, t, null, support, modifier);
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // loop finished
}
// one complete type element
ClusterI.CompleteTypeEnum completeType = ClusterTraits.completeReferenceGetType(completeRef);
if (pCompleteType != completeType) {
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return;
}
int externalRef = ClusterTraits.createForeignReference(clusterIndex, resourceIndex);
procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(externalRef)));
}
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // loop finished
}
long l = table[i];
int p1 = (int) (l >>> 32);
if (0 == p1) {
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // loop finished, no statements
}
long l2 = table[++i];
int p2 = (int) (l2 >>> 32);
if (pRef != p2) {
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
return; // loop finished, one statements
}
int o2 = (int)l2;
procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(o2)));
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
}
}
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
}
*
* @param graph asynchronous graph access
*/
- void finished(AsyncReadGraph graph);
+ void finished(AsyncReadGraph graph, Context context);
/**
* If an error occurs in the processing of the database request that