public interface PGConnection
Modifier and Type | Method and Description |
---|---|
void |
addDataType(String type,
Class<? extends PGobject> klass)
This allows client code to add a handler for one of org.postgresql's more unique data types.
|
void |
addDataType(String type,
String className)
Deprecated.
As of 8.0, replaced by
addDataType(String, Class) . This deprecated method
does not work correctly for registering classes that cannot be directly loaded by
the JDBC driver's classloader. |
void |
cancelQuery()
Sends a query cancellation for this connection.
|
Array |
createArrayOf(String typeName,
@Nullable Object elements)
Creates an
Array wrapping elements. |
String |
escapeIdentifier(String identifier)
Return the given string suitably quoted to be used as an identifier in an SQL statement string.
|
String |
escapeLiteral(String literal)
Return the given string suitably quoted to be used as a string literal in an SQL statement
string.
|
boolean |
getAdaptiveFetch()
Get state of adaptive fetch for connection.
|
AutoSave |
getAutosave()
Connection configuration regarding automatic per-query savepoints.
|
int |
getBackendPID()
Return the process ID (PID) of the backend server process handling this connection.
|
CopyManager |
getCopyAPI()
This returns the COPY API for the current connection.
|
int |
getDefaultFetchSize()
Get the default fetch size for statements created from this connection.
|
Fastpath |
getFastpathAPI()
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.
|
LargeObjectManager |
getLargeObjectAPI()
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.
|
@Nullable String |
getParameterStatus(String parameterName)
Shorthand for getParameterStatuses().get(...) .
|
Map<String,String> |
getParameterStatuses()
Returns the current values of all parameters reported by the server.
|
PreferQueryMode |
getPreferQueryMode()
Returns the query mode for this connection.
|
int |
getPrepareThreshold()
Get the default server-side prepare reuse threshold for statements created from this
connection.
|
PGReplicationConnection |
getReplicationAPI() |
void |
setAdaptiveFetch(boolean adaptiveFetch)
Turn on/off adaptive fetch for connection.
|
void |
setAutosave(AutoSave autoSave)
Configures if connection should use automatic savepoints.
|
void |
setDefaultFetchSize(int fetchSize)
Set the default fetch size for statements created from this connection.
|
void |
setPrepareThreshold(int threshold)
Set the default statement reuse threshold before enabling server-side prepare.
|
Array createArrayOf(String typeName, @Nullable Object elements) throws SQLException
Array
wrapping elements. This is similar to
Connection.createArrayOf(String, Object[])
, but also
provides support for primitive arrays.typeName
- The SQL name of the type to map the elements to.
Must not be null
.elements
- The array of objects to map. A null
value will result in
an Array
representing null
.Array
wrapping elements.SQLException
- If for some reason the array cannot be created.Connection.createArrayOf(String, Object[])
PGNotification[] getNotifications() throws SQLException
SQLException
- if something wrong happensPGNotification[] getNotifications(int timeoutMillis) throws SQLException
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.SQLException
- if something wrong happensCopyManager getCopyAPI() throws SQLException
SQLException
- if something wrong happensLargeObjectManager getLargeObjectAPI() throws SQLException
SQLException
- if something wrong happens@Deprecated Fastpath getFastpathAPI() throws SQLException
SQLException
- if something wrong happens@Deprecated void addDataType(String type, String className)
addDataType(String, Class)
. This deprecated method
does not work correctly for registering classes that cannot be directly loaded by
the JDBC driver's classloader.addDataType(type, Class.forName(name))
.type
- JDBC type nameclassName
- class nameRuntimeException
- if the type cannot be registered (class not found, etc).void addDataType(String type, Class<? extends PGobject> klass) throws SQLException
This 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
type
- the PostgreSQL type to registerklass
- the class implementing the Java representation of the type; this class must
implement PGobject
).SQLException
- if klass
does not implement
PGobject
).PGobject
void setPrepareThreshold(int threshold)
PGStatement.setPrepareThreshold(int)
for details.threshold
- the new thresholdint getPrepareThreshold()
void setDefaultFetchSize(int fetchSize) throws SQLException
fetchSize
- new default fetch sizeSQLException
- if specified negative fetchSize
parameterStatement.setFetchSize(int)
int getDefaultFetchSize()
PGProperty.DEFAULT_ROW_FETCH_SIZE
,
Statement.getFetchSize()
int getBackendPID()
void cancelQuery() throws SQLException
SQLException
- if there are problems cancelling the queryString escapeIdentifier(String identifier) throws SQLException
identifier
- input identifierSQLException
- if something goes wrongString escapeLiteral(String literal) throws SQLException
literal
- input literalSQLException
- if something goes wrongPreferQueryMode 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.
PreferQueryMode
AutoSave getAutosave()
PGProperty.AUTOSAVE
void setAutosave(AutoSave autoSave)
autoSave
- connection configuration regarding automatic per-query savepointsPGProperty.AUTOSAVE
PGReplicationConnection getReplicationAPI()
Map<String,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_REPORT
in the source code. The pg_settings
view 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 a
SHOW paramname;
or SELECT
current_setting('paramname');
query for arbitrary parameters.
Parameter names are case-insensitive and case-preserving
in this map, like in PostgreSQL itself. So DateStyle
and
datestyle
are 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)
and ApplicationName
connection property.
client_encoding
- PgJDBC always sets this to UTF8
.
See allowEncodingChanges
connection property.
DateStyle
- PgJDBC requires this to always be set to ISO
standard_conforming_strings
- indirectly via escapeLiteral(String)
TimeZone
- set from JDK timezone see TimeZone.getDefault()
and TimeZone.setDefault(TimeZone)
integer_datetimes
IntervalStyle
server_encoding
server_version
is_superuser
session_authorization
Note that some PgJDBC operations will change server parameters automatically.
@Nullable String getParameterStatus(String parameterName)
parameterName
- case-insensitive parameter namegetParameterStatuses()
void setAdaptiveFetch(boolean adaptiveFetch)
adaptiveFetch
- desired state of adaptive fetch.boolean getAdaptiveFetch()
Copyright © 1997-2020 PostgreSQL Global Development Group. All Rights Reserved.