Interface PGConnection

  • All Known Subinterfaces:
    BaseConnection
    All Known Implementing Classes:
    PgConnection

    public interface PGConnection
    This interface defines the public PostgreSQL extensions to java.sql.Connection. All Connections returned by the PostgreSQL driver implement PGConnection.
    • Method Summary

      All Methods Instance Methods Abstract Methods Deprecated Methods 
      Modifier and Type Method Description
      void addDataType​(java.lang.String type, java.lang.Class<? extends PGobject> klass)
      This allows client code to add a handler for one of org.postgresql's more unique data types.
      void addDataType​(java.lang.String type, java.lang.String className)
      Deprecated.
      As of 8.0, replaced by addDataType(String, Class).
      java.lang.String escapeIdentifier​(java.lang.String identifier)
      Return the given string suitably quoted to be used as an identifier in an SQL statement string.
      java.lang.String escapeLiteral​(java.lang.String literal)
      Return the given string suitably quoted to be used as a string literal in an SQL statement string.
      AutoSave getAutosave()
      Connection configuration regarding automatic per-query savepoints.
      int getBackendPID()
      Return the process ID (PID) of the backend server process handling this connection.
      CopyManager getCopyAPI()
      This returns the COPY API for the current connection.
      int getDefaultFetchSize()
      Get the default fetch size for statements created from this connection
      Fastpath getFastpathAPI()
      This returns the Fastpath API for the current connection.
      LargeObjectManager getLargeObjectAPI()
      This returns the LargeObject API for the current connection.
      PGNotification[] getNotifications()
      This method returns any notifications that have been received since the last call to this method.
      PreferQueryMode getPreferQueryMode()
      Returns true if the connection is configured to use "simple 'Q' execute" commands only When running in simple protocol only, certain features are not available: callable statements, partial result set fetch, bytea type, etc.
      int getPrepareThreshold()
      Get the default server-side prepare reuse threshold for statements created from this connection.
      void setAutosave​(AutoSave autoSave)
      Configures if connection should use automatic savepoints.
      void setDefaultFetchSize​(int fetchSize)
      Set the default fetch size for statements created from this connection
      void setPrepareThreshold​(int threshold)
      Set the default statement reuse threshold before enabling server-side prepare.
    • Method Detail

      • getNotifications

        PGNotification[] getNotifications()
                                   throws java.sql.SQLException
        This method returns any notifications that have been received since the last call to this method. Returns null if there have been no notifications.
        Returns:
        notifications that have been received
        Throws:
        java.sql.SQLException - if something wrong happens
        Since:
        7.3
      • getCopyAPI

        CopyManager getCopyAPI()
                        throws java.sql.SQLException
        This returns the COPY API for the current connection.
        Returns:
        COPY API for the current connection
        Throws:
        java.sql.SQLException - if something wrong happens
        Since:
        8.4
      • getLargeObjectAPI

        LargeObjectManager getLargeObjectAPI()
                                      throws java.sql.SQLException
        This returns the LargeObject API for the current connection.
        Returns:
        LargeObject API for the current connection
        Throws:
        java.sql.SQLException - if something wrong happens
        Since:
        7.3
      • getFastpathAPI

        Fastpath getFastpathAPI()
                         throws java.sql.SQLException
        This returns the Fastpath API for the current connection.
        Returns:
        Fastpath API for the current connection
        Throws:
        java.sql.SQLException - if something wrong happens
        Since:
        7.3
      • addDataType

        void addDataType​(java.lang.String type,
                         java.lang.String className)
        Deprecated.
        As of 8.0, replaced by addDataType(String, Class). This deprecated method does not work correctly for registering classes that cannot be directly loaded by the JDBC driver's classloader.
        This allows client code to add a handler for one of org.postgresql's more unique data types. It is approximately equivalent to addDataType(type, Class.forName(name)).
        Parameters:
        type - JDBC type name
        className - class name
        Throws:
        java.lang.RuntimeException - if the type cannot be registered (class not found, etc).
      • addDataType

        void addDataType​(java.lang.String type,
                         java.lang.Class<? extends PGobject> klass)
                  throws java.sql.SQLException
        This allows client code to add a handler for one of org.postgresql's more unique data types.

        NOTE: This is not part of JDBC, but an extension.

        The best way to use this is as follows:

         ...
         ((org.postgresql.PGConnection)myconn).addDataType("mytype", my.class.name.class);
         ...
         

        where myconn is an open Connection to org.postgresql.

        The handling class must extend org.postgresql.util.PGobject

        Parameters:
        type - the PostgreSQL type to register
        klass - the class implementing the Java representation of the type; this class must implement PGobject).
        Throws:
        java.sql.SQLException - if klass does not implement PGobject).
        Since:
        8.0
        See Also:
        PGobject
      • setPrepareThreshold

        void setPrepareThreshold​(int threshold)
        Set the default statement reuse threshold before enabling server-side prepare. See PGStatement.setPrepareThreshold(int) for details.
        Parameters:
        threshold - the new threshold
        Since:
        build 302
      • getPrepareThreshold

        int getPrepareThreshold()
        Get the default server-side prepare reuse threshold for statements created from this connection.
        Returns:
        the current threshold
        Since:
        build 302
      • setDefaultFetchSize

        void setDefaultFetchSize​(int fetchSize)
                          throws java.sql.SQLException
        Set the default fetch size for statements created from this connection
        Parameters:
        fetchSize - new default fetch size
        Throws:
        java.sql.SQLException - if specified negative fetchSize parameter
        See Also:
        Statement.setFetchSize(int)
      • getDefaultFetchSize

        int getDefaultFetchSize()
        Get the default fetch size for statements created from this connection
        Returns:
        current state for default fetch size
        See Also:
        PGProperty.DEFAULT_ROW_FETCH_SIZE, Statement.getFetchSize()
      • getBackendPID

        int getBackendPID()
        Return the process ID (PID) of the backend server process handling this connection.
        Returns:
        PID of backend server process.
      • escapeIdentifier

        java.lang.String escapeIdentifier​(java.lang.String identifier)
                                   throws java.sql.SQLException
        Return the given string suitably quoted to be used as an identifier in an SQL statement string. Quotes are added only if necessary (i.e., if the string contains non-identifier characters or would be case-folded). Embedded quotes are properly doubled.
        Parameters:
        identifier - input identifier
        Returns:
        the escaped identifier
        Throws:
        java.sql.SQLException - if something goes wrong
      • escapeLiteral

        java.lang.String escapeLiteral​(java.lang.String literal)
                                throws java.sql.SQLException
        Return the given string suitably quoted to be used as a string literal in an SQL statement string. Embedded single-quotes and backslashes are properly doubled. Note that quote_literal returns null on null input.
        Parameters:
        literal - input literal
        Returns:
        the quoted literal
        Throws:
        java.sql.SQLException - if something goes wrong
      • getPreferQueryMode

        PreferQueryMode getPreferQueryMode()
        Returns true if the connection is configured to use "simple 'Q' execute" commands only When running in simple protocol only, certain features are not available: callable statements, partial result set fetch, bytea type, etc. The list of supported features is subject to change.
        Returns:
        true if the connection is configured to use "simple 'Q' execute" commands only
      • getAutosave

        AutoSave getAutosave()
        Connection configuration regarding automatic per-query savepoints.
        Returns:
        connection configuration regarding automatic per-query savepoints
        See Also:
        PGProperty.AUTOSAVE
      • setAutosave

        void setAutosave​(AutoSave autoSave)
        Configures if connection should use automatic savepoints.
        Parameters:
        autoSave - connection configuration regarding automatic per-query savepoints
        See Also:
        PGProperty.AUTOSAVE