Class 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 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.
      • 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.
      • setCompatible

        public void setCompatible​(java.lang.String compatible)
        See Also:
        PGProperty.COMPATIBLE
      • setSsl

        public void setSsl​(boolean enabled)
        See Also:
        PGProperty.SSL
      • setSslKey

        public void setSslKey​(java.lang.String file)
        See Also:
        PGProperty.SSL_KEY
      • setGssLib

        public void setGssLib​(java.lang.String lib)
        See Also:
        PGProperty.GSS_LIB
      • setCharset

        public void setCharset​(java.lang.String charset)
        See Also:
        PGProperty.CHARSET
      • 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 interface javax.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