com.amazon.redshift.core

## Class QueryExecutorBase

- java.lang.Object
- - com.amazon.redshift.core.QueryExecutorBase

All Implemented Interfaces:
  QueryExecutor, TypeTransferModeRegistry

Direct Known Subclasses:
  QueryExecutorImpl

    public abstract class QueryExecutorBase
    extends Object
    implements QueryExecutor

### Field Summary

Fields
`protected boolean` `datashareEnabled`
`protected boolean` `enableMultiSqlSupport`
`protected boolean` `enableStatementCache`
`protected RedshiftLogger` `logger`
`protected boolean` `logServerErrorDetail`
`protected RedshiftStream` `pgStream`
`protected int` `serverProtocolVersion`

### Fields inherited from interface com.amazon.redshift.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
`protected` `QueryExecutorBase(RedshiftStream pgStream, String user, String database, int cancelSignalTimeout, Properties info, RedshiftLogger logger)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`void` `abort()` Abort at network level without sending the Terminate message to the backend.
`void` `addNotification(RedshiftNotification notification)`
`void` `addWarning(SQLWarning newWarning)`
`CachedQuery` `borrowCallableQuery(String sql)`
`CachedQuery` `borrowQuery(String sql)`
`CachedQuery` `borrowQueryByKey(Object key)`
`CachedQuery` `borrowReturningQuery(String sql, String[] columnNames)`
`void` `close()` Close this connection cleanly.
`void` `closeRingBufferThread(RedshiftRowsBlockingQueue<Tuple> queueRows, Thread ringBufferThread)` Close the last active ring buffer thread.
`void` `closeStatementAndPortal()` Close the statement and portal when statement get closed.
`CachedQuery` `createQuery(String sql, boolean escapeProcessing, boolean isParameterized, String... columnNames)`
`CachedQuery` `createQueryByKey(Object key)`
`Object` `createQueryKey(String sql, boolean escapeProcessing, boolean isParameterized, String... columnNames)`
`AutoSave` `getAutoSave()`
`int` `getBackendPID()` Return the process ID (PID) of the backend server process handling this connection.
`String` `getDatabase()`
`Encoding` `getEncoding()`
`EscapeSyntaxCallMode` `getEscapeSyntaxCallMode()`
`HostSpec` `getHostSpec()`
`int` `getNetworkTimeout()`
`RedshiftNotification[]` `getNotifications()` Retrieve and clear the set of asynchronous notifications pending on this connection.
`String` `getParameterStatus(String parameterName)`
`Map<String,String>` `getParameterStatuses()`
`PreferQueryMode` `getPreferQueryMode()`
`int` `getServerProtocolVersion()` Redshift supports different versions to accomodate new request for optimization for better performance.
`String` `getServerVersion()` Return the server version from the server_version GUC.
`int` `getServerVersionNum()` Get a machine-readable server version.
`boolean` `getStandardConformingStrings()` Returns whether the server treats string-literals according to the SQL standard or if it uses traditional Redshift escaping rules.
`TransactionState` `getTransactionState()` Get the current transaction state of this connection.
`String` `getUser()`
`SQLWarning` `getWarnings()` Retrieve and clear the chain of warnings accumulated on this connection.
`protected boolean` `hasNotifications()`
`boolean` `isClosed()` Check if this connection is closed.
`boolean` `isColumnSanitiserDisabled()`
`boolean` `isDatashareEnabled()` Get the server capability for datashare database query support.
`boolean` `isFlushCacheOnDeallocate()`
`boolean` `isMultiSqlSupport()` Get multiple SQL supports.
`boolean` `isRaiseExceptionOnSilentRollback()`
`boolean` `isReWriteBatchedInsertsEnabled()`
`boolean` `isRingBufferThreadRunning()` Check for a running ring buffer thread.
`protected void` `onParameterStatus(String parameterName, String parameterStatus)` Update the parameter status map in response to a new ParameterStatus wire protocol message.
`void` `releaseQuery(CachedQuery cachedQuery)`
`protected abstract void` `sendCloseMessage()`
`void` `sendQueryCancel()` Sends a query cancellation for this connection.
`void` `setAutoSave(AutoSave autoSave)`
`void` `setBackendKeyData(int cancelPid, int cancelKey)`
`protected void` `setDatashareEnabled(boolean datashareEnabled)`
`void` `setEncoding(Encoding encoding)`
`void` `setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)` By default, the connection resets statement cache in case deallocate all/discard all message is observed.
`void` `setNetworkTimeout(int milliseconds)`
`void` `setRaiseExceptionOnSilentRollback(boolean raiseExceptionOnSilentRollback)`
`protected void` `setServerProtocolVersion(String serverProtocolVersion)`
`void` `setServerVersion(String serverVersion)`
`void` `setServerVersionNum(int serverVersionNum)`
`void` `setStandardConformingStrings(boolean value)`
`void` `setTransactionState(TransactionState state)`
`boolean` `willHealOnRetry(SQLException e)`
`protected boolean` `willHealViaReparse(SQLException e)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface com.amazon.redshift.core.QueryExecutor

`createFastpathParameters, createSimpleQuery, execute, execute, fastpathCall, fetch, getApplicationName, getIntegerDateTimes, getProtocolVersion, getReplicationProtocol, getTimeZone, processNotifies, processNotifies, setBinaryReceiveOids, setBinarySendOids, startCopy, wrap`

### Methods inherited from interface com.amazon.redshift.core.v3.TypeTransferModeRegistry

`useBinaryForReceive, useBinaryForSend`

### Field Detail

#### logger

    protected RedshiftLogger logger

#### pgStream

    protected final RedshiftStream pgStream

#### logServerErrorDetail

    protected final boolean logServerErrorDetail

#### enableStatementCache

    protected boolean enableStatementCache

#### serverProtocolVersion

    protected int serverProtocolVersion

#### datashareEnabled

    protected boolean datashareEnabled

#### enableMultiSqlSupport

    protected boolean enableMultiSqlSupport

### Constructor Detail

#### QueryExecutorBase

    protected QueryExecutorBase(RedshiftStream pgStream,
                                String user,
                                String database,
                                int cancelSignalTimeout,
                                Properties info,
                                RedshiftLogger logger)
                         throws SQLException

Throws:
  `SQLException`

### Method Detail

#### sendCloseMessage

    protected abstract void sendCloseMessage()
                                      throws IOException

Throws:
  `IOException`

#### setNetworkTimeout

    public void setNetworkTimeout(int milliseconds)
                           throws IOException

Specified by:
  `setNetworkTimeout` in interface `QueryExecutor`
Throws:
  `IOException`

#### getNetworkTimeout

    public int getNetworkTimeout()
                          throws IOException

Specified by:
  `getNetworkTimeout` in interface `QueryExecutor`
Throws:
  `IOException`

#### getHostSpec

    public HostSpec getHostSpec()

Specified by:
  `getHostSpec` in interface `QueryExecutor`
Returns:
  the host and port this connection is connected to.

#### getUser

    public String getUser()

Specified by:
  `getUser` in interface `QueryExecutor`
Returns:
  the user this connection authenticated as.

#### getDatabase

    public String getDatabase()

Specified by:
  `getDatabase` in interface `QueryExecutor`
Returns:
  the database this connection is connected to.

#### setBackendKeyData

    public void setBackendKeyData(int cancelPid,
                                  int cancelKey)

#### getBackendPID

    public int getBackendPID()

Description copied from interface: `QueryExecutor`
Return the process ID (PID) of the backend server process handling this connection.

Specified by:
  `getBackendPID` in interface `QueryExecutor`
Returns:
  process ID (PID) of the backend server process handling this connection

#### abort

    public void abort()

Description copied from interface: `QueryExecutor`
Abort at network level without sending the Terminate message to the backend.

Specified by:
  `abort` in interface `QueryExecutor`

#### close

    public void close()

Description copied from interface: `QueryExecutor`
Close this connection cleanly.

Specified by:
  `close` in interface `QueryExecutor`

#### isClosed

    public boolean isClosed()

Description copied from interface: `QueryExecutor`
Check if this connection is closed.

Specified by:
  `isClosed` in interface `QueryExecutor`
Returns:
  true iff the connection is closed.

#### sendQueryCancel

    public void sendQueryCancel()
                         throws SQLException

Description copied from interface: `QueryExecutor`
Sends a query cancellation for this connection.

Specified by:
  `sendQueryCancel` in interface `QueryExecutor`
Throws:
  `SQLException` - if something goes wrong.

#### addWarning

    public void addWarning(SQLWarning newWarning)

#### addNotification

    public void addNotification(RedshiftNotification notification)

#### getNotifications

    public RedshiftNotification[] getNotifications()
                                            throws SQLException

Description copied from interface: `QueryExecutor`
Retrieve and clear the set of asynchronous notifications pending on this connection.

Specified by:
  `getNotifications` in interface `QueryExecutor`
Returns:
  an array of notifications; if there are no notifications, an empty array is returned.
Throws:
  `SQLException` - if and error occurs while fetching notifications

#### getWarnings

    public SQLWarning getWarnings()

Description copied from interface: `QueryExecutor`
Retrieve and clear the chain of warnings accumulated on this connection.

Specified by:
  `getWarnings` in interface `QueryExecutor`
Returns:
  the first SQLWarning in the chain; subsequent warnings can be found via SQLWarning.getNextWarning().

#### getServerVersion

    public String getServerVersion()

Description copied from interface: `QueryExecutor`

Return 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. Redshift 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:
  `getServerVersion` in interface `QueryExecutor`
Returns:
  the server version string from the server_version guc

#### getServerProtocolVersion

    public int getServerProtocolVersion()

Description copied from interface: `QueryExecutor`
Redshift supports different versions to accomodate new request for optimization for better performance. 0 means base protocol version 1 means extended resultset metadata protocol version

Specified by:
  `getServerProtocolVersion` in interface `QueryExecutor`
Returns:
  the server protocol version.

#### isDatashareEnabled

    public boolean isDatashareEnabled()

Description copied from interface: `QueryExecutor`
Get the server capability for datashare database query support. This should enable for data sharing (either producer/consumer).

Specified by:
  `isDatashareEnabled` in interface `QueryExecutor`
Returns:
  true means datashare database query is supported otherwise false.

#### getServerVersionNum

    public int getServerVersionNum()

Description copied from interface: `QueryExecutor`

Get 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:
  `getServerVersionNum` in interface `QueryExecutor`
Returns:
  the server version in numeric XXYYZZ form, eg 090401, from server_version_num

#### setServerVersion

    public void setServerVersion(String serverVersion)

#### setServerProtocolVersion

    protected void setServerProtocolVersion(String serverProtocolVersion)

#### setDatashareEnabled

    protected void setDatashareEnabled(boolean datashareEnabled)

#### 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: `QueryExecutor`
Returns whether the server treats string-literals according to the SQL standard or if it uses traditional Redshift 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 the `standard_conforming_strings` server variable.

Specified by:
  `getStandardConformingStrings` in interface `QueryExecutor`
Returns:
  true if the server treats string literals according to the SQL standard

#### getTransactionState

    public TransactionState getTransactionState()

Description copied from interface: `QueryExecutor`
Get the current transaction state of this connection.

Specified by:
  `getTransactionState` in interface `QueryExecutor`
Returns:
  a ProtocolConnection.TRANSACTION_* constant.

#### setEncoding

    public void setEncoding(Encoding encoding)
                     throws IOException

Throws:
  `IOException`

#### getEncoding

    public Encoding getEncoding()

Specified by:
  `getEncoding` in interface `QueryExecutor`
Returns:
  the current encoding in use by this connection

#### isReWriteBatchedInsertsEnabled

    public boolean isReWriteBatchedInsertsEnabled()

Specified by:
  `isReWriteBatchedInsertsEnabled` in interface `QueryExecutor`

#### isMultiSqlSupport

    public boolean isMultiSqlSupport()

Description copied from interface: `QueryExecutor`
Get multiple SQL supports.

Specified by:
  `isMultiSqlSupport` in interface `QueryExecutor`
Returns:
  true, if supported. false otherwise.

#### borrowQuery

    public final CachedQuery borrowQuery(String sql)
                                  throws SQLException

Specified by:
  `borrowQuery` in interface `QueryExecutor`
Throws:
  `SQLException`

#### borrowCallableQuery

    public final CachedQuery borrowCallableQuery(String sql)
                                          throws SQLException

Specified by:
  `borrowCallableQuery` in interface `QueryExecutor`
Throws:
  `SQLException`

#### borrowReturningQuery

    public final CachedQuery borrowReturningQuery(String sql,
                                                  String[] columnNames)
                                           throws SQLException

Specified by:
  `borrowReturningQuery` in interface `QueryExecutor`
Throws:
  `SQLException`

#### borrowQueryByKey

    public CachedQuery borrowQueryByKey(Object key)
                                 throws SQLException

Specified by:
  `borrowQueryByKey` in interface `QueryExecutor`
Throws:
  `SQLException`

#### releaseQuery

    public void releaseQuery(CachedQuery cachedQuery)

Specified by:
  `releaseQuery` in interface `QueryExecutor`

#### createQueryKey

    public final Object createQueryKey(String sql,
                                       boolean escapeProcessing,
                                       boolean isParameterized,
                                       String... columnNames)

Specified by:
  `createQueryKey` in interface `QueryExecutor`

#### createQueryByKey

    public CachedQuery createQueryByKey(Object key)
                                 throws SQLException

Specified by:
  `createQueryByKey` in interface `QueryExecutor`
Throws:
  `SQLException`

#### createQuery

    public final CachedQuery createQuery(String sql,
                                         boolean escapeProcessing,
                                         boolean isParameterized,
                                         String... columnNames)
                                  throws SQLException

Specified by:
  `createQuery` in interface `QueryExecutor`
Throws:
  `SQLException`

#### isColumnSanitiserDisabled

    public boolean isColumnSanitiserDisabled()

Specified by:
  `isColumnSanitiserDisabled` in interface `QueryExecutor`

#### getEscapeSyntaxCallMode

    public EscapeSyntaxCallMode getEscapeSyntaxCallMode()

Specified by:
  `getEscapeSyntaxCallMode` in interface `QueryExecutor`

#### getPreferQueryMode

    public PreferQueryMode getPreferQueryMode()

Specified by:
  `getPreferQueryMode` in interface `QueryExecutor`

#### getAutoSave

    public AutoSave getAutoSave()

Specified by:
  `getAutoSave` in interface `QueryExecutor`

#### setAutoSave

    public void setAutoSave(AutoSave autoSave)

Specified by:
  `setAutoSave` in interface `QueryExecutor`

#### willHealViaReparse

    protected boolean willHealViaReparse(SQLException e)

#### willHealOnRetry

    public boolean willHealOnRetry(SQLException e)

Specified by:
  `willHealOnRetry` in interface `QueryExecutor`

#### isFlushCacheOnDeallocate

    public boolean isFlushCacheOnDeallocate()

#### setFlushCacheOnDeallocate

    public void setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)

Description copied from interface: `QueryExecutor`
By 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:
  `setFlushCacheOnDeallocate` in interface `QueryExecutor`
Parameters:
  `flushCacheOnDeallocate` - true if statement cache should be reset when "deallocate/discard" message observed

#### isRaiseExceptionOnSilentRollback

    public boolean isRaiseExceptionOnSilentRollback()

Specified by:
  `isRaiseExceptionOnSilentRollback` in interface `QueryExecutor`

#### setRaiseExceptionOnSilentRollback

    public void setRaiseExceptionOnSilentRollback(boolean raiseExceptionOnSilentRollback)

Specified by:
  `setRaiseExceptionOnSilentRollback` in interface `QueryExecutor`

#### hasNotifications

    protected boolean hasNotifications()

#### getParameterStatuses

    public final Map<String,String> getParameterStatuses()

Specified by:
  `getParameterStatuses` in interface `QueryExecutor`

#### getParameterStatus

    public final String getParameterStatus(String parameterName)

Specified by:
  `getParameterStatus` in interface `QueryExecutor`

#### onParameterStatus

    protected void onParameterStatus(String parameterName,
                                     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 update
  `parameterStatus` - new value of parameter
See Also:
  `RedshiftConnection.getParameterStatuses()`, `RedshiftConnection.getParameterStatus(java.lang.String)`

#### closeRingBufferThread

    public void closeRingBufferThread(RedshiftRowsBlockingQueue<Tuple> queueRows,
                                      Thread ringBufferThread)

Close the last active ring buffer thread.

Specified by:
  `closeRingBufferThread` in interface `QueryExecutor`
Parameters:
  `queueRows` - the blocking queue rows
  `ringBufferThread` - the thread fetching rows in the blocking queue.

#### isRingBufferThreadRunning

    public boolean isRingBufferThreadRunning()

Check for a running ring buffer thread.

Specified by:
  `isRingBufferThreadRunning` in interface `QueryExecutor`
Returns:
  returns true if Ring buffer thread is running, otherwise false.

#### closeStatementAndPortal

    public void closeStatementAndPortal()

Description copied from interface: `QueryExecutor`
Close the statement and portal when statement get closed.

Specified by:
  `closeStatementAndPortal` in interface `QueryExecutor`