mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
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
This commit is contained in:
@ -8,7 +8,7 @@ import java.sql.*;
|
||||
* Base class for data sources and related classes.
|
||||
*
|
||||
* @author Aaron Mulder (ammulder@chariotsolutions.com)
|
||||
* @version $Revision: 1.2 $
|
||||
* @version $Revision: 1.3 $
|
||||
*/
|
||||
public abstract class BaseDataSource implements Referenceable
|
||||
{
|
||||
@ -233,9 +233,18 @@ public abstract class BaseDataSource implements Referenceable
|
||||
return "jdbc:postgresql://" + serverName + (portNumber == 0 ? "" : ":" + portNumber) + "/" + databaseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a reference using the appropriate object factory. This
|
||||
* implementation uses the JDBC 2 optional package object factory.
|
||||
*/
|
||||
protected Reference createReference()
|
||||
{
|
||||
return new Reference(getClass().getName(), PGObjectFactory.class.getName(), null);
|
||||
}
|
||||
|
||||
public Reference getReference() throws NamingException
|
||||
{
|
||||
Reference ref = new Reference(getClass().getName(), PGObjectFactory.class.getName(), null);
|
||||
Reference ref = createReference();
|
||||
ref.add(new StringRefAddr("serverName", serverName));
|
||||
if (portNumber != 0)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ import java.util.Hashtable;
|
||||
* consistent.
|
||||
*
|
||||
* @author Aaron Mulder (ammulder@chariotsolutions.com)
|
||||
* @version $Revision: 1.2 $
|
||||
* @version $Revision: 1.3 $
|
||||
*/
|
||||
public class PGObjectFactory implements ObjectFactory
|
||||
{
|
||||
@ -81,7 +81,7 @@ public class PGObjectFactory implements ObjectFactory
|
||||
return loadBaseDataSource(cp, ref);
|
||||
}
|
||||
|
||||
private Object loadBaseDataSource(BaseDataSource ds, Reference ref)
|
||||
protected Object loadBaseDataSource(BaseDataSource ds, Reference ref)
|
||||
{
|
||||
ds.setDatabaseName(getProperty(ref, "databaseName"));
|
||||
ds.setPassword(getProperty(ref, "password"));
|
||||
@ -95,7 +95,7 @@ public class PGObjectFactory implements ObjectFactory
|
||||
return ds;
|
||||
}
|
||||
|
||||
private String getProperty(Reference ref, String s)
|
||||
protected String getProperty(Reference ref, String s)
|
||||
{
|
||||
RefAddr addr = ref.get(s);
|
||||
if (addr == null)
|
||||
|
@ -13,7 +13,7 @@ import java.lang.reflect.*;
|
||||
* @see ConnectionPool
|
||||
*
|
||||
* @author Aaron Mulder (ammulder@chariotsolutions.com)
|
||||
* @version $Revision: 1.2 $
|
||||
* @version $Revision: 1.3 $
|
||||
*/
|
||||
public class PooledConnectionImpl implements PooledConnection
|
||||
{
|
||||
@ -26,7 +26,7 @@ public class PooledConnectionImpl implements PooledConnection
|
||||
* Creates a new PooledConnection representing the specified physical
|
||||
* connection.
|
||||
*/
|
||||
PooledConnectionImpl(Connection con, boolean autoCommit)
|
||||
protected PooledConnectionImpl(Connection con, boolean autoCommit)
|
||||
{
|
||||
this.con = con;
|
||||
this.autoCommit = autoCommit;
|
||||
|
@ -33,7 +33,7 @@ import java.sql.SQLException;
|
||||
* <p>This implementation supports JDK 1.3 and higher.</p>
|
||||
*
|
||||
* @author Aaron Mulder (ammulder@chariotsolutions.com)
|
||||
* @version $Revision: 1.2 $
|
||||
* @version $Revision: 1.3 $
|
||||
*/
|
||||
public class PoolingDataSource extends BaseDataSource implements DataSource
|
||||
{
|
||||
@ -45,7 +45,7 @@ public class PoolingDataSource extends BaseDataSource implements DataSource
|
||||
}
|
||||
|
||||
// Additional Data Source properties
|
||||
private String dataSourceName;
|
||||
protected String dataSourceName; // Must be protected for subclasses to sync updates to it
|
||||
private int initialConnections = 0;
|
||||
private int maxConnections = 0;
|
||||
// State variables
|
||||
@ -262,7 +262,7 @@ public class PoolingDataSource extends BaseDataSource implements DataSource
|
||||
* that number of connections will be created. After this method is called,
|
||||
* the DataSource properties cannot be changed. If you do not call this
|
||||
* explicitly, it will be called the first time you get a connection from the
|
||||
* Datasource.
|
||||
* DataSource.
|
||||
* @throws java.sql.SQLException
|
||||
* Occurs when the initialConnections is greater than zero, but the
|
||||
* DataSource is not able to create enough physical connections.
|
||||
@ -271,7 +271,7 @@ public class PoolingDataSource extends BaseDataSource implements DataSource
|
||||
{
|
||||
synchronized (lock)
|
||||
{
|
||||
source = new ConnectionPool();
|
||||
source = createConnectionPool();
|
||||
source.setDatabaseName(getDatabaseName());
|
||||
source.setPassword(getPassword());
|
||||
source.setPortNumber(getPortNumber());
|
||||
@ -285,6 +285,17 @@ public class PoolingDataSource extends BaseDataSource implements DataSource
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the appropriate ConnectionPool to use for this DataSource.
|
||||
*/
|
||||
protected ConnectionPool createConnectionPool() {
|
||||
return new ConnectionPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a <b>non-pooled</b> connection, unless the user and password are the
|
||||
* same as the default values for this connection pool.
|
||||
@ -358,13 +369,17 @@ public class PoolingDataSource extends BaseDataSource implements DataSource
|
||||
}
|
||||
used = null;
|
||||
}
|
||||
synchronized (dataSources)
|
||||
{
|
||||
dataSources.remove(dataSourceName);
|
||||
}
|
||||
}
|
||||
removeStoredDataSource();
|
||||
}
|
||||
|
||||
/**
|
||||
protected void removeStoredDataSource() {
|
||||
synchronized (dataSources)
|
||||
{
|
||||
dataSources.remove(dataSourceName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a connection from the pool. Will get an available one if
|
||||
* present, or create a new one if under the max limit. Will
|
||||
* block if all used and a new one would exceed the max.
|
||||
|
Reference in New Issue
Block a user