Package org.postgresql.ds.common
Class BaseDataSource
- java.lang.Object
-
- org.postgresql.ds.common.BaseDataSource
-
- All Implemented Interfaces:
javax.naming.Referenceable
- Direct Known Subclasses:
org.postgresql.ds.jdbc23.AbstractJdbc23ConnectionPoolDataSource
,org.postgresql.ds.jdbc23.AbstractJdbc23PoolingDataSource
,org.postgresql.ds.jdbc23.AbstractJdbc23SimpleDataSource
,org.postgresql.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 Description BaseDataSource()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected javax.naming.Reference
createReference()
Generates a reference using the appropriate object factory.boolean
getAllowEncodingChanges()
java.lang.String
getApplicationName()
java.lang.String
getAssumeMinServerVersion()
boolean
getBinaryTransfer()
java.lang.String
getBinaryTransferDisable()
java.lang.String
getBinaryTransferEnable()
java.lang.String
getCharset()
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.int
getConnectTimeout()
java.lang.String
getCurrentSchema()
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.boolean
getDisableColumnSanitiser()
java.lang.String
getGssLib()
int
getHostRecheckSeconds()
java.lang.String
getJaasApplicationName()
java.lang.String
getKerberosServerName()
boolean
getLoadBalanceHosts()
int
getLoginTimeout()
int
getLogLevel()
boolean
getLogUnclosedConnections()
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()
java.lang.String
getProperty(java.lang.String name)
java.lang.String
getProperty(PGProperty property)
int
getProtocolVersion()
boolean
getReadOnly()
int
getReceiveBufferSize()
javax.naming.Reference
getReference()
int
getSendBufferSize()
java.lang.String
getServerName()
Gets the name of the host the PostgreSQL database is running on.int
getSocketTimeout()
boolean
getSsl()
java.lang.String
getSslCert()
java.lang.String
getSslfactory()
java.lang.String
getSslFactoryArg()
java.lang.String
getSslHostnameVerifier()
java.lang.String
getSslKey()
java.lang.String
getSslMode()
java.lang.String
getSslPassword()
java.lang.String
getSslPasswordCallback()
java.lang.String
getSslRootCert()
java.lang.String
getSspiServiceClass()
java.lang.String
getStringType()
java.lang.String
getTargetServerType()
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.boolean
getUseSpNego()
void
initializeFrom(BaseDataSource source)
boolean
isColumnSanitiserDisabled()
protected void
readBaseObject(java.io.ObjectInputStream in)
void
setAllowEncodingChanges(boolean allow)
void
setApplicationName(java.lang.String applicationName)
void
setAssumeMinServerVersion(java.lang.String minVersion)
void
setBinaryTransfer(boolean enabled)
void
setBinaryTransferDisable(java.lang.String oidList)
void
setBinaryTransferEnable(java.lang.String oidList)
void
setCharset(java.lang.String charset)
void
setCompatible(java.lang.String compatible)
void
setConnectTimeout(int connectTimeout)
void
setCurrentSchema(java.lang.String currentSchema)
void
setDatabaseName(java.lang.String databaseName)
Sets the name of the PostgreSQL database, running on the server identified by the serverName property.void
setDisableColumnSanitiser(boolean disableColumnSanitiser)
void
setFromReference(javax.naming.Reference ref)
void
setGssLib(java.lang.String lib)
void
setHostRecheckSeconds(int hostRecheckSeconds)
void
setJaasApplicationName(java.lang.String name)
void
setKerberosServerName(java.lang.String serverName)
void
setLoadBalanceHosts(boolean loadBalanceHosts)
void
setLoginTimeout(int loginTimeout)
void
setLogLevel(int logLevel)
void
setLogUnclosedConnections(boolean enabled)
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)
void
setProperty(java.lang.String name, java.lang.String value)
void
setProperty(PGProperty property, java.lang.String value)
void
setProtocolVersion(int protocolVersion)
void
setReadOnly(boolean readOnly)
void
setReceiveBufferSize(int nbytes)
void
setSendBufferSize(int nbytes)
void
setServerName(java.lang.String serverName)
Sets the name of the host the PostgreSQL database is running on.void
setSocketTimeout(int seconds)
void
setSsl(boolean enabled)
void
setSslCert(java.lang.String file)
void
setSslfactory(java.lang.String classname)
void
setSslFactoryArg(java.lang.String arg)
void
setSslHostnameVerifier(java.lang.String className)
void
setSslKey(java.lang.String file)
void
setSslMode(java.lang.String mode)
void
setSslPassword(java.lang.String password)
void
setSslPasswordCallback(java.lang.String className)
void
setSslRootCert(java.lang.String file)
void
setSspiServiceClass(java.lang.String serviceClass)
void
setStringType(java.lang.String stringType)
void
setTargetServerType(java.lang.String targetServerType)
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.void
setUseSpNego(boolean use)
protected void
writeBaseObject(java.io.ObjectOutputStream out)
-
-
-
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.
-
getLogWriter
public java.io.PrintWriter getLogWriter()
Gets the log writer used to log connections opened.
-
setLogWriter
public void setLogWriter(java.io.PrintWriter printWriter)
The DataSource will note every connection opened to the provided log writer.
-
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.
-
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.
-
getCompatible
public java.lang.String getCompatible()
- See Also:
PGProperty.COMPATIBLE
-
setCompatible
public void setCompatible(java.lang.String compatible)
- See Also:
PGProperty.COMPATIBLE
-
getLoginTimeout
public int getLoginTimeout()
- See Also:
PGProperty.LOGIN_TIMEOUT
-
setLoginTimeout
public void setLoginTimeout(int loginTimeout)
- See Also:
PGProperty.LOGIN_TIMEOUT
-
getConnectTimeout
public int getConnectTimeout()
- See Also:
PGProperty.CONNECT_TIMEOUT
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
- See Also:
PGProperty.CONNECT_TIMEOUT
-
getLogLevel
public int getLogLevel()
- See Also:
PGProperty.LOG_LEVEL
-
setLogLevel
public void setLogLevel(int logLevel)
- See Also:
PGProperty.LOG_LEVEL
-
getProtocolVersion
public int getProtocolVersion()
- See Also:
PGProperty.PROTOCOL_VERSION
-
setProtocolVersion
public void setProtocolVersion(int protocolVersion)
- See Also:
PGProperty.PROTOCOL_VERSION
-
getReceiveBufferSize
public int getReceiveBufferSize()
- See Also:
PGProperty.RECEIVE_BUFFER_SIZE
-
setReceiveBufferSize
public void setReceiveBufferSize(int nbytes)
- See Also:
PGProperty.RECEIVE_BUFFER_SIZE
-
getSendBufferSize
public int getSendBufferSize()
- See Also:
PGProperty.SEND_BUFFER_SIZE
-
setSendBufferSize
public void setSendBufferSize(int nbytes)
- See Also:
PGProperty.SEND_BUFFER_SIZE
-
setPrepareThreshold
public void setPrepareThreshold(int count)
- See Also:
PGProperty.PREPARE_THRESHOLD
-
getPrepareThreshold
public int getPrepareThreshold()
- See Also:
PGProperty.PREPARE_THRESHOLD
-
setUnknownLength
public void setUnknownLength(int unknownLength)
- See Also:
PGProperty.UNKNOWN_LENGTH
-
getUnknownLength
public int getUnknownLength()
- See Also:
PGProperty.UNKNOWN_LENGTH
-
setSocketTimeout
public void setSocketTimeout(int seconds)
- See Also:
PGProperty.SOCKET_TIMEOUT
-
getSocketTimeout
public int getSocketTimeout()
- See Also:
PGProperty.SOCKET_TIMEOUT
-
setSsl
public void setSsl(boolean enabled)
- See Also:
PGProperty.SSL
-
getSsl
public boolean getSsl()
- See Also:
PGProperty.SSL
-
setSslfactory
public void setSslfactory(java.lang.String classname)
- See Also:
PGProperty.SSL_FACTORY
-
getSslfactory
public java.lang.String getSslfactory()
- See Also:
PGProperty.SSL_FACTORY
-
getSslMode
public java.lang.String getSslMode()
- See Also:
PGProperty.SSL_MODE
-
setSslMode
public void setSslMode(java.lang.String mode)
- See Also:
PGProperty.SSL_MODE
-
getSslFactoryArg
public java.lang.String getSslFactoryArg()
- See Also:
PGProperty.SSL_FACTORY_ARG
-
setSslFactoryArg
public void setSslFactoryArg(java.lang.String arg)
- See Also:
PGProperty.SSL_FACTORY_ARG
-
getSslHostnameVerifier
public java.lang.String getSslHostnameVerifier()
- See Also:
PGProperty.SSL_HOSTNAME_VERIFIER
-
setSslHostnameVerifier
public void setSslHostnameVerifier(java.lang.String className)
- See Also:
PGProperty.SSL_HOSTNAME_VERIFIER
-
getSslCert
public java.lang.String getSslCert()
- See Also:
PGProperty.SSL_CERT
-
setSslCert
public void setSslCert(java.lang.String file)
- See Also:
PGProperty.SSL_CERT
-
getSslKey
public java.lang.String getSslKey()
- See Also:
PGProperty.SSL_KEY
-
setSslKey
public void setSslKey(java.lang.String file)
- See Also:
PGProperty.SSL_KEY
-
getSslRootCert
public java.lang.String getSslRootCert()
- See Also:
PGProperty.SSL_ROOT_CERT
-
setSslRootCert
public void setSslRootCert(java.lang.String file)
- See Also:
PGProperty.SSL_ROOT_CERT
-
getSslPassword
public java.lang.String getSslPassword()
- See Also:
PGProperty.SSL_PASSWORD
-
setSslPassword
public void setSslPassword(java.lang.String password)
- See Also:
PGProperty.SSL_PASSWORD
-
getSslPasswordCallback
public java.lang.String getSslPasswordCallback()
- See Also:
PGProperty.SSL_PASSWORD_CALLBACK
-
setSslPasswordCallback
public void setSslPasswordCallback(java.lang.String className)
- See Also:
PGProperty.SSL_PASSWORD_CALLBACK
-
setApplicationName
public void setApplicationName(java.lang.String applicationName)
- See Also:
PGProperty.APPLICATION_NAME
-
getApplicationName
public java.lang.String getApplicationName()
- See Also:
PGProperty.APPLICATION_NAME
-
setTargetServerType
public void setTargetServerType(java.lang.String targetServerType)
- See Also:
PGProperty.TARGET_SERVER_TYPE
-
getTargetServerType
public java.lang.String getTargetServerType()
- See Also:
PGProperty.TARGET_SERVER_TYPE
-
setLoadBalanceHosts
public void setLoadBalanceHosts(boolean loadBalanceHosts)
- See Also:
PGProperty.LOAD_BALANCE_HOSTS
-
getLoadBalanceHosts
public boolean getLoadBalanceHosts()
- See Also:
PGProperty.LOAD_BALANCE_HOSTS
-
setHostRecheckSeconds
public void setHostRecheckSeconds(int hostRecheckSeconds)
- See Also:
PGProperty.HOST_RECHECK_SECONDS
-
getHostRecheckSeconds
public int getHostRecheckSeconds()
- See Also:
PGProperty.HOST_RECHECK_SECONDS
-
setTcpKeepAlive
public void setTcpKeepAlive(boolean enabled)
- See Also:
PGProperty.TCP_KEEP_ALIVE
-
getTcpKeepAlive
public boolean getTcpKeepAlive()
- See Also:
PGProperty.TCP_KEEP_ALIVE
-
setBinaryTransfer
public void setBinaryTransfer(boolean enabled)
- See Also:
PGProperty.BINARY_TRANSFER
-
getBinaryTransfer
public boolean getBinaryTransfer()
- See Also:
PGProperty.BINARY_TRANSFER
-
setBinaryTransferEnable
public void setBinaryTransferEnable(java.lang.String oidList)
- See Also:
PGProperty.BINARY_TRANSFER_ENABLE
-
getBinaryTransferEnable
public java.lang.String getBinaryTransferEnable()
- See Also:
PGProperty.BINARY_TRANSFER_ENABLE
-
setBinaryTransferDisable
public void setBinaryTransferDisable(java.lang.String oidList)
- See Also:
PGProperty.BINARY_TRANSFER_DISABLE
-
getBinaryTransferDisable
public java.lang.String getBinaryTransferDisable()
- See Also:
PGProperty.BINARY_TRANSFER_DISABLE
-
getStringType
public java.lang.String getStringType()
- See Also:
PGProperty.STRING_TYPE
-
setStringType
public void setStringType(java.lang.String stringType)
- See Also:
PGProperty.STRING_TYPE
-
isColumnSanitiserDisabled
public boolean isColumnSanitiserDisabled()
- See Also:
PGProperty.DISABLE_COLUMN_SANITISER
-
getDisableColumnSanitiser
public boolean getDisableColumnSanitiser()
- See Also:
PGProperty.DISABLE_COLUMN_SANITISER
-
setDisableColumnSanitiser
public void setDisableColumnSanitiser(boolean disableColumnSanitiser)
- See Also:
PGProperty.DISABLE_COLUMN_SANITISER
-
getCurrentSchema
public java.lang.String getCurrentSchema()
- See Also:
PGProperty.CURRENT_SCHEMA
-
setCurrentSchema
public void setCurrentSchema(java.lang.String currentSchema)
- See Also:
PGProperty.CURRENT_SCHEMA
-
getReadOnly
public boolean getReadOnly()
- See Also:
PGProperty.READ_ONLY
-
setReadOnly
public void setReadOnly(boolean readOnly)
- See Also:
PGProperty.READ_ONLY
-
getLogUnclosedConnections
public boolean getLogUnclosedConnections()
- See Also:
PGProperty.LOG_UNCLOSED_CONNECTIONS
-
setLogUnclosedConnections
public void setLogUnclosedConnections(boolean enabled)
- See Also:
PGProperty.LOG_UNCLOSED_CONNECTIONS
-
getAssumeMinServerVersion
public java.lang.String getAssumeMinServerVersion()
- See Also:
PGProperty.ASSUME_MIN_SERVER_VERSION
-
setAssumeMinServerVersion
public void setAssumeMinServerVersion(java.lang.String minVersion)
- See Also:
PGProperty.ASSUME_MIN_SERVER_VERSION
-
getJaasApplicationName
public java.lang.String getJaasApplicationName()
- See Also:
PGProperty.JAAS_APPLICATION_NAME
-
setJaasApplicationName
public void setJaasApplicationName(java.lang.String name)
- See Also:
PGProperty.JAAS_APPLICATION_NAME
-
getKerberosServerName
public java.lang.String getKerberosServerName()
- See Also:
PGProperty.KERBEROS_SERVER_NAME
-
setKerberosServerName
public void setKerberosServerName(java.lang.String serverName)
- See Also:
PGProperty.KERBEROS_SERVER_NAME
-
getUseSpNego
public boolean getUseSpNego()
- See Also:
PGProperty.USE_SPNEGO
-
setUseSpNego
public void setUseSpNego(boolean use)
- See Also:
PGProperty.USE_SPNEGO
-
getGssLib
public java.lang.String getGssLib()
- See Also:
PGProperty.GSS_LIB
-
setGssLib
public void setGssLib(java.lang.String lib)
- See Also:
PGProperty.GSS_LIB
-
getSspiServiceClass
public java.lang.String getSspiServiceClass()
- See Also:
PGProperty.SSPI_SERVICE_CLASS
-
setSspiServiceClass
public void setSspiServiceClass(java.lang.String serviceClass)
- See Also:
PGProperty.SSPI_SERVICE_CLASS
-
getCharset
public java.lang.String getCharset()
- See Also:
PGProperty.CHARSET
-
setCharset
public void setCharset(java.lang.String charset)
- See Also:
PGProperty.CHARSET
-
getAllowEncodingChanges
public boolean getAllowEncodingChanges()
- See Also:
PGProperty.ALLOW_ENCODING_CHANGES
-
setAllowEncodingChanges
public void setAllowEncodingChanges(boolean allow)
- See Also:
PGProperty.ALLOW_ENCODING_CHANGES
-
getUrl
public java.lang.String getUrl()
Generates a DriverManager URL from the other properties supplied.
-
setUrl
public void setUrl(java.lang.String url)
Sets properties from a DriverManager URL.
-
getProperty
public java.lang.String getProperty(java.lang.String name) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
setProperty
public void setProperty(java.lang.String name, java.lang.String value) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getProperty
public java.lang.String getProperty(PGProperty property)
-
setProperty
public void setProperty(PGProperty property, java.lang.String value)
-
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 interfacejavax.naming.Referenceable
- Throws:
javax.naming.NamingException
-
setFromReference
public void setFromReference(javax.naming.Reference ref)
-
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
-
-