pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chen Huajun <chenhj@cn.fujitsu.com>
To: dmp <danap@ttc-cmc.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [BUGS]log can not be output when use DataSource
Date: Mon, 21 Jan 2013 18:27:36 +0800
Message-ID: <50FD1818.8060002@cn.fujitsu.com> (raw)
In-Reply-To: <50FCC7EC.7050307@cn.fujitsu.com>
References: <50F8335B.6070404@ttc-cmc.net>
	<50FA1403.7020301@cn.fujitsu.com>
	<50FAF98A.1030008@ttc-cmc.net>
	<50FBCA78.3040007@cn.fujitsu.com>
	<50FC3529.3060101@ttc-cmc.net>
	<50FCC7EC.7050307@cn.fujitsu.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Hi

>
>  > If you would create sample code to run to validate both your
>  > bug report and test your patch you may have seen the breakage.
>  > I can tell you that in all cases when DataSource.SetLogLevel(0)
>  > your patch breaks the standard of the user overrides the
>  > Driver.setLogLevel() when it is stipulated.
>  >
>  > I know that valid inputs maybe only be Driver.INFO & Driver.DEBUG,
>  > but if you treat the PgJDBC has a black box which you stimulate
>  > and watch the output then we can not ignore the boundard cases of
>  > <0, 0, & >2.
>

I made a new patch to avoid the above problem.


But i found a new another problem.
In the following code,source2.getConnection() fail to output log as expected.
----------------------------------------
PGPoolingDataSourcesource = new PGPoolingDataSource();
source.setLogLevel(2);
Connection con = source.getConnection();//OK, log does output

Properties props = new Properties();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,  "org.postgresql.test.util.MiniJndiContextFactory");
InitialContext initialContext = new InitialContext(props);
initialContext.rebind("DataSource", source);

BaseDataSource source2 = (BaseDataSource) initialContext.lookup("DataSource");
con = source2.getConnection();//NG, log does not output
----------------------------------------

The reason is that loadBaseDataSource(BaseDataSource ds, Reference ref)
fail to copy all properties from ref when source2 was created.
So the loglevel of source2 remains to be the defualt value 0.
Not only loglevel, some other properties such as "ssl" have the same problem.



Chen Huajun

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Attachments:

pgjdbc_loglevel_v2.patch (text/plain, 2.2K) download diff --git a/org/postgresql/ds/common/BaseDataSource.java b/org/postgresql/ds/common/BaseDataSource.java index bfe54f7..2aa7b31 100644 --- a/org/postgresql/ds/common/BaseDataSource.java +++ b/org/postgresql/ds/common/BaseDataSource.java @@ -63,6 +63,7 @@ private int logLevel = 0; private int protocolVersion = 0; private String applicationName; + private boolean logLevelIsSet = false; /** * Gets a connection to the PostgreSQL database. The database is identified by the @@ -184,6 +185,7 @@ public void setLogLevel(int logLevel) { this.logLevel = logLevel; + logLevelIsSet = true; } public int getProtocolVersion() @@ -486,7 +488,9 @@ sb.append("&socketTimeout=").append(socketTimeout); sb.append("&prepareThreshold=").append(prepareThreshold); sb.append("&unknownLength=").append(unknownLength); - sb.append("&loglevel=").append(logLevel); + if (logLevelIsSet) { + sb.append("&loglevel=").append(logLevel); + } if (protocolVersion != 0) { sb.append("&protocolVersion=").append(protocolVersion); } @@ -562,7 +566,10 @@ ref.add(new StringRefAddr("compatible", compatible)); } - ref.add(new StringRefAddr("logLevel", Integer.toString(logLevel))); + if(logLevelIsSet) + { + ref.add(new StringRefAddr("logLevel", Integer.toString(logLevel))); + } ref.add(new StringRefAddr("protocolVersion", Integer.toString(protocolVersion))); ref.add(new StringRefAddr("ApplicationName", applicationName)); @@ -592,6 +599,7 @@ out.writeBoolean(binaryTransfer); out.writeObject(binaryTransferEnable); out.writeObject(binaryTransferDisable); + out.writeBoolean(logLevelIsSet); } protected void readBaseObject(ObjectInputStream in) throws IOException, ClassNotFoundException @@ -617,6 +625,7 @@ binaryTransfer = in.readBoolean(); binaryTransferEnable = (String)in.readObject(); binaryTransferDisable = (String)in.readObject(); + logLevelIsSet = in.readBoolean(); } public void initializeFrom(BaseDataSource source) throws IOException, ClassNotFoundException {=

view thread (30+ messages)  latest in thread

Message-ID: <50FD1818.8060002@cn.fujitsu.com>
Permalink:  ../50FD1818.8060002@cn.fujitsu.com/
Also on:    postgresql.org/message-id/50FD1818.8060002@cn.fujitsu.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: chenhj@cn.fujitsu.com, danap@ttc-cmc.net
  Subject: Re: [BUGS]log can not be output when use DataSource
  In-Reply-To: <50FD1818.8060002@cn.fujitsu.com>
  References: <50F8335B.6070404@ttc-cmc.net> <50FA1403.7020301@cn.fujitsu.com> <50FAF98A.1030008@ttc-cmc.net> <50FBCA78.3040007@cn.fujitsu.com> <50FC3529.3060101@ttc-cmc.net> <50FCC7EC.7050307@cn.fujitsu.com> <50FD1818.8060002@cn.fujitsu.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox