Class SimpleQuery

  • All Implemented Interfaces:
    Query
    Direct Known Subclasses:
    BatchedQuery

    class SimpleQuery
    extends java.lang.Object
    implements Query
    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 Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • resultSetColumnNameIndexMap

        private java.util.Map<java.lang.String,​java.lang.Integer> resultSetColumnNameIndexMap
      • statementName

        private java.lang.String statementName
      • encodedStatementName

        private byte[] encodedStatementName
      • fields

        private Field[] 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

        private java.lang.ref.PhantomReference<?> cleanupRef
      • preparedTypes

        private int[] preparedTypes
      • unspecifiedParams

        private java.util.BitSet unspecifiedParams
      • deallocateEpoch

        private short deallocateEpoch
      • cachedMaxResultRowSize

        private java.lang.Integer cachedMaxResultRowSize
    • Method Detail

      • createParameterList

        public ParameterList 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 interface Query
        Returns:
        a suitable ParameterList instance for this query
      • toString

        public java.lang.String toString​(ParameterList parameters)
        Description copied from interface: Query
        Returns string representation of the query, substituting particular parameter values for parameter placeholders.

        Note: the method replaces the values on a best-effort basis as it might omit the replacements for parameters that can't be processed several times. For instance, InputStream can be processed only once.

        Specified by:
        toString in interface Query
        Parameters:
        parameters - a ParameterList returned by this Query's Query.createParameterList() method, or null to leave the parameter placeholders unsubstituted.
        Returns:
        string representation of this query
      • toString

        public java.lang.String toString​(ParameterList parameters,
                                         SqlSerializationContext context)
        Description copied from interface: Query
        Returns string representation of the query, substituting particular parameter values for parameter placeholders.
        Specified by:
        toString in interface Query
        Parameters:
        parameters - a ParameterList returned by this Query's Query.createParameterList() method, or null to leave the parameter placeholders unsubstituted.
        context - specifies configuration for converting the parameters to string
        Returns:
        string representation of this query
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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.

        Specified by:
        close in interface Query
      • getSubqueries

        public SimpleQuery[] 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 interface Query
        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:
        java.lang.IllegalStateException - if the query is not described
      • getNativeSql

        public java.lang.String getNativeSql()
        Description copied from interface: Query
        Returns SQL in native for database format.
        Specified by:
        getNativeSql in interface Query
        Returns:
        SQL in native for database format
      • setStatementName

        void setStatementName​(java.lang.String statementName,
                              short deallocateEpoch)
      • setPrepareTypes

        void setPrepareTypes​(int[] paramTypes)
      • getPrepareTypes

        int[] getPrepareTypes()
      • getStatementName

        java.lang.String getStatementName()
      • isPreparedFor

        boolean isPreparedFor​(int[] paramTypes,
                              short deallocateEpoch)
      • hasUnresolvedTypes

        boolean hasUnresolvedTypes()
      • getEncodedStatementName

        byte[] getEncodedStatementName()
      • setFields

        void setFields​(Field[] fields)
        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 return false. The idea is to perform adjustments only once, not for each QueryExecutorImpl.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)
      • setStatementDescribed

        void setStatementDescribed​(boolean statementDescribed)
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Query
      • setCleanupRef

        void setCleanupRef​(java.lang.ref.PhantomReference<?> cleanupRef)
      • 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 interface Query
        Returns:
        number of times addBatch() has been called.
      • getBindCount

        public final int getBindCount()
      • getResultSetColumnNameIndexMap

        public java.util.Map<java.lang.String,​java.lang.Integer> 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 interface Query
        Returns:
        null if the query implementation does not support this method.
      • getSqlCommand

        public SqlCommand getSqlCommand()
        Description copied from interface: Query
        Returns properties of the query (sql keyword, and some other parsing info).
        Specified by:
        getSqlCommand in interface Query
        Returns:
        returns properties of the query (sql keyword, and some other parsing info) or null if not applicable