org.postgresql.ds.common
Class BaseDataSource

java.lang.Object
  extended by org.postgresql.ds.common.BaseDataSource
All Implemented Interfaces:
Referenceable
Direct Known Subclasses:
org.postgresql.ds.jdbc23.AbstractJdbc23PoolingDataSource, org.postgresql.ds.jdbc23.AbstractJdbc23SimpleDataSource, PGConnectionPoolDataSource, PGXADataSource

public abstract class BaseDataSource
extends Object
implements Referenceable

Base class for data sources and related classes.

Author:
Aaron Mulder (ammulder@chariotsolutions.com)

Constructor Summary
BaseDataSource()
           
 
Method Summary
protected  Reference createReference()
          Generates a reference using the appropriate object factory.
 String getCompatible()
           
 Connection getConnection()
          Gets a connection to the PostgreSQL database.
 Connection getConnection(String user, String password)
          Gets a connection to the PostgreSQL database.
 String getDatabaseName()
          Gets the name of the PostgreSQL database, running on the server identified by the serverName property.
abstract  String getDescription()
          Gets a description of this DataSource-ish thing.
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
          Gets the log writer used to log connections opened.
 String getPassword()
          Gets the password to connect with by default.
 int getPortNumber()
          Gets the port which the PostgreSQL server is listening on for TCP/IP connections.
 int getPrepareThreshold()
          Gets the default threshold for enabling server-side prepare.
 Reference getReference()
           
 String getServerName()
          Gets the name of the host the PostgreSQL database is running on.
 int getSocketTimeout()
           
 boolean getSsl()
          Gets SSL encryption setting.
 String getSslfactory()
          Gets the name of the SSLSocketFactory used for connections.
 boolean getTcpKeepAlive()
           
 int getUnknownLength()
           
 String getUser()
          Gets the user to connect as by default.
 void initializeFrom(BaseDataSource source)
           
protected  void readBaseObject(ObjectInputStream in)
           
 void setCompatible(String compatible)
           
 void setDatabaseName(String databaseName)
          Sets the name of the PostgreSQL database, running on the server identified by the serverName property.
 void setLoginTimeout(int i)
          Set the login timeout, in seconds.
 void setLogWriter(PrintWriter printWriter)
          The DataSource will note every connection opened to the provided log writer.
 void setPassword(String password)
          Sets the password to connect with by default.
 void setPortNumber(int portNumber)
          Gets the port which the PostgreSQL server is listening on for TCP/IP connections.
 void setPrepareThreshold(int count)
          Sets the default threshold for enabling server-side prepare.
 void setServerName(String serverName)
          Sets the name of the host the PostgreSQL database is running on.
 void setSocketTimeout(int seconds)
          Sets the socket timeout (SOTimeout), in seconds
 void setSsl(boolean enabled)
          Set whether the connection will be SSL encrypted or not.
 void setSslfactory(String classname)
          Set the name of the SSLSocketFactory to use for connections.
 void setTcpKeepAlive(boolean enabled)
           
 void setUnknownLength(int unknownLength)
           
 void setUser(String user)
          Sets the user to connect as by default.
protected  void writeBaseObject(ObjectOutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseDataSource

public BaseDataSource()
Method Detail

getConnection

public Connection getConnection()
                         throws SQLException
Gets a connection to the PostgreSQL database. The database is identified by the DataSource properties serverName, databaseName, and portNumber. The user to connect as is identified by the DataSource properties user and password.

Returns:
A valid database connection.
Throws:
SQLException - Occurs when the database connection cannot be established.

getConnection

public Connection getConnection(String user,
                                String password)
                         throws SQLException
Gets a connection to the PostgreSQL database. The database is identified by the DataSource properties serverName, databaseName, and portNumber. The user to connect as is identified by the arguments user and password, which override the DataSource properties by the same name.

Returns:
A valid database connection.
Throws:
SQLException - Occurs when the database connection cannot be established.

getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
Returns:
the login timeout, in seconds.
Throws:
SQLException

setLoginTimeout

public void setLoginTimeout(int i)
                     throws SQLException
Set the login timeout, in seconds.

Throws:
SQLException

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Gets the log writer used to log connections opened.

Throws:
SQLException

setLogWriter

public void setLogWriter(PrintWriter printWriter)
                  throws SQLException
The DataSource will note every connection opened to the provided log writer.

Throws:
SQLException

getServerName

public String getServerName()
Gets the name of the host the PostgreSQL database is running on.


setServerName

public void setServerName(String serverName)
Sets the name of the host the PostgreSQL database is running on. If this is changed, it will only affect future calls to getConnection. The default value is localhost.


getCompatible

public String getCompatible()

setCompatible

public void setCompatible(String compatible)

getDatabaseName

public String getDatabaseName()
Gets the name of the PostgreSQL database, running on the server identified by the serverName property.


setDatabaseName

public void setDatabaseName(String databaseName)
Sets the name of the PostgreSQL database, running on the server identified by the serverName property. If this is changed, it will only affect future calls to getConnection.


getDescription

public abstract String getDescription()
Gets a description of this DataSource-ish thing. Must be customized by subclasses.


getUser

public String getUser()
Gets the user to connect as by default. If this is not specified, you must use the getConnection method which takes a user and password as parameters.


setUser

public void setUser(String user)
Sets the user to connect as by default. If this is not specified, you must use the getConnection method which takes a user and password as parameters. If this is changed, it will only affect future calls to getConnection.


getPassword

public String getPassword()
Gets the password to connect with by default. If this is not specified but a password is needed to log in, you must use the getConnection method which takes a user and password as parameters.


setPassword

public void setPassword(String password)
Sets the password to connect with by default. If this is not specified but a password is needed to log in, you must use the getConnection method which takes a user and password as parameters. If this is changed, it will only affect future calls to getConnection.


getPortNumber

public int getPortNumber()
Gets the port which the PostgreSQL server is listening on for TCP/IP connections.

Returns:
The port, or 0 if the default port will be used.

setPortNumber

public void setPortNumber(int portNumber)
Gets the port which the PostgreSQL server is listening on for TCP/IP connections. Be sure the -i flag is passed to postmaster when PostgreSQL is started. If this is not set, or set to 0, the default port will be used.


setPrepareThreshold

public void setPrepareThreshold(int count)
Sets the default threshold for enabling server-side prepare. See PGConnection.setPrepareThreshold(int) for details.

Parameters:
count - the number of times a statement object must be reused before server-side prepare is enabled.

getPrepareThreshold

public int getPrepareThreshold()
Gets the default threshold for enabling server-side prepare.

See Also:
setPrepareThreshold(int)

setUnknownLength

public void setUnknownLength(int unknownLength)

getUnknownLength

public int getUnknownLength()

setSocketTimeout

public void setSocketTimeout(int seconds)
Sets the socket timeout (SOTimeout), in seconds


getSocketTimeout

public int getSocketTimeout()
Returns:
the socket timeout (SOTimeout), in seconds

setSsl

public void setSsl(boolean enabled)
Set whether the connection will be SSL encrypted or not.

Parameters:
enabled - if true, connect with SSL.

getSsl

public boolean getSsl()
Gets SSL encryption setting.

Returns:
true if connections will be encrypted with SSL.

setSslfactory

public void setSslfactory(String classname)
Set the name of the SSLSocketFactory to use for connections. Use org.postgresql.ssl.NonValidatingFactory if you don't want certificate validation.

Parameters:
classname - name of a subclass of javax.net.ssl.SSLSocketFactory or null for the default implementation.

getSslfactory

public String getSslfactory()
Gets the name of the SSLSocketFactory used for connections.

Returns:
name of the class or null if the default implementation is used.

setTcpKeepAlive

public void setTcpKeepAlive(boolean enabled)

getTcpKeepAlive

public boolean getTcpKeepAlive()

createReference

protected Reference createReference()
Generates a reference using the appropriate object factory.


getReference

public Reference getReference()
                       throws NamingException
Specified by:
getReference in interface Referenceable
Throws:
NamingException

writeBaseObject

protected void writeBaseObject(ObjectOutputStream out)
                        throws IOException
Throws:
IOException

readBaseObject

protected void readBaseObject(ObjectInputStream in)
                       throws IOException,
                              ClassNotFoundException
Throws:
IOException
ClassNotFoundException

initializeFrom

public void initializeFrom(BaseDataSource source)
                    throws IOException,
                           ClassNotFoundException
Throws:
IOException
ClassNotFoundException