public class ConnectionFactoryImpl extends ConnectionFactory
| Modifier and Type | Field and Description |
|---|---|
private static int |
AUTH_REQ_CRYPT |
private static int |
AUTH_REQ_GSS |
private static int |
AUTH_REQ_GSS_CONTINUE |
private static int |
AUTH_REQ_KRB4 |
private static int |
AUTH_REQ_KRB5 |
private static int |
AUTH_REQ_MD5 |
private static int |
AUTH_REQ_OK |
private static int |
AUTH_REQ_PASSWORD |
private static int |
AUTH_REQ_SASL |
private static int |
AUTH_REQ_SASL_CONTINUE |
private static int |
AUTH_REQ_SASL_FINAL |
private static int |
AUTH_REQ_SCM |
private static int |
AUTH_REQ_SSPI |
private static java.lang.String |
IN_HOT_STANDBY |
private static java.util.logging.Logger |
LOGGER |
| Constructor and Description |
|---|
ConnectionFactoryImpl() |
| Modifier and Type | Method and Description |
|---|---|
private static java.lang.String |
createPostgresTimeZone()
Convert Java time zone to postgres time zone.
|
private ISSPIClient |
createSSPI(PGStream pgStream,
java.lang.String spnServiceClass,
boolean enableNegotiate) |
private void |
doAuthentication(PGStream pgStream,
java.lang.String host,
java.lang.String user,
java.util.Properties info) |
private PGStream |
enableGSSEncrypted(PGStream pgStream,
GSSEncMode gssEncMode,
java.lang.String host,
java.util.Properties info,
int connectTimeout) |
private PGStream |
enableSSL(PGStream pgStream,
SslMode sslMode,
java.util.Properties info,
int connectTimeout) |
private java.util.List<java.lang.String[]> |
getParametersForStartup(java.lang.String user,
java.lang.String database,
java.util.Properties info) |
private boolean |
isPrimary(QueryExecutor queryExecutor)
Since PG14 there is GUC_REPORT ParamStatus
in_hot_standby which is set to "on"
when the server is in archive recovery or standby mode. |
private static void |
log(java.util.logging.Level level,
java.lang.String msg,
java.lang.Throwable thrown,
java.lang.Object... params) |
QueryExecutor |
openConnectionImpl(HostSpec[] hostSpecs,
java.util.Properties info)
Implementation of
ConnectionFactory.openConnection(org.postgresql.util.HostSpec[], java.util.Properties) for a particular protocol version. |
private void |
runInitialQueries(QueryExecutor queryExecutor,
java.util.Properties info) |
private void |
sendStartupPacket(PGStream pgStream,
java.util.List<java.lang.String[]> params) |
private PGStream |
tryConnect(java.util.Properties info,
javax.net.SocketFactory socketFactory,
HostSpec hostSpec,
SslMode sslMode,
GSSEncMode gssEncMode) |
closeStream, openConnectionprivate static final java.util.logging.Logger LOGGER
private static final int AUTH_REQ_OK
private static final int AUTH_REQ_KRB4
private static final int AUTH_REQ_KRB5
private static final int AUTH_REQ_PASSWORD
private static final int AUTH_REQ_CRYPT
private static final int AUTH_REQ_MD5
private static final int AUTH_REQ_SCM
private static final int AUTH_REQ_GSS
private static final int AUTH_REQ_GSS_CONTINUE
private static final int AUTH_REQ_SSPI
private static final int AUTH_REQ_SASL
private static final int AUTH_REQ_SASL_CONTINUE
private static final int AUTH_REQ_SASL_FINAL
private static final java.lang.String IN_HOT_STANDBY
private ISSPIClient createSSPI(PGStream pgStream, java.lang.String spnServiceClass, boolean enableNegotiate)
private PGStream tryConnect(java.util.Properties info, javax.net.SocketFactory socketFactory, HostSpec hostSpec, SslMode sslMode, GSSEncMode gssEncMode) throws java.sql.SQLException, java.io.IOException
java.sql.SQLExceptionjava.io.IOExceptionpublic QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, java.util.Properties info) throws java.sql.SQLException
ConnectionFactoryConnectionFactory.openConnection(org.postgresql.util.HostSpec[], java.util.Properties) for a particular protocol version. Implemented by
subclasses of ConnectionFactory.openConnectionImpl in class ConnectionFactoryhostSpecs - 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.null if this protocol version is not
supported by the server.java.sql.SQLException - if the connection could not be established for a reason other than
protocol version incompatibility.private java.util.List<java.lang.String[]> getParametersForStartup(java.lang.String user,
java.lang.String database,
java.util.Properties info)
private static void log(java.util.logging.Level level,
java.lang.String msg,
java.lang.Throwable thrown,
java.lang.Object... params)
private static java.lang.String createPostgresTimeZone()
private PGStream enableGSSEncrypted(PGStream pgStream, GSSEncMode gssEncMode, java.lang.String host, java.util.Properties info, int connectTimeout) throws java.io.IOException, PSQLException
java.io.IOExceptionPSQLExceptionprivate PGStream enableSSL(PGStream pgStream, SslMode sslMode, java.util.Properties info, int connectTimeout) throws java.io.IOException, PSQLException
java.io.IOExceptionPSQLExceptionprivate void sendStartupPacket(PGStream pgStream, java.util.List<java.lang.String[]> params) throws java.io.IOException
java.io.IOExceptionprivate void doAuthentication(PGStream pgStream, java.lang.String host, java.lang.String user, java.util.Properties info) throws java.io.IOException, java.sql.SQLException
java.io.IOExceptionjava.sql.SQLExceptionprivate void runInitialQueries(QueryExecutor queryExecutor, java.util.Properties info) throws java.sql.SQLException
java.sql.SQLExceptionprivate boolean isPrimary(QueryExecutor queryExecutor) throws java.sql.SQLException, java.io.IOException
in_hot_standby which is set to "on"
when the server is in archive recovery or standby mode. In driver's lingo such server is called
HostRequirement.secondary.
Previously transaction_read_only was used as a workable substitute.
However transaction_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 conservatively show transaction_read_only
since users may not be expecting a readonly connection for targetServerType=primaryin_hot_standby has not been reported we fallback to pre v14 behavior.Do not confuse hot_standby and in_hot_standby ParamStatuses
java.sql.SQLExceptionjava.io.IOException