Hi Rick, You should not cast it to a org.neo4j.graphdb.Transaction type but instead use the transaction manager to commit the transaction directly. Something like this:
TransactionManager tm = (( EmbeddedGraphDatabase ) neo).getConfig().getTxModule().getTxManager(); tm.commit(); // will commit the current running tx tm.begin(); // will start a new transaction and the old top level org.neo4j.graphdb.Transaction will commit this one instead upon tx.finish() As I understand it you start a transaction somewhere using the GraphDatabaseService.beginTx() but then deeper down in the code you may not have access to the top level org.neo4j.graphdb.Transaction but still need to commit any work (to avoid to large transactions)? One way to do that is to just invoke tm.commit() followed by tm.begin(). Regarding active locks there is not API to check what locks the current transaction has. However if you only commit the running transaction using the TM and start a new one you do not have to think about the potential deadlock issue I mentioned. -Johan On Sat, Jan 8, 2011 at 4:41 PM, <[email protected]> wrote: > Hi, Johan. > > > > Would the following code also be "legal" to commit the currently > running transaction and start a new one? I'm casting the Transaction > from tm.getTransaction to an org.neo4j.graphdb.Transaction type. The > part I'm not sure about is whether tm.begin creates/enlists a neo > transaction or not. Should I instead use > graphDatabaseService.beginTx()? > > > > The other approach that I'm contemplating involves never actually > keeping a reference to a Transaction object and to always get the > current transaction from the transaction manager whenever calling > success(), failure(), or finish(). Combining this with the below code > allows the "wrappers" to always reference the currently running > transaction as needed. > > > > The root cause for all of this is that I'm trying to do "block commits" > on a lengthy operation that could involve many thousands of database > operations, but have it function inside our existing wrapper(s). > > > > Thanks for any guidance. > > > > Rick > > > > > > =========================== > > > > TransactionManager tm = (( EmbeddedGraphDatabase ) > neo).getConfig().getTxModule().getTxManager(); > Transaction currentTx = (Transaction)tm.getTransaction(); > currentTx.success(); > currentTx.finish(); > tm.begin(); > > > =========================== > > > > -------- Original Message -------- > Subject: Re: [Neo4j] Help needed! Obtaining the active transaction > From: Johan Svensson <[1][email protected]> > Date: Fri, January 07, 2011 8:34 am > To: Neo4j user discussions <[2][email protected]> > You can use the TransactionManager suspend/resume for this. Suspend > the current transaction and start a new one using the underlying TM. > Have a look at > [3]https://svn.neo4j.org/components/rdf-sail/trunk/src/main/java/org/ne > o4j/rdf/sail/GraphDatabaseSailConnectionImpl.java > to see how this can be done. > You have to make sure the parent transaction that you temporary > suspend does not have any locks on nodes or relationships you intend > to update in the new transaction to avoid deadlocks. > Regards, > Johan > On Thu, Jan 6, 2011 at 8:03 PM, Rick Bullotta > <[4][email protected]> wrote: > > We have a situation where we have a wrapper that automatically > > starts/commits Neo transactions as needed. However, in some cases, > within > > the logic that is "wrapped" by this wrapper, we want to break the > work up > > into smaller units (deleting a lot of nodes/relationships, in this > case), > > however, there is already an active transaction. > > > > > > > > Any suggestions on how to handle this? Is there a way to grab the > > transaction from the thread context or somewhere else, so that we can > commit > > it and start a new one? > > > > > > > > Many thanks, > > > > > > > > Rick > _______________________________________________ > Neo4j mailing list > [5][email protected] > [6]https://lists.neo4j.org/mailman/listinfo/user > > References > > 1. mailto:[email protected] > 2. mailto:[email protected] > 3. > https://svn.neo4j.org/components/rdf-sail/trunk/src/main/java/org/neo4j/rdf/sail/GraphDatabaseSailConnectionImpl.java > 4. mailto:[email protected] > 5. mailto:[email protected] > 6. https://lists.neo4j.org/mailman/listinfo/user > _______________________________________________ > Neo4j mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user > -- Johan Svensson [[email protected]] Chief Technology Officer, Neo Technology www.neotechnology.com _______________________________________________ Neo4j mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

