Class RDBMSQueryUtils


  • public class RDBMSQueryUtils
    extends org.datanucleus.query.QueryUtils
    Utilities for use in queries specific to RDBMS.
    • Constructor Detail

      • RDBMSQueryUtils

        public RDBMSQueryUtils()
    • Method Detail

      • getClassNameFromDiscriminatorResultSetRow

        public static String getClassNameFromDiscriminatorResultSetRow​(JavaTypeMapping discrimMapping,
                                                                       org.datanucleus.metadata.DiscriminatorMetaData dismd,
                                                                       ResultSet rs,
                                                                       org.datanucleus.ExecutionContext ec)
        Convenience method that takes a result set that contains a discriminator column and returns the class name that it represents.
        Parameters:
        discrimMapping - Mapping for the discriminator column
        dismd - Metadata for the discriminator
        rs - The result set
        ec - execution context
        Returns:
        The class name for the object represented in the current row
      • getResultSetTypeForQuery

        public static String getResultSetTypeForQuery​(org.datanucleus.store.query.Query query)
        Accessor for the result set type for the specified query. Uses the persistence property "datanucleus.rdbms.query.resultSetType" and allows it to be overridden by the query extension of the same name. Checks both the NucleusContext and also the query extensions.
        Parameters:
        query - The query
        Returns:
        The result set type string
      • getResultSetConcurrencyForQuery

        public static String getResultSetConcurrencyForQuery​(org.datanucleus.store.query.Query query)
        Accessor for the result set concurrency for the specified query. Uses the persistence property "datanucleus.rdbms.query.resultSetConcurrency" and allows it to be overridden by the query extension of the same name. Checks both the NucleusContext and also the query extensions.
        Parameters:
        query - The query
        Returns:
        The result set concurrency string
      • useUpdateLockForQuery

        public static boolean useUpdateLockForQuery​(org.datanucleus.store.query.Query query)
        Convenience method to return if the specified query should use an "UPDATE" lock on returned objects. First checks whether serializeRead is set on the query and, if not, falls back to the setting for the class.
        Parameters:
        query - The query
        Returns:
        Whether to use an "UPDATE" lock
      • getPreparedStatementForQuery

        public static PreparedStatement getPreparedStatementForQuery​(org.datanucleus.store.connection.ManagedConnection conn,
                                                                     String queryStmt,
                                                                     org.datanucleus.store.query.Query query)
                                                              throws SQLException
        Method to create a PreparedStatement for use with the query.
        Parameters:
        conn - the Connection
        queryStmt - The statement text for the query
        query - The query
        Returns:
        the PreparedStatement
        Throws:
        SQLException - Thrown if an error occurs creating the statement
      • prepareStatementForExecution

        public static void prepareStatementForExecution​(PreparedStatement ps,
                                                        org.datanucleus.store.query.Query query,
                                                        boolean applyTimeout)
                                                 throws SQLException
        Method to apply any restrictions to the created ResultSet.
        Parameters:
        ps - The PreparedStatement
        query - The query
        applyTimeout - Whether to apply the query timeout (if any) direct to the PreparedStatement
        Throws:
        SQLException - Thrown when an error occurs applying the constraints
      • getStatementForCandidates

        public static SelectStatement getStatementForCandidates​(RDBMSStoreManager storeMgr,
                                                                SQLStatement parentStmt,
                                                                org.datanucleus.metadata.AbstractClassMetaData cmd,
                                                                StatementClassMapping clsMapping,
                                                                org.datanucleus.ExecutionContext ec,
                                                                Class candidateCls,
                                                                boolean subclasses,
                                                                String result,
                                                                String candidateAlias,
                                                                String candidateTableGroupName,
                                                                Set<String> options)
        Method to return a statement selecting the candidate table(s) required to cover all possible types for this candidates inheritance strategy.
        Parameters:
        storeMgr - RDBMS StoreManager
        parentStmt - Parent statement (if there is one)
        cmd - Metadata for the class
        clsMapping - Mapping for the results of the statement
        ec - ExecutionContext
        candidateCls - Candidate class
        subclasses - Whether to create a statement for subclasses of the candidate too
        result - The result clause
        candidateAlias - alias for the candidate (if any)
        candidateTableGroupName - TableGroup name for the candidate (if any)
        options - Any options for the statement for getting candidates. See SelectStatementGenerator for some options.
        Returns:
        The SQLStatement
        Throws:
        org.datanucleus.exceptions.NucleusException - if there are no tables for concrete classes in this query (hence would return null)
      • getResultObjectFactoryForNoCandidateClass

        public static ResultObjectFactory getResultObjectFactoryForNoCandidateClass​(org.datanucleus.ExecutionContext ec,
                                                                                    ResultSet rs,
                                                                                    Class resultClass)
        Utility to take a ResultSet and return a ResultObjectFactory for extracting the results, assuming that no candidate class is supplied. The QueryResult will return either a result class type, or Object/Object[] depending on whether a ResultClass has been defined.
        Parameters:
        ec - ExecutionContext
        rs - The ResultSet
        resultClass - Result class if required (or null)
        Returns:
        The query ResultObjectFactory