com.foundationdb.sql.jdbc.ds.common

## Class BaseDataSource

- java.lang.Object
- - com.foundationdb.sql.jdbc.ds.common.BaseDataSource

All Implemented Interfaces:
  javax.naming.Referenceable

Direct Known Subclasses:
  com.foundationdb.sql.jdbc.ds.jdbc23.AbstractJdbc23ConnectionPoolDataSource, com.foundationdb.sql.jdbc.ds.jdbc23.AbstractJdbc23PoolingDataSource, com.foundationdb.sql.jdbc.ds.jdbc23.AbstractJdbc23SimpleDataSource, com.foundationdb.sql.jdbc.xa.jdbc3.AbstractJdbc3XADataSource

    public abstract class BaseDataSource
    extends java.lang.Object
    implements javax.naming.Referenceable

Base class for data sources and related classes.

Author:
  Aaron Mulder (ammulder@chariotsolutions.com)

### Constructor Summary

Constructors
Constructor and Description
`BaseDataSource()`

### Method Summary

Methods
`protected javax.naming.Reference` `createReference()` Generates a reference using the appropriate object factory.
`java.lang.String` `getApplicationName()`
`boolean` `getBinaryTransfer()` Gets the protocol transfer mode.
`java.lang.String` `getBinaryTransferDisable()` Gets override set of Oid values that have binary transfer disabled.
`java.lang.String` `getBinaryTransferEnable()` Gets override set of Oid values that have binary transfer enabled.
`java.lang.String` `getCompatible()`
`java.sql.Connection` `getConnection()` Gets a connection to the PostgreSQL database.
`java.sql.Connection` `getConnection(java.lang.String user, java.lang.String password)` Gets a connection to the PostgreSQL database.
`java.lang.String` `getDatabaseName()` Gets the name of the PostgreSQL database, running on the server identified by the serverName property.
`abstract java.lang.String` `getDescription()` Gets a description of this DataSource-ish thing.
`int` `getLoginTimeout()`
`int` `getLogLevel()`
`java.io.PrintWriter` `getLogWriter()` Gets the log writer used to log connections opened.
`java.lang.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.
`java.lang.String` `getProtocol()`
`int` `getProtocolVersion()`
`int` `getReceiveBufferSize()` Gets the write buffer size of TCP/IP socket.
`javax.naming.Reference` `getReference()`
`int` `getSendBufferSize()` Gets the send buffer size of TCP/IP socket.
`java.lang.String` `getServerName()` Gets the name of the host the PostgreSQL database is running on.
`int` `getSocketTimeout()`
`boolean` `getSsl()` Gets SSL encryption setting.
`java.lang.String` `getSslfactory()` Gets the name of the `SSLSocketFactory` used for connections.
`java.lang.String` `getStringType()`
`boolean` `getTcpKeepAlive()`
`int` `getUnknownLength()`
`java.lang.String` `getUrl()` Generates a DriverManager URL from the other properties supplied.
`java.lang.String` `getUser()` Gets the user to connect as by default.
`void` `initializeFrom(BaseDataSource source)`
`protected void` `readBaseObject(java.io.ObjectInputStream in)`
`void` `setApplicationName(java.lang.String applicationName)`
`void` `setBinaryTransfer(boolean enabled)` Sets protocol transfer mode.
`void` `setBinaryTransferDisable(java.lang.String oidList)` Add types to the override set of `Oid` values that will not be used for binary transfer.
`void` `setBinaryTransferEnable(java.lang.String oidList)` Add types to the override set of `Oid` values used for binary transfer.
`void` `setCompatible(java.lang.String compatible)`
`void` `setDatabaseName(java.lang.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` `setLogLevel(int logLevel)`
`void` `setLogWriter(java.io.PrintWriter printWriter)` The DataSource will note every connection opened to the provided log writer.
`void` `setPassword(java.lang.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` `setProtocol(java.lang.String protocol)`
`void` `setProtocolVersion(int protocolVersion)`
`void` `setReceiveBufferSize(int nbytes)` Sets the write buffer size of TCP/IP socket.
`void` `setSendBufferSize(int nbytes)` Sets the send buffer size of TCP/IP socket.
`void` `setServerName(java.lang.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(java.lang.String classname)` Set the name of the `SSLSocketFactory` to use for connections.
`void` `setStringType(java.lang.String stringType)`
`void` `setTcpKeepAlive(boolean enabled)`
`void` `setUnknownLength(int unknownLength)`
`void` `setUrl(java.lang.String url)` Sets properties from a DriverManager URL.
`void` `setUser(java.lang.String user)` Sets the user to connect as by default.
`protected void` `writeBaseObject(java.io.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 java.sql.Connection getConnection()
                                      throws java.sql.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:
  `java.sql.SQLException` - Occurs when the database connection cannot be established.

#### getConnection

    public java.sql.Connection getConnection(java.lang.String user,
                                    java.lang.String password)
                                      throws java.sql.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:
  `java.sql.SQLException` - Occurs when the database connection cannot be established.

#### getLoginTimeout

    public int getLoginTimeout()
                        throws java.sql.SQLException

Returns:
  the login timeout, in seconds.
Throws:
  `java.sql.SQLException`

#### setLoginTimeout

    public void setLoginTimeout(int i)
                         throws java.sql.SQLException

Set the login timeout, in seconds.

Throws:
  `java.sql.SQLException`

#### getLogWriter

    public java.io.PrintWriter getLogWriter()
                                     throws java.sql.SQLException

Gets the log writer used to log connections opened.

Throws:
  `java.sql.SQLException`

#### setLogWriter

    public void setLogWriter(java.io.PrintWriter printWriter)
                      throws java.sql.SQLException

The DataSource will note every connection opened to the provided log writer.

Throws:
  `java.sql.SQLException`

#### getServerName

    public java.lang.String getServerName()

Gets the name of the host the PostgreSQL database is running on.

#### setServerName

    public void setServerName(java.lang.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 java.lang.String getCompatible()

#### setCompatible

    public void setCompatible(java.lang.String compatible)

#### getLogLevel

    public int getLogLevel()

#### setLogLevel

    public void setLogLevel(int logLevel)

#### getProtocolVersion

    public int getProtocolVersion()

#### setProtocolVersion

    public void setProtocolVersion(int protocolVersion)

#### getDatabaseName

    public java.lang.String getDatabaseName()

Gets the name of the PostgreSQL database, running on the server identified by the serverName property.

#### setDatabaseName

    public void setDatabaseName(java.lang.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 java.lang.String getDescription()

Gets a description of this DataSource-ish thing. Must be customized by subclasses.

#### getUser

    public java.lang.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(java.lang.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 java.lang.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(java.lang.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.

#### getReceiveBufferSize

    public int getReceiveBufferSize()

Gets the write buffer size of TCP/IP socket.

#### setReceiveBufferSize

    public void setReceiveBufferSize(int nbytes)

Sets the write buffer size of TCP/IP socket.

#### getSendBufferSize

    public int getSendBufferSize()

Gets the send buffer size of TCP/IP socket.

#### setSendBufferSize

    public void setSendBufferSize(int nbytes)

Sets the send buffer size of TCP/IP socket.

#### 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(java.lang.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 java.lang.String getSslfactory()

Gets the name of the `SSLSocketFactory` used for connections.

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

#### setApplicationName

    public void setApplicationName(java.lang.String applicationName)

#### getApplicationName

    public java.lang.String getApplicationName()

#### setTcpKeepAlive

    public void setTcpKeepAlive(boolean enabled)

#### getTcpKeepAlive

    public boolean getTcpKeepAlive()

#### setProtocol

    public void setProtocol(java.lang.String protocol)

#### getProtocol

    public java.lang.String getProtocol()

#### setBinaryTransfer

    public void setBinaryTransfer(boolean enabled)

Sets protocol transfer mode.

Parameters:
  `enabled` - True if the binary transfer mode is used for supported field types, false if text based transfer is used.

#### getBinaryTransfer

    public boolean getBinaryTransfer()

Gets the protocol transfer mode.

See Also:
  `setBinaryTransfer(boolean)`

#### setBinaryTransferEnable

    public void setBinaryTransferEnable(java.lang.String oidList)

Add types to the override set of `Oid` values used for binary transfer.

Parameters:
  `oidList` - The comma separated list of Oids. Either textual or numeric value.

#### getBinaryTransferEnable

    public java.lang.String getBinaryTransferEnable()

Gets override set of Oid values that have binary transfer enabled.

See Also:
  `setBinaryTransferEnable(String)`

#### setBinaryTransferDisable

    public void setBinaryTransferDisable(java.lang.String oidList)

Add types to the override set of `Oid` values that will not be used for binary transfer. This overrides any values in the driver detault set or values set with `setBinaryTransferEnable(String)`.

Parameters:
  `oidList` - The comma separated list of Oids. Either textual or numeric value.

#### getBinaryTransferDisable

    public java.lang.String getBinaryTransferDisable()

Gets override set of Oid values that have binary transfer disabled.

See Also:
  `setBinaryTransferDisable(String)`

#### getStringType

    public java.lang.String getStringType()

#### setStringType

    public void setStringType(java.lang.String stringType)

#### getUrl

    public java.lang.String getUrl()

Generates a DriverManager URL from the other properties supplied.

#### setUrl

    public void setUrl(java.lang.String url)
                throws java.sql.SQLException

Sets properties from a DriverManager URL.

Throws:
  `java.sql.SQLException`

#### createReference

    protected javax.naming.Reference createReference()

Generates a reference using the appropriate object factory.

#### getReference

    public javax.naming.Reference getReference()
                                        throws javax.naming.NamingException

Specified by:
  `getReference` in interface `javax.naming.Referenceable`
Throws:
  `javax.naming.NamingException`

#### writeBaseObject

    protected void writeBaseObject(java.io.ObjectOutputStream out)
                            throws java.io.IOException

Throws:
  `java.io.IOException`

#### readBaseObject

    protected void readBaseObject(java.io.ObjectInputStream in)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException

Throws:
  `java.io.IOException`
  `java.lang.ClassNotFoundException`

#### initializeFrom

    public void initializeFrom(BaseDataSource source)
                        throws java.io.IOException,
                               java.lang.ClassNotFoundException

Throws:
  `java.io.IOException`
  `java.lang.ClassNotFoundException`