husted 2002/10/09 15:04:09
Modified: scaffold/src/java/org/apache/commons/scaffold/util
ProcessBean.java ProcessBeanBase.java
Added: scaffold/src/java/org/apache/commons/scaffold/util
Scroller.java
Log:
+ Add Scroller
Revision Changes Path
1.2 +2 -3
jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessBean.java
Index: ProcessBean.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProcessBean.java 14 Aug 2002 17:52:18 -0000 1.1
+++ ProcessBean.java 9 Oct 2002 22:04:09 -0000 1.2
@@ -97,8 +97,7 @@
*/
public Object execute(Object parameters) throws Exception;
-
-}
+} // end ProcessBean
/*
1.4 +4 -5
jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessBeanBase.java
Index: ProcessBeanBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessBeanBase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ProcessBeanBase.java 12 Sep 2002 12:38:14 -0000 1.3
+++ ProcessBeanBase.java 9 Oct 2002 22:04:09 -0000 1.4
@@ -1,3 +1,5 @@
+
+
package org.apache.commons.scaffold.util;
@@ -114,10 +116,7 @@
} // end execute
-
-// end ProcessBeanBase
-
-}
+} // end ProcessBeanBase
/*
1.1
jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/Scroller.java
Index: Scroller.java
===================================================================
package org.apache.commons.scaffold.util;
/**
* Scroller tracks the coordinates needed to manage
* flipping through a result list using
* LIMIT and OFFSET clauses (or the equivalent).
*
* Scrolls through entries using a range (10 to 20 of 50)
* but does not support paging per se goto page 3 (or entry 30)),
* though that would be an easy enhancement.
*
* @author Ted Husted
* @version $Revision: 1.1 $ $Date: 2002/10/09 22:04:09 $
*/
public class Scroller {
public Scroller(int limit, int count) {
setLimit(limit);
setCount(count);
}
public Scroller() {
}
// ---------------------------------------------------------------- Properties
/**
* The starting point for the current query [1].
*/
protected int from = 1; // SQL is one-based
/**
* Set from.
* @param from The new from value.
*/
public void setFrom(int from) {
this.from = from;
}
/**
* Return from.
* @returns The form value.
*/
public int getFrom() {
return(this.from);
}
/**
* The ending point for the current query [1].
*/
protected int thru = 1;
/**
* Set thru.
* @param thru The new thru value.
*/
public void setThru(int thru) {
this.thru = thru;
}
/**
* Return thru.
* @returns The form value.
*/
public int getThru() {
return(this.thru);
}
/**
* The starting point to use for a "backward" query.
*/
protected int prev = 1;
/**
* Set prev.
* @param prev The new prev value.
*/
public void setPrev(int prev) {
this.prev = prev;
}
/**
* Return prev.
* @returns The prev value.
*/
public int getPrev() {
return(this.prev);
}
/**
* The starting point to use with a "forward" query.
* This should always be a valid value.
*
*/
protected int next = 1;
/**
* Set next.
* @param next The new next value.
*/
public void setNext(int next) {
this.next = next;
}
/**
* Return next.
* @returns The next value.
*/
public int getNext() {
return(this.next);
}
/**
* The maximum number of entries to fetch at a time
* [Integer.MAX_VALUE].
*/
protected int limit = Integer.MAX_VALUE;
/**
* Set limit.
* @param limit The new limit value.
*/
public void setLimit(int limit) {
this.limit = limit;
}
/**
* Return limit.
* @returns The limit value.
*/
public int getLimit() {
return(this.limit);
}
/**
* The actual number of entries to fetch (e.g. length or limit).
*/
protected int entries = 0;
/**
* Set entries
* @param entries The new entries value.
*/
public void setEntries(int entries) {
this.entries = entries;
}
/**
* Return entries.
* @returns The entries value.
*/
public int getEntries() {
return(this.entries);
}
/**
* The maximum number of entries available (the SQL count).
*
*/
protected int count = 0;
/**
* Set count
* @param count The new count value.
*/
public void setCount(int count) {
this.count = count;
}
/**
* Return count.
* @returns The count value.
*/
public int getCount() {
return(this.count);
}
// ------------------------------------------------------------ Public Methods
/**
* The database offset for the current query [0].
*
* Convenience method to return one less than from
*
* @returns The offset for this query
*/
public int getOffset() {
int from = getFrom();
return(--from);
}
/**
* Calculate the new property values
* using a bean that has already had count and limit set.
*
* @param from The first absolute row
*/
public void calculate() {
int from = getFrom();
int limit = getLimit();
int entries = getEntries();
int count = getCount();
// Calculate "next" relative to starting point; or wrap to beginning.
int thru = (from + entries) - 1 ; if (thru < 1) thru = 1;
// Calculate "previous" relative to starting point, but don't go negative
int prev = from - limit; if (prev < 1) prev = 1;
// Calculate "next" relative to starting point; or wrap to beginning.
int next = from + entries; if (next > count) next = 1;
setPrev(prev);
setNext(next);
setThru(thru);
}
/**
* Calculate the new property values
* using a bean that has already had count and limit set.
*
* @param from The first absolute row
*/
public void calculate(int entries) {
setEntries(entries);
calculate();
}
/**
* Calculate the new property values.
*
* @param entries The number of matches in this set
* @param from The first absolute row in this set
* @param count How many rows in the complete set
* @param limit The maximum many rows in a subset
*/
public void calculate(int entries, int from, int count, int limit) {
if ((from<1) || (from>count)) from = 1;
setLimit(limit);
setCount(count);
setFrom(from);
calculate(entries);
}
} // end Scroller
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>