public class PgConnection extends java.lang.Object implements BaseConnection
| Modifier and Type | Class and Description |
|---|---|
class |
PgConnection.AbortCommand |
private static class |
PgConnection.ReadOnlyBehavior |
private class |
PgConnection.TransactionCommandHandler
Handler for transaction queries.
|
| Modifier and Type | Field and Description |
|---|---|
private boolean |
autoCommit |
private boolean |
bindStringAsVarchar |
private java.util.Timer |
cancelTimer |
private java.sql.PreparedStatement |
checkConnectionQuery |
private java.util.Properties |
clientInfo |
private Query |
commitQuery |
private CopyManager |
copyManager |
private java.lang.String |
creatingURL |
protected int |
defaultFetchSize
Default fetch size for statement.
|
private boolean |
disableColumnSanitiser |
private Fastpath |
fastpath |
private LruCache<FieldMetadata.Key,FieldMetadata> |
fieldMetadataCache |
private java.sql.SQLWarning |
firstWarning |
protected boolean |
forcebinary |
private boolean |
hideUnprivilegedObjects |
private LargeObjectManager |
largeobject |
private static java.util.logging.Logger |
LOGGER |
protected java.sql.DatabaseMetaData |
metadata |
private java.lang.Throwable |
openStackTrace |
protected int |
prepareThreshold |
private QueryExecutor |
queryExecutor |
private boolean |
readOnly |
private PgConnection.ReadOnlyBehavior |
readOnlyBehavior |
private boolean |
replicationConnection
Replication protocol in current version postgresql(10devel) supports a limited number of
commands.
|
private Query |
rollbackQuery |
private int |
rsHoldability |
private int |
savepointId |
private CachedQuery |
setSessionNotReadOnly |
private CachedQuery |
setSessionReadOnly |
private static java.sql.SQLPermission |
SQL_PERMISSION_ABORT |
private static java.sql.SQLPermission |
SQL_PERMISSION_NETWORK_TIMEOUT |
private static java.util.Set<java.lang.Integer> |
SUPPORTED_BINARY_OIDS |
private TimestampUtils |
timestampUtils |
private TypeInfo |
typeCache |
protected java.util.Map<java.lang.String,java.lang.Class<?>> |
typemap
The current type mappings.
|
private PGXmlFactoryFactory |
xmlFactoryFactory |
private java.lang.String |
xmlFactoryFactoryClass |
| Constructor and Description |
|---|
PgConnection(HostSpec[] hostSpecs,
java.lang.String user,
java.lang.String database,
java.util.Properties info,
java.lang.String url) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
abort() |
void |
abort(java.util.concurrent.Executor executor) |
void |
addDataType(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.
|
void |
addDataType(java.lang.String type,
java.lang.String name)
This allows client code to add a handler for one of org.postgresql's more unique data types.
|
void |
addTimerTask(java.util.TimerTask timerTask,
long milliSeconds)
Schedule a TimerTask for later execution.
|
void |
addWarning(java.sql.SQLWarning warn)
This adds a warning to the warning chain.
|
private static void |
appendArray(java.lang.StringBuilder sb,
java.lang.Object elements,
char delim) |
boolean |
binaryTransferSend(int oid)
Returns true if value for the given oid should be sent using binary transfer.
|
(package private) CachedQuery |
borrowCallableQuery(java.lang.String sql) |
(package private) CachedQuery |
borrowQuery(java.lang.String sql) |
private CachedQuery |
borrowReturningQuery(java.lang.String sql,
java.lang.String[] columnNames) |
void |
cancelQuery()
Cancel the current query executing on this connection.
|
protected void |
checkClosed() |
void |
clearWarnings() |
void |
close()
Note: even though
Statement is automatically closed when it is garbage
collected, it is better to close it explicitly to lower resource consumption. |
void |
commit() |
java.sql.Array |
createArrayOf(java.lang.String typeName,
java.lang.Object elements)
Creates an
Array wrapping elements. |
java.sql.Array |
createArrayOf(java.lang.String typeName,
java.lang.Object[] elements) |
java.sql.Blob |
createBlob() |
java.sql.Clob |
createClob() |
java.sql.NClob |
createNClob() |
CachedQuery |
createQuery(java.lang.String sql,
boolean escapeProcessing,
boolean isParameterized,
java.lang.String... columnNames) |
<T> T |
createQueryObject(java.lang.Class<T> ifc) |
java.sql.SQLXML |
createSQLXML() |
java.sql.Statement |
createStatement() |
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency) |
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
java.sql.Struct |
createStruct(java.lang.String typeName,
java.lang.Object[] attributes) |
protected TypeInfo |
createTypeInfo(BaseConnection conn,
int unknownLength) |
byte[] |
encodeString(java.lang.String str)
Encode a string using the database's client_encoding (usually UTF8, but can vary on older
server versions).
|
java.lang.String |
escapeIdentifier(java.lang.String identifier)
Return the given string suitably quoted to be used as an identifier in an SQL statement string.
|
java.lang.String |
escapeLiteral(java.lang.String literal)
Return the given string suitably quoted to be used as a string literal in an SQL statement
string.
|
java.lang.String |
escapeString(java.lang.String str)
Escapes a string for use as string-literal within an SQL command.
|
java.sql.ResultSet |
execSQLQuery(java.lang.String s)
Execute a SQL query that returns a single resultset.
|
java.sql.ResultSet |
execSQLQuery(java.lang.String s,
int resultSetType,
int resultSetConcurrency) |
(package private) void |
execSQLUpdate(CachedQuery query) |
void |
execSQLUpdate(java.lang.String s)
Execute a SQL query that does not return results.
|
private void |
executeTransactionCommand(Query query) |
protected void |
finalize()
Overrides finalize().
|
boolean |
getAutoCommit() |
AutoSave |
getAutosave()
Connection configuration regarding automatic per-query savepoints.
|
int |
getBackendPID()
Return the process ID (PID) of the backend server process handling this connection.
|
private static java.util.Set<java.lang.Integer> |
getBinaryOids(java.util.Properties info) |
java.lang.String |
getCatalog() |
java.util.Properties |
getClientInfo() |
java.lang.String |
getClientInfo(java.lang.String name) |
CopyManager |
getCopyAPI()
This returns the COPY API for the current connection.
|
java.lang.String |
getCursorName()
getCursorName gets the cursor name.
|
java.lang.String |
getDBVersionNumber()
Get server version number.
|
int |
getDefaultFetchSize()
Get the default fetch size for statements created from this connection.
|
Encoding |
getEncoding() |
Fastpath |
getFastpathAPI()
This returns the Fastpath API for the current connection.
|
LruCache<FieldMetadata.Key,FieldMetadata> |
getFieldMetadataCache()
Return metadata cache for given connection.
|
boolean |
getForceBinary() |
boolean |
getHideUnprivilegedObjects() |
int |
getHoldability() |
protected java.lang.String |
getIsolationLevelName(int level) |
LargeObjectManager |
getLargeObjectAPI()
This returns the LargeObject API for the current connection.
|
java.util.logging.Logger |
getLogger() |
java.sql.DatabaseMetaData |
getMetaData() |
int |
getNetworkTimeout() |
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.Object |
getObject(java.lang.String type,
java.lang.String value,
byte[] byteValue)
Construct and return an appropriate object for the given type and value.
|
private static java.util.Set<java.lang.Integer> |
getOidSet(java.lang.String oidList) |
java.lang.String |
getParameterStatus(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.
|
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.
|
int |
getProtocolVersion() |
QueryExecutor |
getQueryExecutor()
Get the QueryExecutor implementation for this connection.
|
private static PgConnection.ReadOnlyBehavior |
getReadOnlyBehavior(java.lang.String property) |
PGReplicationConnection |
getReplicationAPI() |
ReplicationProtocol |
getReplicationProtocol()
Internal protocol for work with physical and logical replication.
|
java.lang.String |
getSchema() |
int |
getServerMajorVersion()
Get server major version.
|
int |
getServerMinorVersion()
Get server minor version.
|
boolean |
getStandardConformingStrings()
Returns whether the server treats string-literals according to the SQL standard or if it uses
traditional PostgreSQL escaping rules.
|
boolean |
getStringVarcharFlag() |
private static java.util.Set<java.lang.Integer> |
getSupportedBinaryOids() |
private java.util.Timer |
getTimer() |
TimestampUtils |
getTimestampUtils() |
int |
getTransactionIsolation() |
TransactionState |
getTransactionState()
Get the current transaction state of this connection.
|
TypeInfo |
getTypeInfo() |
java.util.Map<java.lang.String,java.lang.Class<?>> |
getTypeMap() |
java.lang.String |
getURL()
We are required to bring back certain information by the DatabaseMetaData class.
|
java.lang.String |
getUserName()
Method getUserName() brings back the User Name (again, we saved it).
|
java.sql.SQLWarning |
getWarnings() |
PGXmlFactoryFactory |
getXmlFactoryFactory()
Retrieve the factory to instantiate XML processing factories.
|
boolean |
haveMinimumServerVersion(int ver)
Check if we have at least a particular server version.
|
boolean |
haveMinimumServerVersion(Version ver)
Check if we have at least a particular server version.
|
boolean |
hintReadOnly()
Indicates if statements to backend should be hinted as read only.
|
private void |
initObjectTypes(java.util.Properties info) |
private static int |
integerPart(java.lang.String dirtyString) |
boolean |
isClosed() |
boolean |
isColumnSanitiserDisabled()
Return whether to disable column name sanitation.
|
boolean |
isReadOnly() |
boolean |
isValid(int timeout) |
boolean |
isWrapperFor(java.lang.Class<?> iface) |
protected java.sql.Array |
makeArray(int oid,
java.lang.String fieldString) |
protected java.sql.Blob |
makeBlob(long oid) |
protected java.sql.Clob |
makeClob(long oid) |
protected java.sql.SQLXML |
makeSQLXML() |
java.lang.String |
nativeSQL(java.lang.String sql) |
private java.lang.String |
oidsToString(java.util.Set<java.lang.Integer> oids) |
java.sql.CallableStatement |
prepareCall(java.lang.String sql) |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int autoGeneratedKeys) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int[] columnIndexes) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
java.lang.String[] columnNames) |
void |
purgeTimerTasks()
Invoke purge() on the underlying shared Timer so that internal resources will be released.
|
(package private) void |
releaseQuery(CachedQuery cachedQuery) |
void |
releaseSavepoint(java.sql.Savepoint savepoint) |
private void |
releaseTimer() |
void |
rollback() |
void |
rollback(java.sql.Savepoint savepoint) |
void |
setAutoCommit(boolean autoCommit) |
void |
setAutosave(AutoSave autoSave)
Configures if connection should use automatic savepoints.
|
void |
setCatalog(java.lang.String catalog) |
void |
setClientInfo(java.util.Properties properties) |
void |
setClientInfo(java.lang.String name,
java.lang.String value) |
void |
setCursorName(java.lang.String cursor)
In SQL, a result table can be retrieved through a cursor that is named.
|
void |
setDefaultFetchSize(int fetchSize)
Set the default fetch size for statements created from this connection.
|
void |
setDisableColumnSanitiser(boolean disableColumnSanitiser) |
void |
setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)
By default, the connection resets statement cache in case deallocate all/discard all
message is observed.
|
void |
setForceBinary(boolean newValue) |
void |
setHoldability(int holdability) |
void |
setNetworkTimeout(java.util.concurrent.Executor executor,
int milliseconds) |
void |
setPrepareThreshold(int newThreshold)
Set the default statement reuse threshold before enabling server-side prepare.
|
void |
setReadOnly(boolean readOnly) |
java.sql.Savepoint |
setSavepoint() |
java.sql.Savepoint |
setSavepoint(java.lang.String name) |
void |
setSchema(java.lang.String schema) |
void |
setTransactionIsolation(int level) |
void |
setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map) |
void |
setTypeMapImpl(java.util.Map<java.lang.String,java.lang.Class<?>> map) |
<T> T |
unwrap(java.lang.Class<T> iface) |
private static final java.util.logging.Logger LOGGER
private static final java.util.Set<java.lang.Integer> SUPPORTED_BINARY_OIDS
private static final java.sql.SQLPermission SQL_PERMISSION_ABORT
private static final java.sql.SQLPermission SQL_PERMISSION_NETWORK_TIMEOUT
private final java.util.Properties clientInfo
private final java.lang.String creatingURL
private final PgConnection.ReadOnlyBehavior readOnlyBehavior
private java.lang.Throwable openStackTrace
private final QueryExecutor queryExecutor
private final Query commitQuery
private final Query rollbackQuery
private final CachedQuery setSessionReadOnly
private final CachedQuery setSessionNotReadOnly
private final TypeInfo typeCache
private boolean disableColumnSanitiser
protected int prepareThreshold
protected int defaultFetchSize
PGProperty.DEFAULT_ROW_FETCH_SIZEprotected boolean forcebinary
private int rsHoldability
private int savepointId
private boolean autoCommit
private boolean readOnly
private boolean hideUnprivilegedObjects
private final boolean bindStringAsVarchar
private java.sql.SQLWarning firstWarning
private volatile java.util.Timer cancelTimer
private java.sql.PreparedStatement checkConnectionQuery
private final boolean replicationConnection
private final LruCache<FieldMetadata.Key,FieldMetadata> fieldMetadataCache
private final java.lang.String xmlFactoryFactoryClass
private PGXmlFactoryFactory xmlFactoryFactory
private final TimestampUtils timestampUtils
protected java.util.Map<java.lang.String,java.lang.Class<?>> typemap
private Fastpath fastpath
private LargeObjectManager largeobject
protected java.sql.DatabaseMetaData metadata
private CopyManager copyManager
public PgConnection(HostSpec[] hostSpecs, java.lang.String user, java.lang.String database, java.util.Properties info, java.lang.String url) throws java.sql.SQLException
java.sql.SQLExceptionfinal CachedQuery borrowQuery(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLExceptionfinal CachedQuery borrowCallableQuery(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLExceptionprivate CachedQuery borrowReturningQuery(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
java.sql.SQLExceptionpublic CachedQuery createQuery(java.lang.String sql, boolean escapeProcessing, boolean isParameterized, java.lang.String... columnNames) throws java.sql.SQLException
createQuery in interface BaseConnectionjava.sql.SQLExceptionvoid releaseQuery(CachedQuery cachedQuery)
public void setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)
BaseConnectionsetFlushCacheOnDeallocate in interface BaseConnectionflushCacheOnDeallocate - true if statement cache should be reset when "deallocate/discard" message observedprivate static PgConnection.ReadOnlyBehavior getReadOnlyBehavior(java.lang.String property)
private static java.util.Set<java.lang.Integer> getSupportedBinaryOids()
private static java.util.Set<java.lang.Integer> getBinaryOids(java.util.Properties info)
throws PSQLException
PSQLExceptionprivate static java.util.Set<java.lang.Integer> getOidSet(java.lang.String oidList)
throws PSQLException
PSQLExceptionprivate java.lang.String oidsToString(java.util.Set<java.lang.Integer> oids)
public TimestampUtils getTimestampUtils()
getTimestampUtils in interface BaseConnectionpublic java.sql.Statement createStatement()
throws java.sql.SQLException
createStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.PreparedStatement prepareStatement(java.lang.String sql)
throws java.sql.SQLException
prepareStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.CallableStatement prepareCall(java.lang.String sql)
throws java.sql.SQLException
prepareCall in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap()
throws java.sql.SQLException
getTypeMap in interface java.sql.Connectionjava.sql.SQLExceptionpublic QueryExecutor getQueryExecutor()
BaseConnectiongetQueryExecutor in interface BaseConnectionpublic ReplicationProtocol getReplicationProtocol()
BaseConnectiongetReplicationProtocol in interface BaseConnectionpublic void addWarning(java.sql.SQLWarning warn)
warn - warning to addpublic java.sql.ResultSet execSQLQuery(java.lang.String s)
throws java.sql.SQLException
BaseConnectionexecSQLQuery in interface BaseConnections - the query to executejava.sql.SQLException - if something goes wrong.public java.sql.ResultSet execSQLQuery(java.lang.String s,
int resultSetType,
int resultSetConcurrency)
throws java.sql.SQLException
execSQLQuery in interface BaseConnectionjava.sql.SQLExceptionpublic void execSQLUpdate(java.lang.String s)
throws java.sql.SQLException
BaseConnectionexecSQLUpdate in interface BaseConnections - the query to executejava.sql.SQLException - if something goes wrong.void execSQLUpdate(CachedQuery query) throws java.sql.SQLException
java.sql.SQLExceptionpublic void setCursorName(java.lang.String cursor)
throws java.sql.SQLException
In SQL, a result table can be retrieved through a cursor that is named. The current row of a result can be updated or deleted using a positioned update/delete statement that references the cursor name.
We do not support positioned update/delete, so this is a no-op.
cursor - the cursor namejava.sql.SQLException - if a database access error occurspublic java.lang.String getCursorName()
throws java.sql.SQLException
java.sql.SQLException - if a database access error occurspublic java.lang.String getURL()
throws java.sql.SQLException
We are required to bring back certain information by the DatabaseMetaData class. These functions do that.
Method getURL() brings back the URL (good job we saved it)
java.sql.SQLException - just in case...public java.lang.String getUserName()
throws java.sql.SQLException
java.sql.SQLException - just in case...public Fastpath getFastpathAPI() throws java.sql.SQLException
PGConnectiongetFastpathAPI in interface PGConnectionjava.sql.SQLException - if something wrong happenspublic LargeObjectManager getLargeObjectAPI() throws java.sql.SQLException
PGConnectiongetLargeObjectAPI in interface PGConnectionjava.sql.SQLException - if something wrong happenspublic java.lang.Object getObject(java.lang.String type,
java.lang.String value,
byte[] byteValue)
throws java.sql.SQLException
BaseConnectionConstruct and return an appropriate object for the given type and value. This only considers
the types registered via PGConnection.addDataType(String, Class) and
PGConnection.addDataType(String, String).
If no class is registered as handling the given type, then a generic
PGobject instance is returned.
getObject in interface BaseConnectiontype - the backend typenamevalue - the type-specific string representation of the valuebyteValue - the type-specific binary representation of the valuejava.sql.SQLException - if something goes wrongprotected TypeInfo createTypeInfo(BaseConnection conn, int unknownLength)
public TypeInfo getTypeInfo()
getTypeInfo in interface BaseConnectionpublic void addDataType(java.lang.String type,
java.lang.String name)
PGConnectionaddDataType(type, Class.forName(name)).addDataType in interface PGConnectiontype - JDBC type namename - class namepublic void addDataType(java.lang.String type,
java.lang.Class<? extends PGobject> klass)
throws java.sql.SQLException
PGConnectionThis 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
addDataType in interface PGConnectiontype - the PostgreSQL type to registerklass - the class implementing the Java representation of the type; this class must
implement PGobject).java.sql.SQLException - if klass does not implement
PGobject).PGobjectprivate void initObjectTypes(java.util.Properties info)
throws java.sql.SQLException
java.sql.SQLExceptionpublic void close()
throws java.sql.SQLException
Statement is automatically closed when it is garbage
collected, it is better to close it explicitly to lower resource consumption.
close in interface java.lang.AutoCloseableclose in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.lang.String nativeSQL(java.lang.String sql)
throws java.sql.SQLException
nativeSQL in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.SQLWarning getWarnings()
throws java.sql.SQLException
getWarnings in interface java.sql.Connectionjava.sql.SQLExceptionpublic void clearWarnings()
throws java.sql.SQLException
clearWarnings in interface java.sql.Connectionjava.sql.SQLExceptionpublic void setReadOnly(boolean readOnly)
throws java.sql.SQLException
setReadOnly in interface java.sql.Connectionjava.sql.SQLExceptionpublic boolean isReadOnly()
throws java.sql.SQLException
isReadOnly in interface java.sql.Connectionjava.sql.SQLExceptionpublic boolean hintReadOnly()
BaseConnectionhintReadOnly in interface BaseConnectionPGProperty.READ_ONLY_MODEpublic void setAutoCommit(boolean autoCommit)
throws java.sql.SQLException
setAutoCommit in interface java.sql.Connectionjava.sql.SQLExceptionpublic boolean getAutoCommit()
throws java.sql.SQLException
getAutoCommit in interface java.sql.Connectionjava.sql.SQLExceptionprivate void executeTransactionCommand(Query query) throws java.sql.SQLException
java.sql.SQLExceptionpublic void commit()
throws java.sql.SQLException
commit in interface java.sql.Connectionjava.sql.SQLExceptionprotected void checkClosed()
throws java.sql.SQLException
java.sql.SQLExceptionpublic void rollback()
throws java.sql.SQLException
rollback in interface java.sql.Connectionjava.sql.SQLExceptionpublic TransactionState getTransactionState()
BaseConnectiongetTransactionState in interface BaseConnectionpublic int getTransactionIsolation()
throws java.sql.SQLException
getTransactionIsolation in interface java.sql.Connectionjava.sql.SQLExceptionpublic void setTransactionIsolation(int level)
throws java.sql.SQLException
setTransactionIsolation in interface java.sql.Connectionjava.sql.SQLExceptionprotected java.lang.String getIsolationLevelName(int level)
public void setCatalog(java.lang.String catalog)
throws java.sql.SQLException
setCatalog in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.lang.String getCatalog()
throws java.sql.SQLException
getCatalog in interface java.sql.Connectionjava.sql.SQLExceptionpublic boolean getHideUnprivilegedObjects()
protected void finalize()
throws java.lang.Throwable
Overrides finalize(). If called, it closes the connection.
This was done at the request of Rachel Greenham who hit a problem where multiple clients didn't close the connection, and once a fortnight enough clients were open to kill the postgres server.
finalize in class java.lang.Objectjava.lang.Throwablepublic java.lang.String getDBVersionNumber()
public int getServerMajorVersion()
public int getServerMinorVersion()
public boolean haveMinimumServerVersion(int ver)
BaseConnectionCheck if we have at least a particular server version.
The input version is of the form xxyyzz, matching a PostgreSQL version like xx.yy.zz. So 9.0.12 is 90012.
haveMinimumServerVersion in interface BaseConnectionver - the server version to check, of the form xxyyzz eg 90401public boolean haveMinimumServerVersion(Version ver)
BaseConnectionCheck if we have at least a particular server version.
The input version is of the form xxyyzz, matching a PostgreSQL version like xx.yy.zz. So 9.0.12 is 90012.
haveMinimumServerVersion in interface BaseConnectionver - the server version to checkpublic Encoding getEncoding()
getEncoding in interface BaseConnectionpublic byte[] encodeString(java.lang.String str)
throws java.sql.SQLException
BaseConnectionencodeString in interface BaseConnectionstr - the string to encodejava.sql.SQLException - if something goes wrong.public java.lang.String escapeString(java.lang.String str)
throws java.sql.SQLException
BaseConnectionBaseConnection.getStandardConformingStrings().escapeString in interface BaseConnectionstr - a string valuejava.sql.SQLException - if the string contains a \0 characterpublic boolean getStandardConformingStrings()
BaseConnectionstandard_conforming_strings server variable.getStandardConformingStrings in interface BaseConnectionQueryExecutor.getStandardConformingStrings()public boolean isClosed()
throws java.sql.SQLException
isClosed in interface java.sql.Connectionjava.sql.SQLExceptionpublic void cancelQuery()
throws java.sql.SQLException
BaseConnectioncancelQuery in interface BaseConnectioncancelQuery in interface PGConnectionjava.sql.SQLException - if something goes wrong.public PGNotification[] getNotifications() throws java.sql.SQLException
PGConnectiongetNotifications in interface PGConnectionjava.sql.SQLException - if something wrong happenspublic PGNotification[] getNotifications(int timeoutMillis) throws java.sql.SQLException
PGConnectiongetNotifications in interface PGConnectiontimeoutMillis - 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.java.sql.SQLException - if something wrong happenspublic int getPrepareThreshold()
PGConnectiongetPrepareThreshold in interface PGConnectionpublic void setDefaultFetchSize(int fetchSize)
throws java.sql.SQLException
PGConnectionsetDefaultFetchSize in interface PGConnectionfetchSize - new default fetch sizejava.sql.SQLException - if specified negative fetchSize parameterStatement.setFetchSize(int)public int getDefaultFetchSize()
PGConnectiongetDefaultFetchSize in interface PGConnectionPGProperty.DEFAULT_ROW_FETCH_SIZE,
Statement.getFetchSize()public void setPrepareThreshold(int newThreshold)
PGConnectionPGStatement.setPrepareThreshold(int) for details.setPrepareThreshold in interface PGConnectionnewThreshold - the new thresholdpublic boolean getForceBinary()
public void setForceBinary(boolean newValue)
public void setTypeMapImpl(java.util.Map<java.lang.String,java.lang.Class<?>> map)
throws java.sql.SQLException
java.sql.SQLExceptionpublic java.util.logging.Logger getLogger()
getLogger in interface BaseConnectionpublic int getProtocolVersion()
public boolean getStringVarcharFlag()
getStringVarcharFlag in interface BaseConnectionpublic CopyManager getCopyAPI() throws java.sql.SQLException
PGConnectiongetCopyAPI in interface PGConnectionjava.sql.SQLException - if something wrong happenspublic boolean binaryTransferSend(int oid)
BaseConnectionbinaryTransferSend in interface BaseConnectionoid - The oid to check.public int getBackendPID()
PGConnectiongetBackendPID in interface PGConnectionpublic boolean isColumnSanitiserDisabled()
BaseConnectionisColumnSanitiserDisabled in interface BaseConnectionpublic void setDisableColumnSanitiser(boolean disableColumnSanitiser)
public PreferQueryMode getPreferQueryMode()
PGConnectionReturns 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.
getPreferQueryMode in interface PGConnectionPreferQueryModepublic AutoSave getAutosave()
PGConnectiongetAutosave in interface PGConnectionPGProperty.AUTOSAVEpublic void setAutosave(AutoSave autoSave)
PGConnectionsetAutosave in interface PGConnectionautoSave - connection configuration regarding automatic per-query savepointsPGProperty.AUTOSAVEprotected void abort()
private java.util.Timer getTimer()
private void releaseTimer()
public void addTimerTask(java.util.TimerTask timerTask,
long milliSeconds)
BaseConnectionaddTimerTask in interface BaseConnectiontimerTask - timer task to schedulemilliSeconds - delay in millisecondspublic void purgeTimerTasks()
BaseConnectionpurgeTimerTasks in interface BaseConnectionpublic java.lang.String escapeIdentifier(java.lang.String identifier)
throws java.sql.SQLException
PGConnectionescapeIdentifier in interface PGConnectionidentifier - input identifierjava.sql.SQLException - if something goes wrongpublic java.lang.String escapeLiteral(java.lang.String literal)
throws java.sql.SQLException
PGConnectionescapeLiteral in interface PGConnectionliteral - input literaljava.sql.SQLException - if something goes wrongpublic LruCache<FieldMetadata.Key,FieldMetadata> getFieldMetadataCache()
BaseConnectiongetFieldMetadataCache in interface BaseConnectionpublic PGReplicationConnection getReplicationAPI()
getReplicationAPI in interface PGConnectionprivate static void appendArray(java.lang.StringBuilder sb,
java.lang.Object elements,
char delim)
private static int integerPart(java.lang.String dirtyString)
public java.sql.Statement createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws java.sql.SQLException
createStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws java.sql.SQLException
prepareStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.CallableStatement prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws java.sql.SQLException
prepareCall in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.DatabaseMetaData getMetaData()
throws java.sql.SQLException
getMetaData in interface java.sql.Connectionjava.sql.SQLExceptionpublic void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)
throws java.sql.SQLException
setTypeMap in interface java.sql.Connectionjava.sql.SQLExceptionprotected java.sql.Array makeArray(int oid,
java.lang.String fieldString)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.sql.Blob makeBlob(long oid)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.sql.Clob makeClob(long oid)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.sql.SQLXML makeSQLXML()
throws java.sql.SQLException
java.sql.SQLExceptionpublic java.sql.Clob createClob()
throws java.sql.SQLException
createClob in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.Blob createBlob()
throws java.sql.SQLException
createBlob in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.NClob createNClob()
throws java.sql.SQLException
createNClob in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.SQLXML createSQLXML()
throws java.sql.SQLException
createSQLXML in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.Struct createStruct(java.lang.String typeName,
java.lang.Object[] attributes)
throws java.sql.SQLException
createStruct in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.Array createArrayOf(java.lang.String typeName,
java.lang.Object elements)
throws java.sql.SQLException
PGConnectionArray wrapping elements. This is similar to
Connection.createArrayOf(String, Object[]), but also
provides support for primitive arrays.createArrayOf in interface PGConnectiontypeName - 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.java.sql.SQLException - If for some reason the array cannot be created.Connection.createArrayOf(String, Object[])public java.sql.Array createArrayOf(java.lang.String typeName,
java.lang.Object[] elements)
throws java.sql.SQLException
createArrayOf in interface java.sql.Connectionjava.sql.SQLExceptionpublic boolean isValid(int timeout)
throws java.sql.SQLException
isValid in interface java.sql.Connectionjava.sql.SQLExceptionpublic void setClientInfo(java.lang.String name,
java.lang.String value)
throws java.sql.SQLClientInfoException
setClientInfo in interface java.sql.Connectionjava.sql.SQLClientInfoExceptionpublic void setClientInfo(java.util.Properties properties)
throws java.sql.SQLClientInfoException
setClientInfo in interface java.sql.Connectionjava.sql.SQLClientInfoExceptionpublic java.lang.String getClientInfo(java.lang.String name)
throws java.sql.SQLException
getClientInfo in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.util.Properties getClientInfo()
throws java.sql.SQLException
getClientInfo in interface java.sql.Connectionjava.sql.SQLExceptionpublic <T> T createQueryObject(java.lang.Class<T> ifc)
throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean isWrapperFor(java.lang.Class<?> iface)
throws java.sql.SQLException
isWrapperFor in interface java.sql.Wrapperjava.sql.SQLExceptionpublic <T> T unwrap(java.lang.Class<T> iface)
throws java.sql.SQLException
unwrap in interface java.sql.Wrapperjava.sql.SQLExceptionpublic java.lang.String getSchema()
throws java.sql.SQLException
getSchema in interface java.sql.Connectionjava.sql.SQLExceptionpublic void setSchema(java.lang.String schema)
throws java.sql.SQLException
setSchema in interface java.sql.Connectionjava.sql.SQLExceptionpublic void abort(java.util.concurrent.Executor executor)
throws java.sql.SQLException
abort in interface java.sql.Connectionjava.sql.SQLExceptionpublic void setNetworkTimeout(java.util.concurrent.Executor executor,
int milliseconds)
throws java.sql.SQLException
setNetworkTimeout in interface java.sql.Connectionjava.sql.SQLExceptionpublic int getNetworkTimeout()
throws java.sql.SQLException
getNetworkTimeout in interface java.sql.Connectionjava.sql.SQLExceptionpublic void setHoldability(int holdability)
throws java.sql.SQLException
setHoldability in interface java.sql.Connectionjava.sql.SQLExceptionpublic int getHoldability()
throws java.sql.SQLException
getHoldability in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.Savepoint setSavepoint()
throws java.sql.SQLException
setSavepoint in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.Savepoint setSavepoint(java.lang.String name)
throws java.sql.SQLException
setSavepoint in interface java.sql.Connectionjava.sql.SQLExceptionpublic void rollback(java.sql.Savepoint savepoint)
throws java.sql.SQLException
rollback in interface java.sql.Connectionjava.sql.SQLExceptionpublic void releaseSavepoint(java.sql.Savepoint savepoint)
throws java.sql.SQLException
releaseSavepoint in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.Statement createStatement(int resultSetType,
int resultSetConcurrency)
throws java.sql.SQLException
createStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
throws java.sql.SQLException
prepareStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.CallableStatement prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
throws java.sql.SQLException
prepareCall in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
prepareStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
prepareStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic java.sql.PreparedStatement prepareStatement(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
prepareStatement in interface java.sql.Connectionjava.sql.SQLExceptionpublic final java.util.Map<java.lang.String,java.lang.String> getParameterStatuses()
PGConnectionReturns 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 ISOstandard_conforming_strings - indirectly via PGConnection.escapeLiteral(String)TimeZone - set from JDK timezone see TimeZone.getDefault()
and TimeZone.setDefault(TimeZone)
integer_datetimesIntervalStyleserver_encodingserver_versionis_superuser session_authorizationNote that some PgJDBC operations will change server parameters automatically.
getParameterStatuses in interface PGConnectionpublic final java.lang.String getParameterStatus(java.lang.String parameterName)
PGConnectiongetParameterStatus in interface PGConnectionparameterName - case-insensitive parameter namePGConnection.getParameterStatuses()public PGXmlFactoryFactory getXmlFactoryFactory() throws java.sql.SQLException
BaseConnectiongetXmlFactoryFactory in interface BaseConnectionjava.sql.SQLException - if the class cannot be found or instantiated.