Class PgConnection
- java.lang.Object
-
- org.postgresql.jdbc.PgConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable,java.sql.Connection,java.sql.Wrapper,BaseConnection,PGConnection
public class PgConnection extends java.lang.Object implements BaseConnection
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classPgConnection.AbortCommand
-
Field Summary
Fields Modifier and Type Field Description protected intdefaultFetchSizeDefault fetch size for statement.protected booleanforcebinaryprotected java.sql.DatabaseMetaDatametadataprotected intprepareThresholdprotected java.util.Map<java.lang.String,java.lang.Class<?>>typemapThe current type mappings.
-
Constructor Summary
Constructors Constructor Description PgConnection(HostSpec[] hostSpecs, java.util.Properties info, java.lang.String url)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidabort()voidabort(java.util.concurrent.Executor executor)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 name)Deprecated.voidaddTimerTask(java.util.TimerTask timerTask, long milliSeconds)Schedule a TimerTask for later execution.voidaddWarning(java.sql.SQLWarning warn)This adds a warning to the warning chain.booleanbinaryTransferSend(int oid)Returns true if value for the given oid should be sent using binary transfer.voidcancelQuery()Cancel the current query executing on this connection.protected voidcheckClosed()voidclearWarnings()voidclose()Note: even thoughStatementis automatically closed when it is garbage collected, it is better to close it explicitly to lower resource consumption.voidcommit()java.sql.ArraycreateArrayOf(java.lang.String typeName, java.lang.Object elements)Creates anArraywrapping elements.java.sql.ArraycreateArrayOf(java.lang.String typeName, java.lang.Object[] elements)java.sql.BlobcreateBlob()java.sql.ClobcreateClob()java.sql.NClobcreateNClob()CachedQuerycreateQuery(java.lang.String sql, boolean escapeProcessing, boolean isParameterized, java.lang.String... columnNames)<T> TcreateQueryObject(java.lang.Class<T> ifc)java.sql.SQLXMLcreateSQLXML()java.sql.StatementcreateStatement()java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency)java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.StructcreateStruct(java.lang.String typeName, java.lang.Object[] attributes)protected TypeInfocreateTypeInfo(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.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.java.lang.StringescapeString(java.lang.String str)Escapes a string for use as string-literal within an SQL command.java.sql.ResultSetexecSQLQuery(java.lang.String s)Execute a SQL query that returns a single resultset.java.sql.ResultSetexecSQLQuery(java.lang.String s, int resultSetType, int resultSetConcurrency)voidexecSQLUpdate(java.lang.String s)Execute a SQL query that does not return results.booleangetAdaptiveFetch()Get state of adaptive fetch for connection.booleangetAutoCommit()AutoSavegetAutosave()Connection configuration regarding automatic per-query savepoints.intgetBackendPID()Return the process ID (PID) of the backend server process handling this connection.java.lang.StringgetCatalog()java.util.PropertiesgetClientInfo()java.lang.StringgetClientInfo(java.lang.String name)booleangetConvertBooleanToNumeric()Returns true if boolean values should be converted to numeric types (1/0).CopyManagergetCopyAPI()This returns the COPY API for the current connection.java.lang.StringgetCursorName()getCursorName gets the cursor name.java.lang.StringgetDBVersionNumber()Get server version number.intgetDefaultFetchSize()Get the default fetch size for statements created from this connection.EncodinggetEncoding()FastpathgetFastpathAPI()This returns the Fastpath API for the current connection.LruCache<FieldMetadata.Key,FieldMetadata>getFieldMetadataCache()Return metadata cache for given connection.booleangetForceBinary()booleangetHideUnprivilegedObjects()intgetHoldability()protected java.lang.StringgetIsolationLevelName(int level)LargeObjectManagergetLargeObjectAPI()This returns the LargeObject API for the current connection.java.util.logging.LoggergetLogger()booleangetLogServerErrorDetail()Indicates if error details from server used in included in logging and exceptions.java.sql.DatabaseMetaDatagetMetaData()intgetNetworkTimeout()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.ObjectgetObject(java.lang.String type, java.lang.String value, byte[] byteValue)This method is used internally to return an object based around org.postgresql's more unique data types.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.ProtocolVersiongetProtocolVersion()QueryExecutorgetQueryExecutor()Get the QueryExecutor implementation for this connection.PGReplicationConnectiongetReplicationAPI()ReplicationProtocolgetReplicationProtocol()Internal protocol for work with physical and logical replication.java.lang.StringgetSchema()intgetServerMajorVersion()Get server major version.intgetServerMinorVersion()Get server minor version.booleangetStandardConformingStrings()Returns whether the server treats string-literals according to the SQL standard or if it uses traditional PostgreSQL escaping rules.booleangetStringVarcharFlag()TimestampUtilsgetTimestampUtils()Deprecated.intgetTransactionIsolation()TransactionStategetTransactionState()Get the current transaction state of this connection.TypeInfogetTypeInfo()java.util.Map<java.lang.String,java.lang.Class<?>>getTypeMap()java.lang.StringgetURL()We are required to bring back certain information by the DatabaseMetaData class.java.lang.StringgetUserName()Method getUserName() brings back the User Name (again, we saved it).java.sql.SQLWarninggetWarnings()PGXmlFactoryFactorygetXmlFactoryFactory()Retrieve the factory to instantiate XML processing factories.booleanhaveMinimumServerVersion(int ver)Check if we have at least a particular server version.booleanhaveMinimumServerVersion(Version ver)Check if we have at least a particular server version.booleanhintReadOnly()Indicates if statements to backend should be hinted as read only.booleanisClosed()booleanisColumnSanitiserDisabled()Return whether to disable column name sanitation.booleanisReadOnly()booleanisValid(int timeout)booleanisWrapperFor(java.lang.Class<?> iface)protected java.sql.ArraymakeArray(int oid, java.lang.String fieldString)protected java.sql.BlobmakeBlob(long oid)protected java.sql.ClobmakeClob(long oid)protected java.sql.SQLXMLmakeSQLXML()java.lang.StringnativeSQL(java.lang.String sql)java.sql.CallableStatementprepareCall(java.lang.String sql)java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.PreparedStatementprepareStatement(java.lang.String sql)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autoGeneratedKeys)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columnNames)voidpurgeTimerTasks()Invoke purge() on the underlying shared Timer so that internal resources will be released.voidreleaseSavepoint(java.sql.Savepoint savepoint)voidrollback()voidrollback(java.sql.Savepoint savepoint)voidsetAdaptiveFetch(boolean adaptiveFetch)Turn on/off adaptive fetch for connection.voidsetAutoCommit(boolean autoCommit)voidsetAutosave(AutoSave autoSave)Configures if connection should use automatic savepoints.voidsetCatalog(java.lang.String catalog)voidsetClientInfo(java.lang.String name, java.lang.String value)voidsetClientInfo(java.util.Properties properties)voidsetCursorName(java.lang.String cursor)In SQL, a result table can be retrieved through a cursor that is named.voidsetDefaultFetchSize(int fetchSize)Set the default fetch size for statements created from this connection.voidsetDisableColumnSanitiser(boolean disableColumnSanitiser)voidsetFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)By default, the connection resets statement cache in case deallocate all/discard all message is observed.voidsetForceBinary(boolean newValue)voidsetHoldability(int holdability)voidsetNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds)voidsetPrepareThreshold(int newThreshold)Set the default statement reuse threshold before enabling server-side prepare.voidsetReadOnly(boolean readOnly)java.sql.SavepointsetSavepoint()java.sql.SavepointsetSavepoint(java.lang.String name)voidsetSchema(java.lang.String schema)voidsetTransactionIsolation(int level)voidsetTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)voidsetTypeMapImpl(java.util.Map<java.lang.String,java.lang.Class<?>> map)<T> Tunwrap(java.lang.Class<T> iface)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Methods inherited from interface org.postgresql.PGConnection
alterUserPassword
-
-
-
-
Field Detail
-
prepareThreshold
protected int prepareThreshold
-
defaultFetchSize
protected int defaultFetchSize
Default fetch size for statement.- See Also:
PGProperty.DEFAULT_ROW_FETCH_SIZE
-
forcebinary
protected boolean forcebinary
-
typemap
protected java.util.Map<java.lang.String,java.lang.Class<?>> typemap
The current type mappings.
-
metadata
protected java.sql.DatabaseMetaData metadata
-
-
Constructor Detail
-
PgConnection
public PgConnection(HostSpec[] hostSpecs, java.util.Properties info, java.lang.String url) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
-
Method Detail
-
createQuery
public CachedQuery createQuery(java.lang.String sql, boolean escapeProcessing, boolean isParameterized, java.lang.String... columnNames) throws java.sql.SQLException
- Specified by:
createQueryin interfaceBaseConnection- Throws:
java.sql.SQLException
-
setFlushCacheOnDeallocate
public void setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)
Description copied from interface:BaseConnectionBy default, the connection resets statement cache in case deallocate all/discard all message is observed. This API allows to disable that feature for testing purposes.- Specified by:
setFlushCacheOnDeallocatein interfaceBaseConnection- Parameters:
flushCacheOnDeallocate- true if statement cache should be reset when "deallocate/discard" message observed
-
getTimestampUtils
@Deprecated public TimestampUtils getTimestampUtils()
Deprecated.- Specified by:
getTimestampUtilsin interfaceBaseConnection
-
createStatement
public java.sql.Statement createStatement() throws java.sql.SQLException- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLException- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getTypeMap
public java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap() throws java.sql.SQLException- Specified by:
getTypeMapin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getQueryExecutor
public QueryExecutor getQueryExecutor()
Description copied from interface:BaseConnectionGet the QueryExecutor implementation for this connection.- Specified by:
getQueryExecutorin interfaceBaseConnection- Returns:
- the (non-null) executor
-
getReplicationProtocol
public ReplicationProtocol getReplicationProtocol()
Description copied from interface:BaseConnectionInternal protocol for work with physical and logical replication. Physical replication available only since PostgreSQL version 9.1. Logical replication available only since PostgreSQL version 9.4.- Specified by:
getReplicationProtocolin interfaceBaseConnection- Returns:
- not null replication protocol
-
addWarning
public void addWarning(java.sql.SQLWarning warn)
This adds a warning to the warning chain.- Parameters:
warn- warning to add
-
execSQLQuery
public java.sql.ResultSet execSQLQuery(java.lang.String s) throws java.sql.SQLExceptionDescription copied from interface:BaseConnectionExecute a SQL query that returns a single resultset. Never causes a new transaction to be started regardless of the autocommit setting.- Specified by:
execSQLQueryin interfaceBaseConnection- Parameters:
s- the query to execute- Returns:
- the (non-null) returned resultset
- Throws:
java.sql.SQLException- if something goes wrong.
-
execSQLQuery
public java.sql.ResultSet execSQLQuery(java.lang.String s, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException- Specified by:
execSQLQueryin interfaceBaseConnection- Throws:
java.sql.SQLException
-
execSQLUpdate
public void execSQLUpdate(java.lang.String s) throws java.sql.SQLExceptionDescription copied from interface:BaseConnectionExecute a SQL query that does not return results. Never causes a new transaction to be started regardless of the autocommit setting.- Specified by:
execSQLUpdatein interfaceBaseConnection- Parameters:
s- the query to execute- Throws:
java.sql.SQLException- if something goes wrong.
-
setCursorName
public void setCursorName(java.lang.String cursor) throws java.sql.SQLExceptionIn 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.
- Parameters:
cursor- the cursor name- Throws:
java.sql.SQLException- if a database access error occurs
-
getCursorName
public java.lang.String getCursorName() throws java.sql.SQLExceptiongetCursorName gets the cursor name.- Returns:
- the current cursor name
- Throws:
java.sql.SQLException- if a database access error occurs
-
getURL
public java.lang.String getURL() throws java.sql.SQLExceptionWe 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)
- Returns:
- the url
- Throws:
java.sql.SQLException- just in case...
-
getUserName
public java.lang.String getUserName() throws java.sql.SQLExceptionMethod getUserName() brings back the User Name (again, we saved it).- Returns:
- the user name
- Throws:
java.sql.SQLException- just in case...
-
getFastpathAPI
public Fastpath getFastpathAPI() throws java.sql.SQLException
Description copied from interface:PGConnectionThis returns the Fastpath API for the current connection.Note: 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.
- Specified by:
getFastpathAPIin interfacePGConnection- Returns:
- Fastpath API for the current connection
- Throws:
java.sql.SQLException- if something wrong happens
-
getLargeObjectAPI
public LargeObjectManager getLargeObjectAPI() throws java.sql.SQLException
Description copied from interface:PGConnectionThis returns the LargeObject API for the current connection.- Specified by:
getLargeObjectAPIin interfacePGConnection- Returns:
- LargeObject API for the current connection
- Throws:
java.sql.SQLException- if something wrong happens
-
getObject
public java.lang.Object getObject(java.lang.String type, java.lang.String value, byte[] byteValue) throws java.sql.SQLExceptionThis method is used internally to return an object based around org.postgresql's more unique data types.It uses an internal HashMap to get the handling class. If the type is not supported, then an instance of org.postgresql.util.PGobject is returned.
You can use the getValue() or setValue() methods to handle the returned object. Custom objects can have their own methods.
- Specified by:
getObjectin interfaceBaseConnection- Parameters:
type- the backend typenamevalue- the type-specific string representation of the valuebyteValue- the type-specific binary representation of the value- Returns:
- PGobject for this type, and set to value
- Throws:
java.sql.SQLException- if value is not correct for this type
-
createTypeInfo
protected TypeInfo createTypeInfo(BaseConnection conn, int unknownLength)
-
getTypeInfo
public TypeInfo getTypeInfo()
- Specified by:
getTypeInfoin interfaceBaseConnection
-
addDataType
@Deprecated public void addDataType(java.lang.String type, java.lang.String name)Deprecated.Description copied from interface:PGConnectionThis 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)).- Specified by:
addDataTypein interfacePGConnection- Parameters:
type- JDBC type namename- class name
-
addDataType
public void addDataType(java.lang.String type, java.lang.Class<? extends PGobject> klass) throws java.sql.SQLExceptionDescription copied from interface: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
- Specified by:
addDataTypein interfacePGConnection- Parameters:
type- the PostgreSQL type to registerklass- the class implementing the Java representation of the type; this class must implementPGobject).- Throws:
java.sql.SQLException- ifklassdoes not implementPGobject).- See Also:
PGobject
-
close
public void close() throws java.sql.SQLExceptionNote: even thoughStatementis automatically closed when it is garbage collected, it is better to close it explicitly to lower resource consumption. The spec says that calling close on a closed connection is a no-op.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
nativeSQL
public java.lang.String nativeSQL(java.lang.String sql) throws java.sql.SQLException- Specified by:
nativeSQLin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException- Specified by:
getWarningsin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings() throws java.sql.SQLException- Specified by:
clearWarningsin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setReadOnly
public void setReadOnly(boolean readOnly) throws java.sql.SQLException- Specified by:
setReadOnlyin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
isReadOnly
public boolean isReadOnly() throws java.sql.SQLException- Specified by:
isReadOnlyin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
hintReadOnly
public boolean hintReadOnly()
Description copied from interface:BaseConnectionIndicates if statements to backend should be hinted as read only.- Specified by:
hintReadOnlyin interfaceBaseConnection- Returns:
- Indication if hints to backend (such as when transaction begins) should be read only.
- See Also:
PGProperty.READ_ONLY_MODE
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException- Specified by:
setAutoCommitin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getAutoCommit
public boolean getAutoCommit() throws java.sql.SQLException- Specified by:
getAutoCommitin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
commit
public void commit() throws java.sql.SQLException- Specified by:
commitin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
checkClosed
protected void checkClosed() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
rollback
public void rollback() throws java.sql.SQLException- Specified by:
rollbackin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getTransactionState
public TransactionState getTransactionState()
Description copied from interface:BaseConnectionGet the current transaction state of this connection.- Specified by:
getTransactionStatein interfaceBaseConnection- Returns:
- current transaction state of this connection
-
getTransactionIsolation
public int getTransactionIsolation() throws java.sql.SQLException- Specified by:
getTransactionIsolationin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setTransactionIsolation
public void setTransactionIsolation(int level) throws java.sql.SQLException- Specified by:
setTransactionIsolationin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getIsolationLevelName
protected java.lang.String getIsolationLevelName(int level)
-
setCatalog
public void setCatalog(java.lang.String catalog) throws java.sql.SQLException- Specified by:
setCatalogin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getCatalog
public java.lang.String getCatalog() throws java.sql.SQLException- Specified by:
getCatalogin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getHideUnprivilegedObjects
public boolean getHideUnprivilegedObjects()
-
getDBVersionNumber
public java.lang.String getDBVersionNumber()
Get server version number.- Returns:
- server version number
-
getServerMajorVersion
public int getServerMajorVersion()
Get server major version.- Returns:
- server major version
-
getServerMinorVersion
public int getServerMinorVersion()
Get server minor version.- Returns:
- server minor version
-
haveMinimumServerVersion
public boolean haveMinimumServerVersion(int ver)
Description copied from interface: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.
- Specified by:
haveMinimumServerVersionin interfaceBaseConnection- Parameters:
ver- the server version to check, of the form xxyyzz eg 90401- Returns:
- true if the server version is at least "ver".
-
haveMinimumServerVersion
public boolean haveMinimumServerVersion(Version ver)
Description copied from interface: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.
- Specified by:
haveMinimumServerVersionin interfaceBaseConnection- Parameters:
ver- the server version to check- Returns:
- true if the server version is at least "ver".
-
getEncoding
public Encoding getEncoding()
- Specified by:
getEncodingin interfaceBaseConnection
-
encodeString
public byte[] encodeString(java.lang.String str) throws java.sql.SQLExceptionDescription copied from interface:BaseConnectionEncode a string using the database's client_encoding (usually UTF8, but can vary on older server versions). This is used when constructing synthetic resultsets (for example, in metadata methods).- Specified by:
encodeStringin interfaceBaseConnection- Parameters:
str- the string to encode- Returns:
- an encoded representation of the string
- Throws:
java.sql.SQLException- if something goes wrong.
-
escapeString
public java.lang.String escapeString(java.lang.String str) throws java.sql.SQLExceptionDescription copied from interface:BaseConnectionEscapes a string for use as string-literal within an SQL command. The method chooses the applicable escaping rules based on the value ofBaseConnection.getStandardConformingStrings().- Specified by:
escapeStringin interfaceBaseConnection- Parameters:
str- a string value- Returns:
- the escaped representation of the string
- Throws:
java.sql.SQLException- if the string contains a\0character
-
getStandardConformingStrings
public boolean getStandardConformingStrings()
Description copied from interface:BaseConnectionReturns whether the server treats string-literals according to the SQL standard or if it uses traditional PostgreSQL escaping rules. Versions up to 8.1 always treated backslashes as escape characters in string-literals. Since 8.2, this depends on the value of thestandard_conforming_stringsserver variable.- Specified by:
getStandardConformingStringsin interfaceBaseConnection- Returns:
- true if the server treats string literals according to the SQL standard
- See Also:
QueryExecutor.getStandardConformingStrings()
-
isClosed
public boolean isClosed() throws java.sql.SQLException- Specified by:
isClosedin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
cancelQuery
public void cancelQuery() throws java.sql.SQLExceptionDescription copied from interface:BaseConnectionCancel the current query executing on this connection.- Specified by:
cancelQueryin interfaceBaseConnection- Specified by:
cancelQueryin interfacePGConnection- Throws:
java.sql.SQLException- if something goes wrong.
-
getNotifications
public PGNotification[] getNotifications() throws java.sql.SQLException
Description copied from interface:PGConnectionThis method returns any notifications that have been received since the last call to this method. Returns an empty array if there have been no notifications.- Specified by:
getNotificationsin interfacePGConnection- Returns:
- notifications that have been received
- Throws:
java.sql.SQLException- if something wrong happens
-
getNotifications
public PGNotification[] getNotifications(int timeoutMillis) throws java.sql.SQLException
Description copied from interface:PGConnectionThis method returns any notifications that have been received since the last call to this method. Returns an empty array if there have been no notifications. A timeout can be specified so the driver waits for notifications.- Specified by:
getNotificationsin interfacePGConnection- Parameters:
timeoutMillis- when 0, blocks forever. when > 0, blocks up to the specified number of millis 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
-
getPrepareThreshold
public int getPrepareThreshold()
Description copied from interface:PGConnectionGet the default server-side prepare reuse threshold for statements created from this connection.- Specified by:
getPrepareThresholdin interfacePGConnection- Returns:
- the current threshold
-
setDefaultFetchSize
public void setDefaultFetchSize(int fetchSize) throws java.sql.SQLExceptionDescription copied from interface:PGConnectionSet the default fetch size for statements created from this connection.- Specified by:
setDefaultFetchSizein interfacePGConnection- Parameters:
fetchSize- new default fetch size- Throws:
java.sql.SQLException- if specified negativefetchSizeparameter- See Also:
Statement.setFetchSize(int)
-
getDefaultFetchSize
public int getDefaultFetchSize()
Description copied from interface:PGConnectionGet the default fetch size for statements created from this connection.- Specified by:
getDefaultFetchSizein interfacePGConnection- Returns:
- current state for default fetch size
- See Also:
PGProperty.DEFAULT_ROW_FETCH_SIZE,Statement.getFetchSize()
-
setPrepareThreshold
public void setPrepareThreshold(int newThreshold)
Description copied from interface:PGConnectionSet the default statement reuse threshold before enabling server-side prepare. SeePGStatement.setPrepareThreshold(int)for details.- Specified by:
setPrepareThresholdin interfacePGConnection- Parameters:
newThreshold- the new threshold
-
getForceBinary
public boolean getForceBinary()
-
setForceBinary
public void setForceBinary(boolean newValue)
-
setTypeMapImpl
public void setTypeMapImpl(java.util.Map<java.lang.String,java.lang.Class<?>> map) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getLogger
public java.util.logging.Logger getLogger()
- Specified by:
getLoggerin interfaceBaseConnection
-
getProtocolVersion
public ProtocolVersion getProtocolVersion()
-
getStringVarcharFlag
public boolean getStringVarcharFlag()
- Specified by:
getStringVarcharFlagin interfaceBaseConnection
-
getCopyAPI
public CopyManager getCopyAPI() throws java.sql.SQLException
Description copied from interface:PGConnectionThis returns the COPY API for the current connection.- Specified by:
getCopyAPIin interfacePGConnection- Returns:
- COPY API for the current connection
- Throws:
java.sql.SQLException- if something wrong happens
-
binaryTransferSend
public boolean binaryTransferSend(int oid)
Description copied from interface:BaseConnectionReturns true if value for the given oid should be sent using binary transfer. False if value should be sent using text transfer.- Specified by:
binaryTransferSendin interfaceBaseConnection- Parameters:
oid- The oid to check.- Returns:
- True for binary transfer, false for text transfer.
-
getBackendPID
public int getBackendPID()
Description copied from interface:PGConnectionReturn the process ID (PID) of the backend server process handling this connection.- Specified by:
getBackendPIDin interfacePGConnection- Returns:
- PID of backend server process.
-
isColumnSanitiserDisabled
public boolean isColumnSanitiserDisabled()
Description copied from interface:BaseConnectionReturn whether to disable column name sanitation.- Specified by:
isColumnSanitiserDisabledin interfaceBaseConnection- Returns:
- true column sanitizer is disabled
-
setDisableColumnSanitiser
public void setDisableColumnSanitiser(boolean disableColumnSanitiser)
-
getPreferQueryMode
public PreferQueryMode getPreferQueryMode()
Description copied from interface: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.
- Specified by:
getPreferQueryModein interfacePGConnection- Returns:
- the preferred query mode
- See Also:
PreferQueryMode
-
getAutosave
public AutoSave getAutosave()
Description copied from interface:PGConnectionConnection configuration regarding automatic per-query savepoints.- Specified by:
getAutosavein interfacePGConnection- Returns:
- connection configuration regarding automatic per-query savepoints
- See Also:
PGProperty.AUTOSAVE
-
setAutosave
public void setAutosave(AutoSave autoSave)
Description copied from interface:PGConnectionConfigures if connection should use automatic savepoints.- Specified by:
setAutosavein interfacePGConnection- Parameters:
autoSave- connection configuration regarding automatic per-query savepoints- See Also:
PGProperty.AUTOSAVE
-
abort
protected void abort()
-
addTimerTask
public void addTimerTask(java.util.TimerTask timerTask, long milliSeconds)Description copied from interface:BaseConnectionSchedule a TimerTask for later execution. The task will be scheduled with the shared Timer for this connection.- Specified by:
addTimerTaskin interfaceBaseConnection- Parameters:
timerTask- timer task to schedulemilliSeconds- delay in milliseconds
-
purgeTimerTasks
public void purgeTimerTasks()
Description copied from interface:BaseConnectionInvoke purge() on the underlying shared Timer so that internal resources will be released.- Specified by:
purgeTimerTasksin interfaceBaseConnection
-
escapeIdentifier
public java.lang.String escapeIdentifier(java.lang.String identifier) throws java.sql.SQLExceptionDescription copied from interface:PGConnectionReturn 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.- Specified by:
escapeIdentifierin interfacePGConnection- Parameters:
identifier- input identifier- Returns:
- the escaped identifier
- Throws:
java.sql.SQLException- if something goes wrong
-
escapeLiteral
public java.lang.String escapeLiteral(java.lang.String literal) throws java.sql.SQLExceptionDescription copied from interface:PGConnectionReturn 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.- Specified by:
escapeLiteralin interfacePGConnection- Parameters:
literal- input literal- Returns:
- the quoted literal
- Throws:
java.sql.SQLException- if something goes wrong
-
getFieldMetadataCache
public LruCache<FieldMetadata.Key,FieldMetadata> getFieldMetadataCache()
Description copied from interface:BaseConnectionReturn metadata cache for given connection.- Specified by:
getFieldMetadataCachein interfaceBaseConnection- Returns:
- metadata cache
-
getReplicationAPI
public PGReplicationConnection getReplicationAPI()
- Specified by:
getReplicationAPIin interfacePGConnection- Returns:
- replication API for the current connection
-
createStatement
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getMetaData
public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLException- Specified by:
getMetaDatain interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setTypeMap
public void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map) throws java.sql.SQLException- Specified by:
setTypeMapin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
makeArray
protected java.sql.Array makeArray(int oid, java.lang.String fieldString) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
makeBlob
protected java.sql.Blob makeBlob(long oid) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
makeClob
protected java.sql.Clob makeClob(long oid) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
makeSQLXML
protected java.sql.SQLXML makeSQLXML() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
createClob
public java.sql.Clob createClob() throws java.sql.SQLException- Specified by:
createClobin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createBlob
public java.sql.Blob createBlob() throws java.sql.SQLException- Specified by:
createBlobin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createNClob
public java.sql.NClob createNClob() throws java.sql.SQLException- Specified by:
createNClobin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createSQLXML
public java.sql.SQLXML createSQLXML() throws java.sql.SQLException- Specified by:
createSQLXMLin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createStruct
public java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes) throws java.sql.SQLException- Specified by:
createStructin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createArrayOf
public java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object elements) throws java.sql.SQLExceptionDescription copied from interface:PGConnectionCreates anArraywrapping elements. This is similar toConnection.createArrayOf(String, Object[]), but also provides support for primitive arrays.- Specified by:
createArrayOfin interfacePGConnection- 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[])
-
createArrayOf
public java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements) throws java.sql.SQLException- Specified by:
createArrayOfin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
isValid
public boolean isValid(int timeout) throws java.sql.SQLException- Specified by:
isValidin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setClientInfo
public void setClientInfo(java.lang.String name, java.lang.String value) throws java.sql.SQLClientInfoException- Specified by:
setClientInfoin interfacejava.sql.Connection- Throws:
java.sql.SQLClientInfoException
-
setClientInfo
public void setClientInfo(java.util.Properties properties) throws java.sql.SQLClientInfoException- Specified by:
setClientInfoin interfacejava.sql.Connection- Throws:
java.sql.SQLClientInfoException
-
getClientInfo
public java.lang.String getClientInfo(java.lang.String name) throws java.sql.SQLException- Specified by:
getClientInfoin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getClientInfo
public java.util.Properties getClientInfo() throws java.sql.SQLException- Specified by:
getClientInfoin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createQueryObject
public <T> T createQueryObject(java.lang.Class<T> ifc) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
getLogServerErrorDetail
public boolean getLogServerErrorDetail()
Description copied from interface:BaseConnectionIndicates if error details from server used in included in logging and exceptions.- Specified by:
getLogServerErrorDetailin interfaceBaseConnection- Returns:
- true if should be included and passed on to other exceptions
-
getConvertBooleanToNumeric
public boolean getConvertBooleanToNumeric()
Description copied from interface:BaseConnectionReturns true if boolean values should be converted to numeric types (1/0).- Specified by:
getConvertBooleanToNumericin interfaceBaseConnection- Returns:
- true if boolean to numeric conversion is enabled
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
unwrapin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
getSchema
public java.lang.String getSchema() throws java.sql.SQLException- Specified by:
getSchemain interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setSchema
public void setSchema(java.lang.String schema) throws java.sql.SQLException- Specified by:
setSchemain interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
abort
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException- Specified by:
abortin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setNetworkTimeout
public void setNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds) throws java.sql.SQLException- Specified by:
setNetworkTimeoutin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getNetworkTimeout
public int getNetworkTimeout() throws java.sql.SQLException- Specified by:
getNetworkTimeoutin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setHoldability
public void setHoldability(int holdability) throws java.sql.SQLException- Specified by:
setHoldabilityin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getHoldability
public int getHoldability() throws java.sql.SQLException- Specified by:
getHoldabilityin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setSavepoint
public java.sql.Savepoint setSavepoint() throws java.sql.SQLException- Specified by:
setSavepointin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setSavepoint
public java.sql.Savepoint setSavepoint(java.lang.String name) throws java.sql.SQLException- Specified by:
setSavepointin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
rollback
public void rollback(java.sql.Savepoint savepoint) throws java.sql.SQLException- Specified by:
rollbackin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
releaseSavepoint
public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLException- Specified by:
releaseSavepointin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createStatement
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws java.sql.SQLException- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getParameterStatuses
public final java.util.Map<java.lang.String,java.lang.String> getParameterStatuses()
Description copied from interface: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 backwards-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 assessors, 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 viaPGConnection.escapeLiteral(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.
- Specified by:
getParameterStatusesin interfacePGConnection- Returns:
- unmodifiable map of case-insensitive parameter names to parameter values
-
-
getParameterStatus
public final java.lang.String getParameterStatus(java.lang.String parameterName)
Description copied from interface:PGConnectionShorthand for getParameterStatuses().get(...) .- Specified by:
getParameterStatusin interfacePGConnection- Parameters:
parameterName- case-insensitive parameter name- Returns:
- parameter value if defined, or null if no parameter known
- See Also:
PGConnection.getParameterStatuses()
-
getAdaptiveFetch
public boolean getAdaptiveFetch()
Description copied from interface:PGConnectionGet state of adaptive fetch for connection.- Specified by:
getAdaptiveFetchin interfacePGConnection- Returns:
- state of adaptive fetch (turned on or off)
-
setAdaptiveFetch
public void setAdaptiveFetch(boolean adaptiveFetch)
Description copied from interface:PGConnectionTurn on/off adaptive fetch for connection. Existing statements and resultSets won't be affected by change here.- Specified by:
setAdaptiveFetchin interfacePGConnection- Parameters:
adaptiveFetch- desired state of adaptive fetch.
-
getXmlFactoryFactory
public PGXmlFactoryFactory getXmlFactoryFactory() throws java.sql.SQLException
Description copied from interface:BaseConnectionRetrieve the factory to instantiate XML processing factories.- Specified by:
getXmlFactoryFactoryin interfaceBaseConnection- Returns:
- The factory to use to instantiate XML processing factories
- Throws:
java.sql.SQLException- if the class cannot be found or instantiated.
-
-