Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7bf1c8b

Browse files
author
Barry Lind
committed
Applied patch from Aaron Mulder (ammulder@alumni.princeton.edu) that fixes
jdbc datasource support for jdk1.4/jdbc3 Modified Files: jdbc/build.xml jdbc/org/postgresql/Driver.java.in jdbc/org/postgresql/jdbc2/optional/BaseDataSource.java jdbc/org/postgresql/jdbc2/optional/PGObjectFactory.java jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java jdbc/org/postgresql/jdbc2/optional/PoolingDataSource.java jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java jdbc/org/postgresql/test/jdbc2/optional/OptionalTestSuite.java jdbc/org/postgresql/test/jdbc3/Jdbc3TestSuite.java Added Files: jdbc/org/postgresql/jdbc3/Jdbc3ConnectionPool.java jdbc/org/postgresql/jdbc3/Jdbc3ObjectFactory.java jdbc/org/postgresql/jdbc3/Jdbc3PooledConnection.java jdbc/org/postgresql/jdbc3/Jdbc3PoolingDataSource.java jdbc/org/postgresql/jdbc3/Jdbc3SimpleDataSource.java jdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java jdbc/org/postgresql/test/jdbc3/Jdbc3ConnectionPoolTest.java jdbc/org/postgresql/test/jdbc3/Jdbc3PoolingDataSourceTest.java jdbc/org/postgresql/test/jdbc3/Jdbc3SimpleDataSourceTest.java jdbc/org/postgresql/test/util/MiniJndiContext.java jdbc/org/postgresql/test/util/MiniJndiContextFactory.java
1 parent65bf5a3 commit7bf1c8b

20 files changed

+1023
-31
lines changed

‎src/interfaces/jdbc/build.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
This file now requires Ant 1.4.1. 2002-04-18
88
9-
$Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.28 2002/08/14 20:35:39 barry Exp $
9+
$Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.29 2002/09/25 07:01:30 barry Exp $
1010
1111
-->
1212

@@ -262,6 +262,7 @@
262262
<targetname="testjdbc2optional"depends="jar"if="jdbc2optionaltests">
263263
<javacsrcdir="${srcdir}"destdir="${builddir}"debug="${debug}">
264264
<includename="${package}/test/jdbc2/optional/**" />
265+
<includename="${package}/test/util/**" />
265266
</javac>
266267
<javafork="yes"classname="junit.${junit.ui}.TestRunner"taskname="junit"failonerror="true">
267268
<argvalue="org.postgresql.test.jdbc2.optional.OptionalTestSuite" />
@@ -278,6 +279,7 @@
278279
<targetname="testjdbc3"depends="jar"if="jdbc3tests">
279280
<javacsrcdir="${srcdir}"destdir="${builddir}"debug="${debug}">
280281
<includename="${package}/test/jdbc3/*" />
282+
<includename="${package}/test/util/*" />
281283
</javac>
282284
<javafork="yes"classname="junit.${junit.ui}.TestRunner"taskname="junit"failonerror="true">
283285
<argvalue="org.postgresql.test.jdbc3.Jdbc3TestSuite" />

‎src/interfaces/jdbc/org/postgresql/Driver.java.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,6 @@ public class Driver implements java.sql.Driver
446446
}
447447

448448
//The build number should be incremented for every new build
449-
private static int m_buildNumber =105;
449+
private static int m_buildNumber =106;
450450

451451
}

‎src/interfaces/jdbc/org/postgresql/jdbc2/optional/BaseDataSource.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Base class for data sources and related classes.
99
*
1010
* @author Aaron Mulder (ammulder@chariotsolutions.com)
11-
* @version $Revision: 1.2 $
11+
* @version $Revision: 1.3 $
1212
*/
1313
publicabstractclassBaseDataSourceimplementsReferenceable
1414
{
@@ -233,9 +233,18 @@ private String getUrl()
233233
return"jdbc:postgresql://" +serverName + (portNumber ==0 ?"" :":" +portNumber) +"/" +databaseName;
234234
}
235235

236+
/**
237+
* Generates a reference using the appropriate object factory. This
238+
* implementation uses the JDBC 2 optional package object factory.
239+
*/
240+
protectedReferencecreateReference()
241+
{
242+
returnnewReference(getClass().getName(),PGObjectFactory.class.getName(),null);
243+
}
244+
236245
publicReferencegetReference()throwsNamingException
237246
{
238-
Referenceref =newReference(getClass().getName(),PGObjectFactory.class.getName(),null);
247+
Referenceref =createReference();
239248
ref.add(newStringRefAddr("serverName",serverName));
240249
if (portNumber !=0)
241250
{

‎src/interfaces/jdbc/org/postgresql/jdbc2/optional/PGObjectFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* consistent.
1414
*
1515
* @author Aaron Mulder (ammulder@chariotsolutions.com)
16-
* @version $Revision: 1.2 $
16+
* @version $Revision: 1.3 $
1717
*/
1818
publicclassPGObjectFactoryimplementsObjectFactory
1919
{
@@ -81,7 +81,7 @@ private Object loadConnectionPool(Reference ref)
8181
returnloadBaseDataSource(cp,ref);
8282
}
8383

84-
privateObjectloadBaseDataSource(BaseDataSourceds,Referenceref)
84+
protectedObjectloadBaseDataSource(BaseDataSourceds,Referenceref)
8585
{
8686
ds.setDatabaseName(getProperty(ref,"databaseName"));
8787
ds.setPassword(getProperty(ref,"password"));
@@ -95,7 +95,7 @@ private Object loadBaseDataSource(BaseDataSource ds, Reference ref)
9595
returnds;
9696
}
9797

98-
privateStringgetProperty(Referenceref,Strings)
98+
protectedStringgetProperty(Referenceref,Strings)
9999
{
100100
RefAddraddr =ref.get(s);
101101
if (addr ==null)

‎src/interfaces/jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @see ConnectionPool
1414
*
1515
* @author Aaron Mulder (ammulder@chariotsolutions.com)
16-
* @version $Revision: 1.2 $
16+
* @version $Revision: 1.3 $
1717
*/
1818
publicclassPooledConnectionImplimplementsPooledConnection
1919
{
@@ -26,7 +26,7 @@ public class PooledConnectionImpl implements PooledConnection
2626
* Creates a new PooledConnection representing the specified physical
2727
* connection.
2828
*/
29-
PooledConnectionImpl(Connectioncon,booleanautoCommit)
29+
protectedPooledConnectionImpl(Connectioncon,booleanautoCommit)
3030
{
3131
this.con =con;
3232
this.autoCommit =autoCommit;

‎src/interfaces/jdbc/org/postgresql/jdbc2/optional/PoolingDataSource.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* <p>This implementation supports JDK 1.3 and higher.</p>
3434
*
3535
* @author Aaron Mulder (ammulder@chariotsolutions.com)
36-
* @version $Revision: 1.2 $
36+
* @version $Revision: 1.3 $
3737
*/
3838
publicclassPoolingDataSourceextendsBaseDataSourceimplementsDataSource
3939
{
@@ -45,7 +45,7 @@ static PoolingDataSource getDataSource(String name)
4545
}
4646

4747
// Additional Data Source properties
48-
privateStringdataSourceName;
48+
protectedStringdataSourceName;// Must be protected for subclasses to sync updates to it
4949
privateintinitialConnections =0;
5050
privateintmaxConnections =0;
5151
// State variables
@@ -262,7 +262,7 @@ public void setDataSourceName(String dataSourceName)
262262
* that number of connections will be created.After this method is called,
263263
* the DataSource properties cannot be changed. If you do not call this
264264
* explicitly, it will be called the first time you get a connection from the
265-
*Datasource.
265+
*DataSource.
266266
* @throws java.sql.SQLException
267267
* Occurs when the initialConnections is greater than zero, but the
268268
* DataSource is not able to create enough physical connections.
@@ -271,7 +271,7 @@ public void initialize() throws SQLException
271271
{
272272
synchronized (lock)
273273
{
274-
source =newConnectionPool();
274+
source =createConnectionPool();
275275
source.setDatabaseName(getDatabaseName());
276276
source.setPassword(getPassword());
277277
source.setPortNumber(getPortNumber());
@@ -285,6 +285,17 @@ public void initialize() throws SQLException
285285
}
286286
}
287287

288+
protectedbooleanisInitialized() {
289+
returninitialized;
290+
}
291+
292+
/**
293+
* Creates the appropriate ConnectionPool to use for this DataSource.
294+
*/
295+
protectedConnectionPoolcreateConnectionPool() {
296+
returnnewConnectionPool();
297+
}
298+
288299
/**
289300
* Gets a <b>non-pooled</b> connection, unless the user and password are the
290301
* same as the default values for this connection pool.
@@ -358,13 +369,17 @@ public void close()
358369
}
359370
used =null;
360371
}
361-
synchronized (dataSources)
362-
{
363-
dataSources.remove(dataSourceName);
364-
}
365-
}
372+
removeStoredDataSource();
373+
}
366374

367-
/**
375+
protectedvoidremoveStoredDataSource() {
376+
synchronized (dataSources)
377+
{
378+
dataSources.remove(dataSourceName);
379+
}
380+
}
381+
382+
/**
368383
* Gets a connection from the pool. Will get an available one if
369384
* present, or create a new one if under the max limit. Will
370385
* block if all used and a new one would exceed the max.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
packageorg.postgresql.jdbc3;
2+
3+
importorg.postgresql.jdbc2.optional.ConnectionPool;
4+
5+
importjavax.sql.PooledConnection;
6+
importjavax.naming.Reference;
7+
importjava.sql.SQLException;
8+
9+
/**
10+
* Jdbc3 implementation of ConnectionPoolDataSource. This is
11+
* typically the interface used by an app server to interact
12+
* with connection pools provided by a JDBC driver. PostgreSQL
13+
* does not support XADataSource, the other common connection
14+
* pooling interface (for connections supporting the two-phase
15+
* commit protocol).
16+
*
17+
* @author Aaron Mulder (ammulder@alumni.princeton.edu)
18+
* @version $Revision: 1.1 $
19+
*/
20+
publicclassJdbc3ConnectionPoolextendsConnectionPool
21+
{
22+
/**
23+
* Gets a description of this DataSource.
24+
*/
25+
publicStringgetDescription()
26+
{
27+
return"Jdbc3ConnectionPool from " +org.postgresql.Driver.getVersion();
28+
}
29+
30+
/**
31+
* Gets a connection which may be pooled by the app server or middleware
32+
* implementation of DataSource.
33+
*
34+
* @throws java.sql.SQLException
35+
* Occurs when the physical database connection cannot be established.
36+
*/
37+
publicPooledConnectiongetPooledConnection()throwsSQLException
38+
{
39+
returnnewJdbc3PooledConnection(getConnection(),isDefaultAutoCommit());
40+
}
41+
42+
/**
43+
* Gets a connection which may be pooled by the app server or middleware
44+
* implementation of DataSource.
45+
*
46+
* @throws java.sql.SQLException
47+
* Occurs when the physical database connection cannot be established.
48+
*/
49+
publicPooledConnectiongetPooledConnection(Stringuser,Stringpassword)throwsSQLException
50+
{
51+
returnnewJdbc3PooledConnection(getConnection(user,password),isDefaultAutoCommit());
52+
}
53+
54+
/**
55+
* Generates a JDBC object factory reference.
56+
*/
57+
protectedReferencecreateReference()
58+
{
59+
returnnewReference(getClass().getName(),Jdbc3ObjectFactory.class.getName(),null);
60+
}
61+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
packageorg.postgresql.jdbc3;
2+
3+
importjava.util.*;
4+
importjavax.naming.*;
5+
importorg.postgresql.jdbc2.optional.PGObjectFactory;
6+
7+
/**
8+
* JDBC3 version of the Object Factory used to recreate objects
9+
* from their JNDI references.
10+
*
11+
* @author Aaron Mulder (ammulder@alumni.princeton.edu)
12+
* @version $Revision: 1.1 $
13+
*/
14+
publicclassJdbc3ObjectFactoryextendsPGObjectFactory
15+
{
16+
/**
17+
* Dereferences a PostgreSQL DataSource. Other types of references are
18+
* ignored.
19+
*/
20+
publicObjectgetObjectInstance(Objectobj,Namename,ContextnameCtx,
21+
Hashtableenvironment)throwsException
22+
{
23+
Referenceref = (Reference)obj;
24+
if (ref.getClassName().equals(Jdbc3SimpleDataSource.class.getName()))
25+
{
26+
returnloadSimpleDataSource(ref);
27+
}
28+
elseif (ref.getClassName().equals(Jdbc3ConnectionPool.class.getName()))
29+
{
30+
returnloadConnectionPool(ref);
31+
}
32+
elseif (ref.getClassName().equals(Jdbc3PoolingDataSource.class.getName()))
33+
{
34+
returnloadPoolingDataSource(ref);
35+
}
36+
else
37+
{
38+
returnnull;
39+
}
40+
}
41+
42+
privateObjectloadPoolingDataSource(Referenceref)
43+
{
44+
// If DataSource exists, return it
45+
Stringname =getProperty(ref,"dataSourceName");
46+
Jdbc3PoolingDataSourcepds =Jdbc3PoolingDataSource.getDataSource(name);
47+
if (pds !=null)
48+
{
49+
returnpds;
50+
}
51+
// Otherwise, create a new one
52+
pds =newJdbc3PoolingDataSource();
53+
pds.setDataSourceName(name);
54+
loadBaseDataSource(pds,ref);
55+
Stringmin =getProperty(ref,"initialConnections");
56+
if (min !=null)
57+
{
58+
pds.setInitialConnections(Integer.parseInt(min));
59+
}
60+
Stringmax =getProperty(ref,"maxConnections");
61+
if (max !=null)
62+
{
63+
pds.setMaxConnections(Integer.parseInt(max));
64+
}
65+
returnpds;
66+
}
67+
68+
privateObjectloadSimpleDataSource(Referenceref)
69+
{
70+
Jdbc3SimpleDataSourceds =newJdbc3SimpleDataSource();
71+
returnloadBaseDataSource(ds,ref);
72+
}
73+
74+
privateObjectloadConnectionPool(Referenceref)
75+
{
76+
Jdbc3ConnectionPoolcp =newJdbc3ConnectionPool();
77+
returnloadBaseDataSource(cp,ref);
78+
}
79+
80+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packageorg.postgresql.jdbc3;
2+
3+
importorg.postgresql.jdbc2.optional.PooledConnectionImpl;
4+
5+
importjava.sql.Connection;
6+
7+
/**
8+
* JDBC3 implementation of PooledConnection, which manages
9+
* a connection in a connection pool.
10+
*
11+
* @author Aaron Mulder (ammulder@alumni.princeton.edu)
12+
* @version $Revision: 1.1 $
13+
*/
14+
publicclassJdbc3PooledConnectionextendsPooledConnectionImpl
15+
{
16+
Jdbc3PooledConnection(Connectioncon,booleanautoCommit)
17+
{
18+
super(con,autoCommit);
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp