I'm in the middle of retrofitting neo4j code that was running on 1.9.3 to 
2.0.0.  This is all happening under windows, jdk1.7.0_45, and eclipse.

 I expected some teething problems and cut-overs; here's one I've run into:

org.neo4j.graphdb.NotInTransactionException
    at 
org.neo4j.kernel.impl.persistence.PersistenceManager.getResource(PersistenceManager.java:214)
    at 
org.neo4j.kernel.impl.persistence.PersistenceManager.currentKernelTransaction(PersistenceManager.java:84)
    at 
org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.transaction(ThreadToStatementContextBridge.java:53)
    at 
org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.instance(ThreadToStatementContextBridge.java:47)
    at org.neo4j.kernel.impl.core.NodeProxy.hasProperty(NodeProxy.java:346)
    at blah.blah.mypackage.MyStorage.isMyObjectNode(Neo4JStorage.java:219)
    at 
blah.blah.mypackage.MyFactory.newObject(Neo4JPLUSObjectFactory.java:190)
    at blah.blah.mypackage.MyFactory.listWorkflows(Neo4JStorage.java:933)

I can make it happy by wrapping the methods below in a transaction, but I'm 
pretty sure that's not the right thing to do.

Here's the relevant method:

    public static boolean isMyObjectNode(Node n) { 
        return n != null && n.hasProperty(PROP_PLUSOBJECT_ID) && 
n.hasProperty(PROP_TYPE) && n.hasProperty(PROP_SUBTYPE);
    }

(Context: all of those PROP_TYPE, etc are all public static final String)

The "newObject" method in my package is just creating one of my domain 
objects out of a node.  In order to do that, it needs to check which kind 
of node it's dealing with.   I'd rather not paste that code because it's 
involved and includes many other subclasses that makes the rabbit hole 
deeper.  Suffice to say I'm sure that it's just creating my domain objects, 
and not modifying anything in the graph.

The "listWorkflows" method looks like this:

    public static List<MyWorkflow> listWorkflows(User user, int maxReturn) 
throws MyException {
        if(maxReturn <= 0 || maxReturn > 1000) maxReturn = 100;
        
        String query = "start n=node:node_auto_index(type=\"" + 
MyWorkflow.TYPE_WORKFLOW + "\") " + 
                       "where has(n.oid) " + 
                       "return n " + 
                       "limit " + maxReturn;
        
        Iterator<Node> ns = Neo4JStorage.execute(query).columnAs("n");
        ArrayList<MyWorkflow> wfs = new ArrayList<MyWorkflow>();
        
        while(ns.hasNext()) { 
            MyObject o = MyFactory.newObject(ns.next());
            if(o.isWorkflow()) wfs.add((MyWorkflow)o);
            else { 
                log.warning("Returned non-workflow " + o + " from workflow 
query!");
            }
        }
        
        return wfs;
    } // End listWorkflows

Indeed this code (and its caller) doesn't happen within a transaction, but 
it shouldn't need to -- no modification is going on here.

Lastly -- yes, I know about labels, and how labels would probably be a 
better way to do this.  I'm planning on exploiting that, but the first 
thing to do is to get the current code base working on the new release, and 
I've got other fish to fry (like cypher query syntax updates to get rid of 
"?") before I get to using labels.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to neo4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to