⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 largeselect.java

📁 另外一种持久性o/m软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    {        if (threadRunning)        {            killThread = true;            while (thread.isAlive())            {                try                {                    Thread.sleep(100);                }                catch (InterruptedException e)                {                    throw new TorqueException("Unexpected interruption", e);                }            }            killThread = false;        }    }    /**     * Retrieve the number of the current page.     *     * @return the current page number.     */    public int getCurrentPageNumber()    {        return currentPageNumber;    }    /**     * Retrieve the total number of search result records that are known to     * exist (this will be the actual value when the query has completeted (see     * <code>getTotalsFinalized()</code>).  The convenience method     * <code>getRecordProgressText()</code> may be more useful for presenting to     * users.     *     * @return the number of result records known to exist (not accurate until     * <code>getTotalsFinalized()</code> returns <code>true</code>).     */    public int getTotalRecords()    {        return totalRecords;    }    /**     * Provide an indication of whether or not paging of results will be     * required.     *     * @return <code>true</code> when multiple pages of results exist.     */    public boolean getPaginated()    {        // Handle a page memory limit of 1 page.        if (!getTotalsFinalized())        {            return true;        }        return blockBegin + currentlyFilledTo + 1 > pageSize;    }    /**     * Retrieve the total number of pages of search results that are known to     * exist (this will be the actual value when the query has completeted (see     * <code>getQyeryCompleted()</code>).  The convenience method     * <code>getPageProgressText()</code> may be more useful for presenting to     * users.     *     * @return the number of pages of results known to exist (not accurate until     * <code>getTotalsFinalized()</code> returns <code>true</code>).     */    public int getTotalPages()    {        if (totalPages > -1)        {            return totalPages;        }        int tempPageCount =            getTotalRecords() / pageSize                + (getTotalRecords() % pageSize > 0 ? 1 : 0);        if (getTotalsFinalized())        {            totalPages = tempPageCount;        }        return tempPageCount;    }    /**     * Retrieve the page size.     *     * @return the number of records returned on each invocation of     * <code>getNextResults()</code>/<code>getPreviousResults()</code>.     */    public int getPageSize()    {        return pageSize;    }    /**     * Provide access to indicator that the total values for the number of     * records and pages are now accurate as opposed to known upper limits.     *     * @return <code>true</code> when the totals are known to have been fully     * computed.     */    public boolean getTotalsFinalized()    {        return totalsFinalized;    }    /**     * Provide a way of changing the more pages/records indicator.     *     * @param moreIndicator the indicator to use in place of the default     * ("&gt;").     */    public static void setMoreIndicator(String moreIndicator)    {        LargeSelect.moreIndicator = moreIndicator;    }    /**     * Retrieve the more pages/records indicator.     */    public static String getMoreIndicator()    {        return LargeSelect.moreIndicator;    }    /**     * Sets the multiplier that will be used to compute the memory limit when a     * constructor with no memory page limit is used - the memory limit will be     * this number multiplied by the page size.     *     * @param memoryPageLimit the maximum number of pages to be in memory     * at one time.     */    public static void setMemoryPageLimit(int memoryPageLimit)    {        LargeSelect.memoryPageLimit = memoryPageLimit;    }    /**     * Retrieves the multiplier that will be used to compute the memory limit     * when a constructor with no memory page limit is used - the memory limit     * will be this number multiplied by the page size.     */    public static int getMemoryPageLimit()    {        return LargeSelect.memoryPageLimit;    }    /**     * A convenience method that provides text showing progress through the     * selected rows on a page basis.     *     * @return progress text in the form of "1 of &gt; 5" where "&gt;" can be     * configured using <code>setMoreIndicator()</code>.     */    public String getPageProgressText()    {        StringBuffer result = new StringBuffer();        result.append(getCurrentPageNumber());        result.append(" of ");        if (!totalsFinalized)        {            result.append(moreIndicator);            result.append(" ");        }        result.append(getTotalPages());        return result.toString();    }    /**     * Provides a count of the number of rows to be displayed on the current     * page - for the last page this may be less than the configured page size.     *     * @return the number of records that are included on the current page of     * results.     */    public int getCurrentPageSize()    {        if (null == lastResults)        {            return 0;        }        return lastResults.size();    }    /**     * Provide the record number of the first row included on the current page.     *     * @return The record number of the first row of the current page.     */    public int getFirstRecordNoForPage()    {        if (getCurrentPageNumber() < 1)        {            return 0;        }        return getCurrentPageNumber() * getPageSize() - getPageSize() + 1;    }    /**     * Provide the record number of the last row included on the current page.     *     * @return the record number of the last row of the current page.     */    public int getLastRecordNoForPage()    {        if (0 == currentPageNumber)        {            return 0;        }        return (getCurrentPageNumber() - 1) * getPageSize()                + getCurrentPageSize();    }    /**     * A convenience method that provides text showing progress through the     * selected rows on a record basis.     *     * @return progress text in the form of "26 - 50 of &gt; 250" where "&gt;"     * can be configured using <code>setMoreIndicator()</code>.     */    public String getRecordProgressText()    {        StringBuffer result = new StringBuffer();        result.append(getFirstRecordNoForPage());        result.append(" - ");        result.append(getLastRecordNoForPage());        result.append(" of ");        if (!totalsFinalized)        {            result.append(moreIndicator);            result.append(" ");        }        result.append(getTotalRecords());        return result.toString();    }    /**     * Indicates if further result pages are available.     *     * @return <code>true</code> when further results are available.     */    public boolean getNextResultsAvailable()    {        if (!totalsFinalized || getCurrentPageNumber() < getTotalPages())        {            return true;        }        return false;    }    /**     * Indicates if previous results pages are available.     *     * @return <code>true</code> when previous results are available.     */    public boolean getPreviousResultsAvailable()    {        if (getCurrentPageNumber() <= 1)        {            return false;        }        return true;    }    /**     * Indicates if any results are available.     *     * @return <code>true</code> of any results are available.     */    public boolean hasResultsAvailable()    {        return getTotalRecords() > 0;    }    /**     * Clear the query result so that the query is reexecuted when the next page     * is retrieved.  You may want to invoke this method if you are returning to     * a page after performing an operation on an item in the result set.     *     * @throws TorqueException if a sleep is interrupted.     */    public synchronized void invalidateResult() throws TorqueException    {        stopQuery();        blockBegin = 0;        blockEnd = 0;        currentlyFilledTo = -1;        qds = null;        results = null;        position = 0;        totalPages = -1;        totalRecords = 0;        // todo Perhaps store the oldPageNumber and immediately restart the        // query.         // oldPageNumber = currentPageNumber;        currentPageNumber = 0;        queryCompleted = false;        totalsFinalized = false;        lastResults = null;    }    /**     * Retrieve a search parameter.  This acts as a convenient place to store     * parameters that relate to the LargeSelect to make it easy to get at them     * in order to repopulate search parameters on a form when the next page of     * results is retrieved - they in no way effect the operation of     * LargeSelect.     *     * @param name the search parameter key to retrieve.     * @return the value of the search parameter.     */    public String getSearchParam(String name)    {        return getSearchParam(name, null);    }    /**     * Retrieve a search parameter.  This acts as a convenient place to store     * parameters that relate to the LargeSelect to make it easy to get at them     * in order to repopulate search parameters on a form when the next page of     * results is retrieved - they in no way effect the operation of     * LargeSelect.     *     * @param name the search parameter key to retrieve.     * @param defaultValue the default value to return if the key is not found.     * @return the value of the search parameter.     */    public String getSearchParam(String name, String defaultValue)    {        if (null == params)        {            return defaultValue;        }        String value = (String) params.get(name);        return null == value ? defaultValue : value;    }    /**     * Set a search parameter.  If the value is <code>null</code> then the      * key will be removed from the parameters.     *     * @param name the search parameter key to set.     * @param value the value of the search parameter to store.     */    public void setSearchParam(String name, String value)    {        if (null == value)        {            removeSearchParam(name);        }        else        {            if (null != name)            {                if (null == params)                {                    params = new Hashtable();                }                params.put(name, value);            }        }    }    /**     * Remove a value from the search parameters.     *     * @param name the search parameter key to remove.     */    public void removeSearchParam(String name)    {        if (null != params)        {            params.remove(name);        }    }    /**     * Provide something useful for debugging purposes.     *      * @return some basic information about this instance of LargeSelect.     */    public String toString()    {        StringBuffer result = new StringBuffer();        result.append("LargeSelect - TotalRecords: ");        result.append(getTotalRecords());        result.append(" TotalsFinalised: ");        result.append(getTotalsFinalized());        result.append("\nParameters:");        if (null == params || params.size() == 0)        {            result.append(" No parameters have been set.");        }        else        {            Set keys = params.keySet();            for (Iterator iter = keys.iterator(); iter.hasNext();)            {                String key = (String) iter.next();                String val = (String) params.get(key);                result.append("\n ").append(key).append(": ").append(val);            }        }        return result.toString();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -