Re: [Neo4j] IntArrayIterator: Questionable Iterable implementation
Thanks Mattias. Do you want me to log a ticket for that ? --Pierre On Wed, May 25, 2011 at 1:06 PM, Mattias Persson matt...@neotechnology.comwrote: Hi Pierre, that's a correct observation and I think the reason for it is that it was easier to write it like that and then it was left in that state. I'm pretty sure I've never some across anyone, before you, that have had a problem with it. Nonetheless I think it'd be nice to fix it, and at the same time take a look at all the iterables in there. 2011/5/25 Pierre Fouche pr.fou...@gmail.com Hi, This might seem a minor point but... The method Node.getRelationships() returns IterableRelationships, implemented by IntArrayIterator. It turns out that IntArrayIterator implements both Iterable and Iterator, its iterator() method returning itself. My understanding was that an Iterable was supposed to be stateless, whereas an Iterator is obviously stateful. Having a stateless Iterable makes it useable multiple times in a foreach loop, as it returns a new Iterator whenever iterator() is called. See for instance http://stackoverflow.com/questions/839178/why-is-javas-iterator-not-an-iterable Unfortunately, IntArrayIterator is a stateful Iterable. I've noticed that Traverser, which extends Iterable, is implemented by TraverserImpl, which does not implement Iterator, but returns a new TraverserIterator whenever iterator() is called. This seems right to me. I actually ran into this stateless/stateful issue when I refactored a piece of code that was using the traversal framework and now uses getRelationships instead. Some of the tests failed because they were reusing a resulting Iterable. Is the design of IntArrayIterator intentional? Or is it an oversight? Thanks, Pierre ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user -- Mattias Persson, [matt...@neotechnology.com] Hacker, Neo Technology www.neotechnology.com ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] IntArrayIterator: Questionable Iterable implementation
Hi, This might seem a minor point but... The method Node.getRelationships() returns IterableRelationships, implemented by IntArrayIterator. It turns out that IntArrayIterator implements both Iterable and Iterator, its iterator() method returning itself. My understanding was that an Iterable was supposed to be stateless, whereas an Iterator is obviously stateful. Having a stateless Iterable makes it useable multiple times in a foreach loop, as it returns a new Iterator whenever iterator() is called. See for instance http://stackoverflow.com/questions/839178/why-is-javas-iterator-not-an-iterable Unfortunately, IntArrayIterator is a stateful Iterable. I've noticed that Traverser, which extends Iterable, is implemented by TraverserImpl, which does not implement Iterator, but returns a new TraverserIterator whenever iterator() is called. This seems right to me. I actually ran into this stateless/stateful issue when I refactored a piece of code that was using the traversal framework and now uses getRelationships instead. Some of the tests failed because they were reusing a resulting Iterable. Is the design of IntArrayIterator intentional? Or is it an oversight? Thanks, Pierre ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] About transactions and locking
If you only need to grab a write lock on a node or relationship you can invoke the removeProperty method with a property key that does not exist. Thanks for the trick, Johan. This way I don't even have to bother releasing the lock. --Pierre ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] About transactions and locking
Hi, I have a few questions about transactions and locking in Neo4j. When I read the 'Isolation' section of the transaction wiki page (http://wiki.neo4j.org/content/Transactions), I understand that Neo4j provides a unique isolation level equivalent to the TRANSACTION_READ_COMMITTED in the SQL92 terminology (that is, no dirty reads but no repeatable reads). Is this a fair statement? Neo4j does not provide any optimistic locking mechanism out-of-the-box. Is this correct? The wiki page on transactions (http://wiki.neo4j.org/content/Transactions) refers to the LockManager class (the API link is broken btw). How can I get a reference to a LockManager instance? The only way I found was to call EmbeddedGraphDatabase.getConfig().getLockManager(). However the javadoc for getConfig() states that it Will most likely be removed in future releases. Suppose I opened two Neo4j databases DB1 and DB2. Can I create two transactions (one on DB1, the other on DB2) in the same thread? Thanks for your help, Pierre Fouché ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user