Interface PGConnection
-
- All Known Subinterfaces:
BaseConnection
- All Known Implementing Classes:
PgConnection
public interface PGConnectionThis interface defines the public PostgreSQL extensions to java.sql.Connection. All Connections returned by the PostgreSQL driver implement PGConnection.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidaddDataType(java.lang.String type, java.lang.Class<? extends PGobject> klass)This allows client code to add a handler for one of org.postgresql's more unique data types.voidaddDataType(java.lang.String type, java.lang.String className)Deprecated.As of 8.0, replaced byaddDataType(String, Class).voidcancelQuery()Sends a query cancellation for this connection.java.sql.ArraycreateArrayOf(java.lang.String typeName, java.lang.Object elements)Creates anArraywrapping elements.java.lang.StringescapeIdentifier(java.lang.String identifier)Return the given string suitably quoted to be used as an identifier in an SQL statement string.java.lang.StringescapeLiteral(java.lang.String literal)Return the given string suitably quoted to be used as a string literal in an SQL statement string.AutoSavegetAutosave()Connection configuration regarding automatic per-query savepoints.intgetBackendPID()Return the process ID (PID) of the backend server process handling this connection.CopyManagergetCopyAPI()This returns the COPY API for the current connection.intgetDefaultFetchSize()Get the default fetch size for statements created from this connection.FastpathgetFastpathAPI()Deprecated.This API is somewhat obsolete, as one may achieve similar performance and greater functionality by setting up a prepared statement to define the function call.LargeObjectManagergetLargeObjectAPI()This returns the LargeObject API for the current connection.PGNotification[]getNotifications()This method returns any notifications that have been received since the last call to this method.PGNotification[]getNotifications(int timeoutMillis)This method returns any notifications that have been received since the last call to this method.java.lang.StringgetParameterStatus(java.lang.String parameterName)Shorthand for getParameterStatuses().get(...) .java.util.Map<java.lang.String,java.lang.String>getParameterStatuses()Returns the current values of all parameters reported by the server.PreferQueryModegetPreferQueryMode()Returns the query mode for this connection.intgetPrepareThreshold()Get the default server-side prepare reuse threshold for statements created from this connection.PGReplicationConnectiongetReplicationAPI()voidsetAutosave(AutoSave autoSave)Configures if connection should use automatic savepoints.voidsetDefaultFetchSize(int fetchSize)Set the default fetch size for statements created from this connection.voidsetPrepareThreshold(int threshold)Set the default statement reuse threshold before enabling server-side prepare.
-
-
-
Method Detail
-
createArrayOf
java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object elements) throws java.sql.SQLExceptionCreates anArraywrapping elements. This is similar toConnection.createArrayOf(String, Object[]), but also provides support for primitive arrays.- Parameters:
typeName- The SQL name of the type to map the elements to. Must not benull.elements- The array of objects to map. Anullvalue will result in anArrayrepresentingnull.- Returns:
- An
Arraywrapping elements. - Throws:
java.sql.SQLException- If for some reason the array cannot be created.- See Also:
Connection.createArrayOf(String, Object[])
-
getNotifications
PGNotification[] getNotifications() throws java.sql.SQLException
This method returns any notifications that have been received since the last call to this method. Returns null if there have been no notifications.- Returns:
- notifications that have been received
- Throws:
java.sql.SQLException- if something wrong happens- Since:
- 7.3
-
getNotifications
PGNotification[] getNotifications(int timeoutMillis) throws java.sql.SQLException
This method returns any notifications that have been received since the last call to this method. Returns null if there have been no notifications. A timeout can be specified so the driver waits for notifications.- Parameters:
timeoutMillis- when 0, blocks forever. when > 0, blocks up to the specified number of millies or until at least one notification has been received. If more than one notification is about to be received, these will be returned in one batch.- Returns:
- notifications that have been received
- Throws:
java.sql.SQLException- if something wrong happens- Since:
- 43
-
getCopyAPI
CopyManager getCopyAPI() throws java.sql.SQLException
This returns the COPY API for the current connection.- Returns:
- COPY API for the current connection
- Throws:
java.sql.SQLException- if something wrong happens- Since:
- 8.4
-
getLargeObjectAPI
LargeObjectManager getLargeObjectAPI() throws java.sql.SQLException
This returns the LargeObject API for the current connection.- Returns:
- LargeObject API for the current connection
- Throws:
java.sql.SQLException- if something wrong happens- Since:
- 7.3
-
getFastpathAPI
@Deprecated Fastpath getFastpathAPI() throws java.sql.SQLException
Deprecated.This API is somewhat obsolete, as one may achieve similar performance and greater functionality by setting up a prepared statement to define the function call. Then, executing the statement with binary transmission of parameters and results substitutes for a fast-path function call.This returns the Fastpath API for the current connection.- Returns:
- Fastpath API for the current connection
- Throws:
java.sql.SQLException- if something wrong happens- Since:
- 7.3
-
addDataType
@Deprecated void addDataType(java.lang.String type, java.lang.String className)Deprecated.As of 8.0, replaced byaddDataType(String, Class). This deprecated method does not work correctly for registering classes that cannot be directly loaded by the JDBC driver's classloader.This allows client code to add a handler for one of org.postgresql's more unique data types. It is approximately equivalent toaddDataType(type, Class.forName(name)).- Parameters:
type- JDBC type nameclassName- class name- Throws:
java.lang.RuntimeException- if the type cannot be registered (class not found, etc).
-
addDataType
void addDataType(java.lang.String type, java.lang.Class<? extends PGobject> klass) throws java.sql.SQLExceptionThis allows client code to add a handler for one of org.postgresql's more unique data types.
NOTE: This is not part of JDBC, but an extension.
The best way to use this is as follows:
... ((org.postgresql.PGConnection)myconn).addDataType("mytype", my.class.name.class); ...where myconn is an open Connection to org.postgresql.
The handling class must extend org.postgresql.util.PGobject
-
setPrepareThreshold
void setPrepareThreshold(int threshold)
Set the default statement reuse threshold before enabling server-side prepare. SeePGStatement.setPrepareThreshold(int)for details.- Parameters:
threshold- the new threshold- Since:
- build 302
-
getPrepareThreshold
int getPrepareThreshold()
Get the default server-side prepare reuse threshold for statements created from this connection.- Returns:
- the current threshold
- Since:
- build 302
-
setDefaultFetchSize
void setDefaultFetchSize(int fetchSize) throws java.sql.SQLExceptionSet the default fetch size for statements created from this connection.- Parameters:
fetchSize- new default fetch size- Throws:
java.sql.SQLException- if specified negativefetchSizeparameter- See Also:
Statement.setFetchSize(int)
-
getDefaultFetchSize
int getDefaultFetchSize()
Get the default fetch size for statements created from this connection.- Returns:
- current state for default fetch size
- See Also:
PGProperty.DEFAULT_ROW_FETCH_SIZE,Statement.getFetchSize()
-
getBackendPID
int getBackendPID()
Return the process ID (PID) of the backend server process handling this connection.- Returns:
- PID of backend server process.
-
cancelQuery
void cancelQuery() throws java.sql.SQLExceptionSends a query cancellation for this connection.- Throws:
java.sql.SQLException- if there are problems cancelling the query
-
escapeIdentifier
java.lang.String escapeIdentifier(java.lang.String identifier) throws java.sql.SQLExceptionReturn the given string suitably quoted to be used as an identifier in an SQL statement string. Quotes are added only if necessary (i.e., if the string contains non-identifier characters or would be case-folded). Embedded quotes are properly doubled.- Parameters:
identifier- input identifier- Returns:
- the escaped identifier
- Throws:
java.sql.SQLException- if something goes wrong
-
escapeLiteral
java.lang.String escapeLiteral(java.lang.String literal) throws java.sql.SQLExceptionReturn the given string suitably quoted to be used as a string literal in an SQL statement string. Embedded single-quotes and backslashes are properly doubled. Note that quote_literal returns null on null input.- Parameters:
literal- input literal- Returns:
- the quoted literal
- Throws:
java.sql.SQLException- if something goes wrong
-
getPreferQueryMode
PreferQueryMode getPreferQueryMode()
Returns the query mode for this connection.
When running in simple query mode, certain features are not available: callable statements, partial result set fetch, bytea type, etc.
The list of supported features is subject to change.
- Returns:
- the preferred query mode
- See Also:
PreferQueryMode
-
getAutosave
AutoSave getAutosave()
Connection configuration regarding automatic per-query savepoints.- Returns:
- connection configuration regarding automatic per-query savepoints
- See Also:
PGProperty.AUTOSAVE
-
setAutosave
void setAutosave(AutoSave autoSave)
Configures if connection should use automatic savepoints.- Parameters:
autoSave- connection configuration regarding automatic per-query savepoints- See Also:
PGProperty.AUTOSAVE
-
getReplicationAPI
PGReplicationConnection getReplicationAPI()
- Returns:
- replication API for the current connection
-
getParameterStatuses
java.util.Map<java.lang.String,java.lang.String> getParameterStatuses()
Returns the current values of all parameters reported by the server.
PostgreSQL reports values for a subset of parameters (GUCs) to the client at connect-time, then sends update messages whenever the values change during a session. PgJDBC records the latest values and exposes it to client applications via
getParameterStatuses().PgJDBC exposes individual accessors for some of these parameters as listed below. They are more backwarrds-compatible and should be preferred where possible.
Not all parameters are reported, only those marked
GUC_REPORTin the source code. Thepg_settingsview does not expose information about which parameters are reportable. PgJDBC's map will only contain the parameters the server reports values for, so you cannot use this method as a substitute for running aSHOW paramname;orSELECT current_setting('paramname');query for arbitrary parameters.Parameter names are case-insensitive and case-preserving in this map, like in PostgreSQL itself. So
DateStyleanddatestyleare the same key.As of PostgreSQL 11 the reportable parameter list, and related PgJDBC interfaces or accesors, are:
-
application_name-Connection.getClientInfo(),Connection.setClientInfo(java.util.Properties)andApplicationNameconnection property. -
client_encoding- PgJDBC always sets this toUTF8. SeeallowEncodingChangesconnection property. DateStyle- PgJDBC requires this to always be set toISOstandard_conforming_strings- indirectly viaescapeLiteral(String)-
TimeZone- set from JDK timezone seeTimeZone.getDefault()andTimeZone.setDefault(TimeZone) integer_datetimesIntervalStyleserver_encodingserver_versionis_superusersession_authorization
Note that some PgJDBC operations will change server parameters automatically.
- Returns:
- unmodifiable map of case-insensitive parameter names to parameter values
- Since:
- 42.2.6
-
-
getParameterStatus
java.lang.String getParameterStatus(java.lang.String parameterName)
Shorthand for getParameterStatuses().get(...) .- Parameters:
parameterName- case-insensitive parameter name- Returns:
- parameter value if defined, or null if no parameter known
- Since:
- 42.2.6
- See Also:
getParameterStatuses()
-
-