Top Description Fields Constructors Methods
org.postgresql.core.v3

public Class QueryExecutorImpl

extends QueryExecutorBase
Class Inheritance
Static Imports
org.postgresql.util.internal.Nullness.castNonNull

QueryExecutor implementation for the V3 protocol.

Field Summary

Modifier and TypeField and Description
private final AdaptiveFetchCache
private final boolean
private @Nullable String
applicationName

application_name connection property.

private final SimpleQuery
private final SimpleQuery
private final SimpleQuery
private final boolean
private final CommandCompleteParser
commandCompleteParser

CommandComplete(B) messages are quite common, so we reuse instance to parse those

private short
private final SimpleQuery
private int
estimatedReceiveBufferBytes

The estimated server response size since we last consumed the input stream from the server, in bytes.

private boolean
integerDateTimes

True if server uses integers for date and time fields.

private @Nullable String
lastSetSearchPathQuery

This caches the latest observed set search_path query so the reset of prepared statement cache can be skipped if using repeated calls for the same set search_path value.

private @Nullable Object
lockedFor

Supplement to synchronization of public methods on current QueryExecutor.

private static final Logger
private static final int
private long
private static final Field[]
private static final int
private final ReferenceQueue<Portal>
private final HashMap<PhantomReference<Portal>, String>
private final ReferenceQueue<SimpleQuery>
private final HashMap<PhantomReference<SimpleQuery>, String>
private final Deque<Portal>
private final Deque<SimpleQuery>
private final Deque<DescribeRequest>
private final Deque<ExecuteRequest>
private final Deque<SimpleQuery>
pack-priv AtomicBoolean
private final SimpleQuery
private final ReplicationProtocol
private final SimpleQuery
private final SimpleQuery
sync

This is a fake query object so processResults can distinguish "ReadyForQuery" messages from Sync messages vs from simple execute (aka 'Q').

private @Nullable TimeZone
timeZone

TimeZone of the current connection (TimeZone backend parameter).

private @Nullable SQLException
transactionFailCause

The exception that caused the last transaction to fail.

private static final Portal
private final Set<Integer>
useBinaryReceiveForOids

Bit set that has a bit set for each oid which should be received using binary format.

private final Set<Integer>
useBinarySendForOids

Bit set that has a bit set for each oid which should be sent using binary format.

Inherited from org.postgresql.core.QueryExecutorBase:
closeActionlocklockConditionlogServerErrorDetailpgStream

Constructor Summary

AccessConstructor and Description
public
QueryExecutorImpl(PGStream pgStream, int cancelSignalTimeout, Properties info)

Method Summary

Modifier and TypeMethod and Description
public void
addBinaryReceiveOid(int
The oid to request with binary encoding.
oid
)

Implements org.postgresql.core.QueryExecutor.addBinaryReceiveOid.

Adds a single oid that should be received using binary encoding.

public void
addBinarySendOid(int
The oid to send with binary encoding.
oid
)

Implements org.postgresql.core.QueryExecutor.addBinarySendOid.

Adds a single oid that should be sent using binary encoding.

public void
addQueryToAdaptiveFetchCache(boolean
state of adaptive fetch used during adding query
adaptiveFetch
,
ResultCursor
Cursor used by resultSet, containing query, have to be able to cast to Portal class.
cursor
)

Implements org.postgresql.core.QueryExecutor.addQueryToAdaptiveFetchCache.

Add query to adaptive fetch cache inside QueryExecutor.

public void
cancelCopy(CopyOperationImpl
the copy operation presumably currently holding lock on this connection
op
)

Finishes a copy operation and unlocks connection discarding any exchanged data.

public ParameterList
createFastpathParameters(int
the number of parameters the fastpath call will take
count
)

Implements org.postgresql.core.QueryExecutor.createFastpathParameters.

Create a new ParameterList implementation suitable for invoking a fastpath function via fastpathCall.

public Query
createSimpleQuery(String
the SQL for the query to create
sql
)

Implements org.postgresql.core.QueryExecutor.createSimpleQuery.

Create an unparameterized Query object suitable for execution by this QueryExecutor.

public void
public long

Returns:

number of rows updated for server versions 8.2 or newer
endCopy
(CopyOperationImpl
the copy operation presumably currently holding lock on this connection
op
)

Finishes writing to copy and unlocks connection.

public void
execute(Query query, @Nullable ParameterList parameters, ResultHandler handler, int maxRows, int fetchSize, int flags)

public void
execute(Query query, @Nullable ParameterList parameters, ResultHandler handler, int maxRows, int fetchSize, int flags, boolean adaptiveFetch)

public void
execute(Query[] queries, @Nullable ParameterList[] parameterLists, BatchResultHandler batchHandler, int maxRows, int fetchSize, int flags)

public void
execute(Query[] queries, @Nullable ParameterList[] parameterLists, BatchResultHandler batchHandler, int maxRows, int fetchSize, int flags, boolean adaptiveFetch)

public @Nullable byte[]
fastpathCall(int
the OID of the backend function to invoke
fnid
,
ParameterList
a ParameterList returned from createFastpathParameters containing the parameters to pass to the backend function
parameters
,
boolean
if begin should be suppressed
suppressBegin
)

Implements org.postgresql.core.QueryExecutor.fastpathCall.

Invoke a backend function via the fastpath interface.

public void
fetch(ResultCursor
the cursor to fetch from
cursor
,
ResultHandler
the handler to feed results to
handler
,
int
the preferred number of rows to retrieve before suspending
fetchSize
,
boolean
state of adaptiveFetch to use during fetching
adaptiveFetch
)

Implements org.postgresql.core.QueryExecutor.fetch.

Fetch additional rows from a cursor.

public void
private void
flushIfDeadlockRisk(Query query, boolean disallowBatching, ResultHandler resultHandler, @Nullable BatchResultHandler batchHandler, final int flags)

public boolean
getAdaptiveFetch()

Implements org.postgresql.core.QueryExecutor.getAdaptiveFetch.

Get state of adaptive fetch inside QueryExecutor.

public int
getAdaptiveFetchSize(boolean
state of adaptive fetch, which should be used during retrieving
adaptiveFetch
,
ResultCursor
Cursor used by resultSet, containing query, have to be able to cast to Portal class.
cursor
)

Implements org.postgresql.core.QueryExecutor.getAdaptiveFetchSize.

Get fetch size computed by adaptive fetch size for given query.

public String
getApplicationName()

Implements org.postgresql.core.QueryExecutor.getApplicationName.

Returns application_name connection property.

public Set<? extends Integer>
getBinaryReceiveOids()

Implements org.postgresql.core.QueryExecutor.getBinaryReceiveOids.

Gets the oids that should be received using binary encoding.

public Set<? extends Integer>
getBinarySendOids()

Implements org.postgresql.core.QueryExecutor.getBinarySendOids.

Gets the oids that should be sent using binary encoding.

public boolean
getIntegerDateTimes()

Implements org.postgresql.core.QueryExecutor.getIntegerDateTimes.

Returns true if server uses integer instead of double for binary date and time encodings.

public int
public ReplicationProtocol
public @Nullable TimeZone
getTimeZone()

Implements org.postgresql.core.QueryExecutor.getTimeZone.

Returns backend timezone in java format.

private boolean

Returns:

whether given object actually holds the lock
hasLock
(@Nullable Object
object assumed to hold the lock
holder
)

pack-priv boolean

Returns:

whether given object actually holds the lock
hasLockOn
(@Nullable Object
object assumed to hold the lock
holder
)

private void
initCopy(CopyOperationImpl
an uninitialized CopyOperation
op
)

Locks connection and calls initializer for a new CopyOperation Called via startCopy -> processCopyResults.

private void
private void
lock(Object
object that gets the lock. Normally current thread.
obtainer
)

Obtain lock over this connection for given object, blocking to wait if necessary.

pack-priv @Nullable CopyOperationImpl

Returns:

CopyIn when COPY FROM STDIN starts; CopyOut when COPY TO STDOUT starts; null when copy ends; otherwise, the operation given as parameter.
processCopyResults
(@Nullable CopyOperationImpl op, boolean
whether to block waiting for input
block
)

Handles copy sub protocol responses from server.

private void
private void
public void
processNotifies()

Implements org.postgresql.core.QueryExecutor.processNotifies.

Prior to attempting to retrieve notifications, we need to pull any recently received notifications off of the network buffers.

public void
processNotifies(int
when > 0, block for this time when =0, block forever when < 0, don't block
timeoutMillis
)

Implements org.postgresql.core.QueryExecutor.processNotifies.

Prior to attempting to retrieve notifications, we need to pull any recently received notifications off of the network buffers.

protected void
processResults(ResultHandler handler, int flags)

protected void
processResults(ResultHandler handler, int flags, boolean adaptiveFetch)

pack-priv void
readFromCopy(CopyOperationImpl
the copy operation presumably currently holding lock on this connection
op
,
boolean
whether to block waiting for input
block
)

Wait for a row of data to be received from server on an active copy operation Connection gets unlocked by processCopyResults() at end of operation.

public void
private void
private String
private SQLException
private @Nullable byte[]
private Field[]
private SQLWarning
public void
private void
private void
private void
registerParsedQuery(SimpleQuery query, String statementName)

private void
releaseSavePoint(boolean autosave, int flags)

public void
removeBinaryReceiveOid(int
The oid to request with binary encoding.
oid
)

Implements org.postgresql.core.QueryExecutor.removeBinaryReceiveOid.

Remove given oid from the list of oids for binary receive encoding.

public void
removeBinarySendOid(int
The oid to send with binary encoding.
oid
)

Implements org.postgresql.core.QueryExecutor.removeBinarySendOid.

Remove given oid from the list of oids for binary send encoding.

public void
removeQueryFromAdaptiveFetchCache(boolean
state of adaptive fetch used during removing query
adaptiveFetch
,
ResultCursor
Cursor used by resultSet, containing query, have to be able to cast to Portal class.
cursor
)

Implements org.postgresql.core.QueryExecutor.removeQueryFromAdaptiveFetchCache.

Remove query from adaptive fetch cache inside QueryExecutor

private void
rollbackIfRequired(boolean autosave, SQLException e)

private boolean
sendAutomaticSavepoint(Query query, int flags)

private void
sendBind(SimpleQuery query, SimpleParameterList params, @Nullable Portal portal, boolean noBinaryTransfer)

protected void
sendCloseMessage()

Implements abstract org.postgresql.core.QueryExecutorBase.sendCloseMessage.

Sends "terminate connection" message to the backend.

private void
sendClosePortal(String portalName)

private void
sendCloseStatement(String statementName)

private void
private void
sendDescribeStatement(SimpleQuery query, SimpleParameterList params, boolean describeOnly)

private void
sendExecute(SimpleQuery query, @Nullable Portal portal, int limit)

private void
private void
sendOneQuery(SimpleQuery query, SimpleParameterList params, int maxRows, int fetchSize, int flags)

private void
sendParse(SimpleQuery query, SimpleParameterList params, boolean oneShot)

private void
sendQuery(Query query, V3ParameterList parameters, int maxRows, int fetchSize, int flags, ResultHandler resultHandler, @Nullable BatchResultHandler batchHandler, boolean adaptiveFetch)

private ResultHandler
sendQueryPreamble(final ResultHandler delegateHandler, int flags)

private void
private void
public void
setAdaptiveFetch(boolean
desired state of adaptive fetch
adaptiveFetch
)

Implements org.postgresql.core.QueryExecutor.setAdaptiveFetch.

Set state of adaptive fetch inside QueryExecutor.

public void
setApplicationName(String applicationName)

public void
setBinaryReceiveOids(Set<Integer>
The oids to request with binary encoding.
oids
)

Implements org.postgresql.core.QueryExecutor.setBinaryReceiveOids.

Sets the oids that should be received using binary encoding.

public void
setBinarySendOids(Set<Integer>
The oids to send with binary encoding.
oids
)

Implements org.postgresql.core.QueryExecutor.setBinarySendOids.

Sets the oids that should be sent using binary encoding.

private void
setIntegerDateTimes(boolean state)

private void
setSocketTimeout(int millis)

public void
private void
skipMessage()

Ignore the response message by reading the message length and skipping over those bytes in the communication stream.

public CopyOperation

Returns:

CopyIn or CopyOut operation object
startCopy
(String
COPY FROM STDIN / COPY TO STDOUT statement
sql
,
boolean
if begin should be suppressed
suppressBegin
)

Implements org.postgresql.core.QueryExecutor.startCopy.

Sends given query to BE to start, initialize and lock connection for a CopyOperation.

private void
unlock(Object
object that holds the lock. Normally current thread.
holder
)

Release lock on this connection presumably held by given object.

private int
updateQueryMode(int flags)

private boolean

Returns:

True if Field#BINARY_FORMAT should be used, false if Field#BINARY_FORMAT.
useBinary
(Field
The field whose Oid type to analyse.
field
)

Returns true if the specified field should be retrieved using binary encoding.

public boolean
useBinaryForReceive(int
type oid
oid
)

Implements org.postgresql.core.v3.TypeTransferModeRegistry.useBinaryForReceive.

Returns if given oid should be received in binary format.

public boolean
useBinaryForSend(int
type oid
oid
)

Implements org.postgresql.core.v3.TypeTransferModeRegistry.useBinaryForSend.

Returns if given oid should be sent in binary format.

private void
waitOnLock()

Wait until our lock is released.

public Query
wrap(List<NativeQuery>
list of queries in native to database syntax
queries
)

Implements org.postgresql.core.QueryExecutor.wrap.

Wrap given native query into a ready for execution format.

public void
writeToCopy(CopyOperationImpl
the CopyIn operation presumably currently holding lock on this connection
op
,
byte[]
bytes to send
data
,
int
index of first byte to send (usually 0)
off
,
int
number of bytes to send (usually data.length)
siz
)

Sends data during a live COPY IN operation.

public void
writeToCopy(CopyOperationImpl
the CopyIn operation presumably currently holding lock on this connection
op
,
ByteStreamWriter
the source of bytes, e.g. a ByteBufferByteStreamWriter
from
)

Sends data during a live COPY IN operation.

Inherited from org.postgresql.core.QueryExecutorBase:
abortaddNotificationaddWarningborrowCallableQueryborrowQueryborrowQueryByKeyborrowReturningQueryclosecreateCloseActioncreateQuerycreateQueryByKeycreateQueryKeygetAutoSavegetBackendPIDgetCloseActiongetDatabasegetEncodinggetEscapeSyntaxCallModegetHostSpecgetNetworkTimeoutgetNotificationsgetParameterStatusgetParameterStatusesgetPreferQueryModegetQuoteReturningIdentifiersgetServerVersiongetServerVersionNumgetStandardConformingStringsgetTransactionStategetUsergetWarningshasNotificationsisClosedisColumnSanitiserDisabledisFlushCacheOnDeallocateisReWriteBatchedInsertsEnabledonParameterStatusreleaseQuerysendQueryCancelsetAutoSavesetBackendKeyDatasetEncodingsetFlushCacheOnDeallocatesetNetworkTimeoutsetPreferQueryModesetServerVersionsetServerVersionNumsetStandardConformingStringssetTransactionStatewillHealOnRetrywillHealViaReparse