Class QueryExecutorBase
- java.lang.Object
-
- org.postgresql.core.QueryExecutorBase
-
- All Implemented Interfaces:
QueryExecutor,TypeTransferModeRegistry
- Direct Known Subclasses:
QueryExecutorImpl
public abstract class QueryExecutorBase extends java.lang.Object implements QueryExecutor
-
-
Field Summary
Fields Modifier and Type Field Description private AutoSaveautoSaveprivate CachedQueryCreateActioncachedQueryCreateActionprivate intcancelKeyprivate intcancelPidprivate intcancelSignalTimeoutprivate booleanclosedprivate booleancolumnSanitiserDisabledprivate java.lang.Stringdatabaseprivate EscapeSyntaxCallModeescapeSyntaxCallModeprivate booleanflushCacheOnDeallocateprivate static java.util.logging.LoggerLOGGERprotected booleanlogServerErrorDetailprivate java.util.ArrayList<PGNotification>notificationsprivate java.util.TreeMap<java.lang.String,java.lang.String>parameterStatusesprotected PGStreampgStreamprivate PreferQueryModepreferQueryModeprivate booleanreWriteBatchedInsertsprivate java.lang.StringserverVersionprivate intserverVersionNumprivate booleanstandardConformingStringsprivate LruCache<java.lang.Object,CachedQuery>statementCacheprivate TransactionStatetransactionStateprivate java.lang.Stringuserprivate java.sql.SQLWarningwarnings-
Fields inherited from interface org.postgresql.core.QueryExecutor
MAX_SAVE_POINTS, QUERY_BOTH_ROWS_AND_STATUS, QUERY_DESCRIBE_ONLY, QUERY_DISALLOW_BATCHING, QUERY_EXECUTE_AS_SIMPLE, QUERY_FORCE_DESCRIBE_PORTAL, QUERY_FORWARD_CURSOR, QUERY_NO_BINARY_TRANSFER, QUERY_NO_METADATA, QUERY_NO_RESULTS, QUERY_ONESHOT, QUERY_READ_ONLY_HINT, QUERY_SUPPRESS_BEGIN
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedQueryExecutorBase(PGStream pgStream, java.lang.String user, java.lang.String database, int cancelSignalTimeout, java.util.Properties info)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidabort()Abort at network level without sending the Terminate message to the backend.voidaddNotification(PGNotification notification)voidaddWarning(java.sql.SQLWarning newWarning)CachedQueryborrowCallableQuery(java.lang.String sql)CachedQueryborrowQuery(java.lang.String sql)CachedQueryborrowQueryByKey(java.lang.Object key)CachedQueryborrowReturningQuery(java.lang.String sql, java.lang.String[] columnNames)voidclose()Close this connection cleanly.CachedQuerycreateQuery(java.lang.String sql, boolean escapeProcessing, boolean isParameterized, java.lang.String... columnNames)CachedQuerycreateQueryByKey(java.lang.Object key)java.lang.ObjectcreateQueryKey(java.lang.String sql, boolean escapeProcessing, boolean isParameterized, java.lang.String... columnNames)AutoSavegetAutoSave()intgetBackendPID()Return the process ID (PID) of the backend server process handling this connection.java.lang.StringgetDatabase()EncodinggetEncoding()EscapeSyntaxCallModegetEscapeSyntaxCallMode()HostSpecgetHostSpec()intgetNetworkTimeout()PGNotification[]getNotifications()Retrieve and clear the set of asynchronous notifications pending on this connection.java.lang.StringgetParameterStatus(java.lang.String parameterName)java.util.Map<java.lang.String,java.lang.String>getParameterStatuses()PreferQueryModegetPreferQueryMode()java.lang.StringgetServerVersion()Return the server version from the server_version GUC.intgetServerVersionNum()Get a machine-readable server version.booleangetStandardConformingStrings()Returns whether the server treats string-literals according to the SQL standard or if it uses traditional PostgreSQL escaping rules.TransactionStategetTransactionState()Get the current transaction state of this connection.java.lang.StringgetUser()java.sql.SQLWarninggetWarnings()Retrieve and clear the chain of warnings accumulated on this connection.protected booleanhasNotifications()booleanisClosed()Check if this connection is closed.booleanisColumnSanitiserDisabled()booleanisFlushCacheOnDeallocate()booleanisReWriteBatchedInsertsEnabled()protected voidonParameterStatus(java.lang.String parameterName, java.lang.String parameterStatus)Update the parameter status map in response to a new ParameterStatus wire protocol message.voidreleaseQuery(CachedQuery cachedQuery)protected abstract voidsendCloseMessage()voidsendQueryCancel()Sends a query cancellation for this connection.voidsetAutoSave(AutoSave autoSave)voidsetBackendKeyData(int cancelPid, int cancelKey)voidsetEncoding(Encoding encoding)voidsetFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)By default, the connection resets statement cache in case deallocate all/discard all message is observed.voidsetNetworkTimeout(int milliseconds)voidsetServerVersion(java.lang.String serverVersion)voidsetServerVersionNum(int serverVersionNum)voidsetStandardConformingStrings(boolean value)voidsetTransactionState(TransactionState state)booleanwillHealOnRetry(java.sql.SQLException e)protected booleanwillHealViaReparse(java.sql.SQLException e)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.postgresql.core.QueryExecutor
createFastpathParameters, createSimpleQuery, execute, execute, fastpathCall, fetch, getApplicationName, getIntegerDateTimes, getProtocolVersion, getReplicationProtocol, getTimeZone, processNotifies, processNotifies, setBinaryReceiveOids, setBinarySendOids, startCopy, wrap
-
Methods inherited from interface org.postgresql.core.v3.TypeTransferModeRegistry
useBinaryForReceive, useBinaryForSend
-
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
pgStream
protected final PGStream pgStream
-
user
private final java.lang.String user
-
database
private final java.lang.String database
-
cancelSignalTimeout
private final int cancelSignalTimeout
-
cancelPid
private int cancelPid
-
cancelKey
private int cancelKey
-
closed
private boolean closed
-
serverVersion
private java.lang.String serverVersion
-
serverVersionNum
private int serverVersionNum
-
transactionState
private TransactionState transactionState
-
reWriteBatchedInserts
private final boolean reWriteBatchedInserts
-
columnSanitiserDisabled
private final boolean columnSanitiserDisabled
-
escapeSyntaxCallMode
private final EscapeSyntaxCallMode escapeSyntaxCallMode
-
preferQueryMode
private final PreferQueryMode preferQueryMode
-
autoSave
private AutoSave autoSave
-
flushCacheOnDeallocate
private boolean flushCacheOnDeallocate
-
logServerErrorDetail
protected final boolean logServerErrorDetail
-
standardConformingStrings
private boolean standardConformingStrings
-
warnings
private java.sql.SQLWarning warnings
-
notifications
private final java.util.ArrayList<PGNotification> notifications
-
statementCache
private final LruCache<java.lang.Object,CachedQuery> statementCache
-
cachedQueryCreateAction
private final CachedQueryCreateAction cachedQueryCreateAction
-
parameterStatuses
private final java.util.TreeMap<java.lang.String,java.lang.String> parameterStatuses
-
-
Constructor Detail
-
QueryExecutorBase
protected QueryExecutorBase(PGStream pgStream, java.lang.String user, java.lang.String database, int cancelSignalTimeout, java.util.Properties info) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
-
Method Detail
-
sendCloseMessage
protected abstract void sendCloseMessage() throws java.io.IOException- Throws:
java.io.IOException
-
setNetworkTimeout
public void setNetworkTimeout(int milliseconds) throws java.io.IOException- Specified by:
setNetworkTimeoutin interfaceQueryExecutor- Throws:
java.io.IOException
-
getNetworkTimeout
public int getNetworkTimeout() throws java.io.IOException- Specified by:
getNetworkTimeoutin interfaceQueryExecutor- Throws:
java.io.IOException
-
getHostSpec
public HostSpec getHostSpec()
- Specified by:
getHostSpecin interfaceQueryExecutor- Returns:
- the host and port this connection is connected to.
-
getUser
public java.lang.String getUser()
- Specified by:
getUserin interfaceQueryExecutor- Returns:
- the user this connection authenticated as.
-
getDatabase
public java.lang.String getDatabase()
- Specified by:
getDatabasein interfaceQueryExecutor- Returns:
- the database this connection is connected to.
-
setBackendKeyData
public void setBackendKeyData(int cancelPid, int cancelKey)
-
getBackendPID
public int getBackendPID()
Description copied from interface:QueryExecutorReturn the process ID (PID) of the backend server process handling this connection.- Specified by:
getBackendPIDin interfaceQueryExecutor- Returns:
- process ID (PID) of the backend server process handling this connection
-
abort
public void abort()
Description copied from interface:QueryExecutorAbort at network level without sending the Terminate message to the backend.- Specified by:
abortin interfaceQueryExecutor
-
close
public void close()
Description copied from interface:QueryExecutorClose this connection cleanly.- Specified by:
closein interfaceQueryExecutor
-
isClosed
public boolean isClosed()
Description copied from interface:QueryExecutorCheck if this connection is closed.- Specified by:
isClosedin interfaceQueryExecutor- Returns:
- true iff the connection is closed.
-
sendQueryCancel
public void sendQueryCancel() throws java.sql.SQLExceptionDescription copied from interface:QueryExecutorSends a query cancellation for this connection.- Specified by:
sendQueryCancelin interfaceQueryExecutor- Throws:
java.sql.SQLException- if something goes wrong.
-
addWarning
public void addWarning(java.sql.SQLWarning newWarning)
-
addNotification
public void addNotification(PGNotification notification)
-
getNotifications
public PGNotification[] getNotifications() throws java.sql.SQLException
Description copied from interface:QueryExecutorRetrieve and clear the set of asynchronous notifications pending on this connection.- Specified by:
getNotificationsin interfaceQueryExecutor- Returns:
- an array of notifications; if there are no notifications, an empty array is returned.
- Throws:
java.sql.SQLException- if and error occurs while fetching notifications
-
getWarnings
public java.sql.SQLWarning getWarnings()
Description copied from interface:QueryExecutorRetrieve and clear the chain of warnings accumulated on this connection.- Specified by:
getWarningsin interfaceQueryExecutor- Returns:
- the first SQLWarning in the chain; subsequent warnings can be found via SQLWarning.getNextWarning().
-
getServerVersion
public java.lang.String getServerVersion()
Description copied from interface:QueryExecutorReturn the server version from the server_version GUC.
Note that there's no requirement for this to be numeric or of the form x.y.z. PostgreSQL development releases usually have the format x.ydevel e.g. 9.4devel; betas usually x.ybetan e.g. 9.4beta1. The --with-extra-version configure option may add an arbitrary string to this.
Don't use this string for logic, only use it when displaying the server version to the user. Prefer getServerVersionNum() for all logic purposes.
- Specified by:
getServerVersionin interfaceQueryExecutor- Returns:
- the server version string from the server_version guc
-
getServerVersionNum
public int getServerVersionNum()
Description copied from interface:QueryExecutorGet a machine-readable server version.
This returns the value of the server_version_num GUC. If no such GUC exists, it falls back on attempting to parse the text server version for the major version. If there's no minor version (e.g. a devel or beta release) then the minor version is set to zero. If the version could not be parsed, zero is returned.
- Specified by:
getServerVersionNumin interfaceQueryExecutor- Returns:
- the server version in numeric XXYYZZ form, eg 090401, from server_version_num
-
setServerVersion
public void setServerVersion(java.lang.String serverVersion)
-
setServerVersionNum
public void setServerVersionNum(int serverVersionNum)
-
setTransactionState
public void setTransactionState(TransactionState state)
-
setStandardConformingStrings
public void setStandardConformingStrings(boolean value)
-
getStandardConformingStrings
public boolean getStandardConformingStrings()
Description copied from interface:QueryExecutorReturns 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 interfaceQueryExecutor- Returns:
- true if the server treats string literals according to the SQL standard
-
getTransactionState
public TransactionState getTransactionState()
Description copied from interface:QueryExecutorGet the current transaction state of this connection.- Specified by:
getTransactionStatein interfaceQueryExecutor- Returns:
- a ProtocolConnection.TRANSACTION_* constant.
-
setEncoding
public void setEncoding(Encoding encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
getEncoding
public Encoding getEncoding()
- Specified by:
getEncodingin interfaceQueryExecutor- Returns:
- the current encoding in use by this connection
-
isReWriteBatchedInsertsEnabled
public boolean isReWriteBatchedInsertsEnabled()
- Specified by:
isReWriteBatchedInsertsEnabledin interfaceQueryExecutor
-
borrowQuery
public final CachedQuery borrowQuery(java.lang.String sql) throws java.sql.SQLException
- Specified by:
borrowQueryin interfaceQueryExecutor- Throws:
java.sql.SQLException
-
borrowCallableQuery
public final CachedQuery borrowCallableQuery(java.lang.String sql) throws java.sql.SQLException
- Specified by:
borrowCallableQueryin interfaceQueryExecutor- Throws:
java.sql.SQLException
-
borrowReturningQuery
public final CachedQuery borrowReturningQuery(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
- Specified by:
borrowReturningQueryin interfaceQueryExecutor- Throws:
java.sql.SQLException
-
borrowQueryByKey
public CachedQuery borrowQueryByKey(java.lang.Object key) throws java.sql.SQLException
- Specified by:
borrowQueryByKeyin interfaceQueryExecutor- Throws:
java.sql.SQLException
-
releaseQuery
public void releaseQuery(CachedQuery cachedQuery)
- Specified by:
releaseQueryin interfaceQueryExecutor
-
createQueryKey
public final java.lang.Object createQueryKey(java.lang.String sql, boolean escapeProcessing, boolean isParameterized, java.lang.String... columnNames)- Specified by:
createQueryKeyin interfaceQueryExecutor
-
createQueryByKey
public CachedQuery createQueryByKey(java.lang.Object key) throws java.sql.SQLException
- Specified by:
createQueryByKeyin interfaceQueryExecutor- Throws:
java.sql.SQLException
-
createQuery
public final CachedQuery createQuery(java.lang.String sql, boolean escapeProcessing, boolean isParameterized, java.lang.String... columnNames) throws java.sql.SQLException
- Specified by:
createQueryin interfaceQueryExecutor- Throws:
java.sql.SQLException
-
isColumnSanitiserDisabled
public boolean isColumnSanitiserDisabled()
- Specified by:
isColumnSanitiserDisabledin interfaceQueryExecutor
-
getEscapeSyntaxCallMode
public EscapeSyntaxCallMode getEscapeSyntaxCallMode()
- Specified by:
getEscapeSyntaxCallModein interfaceQueryExecutor
-
getPreferQueryMode
public PreferQueryMode getPreferQueryMode()
- Specified by:
getPreferQueryModein interfaceQueryExecutor
-
getAutoSave
public AutoSave getAutoSave()
- Specified by:
getAutoSavein interfaceQueryExecutor
-
setAutoSave
public void setAutoSave(AutoSave autoSave)
- Specified by:
setAutoSavein interfaceQueryExecutor
-
willHealViaReparse
protected boolean willHealViaReparse(java.sql.SQLException e)
-
willHealOnRetry
public boolean willHealOnRetry(java.sql.SQLException e)
- Specified by:
willHealOnRetryin interfaceQueryExecutor
-
isFlushCacheOnDeallocate
public boolean isFlushCacheOnDeallocate()
-
setFlushCacheOnDeallocate
public void setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)
Description copied from interface:QueryExecutorBy 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 interfaceQueryExecutor- Parameters:
flushCacheOnDeallocate- true if statement cache should be reset when "deallocate/discard" message observed
-
hasNotifications
protected boolean hasNotifications()
-
getParameterStatuses
public final java.util.Map<java.lang.String,java.lang.String> getParameterStatuses()
- Specified by:
getParameterStatusesin interfaceQueryExecutor
-
getParameterStatus
public final java.lang.String getParameterStatus(java.lang.String parameterName)
- Specified by:
getParameterStatusin interfaceQueryExecutor
-
onParameterStatus
protected void onParameterStatus(java.lang.String parameterName, java.lang.String parameterStatus)Update the parameter status map in response to a new ParameterStatus wire protocol message.The server sends ParameterStatus messages when GUC_REPORT settings are initially assigned and whenever they change.
A future version may invoke a client-defined listener class at this point, so this should be the only access path.
Keys are case-insensitive and case-preserving.
The server doesn't provide a way to report deletion of a reportable parameter so we don't expose one here.
- Parameters:
parameterName- case-insensitive case-preserving name of parameter to create or updateparameterStatus- new value of parameter- See Also:
PGConnection.getParameterStatuses(),PGConnection.getParameterStatus(java.lang.String)
-
-