private static final Logger LOGGER = LoggerFactory.getLogger(AsyncMultiReadEntry.class);
- protected AsyncMultiRead<T> request;
+ protected AsyncMultiRead<T> id;
AsyncMultiReadEntry(AsyncMultiRead<T> request) {
- this.request = request;
+ this.id = request;
}
@Override
int makeHash() {
- return request.hashCode();
+ return id.hashCode();
}
@Override
public Object getOriginalRequest() {
- return request;
+ return id;
}
@Override
public void discard() {
super.discard();
- request = null;
+ id = null;
setResult(null);
}
except(t);
}
- }, request);
+ }, id);
- request.perform(graph , proc);
+ id.perform(graph , proc);
proc.get();
@Override
public String toString() {
- if(request == null) return "DISCARDED";
- else return request.toString() + statusOrException;
+ if(id == null) return "DISCARDED";
+ else return id.toString() + statusOrException;
}
};
@Override
public String toString() {
- if(request == null) return "DISCARDED";
- else return request.toString() + statusOrException;
+ if(id == null) return "DISCARDED";
+ else return id.toString() + statusOrException;
}
public Object compute(ReadGraphImpl graph, AsyncMultiProcedure<T> procedure) throws DatabaseException {
- return graph.processor.cache.performQuery(graph, request, this, procedure);
+ return graph.processor.cache.performQuery(graph, id, this, procedure);
}
}
private static final Logger LOGGER = LoggerFactory.getLogger(AsyncReadEntry.class);
- protected AsyncRead<T> request;
+ protected AsyncRead<T> id;
AsyncReadEntry(AsyncRead<T> request) {
- this.request = request;
+ this.id = request;
if (Development.DEVELOPMENT) {
if(Development.<Boolean>getProperty(DevelopmentKeys.CACHE_ENTRY_STATE, Bindings.BOOLEAN)) {
System.err.println("[QUERY STATE]: created " + this);
@Override
int makeHash() {
- return request.hashCode();
+ return id.hashCode();
}
@Override
public Object getOriginalRequest() {
- return request;
+ return id;
}
@Override
except(t);
}
- }, request);
+ }, id);
- request.perform(graph, proc);
+ id.perform(graph, proc);
proc.get();
@Override
public int type() {
- return request.getFlags();
+ return id.getFlags();
}
@Override
public String toString() {
- if (request == null)
+ if (id == null)
return "DISCARDED";
else if (isExcepted())
- return request.toString() + " " + getResult();
+ return id.toString() + " " + getResult();
else
- return request.toString() + " " + statusOrException;
+ return id.toString() + " " + statusOrException;
}
};
@Override
public String toString() {
if (isDiscarded())
- return "DISCARDED " + request.toString();
+ return "DISCARDED " + id.toString();
else if (isExcepted())
- return request.toString() + " " + getResult();
+ return id.toString() + " " + getResult();
else
- return request.toString() + " " + statusOrException;
+ return id.toString() + " " + statusOrException;
}
@Override
abstract void setReady();
abstract void refute();
- abstract void setPending();
+ abstract void setPending(QuerySupport querySupport);
abstract void discard();
abstract void except(Throwable t);
abstract void clearResult(QuerySupport support);
}
@Override
- public void setPending() {
- statusOrException = PENDING;
+ public void setPending(QuerySupport querySupport) {
+ statusOrException = PENDING;
+ clearResult(querySupport);
}
@Override
@Override
void prepareRecompute(QuerySupport querySupport) {
- setPending();
- clearResult(querySupport);
+ setPending(querySupport);
}
@Override
public class CodeGen {
- int indent = 4;
-
- String[] signatureR1RelationInfo = { "int r", "r", "keyR", "long", "InternalProcedure<RelationInfo>", "entry.id" };
- String[] signatureR1Bytes = { "int r", "r", "keyR", "long", "InternalProcedure<byte[]>", "entry.id" };
- String[] signatureR1IntSet = { "int r", "r", "keyR", "long", "InternalProcedure<IntSet>", "entry.id" };
- String[] signatureR1IP = { "int r", "r", "keyR", "long", "IntProcedure", "entry.id" };
- String[] signatureR2IP = { "int r1, int r2", "r1,r2", "keyR2", "long", "IntProcedure", "entry.id" };
- String[] signatureR2TIP = { "int r1, int r2", "r1,r2", "keyR2", "long", "TripleIntProcedure", "entry.id" };
- String[] signatureID1 = { "String id", "id", "keyID", "String", "InternalProcedure<Integer>", "entry.id" };
- String[] signatureID2 = { "String id", "id", "keyID", "String", "InternalProcedure<TObjectIntHashMap<String>>", "entry.id" };
- String[] signatureChildMap = { "int r", "r", "keyR", "long", "InternalProcedure<ObjectResourceIdMap<String>>", "entry.id" };
- String[] signatureRead = { "Read<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
- String[] signatureAsyncRead = { "AsyncRead<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
- String[] signatureMultiRead = { "MultiRead<?> r", "r", "id", "long", "SyncMultiProcedure", "entry.request" };
- String[] signatureAsyncMultiRead = { "AsyncMultiRead<?> r", "r", "id", "long", "AsyncMultiProcedure", "entry.request" };
- String[] signatureExternalRead = { "ExternalRead<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
-
- private void line(StringBuilder content, String line) {
- for(int i=0;i<indent;i++)
- content.append(" ");
- content.append(line);
- content.append("\n");
- }
-
- public void generateQuery(StringBuilder content, String clazz, String[] signature, boolean runnerShortcut, boolean genReturn) {
- generateGetOrCreate(content, clazz, signature);
- generateRemove(content, clazz, signature);
- generateRunner(content, clazz, signature, runnerShortcut, genReturn);
- }
-
- public void generateRunner(StringBuilder content, String clazz, String[] signature, boolean shortcut, boolean genReturn) {
-
- line(content, "public static " + (genReturn ? "Object" : "void") + " runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, final " + signature[4] + " procedure) throws DatabaseException {");
- line(content, " QueryCache cache = graph.processor.cache;");
- if(shortcut) {
- line(content, " if(parent == null && listener == null && !cache.shouldCache(graph.processor, " + signature[1] + ")) {");
- line(content, " if (SINGLE) {");
- line(content, " " + clazz + " e = cache.peek" + clazz + "(" + signature[1] + ");");
- line(content, " if (e != null && e.isReady()) {");
- line(content, " " + (genReturn ? "return " : "") + "e.performFromCache(graph, procedure);");
- if(!genReturn) line(content, " return;");
- line(content, " }");
- line(content, " }");
- line(content, " " + (genReturn ? "return " : "") + clazz + ".computeForEach(graph, " + signature[1] + ", null, procedure);");
- if(!genReturn) line(content, " return;");
- line(content, " }");
- }
- line(content, " " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(graph, " + signature[1] + ");");
- line(content, " " + signature[4] + " procedure_ = procedure != null ? procedure : emptyProcedure" + clazz + ";");
- line(content, " ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);");
- line(content, " if(entry.isReady()) " + (genReturn ? "return " : "") + "entry.performFromCache(graph, procedure_);");
- line(content, " else {");
- line(content, " assert(entry.isPending());");
- if(shortcut) line(content, " " + (genReturn ? "Object result = " : "") + clazz + ".computeForEach(graph, " + signature[1] + ", entry, procedure_);");
- else line(content, " entry.compute(graph, procedure_);");
- line(content, " if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());");
- if(genReturn) line(content, " return result;");
- line(content, " }");
- line(content, "}");
- line(content, "");
+ int indent = 4;
+
+ class GenerationInfo {
+ String p1;
+ String keyName;
+ String keyToId;
+ String procedure;
+ boolean useNeedsToBlock;
+ String entryCreationArguments;
+ GenerationInfo(String p1, String keyName, String keyToId, String p4, String procedure, String entryCreationArguments, boolean useNeedsToBlock) {
+ this.p1 = p1;
+ this.keyName = keyName;
+ this.keyToId = keyToId;
+ this.procedure = procedure;
+ this.useNeedsToBlock = useNeedsToBlock;
+ this.entryCreationArguments = entryCreationArguments;
+ }
+ }
+
+ GenerationInfo signatureR1RelationInfo = new GenerationInfo ( "int r", "r", "keyR", "long", "InternalProcedure<RelationInfo>", "", false );
+ GenerationInfo signatureR1Bytes = new GenerationInfo ( "int r", "r", "keyR", "long", "InternalProcedure<byte[]>", "", false );
+ GenerationInfo signatureR1IntSet = new GenerationInfo ( "int r", "r", "keyR", "long", "InternalProcedure<IntSet>", "", false );
+ GenerationInfo signatureR1IP = new GenerationInfo ( "int r", "r", "keyR", "long", "IntProcedure", "", false );
+ GenerationInfo signatureR2IP = new GenerationInfo ( "int r1, int r2", "r1,r2", "keyR2", "long", "IntProcedure", "", false );
+ GenerationInfo signatureR2TIP = new GenerationInfo ( "int r1, int r2", "r1,r2", "keyR2", "long", "TripleIntProcedure", "", false );
+ GenerationInfo signatureID1 = new GenerationInfo ( "String id", "id", "keyID", "String", "InternalProcedure<Integer>", "", false );
+ GenerationInfo signatureID2 = new GenerationInfo ( "String id", "id", "keyID", "String", "InternalProcedure<TObjectIntHashMap<String>>", "", false );
+ GenerationInfo signatureChildMap = new GenerationInfo ( "int r", "r", "keyR", "long", "InternalProcedure<ObjectResourceIdMap<String>>", "", false );
+ GenerationInfo signatureRead = new GenerationInfo ( "Read<?> r", "r", "id", "long", "AsyncProcedure", "", true );
+ GenerationInfo signatureAsyncRead = new GenerationInfo ( "AsyncRead<?> r", "r", "id", "long", "AsyncProcedure", "", true );
+ GenerationInfo signatureMultiRead = new GenerationInfo ( "MultiRead<?> r", "r", "id", "long", "SyncMultiProcedure", "", false );
+ GenerationInfo signatureAsyncMultiRead = new GenerationInfo ( "AsyncMultiRead<?> r", "r", "id", "long", "AsyncMultiProcedure", "", false );
+ GenerationInfo signatureExternalRead = new GenerationInfo ( "ExternalRead<?> r", "r", "id", "long", "AsyncProcedure", ", graph", false );
+
+ private void line(StringBuilder content, String line) {
+ for(int i=0;i<indent;i++)
+ content.append(" ");
+ content.append(line);
+ content.append("\n");
+ }
+
+ public void generateQuery(StringBuilder content, String clazz, GenerationInfo signature, boolean runnerShortcut, boolean genReturn) {
+ generateGetOrCreate(content, clazz, signature);
+ generateRemove(content, clazz, signature);
+ generateRunner(content, clazz, signature, runnerShortcut, genReturn);
+ }
+
+ public void generateRunner(StringBuilder content, String clazz, GenerationInfo signature, boolean shortcut, boolean genReturn) {
+
+ line(content, "public static " + (genReturn ? "Object" : "void") + " runner" + clazz + "(ReadGraphImpl graph, " + signature.p1 + ", CacheEntry parent, ListenerBase listener, final " + signature.procedure + " procedure" + (signature.useNeedsToBlock ? ", boolean needsToBlock" : "") + ") throws DatabaseException {");
+ line(content, " QueryCache cache = graph.processor.cache;");
+ if(shortcut) {
+ line(content, " if(parent == null && listener == null && !cache.shouldCache(graph.processor, " + signature.keyName + ")) {");
+ line(content, " if (SINGLE) {");
+ line(content, " " + clazz + " e = cache.peek" + clazz + "(" + signature.keyName + ");");
+ line(content, " if (e != null && e.isReady()) {");
+ line(content, " " + (genReturn ? "return " : "") + "e.performFromCache(graph, procedure);");
+ if(!genReturn) line(content, " return;");
+ line(content, " }");
+ line(content, " }");
+ line(content, " " + (genReturn ? "return " : "") + clazz + ".computeForEach(graph, " + signature.keyName + ", null, procedure" + (signature.useNeedsToBlock ? ", needsToBlock" : "") + ");");
+ if(!genReturn) line(content, " return;");
+ line(content, " }");
+ }
+ if(signature.useNeedsToBlock) {
+ line(content, " " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(graph, " + signature.keyName + ", needsToBlock);");
+ line(content, " if(entry == null) {");
+ line(content, " graph.processor.schedule(new SessionTask(graph) {");
+ line(content, " @Override");
+ line(content, " public void run0(int thread) {");
+ line(content, " try {");
+ line(content, " runner" + clazz + "(graph, r, parent, listener, procedure, needsToBlock);");
+ line(content, " } catch (DatabaseException e) {");
+ line(content, " Logger.defaultLogError(e);");
+ line(content, " }");
+ line(content, " }");
+ line(content, " });");
+ line(content, " return null;");
+ line(content, " }");
+ } else {
+ line(content, " " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(graph, " + signature.keyName + ");");
+ }
+ line(content, " " + signature.procedure + " procedure_ = procedure != null ? procedure : emptyProcedure" + clazz + ";");
+ line(content, " ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);");
+ line(content, " if(entry.isReady()) " + (genReturn ? "return " : "") + "entry.performFromCache(graph, procedure_);");
+ line(content, " else {");
+ line(content, " assert(entry.isPending());");
+ if(shortcut) line(content, " " + (genReturn ? "Object result = " : "") + clazz + ".computeForEach(graph, " + signature.keyName + ", entry, procedure_" + (signature.useNeedsToBlock ? ", needsToBlock" : "") + ");");
+ else line(content, " entry.compute(graph, procedure_);");
+ line(content, " if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());");
+ if(genReturn) line(content, " return result;");
+ line(content, " }");
+ line(content, "}");
+ line(content, "");
+
+ String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
+
+ line(content, "private " + clazz + " peek" + clazz + "(" + signature.p1 + ") {");
+ line(content, " synchronized(" + lower +"Map) {");
+ line(content, " return (" + clazz + ") " + lower + "Map.get(" + signature.keyName + ");");
+ line(content, " }");
+ line(content, "}");
+ line(content, "");
+ }
+
+ public void generateRemove(StringBuilder content, String clazz, GenerationInfo signature) {
+
+ String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
+
+ line(content, "void remove(" + clazz + " entry) {");
+ line(content, " synchronized(" + lower + "Map) {");
+ line(content, " " + lower + "Map.remove(entry.id);");
+ line(content, " }");
+ line(content, "}");
+ line(content, "");
+
+ }
+
+ public void generateGetOrCreate(StringBuilder content, String clazz, GenerationInfo signature) {
String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
- line(content, "private " + clazz + " peek" + clazz + "(" + signature[0] + ") {");
- line(content, " synchronized(" + lower +"Map) {");
- line(content, " return (" + clazz + ") " + lower + "Map.get(" + signature[1] + ");");
- line(content, " }");
- line(content, "}");
- line(content, "");
- }
-
- public void generateRemove(StringBuilder content, String clazz, String[] signature) {
-
- String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
-
- line(content, "void remove(" + clazz + " entry) {");
- line(content, " synchronized(" + lower + "Map) {");
- line(content, " " + lower + "Map.remove(" + signature[5] + ");");
- line(content, " }");
- line(content, "}");
- line(content, "");
-
- }
-
- public void generateGetOrCreate(StringBuilder content, String clazz, String[] signature) {
-
- String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
-
- line(content, "" + clazz + " getOrCreate" + clazz + "(ReadGraphImpl graph, " + signature[0] + ") throws DatabaseException {");
- line(content, " " + clazz + " existing = null;");
- line(content, " synchronized(" + lower + "Map) {");
- line(content, " existing = (" + clazz + ")" + lower + "Map.get(" + signature[1] + ");");
- line(content, " if(existing == null) {");
- line(content, " existing = new " + clazz + "(" + signature[1] + ");");
- line(content, " existing.clearResult(querySupport);");
- line(content, " existing.setPending();");
- line(content, " " + lower + "Map.put(" + signature[2] + "(" + signature[1] + "), existing);");
- line(content, " size++;");
- line(content, " return existing;");
- line(content, " }");
- line(content, " if(existing.requiresComputation()) {");
- line(content, " existing.setPending();");
- line(content, " return existing;");
- line(content, " }");
- line(content, " }");
- line(content, " if(existing.isPending()) waitPending(graph, existing);");
- line(content, " return existing;");
- line(content, "}");
- line(content, "");
-
- }
-
- public void generate() {
-
- URL classLocation = CodeGen.class.getResource(".");
- if (classLocation != null) {
- if (classLocation.getProtocol().equals("file")) {
- try {
- URL resource = new URL(classLocation, ".");
- File path = new File(URLDecoder.decode(resource.getPath(), "UTF-8"));
- String target = path.getAbsolutePath().replace("\\", "/");
- target = target.replace("/bin/", "/src/") + "/QueryCache.java";
- System.err.println("target=" + target);
- File source = new File(target);
- StringBuilder content = new StringBuilder();
- content.append("package org.simantics.db.impl.query;\n");
- content.append("\n");
-
- content.append("import org.simantics.db.ObjectResourceIdMap;\n");
- content.append("import org.simantics.db.RelationInfo;\n");
- content.append("import org.simantics.db.common.utils.Logger;\n");
- content.append("import org.simantics.db.exception.DatabaseException;\n");
- content.append("import org.simantics.db.impl.graph.ReadGraphImpl;\n");
- content.append("import org.simantics.db.impl.procedure.InternalProcedure;\n");
- content.append("import org.simantics.db.impl.query.QueryProcessor.SessionTask;\n");
- content.append("import org.simantics.db.procedure.AsyncMultiProcedure;\n");
- content.append("import org.simantics.db.procedure.AsyncProcedure;\n");
- content.append("import org.simantics.db.procedure.ListenerBase;\n");
- content.append("import org.simantics.db.procedure.SyncMultiProcedure;\n");
- content.append("import org.simantics.db.request.AsyncMultiRead;\n");
- content.append("import org.simantics.db.request.AsyncRead;\n");
- content.append("import org.simantics.db.request.ExternalRead;\n");
- content.append("import org.simantics.db.request.MultiRead;\n");
- content.append("import org.simantics.db.request.Read;\n");
- content.append("\n");
-
- content.append("public class QueryCache extends QueryCacheBase {\n");
- content.append("\n");
-
- line(content, "private static final boolean SINGLE = true;");
- content.append("\n");
-
- line(content,"public QueryCache(QuerySupport querySupport, int threads) {");
- line(content," super(querySupport, threads);");
- line(content,"}");
- content.append("\n");
-
- generateQuery(content, "Objects", signatureR2IP, true, false);
- generateQuery(content, "Statements", signatureR2TIP, true, false);
- generateQuery(content, "DirectObjects", signatureR2IP, true, false);
- generateQuery(content, "RelationInfoQuery", signatureR1RelationInfo, true, false);
- generateQuery(content, "URIToResource", signatureID1, true, false);
- generateQuery(content, "ValueQuery", signatureR1Bytes, true, false);
- generateQuery(content, "OrderedSet", signatureR1IP, true, false);
- generateQuery(content, "PrincipalTypes", signatureR1IP, true, false);
- generateQuery(content, "DirectPredicates", signatureR1IntSet, true, false);
- generateQuery(content, "Predicates", signatureR1IntSet, true, false);
- generateQuery(content, "ReadEntry", signatureRead, true, true);
- generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true, true);
- generateQuery(content, "Types", signatureR1IntSet, true, false);
- generateQuery(content, "ChildMap", signatureChildMap, true, false);
- generateQuery(content, "TypeHierarchy", signatureR1IntSet, true, false);
- generateQuery(content, "SuperTypes", signatureR1IntSet, true, false);
- generateQuery(content, "SuperRelations", signatureR1IntSet, true, false);
-
- generateQuery(content, "AssertedPredicates", signatureR1IP, false, false);
- generateQuery(content, "AssertedStatements", signatureR2TIP, false, false);
- generateQuery(content, "DirectSuperRelations", signatureR1IP, false, false);
- generateQuery(content, "MultiReadEntry", signatureMultiRead, false, false);
- generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false, false);
- generateQuery(content, "ExternalReadEntry", signatureExternalRead, false, false);
- content.append("}\n");
- FileUtils.writeFile(source, content.toString().getBytes());
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- }
-
- public static void main(String[] args) {
- new CodeGen().generate();
- }
+ line(content, "" + clazz + " getOrCreate" + clazz + "(ReadGraphImpl graph, " + signature.p1 + (signature.useNeedsToBlock ? ", boolean needsToBlock" : "") + ") throws DatabaseException {");
+ line(content, " " + clazz + " existing = null;");
+ line(content, " synchronized(" + lower + "Map) {");
+ line(content, " existing = (" + clazz + ")" + lower + "Map.get(" + signature.keyName + ");");
+ line(content, " if(existing == null) {");
+ line(content, " existing = new " + clazz + "(" + signature.keyName + signature.entryCreationArguments + ");");
+ line(content, " existing.setPending(querySupport);");
+ line(content, " " + lower + "Map.put(" + signature.keyToId + "(" + signature.keyName + "), existing);");
+ line(content, " size++;");
+ line(content, " return existing;");
+ line(content, " }");
+ line(content, " if(existing.requiresComputation()) {");
+ line(content, " existing.setPending(querySupport);");
+ line(content, " return existing;");
+ line(content, " }");
+ line(content, " }");
+ line(content, " if(existing.isPending()) {");
+ if(signature.useNeedsToBlock) {
+ line(content, " if(needsToBlock)");
+ line(content, " waitPending(graph, existing);");
+ line(content, " else {");
+ line(content, " return null;");
+ line(content, " }");
+ } else {
+ line(content, " waitPending(graph, existing);");
+ }
+ line(content, " }");
+ line(content, " return existing;");
+ line(content, "}");
+ line(content, "");
+
+ }
+
+ public void generate() {
+
+ URL classLocation = CodeGen.class.getResource(".");
+ if (classLocation != null) {
+ if (classLocation.getProtocol().equals("file")) {
+ try {
+ URL resource = new URL(classLocation, ".");
+ File path = new File(URLDecoder.decode(resource.getPath(), "UTF-8"));
+ String target = path.getAbsolutePath().replace("\\", "/");
+ target = target.replace("/bin/", "/src/") + "/QueryCache.java";
+ System.err.println("target=" + target);
+ File source = new File(target);
+ StringBuilder content = new StringBuilder();
+ content.append("package org.simantics.db.impl.query;\n");
+ content.append("\n");
+
+ content.append("import org.simantics.db.ObjectResourceIdMap;\n");
+ content.append("import org.simantics.db.RelationInfo;\n");
+ content.append("import org.simantics.db.common.utils.Logger;\n");
+ content.append("import org.simantics.db.exception.DatabaseException;\n");
+ content.append("import org.simantics.db.impl.graph.ReadGraphImpl;\n");
+ content.append("import org.simantics.db.impl.procedure.InternalProcedure;\n");
+ content.append("import org.simantics.db.impl.query.QueryProcessor.SessionTask;\n");
+ content.append("import org.simantics.db.procedure.AsyncMultiProcedure;\n");
+ content.append("import org.simantics.db.procedure.AsyncProcedure;\n");
+ content.append("import org.simantics.db.procedure.ListenerBase;\n");
+ content.append("import org.simantics.db.procedure.SyncMultiProcedure;\n");
+ content.append("import org.simantics.db.request.AsyncMultiRead;\n");
+ content.append("import org.simantics.db.request.AsyncRead;\n");
+ content.append("import org.simantics.db.request.ExternalRead;\n");
+ content.append("import org.simantics.db.request.MultiRead;\n");
+ content.append("import org.simantics.db.request.Read;\n");
+ content.append("\n");
+
+ content.append("public class QueryCache extends QueryCacheBase {\n");
+ content.append("\n");
+
+ line(content, "private static final boolean SINGLE = false;");
+ content.append("\n");
+
+ line(content,"public QueryCache(QuerySupport querySupport, int threads) {");
+ line(content," super(querySupport, threads);");
+ line(content,"}");
+ content.append("\n");
+
+ generateQuery(content, "Objects", signatureR2IP, true, false);
+ generateQuery(content, "Statements", signatureR2TIP, true, false);
+ generateQuery(content, "DirectObjects", signatureR2IP, true, false);
+ generateQuery(content, "RelationInfoQuery", signatureR1RelationInfo, true, false);
+ generateQuery(content, "URIToResource", signatureID1, true, false);
+ generateQuery(content, "ValueQuery", signatureR1Bytes, true, false);
+ generateQuery(content, "OrderedSet", signatureR1IP, true, false);
+ generateQuery(content, "PrincipalTypes", signatureR1IP, true, false);
+ generateQuery(content, "DirectPredicates", signatureR1IntSet, true, false);
+ generateQuery(content, "Predicates", signatureR1IntSet, true, false);
+ generateQuery(content, "ReadEntry", signatureRead, true, true);
+ generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true, true);
+ generateQuery(content, "Types", signatureR1IntSet, true, false);
+ generateQuery(content, "ChildMap", signatureChildMap, true, false);
+ generateQuery(content, "TypeHierarchy", signatureR1IntSet, true, false);
+ generateQuery(content, "SuperTypes", signatureR1IntSet, true, false);
+ generateQuery(content, "SuperRelations", signatureR1IntSet, true, false);
+
+ generateQuery(content, "AssertedPredicates", signatureR1IP, false, false);
+ generateQuery(content, "AssertedStatements", signatureR2TIP, false, false);
+ generateQuery(content, "DirectSuperRelations", signatureR1IP, false, false);
+ generateQuery(content, "MultiReadEntry", signatureMultiRead, false, false);
+ generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false, false);
+ generateQuery(content, "ExternalReadEntry", signatureExternalRead, false, false);
+ content.append("}\n");
+ FileUtils.writeFile(source, content.toString().getBytes());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ public static void main(String[] args) {
+ new CodeGen().generate();
+ }
}
final LinkedList<T> items = new LinkedList<T>();
- protected ExternalRead<T> request;
+ protected ExternalRead<T> id;
protected ReadGraphImpl graph;
protected boolean registered = false;
@Override
int makeHash() {
- return request.hashCode();
+ return id.hashCode();
}
@Override
public Object getOriginalRequest() {
- return request;
+ return id;
}
@Override
@Override
public void discard() {
- request.unregistered();
- request = null;
+ id.unregistered();
+ id = null;
graph = null;
super.discard();
}
@Override
- public void setPending() {
+ public void setPending(QuerySupport querySupport) {
//if(result != NO_RESULT) {
//new Exception("result = " + result).printStackTrace();
//}
public ExternalReadEntry(ExternalRead<T> request, ReadGraphImpl graph) {
assert request != null;
- this.request = request;
+ this.id = request;
this.graph = graph;
}
}
// Reschedule
if(!items.isEmpty()) {
- graph.processor.updatePrimitive(request);
+ graph.processor.updatePrimitive(id);
}
}
@Override
public String toString() {
- if(request == null) return "DISCARDED ExternalRead";
- else return request.toString();
+ if(id == null) return "DISCARDED ExternalRead";
+ else return id.toString();
}
};
@Override
public String toString() {
- if(request == null) return "DISCARDED ExternalRead " + System.identityHashCode(this);
- else return request.toString() + " " + + System.identityHashCode(this);
+ if(id == null) return "DISCARDED ExternalRead " + System.identityHashCode(this);
+ else return id.toString() + " " + + System.identityHashCode(this);
}
@Override
ReadGraphImpl queryGraph = graph.withParent(this);
if(!registered) {
- request.register(graph, this);
+ id.register(graph, this);
registered = true;
}
- queryGraph.asyncBarrier.waitBarrier(request, graph);
+ queryGraph.asyncBarrier.waitBarrier(id, graph);
} catch (Throwable t) {
synchronized(items) {
items.addLast(result);
- graph.processor.updatePrimitive(request);
+ graph.processor.updatePrimitive(id);
// TODO: implement flags/logic in ExternalRead to state that all but the latest request result can be evaporated
// In some cases where data is produced really fast this might be necessary but currently this queueing will do.
}
private static final Logger LOGGER = LoggerFactory.getLogger(MultiReadEntry.class);
- protected MultiRead<T> request;
+ protected MultiRead<T> id;
MultiReadEntry(MultiRead<T> request) {
- this.request = request;
+ this.id = request;
}
@Override
int makeHash() {
- return request.hashCode();
+ return id.hashCode();
}
@Override
public Object getOriginalRequest() {
- return request;
+ return id;
}
@Override
public void discard() {
super.discard();
- request = null;
+ id = null;
setResult(null);
}
try {
- request.perform(graph , new SyncMultiProcedure<T>() {
+ id.perform(graph , new SyncMultiProcedure<T>() {
@Override
public void execute(ReadGraph graph, T result) {
@Override
public String toString() {
- if(request == null) return "DISCARDED";
- else return request.toString() + statusOrException;
+ if(id == null) return "DISCARDED";
+ else return id.toString() + statusOrException;
}
};
@Override
public String toString() {
- if(request == null) return "DISCARDED";
- else return request.toString() + statusOrException;
+ if(id == null) return "DISCARDED";
+ else return id.toString() + statusOrException;
}
public Object compute(ReadGraphImpl graph, SyncMultiProcedure<T> procedure) throws DatabaseException {
- return graph.processor.cache.performQuery(graph, request, this, procedure);
+ return graph.processor.cache.performQuery(graph, id, this, procedure);
}
}
public class QueryCache extends QueryCacheBase {
- // Using QueryChaching breaks Diagram Editor (and probably something else).
- private static final boolean SINGLE = false;
-
+ private static final boolean SINGLE = false;
+
public QueryCache(QuerySupport querySupport, int threads) {
super(querySupport, threads);
}
existing = (Objects)objectsMap.get(r1,r2);
if(existing == null) {
existing = new Objects(r1,r2);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
objectsMap.put(keyR2(r1,r2), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (Statements)statementsMap.get(r1,r2);
if(existing == null) {
existing = new Statements(r1,r2);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
statementsMap.put(keyR2(r1,r2), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (DirectObjects)directObjectsMap.get(r1,r2);
if(existing == null) {
existing = new DirectObjects(r1,r2);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
directObjectsMap.put(keyR2(r1,r2), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (RelationInfoQuery)relationInfoQueryMap.get(r);
if(existing == null) {
existing = new RelationInfoQuery(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
relationInfoQueryMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (URIToResource)uRIToResourceMap.get(id);
if(existing == null) {
existing = new URIToResource(id);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
uRIToResourceMap.put(keyID(id), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (ValueQuery)valueQueryMap.get(r);
if(existing == null) {
existing = new ValueQuery(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
valueQueryMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (OrderedSet)orderedSetMap.get(r);
if(existing == null) {
existing = new OrderedSet(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
orderedSetMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (PrincipalTypes)principalTypesMap.get(r);
if(existing == null) {
existing = new PrincipalTypes(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
principalTypesMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (DirectPredicates)directPredicatesMap.get(r);
if(existing == null) {
existing = new DirectPredicates(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
directPredicatesMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (Predicates)predicatesMap.get(r);
if(existing == null) {
existing = new Predicates(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
predicatesMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (ReadEntry)readEntryMap.get(r);
if(existing == null) {
existing = new ReadEntry(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
readEntryMap.put(id(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
if(existing.isPending()) {
- if(needsToBlock) waitPending(graph, existing);
- else return null;
+ if(needsToBlock)
+ waitPending(graph, existing);
+ else {
+ return null;
+ }
}
return existing;
}
-
void remove(ReadEntry entry) {
synchronized(readEntryMap) {
- readEntryMap.remove(entry.request);
+ readEntryMap.remove(entry.id);
}
}
- public static Object runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, final boolean needsToBlock) throws DatabaseException {
+ public static Object runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean needsToBlock) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
if (SINGLE) {
return e.performFromCache(graph, procedure);
}
}
- return ReadEntry.computeForEach(graph, r, null, procedure);
+ return ReadEntry.computeForEach(graph, r, null, procedure, needsToBlock);
}
ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(graph, r, needsToBlock);
if(entry == null) {
- graph.processor.schedule(new SessionTask(graph) {
- @Override
- public void run0(int thread) {
- try {
- runnerReadEntry(graph, r, parent, listener, procedure, needsToBlock);
- } catch (DatabaseException e) {
- Logger.defaultLogError(e);
- }
- }
- });
- return null;
+ graph.processor.schedule(new SessionTask(graph) {
+ @Override
+ public void run0(int thread) {
+ try {
+ runnerReadEntry(graph, r, parent, listener, procedure, needsToBlock);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
+ }
+ });
+ return null;
}
AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureReadEntry;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
if(entry.isReady()) return entry.performFromCache(graph, procedure_);
else {
assert(entry.isPending());
- Object result = ReadEntry.computeForEach(graph, r, entry, procedure_);
+ Object result = ReadEntry.computeForEach(graph, r, entry, procedure_, needsToBlock);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
return result;
}
}
-
private ReadEntry peekReadEntry(Read<?> r) {
synchronized(readEntryMap) {
existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
if(existing == null) {
existing = new AsyncReadEntry(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
asyncReadEntryMap.put(id(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
if(existing.isPending()) {
- if(needsToBlock) waitPending(graph, existing);
- else return null;
+ if(needsToBlock)
+ waitPending(graph, existing);
+ else {
+ return null;
+ }
}
return existing;
}
-
void remove(AsyncReadEntry entry) {
synchronized(asyncReadEntryMap) {
- asyncReadEntryMap.remove(entry.request);
+ asyncReadEntryMap.remove(entry.id);
}
}
- public static Object runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, final boolean needsToBlock) throws DatabaseException {
+ public static Object runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean needsToBlock) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
if (SINGLE) {
}
AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph, r, needsToBlock);
if(entry == null) {
- graph.processor.schedule(new SessionTask(graph) {
- @Override
- public void run0(int thread) {
- try {
- runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
- } catch (DatabaseException e) {
- Logger.defaultLogError(e);
- }
- }
- });
- return null;
+ graph.processor.schedule(new SessionTask(graph) {
+ @Override
+ public void run0(int thread) {
+ try {
+ runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
+ }
+ });
+ return null;
}
AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncReadEntry;
ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
return result;
}
}
-
private AsyncReadEntry peekAsyncReadEntry(AsyncRead<?> r) {
synchronized(asyncReadEntryMap) {
existing = (Types)typesMap.get(r);
if(existing == null) {
existing = new Types(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
typesMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (ChildMap)childMapMap.get(r);
if(existing == null) {
existing = new ChildMap(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
childMapMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (TypeHierarchy)typeHierarchyMap.get(r);
if(existing == null) {
existing = new TypeHierarchy(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
typeHierarchyMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (SuperTypes)superTypesMap.get(r);
if(existing == null) {
existing = new SuperTypes(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
superTypesMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (SuperRelations)superRelationsMap.get(r);
if(existing == null) {
existing = new SuperRelations(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
superRelationsMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (AssertedPredicates)assertedPredicatesMap.get(r);
if(existing == null) {
existing = new AssertedPredicates(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
assertedPredicatesMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (AssertedStatements)assertedStatementsMap.get(r1,r2);
if(existing == null) {
existing = new AssertedStatements(r1,r2);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
assertedStatementsMap.put(keyR2(r1,r2), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (DirectSuperRelations)directSuperRelationsMap.get(r);
if(existing == null) {
existing = new DirectSuperRelations(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
directSuperRelationsMap.put(keyR(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
existing = (MultiReadEntry)multiReadEntryMap.get(r);
if(existing == null) {
existing = new MultiReadEntry(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
multiReadEntryMap.put(id(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
void remove(MultiReadEntry entry) {
synchronized(multiReadEntryMap) {
- multiReadEntryMap.remove(entry.request);
+ multiReadEntryMap.remove(entry.id);
}
}
existing = (AsyncMultiReadEntry)asyncMultiReadEntryMap.get(r);
if(existing == null) {
existing = new AsyncMultiReadEntry(r);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
asyncMultiReadEntryMap.put(id(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
void remove(AsyncMultiReadEntry entry) {
synchronized(asyncMultiReadEntryMap) {
- asyncMultiReadEntryMap.remove(entry.request);
+ asyncMultiReadEntryMap.remove(entry.id);
}
}
existing = (ExternalReadEntry)externalReadEntryMap.get(r);
if(existing == null) {
existing = new ExternalReadEntry(r, graph);
- existing.clearResult(querySupport);
- existing.setPending();
+ existing.setPending(querySupport);
externalReadEntryMap.put(id(r), existing);
size++;
return existing;
}
if(existing.requiresComputation()) {
- existing.setPending();
+ existing.setPending(querySupport);
return existing;
}
}
- if(existing.isPending()) waitPending(graph, existing);
+ if(existing.isPending()) {
+ waitPending(graph, existing);
+ }
return existing;
}
-
void remove(ExternalReadEntry entry) {
synchronized(externalReadEntryMap) {
- externalReadEntryMap.remove(entry.request);
+ externalReadEntryMap.remove(entry.id);
}
}
}
@Override
- public void setPending() {
+ public void setPending(QuerySupport querySupport) {
// TODO Auto-generated method stub
}
for(CacheEntry entry : workarea.keySet()) {
Class<?> clazz = entry.getClass();
- if(entry instanceof ReadEntry) clazz = ((ReadEntry)entry).request.getClass();
- else if(entry instanceof MultiReadEntry) clazz = ((MultiReadEntry)entry).request.getClass();
- else if(entry instanceof AsyncReadEntry) clazz = ((AsyncReadEntry)entry).request.getClass();
- else if(entry instanceof AsyncMultiReadEntry) clazz = ((AsyncMultiReadEntry)entry).request.getClass();
- else if(entry instanceof ExternalReadEntry) clazz = ((ExternalReadEntry)entry).request.getClass();
+ if(entry instanceof ReadEntry) clazz = ((ReadEntry)entry).id.getClass();
+ else if(entry instanceof MultiReadEntry) clazz = ((MultiReadEntry)entry).id.getClass();
+ else if(entry instanceof AsyncReadEntry) clazz = ((AsyncReadEntry)entry).id.getClass();
+ else if(entry instanceof AsyncMultiReadEntry) clazz = ((AsyncMultiReadEntry)entry).id.getClass();
+ else if(entry instanceof ExternalReadEntry) clazz = ((ExternalReadEntry)entry).id.getClass();
Integer c = counts.get(clazz);
if(c == null) counts.put(clazz, -1);
else counts.put(clazz, c-1);
return false;
}
- if (entry.isRefuted()) {
- if (Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
- System.err.print("R");
- for (int i = 0; i < e.indent; i++)
- System.err.print(" ");
- System.err.println(entry.getQuery());
- }
- }
- return false;
- }
+// if (entry.isRefuted()) {
+// if (Development.DEVELOPMENT) {
+// if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
+// System.err.print("R");
+// for (int i = 0; i < e.indent; i++)
+// System.err.print(" ");
+// System.err.println(entry.getQuery());
+// }
+// }
+// return false;
+// }
if (entry.isExcepted()) {
if (Development.DEVELOPMENT) {
private Object primitiveUpdateLock = new Object();
private THashSet scheduledPrimitiveUpdates = new THashSet();
+ private ArrayList<CacheEntry> refutations = new ArrayList<>();
+
+ private void markForUpdate(ReadGraphImpl graph, CacheEntry e) {
+ e.refute();
+ refutations.add(e);
+ }
+
+ private void updateRefutations(ReadGraphImpl graph) {
+
+ for(CacheEntry e : refutations)
+ update(graph, e);
+
+ refutations.clear();
+
+ }
+
public void performDirtyUpdates(final ReadGraphImpl graph) {
cache.dirty = false;
final int subject = (int)(arg0 >>> 32);
final int predicate = (int)(arg0 & 0xffffffff);
- for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) update(graph, o);
- for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) update(graph, o);
- for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) update(graph, o);
+ for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
+ for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
+ for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) markForUpdate(graph, o);
if(predicate == instanceOf || predicate == inherits || predicate == subrelationOf) {
PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, subject);
- if(principalTypes != null) update(graph, principalTypes);
+ if(principalTypes != null) markForUpdate(graph, principalTypes);
Types types = QueryCache.entryTypes(QueryProcessor.this, subject);
- if(types != null) update(graph, types);
+ if(types != null) markForUpdate(graph, types);
}
if(predicate == subrelationOf) {
SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, subject);
- if(superRelations != null) update(graph, superRelations);
+ if(superRelations != null) markForUpdate(graph, superRelations);
}
DirectPredicates dp = QueryCache.entryDirectPredicates(QueryProcessor.this, subject);
- if(dp != null) update(graph, dp);
+ if(dp != null) markForUpdate(graph, dp);
OrderedSet os = QueryCache.entryOrderedSet(QueryProcessor.this, predicate);
- if(os != null) update(graph, os);
+ if(os != null) markForUpdate(graph, os);
+ updateRefutations(graph);
+
scheduledObjectUpdates.clear();
+
+ if (Development.DEVELOPMENT) {
+ if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
+ System.err.println("== Query update ends ==");
+ }
+ }
+
return;
}
int arg0 = scheduledValueUpdates.getFirst();
ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, arg0);
- if(valueQuery != null) update(graph, valueQuery);
+ if(valueQuery != null) markForUpdate(graph, valueQuery);
+
+ updateRefutations(graph);
scheduledValueUpdates.clear();
+
+ if (Development.DEVELOPMENT) {
+ if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
+ System.err.println("== Query update ends ==");
+ }
+ }
+
return;
}
scheduledPrimitiveUpdates = new THashSet();
}
- primitiveUpdates.forEach(new TObjectProcedure() {
-
- @Override
- public boolean execute(Object arg0) {
-
- ExternalReadEntry query = (ExternalReadEntry)cache.externalReadEntryMap.get(arg0);
- if (query != null) {
- boolean listening = update(graph, query);
- if (!listening && !query.hasParents()) {
- cache.externalReadEntryMap.remove(arg0);
- query.discard();
- }
- }
- return true;
- }
-
- });
-
scheduledValueUpdates.forEach(new TIntProcedure() {
@Override
public boolean execute(int arg0) {
ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, arg0);
- if(valueQuery != null) update(graph, valueQuery);
+ if(valueQuery != null) markForUpdate(graph, valueQuery);
return true;
}
public boolean execute(int resource) {
ValueQuery valueQuery = QueryCache.entryValueQuery(QueryProcessor.this, resource);
- if(valueQuery != null) update(graph, valueQuery);
+ if(valueQuery != null) markForUpdate(graph, valueQuery);
PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, resource);
- if(principalTypes != null) update(graph, principalTypes);
+ if(principalTypes != null) markForUpdate(graph, principalTypes);
Types types = QueryCache.entryTypes(QueryProcessor.this, resource);
- if(types != null) update(graph, types);
+ if(types != null) markForUpdate(graph, types);
SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, resource);
- if(superRelations != null) update(graph, superRelations);
+ if(superRelations != null) markForUpdate(graph, superRelations);
predicates.add(resource);
if(predicate == instanceOf || predicate == inherits || predicate == subrelationOf) {
PrincipalTypes principalTypes = QueryCache.entryPrincipalTypes(QueryProcessor.this, subject);
- if(principalTypes != null) update(graph, principalTypes);
+ if(principalTypes != null) markForUpdate(graph, principalTypes);
Types types = QueryCache.entryTypes(QueryProcessor.this, subject);
- if(types != null) update(graph, types);
+ if(types != null) markForUpdate(graph, types);
}
if(predicate == subrelationOf) {
SuperRelations superRelations = SuperRelations.entry(QueryProcessor.this, subject);
- if(superRelations != null) update(graph, superRelations);
+ if(superRelations != null) markForUpdate(graph, superRelations);
}
predicates.add(subject);
@Override
public boolean execute(final int subject) {
- for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) update(graph, o);
- for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) update(graph, o);
- for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) update(graph, o);
+ for(Objects o : QueryCache.entriesObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
+ for(DirectObjects o : QueryCache.entriesDirectObjects(QueryProcessor.this, subject)) markForUpdate(graph, o);
+ for(Statements o : QueryCache.entriesStatements(QueryProcessor.this, subject)) markForUpdate(graph, o);
DirectPredicates entry = QueryCache.entryDirectPredicates(QueryProcessor.this, subject);
- if(entry != null) update(graph, entry);
+ if(entry != null) markForUpdate(graph, entry);
return true;
public boolean execute(int orderedSet) {
OrderedSet entry = QueryCache.entryOrderedSet(QueryProcessor.this, orderedSet);
- if(entry != null) update(graph, entry);
+ if(entry != null) markForUpdate(graph, entry);
return true;
});
- // for (Integer subject : predicates) {
- // DirectPredicates entry = DirectPredicates.entry(QueryProcessor.this, subject);
- // if(entry != null) update(graph, entry);
- // }
+ updateRefutations(graph);
+ primitiveUpdates.forEach(new TObjectProcedure() {
- if (Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
- System.err.println("== Query update ends ==");
+ @Override
+ public boolean execute(Object arg0) {
+
+ ExternalReadEntry query = (ExternalReadEntry)cache.externalReadEntryMap.get(arg0);
+ if (query != null) {
+ boolean listening = update(graph, query);
+ if (!listening && !query.hasParents()) {
+ cache.externalReadEntryMap.remove(arg0);
+ query.discard();
+ }
+ }
+ return true;
}
- }
+ });
+
scheduledValueUpdates.clear();
scheduledObjectUpdates.clear();
scheduledInvalidates.clear();
+
+ if (Development.DEVELOPMENT) {
+ if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_UPDATE, Bindings.BOOLEAN)) {
+ System.err.println("== Query update ends ==");
+ }
+ }
}
private static final Logger LOGGER = LoggerFactory.getLogger(ReadEntry.class);
- protected Read<T> request;
+ protected Read<T> id;
public ReadEntry(Read<T> request) {
- this.request = request;
+ this.id = request;
}
@Override
int makeHash() {
- return request.hashCode();
+ return id.hashCode();
}
@Override
public Object getOriginalRequest() {
- return request;
+ return id;
}
@Override
try {
- T result = request.perform(graph);
+ T result = id.perform(graph);
setResult(result);
setReady();
@Override
public int type() {
- if (request instanceof ReadExt) {
- return ((ReadExt) request).getType();
+ if (id instanceof ReadExt) {
+ return ((ReadExt) id).getType();
} else {
return RequestFlags.INVALIDATE;
}
@Override
public String toString() {
- if (request == null)
+ if (id == null)
return "DISCARDED";
else
- return request.toString() + statusOrException;
+ return id.toString() + statusOrException;
}
};
}
public static <T> T computeForEach(ReadGraphImpl graph, Read<T> request, ReadEntry<T> entry,
- AsyncProcedure<T> procedure_) throws DatabaseException {
+ AsyncProcedure<T> procedure_, boolean needsToBlock) throws DatabaseException {
AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
@Override
public String toString() {
- if (request == null)
+ if (id == null)
return "DISCARDED";
else
- return request.toString() + " - " + statusOrException;
+ return id.toString() + " - " + statusOrException;
}
public Object get(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
@Override
boolean isImmutable(ReadGraphImpl graph) throws DatabaseException {
- if (request instanceof ReadExt) {
- return ((ReadExt) request).isImmutable(graph);
+ if (id instanceof ReadExt) {
+ return ((ReadExt) id).isImmutable(graph);
}
return false;
}