public List queryRecordList()

in empire-db/src/main/java/org/apache/empire/db/DBUtils.java [977:1042]


    public <R extends DBRecordBase> List<R> queryRecordList(DBCommand cmd, DBRecordListFactory<R> factory, int first, int pageSize)
    {
        List<R> list = null;
        DBReader r = new DBReader(context);
        try
        {   // prepare
            factory.prepareQuery(cmd, context);
            // check pageSize
            if (pageSize==0)
            {   log.warn("PageSize must not be 0. Setting to -1 for all records!");
                pageSize = -1;
            }
            // set range
            DBMSHandler dbms = context.getDbms();
            if (pageSize>0 && dbms.isSupported(DBMSFeature.QUERY_LIMIT_ROWS))
            {   // let the database limit the rows
                if (first>0 && dbms.isSupported(DBMSFeature.QUERY_SKIP_ROWS))
                {   // let the database skip the rows
                    cmd.skipRows(first);
                    // no need to skip rows ourself
                    first = 0;
                }
                cmd.limitRows(first+pageSize);
            }
            // Runquery
            r.open(cmd);
            if (first>0) 
            {   // skip rows
                r.skipRows(first);
            }
            // Create a list of data entries
            int maxCount = (pageSize>=0) ? pageSize : MAX_QUERY_ROWS;
            list = factory.newList((pageSize>=0) ? pageSize : DEFAULT_LIST_CAPACITY);
            // add data
            int rownum = 0;
            while (r.moveNext() && maxCount != 0)
            {   // Create bean an init
                R entry = factory.newRecord(rownum, r);
                if (entry==null)
                    continue;
                // check
                if (entry.isValid())
                {   // add entry
                    list.add(entry);
                    rownum++;
                }
                else
                    log.trace("Record {} is not valid thus it will not be added to the RecordListQuery.", rownum);
                // Decrease count
                if (maxCount > 0)
                    maxCount--;
            }
            // check
            if (rownum==MAX_QUERY_ROWS)
                queryRowLimitExeeded();
            // done
            return list;
        }
        finally
        {   // close reader
            r.close();
            // complete
            if (list!=null)
                factory.completeQuery(list);
        }
    }