Fix for #140 - Add some support for RawSql findRowCount, remove BeanCollection.hasMoreRows()

This commit is contained in:
Rob Bygrave committed 2014-06-10 23:52:05 +12:00
1 parent db17ddd069
commit af6dbd0dbe
19 files changed
+148 -166

No files matched your search

@@ -476,15 +476,6 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
}
}
private boolean hasMoreRows() throws SQLException {
synchronized (this) {
if (cancelled) {
return false;
}
return dataReader.next();
}
}
/**
* Read a row from the result set returning a bean.
* <p>
@@ -533,7 +524,6 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
private boolean readBeanInternal() throws SQLException {
if (loadedBeanCount >= maxRowsLimit) {
collection.setHasMoreRows(hasMoreRows());
return false;
}
@@ -125,6 +125,10 @@ public class CQueryBuilder implements Constants {
// always set the order by to null for row count query
query.setOrder(null);
if (query.isRawSql()) {
query.setFirstRow(0);
query.setMaxRows(0);
}
ManyWhereJoins manyWhereJoins = query.getManyWhereJoins();
@@ -158,7 +162,7 @@ public class CQueryBuilder implements Constants {
SqlTree sqlTree = createSqlTree(request, predicates);
SqlLimitResponse s = buildSql(sqlSelect, request, predicates, sqlTree);
String sql = s.getSql();
if (hasMany) {
if (hasMany || query.isRawSql()) {
sql = "select count(*) from ( " + sql + ")";
if (selectCountWithAlias) {
sql += " as c";
@@ -115,8 +115,6 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
maxRows = query.getMaxRows();
}
boolean hasHitMaxRows = false;
int loadRowCount = 0;
SqlQueryListener listener = query.getListener();
@@ -152,7 +150,6 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
if (loadRowCount == maxRows) {
// break, as we have hit the max rows to fetch...
hasHitMaxRows = true;
break;
}
}
@@ -160,13 +157,6 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
BeanCollection<?> beanColl = wrapper.getBeanCollection();
if (hasHitMaxRows) {
if (rset.next()) {
// there are more rows available after the maxRows limit
beanColl.setHasMoreRows(true);
}
}
if (request.isLogSummary()) {
long exeTime = System.currentTimeMillis() - startTime;
String msg = "SqlQuery rows[" + loadRowCount + "] time[" + exeTime + "] bind[" + bindLog + "]";
@@ -52,7 +52,7 @@ public class LimitOffsetPage<T> implements Page<T>, BeanCollectionTouched {
* Perform fetch ahead when the list is first accessed.
*/
public void notifyTouched(BeanCollection<?> c) {
if (c.hasMoreRows()) {
if (hasNext()) {
owner.fetchAheadIfRequired(pageIndex);
}
}
@@ -65,9 +65,8 @@ public class LimitOffsetPage<T> implements Page<T>, BeanCollectionTouched {
}
}
@SuppressWarnings("unchecked")
public boolean hasNext() {
return ((BeanCollection<T>) getList()).hasMoreRows();
return pageIndex < getTotalPageCount() - 1;
}
public boolean hasPrev() {