getRowCount()
Counts the total number of rows in this row set.
计算这个行集的行总数
This method retrieves all rows from the View Object by executing the View Object's query and then callingnext() until the last row is retrieved. Thus, since it iterates through the View Object one record at a time, this method may be slow.
该方法通过执行视图对象的查询从视图对象中获取所有行,然后调用next()直到最后一行被调用。于是,由于它通过视图对象一次迭代一条记录,因此该方法是比较慢的。
If you are working with a large number of rows, or if your application demands a fast response, usegetEstimatedRowCount to obtain a quicker count.
如果你操作一大堆行,或者你的应用需要一个快速的响应,使用getEstimatedRowCount获得一个更快的数量。
The following sample code uses getRowCount() to set up separate iterators for even numbered and odd numbered rows:
下面的代码使用getRowCount()为基数和偶数行创立独立的迭代器。
// Default iterator gets even-numbered rows.
// Second iterator gets odd-numbered rows.
long nRows = vo.getRowCount();
String msg = "";
for (int i = 0; i < nRows; i +=2) {
// Get and set row index values relative to a range.
// Index of first row = 0.
vo.setCurrentRowAtRangeIndex(i);
Row currRow = vo.getCurrentRow();
msg = " Default iterator (even): " + vo.getRangeIndexOf(currRow);
printRow(currRow, msg);
secondIter.setCurrentRowAtRangeIndex(i + 1);
currRow = secondIter.getCurrentRow();
msg = " Second iterator (odd): " + vo.getRangeIndexOf(currRow);
printRow(secondIter.getCurrentRow(), msg);
}
getRowCountInRange()
Counts the rows actually in the range.
计算范围内的实际行数
getRowCountInRange() :int
Gets the size of the current RowSet's range
获得当前RowSet(记录集)的范围大小。
getFetchedRowCount() :int
Counts the number of rows fetched from the JDBC result set.
计算从JDBC结果集抓取的行数。
This method delegates to the default RowSetIterator.
This method can be used to determine whether the View Object has read all the rows from the cursor. For example, getEstimatedRowCount returns an equivalent of count(*) on the View Object. ThegetFetchedRowCount() method returns the count of rows already fetched. If getFetchedRowCount() returns a value less than getEstimatedRowCount(), then the View Object has not read all rows from the cursor.
该方法被用于确定视图对象是否从游标中读取所有的行。例如,getEstimatedRowCount返回视图对象上count(*)相等的量。getFetchedRowCount()方法只返回已经抓取的行数。如果getFetchedRowCount()返回的值小于getEstimatedRowCount(),那么视图对象没有从游标中读到所有行。
getEstimatedRowCount
Makes an estimated count of the rows in this row set.
This method estimates the number of rows in the row count by calling getQueryHitCount (which performs a SELECT COUNT (*) FROM table). Internal logic in Business Components for Java keeps the EstimatedRowCount up-to-date as rows are inserted and removed. Thus, after the first call to this method, it can return the estimated count quickly.
For example:
// Get the rowcount again because of deleted or inserted row
rowCount = (int) iter.getRowSet().getEstimatedRowCount();
If you are working with a large number of rows, or if your application demands a fast response, use this method instead ofgetRowCount.
Note however, that this method might not be as accurate as getRowCount().
注意:但是,这个方法可能没有getRowCount准确。
To test whether the View Object has read all the rows from the cursor, you can use getEstimatedRowCount() in conjunction with getFetchedRowCount(). For example, getEstimatedRowCount() returns an equivalent of count(*) on the View Object. The getFetchedRowCount method returns the count of rows already fetched. If getFetchedRowCount() returns a value less than getEstimatedRowCount(), then the View Object has not read all rows from the cursor.
getFetchSize()
Gets the row pre-fetch size.
获得行的预先抓取大小
The framework will use this value to set the JDBC row pre-fetch size. Note that the row pre-fetch size has performance ramifications. A larger fetch size is more expensive in terms of memory usage than a smaller size. The default fetch size is 1 row.
框架将使用这个值去设定JDBC行预抓取大小。注意行预抓取大小影响性能。比较大的抓取大小就内存使用而言比小的抓取大小要更昂贵。 默认的抓取大小是一行。
If the value of setFetchMode(byte) is FETCH_ALL, then the value of setFetchSize is disregarded.
如果setFetchMode的值是FETCH_ALL,则setFetchSize将被忽略。
For each View Object, this method is customizable. Deciding what value to use could be made at runtime based on how many rows are expected for a particular View Object.
对于每个视图对象,这种方法是可定制的。可以在运行时基于一个特定视图对象预期的行数决定使用什么值进行设定。
getRangeSize()
Returns the range size of the iterator.
获得迭代器的范围大小。
测试代码:
PerAllPeopleVOImpl employerInstance=(PerAllPeopleVOImpl) this.getPerAllPeopleVO1();
int fetchedRowCount=employerInstance.getFetchedRowCount();
int rowCount=employerInstance.getRowCount();
int rowCountInRange=employerInstance.getRowCountInRange();
long estimatedRowCount= employerInstance.getEstimatedRowCount();
int rangeSize=employerInstance.getRangeSize();
int fetchSize=employerInstance.getFetchSize();
int allRowLength=employerInstance.getAllRowsInRange().length;
int employerCount=0;
while(employerInstance.hasNext())
{
PerAllPeopleVORowImpl eachEmployer= (PerAllPeopleVORowImpl)employerInstance.next();
String empName= eachEmployer.getLastName();
employerCount++;
}
logInfo("fetchedRowCount is "+fetchedRowCount);
logInfo("rowCount is "+rowCount);
logInfo("rowCountInRange is "+rowCountInRange);
logInfo("estimatedRowCount is "+estimatedRowCount);
logInfo("rangeSize is "+rangeSize);
logInfo("fetchSize is "+fetchSize);
logInfo("employerCount is "+employerCount);
logInfo("allRowLength is "+allRowLength);
测试结果:
fetchedRowCount is 0
rowCount is 1001
rowCountInRange is 1
estimatedRowCount is 1001
rangeSize is 1
fetchSize is 1
employerCount is 0
allRowLength is 1
问题:
实际数据库的记录数是:5 9924,distinct掉重复的person_id后,记录数是3 1113。
在页面上会报出如下警告:警告 - 查询已超出 1000 行。可能存在更多的行,请限制查询。
不知道是否与此设置有关。
关于next()方法:
next() :ROW
Gets the next row in the iterator.
在迭代器中获得下一行
This method delegates to the default RowSetIterator. If this method is called on a row set that has not yet been executed, executeQuery() is implicitly called.
这个方法委托给默认的RowSetIterator。如果这个方法在行集还没有被执行的时候被调用,将隐式调用executeQuery。
If the current row designation is to change, ViewRowImpl.validate() is called to validate the current row.
如果当前行的指定被改变,ViewRowImpl.validate()被调用验证当前行。
The row set has a "slot" before the first row, and one after the last row. When the row set is executed the iterator is positioned at the slot before the first row. If next() is invoked on a newly-executed row, the first row will be returned. If next() is called when the iterator is positioned on the last row of the row set, nullis returned and the iterator is positioned at the slot following the last row.
行集在第一行之前,和最后一行之后都有一个“空位”。当行集被执行时,迭代器定位在第一行之前的空位。如果next()在一个新执行的行上被调用,第一行将返回。
If the iterator is at the last row of the range when next() is called, RowSetListener.rangeScrolled()is called to send ScrollEvent to registered RowSetListeners.
当next()被调用时,如果迭代器在范围的最后一行,RowSetListener.rangeScrolled()被调用发送ScrollEvent到注册的RowSetListeners。
When successful, this method fires a NavigationEvent to registered RowSetListeners, by callingRowSetListener.navigated(). The row returned is designated as the current row.
当成功的时候,该方法通过调用RowSetListener.navigated()触发NavigationEvent 。返回的行被标志为当前行。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。