]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/request/ObjectsWithTypeAsync.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / ObjectsWithTypeAsync.java
index 4287506e10296d9f728486838aa0131a41b24e59..48cc90fb9a67a13dad1059436e19dc520f29dead 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.common.request;\r
-\r
-import java.util.Collection;\r
-import java.util.Set;\r
-import java.util.concurrent.ConcurrentLinkedQueue;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.ProcedureBarrier;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.procedure.AsyncMultiProcedure;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-\r
-final public class ObjectsWithTypeAsync extends ResourceAsyncRead3<Collection<Resource>> {\r
-\r
-    public ObjectsWithTypeAsync(Resource subject, Resource subrelationOf, Resource instanceOf) {\r
-        super(subject, subrelationOf, instanceOf);\r
-    }\r
-\r
-    @Override\r
-    public void perform(AsyncReadGraph graph, final AsyncProcedure<Collection<Resource>> procedure) {\r
-\r
-       final Collection<Resource> result = new ConcurrentLinkedQueue<Resource>();\r
-       final ProcedureBarrier<Collection<Resource>> ready = new ProcedureBarrier<Collection<Resource>>(1);\r
-       \r
-       graph.forEachObject(resource, resource2, new AsyncMultiProcedure<Resource>() {\r
-\r
-                       @Override\r
-                       public void execute(AsyncReadGraph graph, final Resource object) {\r
-                               \r
-                               ready.incrementAndGet();\r
-                               \r
-                               graph.forTypes(object, new AsyncProcedure<Set<Resource>>() {\r
-                                       \r
-                                       @Override\r
-                                       public void execute(AsyncReadGraph graph, Set<Resource> types) {\r
-\r
-                                               if(types.contains(resource3)) {\r
-                                                       result.add(object);\r
-                                               }\r
-                                               \r
-                                               ready.dec(graph, procedure, result);\r
-                                               \r
-                                       }\r
-                                       \r
-                                       @Override\r
-                                       public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                                               \r
-                                               throwable.printStackTrace();\r
-                                       Logger.defaultLogError(throwable);\r
-                                               \r
-                                               ready.except(throwable);\r
-                                               ready.dec(graph, procedure, result);\r
-                                               \r
-                                       }\r
-                                       \r
-                               });\r
-                               \r
-                       }\r
-\r
-                       @Override\r
-                       public void finished(AsyncReadGraph graph) {\r
-                               \r
-                               ready.dec(graph, procedure, result);\r
-                               \r
-                       }\r
-\r
-                       @Override\r
-                       public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                               \r
-                               throwable.printStackTrace();\r
-                       Logger.defaultLogError(throwable);\r
-                               \r
-                               ready.except(throwable);\r
-                               ready.dec(graph, procedure, result);\r
-                               \r
-                       }\r
-               \r
-       });\r
-       \r
-    }\r
-    \r
-//    @Override\r
-//    public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
-//        \r
-//     Set<Resource> result = new HashSet<Resource>();\r
-//     for(Resource object : graph.getObjects(resource, resource2)) {\r
-//             if(graph.isInstanceOf(object, resource3)) result.add(object);\r
-//     }\r
-//     return result;\r
-//        \r
-//    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.request;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.ProcedureBarrier;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.AsyncProcedure;
+
+final public class ObjectsWithTypeAsync extends ResourceAsyncRead3<Collection<Resource>> {
+
+    public ObjectsWithTypeAsync(Resource subject, Resource subrelationOf, Resource instanceOf) {
+        super(subject, subrelationOf, instanceOf);
+    }
+
+    @Override
+    public void perform(AsyncReadGraph graph, final AsyncProcedure<Collection<Resource>> procedure) {
+
+       final Collection<Resource> result = new ConcurrentLinkedQueue<Resource>();
+       final ProcedureBarrier<Collection<Resource>> ready = new ProcedureBarrier<Collection<Resource>>(1);
+       
+       graph.forEachObject(resource, resource2, new AsyncMultiProcedure<Resource>() {
+
+                       @Override
+                       public void execute(AsyncReadGraph graph, final Resource object) {
+                               
+                               ready.incrementAndGet();
+                               
+                               graph.forTypes(object, new AsyncProcedure<Set<Resource>>() {
+                                       
+                                       @Override
+                                       public void execute(AsyncReadGraph graph, Set<Resource> types) {
+
+                                               if(types.contains(resource3)) {
+                                                       result.add(object);
+                                               }
+                                               
+                                               ready.dec(graph, procedure, result);
+                                               
+                                       }
+                                       
+                                       @Override
+                                       public void exception(AsyncReadGraph graph, Throwable throwable) {
+                                               
+                                               throwable.printStackTrace();
+                                       Logger.defaultLogError(throwable);
+                                               
+                                               ready.except(throwable);
+                                               ready.dec(graph, procedure, result);
+                                               
+                                       }
+                                       
+                               });
+                               
+                       }
+
+                       @Override
+                       public void finished(AsyncReadGraph graph) {
+                               
+                               ready.dec(graph, procedure, result);
+                               
+                       }
+
+                       @Override
+                       public void exception(AsyncReadGraph graph, Throwable throwable) {
+                               
+                               throwable.printStackTrace();
+                       Logger.defaultLogError(throwable);
+                               
+                               ready.except(throwable);
+                               ready.dec(graph, procedure, result);
+                               
+                       }
+               
+       });
+       
+    }
+    
+//    @Override
+//    public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
+//        
+//     Set<Resource> result = new HashSet<Resource>();
+//     for(Resource object : graph.getObjects(resource, resource2)) {
+//             if(graph.isInstanceOf(object, resource3)) result.add(object);
+//     }
+//     return result;
+//        
+//    }
+
+}