Package org.postgresql.core.v3
Class SimpleQuery
java.lang.Object
org.postgresql.core.v3.SimpleQuery
- All Implemented Interfaces:
Query
- Direct Known Subclasses:
BatchedQuery
V3 Query implementation for a single-statement query. This also holds the state of any associated
server-side named statement. We use a PhantomReference managed by the QueryExecutor to handle
statement cleanup.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Integer
private PhantomReference<?>
private short
private byte[]
private Field[]
The stored fields from previous execution or describe of a prepared statement.private boolean
private static final Logger
private final NativeQuery
private boolean
(package private) static final SimpleParameterList
private boolean
private int[]
private final boolean
private boolean
private String
private final TypeTransferModeRegistry
private BitSet
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleQuery
(NativeQuery query, TypeTransferModeRegistry transferModeRegistry, boolean sanitiserDisabled) SimpleQuery
(SimpleQuery src) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this query and free any server-side resources associated with it.Create a ParameterList suitable for storing parameters associated with this Query.int
Get the number of times this Query has been batched.final int
(package private) byte[]
(package private) Field[]
Returns the fields that this query will return.int
Return maximum size in bytes that each result row from this query may return.(package private) NativeQuery
Returns SQL in native for database format.(package private) int[]
Get a map that a result set can use to find the index associated to a name.Returns properties of the query (sql keyword, and some other parsing info).(package private) String
Return a list of the Query objects that make up this query.boolean
(package private) boolean
boolean
isEmpty()
(package private) boolean
(package private) boolean
isPreparedFor
(int[] paramTypes, short deallocateEpoch) boolean
(package private) boolean
Returns true if current query needs field formats be adjusted as per connection configuration.void
(package private) void
setCleanupRef
(PhantomReference<?> cleanupRef) (package private) void
Sets the fields that this query will return.void
setHasBinaryFields
(boolean hasBinaryFields) (package private) void
setPortalDescribed
(boolean portalDescribed) (package private) void
setPrepareTypes
(int[] paramTypes) (package private) void
setStatementDescribed
(boolean statementDescribed) (package private) void
setStatementName
(String statementName, short deallocateEpoch) toString()
toString
(ParameterList parameters) Stringize this query to a human-readable form, substituting particular parameter values for parameter placeholders.(package private) void
-
Field Details
-
LOGGER
-
resultSetColumnNameIndexMap
-
nativeQuery
-
transferModeRegistry
-
statementName
-
encodedStatementName
private byte[] encodedStatementName -
fields
The stored fields from previous execution or describe of a prepared statement. Always null for non-prepared statements. -
needUpdateFieldFormats
private boolean needUpdateFieldFormats -
hasBinaryFields
private boolean hasBinaryFields -
portalDescribed
private boolean portalDescribed -
statementDescribed
private boolean statementDescribed -
sanitiserDisabled
private final boolean sanitiserDisabled -
cleanupRef
-
preparedTypes
private int[] preparedTypes -
unspecifiedParams
-
deallocateEpoch
private short deallocateEpoch -
cachedMaxResultRowSize
-
NO_PARAMETERS
-
-
Constructor Details
-
SimpleQuery
SimpleQuery(SimpleQuery src) -
SimpleQuery
SimpleQuery(NativeQuery query, TypeTransferModeRegistry transferModeRegistry, boolean sanitiserDisabled)
-
-
Method Details
-
createParameterList
Description copied from interface:Query
Create a ParameterList suitable for storing parameters associated with this Query.
If this query has no parameters, a ParameterList will be returned, but it may be a shared immutable object. If this query does have parameters, the returned ParameterList is a new list, unshared by other callers.
- Specified by:
createParameterList
in interfaceQuery
- Returns:
- a suitable ParameterList instance for this query
-
toString
Description copied from interface:Query
Stringize this query to a human-readable form, substituting particular parameter values for parameter placeholders.- Specified by:
toString
in interfaceQuery
- Parameters:
parameters
- a ParameterList returned by this Query'sQuery.createParameterList()
method, ornull
to leave the parameter placeholders unsubstituted.- Returns:
- a human-readable representation of this query
-
toString
-
close
public void close()Description copied from interface:Query
Close this query and free any server-side resources associated with it. The resources may not be immediately deallocated, but closing a Query may make the deallocation more prompt.
A closed Query should not be executed.
-
getSubqueries
Description copied from interface:Query
Return a list of the Query objects that make up this query. If this object is already a SimpleQuery, returns null (avoids an extra array construction in the common case).- Specified by:
getSubqueries
in interfaceQuery
- Returns:
- an array of single-statement queries, or
null
if this object is already a single-statement query.
-
getMaxResultRowSize
public int getMaxResultRowSize()Return maximum size in bytes that each result row from this query may return. Mainly used for batches that return results.
Results are cached until/unless the query is re-described.
- Returns:
- Max size of result data in bytes according to returned fields, 0 if no results, -1 if result is unbounded.
- Throws:
IllegalStateException
- if the query is not described
-
getNativeSql
Description copied from interface:Query
Returns SQL in native for database format.- Specified by:
getNativeSql
in interfaceQuery
- Returns:
- SQL in native for database format
-
setStatementName
-
setPrepareTypes
void setPrepareTypes(int[] paramTypes) -
getPrepareTypes
int[] getPrepareTypes() -
getStatementName
String getStatementName() -
isPreparedFor
boolean isPreparedFor(int[] paramTypes, short deallocateEpoch) -
hasUnresolvedTypes
boolean hasUnresolvedTypes() -
getEncodedStatementName
byte[] getEncodedStatementName() -
setFields
Sets the fields that this query will return.- Parameters:
fields
- The fields that this query will return.
-
getFields
Field[] getFields()Returns the fields that this query will return. If the result set fields are not known returns null.- Returns:
- the fields that this query will return.
-
needUpdateFieldFormats
boolean needUpdateFieldFormats()Returns true if current query needs field formats be adjusted as per connection configuration. Subsequent invocations would returnfalse
. The idea is to perform adjustments only once, not for eachQueryExecutorImpl.sendBind(SimpleQuery, SimpleParameterList, Portal, boolean)
.- Returns:
- true if current query needs field formats be adjusted as per connection configuration
-
resetNeedUpdateFieldFormats
public void resetNeedUpdateFieldFormats() -
hasBinaryFields
public boolean hasBinaryFields() -
setHasBinaryFields
public void setHasBinaryFields(boolean hasBinaryFields) -
isPortalDescribed
boolean isPortalDescribed() -
setPortalDescribed
void setPortalDescribed(boolean portalDescribed) -
isStatementDescribed
public boolean isStatementDescribed()- Specified by:
isStatementDescribed
in interfaceQuery
-
setStatementDescribed
void setStatementDescribed(boolean statementDescribed) -
isEmpty
public boolean isEmpty() -
setCleanupRef
-
unprepare
void unprepare() -
getBatchSize
public int getBatchSize()Description copied from interface:Query
Get the number of times this Query has been batched.- Specified by:
getBatchSize
in interfaceQuery
- Returns:
- number of times
addBatch()
has been called.
-
getNativeQuery
NativeQuery getNativeQuery() -
getBindCount
public final int getBindCount() -
getResultSetColumnNameIndexMap
Description copied from interface:Query
Get a map that a result set can use to find the index associated to a name.- Specified by:
getResultSetColumnNameIndexMap
in interfaceQuery
- Returns:
- null if the query implementation does not support this method.
-
getSqlCommand
Description copied from interface:Query
Returns properties of the query (sql keyword, and some other parsing info).- Specified by:
getSqlCommand
in interfaceQuery
- Returns:
- returns properties of the query (sql keyword, and some other parsing info) or null if not applicable
-