import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
import org.simantics.Simantics;
import org.simantics.databoard.Datatypes;
import org.simantics.databoard.binding.Binding;
import org.simantics.databoard.type.Datatype;
+import org.simantics.db.AsyncReadGraph;
import org.simantics.db.DirectStatements;
import org.simantics.db.ReadGraph;
import org.simantics.db.RequestProcessor;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.request.BinaryRead;
-import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.common.request.ResourceAsyncRead;
import org.simantics.db.common.request.UniqueRead;
import org.simantics.db.common.request.WriteResultRequest;
import org.simantics.db.common.utils.Logger;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ServiceException;
import org.simantics.db.layer0.function.All;
import org.simantics.db.layer0.request.ProjectModels;
import org.simantics.db.layer0.request.PropertyInfo;
import org.simantics.db.layer0.variable.VariableMap;
import org.simantics.db.layer0.variable.VariableMapImpl;
import org.simantics.db.layer0.variable.Variables;
+import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.db.service.DirectQuerySupport;
import org.simantics.document.base.ontology.DocumentationResource;
import org.simantics.document.server.bean.Command;
};
- static class DocumentPropertyKeys extends ResourceRead<List<String>> {
+ static class DocumentPropertyKeys extends ResourceAsyncRead<List<String>> {
protected DocumentPropertyKeys(Resource resource) {
super(resource);
}
@Override
- public List<String> perform(ReadGraph graph) throws DatabaseException {
+ public void perform(AsyncReadGraph graph, final AsyncProcedure<List<String>> procedure) {
- List<String> result = new ArrayList<>();
+ final List<String> result = new ArrayList<>();
DocumentationResource DOC = DocumentationResource.getInstance(graph);
- if(graph.hasStatement(resource, DOC.Properties_commands))
- result.add("commands");
- if(graph.hasStatement(resource, DOC.Properties_dataDefinitions))
- result.add("dataDefinitions");
+ try {
+ if(graph.hasStatement(resource, DOC.Properties_commands))
+ result.add("commands");
+ if(graph.hasStatement(resource, DOC.Properties_dataDefinitions))
+ result.add("dataDefinitions");
+ } catch(ServiceException e) {
+ LOGGER.info(e.getMessage(), e);
+ }
+
+ graph.forEachDirectPredicate(resource, new AsyncProcedure<Set<Resource>>() {
- DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
- DirectStatements ds = dqs.getDirectPersistentStatements(graph, resource);
+ @Override
+ public void execute(AsyncReadGraph graph, Set<Resource> predicates) {
+
+ for(Resource predicate : predicates) {
- for(Statement stm : ds) {
+ try {
- Resource predicate = stm.getPredicate();
- PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate));
+ PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate));
+
+ if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) {
+ result.add(info.name);
+ } else {
+ Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation);
+ if(definition != null) {
+ PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition));
+ result.add(info2.name);
+ }
+ }
+
+ } catch (DatabaseException e) {
+ LOGGER.info(e.getMessage(), e);
+ }
- if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) {
- result.add(info.name);
- } else {
- Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation);
- if(definition != null) {
- PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition));
- result.add(info2.name);
}
+
+ procedure.execute(graph, result);
+
}
- }
- return result;
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ LOGGER.info(throwable.getMessage(), throwable);
+ procedure.exception(graph, throwable);
+ }
+
+ });
}