Examples of QueryDataSet


Examples of com.workingdogs.village.QueryDataSet

            size = blockBegin + memoryLimit + 1;
        }
        /* The connection to the database. */
        Connection conn = null;
        /** Used to retrieve query results from Village. */
        QueryDataSet qds = null;

        try
        {
            // Add 1 to memory limit to check if the query ends on a page break.
            results = new ArrayList(memoryLimit + 1);

            if (dbSupportsNativeLimit)
            {
                // Use the criteria to limit the rows that are retrieved to the
                // block of records that fit in the predefined memoryLimit.
                criteria.setOffset(blockBegin);
                // Add 1 to memory limit to check if the query ends on a
                // page break.
                criteria.setLimit(memoryLimit + 1);
            }
            query = BasePeer.createQueryString(criteria);

            // Get a connection to the db.
            conn = Torque.getConnection(dbName);

            // Execute the query.
            if (log.isDebugEnabled())
            {
                log.debug("run(): query = " + query);
                log.debug("run(): memoryLimit = " + memoryLimit);
                log.debug("run(): blockBegin = " + blockBegin);
                log.debug("run(): blockEnd = " + blockEnd);
            }
            qds = new QueryDataSet(conn, query);

            // Continue getting rows one page at a time until the memory limit
            // is reached, all results have been retrieved, or the rest
            // of the results have been determined to be irrelevant.
            while (!killThread
                && !qds.allRecordsRetrieved()
                && currentlyFilledTo + pageSize <= blockEnd)
            {
                // This caters for when memoryLimit is not a multiple of
                //  pageSize which it never is because we always add 1 above.
                // not applicable if the db has no native limit where this
                // was already considered
                if ((currentlyFilledTo + pageSize) >= blockEnd
                        && dbSupportsNativeLimit)
                {
                    // Add 1 to check if the query ends on a page break.
                    size = blockEnd - currentlyFilledTo + 1;
                }

                if (log.isDebugEnabled())
                {
                    log.debug("run(): Invoking BasePeer.getSelectResults(qds, "
                            + size + ", false)");
                }

                List tempResults
                        = BasePeer.getSelectResults(qds, size, false);

                synchronized (results)
                {
                    for (int i = 0, n = tempResults.size(); i < n; i++)
                    {
                        if (dbSupportsNativeLimit
                                || (i >= blockBegin))
                        results.add(tempResults.get(i));
                    }
                }

                if (dbSupportsNativeLimit)
                {
                    currentlyFilledTo += tempResults.size();
                }
                else
                {
                    currentlyFilledTo = tempResults.size() - 1 - blockBegin;
                }
               
                boolean perhapsLastPage = true;

                // If the extra record was indeed found then we know we are not
                // on the last page but we must now get rid of it.
                if ((dbSupportsNativeLimit
                        && (results.size() == memoryLimit + 1))
                    || (!dbSupportsNativeLimit
                            && currentlyFilledTo >= memoryLimit))
                {
                    synchronized (results)
                    {
                        results.remove(currentlyFilledTo--);
                    }
                    perhapsLastPage = false;
                }

                if (results.size() > 0
                    && blockBegin + currentlyFilledTo >= totalRecords)
                {
                    // Add 1 because index starts at 0
                    totalRecords = blockBegin + currentlyFilledTo + 1;
                }

                // if the db has limited the datasets, we must retrieve all
                // datasets. If not, we are always finished because we fetch
                // the whole block at once.
                if (qds.allRecordsRetrieved()
                        || !dbSupportsNativeLimit)
                {
                    queryCompleted = true;
                    // The following ugly condition ensures that the totals are
                    // not finalized when a user does something like requesting
                    // a page greater than what exists in the database.
                    if (perhapsLastPage
                        && getCurrentPageNumber() <= getTotalPages())
                    {
                        totalsFinalized = true;
                    }
                }
                qds.clearRecords();
            }

            if (log.isDebugEnabled())
            {
                log.debug("run(): While loop terminated because either:");
                log.debug("run(): 1. qds.allRecordsRetrieved(): "
                        + qds.allRecordsRetrieved());
                log.debug("run(): 2. killThread: " + killThread);
                log.debug("run(): 3. !(currentlyFilledTo + size <= blockEnd): !"
                        + (currentlyFilledTo + pageSize <= blockEnd));
                log.debug("run(): - currentlyFilledTo: " + currentlyFilledTo);
                log.debug("run(): - size: " + pageSize);
                log.debug("run(): - blockEnd: " + blockEnd);
                log.debug("run(): - results.size(): " + results.size());
            }
        }
        catch (TorqueException e)
        {
            log.error(e);
        }
        catch (SQLException e)
        {
            log.error(e);
        }
        catch (DataSetException e)
        {
            log.error(e);
        }
        finally
        {
            try
            {
                if (qds != null)
                {
                    qds.close();
                }
                Torque.closeConnection(conn);
            }
            catch (SQLException e)
            {
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

        int numberOfResults,
        boolean singleRecord,
        Connection con)
        throws TorqueException
    {
        QueryDataSet qds = null;
        List results = Collections.EMPTY_LIST;
        try
        {
            // execute the query
            long startTime = System.currentTimeMillis();
            qds = new QueryDataSet(con, queryString);
            if (log.isDebugEnabled())
            {
                log.debug("Elapsed time="
                        + (System.currentTimeMillis() - startTime) + " ms");
            }
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

                {
                    statement.setString(i + 1, param.toString());
                }
            }

            QueryDataSet qds = null;
            try
            {
                qds = new QueryDataSet(statement.executeQuery());
                v = getSelectResults(qds);
            }
            finally
            {
                VillageUtils.close(qds);
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

        {
            log.debug(idSql);
        }

        // Execute the query.
        QueryDataSet qds = new QueryDataSet(connection, idSql);
        Record rec;
        try
        {
            qds.fetchRecords(1);
            rec = qds.getRecord(0)// Records are 0 based.
        }
        finally
        {
            if (qds != null)
            {
                qds.close();
            }
        }
        return rec.getValue(1); // Values are 1 based.
    }
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

        throws Exception
    {
        String tableName = SQLBuilder.getFullTableName(String.valueOf(keyInfo), name);
        String idSQL = dbAdapter.getIDMethodSQL(tableName);
        Value id = null;
        QueryDataSet qds = null;
        try
        {
            qds = new QueryDataSet(connection, idSQL);
            qds.fetchRecords(1);
            Record rec = qds.getRecord(0);
            id = rec.getValue(1);
        }
        finally
        {
            if (qds != null)
            {
                qds.close();
            }
        }
        return id;
    }
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

        {
            log("Fetching data for table " + tableName, Project.MSG_INFO);
            // Set Statement object in associated TorqueDataDump
            // instance
            return new TableTool
                (new QueryDataSet(conn, "SELECT * FROM " + tableName));
        }
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

        int numberOfResults,
        boolean singleRecord,
        Connection con)
        throws TorqueException
    {
        QueryDataSet qds = null;
        List results = Collections.EMPTY_LIST;
        try
        {
            // execute the query
            long startTime = System.currentTimeMillis();
            qds = new QueryDataSet(con, queryString);
            if (log.isDebugEnabled())
            {
                log.debug("Elapsed time="
                        + (System.currentTimeMillis() - startTime) + " ms");
            }
            results = getSelectResults(
                    qds, start, numberOfResults, singleRecord);
        }
        catch (Exception e)
        {
            throwTorqueException(e);
        }
        finally
        {
            if (qds != null)
            {
                try
                {
                    qds.close();
                }
                catch (Exception ignored)
                {
                }
            }
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

                {
                    stmt.setString(i + 1, param.toString());
                }
            }

            QueryDataSet qds = null;
            try
            {
                qds = new QueryDataSet(stmt.executeQuery());
                v = getSelectResults(qds);
            }
            finally
            {
                if (qds != null)
                {
                    qds.close();
                }
            }
        }
        catch (Exception e)
        {
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

        {
            log.debug(idSql);
        }

        // Execute the query.
        QueryDataSet qds = new QueryDataSet(connection, idSql);
        Record rec;
        try
        {
            qds.fetchRecords(1);
            rec = qds.getRecord(0)// Records are 0 based.
        }
        finally
        {
            if (qds != null)
            {
                qds.close();
            }
        }
        return rec.getValue(1); // Values are 1 based.
    }
View Full Code Here

Examples of com.workingdogs.village.QueryDataSet

    private Value getIdAsVillageValue(Connection connection, Object keyInfo)
        throws Exception
    {
        String idSQL = dbAdapter.getIDMethodSQL(keyInfo);
        Value id = null;
        QueryDataSet qds = null;
        try
        {
            qds = new QueryDataSet(connection, idSQL);
            qds.fetchRecords(1);
            Record rec = qds.getRecord(0);
            id = rec.getValue(1);
        }
        finally
        {
            if (qds != null)
            {
                qds.close();
            }
        }
        return id;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.