import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
import org.simantics.db.layer0.util.DomainProcessor3.ExclusionDecision;
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec.SeedSpecType;
import org.simantics.scl.runtime.function.Function1;
public class TransferableGraphConfiguration2 {
-
- public static class RootSpec {
+
+ public static class SeedSpec {
+
+ public static enum SeedSpecType {
+ INTERNAL, ROOT, SPECIAL_ROOT
+ }
+
public final Resource resource;
public final String name;
- public final boolean internal;
+ // Special roots are not normal seeds - e.g. %model
+ public final SeedSpecType specType;
+ /**
+ * Optional, may be null.
+ */
+ public final String type;
+
+ public SeedSpec(Resource resource, String name, SeedSpecType specType) {
+ this(resource, name, specType, null);
+ }
- public RootSpec(Resource resource, String name, boolean internal) {
+ public SeedSpec(Resource resource, String name, SeedSpecType specType, String type) {
if (resource == null)
throw new NullPointerException("null resource");
if (name == null)
throw new NullPointerException("null name");
this.resource = resource;
this.name = name;
- this.internal = internal;
+ this.specType = specType;
+ this.type = type;
+ }
+
+ public static SeedSpec internal(Resource resource) {
+ return new SeedSpec(resource, "", SeedSpecType.ROOT);
}
@Override
public String toString() {
- return "RootSpec[" + name + ", " + resource + ", " + internal + "]";
+ return "SeedSpec[" + name + ", " + resource + ", " + specType + ", " + type + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + (internal ? 1231 : 1237);
+ result = prime * result + specType.hashCode();
result = prime * result + resource.hashCode();
result = prime * result + name.hashCode();
+ result = prime * result + (type != null ? type.hashCode() : 0);
return result;
}
return false;
if (getClass() != obj.getClass())
return false;
- RootSpec other = (RootSpec) obj;
- return internal == other.internal && resource.equals(other.resource) && name.equals(other.name);
+ SeedSpec other = (SeedSpec) obj;
+ return specType.equals(other.specType) && resource.equals(other.resource) && name.equals(other.name)
+ && objectEquals(type, other.type);
+ }
+
+ private boolean objectEquals(Object o1, Object o2) {
+ if (o1 == o2) return true;
+ if (o1 == null && o2 == null) return true;
+ if (o1 == null || o2 == null) return false;
+ return o1.equals(o2);
}
}
-
- final public TreeMap<String, Variant> baseExtensions = new TreeMap<String,Variant>();
+
+ final public TreeMap<String, Variant> baseExtensions = new TreeMap<>();
final public Resource indexRoot;
- final public Collection<RootSpec> roots;
+ final public Collection<SeedSpec> seeds;
final public Map<Resource, ExtentStatus> preStatus;
final public boolean ignoreVirtualResources;
final public boolean validate;
-
+
/**
* <code>true</code> to export values, <code>false</code> to skip the actual
* values and only write the resource id.
public Collection<TGValueModifier> valueModifiers;
public Function1<Statement,ExclusionDecision> exclusionFunction;
- public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources, boolean validate) {
+ public TransferableGraphConfiguration2(Resource indexRoot, Collection<SeedSpec> seeds, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources, boolean validate) {
this.indexRoot = indexRoot;
- this.roots = roots;
+ this.seeds = seeds;
this.preStatus = preStatus;
this.ignoreVirtualResources = ignoreVirtualResources;
this.validate = validate;
this.valueModifiers = null;
}
- public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources) {
+ public TransferableGraphConfiguration2(Resource indexRoot, Collection<SeedSpec> roots, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources) {
this(indexRoot, roots, preStatus, ignoreVirtualResources, true);
}
- public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus) {
+ public TransferableGraphConfiguration2(Resource indexRoot, Collection<SeedSpec> roots, Map<Resource, ExtentStatus> preStatus) {
this(indexRoot, roots, preStatus, true);
}
public TransferableGraphConfiguration2(TransferableGraphConfiguration2 conf) throws DatabaseException {
- this(conf.indexRoot, conf.roots, conf.preStatus, conf.ignoreVirtualResources, conf.validate);
+ this(conf.indexRoot, conf.seeds, conf.preStatus, conf.ignoreVirtualResources, conf.validate);
}
public TransferableGraphConfiguration2(ReadGraph graph, Resource model, boolean ignoreVirtualResources, boolean validate) throws DatabaseException {
public TransferableGraphConfiguration2(ReadGraph graph, Resource model) throws DatabaseException {
this(graph, model, true);
}
-
- public TransferableGraphConfiguration2(ReadGraph graph, Collection<RootSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions) throws DatabaseException {
+
+ public TransferableGraphConfiguration2(ReadGraph graph, Collection<SeedSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions) throws DatabaseException {
this(new TGConfigurer(graph, true).roots(roots).roots2(resourceRoots).exclusions(exclusions).create());
}
- public TransferableGraphConfiguration2(ReadGraph graph, Collection<RootSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions, boolean ignoreVirtualResource, boolean validate) throws DatabaseException {
+ public TransferableGraphConfiguration2(ReadGraph graph, Collection<SeedSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions, boolean ignoreVirtualResource, boolean validate) throws DatabaseException {
this(new TGConfigurer(graph, ignoreVirtualResource, validate).roots(roots).roots2(resourceRoots).exclusions(exclusions).create());
}
public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
return new TransferableGraphConfiguration2(graph, translate(roots), Collections.<Resource>emptyList(), exclusions, ignoreVirtualResource, validate);
}
-
+
});
}
- public static TransferableGraphConfiguration2 createWithNames2(RequestProcessor processor, final Collection<RootSpec> roots, final Collection<Resource> exclusions, final boolean ignoreVirtualResource, final boolean validate) throws DatabaseException {
+ public static TransferableGraphConfiguration2 createWithNames2(RequestProcessor processor, final Collection<SeedSpec> roots, final Collection<Resource> exclusions, final boolean ignoreVirtualResource, final boolean validate) throws DatabaseException {
return processor.sync(new UniqueRead<TransferableGraphConfiguration2>() {
@Override
public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
return new TransferableGraphConfiguration2(graph, roots, Collections.<Resource>emptyList(), exclusions, ignoreVirtualResource, validate);
}
-
+
});
}
@Override
public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
- return new TransferableGraphConfiguration2(graph, Collections.<RootSpec>emptyList(), roots, exclusions);
+ return new TransferableGraphConfiguration2(graph, Collections.<SeedSpec>emptyList(), roots, exclusions);
}
-
+
});
}
return createWithResources(processor, Collections.singletonList(model), Collections.<Resource>emptyList());
}
- private static Collection<RootSpec> translate(Collection<NamedResource> roots) {
- ArrayList<RootSpec> result = new ArrayList<RootSpec>();
- for(NamedResource nr : roots) result.add(new RootSpec(nr.getResource(), nr.getName(), true));
+ private static Collection<SeedSpec> translate(Collection<NamedResource> roots) {
+ ArrayList<SeedSpec> result = new ArrayList<>();
+ for(NamedResource nr : roots) result.add(new SeedSpec(nr.getResource(), nr.getName(), SeedSpecType.ROOT));
return result;
}
-
+
}