Changeset: 2053a9fc56ca for monetdb-java URL: https://dev.monetdb.org/hg/monetdb-java/rev/2053a9fc56ca Modified Files: src/main/java/nl/cwi/monetdb/embedded/tables/IMonetDBTableBaseIterator.java src/main/java/nl/cwi/monetdb/embedded/tables/MonetDBTable.java src/main/java/nl/cwi/monetdb/embedded/tables/RowIterator.java Branch: embedded Log Message:
Consistent iteration limits. diffs (96 lines): diff --git a/src/main/java/nl/cwi/monetdb/embedded/tables/IMonetDBTableBaseIterator.java b/src/main/java/nl/cwi/monetdb/embedded/tables/IMonetDBTableBaseIterator.java --- a/src/main/java/nl/cwi/monetdb/embedded/tables/IMonetDBTableBaseIterator.java +++ b/src/main/java/nl/cwi/monetdb/embedded/tables/IMonetDBTableBaseIterator.java @@ -8,7 +8,7 @@ package nl.cwi.monetdb.embedded.tables; public interface IMonetDBTableBaseIterator { /** - * Specify the first row in the table to iterate starting from 1. If a lower number is provided, then the iteration + * Specify the first row in the table to iterate starting from 0. If a lower number is provided, then the iteration * will start on the first row. * * @return The first row in the table to iterate diff --git a/src/main/java/nl/cwi/monetdb/embedded/tables/MonetDBTable.java b/src/main/java/nl/cwi/monetdb/embedded/tables/MonetDBTable.java --- a/src/main/java/nl/cwi/monetdb/embedded/tables/MonetDBTable.java +++ b/src/main/java/nl/cwi/monetdb/embedded/tables/MonetDBTable.java @@ -136,8 +136,8 @@ public class MonetDBTable extends Abstra res[0] = res[1]; res[0] = aux; } - if (res[0] < 1) { - res[0] = 1; + if (res[0] < 0) { + res[0] = 0; } int numberOfRows = this.getNumberOfRows(); if (res[1] >= numberOfRows) { @@ -155,9 +155,9 @@ public class MonetDBTable extends Abstra */ public int iterateTable(IMonetDBTableCursor cursor) throws MonetDBEmbeddedException { int[] limits = this.prepareIterator(cursor); - int res = 0, total = limits[1] - limits[0] + 1; + int res = 0, total = limits[1] - limits[0]; String query = new StringBuffer("SELECT * FROM ").append(this.getTableSchema()).append(".").append(this.getTableName()) - .append(" LIMIT ").append(total).append(" OFFSET ").append(limits[0] - 1).append(";").toString(); + .append(" LIMIT ").append(total).append(" OFFSET ").append(limits[0]).append(";").toString(); QueryResultSet eqr = this.getConnection().sendQuery(query); MonetDBRow[] array = eqr.fetchAllRowValues().getAllRows(); @@ -168,8 +168,9 @@ public class MonetDBTable extends Abstra } RowIterator ri = new RowIterator(this, data, limits[0], limits[1]); - while(ri.tryContinueIteration()) { + while(ri.hasMore()) { cursor.processNextRow(ri); + ri.setNextIteration(); res++; } return res; diff --git a/src/main/java/nl/cwi/monetdb/embedded/tables/RowIterator.java b/src/main/java/nl/cwi/monetdb/embedded/tables/RowIterator.java --- a/src/main/java/nl/cwi/monetdb/embedded/tables/RowIterator.java +++ b/src/main/java/nl/cwi/monetdb/embedded/tables/RowIterator.java @@ -22,7 +22,7 @@ public class RowIterator extends Abstrac /** * The current table row number on the fetched set. */ - protected int currentIterationNumber; + protected int currentIterationNumber = 0; /** * The first row in the table to iterate. @@ -38,7 +38,6 @@ public class RowIterator extends Abstrac super(table, table.getMappings(), rows); this.firstIndex = firstIndex; this.lastIndex = lastIndex; - this.currentIterationNumber = -1; } @Override @@ -101,7 +100,7 @@ public class RowIterator extends Abstrac * * @return There are more rows to iterate */ - public boolean hasMore() { return this.currentIterationNumber + this.firstIndex < this.lastIndex; } + public boolean hasMore() { return this.firstIndex + this.currentIterationNumber < this.lastIndex; } /** * Gets a column value as a Java class. @@ -153,15 +152,7 @@ public class RowIterator extends Abstrac } /** - * Get the next row in the table if there are more. - * - * @return A boolean indicating if there are more rows to fetch + * Sets the next value to iterate. */ - protected boolean tryContinueIteration() { - if(this.hasMore()) { - this.currentIterationNumber++; - return true; - } - return false; - } + protected void setNextIteration() { this.currentIterationNumber++; } } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list