--- /dev/null
+package org.simantics.db.common;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.exception.DatabaseException;
+
+public class GraphSemaphore extends Semaphore {
+
+ private static final long serialVersionUID = 2114861433176831938L;
+
+ private final AsyncReadGraph graph;
+
+ public GraphSemaphore(AsyncReadGraph graph, int permits) {
+ super(permits);
+ this.graph = graph;
+ }
+
+ public void waitFor(int permits) throws DatabaseException, InterruptedException {
+
+ boolean success = false;
+ success = tryAcquire(permits);
+ if(success) return;
+
+ while(!success) {
+
+ if(graph.performPending()) {
+ // Some task was done
+ success = tryAcquire(permits);
+ } else {
+ // Nothing to do - just wait
+ try {
+ success = tryAcquire(permits, 10, TimeUnit.SECONDS);
+ if(!success) throw new DatabaseException("Timeout while waiting for async request to complete.");
+ } catch (InterruptedException e) {
+ throw new DatabaseException(e);
+ }
+ }
+
+ }
+
+
+ }
+
+
+
+}
final private Object key;
private Result result = null;
private Throwable exception = null;
+ final private AsyncReadGraph graph;
final private AsyncProcedure<Result> procedure;
final private Semaphore semaphore = new Semaphore(0);
// final private AtomicBoolean latch;
- public BlockingAsyncProcedure(AsyncProcedure<Result> procedure, Object key) {
+ public BlockingAsyncProcedure(AsyncReadGraph graph, AsyncProcedure<Result> procedure, Object key) {
// assert(procedure != null);
+ this.graph = graph;
this.key = key;
this.procedure = procedure;
if(key == null)
}
- public Result get() throws DatabaseException {
+ private void waitFor() throws DatabaseException {
+
+ boolean success = false;
+ success = semaphore.tryAcquire();
+ if(success) return;
+
+ while(!success) {
+
+ if(graph.performPending()) {
+ // Some task was done
+ success = semaphore.tryAcquire();
+ } else {
+ // Nothing to do - just wait
+ try {
+ success = semaphore.tryAcquire(10, TimeUnit.SECONDS);
+ if(!success) throw new DatabaseException("Timeout while waiting for async request to complete: " + key);
+ } catch (InterruptedException e) {
+ throw new DatabaseException(e);
+ }
+ }
+
+ }
- try {
- boolean success = semaphore.tryAcquire(10, TimeUnit.SECONDS);
- if(!success) throw new DatabaseException("Timeout while waiting for async request to complete: " + key);
- } catch (InterruptedException e) {
- throw new DatabaseException(e);
- }
+ }
+
+ public Result get() throws DatabaseException {
+
+ waitFor();
if(exception != null) {
if(exception instanceof DatabaseException) throw (DatabaseException)exception;
*******************************************************************************/
package org.simantics.db.common.uri;
-import java.util.Collection;
import java.util.Map;
-import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.service.CollectionSupport;
-import org.simantics.layer0.Layer0;
-import org.simantics.utils.Development;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
- Layer0 L0 = Layer0.getInstance(graph);
- Collection<Resource> objects = graph.getObjects(resource, L0.ConsistsOf);
- CollectionSupport cs = graph.getService(CollectionSupport.class);
- Map<String,Resource> result = cs.createObjectResourceMap(String.class, objects.size());
- for(Resource r : objects) {
- String name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);
- if(name != null) {
- Resource old = result.put(name, r);
- if (old != null)
- LOGGER.error("The database contains siblings with the same name " + name + " (resource=$" + resource.getResourceId() + ", child=$" + r.getResourceId() + ", previous child=$" + old.getResourceId() + ").");
- } else {
- if(Development.DEVELOPMENT)
- LOGGER.error("The database contains a child with no unique name (resource=$" + resource.getResourceId() + ", child=$" + r.getResourceId() + ").");
- }
- }
- return result;
+ return graph.getChildren(resource);
+// Layer0 L0 = Layer0.getInstance(graph);
+// Collection<Resource> objects = graph.getObjects(resource, L0.ConsistsOf);
+// CollectionSupport cs = graph.getService(CollectionSupport.class);
+// Map<String,Resource> result = cs.createObjectResourceMap(String.class, objects.size());
+// for(Resource r : objects) {
+// String name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);
+// if(name != null) {
+// Resource old = result.put(name, r);
+// if (old != null)
+// LOGGER.error("The database contains siblings with the same name " + name + " (resource=$" + resource.getResourceId() + ", child=$" + r.getResourceId() + ", previous child=$" + old.getResourceId() + ").");
+// } else {
+// if(Development.DEVELOPMENT)
+// LOGGER.error("The database contains a child with no unique name (resource=$" + resource.getResourceId() + ", child=$" + r.getResourceId() + ").");
+// }
+// }
+// return result;
}
}
if(Development.DEVELOPMENT) {
- impl.processor.threadLocks[0].lock();
+// impl.processor.threadLocks[0].lock();
// System.err.println("-queues=" + impl.processor.queues[0].size());
- impl.processor.threadLocks[0].unlock();
+// impl.processor.threadLocks[0].unlock();
// System.err.println("-own=" + impl.processor.ownTasks[0].size());
// System.err.println("-ownSync=" + impl.processor.ownSyncTasks[0].size());
// for(SessionTask task : impl.processor.ownSyncTasks[0]) {
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
}
}
+
+ @Override
+ public Map<String, Resource> getChildren(Resource resource) throws ValidationException, ServiceException {
+
+ assert (resource != null);
+
+ try {
+
+ int rId = processor.querySupport.getId(resource);
+ return QueryCache.resultChildMap(this, rId, parent, null);
+
+ } catch (ValidationException e) {
+
+ throw new ValidationException(e);
+
+ } catch (ServiceException e) {
+
+ throw new ServiceException(e);
+
+ } catch (DatabaseException e) {
+
+ throw new ServiceException(INTERNAL_ERROR_STRING, e);
+
+ }
+
+ }
final public Resource getRootLibrary() {
return processor.getRootLibraryResource();
assert (request != null);
// AsyncReadProcedure<T> procedure = new AsyncReadProcedure<T>();
- BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(null, request);
+ BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, null, request);
syncRequest(request, ap);
return ap.get();
// procedure.checkAndThrow();
ListenerBase listener = getListenerBase(procedure);
- BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(procedure, request);
+ BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, procedure, request);
// final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
// procedure, request);
ListenerBase listener = getListenerBase(procedure);
assert(listener == null);
- BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(procedure, request);
+ BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, procedure, request);
// final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
// procedure, request);
assert (request != null);
assert (procedure != null);
- processor.schedule(Integer.MIN_VALUE, new SessionTask(request, processor.THREAD_MASK+1, -1) {
+ processor.schedule(new SessionTask(false) {
@Override
public void run(int thread) {
});
-
-// quer
-//
-// final ListenerBase listener = getListenerBase(procedure);
-//
-// if (parent != null || listener != null) {
-//
-// try {
-// QueryCache.runnerReadEntry(this, request, parent, listener, procedure);
-// //processor.query(this, request, parent, procedure,listener);
-// } catch (DatabaseException e) {
-// Logger.defaultLogError(e);
-// // This throwable has already been transferred to procedure at this point - do nothing about it
-// //
-// }
-//
-// } else {
-//
-//// final ReadGraphImpl newGraph = newSync();
-//
-// try {
-//
-// T result = request.perform(this);
-//
-// try {
-// procedure.execute(this, result);
-// } catch (Throwable t) {
-// Logger.defaultLogError(t);
-// }
-//
-// } catch (Throwable t) {
-//
-// try {
-// procedure.exception(this, t);
-// } catch (Throwable t2) {
-// Logger.defaultLogError(t2);
-// }
-//
-// } finally {
-//
-// }
-//
-// }
-
}
public static ReadGraphImpl createAsync(QueryProcessor support) {
assert (request != null);
assert (procedure != null);
- //final ListenerBase listener = getListenerBase(procedure);
-
- processor.schedule(Integer.MIN_VALUE, new SessionTask(request, processor.THREAD_MASK+1, -1) {
+ processor.schedule(new SessionTask(false) {
@Override
public void run(int thread) {
});
-
-
-
-// if (parent != null || listener != null) {
-//
-// try {
-// QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure);
-// //processor.query(this, request, parent, procedure, listener);
-// } catch (DatabaseException e) {
-// Logger.defaultLogError(e);
-// }
-//
-// } else {
-//
-// try {
-//
-// request.perform(this, new CallWrappedSingleQueryProcedure4<T>(procedure, request));
-//
-// } catch (Throwable t) {
-//
-// if (t instanceof DatabaseException)
-// procedure.exception(this, t);
-// else
-// procedure
-// .exception(
-// this,
-// new DatabaseException(
-// "Unexpected exception in ReadGraph.asyncRequest(SingleAsyncRead, SingleProcedure)",
-// t));
-//
-// }
-//
-// }
-
}
@Override
public Object getModificationCounter() {
return processor.getSession().getModificationCounter();
}
+
+ @Override
+ public boolean performPending() {
+ return processor.performPending(processor.thread.get());
+ }
}
line(content, " return;");
line(content, " }");
}
- line(content, " " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(" + signature[1] + (genAsync ? ", isSync" : "") + ");");
+ line(content, " " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(graph, " + signature[1] + (genAsync ? ", isSync" : "") + ");");
if(genAsync) {
line(content, " if(entry == null) {");
- line(content, " graph.processor.schedule(Integer.MIN_VALUE, new SessionTask(r, graph.processor.THREAD_MASK+1, -1) {");
+ line(content, " graph.processor.schedule(new SessionTask(false) {");
line(content, " @Override");
line(content, " public void run(int thread) {");
line(content, " try {");
String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
- line(content, "" + clazz + " getOrCreate" + clazz + "(" + signature[0] + (genAsync ? ", boolean isSync" : "") + ") throws DatabaseException {");
+ line(content, "" + clazz + " getOrCreate" + clazz + "(ReadGraphImpl graph, " + signature[0] + (genAsync ? ", boolean isSync" : "") + ") throws DatabaseException {");
line(content, " " + clazz + " existing = null;");
line(content, " synchronized(" + lower + "Map) {");
line(content, " existing = (" + clazz + ")" + lower + "Map.get(" + signature[1] + ");");
line(content, " }");
if(genAsync) {
line(content, " if(existing.isPending()) {");
- line(content, " if(isSync) waitPending(existing);");
+ line(content, " if(isSync) waitPending(graph, existing);");
line(content, " else return null;");
line(content, " }");
} else {
- line(content, " if(existing.isPending()) waitPending(existing);");
+ line(content, " if(existing.isPending()) waitPending(graph, existing);");
}
line(content, " return existing;");
line(content, "}");
super(querySupport, threads);
}
- Objects getOrCreateObjects(int r1, int r2) throws DatabaseException {
+ Objects getOrCreateObjects(ReadGraphImpl graph, int r1, int r2) throws DatabaseException {
Objects existing = null;
synchronized(objectsMap) {
existing = (Objects)objectsMap.get(r1,r2);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
Objects.computeForEach(graph, r1,r2, null, procedure);
return;
}
- Objects entry = (Objects)cache.getOrCreateObjects(r1,r2);
+ Objects entry = (Objects)cache.getOrCreateObjects(graph, r1,r2);
IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureObjects;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- Statements getOrCreateStatements(int r1, int r2) throws DatabaseException {
+ Statements getOrCreateStatements(ReadGraphImpl graph, int r1, int r2) throws DatabaseException {
Statements existing = null;
synchronized(statementsMap) {
existing = (Statements)statementsMap.get(r1,r2);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
Statements.computeForEach(graph, r1,r2, null, procedure);
return;
}
- Statements entry = (Statements)cache.getOrCreateStatements(r1,r2);
+ Statements entry = (Statements)cache.getOrCreateStatements(graph, r1,r2);
TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureStatements;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- DirectObjects getOrCreateDirectObjects(int r1, int r2) throws DatabaseException {
+ DirectObjects getOrCreateDirectObjects(ReadGraphImpl graph, int r1, int r2) throws DatabaseException {
DirectObjects existing = null;
synchronized(directObjectsMap) {
existing = (DirectObjects)directObjectsMap.get(r1,r2);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
DirectObjects.computeForEach(graph, r1,r2, null, procedure);
return;
}
- DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(r1,r2);
+ DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(graph, r1,r2);
IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectObjects;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- RelationInfoQuery getOrCreateRelationInfoQuery(int r) throws DatabaseException {
+ RelationInfoQuery getOrCreateRelationInfoQuery(ReadGraphImpl graph, int r) throws DatabaseException {
RelationInfoQuery existing = null;
synchronized(relationInfoQueryMap) {
existing = (RelationInfoQuery)relationInfoQueryMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
RelationInfoQuery.computeForEach(graph, r, null, procedure);
return;
}
- RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(r);
+ RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(graph, r);
InternalProcedure<RelationInfo> procedure_ = procedure != null ? procedure : emptyProcedureRelationInfoQuery;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- URIToResource getOrCreateURIToResource(String id) throws DatabaseException {
+ URIToResource getOrCreateURIToResource(ReadGraphImpl graph, String id) throws DatabaseException {
URIToResource existing = null;
synchronized(uRIToResourceMap) {
existing = (URIToResource)uRIToResourceMap.get(id);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
URIToResource.computeForEach(graph, id, null, procedure);
return;
}
- URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(id);
+ URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(graph, id);
InternalProcedure<Integer> procedure_ = procedure != null ? procedure : emptyProcedureURIToResource;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- ValueQuery getOrCreateValueQuery(int r) throws DatabaseException {
+ ValueQuery getOrCreateValueQuery(ReadGraphImpl graph, int r) throws DatabaseException {
ValueQuery existing = null;
synchronized(valueQueryMap) {
existing = (ValueQuery)valueQueryMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
ValueQuery.computeForEach(graph, r, null, procedure);
return;
}
- ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(r);
+ ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(graph, r);
InternalProcedure<byte[]> procedure_ = procedure != null ? procedure : emptyProcedureValueQuery;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- OrderedSet getOrCreateOrderedSet(int r) throws DatabaseException {
+ OrderedSet getOrCreateOrderedSet(ReadGraphImpl graph, int r) throws DatabaseException {
OrderedSet existing = null;
synchronized(orderedSetMap) {
existing = (OrderedSet)orderedSetMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
OrderedSet.computeForEach(graph, r, null, procedure);
return;
}
- OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(r);
+ OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(graph, r);
IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureOrderedSet;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- PrincipalTypes getOrCreatePrincipalTypes(int r) throws DatabaseException {
+ PrincipalTypes getOrCreatePrincipalTypes(ReadGraphImpl graph, int r) throws DatabaseException {
PrincipalTypes existing = null;
synchronized(principalTypesMap) {
existing = (PrincipalTypes)principalTypesMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
PrincipalTypes.computeForEach(graph, r, null, procedure);
return;
}
- PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(r);
+ PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(graph, r);
IntProcedure procedure_ = procedure != null ? procedure : emptyProcedurePrincipalTypes;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- DirectPredicates getOrCreateDirectPredicates(int r) throws DatabaseException {
+ DirectPredicates getOrCreateDirectPredicates(ReadGraphImpl graph, int r) throws DatabaseException {
DirectPredicates existing = null;
synchronized(directPredicatesMap) {
existing = (DirectPredicates)directPredicatesMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
DirectPredicates.computeForEach(graph, r, null, procedure);
return;
}
- DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(r);
+ DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(graph, r);
InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureDirectPredicates;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- Predicates getOrCreatePredicates(int r) throws DatabaseException {
+ Predicates getOrCreatePredicates(ReadGraphImpl graph, int r) throws DatabaseException {
Predicates existing = null;
synchronized(predicatesMap) {
existing = (Predicates)predicatesMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
Predicates.computeForEach(graph, r, null, procedure);
return;
}
- Predicates entry = (Predicates)cache.getOrCreatePredicates(r);
+ Predicates entry = (Predicates)cache.getOrCreatePredicates(graph, r);
InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedurePredicates;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- ReadEntry getOrCreateReadEntry(Read<?> r, boolean isSync) throws DatabaseException {
+ ReadEntry getOrCreateReadEntry(ReadGraphImpl graph, Read<?> r, boolean isSync) throws DatabaseException {
ReadEntry existing = null;
synchronized(readEntryMap) {
existing = (ReadEntry)readEntryMap.get(r);
}
}
if(existing.isPending()) {
- if(isSync) waitPending(existing);
+ if(isSync) waitPending(graph, existing);
else return null;
}
return existing;
ReadEntry.computeForEach(graph, r, null, procedure);
return;
}
- ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(r, isSync);
+ ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(graph, r, isSync);
if(entry == null) {
- graph.processor.schedule(Integer.MIN_VALUE, new SessionTask(r, graph.processor.THREAD_MASK+1, -1) {
+ graph.processor.schedule(new SessionTask(false) {
@Override
public void run(int thread) {
try {
}
}
- AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead<?> r, boolean isSync) throws DatabaseException {
+ AsyncReadEntry getOrCreateAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, boolean isSync) throws DatabaseException {
AsyncReadEntry existing = null;
synchronized(asyncReadEntryMap) {
existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
}
}
if(existing.isPending()) {
- if(isSync) waitPending(existing);
+ if(isSync) waitPending(graph, existing);
else return null;
}
return existing;
AsyncReadEntry.computeForEach(graph, r, null, procedure);
return;
}
- AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r, isSync);
+ AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph, r, isSync);
if(entry == null) {
- graph.processor.schedule(Integer.MIN_VALUE, new SessionTask(r, graph.processor.THREAD_MASK+1, -1) {
+ graph.processor.schedule(new SessionTask(false) {
@Override
public void run(int thread) {
try {
}
}
- Types getOrCreateTypes(int r) throws DatabaseException {
+ Types getOrCreateTypes(ReadGraphImpl graph, int r) throws DatabaseException {
Types existing = null;
synchronized(typesMap) {
existing = (Types)typesMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
Types.computeForEach(graph, r, null, procedure);
return;
}
- Types entry = (Types)cache.getOrCreateTypes(r);
+ Types entry = (Types)cache.getOrCreateTypes(graph, r);
InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypes;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- ChildMap getOrCreateChildMap(int r) throws DatabaseException {
+ ChildMap getOrCreateChildMap(ReadGraphImpl graph, int r) throws DatabaseException {
ChildMap existing = null;
synchronized(childMapMap) {
existing = (ChildMap)childMapMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
ChildMap.computeForEach(graph, r, null, procedure);
return;
}
- ChildMap entry = (ChildMap)cache.getOrCreateChildMap(r);
+ ChildMap entry = (ChildMap)cache.getOrCreateChildMap(graph, r);
InternalProcedure<ObjectResourceIdMap<String>> procedure_ = procedure != null ? procedure : emptyProcedureChildMap;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- AssertedStatements getOrCreateAssertedStatements(int r1, int r2) throws DatabaseException {
+ AssertedStatements getOrCreateAssertedStatements(ReadGraphImpl graph, int r1, int r2) throws DatabaseException {
AssertedStatements existing = null;
synchronized(assertedStatementsMap) {
existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2);
+ AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph, r1,r2);
TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- AssertedPredicates getOrCreateAssertedPredicates(int r) throws DatabaseException {
+ AssertedPredicates getOrCreateAssertedPredicates(ReadGraphImpl graph, int r) throws DatabaseException {
AssertedPredicates existing = null;
synchronized(assertedPredicatesMap) {
existing = (AssertedPredicates)assertedPredicatesMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(r);
+ AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph, r);
IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- DirectSuperRelations getOrCreateDirectSuperRelations(int r) throws DatabaseException {
+ DirectSuperRelations getOrCreateDirectSuperRelations(ReadGraphImpl graph, int r) throws DatabaseException {
DirectSuperRelations existing = null;
synchronized(directSuperRelationsMap) {
existing = (DirectSuperRelations)directSuperRelationsMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(r);
+ DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph, r);
IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- SuperTypes getOrCreateSuperTypes(int r) throws DatabaseException {
+ SuperTypes getOrCreateSuperTypes(ReadGraphImpl graph, int r) throws DatabaseException {
SuperTypes existing = null;
synchronized(superTypesMap) {
existing = (SuperTypes)superTypesMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(r);
+ SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph, r);
InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- TypeHierarchy getOrCreateTypeHierarchy(int r) throws DatabaseException {
+ TypeHierarchy getOrCreateTypeHierarchy(ReadGraphImpl graph, int r) throws DatabaseException {
TypeHierarchy existing = null;
synchronized(typeHierarchyMap) {
existing = (TypeHierarchy)typeHierarchyMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(r);
+ TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph, r);
InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- SuperRelations getOrCreateSuperRelations(int r) throws DatabaseException {
+ SuperRelations getOrCreateSuperRelations(ReadGraphImpl graph, int r) throws DatabaseException {
SuperRelations existing = null;
synchronized(superRelationsMap) {
existing = (SuperRelations)superRelationsMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(r);
+ SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph, r);
InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- MultiReadEntry getOrCreateMultiReadEntry(MultiRead<?> r) throws DatabaseException {
+ MultiReadEntry getOrCreateMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r) throws DatabaseException {
MultiReadEntry existing = null;
synchronized(multiReadEntryMap) {
existing = (MultiReadEntry)multiReadEntryMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(r);
+ MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(graph, r);
AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(AsyncMultiRead<?> r) throws DatabaseException {
+ AsyncMultiReadEntry getOrCreateAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r) throws DatabaseException {
AsyncMultiReadEntry existing = null;
synchronized(asyncMultiReadEntryMap) {
existing = (AsyncMultiReadEntry)asyncMultiReadEntryMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(r);
+ AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(graph, r);
AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncMultiReadEntry;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
}
}
- ExternalReadEntry getOrCreateExternalReadEntry(ExternalRead<?> r) throws DatabaseException {
+ ExternalReadEntry getOrCreateExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r) throws DatabaseException {
ExternalReadEntry existing = null;
synchronized(externalReadEntryMap) {
existing = (ExternalReadEntry)externalReadEntryMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) waitPending(graph, existing);
return existing;
}
public static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(r);
+ ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(graph, r);
AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureExternalReadEntry;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) entry.performFromCache(graph, procedure_);
import org.simantics.db.impl.DebugPolicy;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
+import org.simantics.db.impl.query.QueryProcessor.SessionTask;
import org.simantics.db.procedure.AsyncMultiProcedure;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.db.procedure.Listener;
}
}
- public static void waitPending(CacheEntry entry) throws DatabaseException {
+ public static void waitPending(ReadGraphImpl graph, CacheEntry entry) throws DatabaseException {
+
+ QueryProcessor processor = graph.processor;
int counter = 0;
while(entry.isPending()) {
try {
- Thread.sleep(1);
- counter++;
- if(counter > 5000) {
- CacheEntryBase base = ((CacheEntryBase)entry);
-// if(base.created != null) {
-// System.err.println("created:");
-// base.created.printStackTrace();
-// }
-// if(base.performed != null) {
-// System.err.println("performed:");
-// base.performed.printStackTrace();
-// }
-// if(base.ready != null) {
-// System.err.println("ready:");
-// base.ready.printStackTrace();
-// }
- new Exception("Timeout waiting for request to complete: " + entry.getOriginalRequest().toString()).printStackTrace();
- throw new DatabaseException("Timeout waiting for request to complete.");
- //System.err.println("asd");
- //base.getQuery().recompute(null, null, entry);
+ SessionTask task = processor.getOwnTask(processor.thread.get());
+ if(task != null) {
+ task.run(processor.thread.get());
+ } else {
+ Thread.sleep(1);
+ counter++;
+ if(counter > 5000) {
+ CacheEntryBase base = ((CacheEntryBase)entry);
+// if(base.created != null) {
+// System.err.println("created:");
+// base.created.printStackTrace();
+// }
+// if(base.performed != null) {
+// System.err.println("performed:");
+// base.performed.printStackTrace();
+// }
+// if(base.ready != null) {
+// System.err.println("ready:");
+// base.ready.printStackTrace();
+// }
+ new Exception("Timeout waiting for request to complete: " + entry.getOriginalRequest().toString()).printStackTrace();
+ throw new DatabaseException("Timeout waiting for request to complete.");
+ //System.err.println("asd");
+ //base.getQuery().recompute(null, null, entry);
+ }
}
} catch (InterruptedException e) {
}
}
public ThreadState[] threadStates;
- public ReentrantLock[] threadLocks;
- public Condition[] threadConditions;
+// public ReentrantLock[] threadLocks;
+// public Condition[] threadConditions;
//public ArrayList<SessionTask>[] ownTasks;
public void close() {
}
+ SessionTask getOwnTask(int thread) {
+ synchronized(querySupportLock) {
+ int index = 0;
+ while(index < freeScheduling.size()) {
+ SessionTask task = freeScheduling.get(index);
+ if(task.thread == thread && !task.systemCall)
+ return freeScheduling.remove(index);
+ index++;
+ }
+ }
+ return null;
+ }
+
+ public boolean performPending(int thread) {
+ SessionTask task = getOwnTask(thread);
+ if(task != null) {
+ task.run(thread);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
// final public void scheduleOwn(int caller, SessionTask request) {
// ownTasks[caller].add(request);
// }
- final public void scheduleAlways(int caller, SessionTask request) {
-
-// int performer = request.thread;
-// if(caller == performer) {
-// ownTasks[caller].add(request);
-// } else {
-// schedule(caller, request);
-// }
-
- schedule(caller, request);
-
- }
-
- final public void schedule(int caller, SessionTask request) {
+ final public void schedule(SessionTask request) {
int performer = request.thread;
if(DebugPolicy.SCHEDULE)
- System.out.println("schedule " + request + " " + caller + " -> " + performer);
+ System.out.println("schedule " + request + " " + " -> " + performer);
- assert(performer >= 0);
+ //assert(performer >= 0);
assert(request != null);
synchronized(querySupportLock) {
+ //new Exception().printStackTrace();
+
freeScheduling.add(request);
+
+ querySupportLock.notifyAll();
//System.err.println("schedule free task " + request + " => " + freeScheduling.size());
- for(int i=0;i<THREADS;i++) {
- ReentrantLock queueLock = threadLocks[i];
- queueLock.lock();
- //queues[performer].add(request);
- //if(ThreadState.SLEEP == threadStates[i]) sleepers.decrementAndGet();
- threadConditions[i].signalAll();
- queueLock.unlock();
- }
+// for(int i=0;i<THREADS;i++) {
+// ReentrantLock queueLock = threadLocks[i];
+// queueLock.lock();
+// //queues[performer].add(request);
+// //if(ThreadState.SLEEP == threadStates[i]) sleepers.decrementAndGet();
+// threadConditions[i].signalAll();
+// queueLock.unlock();
+// }
}
public static abstract class SessionTask {
final public int thread;
- final public int syncCaller;
- final public Object object;
-
- public SessionTask(WriteTraits object, int thread) {
- this.thread = thread;
- this.syncCaller = -1;
- this.object = object;
+ final public boolean systemCall;
+// final public int syncCaller;
+ //final public Object object;
+
+ public SessionTask(boolean systemCall) {
+ this.thread = QueryProcessor.thread.get();
+ this.systemCall = systemCall;
+// this.syncCaller = -1;
+ //this.object = object;
}
- public SessionTask(Object object, int thread, int syncCaller) {
- this.thread = thread;
- this.syncCaller = syncCaller;
- this.object = object;
- }
+// public SessionTask(Object object, int syncCaller) {
+// this.thread = QueryProcessor.thread.get();
+// this.syncCaller = syncCaller;
+// this.object = object;
+// }
public abstract void run(int thread);
@Override
public String toString() {
- return "SessionTask[" + object + "]";
+ return "SessionTask[" + super.toString() + "]";
}
}
final public Semaphore notify;
final public DataContainer<Throwable> throwable;
- public SessionRead(Object object, DataContainer<Throwable> throwable, Semaphore notify, int thread) {
- super(object, thread, thread);
- this.throwable = throwable;
- this.notify = notify;
- }
-
- public SessionRead(Object object, DataContainer<Throwable> throwable, Semaphore notify, int thread, int syncThread) {
- super(object, thread, syncThread);
+ public SessionRead(DataContainer<Throwable> throwable, Semaphore notify) {
+ super(true);
this.throwable = throwable;
this.notify = notify;
}
executors = new QueryThread[THREADS];
// queues = new ArrayList[THREADS];
- threadLocks = new ReentrantLock[THREADS];
- threadConditions = new Condition[THREADS];
+// threadLocks = new ReentrantLock[THREADS];
+// threadConditions = new Condition[THREADS];
threadStates = new ThreadState[THREADS];
// ownTasks = new ArrayList[THREADS];
// ownSyncTasks = new ArrayList[THREADS];
// ownTasks[i] = new ArrayList<SessionTask>();
// ownSyncTasks[i] = new ArrayList<SessionTask>();
// queues[i] = new ArrayList<SessionTask>();
- threadLocks[i] = new ReentrantLock();
- threadConditions[i] = threadLocks[i].newCondition();
+// threadLocks[i] = new ReentrantLock();
+// threadConditions[i] = threadLocks[i].newCondition();
// limits[i] = false;
threadStates[i] = ThreadState.INIT;
}
return L0;
}
+
+ public static ThreadLocal<Integer> thread = new ThreadLocal<Integer>() {
+ protected Integer initialValue() {
+ return -1;
+ }
+ };
}
import java.util.ArrayList;
import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
// final private ArrayList<SessionTask> own;
// final private ArrayList<SessionTask> ownSync;
// final private ArrayList<SessionTask> queue;
- final private ReentrantLock lock;
- final private Condition condition;
+// final private ReentrantLock lock;
+// final private Condition condition;
final private Object querySupportLock;
final private int THREADS;
final private AtomicInteger sleepers;
final private ThreadState[] threadStates;
// final private ArrayList<SessionTask>[] delayQueues;
- final private QueryThread[] executors;
- final private ReentrantLock[] threadLocks;
+// final private QueryThread[] executors;
+// final private ReentrantLock[] threadLocks;
// final private ArrayList<SessionTask>[] queues;
// final private ArrayList<SessionTask>[] ownSyncTasks;
// own = processor.ownTasks[index];
// ownSync = processor.ownSyncTasks[index];
// queue = processor.queues[index];
- lock = processor.threadLocks[index];
- condition = processor.threadConditions[index];
+// lock = processor.threadLocks[index];
+// condition = processor.threadConditions[index];
querySupportLock = processor.querySupportLock;
THREADS = processor.THREADS;
sleepers = processor.sleepers;
querySupport = processor.querySupport;
threadStates = processor.threadStates;
// delayQueues = processor.delayQueues;
- executors = processor.executors;
- threadLocks = processor.threadLocks;
+// executors = processor.executors;
+// threadLocks = processor.threadLocks;
// queues = processor.queues;
// ownSyncTasks = processor.ownSyncTasks;
}
// System.err.println("qt dispose");
disposed = true;
- lock.lock();
- condition.signalAll();
- lock.unlock();
+// lock.lock();
+// condition.signalAll();
+// lock.unlock();
try {
exited.acquire();
}
+ private boolean pumpTask() {
+ if(!processor.freeScheduling.isEmpty()) {
+ tasks.add(processor.freeScheduling.removeFirst());
+ return true;
+ }
+ return false;
+ }
+
ArrayList<SessionTask> newTasks(boolean doWait, ArrayList<SessionTask> tasks) {
try {
while(true) {
- // Perform own tasks first
-// if(tasks.addAll(own)) {
-// own.clear();
-// } else if (doWait && !ownSync.isEmpty()) {
-// tasks.add(ownSync.remove(ownSync.size()-1));
-// }
-
- // Try some queued tasks
-// lock.lock();
-// if(tasks.addAll(queue)) {
-// queue.clear();
-// lock.unlock();
-// return tasks;
-// } else {
-// lock.unlock();
-// }
-
// Return tasks if some were found
if(!tasks.isEmpty()) return tasks;
synchronized (querySupportLock) {
-// System.err.println("check free tasks for QT " + index + " (" + processor.freeScheduling + ")");
-
- if(!processor.freeScheduling.isEmpty()) {
- tasks.add(processor.freeScheduling.removeFirst());
+ if(pumpTask())
return tasks;
- }
- lock.lock();
-
- // Just maybe someone inserted tasks and notified just before synchronized block
-// if(tasks.addAll(queue)) {
-// queue.clear();
-// lock.unlock();
-// return tasks;
-// }
-
-// System.err.println("QT " + index + ", sleepers = " + sleepers);
+// lock.lock();
// We are the last one awake
if(sleepers.incrementAndGet() == THREADS) {
if(querySupport == null) System.err.println("null qs");
querySupport.ceased(index);
-// if(tasks.addAll(own)) {
-// own.clear();
-// }
- // System.err.println("tasks after ceased: " + tasks.size());
- if(!tasks.isEmpty()) {
- lock.unlock();
+ if(pumpTask()) {
+// lock.unlock();
return tasks;
}
// We are done
if(isDisposed()) {
threadStates[index] = ThreadState.DISPOSED;
- lock.unlock();
+// lock.unlock();
return null;
}
+
threadStates[index] = ThreadState.SLEEP;
- condition.await();
+
+ synchronized (querySupportLock) {
+ querySupportLock.wait(100);
+
+ }
+
+// boolean woken = condition.await(10, TimeUnit.MILLISECONDS);
+// if(!woken) {
+// synchronized (querySupportLock) {
+// if(!processor.freeScheduling.isEmpty())
+// System.err.println("some tasks are available!");
+// }
+// }
sleepers.decrementAndGet();
// We are done
if(isDisposed()) {
threadStates[index] = ThreadState.DISPOSED;
- lock.unlock();
+ //lock.unlock();
return null;
}
threadStates[index] = ThreadState.RUN;
- lock.unlock();
+ //lock.unlock();
}
@Override
public void run() {
+ processor.thread.set(index);
+
QuerySupport support = this.querySupport;
try {
public static class SeedSpec {
public static enum SeedSpecType {
- INTERNAL, ROOT, SPECIAL_ROOT
+ // These seeds and all their child resources (ConsistsOfProcess) are internal
+ INTERNAL,
+ // These seeds are reported as root entries in TG,
+ ROOT,
+ SPECIAL_ROOT
}
public final Resource resource;
import org.simantics.db.layer0.variable.RVI.StringRVIPart;
import org.simantics.db.layer0.variable.Variables.Role;
import org.simantics.layer0.Layer0;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function2;
/**
* Abstract implementation of Variable -interface.
return graph.getPossibleRelatedValue2(represents, graph.getService(Layer0.class).HasLabel, getParent(graph), Bindings.STRING);
}
- public Resource getType(ReadGraph graph) throws DatabaseException {
-
- Resource resource = getPossibleRepresents(graph);
- if(resource == null) {
- String uri = getPossiblePropertyValue(graph, "typeURI");
- if(uri != null) return graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.<Resource>instance());
- throw new DatabaseException("No type for " + getURI(graph));
- }
- return graph.getSingleType(resource);
-
- }
-
public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException {
throw new UnsupportedOperationException();
}
}
}
+ public Resource getType(ReadGraph graph) throws DatabaseException {
+
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ if(custom != null) {
+
+ Object o = custom.getPossibleValue(graph);
+ Function2<Variable,Resource,Resource> fn = (Function2<Variable,Resource,Resource>)o;
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.put("graph", graph);
+ try {
+ return (Resource)fn.apply(this, Layer0.getInstance(graph).Entity);
+ } catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+
+ }
+
+ Resource resource = getPossibleRepresents(graph);
+ if(resource == null) {
+ String uri = getPossiblePropertyValue(graph, "typeURI");
+ if(uri != null) return graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.<Resource>instance());
+ throw new DatabaseException("No type for " + getURI(graph));
+ }
+ return graph.getSingleType(resource);
+
+ }
+
+
@Override
public Resource getPossibleType(ReadGraph graph) throws DatabaseException {
+
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ if(custom != null) {
+
+ Object o = custom.getPossibleValue(graph);
+ Function2<Variable,Resource,Resource> fn = (Function2<Variable,Resource,Resource>)o;
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.put("graph", graph);
+ try {
+ return (Resource)fn.apply(this, Layer0.getInstance(graph).Entity);
+ } catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+
+ }
+
Resource resource = getPossibleRepresents(graph);
if(resource == null) {
String uri = getPossiblePropertyValue(graph, "typeURI");
}
public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
+
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ if(custom != null) {
+
+ Object o = custom.getPossibleValue(graph);
+ Function2<Variable,Resource,Resource> fn = (Function2<Variable,Resource,Resource>)o;
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.put("graph", graph);
+ try {
+ return (Resource)fn.apply(this, baseType);
+ } catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+
+ }
+
Resource resource = getPossibleRepresents(graph);
if(resource == null) {
String uri = getPossiblePropertyValue(graph, "typeURI");
@Override
public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {
+
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ if(custom != null) {
+ Object o = custom.getPossibleValue(graph);
+ Function2<Variable,Resource,Resource> fn = (Function2<Variable,Resource,Resource>)o;
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.put("graph", graph);
+ try {
+ return (Resource)fn.apply(this, baseType);
+ } catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+
+ }
+
Resource resource = getPossibleRepresents(graph);
if(resource == null) {
String uri = getPossiblePropertyValue(graph, "typeURI");
int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleWrite(new SessionTask(request, thread, thread) {
+ requestManager.scheduleWrite(new SessionTask(true) {
@Override
public void run(int thread) {
int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleWrite(new SessionTask(request, thread) {
+ requestManager.scheduleWrite(new SessionTask(true) {
@Override
public void run(int thread) {
int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleWrite(new SessionTask(request, thread) {
+ requestManager.scheduleWrite(new SessionTask(true) {
@Override
public void run(int thread) {
int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleWrite(new SessionTask(request, thread, thread) {
+ requestManager.scheduleWrite(new SessionTask(true) {
@Override
public void run(int thread) {
int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleWrite(new SessionTask(request, thread) {
+ requestManager.scheduleWrite(new SessionTask(true) {
@Override
public void run(int thread) {
//int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleRead(new SessionRead(request, throwable, notify, queryProvider2.THREAD_MASK + 1, -1) {
+ requestManager.scheduleRead(new SessionRead(throwable, notify) {
@Override
public void run(int thread) {
int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleRead(new SessionRead(request, null, notify, thread) {
+ requestManager.scheduleRead(new SessionRead(null, notify) {
@Override
public void run(int thread) {
// final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
// procedure, "request");
- BlockingAsyncProcedure<T> wrap = new BlockingAsyncProcedure<T>(procedure, request);
+ BlockingAsyncProcedure<T> wrap = new BlockingAsyncProcedure<T>(newGraph, procedure, request);
try {
int sync = notify != null ? thread : -1;
- requestManager.scheduleRead(new SessionRead(request, null, notify, thread, sync) {
+ requestManager.scheduleRead(new SessionRead(null, notify) {
@Override
public void run(int thread) {
int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleRead(new SessionRead(request, throwable, notify, thread, thread) {
+ requestManager.scheduleRead(new SessionRead(throwable, notify) {
@Override
public void run(int thread) {
public int getAmountOfQueryThreads() {
// This must be a power of two
- return 16;
+ return 1;
// return Integer.highestOneBit(Runtime.getRuntime().availableProcessors());
}
public synchronized void startRead(int thread, final SessionRead task) {
- session.queryProvider2.scheduleAlways(thread, new SessionTask(task.object, task.thread, task.syncCaller) {
+ session.queryProvider2.schedule(new SessionTask(true) {
@Override
public void run(int thread) {
public synchronized void startReadUpdate(int thread) {
- session.queryProvider2.scheduleAlways(thread, new SessionTask(null, thread) {
+ session.queryProvider2.schedule(new SessionTask(true) {
@Override
public void run(int thread) {
public synchronized void startWrite(int thread, final SessionTask task) {
- session.queryProvider2.scheduleAlways(thread, new SessionTask((WriteTraits)task.object, task.thread) {
+ session.queryProvider2.schedule(new SessionTask(true) {
@Override
public void run(int thread) {
public synchronized void startWriteUpdate(int thread) {
- session.queryProvider2.scheduleAlways(thread, new SessionTask(null, thread) {
+ session.queryProvider2.schedule(new SessionTask(true) {
@Override
public void run(int thread) {
if (!reads.isEmpty()) {
final SessionRead read = reads.poll();
- session.queryProvider2.scheduleAlways(thread, new SessionTask(read.object, read.thread, read.syncCaller) {
+ session.queryProvider2.schedule(new SessionTask(true) {
@Override
public void run(int thread) {
assert(State.INIT != state);
if(State.READ == state) {
- session.queryProvider2.schedule(Integer.MIN_VALUE, new SessionTask(task.object, task.thread, task.syncCaller) {
+ session.queryProvider2.schedule(new SessionTask(true) {
@Override
public void run(int thread) {
final Operation fop = (Operation)ops.toArray()[0];
final DataContainer<Long> id = new DataContainer<Long>(0L);
final TaskHelper th = new TaskHelper("Undo");
- session.requestManager.scheduleWrite(new SessionTask(null, 0) {
+ session.requestManager.scheduleWrite(new SessionTask(true) {
@Override
public void run(int thread) {
session.flushCounter = 0;
import org.simantics.utils.datastructures.Pair;
public class AdaptionService2 implements AdaptionService {
+
+ int foobaz;
THashMap<Pair<Class<?>,Class<?>>, AdapterDeclaration<?>> adapters =
new THashMap<Pair<Class<?>,Class<?>>, AdapterDeclaration<?>>();
Adapter<T,C> adapter = getAdapter(g, r, context, contextClass, targetClass, possible);
if(adapter == null) return null;
- BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<T>(null, adapter);
+ BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<T>(g, null, adapter);
// SyncReadProcedure<T> procedure = new SyncReadProcedure<T>();
adapter.adapt(g, r, context, ap);
+
return ap.get();
// procedure.checkAndThrow();
// return procedure.result;
boolean isImmutable(Resource resource) throws DatabaseException;
+ boolean performPending();
+
}
package org.simantics.db;
import java.util.Collection;
+import java.util.Map;
import java.util.Set;
import org.simantics.databoard.accessor.Accessor;
*/
Resource getPossibleResource(String uri) throws ResourceNotFoundException, ValidationException, ServiceException;
+ /**
+ * Computes a map of objects related to resource with L0.ConsistsOf that also contain a L0.HasName property
+ *
+ * @param resource the resource
+ * @return the children
+ * @throws ValidationException if a resource could not be produced due to
+ * invalid semantics
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forResourceByURI
+ */
+ Map<String,Resource> getChildren(Resource resource) throws ValidationException, ServiceException;
+
/**
* Gets a builtin resource. For a list of builtin resources see TODO Wiki
*
if(o instanceof Connection) {
Connection c = (Connection)o;
ArrayList<String> result = new ArrayList<String>();
- for(VariableConnectionPointDescriptor v : c.getConnectionPointDescriptors(graph, base, null)) {
+ System.err.println("base: " + base.getURI(graph));
+ for(VariableConnectionPointDescriptor v : c.getConnectionPointDescriptors(graph, base.getParent(graph), null)) {
+ Variable asd = v.getVariable(graph);
+ System.err.println("spadopo " + asd.getURI(graph));
result.add(v.getRelativeRVI(graph, base));
}
return "c " + result.toString();
*******************************************************************************/
package org.simantics.diagram.adapter;
-import gnu.trove.list.array.TIntArrayList;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.procedure.TIntProcedure;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
-import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
-import org.simantics.db.AsyncReadGraph;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
-import org.simantics.db.common.primitiverequest.OrderedSet;
+import org.simantics.db.common.GraphSemaphore;
import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
import org.simantics.db.common.utils.OrderedSetUtils;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.procedure.AsyncMultiProcedure;
-import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.diagram.content.ConnectionPartData;
import org.simantics.diagram.content.ConnectionPartRequest;
import org.simantics.diagram.content.DiagramContents;
import org.simantics.diagram.synchronization.ErrorHandler;
import org.simantics.g2d.canvas.ICanvasContext;
+import gnu.trove.list.array.TIntArrayList;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.procedure.TIntProcedure;
+import gnu.trove.set.hash.THashSet;
+
/**
* @author Tuukka Lehtonen
*/
Collection<Resource> components = OrderedSetUtils.toList(g, data);
- Semaphore s = new Semaphore(0);
+ GraphSemaphore s = new GraphSemaphore(g, 0);
for(Resource component : components) {
}
}
-
+
try {
- s.acquire(components.size());
+ s.waitFor(components.size());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static Pair<Integer, Collection<JSONObject>> getContent(Listener<Integer> listener, String location, int sequenceNumber) {
+ System.err.println("getContent " + location);
DocumentHistory history = getHistory(location, true);
return history.getContent(listener, location, sequenceNumber);
}
@Override
public WidgetManager<?, ?> getManager(JSONObject object) {
- return mapping.getWidget(object.getType());
+ WidgetManager<?, ?> result = mapping.getWidget(object.getType());
+ if(result == null)
+ throw new RuntimeException("No manager for type " + object.getType());
+ return result;
}
@Override
import java.util.concurrent.TimeUnit;
import org.simantics.db.ReadGraph;
+import org.simantics.db.common.GraphSemaphore;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.request.VariableRead;
System.out.println(" " + node.getURI(graph));
}*/
- Semaphore done = new Semaphore(0);
+ GraphSemaphore done = new GraphSemaphore(graph, 0);
for(Variable node : nodes) {
}
try {
- boolean success = done.tryAcquire(nodes.size(), 10, TimeUnit.MILLISECONDS);
- while(!success) {
- success = done.tryAcquire(nodes.size(), 10, TimeUnit.MILLISECONDS);
- System.err.println("still trying to acquire semaphore, avail = " + done.availablePermits() );
- }
-
+ done.waitFor(nodes.size());
} catch (InterruptedException e) {
e.printStackTrace();
}
propertyValueSetter :: Variable -> String -> <ReadGraph> AbstractEventHandler
+ columnsBean :: Resource -> <ReadGraph> ColumnsBean
+ columnBeans :: ColumnsBean -> [ColumnBean]
+
+ columnBeanKey :: ColumnBean -> String
+ columnBeanLabel :: ColumnBean -> String
\ No newline at end of file
importJava "org.simantics.document.swt.core.bean.ColumnBean" where
data ColumnBean
+importJava "org.simantics.document.swt.core.bean.ColumnsBean" where
+ data ColumnsBean
+
importJava "org.simantics.browsing.ui.StatePersistor" where
data StatePersistor
// TODO: pc may be disposed, how to handle this and why is it happening?
if(pc != null && !pc.isDisposed())
createControl(document, pc, object);
+ else
+ System.err.println("whatta!");
}
}
return (T)control;
package org.simantics.document.swt.core.scl;
+import java.util.ArrayList;
import java.util.List;
import org.simantics.databoard.Bindings;
import org.simantics.document.server.io.CommandResult;
import org.simantics.document.server.serverResponse.ServerResponse;
import org.simantics.document.swt.core.SWTViews;
+import org.simantics.document.swt.core.bean.ColumnBean;
+import org.simantics.document.swt.core.bean.ColumnsBean;
import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.function.Function1;
import org.simantics.scl.runtime.reporting.SCLReportingHandler;
public static Resource wseResource(ReadGraph graph, WorkbenchSelectionElement wse) throws DatabaseException {
return WorkbenchSelectionUtils.getPossibleResource(wse);
}
+
+ public static ColumnsBean columnsBean(ReadGraph graph, Resource value) throws DatabaseException {
+ return graph.getValue(value, ColumnsBean.BINDING);
+ }
+
+ public static List<ColumnBean> columnBeans(ColumnsBean bean) {
+ ArrayList<ColumnBean> result = new ArrayList<>();
+ for(ColumnBean b : bean.columns) result.add(b);
+ return result;
+ }
+
+ public static String columnBeanKey(ColumnBean bean) {
+ return bean.key;
+ }
+
+ public static String columnBeanLabel(ColumnBean bean) {
+ return bean.label;
+ }
}
>-- L0.typeURI <R L0.HasProperty : L0.FunctionalRelation
L0.HasLabel "Type URI"
--> L0.String
+ >-- L0.typeResource <R L0.HasProperty : L0.FunctionalRelation
+ L0.HasLabel "Type Resource"
+ ==> "Variable -> Resource -> <ReadGraph> Resource"
+ >-- L0.representsResource <R L0.HasProperty : L0.FunctionalRelation
+ L0.HasLabel "Representing Resource"
+ ==> "Variable -> <ReadGraph> Resource"
>-- L0.HasComment --> L0.String <R L0.HasProperty
>-- L0.ConsistsOf --> L0.Entity <R L0.IsComposedOf
L0.InverseOf L0.PartOf : L0.FunctionalRelation
@Override
public Variable buildChild(ReadGraph graph, Variable parent, VariableNode<Node> node, Resource child) throws DatabaseException {
boolean isImmutable = graph.isImmutable(child);
- Resource possibleIndexRoot = graph.syncRequest(new PossibleIndexRoot(child));
- if(possibleIndexRoot != null) {
-// String puri = graph.getURI(possibleIndexRoot);
-// if(puri.contains("ModelBroker"))
-// isImmutable = true;
-// if(NameUtils.getSafeName(graph, child).equals("Project"))
-// isImmutable = false;
- }
if(isImmutable) {
-// System.err.println("ImmutableComponentVariableContentRequest " + parent.getURI(graph) + " " + NameUtils.getSafeName(graph, child));
- ImmutableComponentVariableContent content = graph.syncRequest(new ImmutableComponentVariableContentRequest(child), TransientCacheListener.instance());
- return new ImmutableComponentVariable(parent, content);
+// ImmutableComponentVariableContent content = graph.syncRequest(new ImmutableComponentVariableContentRequest(child), TransientCacheListener.instance());
+// return new ImmutableComponentVariable(parent, content);
+ return new StandardGraphChildVariable(parent, node, child);
} else {
return new StandardGraphChildVariable(parent, node, child);
}
import org.simantics.layer0.Layer0;
import org.simantics.structural.stubs.StructuralResource2;
import org.simantics.structural2.ConnectionImpl;
-import org.simantics.structural2.Functions.StructuralChildMapOfResource;
import org.simantics.structural2.queries.ConnectionPointMapOfResource;
public class ImmutableComponentVariableContentRequest extends ResourceRead<ImmutableComponentVariableContent> {
}
HashSet<Resource> childSet = null;
- for(Resource child : graph.syncRequest(new StructuralChildMapOfResource(resource)).values()) {
+
+ Resource container = resource;
+ Resource possibleType = graph.getPossibleType(resource, STR.Component);
+ if(possibleType != null) {
+ Resource def = graph.getPossibleObject(possibleType, STR.IsDefinedBy);
+ if(def != null) container = def;
+ }
+
+ for(Resource child : graph.getChildren(container).values()) {
if(childSet == null)
childSet = new HashSet<>();
childSet.add(child);
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.LoggerFactory;
/**
- * This class contains utilities for managing bundles in a active platform.
+ * This class contains utilities for managing bundles in a active platform.
*
*/
@SuppressWarnings("restriction")
/**
* Get the manifest file of a bundle
*
- * @param bundle bundle
+ * @param bundle
+ * bundle
* @return manifest or <tt>null</tt> if doesn't not exist
- * @throws IOException
+ * @throws IOException
*/
public static Manifest getManifest(Bundle bundle) throws IOException {
URL url = bundle.getEntry("META-INF/MANIFEST.MF");
- if (url==null) return null;
+ if (url == null)
+ return null;
try (InputStream is = url.openStream()) {
return new Manifest(is);
}
/**
* Get the manifest file of a bundle
*
- * @param bundle bundle
+ * @param bundle
+ * bundle
* @return manifest or <tt>null</tt> if doesn't not exist
- * @throws IOException
+ * @throws IOException
*/
public static Manifest getSimanticsManifest(Bundle bundle) throws IOException {
URL url = bundle.getEntry("META-INF/SIMANTICS.MF");
- if (url==null) return null;
+ if (url == null)
+ return null;
try (InputStream is = url.openStream()) {
return new Manifest(is);
}
}
-
+
/**
- * Get a list (BundleIds) of all user installable units. These are the
- * top-level items that are visible for the end-user.
- * The list is acquired from the bundles of the current application.
+ * Get a list (BundleIds) of all user installable units. These are the top-level
+ * items that are visible for the end-user. The list is acquired from the
+ * bundles of the current application.
*
- * @param list of simantics features URIs
- * @throws IOException
+ * @param list
+ * of simantics features URIs
+ * @throws IOException
*/
- public static void getUserInstallableUnits(Collection<String> list)
- throws IOException
- {
+ public static void getUserInstallableUnits(Collection<String> list) throws IOException {
for (Bundle bundle : getBundles()) {
Manifest manifest = getSimanticsManifest(bundle);
- if (manifest==null) continue;
+ if (manifest == null)
+ continue;
Attributes attributes = manifest.getMainAttributes();
for (Entry<Object, Object> entry2 : attributes.entrySet()) {
Object key = entry2.getKey();
- if (key.toString().contains("Installable-Unit")) {
- String bid = entry2.getValue().toString();
- list.add( bid );
- }
+ if (key.toString().contains("Installable-Unit")) {
+ String bid = entry2.getValue().toString();
+ list.add(bid);
+ }
}
}
}
/**
* Get all transferable graphs in the platform
*
- * @param result collection to be filled with transferable graph info
+ * @param result
+ * collection to be filled with transferable graph info
*/
public static void getPlatformTGInfos(Collection<TGInfo> result) {
for (Bundle bundle : getBundles()) {
Enumeration<URL> e = bundle.findEntries("graphs/", "*.tg", false);
- if (e==null) continue;
+ if (e == null)
+ continue;
while (e.hasMoreElements()) {
org.osgi.framework.Version osgiVersion = bundle.getVersion();
- Version p2Version = Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor(), osgiVersion.getMicro(), osgiVersion.getQualifier());
+ Version p2Version = Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor(),
+ osgiVersion.getMicro(), osgiVersion.getQualifier());
String id = bundle.getSymbolicName();
TGInfo info = new TGInfo();
info.location = e.nextElement();
info.bundle = bundle;
info.vid = new VersionedId(id, p2Version);
- result.add( info );
+ result.add(info);
+ }
+ }
+ }
+
+ private static void uncheckedClose(Closeable closeable) {
+ try {
+ if (closeable != null)
+ closeable.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
+ private static File copyResource(URL url, File targetFile) throws IOException, FileNotFoundException {
+ FileOutputStream os = null;
+ InputStream is = null;
+ try {
+ if (targetFile.exists())
+ targetFile.delete();
+
+ is = url.openStream();
+ int read;
+ byte[] buffer = new byte[16384];
+ os = new FileOutputStream(targetFile);
+ while ((read = is.read(buffer)) != -1) {
+ os.write(buffer, 0, read);
}
+ os.close();
+ is.close();
+
+ return targetFile;
+ } finally {
+ uncheckedClose(os);
+ uncheckedClose(is);
}
}
- private static void uncheckedClose(Closeable closeable) {
- try {
- if (closeable != null)
- closeable.close();
- } catch (IOException e) {
- //ignore
- }
- }
-
- private static File copyResource(URL url, File targetFile) throws IOException, FileNotFoundException {
- FileOutputStream os = null;
- InputStream is = null;
- try {
- if (targetFile.exists())
- targetFile.delete();
-
- is = url.openStream();
- int read;
- byte [] buffer = new byte [16384];
- os = new FileOutputStream (targetFile);
- while ((read = is.read (buffer)) != -1) {
- os.write(buffer, 0, read);
- }
- os.close ();
- is.close ();
-
- return targetFile;
- } finally {
- uncheckedClose(os);
- uncheckedClose(is);
- }
- }
-
- private static File extractLib(URL libURL, String libName) throws FileNotFoundException, IOException {
- String tmpDirStr = System.getProperty("java.io.tmpdir");
- if (tmpDirStr == null)
- throw new NullPointerException("java.io.tmpdir property is null");
- File tmpDir = new File(tmpDirStr);
- File libFile = new File(tmpDir, libName);
- return copyResource(libURL, libFile);
- }
-
- private static File url2file(URL url, String fileName) {
+ private static File extractLib(URL libURL, String libName) throws FileNotFoundException, IOException {
+ String tmpDirStr = System.getProperty("java.io.tmpdir");
+ if (tmpDirStr == null)
+ throw new NullPointerException("java.io.tmpdir property is null");
+ File tmpDir = new File(tmpDirStr);
+ File libFile = new File(tmpDir, libName);
+ return copyResource(libURL, libFile);
+ }
+
+ private static File url2file(URL url, String fileName) {
if ("file".equals(url.getProtocol())) {
try {
File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
}
} else {
LOGGER.error("Unsupported URL protocol '" + url + "' for FastLZ native library file '" + fileName);
- }
+ }
return null;
}
+ public static Collection<URL> getTGFiles(Bundle b) {
+ Enumeration<URL> enu = b.findEntries("/", "*.tg", false);
+ if (enu == null)
+ return Collections.emptyList();
+ if (!enu.hasMoreElements())
+ return Collections.emptyList();
+ ArrayList<URL> result = new ArrayList<>();
+ while (enu.hasMoreElements()) {
+ result.add(enu.nextElement());
+ }
+ return result;
+ }
+
public static void compile(Bundle b) throws Exception {
Collection<ISource> sources = new ArrayList<>();
Collection<TransferableGraph1> dependencies = new ArrayList<>();
for (Bundle b2 : getBundles()) {
- if(b.equals(b2)) continue;
- URL url = b2.getEntry("graph.tg");
- if (url==null) continue;
- File graphFile = url2file(FileLocator.resolve(b2.getEntry("/graph.tg")), b2.toString());
- dependencies.add(GraphCompiler.read(graphFile));
+ if (b.equals(b2))
+ continue;
+ for (URL url : getTGFiles(b2)) {
+ File graphFile = url2file(url, b2.toString() + url.toString());
+ dependencies.add(GraphCompiler.read(graphFile));
+ }
}
File bundleFile = FileLocator.getBundleFile(b);
- if(bundleFile.isDirectory()) {
+ if (bundleFile.isDirectory()) {
File folder = new File(bundleFile, "dynamicGraph");
- for(File f : folder.listFiles(new FilenameFilter() {
+ for (File f : folder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
}
}
-// System.out.println("source is " + tmpFile.getAbsolutePath());
+ // System.out.println("source is " + tmpFile.getAbsolutePath());
final StringBuilder errorStringBuilder = new StringBuilder();
GraphCompilerPreferences prefs = new GraphCompilerPreferences();
prefs.validate = true;
prefs.validateRelationRestrictions = ValidationMode.ERROR;
prefs.validateResourceHasType = ValidationMode.ERROR;
- String currentLayer0Version = OntologyVersions.getInstance().currentOntologyVersion("http://www.simantics.org/Layer0-0.0");
+ String currentLayer0Version = OntologyVersions.getInstance()
+ .currentOntologyVersion("http://www.simantics.org/Layer0-0.0");
CompilationResult result = GraphCompiler.compile(currentLayer0Version, sources, dependencies, null, prefs);
- for(Problem problem : result.getErrors())
+ for (Problem problem : result.getErrors())
errorStringBuilder.append(problem.getLocation() + ": " + problem.getDescription() + "\n");
- for(Problem problem : result.getWarnings())
+ for (Problem problem : result.getWarnings())
errorStringBuilder.append(problem.getLocation() + ": " + problem.getDescription() + "\n");
- if(errorStringBuilder.length() > 0) {
+ if (errorStringBuilder.length() > 0) {
LOGGER.error(errorStringBuilder.toString());
} else {
GraphCompiler.write(new File(bundleFile, "graph.tg"), result.getGraph());
*/
public static void compileAllDynamicOntologies() {
for (Bundle bundle : getBundles()) {
- if(bundle.getEntry("dynamicGraph") != null) {
+ if (bundle.getEntry("dynamicGraph") != null) {
try {
File bundleFile = FileLocator.getBundleFile(bundle);
- if(bundleFile.isDirectory()) {
+ if (bundleFile.isDirectory()) {
File tg = new File(bundleFile, "graph.tg");
long tgLastModified = tg.lastModified();
File folder = new File(bundleFile, "dynamicGraph");
- for(File f : folder.listFiles()) {
- if(f.isFile() && f.getName().endsWith(".pgraph") && f.lastModified() > tgLastModified) {
+ for (File f : folder.listFiles()) {
+ if (f.isFile() && f.getName().endsWith(".pgraph") && f.lastModified() > tgLastModified) {
compile(bundle);
break;
}
public static Collection<GraphBundle> getAllGraphs() throws IOException {
AtomicReference<IOException> problem = new AtomicReference<>();
+ // Collection<GraphBundle> gbundles = Arrays.stream(getBundles())
+ // // #7806: Due to databoard Binding/Serializer construction process
+ // thread-unsafety
+ // // not even the DataContainer.readHeader invocations can run in parallel,
+ // most likely
+ // // due to recurring serializer construction for Variant datatypes.
+ // // Therefore, we must disable parallel loading for now.
+ // //.parallel()
+ // .map(b -> {
+ // try {
+ // return problem.get() == null ? getGraph(b) : null;
+ // } catch (IOException e) {
+ // if (LOGGER.isDebugEnabled())
+ // LOGGER.debug("Could not get graph from bundle {}", b, e);
+ // problem.set(e);
+ // return null;
+ // }
+ // })
+ // .filter(Objects::nonNull)
+ // .collect(Collectors.toList());
+
Collection<GraphBundle> gbundles = Arrays.stream(getBundles())
- // #7806: Due to databoard Binding/Serializer construction process thread-unsafety
- // not even the DataContainer.readHeader invocations can run in parallel, most likely
+ // #7806: Due to databoard Binding/Serializer construction process
+ // thread-unsafety
+ // not even the DataContainer.readHeader invocations can run in parallel, most
+ // likely
// due to recurring serializer construction for Variant datatypes.
// Therefore, we must disable parallel loading for now.
- //.parallel()
+ // .parallel()
.map(b -> {
try {
- return problem.get() == null ? getGraph(b) : null;
+ return problem.get() == null ? getGraphs(b) : null;
} catch (IOException e) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Could not get graph from bundle {}", b, e);
problem.set(e);
return null;
}
- })
- .filter(Objects::nonNull)
- .collect(Collectors.toList());
+ }).flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList());
if (problem.get() != null)
throw problem.get();
}
/**
- * Get bundle
+ * Get bundle
*
* @param symbolicName
- * @return bundle or <tt>null</tt> if there is no bundle or graph
+ * @return bundle or <tt>null</tt> if there is no bundle or graph
* @throws IOException
*/
public static GraphBundle getGraph(String symbolicName) throws IOException {
Bundle bundle = Platform.getBundle(symbolicName);
- if (bundle == null) return null;
- return getGraph( bundle );
+ if (bundle == null)
+ return null;
+ return getGraph(bundle);
}
/**
- * Read the graph in a graph bundle. Graph is read from "graph.tg" file in the root.
+ * Read the graph in a graph bundle. Graph is read from "graph.tg" file in the
+ * root.
*
* @param bundle
- * @return transferable graph, or <tt>null</tt> if there is no graph in the bundle.
- * @throws IOException
+ * @return transferable graph, or <tt>null</tt> if there is no graph in the
+ * bundle.
+ * @throws IOException
*/
public static GraphBundleEx getGraph(Bundle bundle) throws IOException {
URL url = bundle.getEntry("graph.tg");
return result != null ? result : getCompleteGraph(bundle, url);
}
+ public static Collection<GraphBundleEx> getGraphs(Bundle bundle) throws IOException {
+ return getTGFiles(bundle).stream().map(url -> {
+ try {
+ GraphBundleEx result = tryGetOnDemandGraph(bundle, url);
+ return result != null ? result : getCompleteGraph(bundle, url);
+ } catch (IOException e) {
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("Could not get graph from bundle url {}", url, e);
+ return null;
+ }
+ }).filter(Objects::nonNull).collect(Collectors.toList());
+ }
+
private static GraphBundleEx getCompleteGraph(Bundle bundle, URL url) throws IOException {
try {
- String id = bundle.getSymbolicName();
- return new GraphBundleEx(
- getBundleName(bundle, id),
- readTG(url),
- new VersionedId(id, toP2Version(bundle)),
+ String id = tgFileId(bundle, url);
+ System.err.println("getCompleteGraph " + id);
+ return new GraphBundleEx(getBundleName(bundle, id), readTG(url), new VersionedId(id, toP2Version(bundle)),
isImmutable(bundle));
} catch (Exception e) {
throw new IOException("Problem loading graph.tg from bundle " + bundle.getSymbolicName(), e);
throw e;
}
}
+
+ private static String tgFileId(Bundle bundle, URL url) {
+ String urlString = url.toString();
+ String file = urlString.substring(urlString.lastIndexOf("/")+1);
+ return bundle.getSymbolicName() + "_" + file;
+ }
/**
- * Read the graph in a graph bundle. Graph is read from "graph.tg" file in the root.
+ * Read the graph in a graph bundle. Graph is read from "graph.tg" file in the
+ * root.
*
* @param bundle
- * @return transferable graph, or <tt>null</tt> if there is no graph in the bundle.
- * @throws IOException
+ * @return transferable graph, or <tt>null</tt> if there is no graph in the
+ * bundle.
+ * @throws IOException
*/
private static GraphBundleEx tryGetOnDemandGraph(Bundle bundle, URL url) throws IOException {
try {
}
};
- String id = bundle.getSymbolicName();
+ String id = tgFileId(bundle, url);
+
+ System.err.println("tryGetOnDemandGraph: " + id);
- return new GraphBundleEx(
- getBundleName(bundle, id),
- graphSource,
- cachedHash,
- new VersionedId(id, toP2Version(bundle)),
- isImmutable(bundle));
+ return new GraphBundleEx(getBundleName(bundle, id), graphSource, cachedHash,
+ new VersionedId(id, toP2Version(bundle)), isImmutable(bundle));
} catch (Exception e) {
throw new IOException("Problem loading graph.tg from bundle " + bundle.getSymbolicName(), e);
}
private static Version toP2Version(Bundle bundle) {
org.osgi.framework.Version osgiVersion = bundle.getVersion();
- return Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor(), osgiVersion.getMicro(), osgiVersion.getQualifier());
+ return Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor(), osgiVersion.getMicro(),
+ osgiVersion.getQualifier());
}
private static String getBundleName(Bundle bundle, String id) {
*/
public final class DebugPolicy {
- public static final boolean DEBUG = false;
+ public static final boolean DEBUG = true;
}
TabContribution<?> contribution = graph.adapt(r, TabContribution.class);
contributions.add(contribution);
if(DebugPolicy.DEBUG) LOGGER.debug("-contribution " + graph.getURI(r));
+ System.err.println("-contribution " + graph.getURI(r));
}
ArrayList<Resource> transforms = new ArrayList<>();
transforms.addAll(transformationFinder.find(graph, index));
if(DebugPolicy.DEBUG) {
- for(Resource r : transforms)
+ for(Resource r : transforms) {
LOGGER.debug("-transform " + NameUtils.getSafeLabel(graph, r));
+ System.err.println("-transform " + NameUtils.getSafeLabel(graph, r));
+ }
}
HashSet<Object> inputs = new HashSet<>();
}
if(DebugPolicy.DEBUG) {
- for(Object o : inputs)
+ for(Object o : inputs) {
LOGGER.debug("-input " + inputName(graph, o));
+ System.err.println("-input " + inputName(graph, o));
+ }
}
Set<ComparableTabContributor> result = new HashSet<>();
if(DebugPolicy.DEBUG) {
LOGGER.debug("result: " + result);
+ System.err.println("result: " + result);
}
return result;
Collection<Resource> ts = graph.getTypes(resource);
+ for(Resource r : ts)
+ System.err.println("ts: " + graph.getURI(r));
+ for(Resource r : types)
+ System.err.println("types: " + graph.getURI(r));
+
if (!Collections.disjoint(types, ts)) {
for(Resource r : graph.getObjects(configuration, SEL.VariableTabContribution_HasTest)) {
STR.DefinedComponentType <T STR.AbstractDefinedComponentType
+STR.ReplaceableDefinedComponentType <T STR.AbstractDefinedComponentType
+
STR.ProceduralComponentType <T STR.AbstractDefinedComponentType
>-- STR.ProceduralComponentType.code --> STR.ProceduralComponentTypeCode <R L0.HasProperty : L0.TotalFunction
>-- STR.ProceduralComponentType.environment --> L0.SCLValue.Environment <R L0.IsRelatedTo : L0.FunctionalRelation
STR.ProceduralComponentTypeCode <T L0.String
+
//STR.proceduralConnectionPointPath --> L0.String <R L0.HasProperty : L0.FunctionalRelation
/*
@L0.assert L0.domainChildren
STR.Functions.structuralChildDomainChildren : L0.ExternalValue
L0.HasValueType "VariableMap"
+ @L0.sclAssertion L0.typeResource "structuralTypeResource" "Variable -> Resource -> <ReadGraph> Resource"
STR.Run
@L0.assert L0.domainChildren
STR.UserDefinedProperty <T L0.Entity
+STR.TypeOverride <T L0.Entity
+ >-- STR.TypeOverride.HasOriginalType --> STR.ComponentType <R L0.IsRelatedTo : L0.TotalFunction
+ >-- STR.TypeOverride.HasReplacementType --> STR.ComponentType <R L0.IsRelatedTo : L0.TotalFunction
+STR.HasTypeOverride --> STR.TypeOverride <R L0.IsRelatedTo
+
+
STR.ComponentType
// This relation is inherited from L0.IsComposedOf because changes in the code
// need to be propagated to the component type
importJava "org.simantics.structural2.utils.StructuralUtils" where
structuralConnectionConnectionPoints :: Variable -> StructuralConnection -> Resource -> <ReadGraph> [Variable]
+ structuralTypeResource :: Variable -> Resource -> <ReadGraph> Resource
\ No newline at end of file
@Override
public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException {
+ System.err.println("getConnectionPointDescriptors " + component.getURI(graph));
return ConnectionBrowser.flatten(graph, component, predicate, relationType);
}
--- /dev/null
+package org.simantics.structural2;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.Functions.InterfaceResolution;
+
+public class DefinedUCInterfaceMap extends ResourceRead<Collection<InterfaceResolution>> {
+
+ public DefinedUCInterfaceMap(Resource resource) {
+ super(resource);
+ }
+
+ @Override
+ public Collection<InterfaceResolution> perform(ReadGraph graph)
+ throws DatabaseException {
+
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource definition = graph.getPossibleObject(resource, STR.IsDefinedBy);
+ if(definition != null) {
+ Collection<InterfaceResolution> result = new ArrayList<InterfaceResolution>();
+ Layer0 L0 = Layer0.getInstance(graph);
+ for(Resource cp : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, STR.ConnectionRelation))) {
+ String cpName = graph.getRelatedValue(cp, L0.HasName, Bindings.STRING);
+ for(Resource conn : graph.getObjects(cp, STR.IsBoundBy)) {
+ Statement stm = graph.getPossibleStatement(conn, STR.Connects);
+ if(stm == null) continue;
+ Resource component = stm.getObject();
+ String componentName = graph.getRelatedValue(component, L0.HasName, Bindings.STRING);
+ result.add(new InterfaceResolution(cp, cpName, componentName, graph.getInverse(stm.getPredicate())));
+ }
+ }
+ return result;
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.request.ObjectsWithType;
import org.simantics.db.common.request.PossibleIndexRoot;
+import org.simantics.db.common.request.PossibleObjectWithType;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.common.uri.UnescapedChildMapOfResource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.variable.VariableMap;
import org.simantics.db.layer0.variable.VariableMapImpl;
import org.simantics.db.layer0.variable.VariableNode;
+import org.simantics.db.service.CollectionSupport;
import org.simantics.issues.common.IssueUtils;
import org.simantics.layer0.Layer0;
import org.simantics.scl.reflection.annotations.SCLValue;
import org.simantics.structural2.queries.PossibleConnectionPointInfo;
import org.simantics.structural2.scl.CompileStructuralValueRequest;
import org.simantics.structural2.scl.procedural.CompileProceduralComponentTypeRequest;
+import org.simantics.structural2.utils.StructuralUtils;
+import org.simantics.structural2.utils.StructuralUtils.StructuralComponentClass;
import org.simantics.structural2.variables.Connection;
import org.simantics.structural2.variables.StandardProceduralChildVariable;
import org.simantics.utils.datastructures.MapList;
+import org.simantics.utils.datastructures.Pair;
import gnu.trove.map.hash.THashMap;
};
- public static class StructuralChildMapOfResource extends ResourceRead<Map<String, Resource>> {
+ /*public static class StructuralChildMapOfResource extends ResourceRead<Map<String, Resource>> {
public StructuralChildMapOfResource(Resource resource) {
super(resource);
return directChildren;
}
- }
+ }*/
- public static class StructuralChildMapOfResourceT extends ResourceRead<Map<String, Resource>> {
+ /*public static class StructuralChildMapOfResourceT extends ResourceRead<Map<String, Resource>> {
- public StructuralChildMapOfResourceT(Resource resource) {
- super(resource);
+ public StructuralChildMapOfResourceT(Resource type) {
+ super(type);
}
@Override
return Collections.emptyMap();
}
- }
+ }*/
- static class StructuralRunChildMapOfResource extends ResourceRead<Map<String, Resource>> {
+ /*static class StructuralRunChildMapOfResource extends ResourceRead<Map<String, Resource>> {
public StructuralRunChildMapOfResource(Resource resource) {
super(resource);
}
+ }*/
+
+ static class StructuralRunContext extends ResourceRead<Resource> {
+
+ public StructuralRunContext(Resource resource) {
+ super(resource);
+ }
+
+ @Override
+ public Resource perform(ReadGraph graph) throws DatabaseException {
+
+ Layer0 L0 = Layer0.getInstance(graph);
+ SimulationResource SIMU = SimulationResource.getInstance(graph);
+ Resource model = graph.sync(new PossibleIndexRoot(resource));
+ if(graph.isInstanceOf(model, L0.RVIContext)) {
+ return model;
+ }
+ Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration);
+ if(configuration != null) {
+ if(graph.isInstanceOf(configuration, L0.RVIContext)) {
+ return configuration;
+ }
+ }
+
+ return null;
+
+ }
+
}
private static class SubstructureRequest extends VariableRead<List<SubstructureElement>> {
}
}
+ public static class StructuralTypeOverrideMap extends ResourceRead<Map<Resource,Resource>> {
+
+ protected StructuralTypeOverrideMap(Resource composite) {
+ super(composite);
+ }
+
+ @Override
+ public Map<Resource, Resource> perform(ReadGraph graph) throws DatabaseException {
+
+ Layer0 L0 = Layer0.getInstance(graph);
+
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+
+ CollectionSupport cs = graph.getService(CollectionSupport.class);
+
+ Map<Resource,Resource> result = null;
+
+ for(Resource override : graph.getObjects(resource, STR.HasTypeOverride)) {
+ Resource original = graph.getSingleObject(override, STR.TypeOverride_HasOriginalType);
+ Resource replacement = graph.getSingleObject(override, STR.TypeOverride_HasReplacementType);
+ if(result == null) result = cs.createMap(Resource.class);
+ result.put(original, replacement);
+ }
+
+ if(result == null) return Collections.emptyMap();
+
+ return result;
+
+ }
+
+ }
+
+ public static class StructuralOverrideData {
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((actualRepresents == null) ? 0 : actualRepresents.hashCode());
+ result = prime * result + ((actualType == null) ? 0 : actualType.hashCode());
+ result = prime * result + ((overrideType == null) ? 0 : overrideType.hashCode());
+ return result;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ StructuralOverrideData other = (StructuralOverrideData) obj;
+ if (actualRepresents == null) {
+ if (other.actualRepresents != null)
+ return false;
+ } else if (!actualRepresents.equals(other.actualRepresents))
+ return false;
+ if (actualType == null) {
+ if (other.actualType != null)
+ return false;
+ } else if (!actualType.equals(other.actualType))
+ return false;
+ if (overrideType == null) {
+ if (other.overrideType != null)
+ return false;
+ } else if (!overrideType.equals(other.overrideType))
+ return false;
+ return true;
+ }
+ Resource actualRepresents;
+ Resource actualType;
+ Resource overrideType;
+ public StructuralOverrideData(Resource actualRepresents, Resource actualType, Resource overrideType) {
+ this.actualRepresents = actualRepresents;
+ this.actualType = actualType;
+ this.overrideType = overrideType;
+ }
+
+ public static StructuralOverrideData compute(ReadGraph graph, Variable context) throws DatabaseException {
+ return graph.syncRequest(new StructuralOverrideDataRequest(context));
+ }
+
+ public Resource type() {
+ if(overrideType != null)
+ return overrideType;
+ return actualType;
+ }
+
+ public Resource represents() {
+ return actualRepresents;
+ }
+
+ }
+
+ public static class StructuralOverrideDataRequest extends VariableRead<StructuralOverrideData> {
+
+ public StructuralOverrideDataRequest(Variable component) {
+ super(component);
+ }
+
+ public StructuralOverrideData walk(ReadGraph graph, Variable component, Resource actualRepresents, Resource actualType) throws DatabaseException {
+ System.err.println("walk: " + component.getURI(graph));
+ Resource represents = component.getPossibleRepresents(graph);
+ if(represents != null) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource container = graph.syncRequest(new PossibleObjectWithType(represents, L0.PartOf, STR.Composite));
+ if(container != null) {
+ Map<Resource,Resource> overrides = graph.syncRequest(new StructuralTypeOverrideMap(container));
+ if(!overrides.isEmpty()) {
+ System.err.println("Check overrides for " + graph.getPossibleURI(actualType));
+ for(Resource r : overrides.keySet()) {
+ System.err.println("-available OR: " + graph.getPossibleURI(r) + " = > " + graph.getPossibleURI(overrides.get(r)));
+ }
+ }
+ Resource override = overrides.get(actualType);
+ if(override != null) {
+ System.err.println("Override! " + graph.getPossibleURI(actualType) + " = > " + graph.getPossibleURI(override));
+ return new StructuralOverrideData(actualRepresents, actualType, override);
+ }
+ }
+ }
+ Variable parent = component.getParent(graph);
+ if(parent == null) return new StructuralOverrideData(actualRepresents, actualType, null);
+ else return walk(graph, parent, represents, actualType);
+ }
+
+ @Override
+ public StructuralOverrideData perform(ReadGraph graph) throws DatabaseException {
+
+ if(variable.getURI(graph).endsWith("/Alternative/Panel2"))
+ System.err.println("walk1: " + variable.getURI(graph));
+
+ Resource represents = variable.getPossibleRepresents(graph);
+ if(represents == null) {
+ String uri = variable.getPossiblePropertyValue(graph, "typeURI");
+ if(uri != null) {
+ Resource actualType = graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.<Resource>instance());
+ return walk(graph, variable, null, actualType);
+ }
+ throw new DatabaseException("No type for " + variable.getURI(graph));
+ } else {
+ return walk(graph, variable, represents, graph.getPossibleType(represents, Layer0.getInstance(graph).Entity));
+ }
+
+ }
+
+ }
+
@SCLValue(type = "VariableMap")
public static VariableMap structuralChildDomainChildren = new VariableMapImpl() {
+// private Variable childWithTypeOverrides(ReadGraph graph, Variable parent, Resource child, String name) throws DatabaseException {
+// return All.getStandardChildDomainChildVariable(graph, parent, child, name);
+// }
+//
+// private Map<String, Variable> childrenWithTypeOverrides(ReadGraph graph, Variable parent, Map<String, Resource> children, Map<String, Variable> map) throws DatabaseException {
+// return StandardChildDomainChildren.getStandardChildDomainChildVariables(graph, parent, children, map);
+// }
+
@Override
public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {
+
+ System.err.println("foobar1: " + context.getURI(graph));
- final Resource type = context.getPossibleType(graph);
- if(type != null) {
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
- if(graph.isInstanceOf(type, STR.ProceduralComponentType)) {
- Map<String,Variable> map = graph.syncRequest(new ProceduralSubstructureRequest(context),
- TransientCacheListener.<Map<String,Variable>>instance());
- if(map != null) return map.get(name);
- }
- }
-
- Resource represents = context.getPossibleRepresents(graph);
- if(represents == null) {
- Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResourceT(type));
+ Resource type = context.getPossibleType(graph);
+ if(type == null) return null;
+
+ StructuralComponentClass clazz = StructuralComponentClass.get(graph, type);
+ if(StructuralComponentClass.PROCEDURAL.equals(clazz)) {
+ Map<String,Variable> map = graph.syncRequest(new ProceduralSubstructureRequest(context),
+ TransientCacheListener.<Map<String,Variable>>instance());
+ if(map != null) return map.get(name);
+ return null;
+ } else if (StructuralComponentClass.DEFINED.equals(clazz)) {
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource def = graph.getSingleObject(type, STR.IsDefinedBy);
+ Map<String, Resource> children = graph.getChildren(def);
Resource child = children.get(name);
- return All.getStandardChildDomainChildVariable(graph, context, child, name);
- }
- Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResource(represents));
- Resource child = children.get(name);
- return All.getStandardChildDomainChildVariable(graph, context, child, name);
+ if(child == null) return null;
+ return StandardChildDomainChildren.getStandardChildDomainChildVariable(graph, context, child, name);
+ } else {
+ Resource represents = context.getPossibleRepresents(graph);
+ if(represents == null) return null;
+ Map<String, Resource> children = graph.getChildren(represents);
+ Resource child = children.get(name);
+ if(child == null) return null;
+ return StandardChildDomainChildren.getStandardChildDomainChildVariable(graph, context, child, name);
+ }
+
+// StructuralOverrideData od = StructuralOverrideData.compute(graph, context);
+// if(od.type() != null) {
+// StructuralResource2 STR = StructuralResource2.getInstance(graph);
+// if(graph.isInstanceOf(od.type(), STR.ProceduralComponentType)) {
+// Map<String,Variable> map = graph.syncRequest(new ProceduralSubstructureRequest(context),
+// TransientCacheListener.<Map<String,Variable>>instance());
+// if(map != null) return map.get(name);
+// }
+// }
+//
+// Resource type = context.getPossibleType(graph, baseType);
+//
+// Resource represents = od.represents();
+// if(represents == null) {
+// Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResourceT(od.type()));
+// Resource child = children.get(name);
+// return childWithTypeOverrides(graph, context, child, name);
+// }
+// Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResource(represents));
+// Resource child = children.get(name);
+// return childWithTypeOverrides(graph, context, child, name);
+
}
@Override
public Map<String, Variable> getVariables(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {
- final Resource type = context.getPossibleType(graph);
- if(type != null) {
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
- if(graph.isInstanceOf(type, STR.ProceduralComponentType)) {
- Map<String,Variable> mapPrime = graph.syncRequest(new ProceduralSubstructureRequest(context),
- TransientCacheListener.<Map<String,Variable>>instance());
- if(mapPrime != null) {
- if(map != null) {
- map.putAll(mapPrime);
- return map;
- }
- else
- return mapPrime;
- }
- }
- }
- Resource represents = context.getPossibleRepresents(graph);
- if(represents == null) {
- Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResourceT(type));
+ System.err.println("foobar2: " + context.getURI(graph));
+
+ Resource type = context.getPossibleType(graph);
+ if(type == null) return null;
+
+ StructuralComponentClass clazz = StructuralComponentClass.get(graph, type);
+ if(StructuralComponentClass.PROCEDURAL.equals(clazz)) {
+ Map<String,Variable> mapPrime = graph.syncRequest(new ProceduralSubstructureRequest(context),
+ TransientCacheListener.<Map<String,Variable>>instance());
+ if(mapPrime != null) {
+ if(map != null) {
+ map.putAll(mapPrime);
+ return map;
+ }
+ else
+ return mapPrime;
+ }
+ return map;
+ } else if (StructuralComponentClass.DEFINED.equals(clazz)) {
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource def = graph.getSingleObject(type, STR.IsDefinedBy);
+ Map<String, Resource> children = graph.getChildren(def);
return StandardChildDomainChildren.getStandardChildDomainChildVariables(graph, context, children, map);
- }
- Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResource(represents));
- return StandardChildDomainChildren.getStandardChildDomainChildVariables(graph, context, children, map);
+ } else {
+ Resource represents = context.getPossibleRepresents(graph);
+ if(represents == null) return null;
+ Map<String, Resource> children = graph.getChildren(represents);
+ return StandardChildDomainChildren.getStandardChildDomainChildVariables(graph, context, children, map);
+ }
+
+
+// StructuralOverrideData od = StructuralOverrideData.compute(graph, context);
+// if(od.type() != null) {
+// StructuralResource2 STR = StructuralResource2.getInstance(graph);
+// if(graph.isInstanceOf(od.type(), STR.ProceduralComponentType)) {
+// Map<String,Variable> mapPrime = graph.syncRequest(new ProceduralSubstructureRequest(context),
+// TransientCacheListener.<Map<String,Variable>>instance());
+// if(mapPrime != null) {
+// if(map != null) {
+// map.putAll(mapPrime);
+// return map;
+// }
+// else
+// return mapPrime;
+// }
+// }
+// }
+//
+// Resource represents = od.represents();
+// if(represents == null) {
+// Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResourceT(od.type()));
+// return childrenWithTypeOverrides(graph, context, children, map);
+// }
+// Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResource(represents));
+// return childrenWithTypeOverrides(graph, context, children, map);
+
}
};
@Override
public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {
- Map<String, Resource> children = graph.syncRequest(new StructuralRunChildMapOfResource(context.getRepresents(graph)));
+ Resource ctx = graph.syncRequest(new StructuralRunContext(context.getRepresents(graph)));
+ if(ctx == null) return null;
+ Map<String, Resource> children = graph.getChildren(ctx);
Resource child = children.get(name);
return StandardChildDomainChildren.getStandardChildDomainChildVariable(graph, context, child, name);
}
@Override
public Map<String, Variable> getVariables(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {
- StandardGraphChildVariable variable = (StandardGraphChildVariable)context;
- Map<String,Resource> children = graph.syncRequest(new StructuralRunChildMapOfResource(variable.resource));
+ Resource ctx = graph.syncRequest(new StructuralRunContext(context.getRepresents(graph)));
+ if(ctx == null) return map;
+ Map<String, Resource> children = graph.getChildren(ctx);
return StandardChildDomainChildren.getStandardChildDomainChildVariables(graph, context, children, map);
}
}
- static class DefinedUCInterfaceMap extends ResourceRead<Collection<InterfaceResolution>> {
-
- public DefinedUCInterfaceMap(Resource resource) {
- super(resource);
- }
-
- @Override
- public Collection<InterfaceResolution> perform(ReadGraph graph)
- throws DatabaseException {
-
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
- Resource definition = graph.getPossibleObject(resource, STR.IsDefinedBy);
- if(definition != null) {
- Collection<InterfaceResolution> result = new ArrayList<InterfaceResolution>();
- Layer0 L0 = Layer0.getInstance(graph);
- for(Resource cp : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, STR.ConnectionRelation))) {
- String cpName = graph.getRelatedValue(cp, L0.HasName, Bindings.STRING);
- for(Resource conn : graph.getObjects(cp, STR.IsBoundBy)) {
- Statement stm = graph.getPossibleStatement(conn, STR.Connects);
- if(stm == null) continue;
- Resource component = stm.getObject();
- String componentName = graph.getRelatedValue(component, L0.HasName, Bindings.STRING);
- result.add(new InterfaceResolution(cp, cpName, componentName, graph.getInverse(stm.getPredicate())));
- }
- }
- return result;
- }
- return null;
- }
-
- }
-
public static final Collection<InterfaceResolution> BUILTIN_STRUCTURAL_CPS = new ArrayList<InterfaceResolution>();
@SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
import org.simantics.db.Statement;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.common.request.ObjectsWithType;
import org.simantics.db.common.request.PossibleTypedParent;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.layer0.Layer0;
import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.Functions.StructuralOverrideData;
import org.simantics.structural2.internal.queries.ConnectedTo;
import org.simantics.structural2.internal.queries.RelatedConnections;
import org.simantics.structural2.internal.queries.RelatedConnectionsOfConnectionJoin;
*/
public class StructuralUtils {
+ public static enum StructuralComponentClass {
+
+ PRIMITIVE,REPLACEABLE,DEFINED,PROCEDURAL;
+
+ public static StructuralComponentClass get(ReadGraph graph, Resource componentType) throws DatabaseException {
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ if(graph.isInstanceOf(componentType, STR.ProceduralComponentType))
+ return StructuralComponentClass.PROCEDURAL;
+ else if(graph.hasStatement(componentType, STR.IsDefinedBy))
+ return StructuralComponentClass.DEFINED;
+ else if(graph.isInstanceOf(componentType, STR.ReplaceableDefinedComponentType))
+ return StructuralComponentClass.REPLACEABLE;
+ else
+ return StructuralComponentClass.PRIMITIVE;
+ }
+
+ }
+
public static Collection<Resource> getConnectionRelations(ReadGraph graph, Resource componentType) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
StructuralResource2 STR = StructuralResource2.getInstance(graph);
* Returns the component type of the given component or null if the
* parameter is not a component.
*/
+ @Deprecated
public static Resource getComponentType(ReadGraph g, Resource component) throws DatabaseException {
StructuralResource2 STR = StructuralResource2.getInstance(g);
return g.getPossibleType(component, STR.Component);
public static List<Variable> structuralConnectionConnectionPoints(ReadGraph graph, Variable component, Connection conn, Resource relationType) throws DatabaseException {
return new ArrayList<Variable>(conn.getConnectionPoints(graph, component, relationType));
}
+
+ public static Resource structuralTypeResource(ReadGraph graph, Variable component, Resource baseType) throws DatabaseException {
+
+ if(component.getURI(graph).endsWith("/Alternative/Alternative/Panel2"))
+ System.err.println("structuralTypeResource " + component.getURI(graph));
+
+ StructuralOverrideData od = StructuralOverrideData.compute(graph, component);
+ return od.type();
+
+// Resource represents = component.getPossibleRepresents(graph);
+// if(represents == null) {
+// String uri = component.getPossiblePropertyValue(graph, "typeURI");
+// if(uri != null) return graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.<Resource>instance());
+// throw new DatabaseException("No type for " + component.getURI(graph));
+// }
+// return graph.getPossibleType(represents, baseType);
+//
+// Pair<Resource,Resource> representsAndType = graph.syncRequest(new PossibleRepresentsAndTypeWithOverrides(component));
+// return representsAndType.second;
+
+ }
+
+ public static Resource getComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException {
+
+ Variable componentVariable = configuration.browse(graph, component);
+ return componentVariable.getType(graph);
+
+ }
+
+
}
@Override
public Collection<InterfaceResolution> perform(ReadGraph graph) throws DatabaseException {
- return Functions.computeInterfacePaths(graph, parameter.getVariable(graph).getParent(graph));
+ Variable var = parameter.getVariable(graph);
+ System.err.println("ComputeInterfaceDescription " + var.getURI(graph));
+ Collection<InterfaceResolution> res = Functions.computeInterfacePaths(graph, var.getParent(graph));
+ for(InterfaceResolution r : res)
+ System.err.println("-res " + r);
+ return res;
}
}
import org.simantics.layer0.Layer0;
import org.simantics.modeling.ModelingResources;
import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.DefinedUCInterfaceMap;
import org.simantics.structural2.Functions;
import org.simantics.structural2.Functions.InterfaceResolution;
+import org.simantics.structural2.utils.StructuralUtils.StructuralComponentClass;
import org.simantics.structural2.variables.ConnectionBrowser.IsLeafType;
/*
- * This connection descriptor variable
+ * This connection descriptor
+ *
* -has not been lifted into interface
* -has a structural configuration defined as resources
- * -has not been drilled
+ * -might not be drilled
+ *
+ * Note: these are constructed after climb (before drill) phase of the connection browser. This means that
+ * the component can still contain sub structure during connection browsing. This means that some descriptors
+ * are not final and are replaced by correct descriptors during drill phase.
+ *
*/
class ActualConnectionDescriptor extends AbstractVariableConnectionPointDescriptor {
- final private Variable root;
- final private Resource component;
- final private Resource cp;
+ /*
+ * This is the nearest known ancestor variable
+ */
+ final Variable root;
+ /*
+ * A component on variable path under the root variable.
+ */
+ final Resource component;
+ /*
+ * TODO
+ */
+ final Resource componentType;
+ /*
+ * The connection point that has type of the component as its domain
+ */
+ final Resource cp;
- public ActualConnectionDescriptor(Variable root, Resource component, Resource cp) {
+ public ActualConnectionDescriptor(Variable root, Resource component, Resource componentType, Resource cp) {
this.root = root;
this.component = component;
+ this.componentType = componentType;
this.cp = cp;
}
- static class ComputeInterfaceDescription extends UnaryRead<ActualConnectionDescriptor, Collection<InterfaceResolution>> {
+ static class ActualConnectionDescriptorInterfaceDescription extends UnaryRead<ActualConnectionDescriptor, Collection<InterfaceResolution>> {
- public ComputeInterfaceDescription(ActualConnectionDescriptor desc) {
+ public ActualConnectionDescriptorInterfaceDescription(ActualConnectionDescriptor desc) {
super(desc);
}
@Override
public Collection<InterfaceResolution> perform(ReadGraph graph) throws DatabaseException {
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
- Resource type = graph.getPossibleType(parameter.component, STR.Component);
- if(graph.syncRequest(new IsLeafType(type))) return null;
-
- return Functions.computeInterfacePaths(graph, parameter.getVariable(graph).getParent(graph));
+ System.err.println("ActualConnectionDescriptorInterfaceDescription");
+
+ ConnectionBrowser.reportDescriptor(graph, parameter);
+
+ /*
+ * The componentType is the possibly replaced (STR.ReplaceableDefinedComponentType) type
+ */
+ StructuralComponentClass clazz = StructuralComponentClass.get(graph, parameter.componentType);
+ if(StructuralComponentClass.PRIMITIVE.equals(clazz)) {
+ return null;
+ } else if(StructuralComponentClass.DEFINED.equals(clazz)) {
+ final Collection<InterfaceResolution> interfaces = graph.syncRequest(new DefinedUCInterfaceMap(parameter.componentType));
+ if(interfaces != null) return interfaces;
+ else return Functions.BUILTIN_STRUCTURAL_CPS;
+ } else if(StructuralComponentClass.REPLACEABLE.equals(clazz)) {
+ throw new DatabaseException("ConnectionBrowser does not support nested replaceable defined structural types.");
+ } else {
+ return Functions.computeInterfacePaths(graph, parameter.getVariable(graph).getParent(graph));
+ }
}
}
+ @Override
+ public boolean isLeaf(ReadGraph graph) throws DatabaseException {
+
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource type = graph.getPossibleType(component, STR.Component);
+ return graph.syncRequest(new IsLeafType(type));
+
+ }
+
@Override
public Collection<InterfaceResolution> getInterfaceDescription(ReadGraph graph) throws DatabaseException {
- return graph.syncRequest(new ComputeInterfaceDescription(this), TransientCacheAsyncListener.<Collection<InterfaceResolution>>instance());
+ return graph.syncRequest(new ActualConnectionDescriptorInterfaceDescription(this), TransientCacheAsyncListener.<Collection<InterfaceResolution>>instance());
}
public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException {
package org.simantics.structural2.variables;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.simantics.structural2.Functions;
import org.simantics.structural2.Functions.InterfaceResolution;
import org.simantics.structural2.queries.ConnectionSet;
+import org.simantics.structural2.utils.StructuralUtils;
+import org.simantics.structural2.utils.StructuralUtils.StructuralComponentClass;
import org.simantics.structural2.variables.StandardProceduralChildVariable.FixedConnection;
import org.simantics.utils.datastructures.Pair;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
public class ConnectionBrowser {
/**
Resource relation = graph.getInverse(stat.getPredicate());
//System.out.println(NameUtils.getSafeName(graph, component) + "." + NameUtils.getSafeName(graph, relation));
Resource boundConnection = graph.getPossibleObject(relation, STR.IsBoundBy);
- Resource type = graph.getPossibleObject(component, L0.InstanceOf);
+ Resource type = StructuralUtils.getComponentType(graph, configuration, component);
+ //
+ //Resource type = StructuralUtils.getComponentType(graph, configuration, component);
+ //Resource type = newContext != null ? newContext.getPossibleType(graph) : graph.getPossibleObject(component, L0.InstanceOf);
Resource def = type != null ? graph.getPossibleObject(type, STR.IsDefinedBy) : null;
if(boundConnection != null && def != null) {
// The connection point is bound in component type
HashSet<VariableConnectionPointDescriptor> result = new HashSet<VariableConnectionPointDescriptor>();
for(Resource c : conns) {
List<Resource> rs = graph.syncRequest(new ConnectionComponentsWithAncestor(graph, c), TransientCacheAsyncListener.<List<Resource>>instance());
+ for(Resource r : rs) {
+ System.err.println("--connections " + NameUtils.getSafeName(graph, r));
+ }
result.addAll(graph.syncRequest(ConnectionVariables.forStructural(graph, curConfiguration, rs)));
+ for(VariableConnectionPointDescriptor desc2 : result) {
+ reportDescriptor(graph, desc2);
+ }
}
return result;
Resource connection = graph.getPossibleObject(represents, res);
if(connection != null) {
List<Resource> rs = graph.syncRequest(new ConnectionComponentsWithAncestor(graph, connection), TransientCacheAsyncListener.<List<Resource>>instance());
+ for(Resource r : rs) {
+ System.err.println("--connections " + NameUtils.getSafeName(graph, r));
+ }
return graph.syncRequest(ConnectionVariables.forConfiguration(graph, curConfiguration, rs));
}
else {
}
+ public static void reportDescriptor(ReadGraph graph, VariableConnectionPointDescriptor d) throws DatabaseException {
+
+ if(d instanceof ActualConnectionDescriptor) {
+ ActualConnectionDescriptor d2 = (ActualConnectionDescriptor)d;
+
+ System.err.println("--ActualConnectionPointDescriptor2");
+ System.err.println("---root: " + d2.root.getURI(graph));
+ System.err.println("---component: " + graph.getPossibleURI(d2.component));
+ System.err.println("---type: " + graph.getPossibleURI(d2.componentType));
+ System.err.println("---cp: " + graph.getPossibleURI(d2.cp));
+ System.err.println("---var: " + d2.getVariable(graph).getURI(graph));
+ }
+
+ }
+
public static class ConnectionVariables extends BinaryRead<Variable, List<Resource>, Collection<VariableConnectionPointDescriptor>> {
private ConnectionVariables(Variable parameter1, List<Resource> parameter2) {
@Override
public Collection<VariableConnectionPointDescriptor> perform(ReadGraph graph) throws DatabaseException {
if(parameter == null) return Collections.emptyList();
+ System.err.println("ConnectionVariables " + parameter.getURI(graph));
StructuralResource2 STR = StructuralResource2.getInstance(graph);
ArrayList<VariableConnectionPointDescriptor> result = null;
for(int i=1;i<parameter2.size();i++) {
Resource connRes = parameter2.get(i);
for(Statement stm : graph.getStatements(connRes, STR.Connects)) {
+ Layer0 L0 = Layer0.getInstance(graph);
Resource component = stm.getObject();
Resource connectionPoint = graph.getInverse(stm.getPredicate());
if(result == null) result = new ArrayList<VariableConnectionPointDescriptor>();
- result.add(new ActualConnectionDescriptor(parameter, component, connectionPoint));
+ String componentName = graph.getRelatedValue(component, L0.HasName, Bindings.STRING);
+ if(parameter.getURI(graph).endsWith("SelectionView/Instance") && componentName.equals("Explorer1"))
+ System.err.println("asd");
+ Variable possibleChild = parameter.getPossibleChild(graph, componentName);
+ if(possibleChild != null) {
+ result.add(new ActualConnectionDescriptor(parameter, component, possibleChild.getType(graph), connectionPoint));
+ } else {
+ throw new DatabaseException("No child with name " + componentName + " could be resolved for variable " + parameter.getURI(graph));
+ }
}
}
if(result == null) return Collections.emptyList();
@Override
public Boolean perform(ReadGraph graph) throws DatabaseException {
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
-
- if(graph.isInstanceOf(resource, STR.ProceduralComponentType)) return false;
- if(graph.hasStatement(resource, STR.IsDefinedBy)) return false;
-
- return true;
+ StructuralComponentClass clazz = StructuralComponentClass.get(graph, resource);
+ return StructuralComponentClass.PRIMITIVE.equals(clazz);
}
public static Collection<VariableConnectionPointDescriptor> doFlatten(ReadGraph graph, Variable child, Resource cp, Resource relationType) throws DatabaseException {
- Collection<VariableConnectionPointDescriptor> climbed = climb(graph, child, cp, null);
- boolean needDrill = false;
+ Set<VariableConnectionPointDescriptor> result = null;
+ Set<VariableConnectionPointDescriptor> needDrill = null;
+
+ String debug = child.getURI(graph) + " " + NameUtils.getSafeLabel(graph, cp);
+ System.err.println("doFlatten " + debug);
+
+ if(debug.endsWith("01/TreeTable01 parent"))
+ System.err.println("asd");
+
+ Collection<VariableConnectionPointDescriptor> climbed = climb(graph, child, cp, null);
for(VariableConnectionPointDescriptor desc : climbed) {
if(!desc.isLeaf(graph)) {
- needDrill = true;
- break;
+ if(needDrill == null)
+ needDrill = new THashSet<VariableConnectionPointDescriptor>(climbed.size());
+ needDrill.add(desc);
+ } else {
+ if(result == null)
+ result = new THashSet<VariableConnectionPointDescriptor>(climbed.size());
+ result.add(desc);
}
}
- if(!needDrill) {
+ if(needDrill == null) {
+ /*
+ * All descriptors were already flat - just take case of filtering
+ */
if(relationType != null) {
ArrayList<VariableConnectionPointDescriptor> filtered = new ArrayList<VariableConnectionPointDescriptor>(climbed.size());
for(VariableConnectionPointDescriptor desc : climbed)
if(filterByRelationType(graph, desc, relationType))
filtered.add(desc);
return filtered;
+ } else {
+ return climbed;
}
- return climbed;
}
- THashSet<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>(climbed.size());
- for(VariableConnectionPointDescriptor top : climbed) {
+
+ /*
+ * There were some descriptors that require drill
+ */
+ for(VariableConnectionPointDescriptor top : needDrill) {
+
+ if(debug.endsWith("01/TreeTable01 parent"))
+ System.err.println("asd");
+
Collection<VariableConnectionPointDescriptor> drilled = drill(graph, top);
if(drilled != null) {
for(VariableConnectionPointDescriptor drill : drilled) {
if(!filterByRelationType(graph, drill, relationType))
continue;
}
+ if(result == null)
+ result = new THashSet<VariableConnectionPointDescriptor>(climbed.size());
result.add(drill);
}
}
}
+
+ System.err.println("doFlatten finished: " + debug);
+
+ if(debug.endsWith("01/TreeTable01 parent"))
+ System.err.println("asd");
+
+ for(VariableConnectionPointDescriptor desc2 : result) {
+ reportDescriptor(graph, desc2);
+ }
+
return result;
}
--- /dev/null
+package org.simantics.structural2.variables;
+
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.structural2.Functions.InterfaceResolution;
+
+public interface ConnectionBrowserConnectionPointDescriptor {
+
+ public boolean isLeaf(ReadGraph graph) throws DatabaseException;
+ public Collection<InterfaceResolution> getInterfaceDescription(ReadGraph graph) throws DatabaseException;
+
+}
package org.simantics.structural2.variables;
-import java.util.Collection;
-
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.variable.Variable;
-import org.simantics.structural2.Functions.InterfaceResolution;
-public interface VariableConnectionPointDescriptor {
+public interface VariableConnectionPointDescriptor extends ConnectionBrowserConnectionPointDescriptor {
public boolean isFlattenedFrom(ReadGraph graph, Variable possiblyStructuralCp) throws DatabaseException;
public Variable getVariable(ReadGraph graph) throws DatabaseException;
public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException;
public String getURI(ReadGraph graph) throws DatabaseException;
- public Collection<InterfaceResolution> getInterfaceDescription(ReadGraph graph) throws DatabaseException;
- public boolean isLeaf(ReadGraph graph) throws DatabaseException;
public boolean hasClassification(ReadGraph graph, String classification) throws DatabaseException;
public String getRelativeRVI(ReadGraph graph, Variable base) throws DatabaseException;
monitor.subTask(message);
LOGGER.info(message);
Collection<GraphBundle> tgs = PlatformUtil.getAllGraphs();
+ System.err.println("getAllGraphs " + tgs.size());
message = "extend bundles to compile versions";
monitor.subTask(message);
LOGGER.info(message);