Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E753C632326 for ; Mon, 12 Apr 2010 17:16:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 80418-02 for ; Mon, 12 Apr 2010 20:15:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id 236A3630749 for ; Mon, 12 Apr 2010 17:16:02 -0300 (ADT) Received: by vws18 with SMTP id 18so1297780vws.19 for ; Mon, 12 Apr 2010 13:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :x-enigmail-version:content-type:content-transfer-encoding; bh=62eI4PTDrwe/3suUgJFpv9yAii1AWB2o0L1yHH5unpI=; b=pDQRjXW7ZqdXG9/klZXo4z/1zQ71toPT4Q0NYr8Kz+3mL7RVQSD1gD5OCNz7vuCVT+ inQtz9XFdK4XiS/l0ovz3NJo4LKxpJaWKI2cdn3Dun9eB9GIsdBaD/2QtKGiWN1FAvAI jdbbFlLpVClaU4HDQMKCJwfSPqvYUiHYn2xpQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=QQGkK6Tx8vsImWQMrGmJcoINhz5qHbv5SBeipzeZqaI0WTU82Jqmuri1lHUjjwJ3Kf 7gSXZdSmGoCtQf1LpPY86GesAKjvVLCr2mLN5z52975p5nRAH0XXeaKvIaudd4nJD7Mm uKiSa91zhCDIelStabk2iLgNvSJBExR7dzXPk= Received: by 10.220.107.148 with SMTP id b20mr2295661vcp.210.1271103360567; Mon, 12 Apr 2010 13:16:00 -0700 (PDT) Received: from [192.168.1.100] ([190.177.75.77]) by mx.google.com with ESMTPS id 4sm1244111ywd.13.2010.04.12.13.15.57 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 12 Apr 2010 13:15:59 -0700 (PDT) Message-ID: <4BC37FE6.2010500@gmail.com> Date: Mon, 12 Apr 2010 17:17:42 -0300 From: Ader Javier User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Maciek Sakrejda CC: pgsql-jdbc@postgresql.org Subject: Re: It is safe remenber current Isolation level in AbstractJdbc2Connection? References: <4BC144D3.4030808@gmail.com> In-Reply-To: X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201004/20 X-Sequence-Number: 20431 Good point.... but, then the current getReadOnly() neither is safe! Potencially, these connection properties can be changed in every statement (ex, "set session characteristics", "set transaction", "set default_transaction_isolation or transaction_isolation to ", "set transaction_read_only or default_transaction_read_only" or worse, indirectly via a function...); I don't see any way for keep track for these properties without access the server... (maybe, protocol V3 o V2 return this info in every access; I don't know) Offtopic: By the way, reading the source it's not clear to me why setTransactionIsolation use "SET SESSION CHARACTERISTICS"; why it don't use "SET TRANSACTION" (the same for setReadOnly)?. SET SESSION CHARACTERISTICS only take efects in mode autocommit or as defaults values for new transacctions (SET SESSION AS TRANSACTION modifies default_transaction_read_only and default_transaction_isolation) For example: (default_transaction_read_only = off) BEGIN ; (user call to setReadOnly(true)) SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY; insert into.... -> don't problem, set session don't take efect in this transaction But (in other connection) (default_transaction_read_only = off) BEGIN; SET TRANSACTION READ ONLY; inser into ... -> Error (correct!): ERROR: transaction is read-only, SQL state: 25006 It is : if we are outside a transaction (mode autocommit), it's correct use "set session charactistics" or "set default_transaction_read_only"; but in mode "transaction", don't. (use instead SET Transction or set transaction_read_only) Maciek Sakrejda escribió: > The one problem I see is that an explicit "SET TRANSACTION > SERIALIZABLE" through a plain query will foil your scheme, but given > that ReadOnly is already handled that way, this may be a moot point... > --- > Maciek Sakrejda | Software Engineer | Truviso > > 1065 E. Hillsdale Blvd., Suite 230 > Foster City, CA 94404 > (650) 242-3500 Main > (650) 242-3501 F > www.truviso.com > > > > On Sat, Apr 10, 2010 at 8:41 PM, Ader Javier wrote: > >> Hi and sorry by my English. I have a software that checks the Isolation >> level before create "every" PreparedStatement over a Connection (there >> is a pool of connections from we pick one). Some like this: >> if( connection.getTransactionIsolation() != >> Connection.TRANSACTION_READ_COMMITTED ) { >> connection.setTransactionIsolation( >> Connection.TRANSACTION_READ_COMMITTED ); >> } >> >> .... >> PreparedStatement stmt = connection.createPreparedStatement(....) >> return stmt; >> >> My problem is that AbstractJdbc2Connection.getTransactionIsolation() >> access the server ever and don't remember the last level used, so It's >> safe change getTransactionIsolation() and setTransactionIsolation(level) >> for avoid unnecessary access? That's my idea >> public abstract class AbstractJdbc2Connection implements BaseConnection >> { >> .... >> //cached Isolation level >> private Integer level = null; >> .... >> public int getTransactionIsolation() throws SQLException >> { >> checkClosed(); >> //new : avoid access if there is one previous >> if (this.level != null) return this.level.intValue(); >> >> .... >> .... >> >> level = level.toUpperCase(Locale.US); >> // mod: caching before return return >> if (level.indexOf("READ COMMITTED") != -1) >> this.level = new Integer(Connection.TRANSACTION_READ_COMMITTED); >> if (level.indexOf("READ UNCOMMITTED") != -1) >> this.level= new Integer(Connection.TRANSACTION_READ_UNCOMMITTED); >> if (level.indexOf("REPEATABLE READ") != -1) >> this.level = new Integer(Connection.TRANSACTION_REPEATABLE_READ) >> if (level.indexOf("SERIALIZABLE") != -1) >> this.level = new Integer(Connection.TRANSACTION_SERIALIZABLE); >> >> if (this.level != null) >> return this.level.valueInt(); >> >> this.level = new Integer(Connection.TRANSACTION_READ_COMMITTED); // Best >> guess >> return this.level.valueInt(); >> } >> >> public void setTransactionIsolation(int level) throws SQLException >> { >> ... >> >> //new: caching before return >> this.level = new Integer(level); >> } >> >> By the way, property "read only" is managed in this way (see >> AbstractJdbc2Connection.getReadOnly() and >> AbstractJdbc2Connection.setReadOnly(boolean). >> >> Thanks! >> Ader Javier >> >> -- >> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-jdbc >> >> > >