I use jUnit MethodRule that starts embedded server in temporary folder
and cleans up transaction after the test:
public class Neo4jRule extends TemporaryFolder {
        
        private GraphDatabaseService graphDatabase;
        private Transaction transaction;

        @Override
        protected void before() throws Throwable {
                super.before();
                graphDatabase = new
EmbeddedGraphDatabase(newFolder("neo4j").getAbsolutePath());
                transaction = graphDatabase.beginTx();
        }
        
        @Override
        protected void after() {
                transaction.finish();
                graphDatabase.shutdown();
                super.after();
        }

        public GraphDatabaseService getGraphDatabase() {
                return graphDatabase;
        }

        public Transaction getTransaction() {
                return transaction;
        }
}

On Thu, Aug 25, 2011 at 7:18 AM, Jim Webber <[email protected]> wrote:
> If you're using the standard try/catch/finally idiom in Neo4j then consider 
> using Nat Pryce/Steve Freeman's transactor pattern.
>
> We have an example of this in the neo4j server code here:
>
> https://github.com/neo4j/community/blob/master/server/src/functionaltest/java/org/neo4j/server/helpers/Transactor.java
>
> It's not always appropriate, but it the general case it can keep your code a 
> bit terser and more intent-ful.
>
> Jim
>
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
_________________
entia non sunt multiplicanda praeter necessitatem,
(entities should not be multiplied beyond necessity.)
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to