Class ResultsConverter


  • public final class ResultsConverter
    extends java.lang.Object
    Provides a method to convert from SQL ResultSet data to InterMine object-based data.
    Author:
    Matthew Wakeling, Andrew Varley
    • Method Detail

      • convert

        public static java.util.List<ResultsRow<java.lang.Object>> convert​(java.sql.ResultSet sqlResults,
                                                                           Query q,
                                                                           ObjectStoreInterMineImpl os,
                                                                           java.sql.Connection c,
                                                                           java.util.Map<java.lang.Object,​java.lang.Integer> sequence,
                                                                           boolean optimise,
                                                                           ExtraQueryTime extra,
                                                                           java.util.Set<PrecomputedTable> goFasterTables,
                                                                           OptimiserCache goFasterCache)
                                                                    throws ObjectStoreException
        Method to convert from SQL results to InterMine object-based results. This method accepts an SQL ResultSet and a Query as an input. The ResultSet must contain a column named the same as the aliases of the elements in the SELECT list of the Query, each containing either the OBJECT column in the case of a business object, or the value of any other value.
        This method will return a List of ResultsRow objects.
        Parameters:
        sqlResults - the ResultSet
        q - the Query
        os - the ObjectStoreInterMineImpl with which to associate any new lazy objects
        c - a Connection with which to make extra requests
        sequence - an object representing the state of the database
        optimise - whether to use optimisation on path expression queries
        extra - object to record extra query execution time
        goFasterTables - a Set of PrecomputedTables that may help with extra queries
        goFasterCache - an OptimiserCache that may help with extra queries
        Returns:
        a List of ResultsRow objects
        Throws:
        ObjectStoreException - if the ResultSet does not match the Query in any way, or if a SQL exception occurs
      • buildObject

        protected static java.lang.Object buildObject​(java.sql.ResultSet sqlResults,
                                                      java.lang.String alias,
                                                      ObjectStoreInterMineImpl os,
                                                      java.lang.Class<?> type,
                                                      java.util.Set<java.lang.String> noObjectClassColumns)
                                               throws java.sql.SQLException
        Builds an object from separate fields in flat mode.
        Parameters:
        sqlResults - the SQL ResultSet
        alias - the name of the column being built
        os - the ObjectStore
        type - a Class matching the QueryClass that is this column
        noObjectClassColumns - a Set used internally
        Returns:
        an InterMineObject
        Throws:
        java.sql.SQLException - if something goes wrong
      • fetchObjectPathExpression

        protected static void fetchObjectPathExpression​(ObjectStoreInterMineImpl os,
                                                        java.sql.Connection c,
                                                        java.util.Map<java.lang.Object,​java.lang.Integer> sequence,
                                                        Query q,
                                                        QueryObjectPathExpression qope,
                                                        java.util.List<ResultsRow<java.lang.Object>> retval,
                                                        boolean optimise,
                                                        ExtraQueryTime extra,
                                                        java.util.Set<PrecomputedTable> goFasterTables,
                                                        OptimiserCache goFasterCache)
                                                 throws ObjectStoreException
        Fetches the contents of a QueryObjectPathExpression for a query.
        Parameters:
        os - the ObjectStoreInterMineImpl
        c - the Connection
        sequence - an object representing the state of the database
        q - the Query
        qope - the QueryObjectPathExpression to fetch data for
        retval - the array of results that will be returned
        optimise - whether to optimise the query
        extra - object to record extra query execution time
        goFasterTables - a Set of PrecomputedTables that may help with extra queries
        goFasterCache - an OptimiserCache that may help with extra queries
        Throws:
        ObjectStoreException - if something goes wrong
      • fetchCollectionPathExpression

        protected static void fetchCollectionPathExpression​(ObjectStoreInterMineImpl os,
                                                            java.sql.Connection c,
                                                            java.util.Map<java.lang.Object,​java.lang.Integer> sequence,
                                                            Query q,
                                                            QueryCollectionPathExpression qcpe,
                                                            java.util.List<ResultsRow<java.lang.Object>> retval,
                                                            boolean optimise,
                                                            ExtraQueryTime extra,
                                                            java.util.Set<PrecomputedTable> goFasterTables,
                                                            OptimiserCache goFasterCache)
                                                     throws ObjectStoreException
        Fetches the QueryCollectionPathExpression data for a query.
        Parameters:
        os - the ObjectStoreInterMineImpl
        c - the Connection
        sequence - an object representing the state of the database
        q - the Query
        qcpe - the QueryCollectionPathExpression to fetch data for
        retval - the array of results that will be returned
        optimise - whether to optimise the query
        extra - object to record extra query execution time
        goFasterTables - a Set of PrecomputedTables that may help with extra queries
        goFasterCache - an OptimiserCache that may help with extra queries
        Throws:
        ObjectStoreException - if something goes wrong
      • fetchByIds

        protected static java.util.Map<java.lang.Integer,​InterMineObject> fetchByIds​(ObjectStoreInterMineImpl os,
                                                                                           java.sql.Connection c,
                                                                                           java.util.Map<java.lang.Object,​java.lang.Integer> sequence,
                                                                                           java.lang.Class<?> clazz,
                                                                                           java.util.Collection<java.lang.Integer> idsToFetch,
                                                                                           ExtraQueryTime extra)
                                                                                    throws ObjectStoreException
        Fetches a group of objects from the database by ID.
        Parameters:
        os - the ObjectStore
        c - the Connection
        sequence - an object representing the state of the database
        clazz - the class of the table to search in
        idsToFetch - a Collection of IDs to fetch
        extra - object to record extra query execution time
        Returns:
        a Map from ID to object
        Throws:
        ObjectStoreException - if an error occurs