diff options
Diffstat (limited to 'src/java/com')
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Table.java | 18 | ||||
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/UsageMap.java | 10 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 96b51ca..b0223b6 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -139,6 +139,7 @@ public class Table { public void reset() { _rowsLeftOnPage = 0; _ownedPages.reset(); + _currentRowInPage = 0; } /** @@ -147,6 +148,19 @@ public class Table { public Map<String, Object> getNextRow() throws IOException { return getNextRow(null); } + + /** + * Delete the current row (retrieved by a call to {@link #getNextRow}). + */ + public void deleteCurrentRow() throws IOException { + if (_currentRowInPage == 0) { + throw new IllegalStateException("Must call getNextRow first"); + } + int index = _format.OFFSET_DATA_ROW_LOCATION_BLOCK + (_currentRowInPage - 1) * + _format.SIZE_ROW_LOCATION + 1; + _buffer.put(index, (byte) (_buffer.get(index) | 0xc0)); + _pageChannel.writePage(_buffer, _ownedPages.getCurrentPageNumber()); + } /** * @param columnNames Only column names in this collection will be returned @@ -384,6 +398,10 @@ public class Table { if (rowCount > 0) { rowLocation = dataPage.getShort(_format.OFFSET_DATA_ROW_LOCATION_BLOCK + (rowCount - 1) * _format.SIZE_ROW_LOCATION); + if (rowLocation < 0) { + // Deleted row + rowLocation &= ~0xc000; + } } rowLocation -= rowSize; dataPage.putShort(_format.OFFSET_DATA_ROW_LOCATION_BLOCK + diff --git a/src/java/com/healthmarketscience/jackcess/UsageMap.java b/src/java/com/healthmarketscience/jackcess/UsageMap.java index c6ddbc7..642470b 100644 --- a/src/java/com/healthmarketscience/jackcess/UsageMap.java +++ b/src/java/com/healthmarketscience/jackcess/UsageMap.java @@ -128,7 +128,11 @@ public abstract class UsageMap { public List<Integer> getPageNumbers() { return _pageNumbers; } - + + public Integer getCurrentPageNumber() { + return _pageNumbers.get(_currentPageIndex - 1); + } + protected void setStartOffset(int startOffset) { _startOffset = startOffset; } @@ -166,8 +170,8 @@ public abstract class UsageMap { */ public boolean getNextPage(ByteBuffer buffer) throws IOException { if (_pageNumbers.size() > _currentPageIndex) { - Integer pageNumber = (Integer) _pageNumbers.get(_currentPageIndex++); - _pageChannel.readPage(buffer, pageNumber.intValue()); + Integer pageNumber = _pageNumbers.get(_currentPageIndex++); + _pageChannel.readPage(buffer, pageNumber); return true; } else { return false; |