]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
Work in progress
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / ReadGraphImpl.java
index f0147e047e001cf6f82d809a269aec65e100ed13..fe0e3fcee535b983e119730e00e7d239e789474d 100644 (file)
@@ -26,6 +26,7 @@ import java.util.IdentityHashMap;
 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;
 
@@ -350,6 +351,32 @@ public class ReadGraphImpl implements ReadGraph {
                }
 
        }
+       
+       @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();
@@ -2065,7 +2092,7 @@ public class ReadGraphImpl implements ReadGraph {
 
                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();
@@ -2101,7 +2128,7 @@ public class ReadGraphImpl implements ReadGraph {
 
                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);
@@ -2180,7 +2207,7 @@ public class ReadGraphImpl implements ReadGraph {
                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);
@@ -5425,7 +5452,7 @@ public class ReadGraphImpl implements ReadGraph {
                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) {
@@ -5439,50 +5466,6 @@ public class ReadGraphImpl implements ReadGraph {
                        
                });
 
-               
-//             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) {
@@ -5553,9 +5536,7 @@ public class ReadGraphImpl implements ReadGraph {
                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) {
@@ -5569,40 +5550,6 @@ public class ReadGraphImpl implements ReadGraph {
                        
                });
 
-               
-
-
-//             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
@@ -6874,5 +6821,10 @@ public class ReadGraphImpl implements ReadGraph {
     public Object getModificationCounter() {
        return processor.getSession().getModificationCounter();
     }
+
+       @Override
+       public boolean performPending() {
+               return processor.performPending(processor.thread.get());
+       }
     
 }