1 package org.simantics.db.layer0.util;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
7 import java.util.TreeMap;
9 import org.simantics.databoard.binding.mutable.Variant;
10 import org.simantics.db.ReadGraph;
11 import org.simantics.db.RequestProcessor;
12 import org.simantics.db.Resource;
13 import org.simantics.db.Statement;
14 import org.simantics.db.common.NamedResource;
15 import org.simantics.db.common.request.UniqueRead;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
18 import org.simantics.db.layer0.util.DomainProcessor3.ExclusionDecision;
19 import org.simantics.scl.runtime.function.Function1;
21 public class TransferableGraphConfiguration2 {
23 public static class RootSpec {
24 public final Resource resource;
25 public final String name;
26 public final boolean internal;
28 public RootSpec(Resource resource, String name, boolean internal) {
30 throw new NullPointerException("null resource");
32 throw new NullPointerException("null name");
33 this.resource = resource;
35 this.internal = internal;
39 public String toString() {
40 return "RootSpec[" + name + ", " + resource + ", " + internal + "]";
44 public int hashCode() {
47 result = prime * result + (internal ? 1231 : 1237);
48 result = prime * result + resource.hashCode();
49 result = prime * result + name.hashCode();
54 public boolean equals(Object obj) {
59 if (getClass() != obj.getClass())
61 RootSpec other = (RootSpec) obj;
62 return internal == other.internal && resource.equals(other.resource) && name.equals(other.name);
66 final public TreeMap<String, Variant> baseExtensions = new TreeMap<String,Variant>();
67 final public Resource indexRoot;
68 final public Collection<RootSpec> roots;
69 final public Map<Resource, ExtentStatus> preStatus;
70 final public boolean ignoreVirtualResources;
71 final public boolean validate;
74 * <code>true</code> to export values, <code>false</code> to skip the actual
75 * values and only write the resource id.
77 public boolean values = true;
79 public Collection<TGValueModifier> valueModifiers;
80 public Function1<Statement,ExclusionDecision> exclusionFunction;
82 public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources, boolean validate) {
83 this.indexRoot = indexRoot;
85 this.preStatus = preStatus;
86 this.ignoreVirtualResources = ignoreVirtualResources;
87 this.validate = validate;
88 this.valueModifiers = null;
91 public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources) {
92 this(indexRoot, roots, preStatus, ignoreVirtualResources, true);
95 public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus) {
96 this(indexRoot, roots, preStatus, true);
99 public TransferableGraphConfiguration2(TransferableGraphConfiguration2 conf) throws DatabaseException {
100 this(conf.indexRoot, conf.roots, conf.preStatus, conf.ignoreVirtualResources, conf.validate);
103 public TransferableGraphConfiguration2(ReadGraph graph, Resource model, boolean ignoreVirtualResources, boolean validate) throws DatabaseException {
104 this(new TGConfigurer(graph, ignoreVirtualResources, validate).roots2(Collections.singletonList(model)).create());
107 public TransferableGraphConfiguration2(ReadGraph graph, Collection<Resource> roots, boolean ignoreVirtualResources, boolean validate) throws DatabaseException {
108 this(new TGConfigurer(graph, ignoreVirtualResources, validate).roots2(roots).create());
111 public TransferableGraphConfiguration2(ReadGraph graph, Resource model, boolean ignoreVirtualResources) throws DatabaseException {
112 this(graph, model, ignoreVirtualResources, true);
115 public TransferableGraphConfiguration2(ReadGraph graph, Resource model) throws DatabaseException {
116 this(graph, model, true);
119 public TransferableGraphConfiguration2(ReadGraph graph, Collection<RootSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions) throws DatabaseException {
120 this(new TGConfigurer(graph, true).roots(roots).roots2(resourceRoots).exclusions(exclusions).create());
123 public TransferableGraphConfiguration2(ReadGraph graph, Collection<RootSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions, boolean ignoreVirtualResource, boolean validate) throws DatabaseException {
124 this(new TGConfigurer(graph, ignoreVirtualResource, validate).roots(roots).roots2(resourceRoots).exclusions(exclusions).create());
127 public static TransferableGraphConfiguration2 createWithNames(RequestProcessor processor, final Collection<NamedResource> roots, final Collection<Resource> exclusions, final boolean ignoreVirtualResource, final boolean validate) throws DatabaseException {
128 return processor.sync(new UniqueRead<TransferableGraphConfiguration2>() {
131 public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
132 return new TransferableGraphConfiguration2(graph, translate(roots), Collections.<Resource>emptyList(), exclusions, ignoreVirtualResource, validate);
138 public static TransferableGraphConfiguration2 createWithNames2(RequestProcessor processor, final Collection<RootSpec> roots, final Collection<Resource> exclusions, final boolean ignoreVirtualResource, final boolean validate) throws DatabaseException {
139 return processor.sync(new UniqueRead<TransferableGraphConfiguration2>() {
142 public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
143 return new TransferableGraphConfiguration2(graph, roots, Collections.<Resource>emptyList(), exclusions, ignoreVirtualResource, validate);
149 public static TransferableGraphConfiguration2 createWithNames(RequestProcessor processor, final Collection<NamedResource> roots, final Collection<Resource> exclusions) throws DatabaseException {
150 return createWithNames(processor, roots, exclusions, true, true);
153 public static TransferableGraphConfiguration2 createWithResources(RequestProcessor processor, final Collection<Resource> roots, final Collection<Resource> exclusions) throws DatabaseException {
154 return processor.sync(new UniqueRead<TransferableGraphConfiguration2>() {
157 public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
158 return new TransferableGraphConfiguration2(graph, Collections.<RootSpec>emptyList(), roots, exclusions);
164 public static TransferableGraphConfiguration2 createForModel(RequestProcessor processor, final Resource model) throws DatabaseException {
165 return createWithResources(processor, Collections.singletonList(model), Collections.<Resource>emptyList());
168 private static Collection<RootSpec> translate(Collection<NamedResource> roots) {
169 ArrayList<RootSpec> result = new ArrayList<RootSpec>();
170 for(NamedResource nr : roots) result.add(new RootSpec(nr.getResource(), nr.getName(), true));