pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH] Expose URL property in BaseDataSource
8+ messages / 3 participants
[nested] [flat]

* [PATCH] Expose URL property in BaseDataSource
@ 2013-03-11 14:23  Loïc PÉRON <loic.peron@bigfoot.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Loïc PÉRON @ 2013-03-11 14:23 UTC (permalink / raw)
  To: pgsql-jdbc

Hi all,

The attached patch does the following:

- changes visibility of Driver.parseUrl to public static
 - changes visibility of BaseDataSource.getUrl to public
 - add setUrl to BaseDataSourc based on Driver.parseUrl

Adding this property to all datasources simplifies their set-up by
 using the same url/user/pass as with DriverManager.

-- 
Loïc PÉRON
mailto:loic.peron<at>bigfoot.com

-- 
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-seturl.patch (text/plain, 2.6K) download diff --git a/org/postgresql/Driver.java.in b/org/postgresql/Driver.java.in index f6c69c0..8d00c7a 100644 --- a/org/postgresql/Driver.java.in +++ b/org/postgresql/Driver.java.in @@ -562,7 +562,7 @@ * @return Properties with elements added from the url * @exception SQLException */ - Properties parseURL(String url, Properties defaults) throws SQLException + public static Properties parseURL(String url, Properties defaults) throws SQLException { Properties urlProps = new Properties(defaults); diff --git a/org/postgresql/ds/common/BaseDataSource.java b/org/postgresql/ds/common/BaseDataSource.java index bfe54f7..47fc04f 100644 --- a/org/postgresql/ds/common/BaseDataSource.java +++ b/org/postgresql/ds/common/BaseDataSource.java @@ -9,6 +9,7 @@ import javax.naming.*; import java.sql.*; +import java.util.Properties; import java.io.IOException; import java.io.PrintWriter; @@ -473,7 +474,7 @@ /** * Generates a DriverManager URL from the other properties supplied. */ - private String getUrl() + public String getUrl() { StringBuffer sb = new StringBuffer(100); sb.append("jdbc:postgresql://"); @@ -516,6 +517,30 @@ return sb.toString(); } + + /** + * Sets properties from a DriverManager URL. + */ + public void setUrl(String url) throws SQLException { + Properties p = org.postgresql.Driver.parseURL(url, null); + serverName = p.getProperty("PGHOST", "localhost"); + portNumber = Integer.parseInt(p.getProperty("PGPORT", "0")); + databaseName = p.getProperty("PGDBNAME"); + loginTimeout = Integer.parseInt(p.getProperty("loginTimeout", "0")); + socketTimeout = Integer.parseInt(p.getProperty("socketTimeout", "0")); + prepareThreshold = Integer.parseInt(p.getProperty("prepareThreshold", "5")); + unknownLength = Integer.parseInt(p.getProperty("unknownLength", "0")); + logLevel = Integer.parseInt(p.getProperty("loglevel", "0")); + protocolVersion = Integer.parseInt(p.getProperty("protocolVersion", "0")); + ssl = Boolean.parseBoolean(p.getProperty("ssl")); + sslfactory = p.getProperty("sslfactory"); + receiveBufferSize = Integer.parseInt(p.getProperty("receiveBufferSize", "-1")); + sendBufferSize = Integer.parseInt(p.getProperty("sendBufferSize", "-1")); + tcpKeepAlive = Boolean.parseBoolean(p.getProperty("tcpkeepalive")); + compatible = p.getProperty("compatible"); + applicationName = p.getProperty("ApplicationName"); + binaryTransfer = Boolean.parseBoolean(p.getProperty("binaryTransfer")); + } /** * Generates a reference using the appropriate object factory.
^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: [PATCH] Expose URL property in BaseDataSource
@ 2013-03-11 22:32  Dave Cramer <pg@fastcrypt.com>
  parent: Loïc PÉRON <loic.peron@bigfoot.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Dave Cramer @ 2013-03-11 22:32 UTC (permalink / raw)
  To: Loïc PÉRON <loic.peron@bigfoot.com>; +Cc: pgsql-jdbc

Looking at the spec these are not part of the Datasource API ? Or am I
mistaken ?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Mon, Mar 11, 2013 at 10:23 AM, Loïc PÉRON <loic.peron@bigfoot.com> wrote:

> Hi all,
>
> The attached patch does the following:
>
> - changes visibility of Driver.parseUrl to public static
>  - changes visibility of BaseDataSource.getUrl to public
>  - add setUrl to BaseDataSourc based on Driver.parseUrl
>
> Adding this property to all datasources simplifies their set-up by
>  using the same url/user/pass as with DriverManager.
>
> --
> Loïc PÉRON
> mailto:loic.peron<at>bigfoot.com
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [PATCH] Expose URL property in BaseDataSource
@ 2013-03-12 11:20  Loïc PÉRON <loic.peron@bigfoot.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Loïc PÉRON @ 2013-03-12 11:20 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc

2013/3/11 Dave Cramer <pg@fastcrypt.com>:
> Looking at the spec these are not part of the Datasource API ? Or am I
> mistaken ?

No they are not, but in fact no connection property is mandated by the
spec regarding DataSources.

It is simply a convenient way of configuring the DataSource, similar
to the configuration through DriverManager: url+user+pass

As the URL parsing is already present in Driver, and the URL building
in BaseDataaSource, I just connected url parsing to the BaseDataSource
attributes.

We currently use Oracle, HSQLDB and Postgresql, which is the only one
not exposing a URL property for datasources.

-- 
Loïc PÉRON
phone:(33) 683 880 177
mailto:loic.peron<at>bigfoot.com


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [PATCH] Expose URL property in BaseDataSource
@ 2013-03-19 22:51  Loïc PÉRON <loic.peron@bigfoot.com>
  parent: Loïc PÉRON <loic.peron@bigfoot.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Loïc PÉRON @ 2013-03-19 22:51 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc

Hi,

Is the patch attached to my initial message
(http://www.postgresql.org/message-id/CAFKiveQyuA+PQ310pV3tLB5yyjWWbNsuyMaLcpuEW3jk8F_uFg@mail.gmail....)
acceptable? Does it need more work?

-- 
Loïc PÉRON
mailto:loic.peron<at>bigfoot.com


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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [PATCH] Expose URL property in BaseDataSource
@ 2013-05-22 12:17  LoïcPÉRON <loic.peron@bigfoot.com>
  parent: Loïc PÉRON <loic.peron@bigfoot.com>
  1 sibling, 1 reply; 8+ messages in thread

From: LoïcPÉRON @ 2013-05-22 12:17 UTC (permalink / raw)
  To: pgsql-jdbc

Hi Dave,

May the patch be included in the upcoming PostgreSQL 9.3 JDBC driver?

http://www.postgresql.org/message-
id/CAFKiveQyuA+PQ310pV3tLB5yyjWWbNsuyMaLcpuEW3jk8F_uFg@mail.gmail.com

Thanks.




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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [PATCH] Expose URL property in BaseDataSource
@ 2013-05-22 12:24  Dave Cramer <pg@fastcrypt.com>
  parent: LoïcPÉRON <loic.peron@bigfoot.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Dave Cramer @ 2013-05-22 12:24 UTC (permalink / raw)
  To: LoïcPÉRON <loic.peron@bigfoot.com>; +Cc: pgsql-jdbc

Hi,

I expect so yes.

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Wed, May 22, 2013 at 8:17 AM, LoïcPÉRON <loic.peron@bigfoot.com> wrote:

> Hi Dave,
>
> May the patch be included in the upcoming PostgreSQL 9.3 JDBC driver?
>
> http://www.postgresql.org/message-
> id/CAFKiveQyuA+PQ310pV3tLB5yyjWWbNsuyMaLcpuEW3jk8F_uFg@mail.gmail.com
>
> Thanks.
>
>
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [PATCH] Expose URL property in BaseDataSource
@ 2013-05-22 13:43  Dave Cramer <pg@fastcrypt.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Dave Cramer @ 2013-05-22 13:43 UTC (permalink / raw)
  To: LoïcPÉRON <loic.peron@bigfoot.com>; +Cc: pgsql-jdbc

Why does the parseURL need to be static or even public in the Driver ?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Wed, May 22, 2013 at 8:24 AM, Dave Cramer <pg@fastcrypt.com> wrote:

> Hi,
>
> I expect so yes.
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On Wed, May 22, 2013 at 8:17 AM, LoïcPÉRON <loic.peron@bigfoot.com> wrote:
>
>> Hi Dave,
>>
>> May the patch be included in the upcoming PostgreSQL 9.3 JDBC driver?
>>
>> http://www.postgresql.org/message-
>> id/CAFKiveQyuA+PQ310pV3tLB5yyjWWbNsuyMaLcpuEW3jk8F_uFg@mail.gmail.com
>>
>> Thanks.
>>
>>
>>
>>
>> --
>> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-jdbc
>>
>
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: [PATCH] Expose URL property in BaseDataSource
@ 2013-05-22 16:28  LoïcPÉRON <loic.peron@bigfoot.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 8+ messages in thread

From: LoïcPÉRON @ 2013-05-22 16:28 UTC (permalink / raw)
  To: pgsql-jdbc

Dave Cramer <pg <at> fastcrypt.com> writes:

> Why does the parseURL need to be static or even public in the Driver ?

To be used from BaseDataSource without requiring instantiation.

-- 
Loïc PÉRON





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



^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2013-05-22 16:28 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-03-11 14:23 [PATCH] Expose URL property in BaseDataSource Loïc PÉRON <loic.peron@bigfoot.com>
2013-03-11 22:32 ` Dave Cramer <pg@fastcrypt.com>
2013-03-12 11:20   ` Loïc PÉRON <loic.peron@bigfoot.com>
2013-03-19 22:51     ` Loïc PÉRON <loic.peron@bigfoot.com>
2013-05-22 12:17 ` LoïcPÉRON <loic.peron@bigfoot.com>
2013-05-22 12:24   ` Dave Cramer <pg@fastcrypt.com>
2013-05-22 13:43     ` Dave Cramer <pg@fastcrypt.com>
2013-05-22 16:28       ` LoïcPÉRON <loic.peron@bigfoot.com>

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