import org.simantics.databoard.Bindings;
import org.simantics.databoard.util.ObjectUtils;
import org.simantics.datatypes.literal.GUID;
-import org.simantics.db.AsyncReadGraph;
import org.simantics.db.ChangeSet;
import org.simantics.db.ChangeSet.StatementChange;
import org.simantics.db.MetadataI;
import org.simantics.db.common.request.SuperTypeString;
import org.simantics.db.common.request.TypeString;
import org.simantics.db.common.request.UnaryRead;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.event.ChangeListener;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.NoSingleResultException;
import org.simantics.db.layer0.adapter.GenericRelation;
import org.simantics.db.layer0.adapter.GenericRelationIndex;
import org.simantics.db.layer0.genericrelation.DependencyChanges.Change;
import org.simantics.db.layer0.genericrelation.DependencyChanges.ComponentModification;
import org.simantics.db.layer0.genericrelation.DependencyChanges.ComponentRemoval;
import org.simantics.db.layer0.genericrelation.DependencyChanges.LinkChange;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
-import org.simantics.db.procedure.AsyncContextProcedure;
+import org.simantics.db.procedure.SyncContextMultiProcedure;
+import org.simantics.db.procedure.SyncContextProcedure;
import org.simantics.db.service.CollectionSupport;
import org.simantics.db.service.DirectQuerySupport;
import org.simantics.db.service.GraphChangeListenerSupport;
import org.simantics.operation.Layer0X;
import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.logging.TimeLogger;
+import org.slf4j.LoggerFactory;
public class DependenciesRelation extends UnsupportedRelation implements GenericRelationIndex {
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DependenciesRelation.class);
private static final boolean DEBUG = false;
static final boolean DEBUG_LISTENERS = false;
private static final boolean PROFILE = false;
class Process {
final ArrayList<Entry> result = new ArrayList<Entry>();
- final AsyncContextMultiProcedure<Resource, Resource> structure;
- final AsyncContextProcedure<Entry, String> names;
- final AsyncContextProcedure<Entry, Resource> type;
+ final SyncContextMultiProcedure<Resource, Resource> structure;
+ final SyncContextProcedure<Entry, String> names;
+ final SyncContextProcedure<Entry, Resource> type;
Process(ReadGraph graph, final Resource resource) throws DatabaseException {
final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
final CollectionSupport cs = graph.getService(CollectionSupport.class);
- names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new AsyncContextProcedure<Entry, String>() {
+ names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new SyncContextProcedure<Entry, String>() {
@Override
- public void execute(AsyncReadGraph graph, Entry entry, String name) {
+ public void execute(ReadGraph graph, Entry entry, String name) {
entry.name = name;
}
@Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- Logger.defaultLogError(throwable);
+ public void exception(ReadGraph graph, Throwable throwable) {
+ LOGGER.error("Could not compile possible related value for resource {}", resource, throwable);
}
});
- type = new AsyncContextProcedure<Entry, Resource>() {
+ type = new SyncContextProcedure<Entry, Resource>() {
@Override
- public void execute(AsyncReadGraph graph, Entry entry, Resource type) {
+ public void execute(ReadGraph graph, Entry entry, Resource type) {
entry.principalType = type;
}
@Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- Logger.defaultLogError(throwable);
+ public void exception(ReadGraph graph, Throwable throwable) {
+ LOGGER.error("Could not find type for resource {}", resource, throwable);
}
};
- structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure<Resource, Resource>() {
+ structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncContextMultiProcedure<Resource, Resource>() {
@Override
- public void execute(AsyncReadGraph graph, Resource parent, Resource child) {
+ public void execute(ReadGraph graph, Resource parent, Resource child) {
// WORKAROUND: don't browse virtual child resources
if(!child.isPersistent()) return;
Entry entry = new Entry(parent, child, "", "", "");
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(ReadGraph graph, Resource parent) {
}
@Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- Logger.defaultLogError(throwable);
+ public void exception(ReadGraph graph, Throwable throwable) {
+ if (throwable instanceof NoSingleResultException) {
+ // Ignore
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("Could not compile for resource {}", resource, throwable);
+ } else {
+ LOGGER.error("Could not compile for resource {}", resource, throwable);
+ }
}
});
if(typeString == null) {
typeString = graph.syncRequest(new SuperTypeString(e.principalType));
if (typeString.isEmpty()) {
- Logger.defaultLogError(new DatabaseException("No name for type " + NameUtils.getURIOrSafeNameInternal(graph, e.resource) + " (" + e.resource + ")"));
+ LOGGER.error("No name for type", new DatabaseException("No name for type " + NameUtils.getURIOrSafeNameInternal(graph, e.resource) + " (" + e.resource + ")"));
}
typeStrings.put(e.principalType, typeString);
}
ArrayList<Object[]> result = new ArrayList<Object[]>();
for (Entry entry : entries) {
+ if(entry.name == null) continue;
result.add(new Object[] { ss.getRandomAccessId(entry.parent), ss.getRandomAccessId(entry.resource), entry.name, entry.types, entry.id });
}
return result;
Resource changeInformation = graph.getPossibleResource("http://www.simantics.org/Modeling-1.2/changeInformation/Inverse");
for (Resource value : parameter.changedValues()) {
+ if(!value.isPersistent()) continue;
Statement modifiedComponent = graph.getPossibleStatement(value, l0.PropertyOf);
if (modifiedComponent == null
|| modifiedComponent.getPredicate().equals(changeInformation))
} catch (Throwable t) {
// Just to know if something unexpected happens here.
- Logger.defaultLogError("Dependencies index update failed for model "
- + model + " and relation " + resource + ".", t);
- t.printStackTrace();
+ LOGGER.error("Dependencies index update failed for model "
+ + model + " and relation " + resource + ".", t);
// NOTE: Last resort: failure to update index
// properly results in removal of the whole index.