]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java
Generate parts of db client query code
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / QuerySupportImpl.java
index 190db364cbdf8bda86c56cc2c4f427990200c352..b3b403ea7175cdf94bb98f15d58d87e9ca53e572 100644 (file)
@@ -1,7 +1,5 @@
 package fi.vtt.simantics.procore.internal;
 
-import gnu.trove.set.hash.TIntHashSet;
-
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.util.Collection;
@@ -36,6 +34,8 @@ import org.simantics.db.procore.cluster.ClusterSmall;
 import org.simantics.db.service.SerialisationSupport;
 import org.simantics.utils.DataContainer;
 
+import gnu.trove.set.hash.TIntHashSet;
+
 public class QuerySupportImpl implements QuerySupport {
        
        final SessionImplSocket session;
@@ -435,178 +435,8 @@ public class QuerySupportImpl implements QuerySupport {
        
     }
 
-//     @Override
-//    public void getSingleSuperrelation(ReadGraphImpl graph, final int subject, final AsyncProcedure<Resource> procedure) {
-//     
-//     // Do not process this information for virtual resources
-//     if(subject < 0) {
-//             procedure.execute(graph, null);
-//                     graph.state.barrier.dec();
-//             return;
-//     }
-//
-//     final ClusterI cluster = clusterTable.getClusterByResourceKey(subject);
-//        if (cluster == null)
-//            System.out.println("null cluster: " + Integer.toString(subject, 16));
-//        
-//        assert (cluster != null);
-//
-//        if(!cluster.isLoaded()) {
-//            
-//             procedure.execute(graph, null);
-//                     graph.state.barrier.dec();
-//             return;
-//
-////           queryProvider2.requestCluster(callerThread, cluster.getClusterId(), new Callback<Integer>() {
-////   
-////                           @Override
-////                           public void run(Integer i) {
-////   
-////                                   queryProvider2.schedule(i, callerThread, new Runnable() {
-////   
-////                                           @Override
-////                                           public void run() {
-////                                                   
-////                                                   try  {
-////                                                   
-////                                               ClusterI.CompleteTypeEnum type = cluster.getCompleteType(callerThread, subject, SessionImplSocket.this);
-////                                               if(ClusterI.CompleteTypeEnum.SubrelationOf == type) {
-////                                                   int result = cluster.getCompleteObjectKey(callerThread, subject, SessionImplSocket.this);
-////                                                   assert(result > 0);
-////                                                   procedure.execute(graph, getResourceByKey(result));
-////                                               } else {
-////                                                   procedure.execute(graph, null);
-////                                               }
-////                                                           graph.state.barrier.dec();
-////                                                           
-////                                                   } catch (DatabaseException e) {
-////                                                           e.printStackTrace();
-////                                                   }
-////                                                   
-////                                           }
-////   
-////                                   });
-////   
-////                           }
-////   
-////                   });
-//                     
-//        } else {
-//
-//             try {
-//
-//                     ClusterI.CompleteTypeEnum type = cluster.getCompleteType(graph.callerThread, subject, clusterSupport);
-//                     if(ClusterI.CompleteTypeEnum.SubrelationOf == type) {
-//                             int result = cluster.getCompleteObjectKey(graph.callerThread, subject, clusterSupport);
-//                             assert(result > 0);
-//                             procedure.execute(graph, new ResourceImpl(resourceSupport, result));
-//                     } else {
-//                             procedure.execute(graph, null);
-//                     }
-//                     graph.state.barrier.dec();
-//
-//             } catch (DatabaseException e) {
-//                     e.printStackTrace();
-//             }
-//                     
-//        }
-//        
-//        
-//    }
-
-//     @Override
-//    public void getObjects2(final int callerThread, final int subject, final int predicate, final IntProcedure procedure) {
-//             ensureLoaded(callerThread, subject, predicate, new Runnable() {
-//
-//                     @Override
-//                     public void run() {
-//                             safeGetObjects2(callerThread, subject, predicate, procedure);
-//                     }
-//                     
-//             });
-//     }
-
-//    public void safeGetObjects2(final ReadGraphImpl graph, final int subject, final int predicate, final IntProcedure procedure) {
-//
-//        assert (subject != 0);
-//        assert (predicate != 0);
-////        System.out.println("getObjects2: s=" + subject + "p=" + predicate);
-//        Collection<TransientGraph> providers = virtualGraphServerSupport.getVirtualGraphs(subject);
-//        if (providers != null) {
-//
-//            final TIntHashSet result = new TIntHashSet(16);
-//
-//            for (VirtualGraph provider : providers) {
-//
-//                for (int id : ((VirtualGraphImpl)provider).getObjects(subject, predicate)) {
-//
-//                    if (result.add(id)) {
-//                     procedure.execute(graph, id);
-//                    }
-//
-//                }
-//
-//            }
-//
-//            if (subject < 0)
-//                return;
-//
-//            final ClusterI cluster = clusterTable.getClusterByResourceKey(subject);
-//
-//            assert (testCluster(subject, cluster));
-//            
-//            // wheels within wheels
-//            final ClusterI.ObjectProcedure<Object> proc = new ClusterI.ObjectProcedure<Object>() {
-//
-//                @Override
-//                public boolean execute(int callerThread, Object context, int object) {
-//
-//                    if (result.add(object)) {
-//                     procedure.execute(graph.newAsync(callerThread), object);
-//                    }
-//
-//                    return false; // continue looping
-//
-//                }
-//                
-//                             @Override
-//                             public boolean found() {
-//                                     throw new UnsupportedOperationException();
-//                             }
-//                
-//            };
-//
-//            try {
-//                cluster.forObjects(graph.callerThread, subject, predicate, proc, null, clusterSupport);
-//            } catch (DatabaseException e) {
-//                Logger.defaultLogError(e);
-//            } catch (Throwable t) {
-//                Logger.defaultLogError(t);
-//             t.printStackTrace();
-//            }
-//            return;
-//            
-//        }
-//        
-//        assert(subject > 0);
-//
-//        final ClusterI cluster = clusterTable.getClusterByResourceKey(subject);
-//
-//        assert (testCluster(subject, cluster));
-//        
-//        try {
-//            cluster.forObjects(graph.callerThread, subject, predicate, new Wheels(procedure), null, clusterSupport);
-//        } catch (DatabaseException e) {
-//            Logger.defaultLogError(e);
-//        } catch (Throwable t) {
-//             t.printStackTrace();
-//            Logger.defaultLogError(t);
-//        }
-//        
-//    }
-
        @Override
-    public boolean getObjects(final ReadGraphImpl graph, final int subject, final int predicate, final IntProcedure procedure) {
+    public boolean getObjects(final ReadGraphImpl graph, final int subject, final int predicate, final IntProcedure procedure) throws DatabaseException {
                
                assert (subject != 0);
                assert (predicate != 0);
@@ -656,7 +486,11 @@ public class QuerySupportImpl implements QuerySupport {
 
                                found.set(true);
                                if (result.add(object)) {
-                                       procedure.execute(graph, object);
+                                       try {
+                                                       procedure.execute(graph, object);
+                                               } catch (DatabaseException e) {
+                                                       Logger.defaultLogError(e);
+                                               }
                                }
 
                                return false; // continue looping
@@ -686,8 +520,11 @@ public class QuerySupportImpl implements QuerySupport {
                        public boolean execute(Object context, int object) {
 
                                found = true;
-                               procedure.execute(graph, object);
-
+                               try {
+                                               procedure.execute(graph, object);
+                                       } catch (DatabaseException e) {
+                                               Logger.defaultLogError(e);
+                                       }
                                return false; // continue looping
 
                        }
@@ -1041,15 +878,8 @@ public class QuerySupportImpl implements QuerySupport {
 
     }
 
-//    @Override
-//    public void getStatements(ReadGraphImpl graph, final int subject, final Procedure<DirectStatements> procedure) {
-//     
-//             procedure.exception(new DatabaseException("Not supported"));
-//             
-//    }
-
     @Override
-    public void getPredicates(final ReadGraphImpl graph, final int subject, final IntProcedure procedure) {
+    public void getPredicates(final ReadGraphImpl graph, final int subject, final IntProcedure procedure) throws DatabaseException {
 
         final TIntHashSet result = new TIntHashSet(16);
 
@@ -1077,19 +907,6 @@ public class QuerySupportImpl implements QuerySupport {
         }
 
         ClusterI proxy = clusterTable.getClusterByResourceKey(subject);
-//        if(!proxy.isLoaded()) {
-//             
-//             proxy.load(callerThread, session, new Runnable() {
-//
-//                             @Override
-//                             public void run() {
-//                                     getPredicates(callerThread, subject, procedure);
-//                             }
-//                     
-//             });
-//             return;
-//             
-//        }
         assert (proxy != null);
 
         final DataContainer<Integer> got = new DataContainer<Integer>(0);
@@ -1097,7 +914,11 @@ public class QuerySupportImpl implements QuerySupport {
             @Override
             public boolean execute(Object context, int predicate, int oi) {
                 if (result.add(predicate)) {
-                    procedure.execute(graph, predicate);
+                    try {
+                                               procedure.execute(graph, predicate);
+                                       } catch (DatabaseException e) {
+                                               Logger.defaultLogError(e);
+                                       }
                 }
                 got.set(got.get() + 1);
                 return false; // continue looping