Package org.postgresql.core
Class ConnectionFactory
- java.lang.Object
-
- org.postgresql.core.ConnectionFactory
-
- Direct Known Subclasses:
ConnectionFactoryImpl
public abstract class ConnectionFactory extends java.lang.Object
Handles protocol-specific connection setup.- Author:
- Oliver Jowett (oliver@opencloud.com)
-
-
Constructor Summary
Constructors Constructor Description ConnectionFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
closeStream(PGStream newStream)
Safely close the given stream.static QueryExecutor
openConnection(HostSpec[] hostSpecs, java.lang.String user, java.lang.String database, java.util.Properties info, Logger logger)
Establishes and initializes a new connection.abstract QueryExecutor
openConnectionImpl(HostSpec[] hostSpecs, java.lang.String user, java.lang.String database, java.util.Properties info, Logger logger)
Implementation ofopenConnection(org.postgresql.util.HostSpec[], java.lang.String, java.lang.String, java.util.Properties, org.postgresql.core.Logger)
for a particular protocol version.
-
-
-
Method Detail
-
openConnection
public static QueryExecutor openConnection(HostSpec[] hostSpecs, java.lang.String user, java.lang.String database, java.util.Properties info, Logger logger) throws java.sql.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 failoveruser
- 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:
java.sql.SQLException
- if the connection could not be established.
-
openConnectionImpl
public abstract QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, java.lang.String user, java.lang.String database, java.util.Properties info, Logger logger) throws java.sql.SQLException
Implementation ofopenConnection(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 ofConnectionFactory
.- Parameters:
hostSpecs
- at least one host and port to connect to; multiple elements for round-robin failoveruser
- 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:
java.sql.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.
-
-