org.postgresql.core
Class ConnectionFactory

java.lang.Object
  extended by org.postgresql.core.ConnectionFactory
Direct Known Subclasses:
ConnectionFactoryImpl, ConnectionFactoryImpl

public abstract class ConnectionFactory
extends Object

Handles protocol-specific connection setup.

Author:
Oliver Jowett ([email protected])

Constructor Summary
ConnectionFactory()
           
 
Method Summary
protected  void closeStream(PGStream newStream)
          Safely close the given stream.
static ProtocolConnection openConnection(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger)
          Establishes and initializes a new connection.
abstract  ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger)
          Implementation of openConnection(org.postgresql.util.HostSpec[], java.lang.String, java.lang.String, java.util.Properties, org.postgresql.core.Logger) for a particular protocol version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionFactory

public ConnectionFactory()
Method Detail

openConnection

public static ProtocolConnection openConnection(HostSpec[] hostSpecs,
                                                String user,
                                                String database,
                                                Properties info,
                                                Logger logger)
                                         throws SQLException
Establishes and initializes a new connection.

If the "protocolVersion" property is specified, only that protocol version is tried. Otherwise, all protocols are tried in order, falling back to older protocols as necessary.

Currently, protocol versions 3 (7.4+) and 2 (pre-7.4) are supported.

Parameters:
hostSpecs - at least one host and port to connect to; multiple elements for round-robin failover
user - the username to authenticate with; may not be null.
database - the database on the server to connect to; may not be null.
info - extra properties controlling the connection; notably, "password" if present supplies the password to authenticate with.
logger - the logger to use for this connection
Returns:
the new, initialized, connection
Throws:
SQLException - if the connection could not be established.

openConnectionImpl

public abstract ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs,
                                                      String user,
                                                      String database,
                                                      Properties info,
                                                      Logger logger)
                                               throws SQLException
Implementation of openConnection(org.postgresql.util.HostSpec[], java.lang.String, java.lang.String, java.util.Properties, org.postgresql.core.Logger) for a particular protocol version. Implemented by subclasses of ConnectionFactory.

Parameters:
hostSpecs - at least one host and port to connect to; multiple elements for round-robin failover
user - the username to authenticate with; may not be null.
database - the database on the server to connect to; may not be null.
info - extra properties controlling the connection; notably, "password" if present supplies the password to authenticate with.
logger - the logger to use for this connection
Returns:
the new, initialized, connection, or null if this protocol version is not supported by the server.
Throws:
SQLException - if the connection could not be established for a reason other than protocol version incompatibility.

closeStream

protected void closeStream(PGStream newStream)
Safely close the given stream.

Parameters:
newStream - The stream to close.


Copyright © 2016 PostgreSQL Global Development Group. All rights reserved.