]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/IntSet.java
Multiple reader thread support for db client
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / IntSet.java
index 7c32b8e593e19ea7757355d3c1768c0757abe7c1..3ef19b8f335ec9dbf60aeaf1df6bf818251d67a2 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 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
@@ -11,8 +11,6 @@
  *******************************************************************************/
 package org.simantics.db.impl.query;
 
-import gnu.trove.procedure.TIntProcedure;
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
@@ -20,9 +18,13 @@ import java.util.Set;
 
 import org.simantics.db.Resource;
 import org.simantics.db.ResourceSet;
+import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.ResourceImpl;
+import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.support.ResourceSupport;
 
+import gnu.trove.procedure.TIntProcedure;
+
 
 final public class IntSet implements ResourceSet {
 
@@ -40,10 +42,10 @@ final public class IntSet implements ResourceSet {
     
     private static final Object[] EMPTY_ARRAY = new Object[0];
 
-    public IntSet() {
+    public static IntSet EMPTY = new IntSet();
+
+    private IntSet() {
         support = null;
-        data = null;
-        sizeOrData = NO_DATA;
     }
 
     public IntSet(QuerySupport support) {
@@ -287,4 +289,15 @@ final public class IntSet implements ResourceSet {
         }
     }
 
+    public void forEach(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException {
+        if (data != null) {
+            for (int i=0;i<sizeOrData;++i)
+                procedure.execute(graph, data[i]);
+        } else if(sizeOrData == NO_DATA) {
+        } else {
+            procedure.execute(graph, sizeOrData);
+        }
+        procedure.finished(graph);
+    }
+
 }
\ No newline at end of file