Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DA3DF37C671 for ; Mon, 12 Nov 2007 06:00:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 82206-02 for ; Mon, 12 Nov 2007 06:00:04 -0400 (AST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.171]) by postgresql.org (Postfix) with ESMTP id 1AFC337B9BC for ; Mon, 12 Nov 2007 06:00:02 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id j3so710886ugf for ; Mon, 12 Nov 2007 02:00:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:sender; bh=XVRhopxZC2aw2+QAEkw+Lai9k6qd6QfXvv/bXDG/vqk=; b=bnPYB7Qtq4fHzdru0r5Gy6JjG5yoXtAwGlmF/upzsoqYV50Hj8u1PtIXPX8Wd/NewtkBn/U4z7J4hjLmHDO+ncsnZof9To/MskkOg6U+cYQ7TkxDqtu3sWR1BrLtUTb300FEGCCRiFcP6izLLe6mPXn42x53HcAj1nraYoQ6EAU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:sender; b=gdOSUAKvbWx3QOnDKNzOlUdxXyRFdLB5vFBBAtLWyT9YwXwnnxc8CaZ1dxXy9vOh9ny/tVoBNy07OS1F6APdsvNkWBRu3sZ6lZcC+bgFmUepomyoz/85w4hcpRGbeMevltAJ3nOq9NcwoIjkH3JiCwhQDLXxopmEBDaAZM08/7g= Received: by 10.67.116.15 with SMTP id t15mr260255ugm.1194861600454; Mon, 12 Nov 2007 02:00:00 -0800 (PST) Received: from ?192.168.1.33? ( [82.25.187.136]) by mx.google.com with ESMTPS id 24sm11225303ugf.2007.11.12.01.59.56 (version=SSLv3 cipher=RC4-MD5); Mon, 12 Nov 2007 01:59:58 -0800 (PST) Message-ID: <47382418.604@enterprisedb.com> Date: Mon, 12 Nov 2007 09:59:52 +0000 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.12 (X11/20070730) MIME-Version: 1.0 To: =?ISO-8859-1?Q?jo=EBl_Winteregg?= CC: pgsql-jdbc@postgresql.org Subject: Re: XAResource implementation References: <1193736934.5565.40.camel@hatman> <4727420A.4060209@enterprisedb.com> <1193757567.5565.46.camel@hatman> <47275A50.2050201@enterprisedb.com> <47275BA6.3030200@enterprisedb.com> <1194819933.5545.100.camel@hatman> In-Reply-To: <1194819933.5545.100.camel@hatman> Content-Type: multipart/mixed; boundary="------------010900080604020501010300" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/50 X-Sequence-Number: 17805 This is a multi-part message in MIME format. --------------010900080604020501010300 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit joël Winteregg wrote: > I said that BTM TransactionManager was "mostly" working because when I > was using the XA implementation, SQL BEGIN and COMMIT where generated > arround each SQL query (even if several queries were located inside the > same transaction). So at the end, I used the TransactionManager with the > "Last Resource Commit Optimization" which allow the use of a pure jdbc > driver during transaction (I only have a single DB (1 Phase Commit) so > it is 100% safe to use this specificity). In this case, my BEGIN and > COMMIT statement where just perfect: > BEGIN > SELECT .. > SELECT .. > SELECT .. > COMMIT > > So I was just wondering if my XA problem (BEGIN and COMMIT location when > using XA) could come from the postgresql XA driver ? Hmm. I downloaded the BTM newUserDemo.zip and modified it to run with Postgres, and to run two queries in same transaction. Works for me. Attached is the modified Test.java I used. To run: 0. Download newUserDemo.zip from http://docs.codehaus.org/display/BTM/NewUserGuide 1. Put postgresql.jar in newUserDemo/lib 2. Copy the attached Test.java to newUserDemo/src/jtatest 3. Modify database/username/password in Test.java if necessary 4. Run the CREATE TABLE from derby-create.sql Here's what I get in the Postgres log, with log_statements='all': LOG: execute : SELECT gid FROM pg_prepared_xacts LOG: execute S_1: BEGIN LOG: execute : insert into messages(content) values ($1) DETAIL: parameters: $1 = 'hello, world!' LOG: execute S_2: COMMIT LOG: execute S_1: BEGIN LOG: execute : select content from messages LOG: execute : select content from messages LOG: execute S_2: COMMIT -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com --------------010900080604020501010300 Content-Type: text/x-java; name="Test.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Test.java" package jtatest; import bitronix.tm.TransactionManagerServices; import bitronix.tm.resource.jdbc.PoolingDataSource; import javax.transaction.UserTransaction; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.ResultSet; public class Test { public static void main(String[] args) throws Exception { String who = "world"; if (args.length > 0) who = args[0]; PoolingDataSource derby1Ds = new PoolingDataSource(); derby1Ds.setClassName("org.postgresql.xa.PGXADataSource"); derby1Ds.setUniqueName("derby1"); derby1Ds.setPoolSize(3); derby1Ds.getDriverProperties().setProperty("user", "postgres"); derby1Ds.getDriverProperties().setProperty("databaseName", "postgres"); derby1Ds.init(); UserTransaction ut = TransactionManagerServices.getTransactionManager(); ut.begin(); try { Connection c = derby1Ds.getConnection(); PreparedStatement stmt = c.prepareStatement("insert into messages(content) values (?)"); stmt.setString(1, "hello, " + who + "!"); stmt.executeUpdate(); stmt.close(); c.close(); ut.commit(); } catch (SQLException ex) { ex.printStackTrace(); ut.rollback(); } ut.begin(); try { Connection c = derby1Ds.getConnection(); PreparedStatement stmt = c.prepareStatement("select content from messages"); ResultSet rs = stmt.executeQuery(); while(rs.next()) System.out.println(rs.getString(1)); rs.close(); stmt.close(); /* Run another query */ stmt = c.prepareStatement("select content from messages"); rs = stmt.executeQuery(); while(rs.next()) System.out.println(rs.getString(1)); rs.close(); stmt.close(); c.close(); ut.commit(); } catch (SQLException ex) { ex.printStackTrace(); ut.rollback(); } derby1Ds.close(); } } --------------010900080604020501010300--