Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U1qJs-0002LZ-36 for pgsql-jdbc@arkaria.postgresql.org; Sun, 03 Feb 2013 03:32:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U1qJr-0007oW-6r for pgsql-jdbc@arkaria.postgresql.org; Sun, 03 Feb 2013 03:32:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U1qJq-0007oQ-8x for pgsql-jdbc@postgresql.org; Sun, 03 Feb 2013 03:32:38 +0000 Received: from [222.73.24.84] (helo=song.cn.fujitsu.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U1qJl-0002sy-9r for pgsql-jdbc@postgresql.org; Sun, 03 Feb 2013 03:32:38 +0000 X-IronPort-AV: E=Sophos;i="4.84,592,1355068800"; d="scan'208";a="6681376" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 03 Feb 2013 11:30:15 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r133WQa4031492; Sun, 3 Feb 2013 11:32:27 +0800 Received: from [127.0.0.1] ([10.167.159.99]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013020311311402-252858 ; Sun, 3 Feb 2013 11:31:14 +0800 Message-ID: <510DD9F0.5070403@cn.fujitsu.com> Date: Sun, 03 Feb 2013 11:30:56 +0800 From: Chen Huajun User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.28) Gecko/20120306 Lightning/1.0b2 Thunderbird/3.1.20 MIME-Version: 1.0 To: dmp CC: pgsql-jdbc@postgresql.org Subject: Re: [BUGS]log can not be output when use DataSource 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> <50FD379F.1020304@cn.fujitsu.com> <50FD7094.9050104@ttc-cmc.net> <50FFEB3C.5050700@cn.fujitsu.com> <51002D8E.9040905@ttc-cmc.net> <510660C5.1080801@cn.fujitsu.com> <5106BB52.5000203@ttc-cmc.net> <51076176.5070800@cn.fujitsu.com> <51080592.5080904@ttc-cmc.net> <510D5247.5030508@cn.fujitsu.com> <510DCC36.5000207@ttc-cmc.net> In-Reply-To: <510DCC36.5000207@ttc-cmc.net> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/02/03 11:31:14, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/02/03 11:31:14 Content-Type: multipart/mixed; boundary="------------080801090306080701080900" X-Host-Lookup-Failed: Reverse DNS lookup failed for 222.73.24.84 (failed) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org --------------080801090306080701080900 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed danap, Please use the new patch. I add a test case,and fixed a mistake in the old one. Chen Huajun (2013/02/03 10:32), dmp wrote: > Hello, > > I can review this tomorrow and get back by Monday, or sooner. > > danap. > > Chen Huajun wrote: >> Hi >> >> I have made a new patch for BaseDataSource ,please check it. >> Some modifications in getReference() is just for keeping >> the same style to other String parameters . >> >> Chen Huajun > > --------------080801090306080701080900 Content-Type: text/plain; name="pgjdbc_BaseDataSourceV2.patch" Content-Disposition: attachment; filename="pgjdbc_BaseDataSourceV2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/org/postgresql/ds/common/BaseDataSource.java b/org/postgresql/= ds/common/BaseDataSource.java index bfe54f7..b7743df 100644 --- a/org/postgresql/ds/common/BaseDataSource.java +++ b/org/postgresql/ds/common/BaseDataSource.java @@ -43,15 +43,15 @@ =20 // Standard properties, defined in the JDBC 2.0 Optional Package spec private String serverName =3D "localhost"; - private String databaseName; + private String databaseName =3D ""; private String user; private String password; private int portNumber =3D 0; private int prepareThreshold =3D 5; private int unknownLength =3D Integer.MAX_VALUE; private boolean binaryTransfer =3D true; - private String binaryTransferEnable =3D ""; - private String binaryTransferDisable =3D ""; + private String binaryTransferEnable; + private String binaryTransferDisable; private int loginTimeout =3D 0; // in seconds private int socketTimeout =3D 0; // in seconds private int receiveBufferSize =3D -1; // off (-1), not in use @@ -63,6 +63,7 @@ private int logLevel =3D 0; private int protocolVersion =3D 0; private String applicationName; + private boolean logLevelSet =3D false;=20=20=20=20=20=20 =20 /** * Gets a connection to the PostgreSQL database. The database is iden= tified by the @@ -184,6 +185,7 @@ public void setLogLevel(int logLevel) { this.logLevel =3D logLevel; + logLevelSet =3D true; } =20 public int getProtocolVersion() @@ -295,6 +297,14 @@ } =20 /** + * Gets the write buffer size of TCP/IP socket. + */ + public int getReceiveBufferSize() + { + return receiveBufferSize; + } +=20=20=20=20 + /** * Sets the write buffer size of TCP/IP socket. */ public void setReceiveBufferSize(int nbytes) @@ -302,6 +312,14 @@ this.receiveBufferSize =3D nbytes; } =20 + /** + * Gets the send buffer size of TCP/IP socket. + */ + public int getSendBufferSize() + { + return sendBufferSize; + } +=20=20=20=20 /** * Sets the send buffer size of TCP/IP socket. */ @@ -473,7 +491,7 @@ /** * Generates a DriverManager URL from the other properties supplied. */ - private String getUrl() + public String getUrl() { StringBuffer sb =3D new StringBuffer(100); sb.append("jdbc:postgresql://"); @@ -486,7 +504,15 @@ sb.append("&socketTimeout=3D").append(socketTimeout); sb.append("&prepareThreshold=3D").append(prepareThreshold); sb.append("&unknownLength=3D").append(unknownLength); - sb.append("&loglevel=3D").append(logLevel); + if(user !=3D null) { + sb.append("&user=3D").append(user); + } + if(password !=3D null) { + sb.append("&password=3D").append(password); + } + if (logLevelSet) { + sb.append("&loglevel=3D").append(logLevel); + } if (protocolVersion !=3D 0) { sb.append("&protocolVersion=3D").append(protocolVersion); } @@ -510,10 +536,14 @@ sb.append("&ApplicationName=3D"); sb.append(applicationName); } - if (binaryTransfer) { - sb.append("&binaryTransfer=3Dtrue"); + sb.append("&binaryTransfer=3D").append(binaryTransfer); + if (binaryTransferEnable !=3D null) { + sb.append("&binaryTransferEnable=3D").append(binaryTransferEna= ble); } - + if (binaryTransferDisable !=3D null) { + sb.append("&binaryTransferDisable=3D").append(binaryTransferDi= sable); + } +=20=20=20=20=20=20=20=20 return sb.toString(); } =20 @@ -548,11 +578,22 @@ ref.add(new StringRefAddr("prepareThreshold", Integer.toString(pre= pareThreshold))); ref.add(new StringRefAddr("unknownLength", Integer.toString(unknow= nLength))); ref.add(new StringRefAddr("binaryTransfer", Boolean.toString(binar= yTransfer))); + if (binaryTransferEnable !=3D null) + { + ref.add(new StringRefAddr("binaryTransferEnable", binaryTransf= erEnable)); + } + if (binaryTransferDisable !=3D null) + { + ref.add(new StringRefAddr("binaryTransferDisable", binaryTrans= ferDisable)); + } ref.add(new StringRefAddr("loginTimeout", Integer.toString(loginTi= meout))); ref.add(new StringRefAddr("socketTimeout", Integer.toString(socket= Timeout))); =20 ref.add(new StringRefAddr("ssl", Boolean.toString(ssl))); - ref.add(new StringRefAddr("sslfactory", sslfactory)); + if(sslfactory !=3Dnull) + { + ref.add(new StringRefAddr("sslfactory", sslfactory)); + } =20 ref.add(new StringRefAddr("receiveBufferSize", Integer.toString(re= ceiveBufferSize))); ref.add(new StringRefAddr("sendBufferSize", Integer.toString(sendB= ufferSize))); @@ -562,9 +603,15 @@ ref.add(new StringRefAddr("compatible", compatible)); } =20 - ref.add(new StringRefAddr("logLevel", Integer.toString(logLevel))); + if(logLevelSet) + { + ref.add(new StringRefAddr("logLevel", Integer.toString(logLeve= l))); + } ref.add(new StringRefAddr("protocolVersion", Integer.toString(prot= ocolVersion))); - ref.add(new StringRefAddr("ApplicationName", applicationName)); + if(applicationName !=3D null) + { + ref.add(new StringRefAddr("ApplicationName", applicationName)); + } =20 return ref; } @@ -592,6 +639,7 @@ out.writeBoolean(binaryTransfer); out.writeObject(binaryTransferEnable); out.writeObject(binaryTransferDisable); + out.writeBoolean(logLevelSet); } =20 protected void readBaseObject(ObjectInputStream in) throws IOException= , ClassNotFoundException @@ -617,6 +665,7 @@ binaryTransfer =3D in.readBoolean(); binaryTransferEnable =3D (String)in.readObject(); binaryTransferDisable =3D (String)in.readObject(); + logLevelSet =3D in.readBoolean(); } =20 public void initializeFrom(BaseDataSource source) throws IOException, = ClassNotFoundException { diff --git a/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java b/o= rg/postgresql/test/jdbc2/optional/BaseDataSourceTest.java index 8871d4a..32d1fb0 100644 --- a/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java +++ b/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java @@ -11,6 +11,7 @@ import org.postgresql.test.TestUtil; import org.postgresql.test.util.MiniJndiContextFactory; import org.postgresql.ds.common.BaseDataSource; +import org.postgresql.jdbc2.optional.SimpleDataSource; import org.postgresql.PGConnection; =20 import java.sql.*; @@ -262,4 +263,33 @@ protected void compareJndiDataSource(BaseDataSource oldbds, BaseDataSo= urce bds) { assertTrue("DataSource was dereferenced, should have been serializ= ed or recreated", bds !=3D oldbds); } +=20=20=20=20 + public void testGetURL() + { + BaseDataSource ds; + ds =3D (BaseDataSource)new SimpleDataSource(); + assertTrue("Got database name of 'null' from getUrl() !", ds.getU= rl().indexOf("/null?")<0); +=20=20=20=20=20=20=20=20=20=20=20=20 + assertTrue("Got 'loglevel=3D' from getUrl(),Driver.setLoglevel() = should not be overrided without BaseDataSource.setLoglevel() called!", ds.g= etUrl().indexOf("loglevel=3D")<0); + ds.setLogLevel(0); + assertTrue("Should include 'loglevel=3D0' in getUrl() :" + ds.getU= rl(), ds.getUrl().indexOf("loglevel=3D0")>0); + ds.setLogLevel(1); + assertTrue("Should include 'loglevel=3D1' in getUrl() :" + ds.getU= rl(), ds.getUrl().indexOf("loglevel=3D1")>0); +=20=20=20=20=20=20=20=20=20=20=20=20 + ds.setBinaryTransfer(false); + assertTrue("Should include 'binaryTransfer=3Dfalse' in getUrl() :"= + ds.getUrl(), ds.getUrl().indexOf("binaryTransfer=3Dfalse")>0); + ds.setBinaryTransfer(true); + ds.setBinaryTransferEnable("1"); + ds.setBinaryTransferDisable("2"); + assertTrue("Should include 'binaryTransfer=3Dtrue' in getUrl() :" = + ds.getUrl(), ds.getUrl().indexOf("binaryTransfer=3Dtrue")>0); + assertTrue("Should include 'binaryTransferEnable=3D1' in getUrl() = :" + ds.getUrl(), ds.getUrl().indexOf("binaryTransferEnable=3D1")>0); + assertTrue("Should include 'binaryTransferDisable=3D2' in getUrl()= :" + ds.getUrl(), ds.getUrl().indexOf("binaryTransferDisable=3D2")>0); +=20=20=20=20=20=20=20=20 + ds.setUser("aaa"); + ds.setPassword("bbb"); + assertTrue("Should include 'user=3Daaa' in getUrl() :" + ds.getUrl= (), ds.getUrl().indexOf("user=3Daaa")>0); + assertTrue("Should include 'password=3Dbbb' in getUrl() :" + ds.ge= tUrl(), ds.getUrl().indexOf("password=3Dbbb")>0); +=20=20=20=20=20=20=20=20 + } +=20=20=20=20=20 }= --------------080801090306080701080900 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc --------------080801090306080701080900--