-/*******************************************************************************\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.impl.query;\r
-\r
-import java.util.ArrayList;\r
-import java.util.concurrent.Semaphore;\r
-import java.util.concurrent.atomic.AtomicInteger;\r
-\r
-import org.simantics.db.RelationInfo;\r
-import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
-import org.simantics.db.impl.graph.ReadGraphImpl;\r
-import org.simantics.db.impl.procedure.InternalProcedure;\r
-import org.simantics.db.impl.procedure.TripleIntProcedureAdapter;\r
-import org.simantics.db.procedure.ListenerBase;\r
-import org.simantics.db.request.RequestFlags;\r
-\r
-\r
-final public class AssertedStatements extends CollectionBinaryQuery<TripleIntProcedure> {\r
- \r
-// public ArrayList<TripleIntProcedure> procs;\r
- \r
- public AssertedStatements(final int r1, final int r2) {\r
- super(r1, r2);\r
- }\r
-\r
- public static AssertedStatements newInstance(final int r1, final int r2) {\r
- return new AssertedStatements(r1, r2);\r
- }\r
- \r
- final static AssertedStatements runner(ReadGraphImpl graph, final int r1, final int r2, final QueryProcessor provider, final AssertedStatements cached, final CacheEntry parent, final ListenerBase listener, final TripleIntProcedure procedure) {\r
- \r
- AssertedStatements entry = cached != null ? cached : (AssertedStatements)provider.assertedStatementsMap.get(id(r1,r2)); \r
- if(entry == null) {\r
- \r
- entry = new AssertedStatements(r1, r2);\r
- entry.setPending();\r
- entry.clearResult(provider.querySupport);\r
- entry.putEntry(provider);\r
- \r
- provider.performForEach(graph, entry, parent, listener, procedure);\r
- \r
- return entry;\r
- \r
- } else {\r
- \r
- if(entry.isPending()) {\r
- synchronized(entry) {\r
- if(entry.isPending()) {\r
- throw new IllegalStateException();\r
-// if(entry.procs == null) entry.procs = new ArrayList<TripleIntProcedure>();\r
-// entry.procs.add(procedure);\r
-// provider.registerDependencies(graph, entry, parent, listener, procedure, false);\r
-// return entry;\r
- }\r
- }\r
- }\r
- provider.performForEach(graph, entry, parent, listener, procedure);\r
- }\r
- \r
- return entry;\r
- \r
- }\r
- \r
- final public static AssertedStatements queryEach(ReadGraphImpl graph, final int r1, final int r2, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final TripleIntProcedure procedure) {\r
- \r
- assert(r1 != 0);\r
- assert(r2 != 0);\r
- \r
- final AssertedStatements entry = (AssertedStatements)provider.assertedStatementsMap.get(id(r1,r2));\r
- \r
- if(parent == null && !(listener != null)) {\r
- if(entry != null && entry.isReady()) { \r
- entry.performFromCache(graph, provider, procedure);\r
- return entry;\r
- }\r
- }\r
-\r
- return runner(graph, r1, r2, provider, entry, parent, listener, procedure);\r
- \r
- }\r
-\r
- @Override\r
- public BinaryQuery<TripleIntProcedure> getEntry(QueryProcessor provider) {\r
- return provider.assertedStatementsMap.get(id);\r
- }\r
- \r
- @Override\r
- public void putEntry(QueryProcessor provider) {\r
- provider.assertedStatementsMap.put(id, this);\r
- }\r
-\r
- @Override\r
- final public void removeEntry(QueryProcessor provider) {\r
- provider.assertedStatementsMap.remove(id);\r
- }\r
- \r
- void computeInheritedAssertions(ReadGraphImpl graph, int type, final int predicate, final RelationInfo ri, final QueryProcessor queryProvider, final TripleIntProcedure proc) {\r
- \r
-// final AtomicBoolean found = new AtomicBoolean(0);\r
-\r
- DirectObjects.queryEach(graph, type, queryProvider.getInherits(), queryProvider, this, null, new SyncIntProcedure() {\r
-\r
- @Override\r
- public void run(ReadGraphImpl graph) {\r
-\r
-// if(ri.isFunctional && found.get() == 1) {\r
-//\r
-// ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has assertions from multiple inherited types.");\r
-// except(exception);\r
-// proc.exception(graph, exception);\r
-// return;\r
-// \r
-// }\r
-\r
- finish(graph, queryProvider);\r
- proc.finished(graph);\r
- \r
- }\r
-\r
- @Override\r
- public void execute(ReadGraphImpl graph, int inh) {\r
- \r
-// if(ri.isFunctional && found.get() == 1) return;\r
-\r
- inc();\r
- \r
- AssertedStatements.queryEach(graph, inh, predicate, queryProvider, AssertedStatements.this, null, new TripleIntProcedureAdapter() {\r
-\r
- @Override\r
- public void execute(ReadGraphImpl graph, int s, int p, int o) {\r
-\r
-// if(ri.isFunctional) {\r
-// \r
-//// if(found.get() == 1) return;\r
-//\r
-// if(found.compareAndSet(0, o)) {\r
- if(addOrSet(s,p,o))\r
- proc.execute(graph, s, p, o);\r
-// }\r
-// // If this was a duplicate, we can ignore this\r
-// else if (found.compareAndSet(o, o)) {\r
-// //System.err.println("duplicates!");\r
-// }\r
-// // Otherwise we have error\r
-// else {\r
-// found.set(1);\r
-// }\r
-// \r
-// } else {\r
-// \r
-// addOrSet(s, p, o);\r
-// proc.execute(graph, s, p, o);\r
-// \r
-// }\r
- \r
- }\r
-\r
- @Override\r
- public void finished(ReadGraphImpl graph) {\r
- dec(graph);\r
- }\r
- \r
- @Override\r
- public void exception(ReadGraphImpl graph, Throwable t) {\r
- proc.exception(graph, t);\r
- dec(graph);\r
- }\r
- \r
- });\r
- \r
- }\r
-\r
- @Override\r
- public void finished(ReadGraphImpl graph) {\r
- dec(graph);\r
- }\r
- \r
- });\r
-\r
- }\r
-\r
- void computeLocalAssertions(ReadGraphImpl graph, final int type, final int predicate, final RelationInfo ri, final QueryProcessor queryProvider, final TripleIntProcedure proc) {\r
- \r
- final AtomicInteger found = new AtomicInteger(0);\r
-\r
- DirectObjects.queryEach(graph, type, queryProvider.getAsserts(), queryProvider, this, null, new SyncIntProcedure() {\r
-\r
- @Override\r
- public void run(ReadGraphImpl graph) {\r
- \r
- if(ri.isFunctional && found.get() > 1) {\r
-\r
- ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has more than one asserted statement.");\r
- except(exception);\r
- proc.exception(graph, exception);\r
- return;\r
- \r
- }\r
-\r
- if(ri.isFunctional && found.get() == 1) {\r
- \r
- finish(graph, queryProvider);\r
- proc.finished(graph);\r
- return;\r
- \r
- }\r
-\r
- computeInheritedAssertions(graph, type, predicate, ri, queryProvider, proc);\r
- \r
- }\r
-\r
- @Override\r
- public void execute(ReadGraphImpl graph, final int ass) {\r
- \r
- if(ri.isFunctional && found.get() > 1) return;\r
- \r
- inc();\r
- \r
- DirectObjects.queryEach(graph, ass, queryProvider.getHasPredicate(), queryProvider, AssertedStatements.this, null, new IntProcedure() {\r
-\r
- @Override\r
- public void execute(ReadGraphImpl graph, final int pred) {\r
- \r
- if(ri.isFunctional) {\r
- \r
- if(found.get() > 1) return;\r
-\r
- inc();\r
-\r
- DirectObjects.queryEach(graph, ass, queryProvider.getHasObject(), queryProvider, AssertedStatements.this, null, new IntProcedure() {\r
-\r
- @Override\r
- public void execute(ReadGraphImpl graph, final int object) {\r
- \r
- if(found.get() > 1) return;\r
-\r
- if(pred == predicate) {\r
-\r
- if(found.getAndIncrement() == 0) {\r
- if(addOrSet(type, pred, object))\r
- proc.execute(graph, type, pred, object);\r
- }\r
- \r
- return;\r
- \r
- }\r
- \r
- if ( !ri.isFinal ) {\r
-\r
- inc();\r
-\r
- SuperRelations.queryEach(graph, pred, queryProvider, AssertedStatements.this, null, new InternalProcedure<IntSet>() {\r
- \r
- @Override\r
- public void execute(ReadGraphImpl graph, IntSet result) {\r
- \r
- if(found.get() > 1) {\r
- dec(graph);\r
- return;\r
- }\r
-\r
- if(result.contains(predicate)) {\r
- \r
- if(found.getAndIncrement() == 0) {\r
- if(addOrSet(type, pred, object))\r
- proc.execute(graph, type, pred, object);\r
- }\r
- \r
- }\r
- \r
- dec(graph);\r
- \r
- }\r
- \r
- @Override\r
- public void exception(ReadGraphImpl graph, Throwable t) {\r
- \r
- proc.exception(graph, t);\r
- dec(graph);\r
- \r
- }\r
-\r
- });\r
-\r
- }\r
-\r
- }\r
- \r
- @Override\r
- public void finished(ReadGraphImpl graph) {\r
- dec(graph);\r
- }\r
- \r
- @Override\r
- public void exception(ReadGraphImpl graph, Throwable t) {\r
- proc.exception(graph, t);\r
- dec(graph);\r
- }\r
-\r
- });\r
- \r
- } else {\r
-\r
- inc();\r
-\r
- DirectObjects.queryEach(graph, ass, queryProvider.getHasObject(), queryProvider, AssertedStatements.this, null, new IntProcedure() {\r
-\r
- @Override\r
- public void execute(ReadGraphImpl graph, final int object) {\r
- \r
- if(pred == predicate) {\r
-\r
- addOrSet(type, pred, object);\r
- proc.execute(graph, type, pred, object);\r
- return;\r
- \r
- }\r
- \r
- if ( !ri.isFinal ) {\r
-\r
- inc();\r
-\r
- SuperRelations.queryEach(graph, pred, queryProvider, AssertedStatements.this, null, new InternalProcedure<IntSet>() {\r
- \r
- @Override\r
- public void execute(ReadGraphImpl graph, IntSet result) {\r
- \r
- if(result.contains(predicate)) {\r
- \r
- addOrSet(type, pred, object);\r
- proc.execute(graph, type, pred, object);\r
-\r
- }\r
- \r
- dec(graph);\r
- \r
- }\r
- \r
- @Override\r
- public void exception(ReadGraphImpl graph, Throwable t) {\r
- proc.exception(graph, t);\r
- dec(graph);\r
- }\r
- \r
- });\r
-\r
- }\r
-\r
- }\r
- \r
- @Override\r
- public void finished(ReadGraphImpl graph) {\r
- dec(graph);\r
- }\r
- \r
- @Override\r
- public void exception(ReadGraphImpl graph, Throwable t) {\r
- proc.exception(graph, t);\r
- dec(graph);\r
- }\r
-\r
- });\r
-\r
- }\r
-\r
- }\r
-\r
- @Override\r
- public void finished(ReadGraphImpl graph) {\r
- dec(graph);\r
- }\r
- \r
- @Override\r
- public void exception(ReadGraphImpl graph, Throwable t) {\r
- proc.exception(graph, t);\r
- dec(graph);\r
- }\r
-\r
- });\r
- \r
- }\r
-\r
- @Override\r
- public void finished(ReadGraphImpl graph) {\r
- dec(graph);\r
- }\r
- \r
- });\r
- \r
- }\r
-\r
- @Override\r
- public void computeForEach(ReadGraphImpl graph, final QueryProcessor provider, final TripleIntProcedure procedure, boolean store) {\r
- \r
- RelationInfoQuery.queryEach(graph, r2(), provider, this, null, new InternalProcedure<RelationInfo>() {\r
-\r
- @Override\r
- public void execute(ReadGraphImpl graph, RelationInfo ri) {\r
- \r
- computeLocalAssertions(graph, r1(), r2(), ri, provider, procedure);\r
- \r
- }\r
- \r
- @Override\r
- public void exception(ReadGraphImpl graph, Throwable t) {\r
- procedure.exception(graph, t);\r
- }\r
- \r
- });\r
- \r
- }\r
- \r
- @Override\r
- public String toString() {\r
- return "AssertedStatements2[" + r1() + " - " + r2() + "]";\r
- }\r
-\r
- private boolean addOrSet(int s, int p, int o) {\r
- \r
- assert(isPending());\r
- \r
- IntArray value = (IntArray)getResult();\r
- if(value.data != null) {\r
- for(int i = 0;i < value.sizeOrData ; i+=3) {\r
- int existingP = value.data[i+1];\r
- if(p == existingP) {\r
- int existingO = value.data[i+2];\r
- if(existingO == o) return false;\r
- }\r
- }\r
- value.add(s);\r
- value.add(p);\r
- value.add(o);\r
- } else {\r
- value.add(s);\r
- value.add(p);\r
- value.add(o);\r
- }\r
- \r
- return true;\r
- \r
- }\r
- \r
- final private void finish(ReadGraphImpl graph, QueryProcessor provider) {\r
- \r
- assert(isPending());\r
-\r
-// ArrayList<TripleIntProcedure> p = null;\r
-\r
- synchronized(this) {\r
- \r
- setReady();\r
-// p = procs;\r
-// procs = null; \r
- \r
- }\r
- \r
-// if(p != null) {\r
-// final IntArray value = (IntArray)getResult();\r
-// for(TripleIntProcedure proc : p) {\r
-// for(int i=0;i<value.size();i+=3) {\r
-// proc.execute(graph, value.data[i], value.data[i+1], value.data[i+2]);\r
-// }\r
-// }\r
-//\r
-// for(TripleIntProcedure proc : p) proc.finished(graph);\r
-// }\r
-\r
- }\r
-\r
- @Override\r
- public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, final TripleIntProcedure procedure) {\r
- \r
- assert(isReady());\r
- \r
- if(handleException(graph, procedure)) return;\r
- \r
- final IntArray value = (IntArray)getResult();\r
- for(int i=0;i<value.size();i+=3) {\r
- procedure.execute(graph, value.data[i], value.data[i+1], value.data[i+2]);\r
- }\r
-\r
- procedure.finished(graph);\r
- \r
- }\r
- \r
- @Override\r
- public void recompute(ReadGraphImpl graph, QueryProcessor provider) {\r
- \r
- final Semaphore s = new Semaphore(0);\r
-\r
- computeForEach(graph, provider, new TripleIntProcedureAdapter() {\r
-\r
- @Override\r
- public void finished(ReadGraphImpl graph) {\r
- s.release();\r
- }\r
- \r
- @Override\r
- public void exception(ReadGraphImpl graph, Throwable t) {\r
- throw new Error("Error in recompute", t);\r
- }\r
- \r
- }, true);\r
- \r
- try {\r
- s.acquire();\r
- } catch (InterruptedException e) {\r
- throw new Error(e);\r
- }\r
- \r
- }\r
- \r
- @Override\r
- public int type() {\r
- return RequestFlags.IMMEDIATE_UPDATE;\r
- }\r
- \r
-\r
- @Override\r
- boolean isImmutable(ReadGraphImpl graph) {\r
- return graph.processor.isImmutable(r1());\r
- }\r
- \r
-}\r
+/*******************************************************************************
+ * 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
+ * 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.impl.query;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.simantics.db.RelationInfo;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
+import org.simantics.db.impl.graph.ReadGraphImpl;
+import org.simantics.db.impl.procedure.InternalProcedure;
+import org.simantics.db.impl.procedure.TripleIntProcedureAdapter;
+import org.simantics.db.request.RequestFlags;
+
+
+final public class AssertedStatements extends CollectionBinaryQuery<TripleIntProcedure> {
+
+ public AssertedStatements(final int r1, final int r2) {
+ super(r1, r2);
+ }
+
+ public static AssertedStatements newInstance(final int r1, final int r2) {
+ return new AssertedStatements(r1, r2);
+ }
+
+ @Override
+ final public void removeEntry(QueryProcessor provider) {
+ provider.cache.remove(this);
+ }
+
+ static void computeInheritedAssertions(ReadGraphImpl graph, int type, final int predicate, final RelationInfo ri, final AssertedStatements entry, final TripleIntProcedure proc) throws DatabaseException {
+
+ QueryProcessor processor = graph.processor;
+
+ QueryCache.runnerDirectObjects(graph, type, processor.getInherits(), entry, null, new SyncIntProcedure() {
+
+ @Override
+ public void run(ReadGraphImpl graph) throws DatabaseException {
+
+// if(ri.isFunctional && found.get() == 1) {
+//
+// ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has assertions from multiple inherited types.");
+// except(exception);
+// proc.exception(graph, exception);
+// return;
+//
+// }
+
+ finish(graph, entry);
+ proc.finished(graph);
+
+ }
+
+ @Override
+ public void execute(ReadGraphImpl graph, int inh) throws DatabaseException {
+
+// if(ri.isFunctional && found.get() == 1) return;
+
+ inc();
+
+ QueryCache.runnerAssertedStatements(graph, inh, predicate, entry, null, new TripleIntProcedureAdapter() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, int s, int p, int o) throws DatabaseException {
+
+// if(ri.isFunctional) {
+//
+//// if(found.get() == 1) return;
+//
+// if(found.compareAndSet(0, o)) {
+ if(addOrSet(s,p,o, entry))
+ proc.execute(graph, s, p, o);
+// }
+// // If this was a duplicate, we can ignore this
+// else if (found.compareAndSet(o, o)) {
+// //System.err.println("duplicates!");
+// }
+// // Otherwise we have error
+// else {
+// found.set(1);
+// }
+//
+// } else {
+//
+// addOrSet(s, p, o);
+// proc.execute(graph, s, p, o);
+//
+// }
+
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ dec(graph);
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ proc.exception(graph, t);
+ dec(graph);
+ }
+
+ });
+
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ dec(graph);
+ }
+
+ });
+
+ }
+
+ static void computeLocalAssertions(ReadGraphImpl graph, final int type, final int predicate, final RelationInfo ri, final AssertedStatements entry, final TripleIntProcedure proc) throws DatabaseException {
+
+
+ }
+
+ //@Override
+ public Object compute(ReadGraphImpl graph, final TripleIntProcedure procedure) throws DatabaseException {
+ computeForEach(graph, r1(), r2(), this, procedure);
+ return getResult();
+ }
+
+ public static void computeForEach(ReadGraphImpl graph, final int type, final int predicate, final AssertedStatements entry, final TripleIntProcedure procedure) throws DatabaseException {
+
+ RelationInfo ri = QueryCache.resultRelationInfoQuery(graph, predicate, entry, null);
+
+ final AtomicInteger found = new AtomicInteger(0);
+
+ QueryProcessor processor = graph.processor;
+
+ QueryCache.runnerDirectObjects(graph, type, processor.getAsserts(), entry, null, new SyncIntProcedure() {
+
+ @Override
+ public void run(ReadGraphImpl graph) throws DatabaseException {
+
+ if(ri.isFunctional && found.get() > 1) {
+
+ ManyObjectsForFunctionalRelationException exception = new ManyObjectsForFunctionalRelationException("Functional relation has more than one asserted statement.");
+ except(exception, entry);
+ procedure.exception(graph, exception);
+ return;
+
+ }
+
+ if(ri.isFunctional && found.get() == 1) {
+
+ finish(graph, entry);
+ procedure.finished(graph);
+ return;
+
+ }
+
+ computeInheritedAssertions(graph, type, predicate, ri, entry, procedure);
+
+ }
+
+ @Override
+ public void execute(ReadGraphImpl graph, final int ass) throws DatabaseException {
+
+ if(ri.isFunctional && found.get() > 1) return;
+
+ inc();
+
+ QueryCache.runnerDirectObjects(graph, ass, processor.getHasPredicate(), entry, null, new IntProcedure() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, final int pred) throws DatabaseException {
+
+ if(ri.isFunctional) {
+
+ if(found.get() > 1) return;
+
+ inc();
+
+ QueryCache.runnerDirectObjects(graph, ass, processor.getHasObject(), entry, null, new IntProcedure() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, final int object) throws DatabaseException {
+
+ if(found.get() > 1) return;
+
+ if(pred == predicate) {
+
+ if(found.getAndIncrement() == 0) {
+ if(addOrSet(type, pred, object, entry))
+ procedure.execute(graph, type, pred, object);
+ }
+
+ return;
+
+ }
+
+ if ( !ri.isFinal ) {
+
+ inc();
+
+ QueryCache.runnerSuperRelations(graph, pred, entry, null, new InternalProcedure<IntSet>() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, IntSet result) throws DatabaseException {
+
+ if(found.get() > 1) {
+ dec(graph);
+ return;
+ }
+
+ if(result.contains(predicate)) {
+
+ if(found.getAndIncrement() == 0) {
+ if(addOrSet(type, pred, object, entry))
+ procedure.execute(graph, type, pred, object);
+ }
+
+ }
+
+ dec(graph);
+
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+
+ procedure.exception(graph, t);
+ dec(graph);
+
+ }
+
+ });
+
+ }
+
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ dec(graph);
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ procedure.exception(graph, t);
+ dec(graph);
+ }
+
+ });
+
+ } else {
+
+ inc();
+
+ QueryCache.runnerDirectObjects(graph, ass, processor.getHasObject(), entry, null, new IntProcedure() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, final int object) throws DatabaseException {
+
+ if(pred == predicate) {
+
+ addOrSet(type, pred, object, entry);
+ procedure.execute(graph, type, pred, object);
+ return;
+
+ }
+
+ if ( !ri.isFinal ) {
+
+ inc();
+
+ QueryCache.runnerSuperRelations(graph, pred, entry, null, new InternalProcedure<IntSet>() {
+
+ @Override
+ public void execute(ReadGraphImpl graph, IntSet result) throws DatabaseException {
+
+ if(result.contains(predicate)) {
+
+ addOrSet(type, pred, object, entry);
+ procedure.execute(graph, type, pred, object);
+
+ }
+
+ dec(graph);
+
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ procedure.exception(graph, t);
+ dec(graph);
+ }
+
+ });
+
+ }
+
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ dec(graph);
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ procedure.exception(graph, t);
+ dec(graph);
+ }
+
+ });
+
+ }
+
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ dec(graph);
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
+ procedure.exception(graph, t);
+ dec(graph);
+ }
+
+ });
+
+ }
+
+ @Override
+ public void finished(ReadGraphImpl graph) throws DatabaseException {
+ dec(graph);
+ }
+
+ });
+
+ }
+
+ @Override
+ public String toString() {
+ return "AssertedStatements[" + r1() + " - " + r2() + "]";
+ }
+
+ private boolean addOrSet(int s, int p, int o) {
+
+ assert(isPending());
+
+ IntArray value = (IntArray)getResult();
+ if(value.data != null) {
+ for(int i = 0;i < value.sizeOrData ; i+=3) {
+ int existingP = value.data[i+1];
+ if(p == existingP) {
+ int existingO = value.data[i+2];
+ if(existingO == o) return false;
+ }
+ }
+ value.add(s);
+ value.add(p);
+ value.add(o);
+ } else {
+ value.add(s);
+ value.add(p);
+ value.add(o);
+ }
+
+ return true;
+
+ }
+
+ static boolean addOrSet(int s, int p, int o, AssertedStatements entry) {
+ if(entry != null) {
+ return entry.addOrSet(s, p, o);
+ } else {
+ return true;
+ }
+ }
+
+ static void finish(ReadGraphImpl graph, AssertedStatements entry) {
+
+ assert(entry.isPending());
+ if(entry != null) {
+ synchronized(entry) {
+ entry.setReady();
+ }
+ }
+
+ }
+
+ static void except(Throwable t, AssertedStatements entry) {
+ if(entry != null) {
+ synchronized(entry) {
+ entry.except(t);
+ }
+ }
+ }
+
+ @Override
+ public Object performFromCache(ReadGraphImpl graph, final TripleIntProcedure procedure) throws DatabaseException {
+
+ assert(isReady());
+
+ if(handleException(graph, procedure)) return getResult();
+
+ final IntArray value = (IntArray)getResult();
+ for(int i=0;i<value.size();i+=3) {
+ procedure.execute(graph, value.data[i], value.data[i+1], value.data[i+2]);
+ }
+
+ procedure.finished(graph);
+
+ return value;
+
+ }
+
+ @Override
+ public void recompute(ReadGraphImpl graph) throws DatabaseException {
+
+ compute(graph, new TripleIntProcedureAdapter() {
+
+ @Override
+ public void finished(ReadGraphImpl graph) {
+ }
+
+ @Override
+ public void exception(ReadGraphImpl graph, Throwable t) {
+ throw new Error("Error in recompute", t);
+ }
+
+ });
+
+ }
+
+ @Override
+ public int type() {
+ return RequestFlags.IMMEDIATE_UPDATE;
+ }
+
+
+ @Override
+ boolean isImmutable(ReadGraphImpl graph) {
+ return graph.processor.isImmutable(r1());
+ }
+
+}