Package org.postgresql.core

# Class ConnectionFactory

java.lang.Object
org.postgresql.core.ConnectionFactory

Direct Known Subclasses:
  `ConnectionFactoryImpl`

public abstract class ConnectionFactory extends Object
Handles protocol-specific connection setup.

## Constructor Summary

Constructors
Constructor
Description
`ConnectionFactory()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`closeStream(@Nullable PGStream newStream)`
Safely close the given stream.
`static QueryExecutor`
`openConnection(HostSpec[] hostSpecs, Properties info)`
Establishes and initializes a new connection.
`abstract QueryExecutor`
`openConnectionImpl(HostSpec[] hostSpecs, Properties info)`
Implementation of `openConnection(org.postgresql.util.HostSpec[], java.util.Properties)` for a particular protocol version.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ConnectionFactory

public ConnectionFactory()

## Method Details

### openConnection

public static QueryExecutor openConnection(HostSpec[] hostSpecs, Properties info) 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+) is supported.

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

### openConnectionImpl

public abstract QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, Properties info) throws SQLException
Implementation of `openConnection(org.postgresql.util.HostSpec[], java.util.Properties)` 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
  `info` - extra properties controlling the connection; notably, "password" if present supplies the password to authenticate with.
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(@Nullable PGStream newStream)
Safely close the given stream.

Parameters:
  `newStream` - The stream to close.