EmmanuelOga / hypergraphdb

Automatically exported from code.google.com/p/hypergraphdb
1 stars 0 forks source link

Unable to use precompiled Query in nested loops or recursive calls #97

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

The following code will not work like one expects:
void recursion(HGHandle node) {
this.outgoingIncidentNodesQuery = make(HGHandle.class, graphDB)
    .compile(
        apply(
            targetAt(graphDB, 1),
            incidentAt(
                var("sourceNode", HGHandle.class),
                0)
        )
    );

for (HGHandle incident : outgoingIncidentNodesQuery.var("sourceNode", 
node).execute) {
    for (HGHandle incident : outgoingIncidentNodesQuery.var("sourceNode", someOtherNode).execute) {
        // do something
    }
}

Since VarContext stores its "locals" in a ThreadLocal,  the second call to 
outgoingIncidentNodesQuery.var() will override the variable globaly and the 
Iterator of the outer loop will subsequently check for incidence to 
"someOtherNode", not for incidence to "node", as it was constructed to do.

Original issue reported on code.google.com by google-a...@gehrels.info on 12 Feb 2013 at 5:23

GoogleCodeExporter commented 9 years ago
Oh, the void "recursion(HGHandle node) {" accidentially slipped through, just 
ignore it please.

Original comment by google-a...@gehrels.info on 12 Feb 2013 at 5:24