Package org.postgresql.core.v3
Class ConnectionFactoryImpl
java.lang.Object
org.postgresql.core.ConnectionFactory
org.postgresql.core.v3.ConnectionFactoryImpl
ConnectionFactory implementation for version 3 (7.4+) connections.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final String
private static final Logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
Convert Java time zone to postgres time zone.private ISSPIClient
createSSPI
(PGStream pgStream, String spnServiceClass, boolean enableNegotiate) private void
doAuthentication
(PGStream pgStream, String host, String user, Properties info) private PGStream
enableGSSEncrypted
(PGStream pgStream, GSSEncMode gssEncMode, String host, Properties info, int connectTimeout) private PGStream
enableSSL
(PGStream pgStream, SslMode sslMode, Properties info, int connectTimeout) private List<ConnectionFactoryImpl.StartupParam>
getParametersForStartup
(String user, String database, Properties info) private boolean
isPrimary
(QueryExecutor queryExecutor) Since PG14 there is GUC_REPORT ParamStatusin_hot_standby
which is set to "on" when the server is in archive recovery or standby mode.private static void
openConnectionImpl
(HostSpec[] hostSpecs, Properties info) Implementation ofConnectionFactory.openConnection(org.postgresql.util.HostSpec[], java.util.Properties)
for a particular protocol version.private void
runInitialQueries
(QueryExecutor queryExecutor, Properties info) private void
sendStartupPacket
(PGStream pgStream, List<ConnectionFactoryImpl.StartupParam> params) private PGStream
tryConnect
(Properties info, SocketFactory socketFactory, HostSpec hostSpec, SslMode sslMode, GSSEncMode gssEncMode) Methods inherited from class org.postgresql.core.ConnectionFactory
closeStream, openConnection
-
Field Details
-
LOGGER
-
AUTH_REQ_OK
private static final int AUTH_REQ_OK- See Also:
-
AUTH_REQ_KRB4
private static final int AUTH_REQ_KRB4- See Also:
-
AUTH_REQ_KRB5
private static final int AUTH_REQ_KRB5- See Also:
-
AUTH_REQ_PASSWORD
private static final int AUTH_REQ_PASSWORD- See Also:
-
AUTH_REQ_CRYPT
private static final int AUTH_REQ_CRYPT- See Also:
-
AUTH_REQ_MD5
private static final int AUTH_REQ_MD5- See Also:
-
AUTH_REQ_SCM
private static final int AUTH_REQ_SCM- See Also:
-
AUTH_REQ_GSS
private static final int AUTH_REQ_GSS- See Also:
-
AUTH_REQ_GSS_CONTINUE
private static final int AUTH_REQ_GSS_CONTINUE- See Also:
-
AUTH_REQ_SSPI
private static final int AUTH_REQ_SSPI- See Also:
-
AUTH_REQ_SASL
private static final int AUTH_REQ_SASL- See Also:
-
AUTH_REQ_SASL_CONTINUE
private static final int AUTH_REQ_SASL_CONTINUE- See Also:
-
AUTH_REQ_SASL_FINAL
private static final int AUTH_REQ_SASL_FINAL- See Also:
-
IN_HOT_STANDBY
- See Also:
-
-
Constructor Details
-
ConnectionFactoryImpl
public ConnectionFactoryImpl()
-
-
Method Details
-
createSSPI
-
tryConnect
private PGStream tryConnect(Properties info, SocketFactory socketFactory, HostSpec hostSpec, SslMode sslMode, GSSEncMode gssEncMode) throws SQLException, IOException - Throws:
SQLException
IOException
-
openConnectionImpl
Description copied from class:ConnectionFactory
Implementation ofConnectionFactory.openConnection(org.postgresql.util.HostSpec[], java.util.Properties)
for a particular protocol version. Implemented by subclasses ofConnectionFactory
.- Specified by:
openConnectionImpl
in classConnectionFactory
- Parameters:
hostSpecs
- at least one host and port to connect to; multiple elements for round-robin failoverinfo
- 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.
-
getParametersForStartup
private List<ConnectionFactoryImpl.StartupParam> getParametersForStartup(String user, String database, Properties info) -
log
-
createPostgresTimeZone
Convert Java time zone to postgres time zone. All others stay the same except that GMT+nn changes to GMT-nn and vise versa. If you provide GMT+/-nn postgres uses POSIX rules which has a positive sign for west of Greenwich JAVA uses ISO rules which the positive sign is east of Greenwich To make matters more interesting postgres will always report in ISO- Returns:
- The current JVM time zone in postgresql format.
-
enableGSSEncrypted
private PGStream enableGSSEncrypted(PGStream pgStream, GSSEncMode gssEncMode, String host, Properties info, int connectTimeout) throws IOException, PSQLException - Throws:
IOException
PSQLException
-
enableSSL
private PGStream enableSSL(PGStream pgStream, SslMode sslMode, Properties info, int connectTimeout) throws IOException, PSQLException - Throws:
IOException
PSQLException
-
sendStartupPacket
private void sendStartupPacket(PGStream pgStream, List<ConnectionFactoryImpl.StartupParam> params) throws IOException - Throws:
IOException
-
doAuthentication
private void doAuthentication(PGStream pgStream, String host, String user, Properties info) throws IOException, SQLException - Throws:
IOException
SQLException
-
runInitialQueries
- Throws:
SQLException
-
isPrimary
Since PG14 there is GUC_REPORT ParamStatusin_hot_standby
which is set to "on" when the server is in archive recovery or standby mode. In driver's lingo such server is calledHostRequirement.secondary
. Previouslytransaction_read_only
was used as a workable substitute. Howevertransaction_read_only
could have been manually overridden on the primary server by database user leading to a false positives: ie server is effectively read-only but technically is "primary" (not in a recovery/standby mode).This method checks whether
in_hot_standby
GUC was reported by the server during initial connection:in_hot_standby
was reported and the value was "on" then the server is a replica and database is read-only by definition, false is returned.in_hot_standby
was reported and the value was "off" then the server is indeed primary but database may be in read-only mode nevertheless. We proceed to conservativelyshow transaction_read_only
since users may not be expecting a readonly connection fortargetServerType=primary
- If
in_hot_standby
has not been reported we fallback to pre v14 behavior.
Do not confuse
hot_standby
andin_hot_standby
ParamStatuses
-