Return-Path: Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 97104 invoked by uid 500); 13 Aug 2003 00:25:14 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 97089 invoked from network); 13 Aug 2003 00:25:13 -0000 Received: from redgate.vislab.usyd.edu.au (129.78.157.26) by daedalus.apache.org with SMTP; 13 Aug 2003 00:25:13 -0000 Received: from piccinini.vislab.usyd.edu.au (piccinini.vislab.usyd.edu.au [129.78.157.158]) by redgate.vislab.usyd.edu.au (SGI-8.9.3p2/8.9.0) with ESMTP id KAA07434 for ; Wed, 13 Aug 2003 10:25:18 +1000 (EST) Subject: Transactions: Is this valid From: Steve Smith To: torque-user@db.apache.org Content-Type: text/plain Message-Id: <1060734318.4792.10.camel@piccinini.vislab.usyd.edu.au> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.4 Date: Wed, 13 Aug 2003 10:25:18 +1000 Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hi, I want to use transactions over a series of operations with the ability to commit or rollback. However, by default Torque appears to auto-commit all save operations. Looking at the code I've come up with the following scheme to do this that appears to work, but I was hoping if experts on list could confirm that I'm doing the right thing: import org.apache.torque.Torque; import org.apache.torque.Brokers; import org.apache.torque.BrokersPeer; import org.apache.torque.Referrer; import org.apache.torque.ReferrerPeer; import org.apache.torque.util.Transaction; import java.sql.Connection; class Test { public Test() { try { Torque.init("Torque.properties"); Connection conn = Transaction.begin(Torque.getDefaultDB()); for (int i=10; i < 100; i++) { Brokers b = new Brokers(); b.setName("Broker " + i); b.save(conn); } // Whoops, changed my mind ... Transaction.rollback(conn); // Do it correctly: conn = Transaction.begin(Torque.getDefaultDB()); for (int i=1; i < 4; i++) { Brokers b = new Brokers(); b.setName("Broker " + i); b.save(conn); } Transaction.commit(conn); } catch (Exception e) { System.out.println("Caught: " + e); e.printStackTrace(); } } public static void main(String args[]) { new Test(); } } Hopefully the another advantage to this scheme is that if Torque is configured via JNDI to use XAConnections the above could be be part of a wider transaction. Anybody care to comment on this? Cheers, Steve -- Steve Smith Phone: (02) 9351 5967 Vislab, University of Sydney Email: ssmith@vislab.usyd.edu.au --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org