From 70e3b4b170b08c58f64dcc5a9be509651f7210b0 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 14 Mar 2013 20:51:19 +0000 Subject: [PATCH] move RowId impl into RowIdImpl, clean up Relationship api git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jackcess-2@682 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/Relationship.java | 18 +-- .../healthmarketscience/jackcess/RowId.java | 107 +------------- .../jackcess/impl/CursorImpl.java | 20 +-- .../jackcess/impl/IndexCursorImpl.java | 2 +- .../jackcess/impl/IndexData.java | 43 +++--- .../jackcess/impl/IndexImpl.java | 4 +- .../jackcess/impl/RowIdImpl.java | 138 ++++++++++++++++++ .../jackcess/impl/TableImpl.java | 40 ++--- .../jackcess/impl/UsageMap.java | 21 +-- .../jackcess/CursorTest.java | 18 ++- .../jackcess/IndexTest.java | 12 +- 11 files changed, 233 insertions(+), 190 deletions(-) create mode 100644 src/java/com/healthmarketscience/jackcess/impl/RowIdImpl.java diff --git a/src/java/com/healthmarketscience/jackcess/Relationship.java b/src/java/com/healthmarketscience/jackcess/Relationship.java index 7f5cb49..66ff0a2 100644 --- a/src/java/com/healthmarketscience/jackcess/Relationship.java +++ b/src/java/com/healthmarketscience/jackcess/Relationship.java @@ -31,8 +31,6 @@ import java.util.Collections; import java.util.List; import java.util.ArrayList; -import com.healthmarketscience.jackcess.impl.ColumnImpl; - /** * Information about a relationship between two tables in the database. * @@ -61,10 +59,10 @@ public class Relationship { private final Table _toTable; /** the columns in the "from" table in this relationship (aligned w/ toColumns list) */ - private List _toColumns; + private final List _toColumns; /** the columns in the "to" table in this relationship (aligned w/ toColumns list) */ - private List _fromColumns; + private final List _fromColumns; /** the various flags describing this relationship */ private final int _flags; @@ -73,11 +71,11 @@ public class Relationship { { _name = name; _fromTable = fromTable; - _fromColumns = new ArrayList( - Collections.nCopies(numCols, (ColumnImpl)null)); + _fromColumns = new ArrayList( + Collections.nCopies(numCols, (Column)null)); _toTable = toTable; - _toColumns = new ArrayList( - Collections.nCopies(numCols, (ColumnImpl)null)); + _toColumns = new ArrayList( + Collections.nCopies(numCols, (Column)null)); _flags = flags; } @@ -89,7 +87,7 @@ public class Relationship { return _fromTable; } - public List getFromColumns() { + public List getFromColumns() { return _fromColumns; } @@ -97,7 +95,7 @@ public class Relationship { return _toTable; } - public List getToColumns() { + public List getToColumns() { return _toColumns; } diff --git a/src/java/com/healthmarketscience/jackcess/RowId.java b/src/java/com/healthmarketscience/jackcess/RowId.java index 1217538..b5b20f6 100644 --- a/src/java/com/healthmarketscience/jackcess/RowId.java +++ b/src/java/com/healthmarketscience/jackcess/RowId.java @@ -1,5 +1,5 @@ /* -Copyright (c) 2007 Health Market Science, Inc. +Copyright (c) 2013 James Ahlborn This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -15,119 +15,16 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -You can contact Health Market Science at info@healthmarketscience.com -or at the following address: - -Health Market Science -2700 Horizon Drive -Suite 200 -King of Prussia, PA 19406 */ package com.healthmarketscience.jackcess; -import org.apache.commons.lang.builder.CompareToBuilder; - - /** * Uniquely identifies a row of data within the access database. * * @author James Ahlborn */ -public class RowId implements Comparable +public interface RowId extends Comparable { - /** special page number which will sort before any other valid page - number */ - public static final int FIRST_PAGE_NUMBER = -1; - /** special page number which will sort after any other valid page - number */ - public static final int LAST_PAGE_NUMBER = -2; - - /** special row number representing an invalid row number */ - public static final int INVALID_ROW_NUMBER = -1; - - /** type attributes for RowIds which simplify comparisons */ - public enum Type { - /** comparable type indicating this RowId should always compare less than - normal RowIds */ - ALWAYS_FIRST, - /** comparable type indicating this RowId should always compare - normally */ - NORMAL, - /** comparable type indicating this RowId should always compare greater - than normal RowIds */ - ALWAYS_LAST; - } - - /** special rowId which will sort before any other valid rowId */ - public static final RowId FIRST_ROW_ID = new RowId( - FIRST_PAGE_NUMBER, INVALID_ROW_NUMBER); - - /** special rowId which will sort after any other valid rowId */ - public static final RowId LAST_ROW_ID = new RowId( - LAST_PAGE_NUMBER, INVALID_ROW_NUMBER); - - private final int _pageNumber; - private final int _rowNumber; - private final Type _type; - - /** - * Creates a new RowId instance. - * - */ - public RowId(int pageNumber,int rowNumber) { - _pageNumber = pageNumber; - _rowNumber = rowNumber; - _type = ((_pageNumber == FIRST_PAGE_NUMBER) ? Type.ALWAYS_FIRST : - ((_pageNumber == LAST_PAGE_NUMBER) ? Type.ALWAYS_LAST : - Type.NORMAL)); - } - - public int getPageNumber() { - return _pageNumber; - } - - public int getRowNumber() { - return _rowNumber; - } - - /** - * Returns {@code true} if this rowId potentially represents an actual row - * of data, {@code false} otherwise. - */ - public boolean isValid() { - return((getRowNumber() >= 0) && (getPageNumber() >= 0)); - } - - public Type getType() { - return _type; - } - - public int compareTo(RowId other) { - return new CompareToBuilder() - .append(getType(), other.getType()) - .append(getPageNumber(), other.getPageNumber()) - .append(getRowNumber(), other.getRowNumber()) - .toComparison(); - } - - @Override - public int hashCode() { - return getPageNumber() ^ getRowNumber(); - } - @Override - public boolean equals(Object o) { - return ((this == o) || - ((o != null) && (getClass() == o.getClass()) && - (getPageNumber() == ((RowId)o).getPageNumber()) && - (getRowNumber() == ((RowId)o).getRowNumber()))); - } - - @Override - public String toString() { - return getPageNumber() + ":" + getRowNumber(); - } - } diff --git a/src/java/com/healthmarketscience/jackcess/impl/CursorImpl.java b/src/java/com/healthmarketscience/jackcess/impl/CursorImpl.java index e995f5d..fd5db70 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/CursorImpl.java +++ b/src/java/com/healthmarketscience/jackcess/impl/CursorImpl.java @@ -73,10 +73,10 @@ public abstract class CursorImpl implements Cursor /** first position for the TableScanCursor */ private static final ScanPosition FIRST_SCAN_POSITION = - new ScanPosition(RowId.FIRST_ROW_ID); + new ScanPosition(RowIdImpl.FIRST_ROW_ID); /** last position for the TableScanCursor */ private static final ScanPosition LAST_SCAN_POSITION = - new ScanPosition(RowId.LAST_ROW_ID); + new ScanPosition(RowIdImpl.LAST_ROW_ID); /** identifier for this cursor */ private final IdImpl _id; @@ -1136,7 +1136,7 @@ public abstract class CursorImpl implements Cursor // figure out how many rows are left on this page so we can find the // next row - RowId curRowId = curPos.getRowId(); + RowIdImpl curRowId = curPos.getRowId(); TableImpl.positionAtRowHeader(rowState, curRowId); int currentRowNumber = curRowId.getRowNumber(); @@ -1144,14 +1144,14 @@ public abstract class CursorImpl implements Cursor while(true) { currentRowNumber = handler.getAnotherRowNumber(currentRowNumber); - curRowId = new RowId(curRowId.getPageNumber(), currentRowNumber); + curRowId = new RowIdImpl(curRowId.getPageNumber(), currentRowNumber); TableImpl.positionAtRowHeader(rowState, curRowId); if(!rowState.isValid()) { // load next page - curRowId = new RowId(handler.getAnotherPageNumber(), - RowId.INVALID_ROW_NUMBER); + curRowId = new RowIdImpl(handler.getAnotherPageNumber(), + RowIdImpl.INVALID_ROW_NUMBER); TableImpl.positionAtRowHeader(rowState, curRowId); if(!rowState.isHeaderPageNumberValid()) { @@ -1293,7 +1293,7 @@ public abstract class CursorImpl implements Cursor /** * Returns the unique RowId of the position of the cursor. */ - public abstract RowId getRowId(); + public abstract RowIdImpl getRowId(); /** * Returns {@code true} if the subclass specific info in a Position is @@ -1344,14 +1344,14 @@ public abstract class CursorImpl implements Cursor */ private static final class ScanPosition extends PositionImpl { - private final RowId _rowId; + private final RowIdImpl _rowId; - private ScanPosition(RowId rowId) { + private ScanPosition(RowIdImpl rowId) { _rowId = rowId; } @Override - public RowId getRowId() { + public RowIdImpl getRowId() { return _rowId; } diff --git a/src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java b/src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java index a501c9d..d262e2a 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java +++ b/src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java @@ -502,7 +502,7 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor } @Override - public RowId getRowId() { + public RowIdImpl getRowId() { return getEntry().getRowId(); } diff --git a/src/java/com/healthmarketscience/jackcess/impl/IndexData.java b/src/java/com/healthmarketscience/jackcess/impl/IndexData.java index 2262420..4533fa5 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/IndexData.java +++ b/src/java/com/healthmarketscience/jackcess/impl/IndexData.java @@ -60,11 +60,11 @@ public class IndexData { /** special entry which is less than any other entry */ public static final Entry FIRST_ENTRY = - createSpecialEntry(RowId.FIRST_ROW_ID); + createSpecialEntry(RowIdImpl.FIRST_ROW_ID); /** special entry which is greater than any other entry */ public static final Entry LAST_ENTRY = - createSpecialEntry(RowId.LAST_ROW_ID); + createSpecialEntry(RowIdImpl.LAST_ROW_ID); /** special object which will always be greater than any other value, when searching for an index entry range in a multi-value index */ @@ -529,7 +529,7 @@ public class IndexData { * @param row Row to add * @param rowId rowId of the row to be added */ - public void addRow(Object[] row, RowId rowId) + public void addRow(Object[] row, RowIdImpl rowId) throws IOException { int nullCount = countNullValues(row); @@ -603,7 +603,7 @@ public class IndexData { * @param row Row to remove * @param rowId rowId of the row to be removed */ - public void deleteRow(Object[] row, RowId rowId) + public void deleteRow(Object[] row, RowIdImpl rowId) throws IOException { int nullCount = countNullValues(row); @@ -700,7 +700,7 @@ public class IndexData { startEntryBytes = createEntryBytes(startRow); startEntry = new Entry(startEntryBytes, (startInclusive ? - RowId.FIRST_ROW_ID : RowId.LAST_ROW_ID)); + RowIdImpl.FIRST_ROW_ID : RowIdImpl.LAST_ROW_ID)); } Entry endEntry = LAST_ENTRY; if(endRow != null) { @@ -711,7 +711,7 @@ public class IndexData { createEntryBytes(endRow)); endEntry = new Entry(endEntryBytes, (endInclusive ? - RowId.LAST_ROW_ID : RowId.FIRST_ROW_ID)); + RowIdImpl.LAST_ROW_ID : RowIdImpl.FIRST_ROW_ID)); } return new EntryCursor(findEntryPosition(startEntry), findEntryPosition(endEntry)); @@ -1184,7 +1184,7 @@ public class IndexData { /** * Creates one of the special index entries. */ - private static Entry createSpecialEntry(RowId rowId) { + private static Entry createSpecialEntry(RowIdImpl rowId) { return new Entry((byte[])null, rowId); } @@ -1241,16 +1241,17 @@ public class IndexData { /** * Returns the EntryType based on the given entry info. */ - private static EntryType determineEntryType(byte[] entryBytes, RowId rowId) + private static EntryType determineEntryType(byte[] entryBytes, + RowIdImpl rowId) { if(entryBytes != null) { - return ((rowId.getType() == RowId.Type.NORMAL) ? + return ((rowId.getType() == RowIdImpl.Type.NORMAL) ? EntryType.NORMAL : - ((rowId.getType() == RowId.Type.ALWAYS_FIRST) ? + ((rowId.getType() == RowIdImpl.Type.ALWAYS_FIRST) ? EntryType.FIRST_VALID : EntryType.LAST_VALID)); } else if(!rowId.isValid()) { // this is a "special" entry (first/last) - return ((rowId.getType() == RowId.Type.ALWAYS_FIRST) ? + return ((rowId.getType() == RowIdImpl.Type.ALWAYS_FIRST) ? EntryType.ALWAYS_FIRST : EntryType.ALWAYS_LAST); } throw new IllegalArgumentException("Values was null for valid entry"); @@ -1645,7 +1646,7 @@ public class IndexData { public static class Entry implements Comparable { /** page/row on which this row is stored */ - private final RowId _rowId; + private final RowIdImpl _rowId; /** the entry value */ private final byte[] _entryBytes; /** comparable type for the entry */ @@ -1657,7 +1658,7 @@ public class IndexData { * @param rowId rowId in which the row is stored * @param type the type of the entry */ - private Entry(byte[] entryBytes, RowId rowId, EntryType type) { + private Entry(byte[] entryBytes, RowIdImpl rowId, EntryType type) { _rowId = rowId; _entryBytes = entryBytes; _type = type; @@ -1668,7 +1669,7 @@ public class IndexData { * @param entryBytes encoded bytes for this index entry * @param rowId rowId in which the row is stored */ - private Entry(byte[] entryBytes, RowId rowId) + private Entry(byte[] entryBytes, RowIdImpl rowId) { this(entryBytes, rowId, determineEntryType(entryBytes, rowId)); } @@ -1699,11 +1700,11 @@ public class IndexData { int page = ByteUtil.get3ByteInt(buffer, ENTRY_BYTE_ORDER); int row = ByteUtil.getUnsignedByte(buffer); - _rowId = new RowId(page, row); + _rowId = new RowIdImpl(page, row); _type = EntryType.NORMAL; } - public RowId getRowId() { + public RowIdImpl getRowId() { return _rowId; } @@ -1857,7 +1858,7 @@ public class IndexData { * @param type the type of the entry * @param subPageNumber the sub-page to which this node entry refers */ - private NodeEntry(byte[] entryBytes, RowId rowId, EntryType type, + private NodeEntry(byte[] entryBytes, RowIdImpl rowId, EntryType type, Integer subPageNumber) { super(entryBytes, rowId, type); _subPageNumber = subPageNumber; @@ -2006,8 +2007,8 @@ public class IndexData { public void beforeEntry(Object[] row) throws IOException { - restorePosition( - new Entry(IndexData.this.createEntryBytes(row), RowId.FIRST_ROW_ID)); + restorePosition(new Entry(IndexData.this.createEntryBytes(row), + RowIdImpl.FIRST_ROW_ID)); } /** @@ -2017,8 +2018,8 @@ public class IndexData { public void afterEntry(Object[] row) throws IOException { - restorePosition( - new Entry(IndexData.this.createEntryBytes(row), RowId.LAST_ROW_ID)); + restorePosition(new Entry(IndexData.this.createEntryBytes(row), + RowIdImpl.LAST_ROW_ID)); } /** diff --git a/src/java/com/healthmarketscience/jackcess/impl/IndexImpl.java b/src/java/com/healthmarketscience/jackcess/impl/IndexImpl.java index 12d61af..1fd560b 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/IndexImpl.java +++ b/src/java/com/healthmarketscience/jackcess/impl/IndexImpl.java @@ -253,7 +253,7 @@ public class IndexImpl implements Index, Comparable * @param row Row to add * @param rowId rowId of the row to be added */ - public void addRow(Object[] row, RowId rowId) + public void addRow(Object[] row, RowIdImpl rowId) throws IOException { getIndexData().addRow(row, rowId); @@ -267,7 +267,7 @@ public class IndexImpl implements Index, Comparable * @param row Row to remove * @param rowId rowId of the row to be removed */ - public void deleteRow(Object[] row, RowId rowId) + public void deleteRow(Object[] row, RowIdImpl rowId) throws IOException { getIndexData().deleteRow(row, rowId); diff --git a/src/java/com/healthmarketscience/jackcess/impl/RowIdImpl.java b/src/java/com/healthmarketscience/jackcess/impl/RowIdImpl.java new file mode 100644 index 0000000..7524f1c --- /dev/null +++ b/src/java/com/healthmarketscience/jackcess/impl/RowIdImpl.java @@ -0,0 +1,138 @@ +/* +Copyright (c) 2007 Health Market Science, Inc. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +You can contact Health Market Science at info@healthmarketscience.com +or at the following address: + +Health Market Science +2700 Horizon Drive +Suite 200 +King of Prussia, PA 19406 +*/ + +package com.healthmarketscience.jackcess.impl; + +import org.apache.commons.lang.builder.CompareToBuilder; +import com.healthmarketscience.jackcess.RowId; + + +/** + * Uniquely identifies a row of data within the access database. + * + * @author James Ahlborn + */ +public class RowIdImpl implements RowId +{ + /** special page number which will sort before any other valid page + number */ + public static final int FIRST_PAGE_NUMBER = -1; + /** special page number which will sort after any other valid page + number */ + public static final int LAST_PAGE_NUMBER = -2; + + /** special row number representing an invalid row number */ + public static final int INVALID_ROW_NUMBER = -1; + + /** type attributes for RowIds which simplify comparisons */ + public enum Type { + /** comparable type indicating this RowId should always compare less than + normal RowIds */ + ALWAYS_FIRST, + /** comparable type indicating this RowId should always compare + normally */ + NORMAL, + /** comparable type indicating this RowId should always compare greater + than normal RowIds */ + ALWAYS_LAST; + } + + /** special rowId which will sort before any other valid rowId */ + public static final RowIdImpl FIRST_ROW_ID = new RowIdImpl( + FIRST_PAGE_NUMBER, INVALID_ROW_NUMBER); + + /** special rowId which will sort after any other valid rowId */ + public static final RowIdImpl LAST_ROW_ID = new RowIdImpl( + LAST_PAGE_NUMBER, INVALID_ROW_NUMBER); + + private final int _pageNumber; + private final int _rowNumber; + private final Type _type; + + /** + * Creates a new RowId instance. + * + */ + public RowIdImpl(int pageNumber,int rowNumber) { + _pageNumber = pageNumber; + _rowNumber = rowNumber; + _type = ((_pageNumber == FIRST_PAGE_NUMBER) ? Type.ALWAYS_FIRST : + ((_pageNumber == LAST_PAGE_NUMBER) ? Type.ALWAYS_LAST : + Type.NORMAL)); + } + + public int getPageNumber() { + return _pageNumber; + } + + public int getRowNumber() { + return _rowNumber; + } + + /** + * Returns {@code true} if this rowId potentially represents an actual row + * of data, {@code false} otherwise. + */ + public boolean isValid() { + return((getRowNumber() >= 0) && (getPageNumber() >= 0)); + } + + public Type getType() { + return _type; + } + + public int compareTo(RowId other) { + return compareTo((RowIdImpl)other); + } + + public int compareTo(RowIdImpl other) { + return new CompareToBuilder() + .append(getType(), other.getType()) + .append(getPageNumber(), other.getPageNumber()) + .append(getRowNumber(), other.getRowNumber()) + .toComparison(); + } + + @Override + public int hashCode() { + return getPageNumber() ^ getRowNumber(); + } + + @Override + public boolean equals(Object o) { + return ((this == o) || + ((o != null) && (getClass() == o.getClass()) && + (getPageNumber() == ((RowIdImpl)o).getPageNumber()) && + (getRowNumber() == ((RowIdImpl)o).getRowNumber()))); + } + + @Override + public String toString() { + return getPageNumber() + ":" + getRowNumber(); + } + +} diff --git a/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java b/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java index 326de2c..5d7f05d 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java +++ b/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java @@ -473,7 +473,9 @@ public class TableImpl implements Table * allows for more complex table interactions. * @usage _advanced_method_ */ - public void deleteRow(RowState rowState, RowId rowId) throws IOException { + public void deleteRow(RowState rowState, RowIdImpl rowId) + throws IOException + { requireValidRowId(rowId); // ensure that the relevant row state is up-to-date @@ -534,7 +536,8 @@ public class TableImpl implements Table * e.g. {@link Cursor#getCurrentRowValue}. * @usage _advanced_method_ */ - public Object getRowValue(RowState rowState, RowId rowId, ColumnImpl column) + public Object getRowValue(RowState rowState, RowIdImpl rowId, + ColumnImpl column) throws IOException { if(this != column.getTable()) { @@ -556,7 +559,7 @@ public class TableImpl implements Table * @usage _advanced_method_ */ public Map getRow( - RowState rowState, RowId rowId, Collection columnNames) + RowState rowState, RowIdImpl rowId, Collection columnNames) throws IOException { requireValidRowId(rowId); @@ -759,7 +762,8 @@ public class TableImpl implements Table * @return a ByteBuffer of the relevant page, or null if row was invalid * @usage _advanced_method_ */ - public static ByteBuffer positionAtRowHeader(RowState rowState, RowId rowId) + public static ByteBuffer positionAtRowHeader(RowState rowState, + RowIdImpl rowId) throws IOException { ByteBuffer rowBuffer = rowState.setHeaderRow(rowId); @@ -803,7 +807,8 @@ public class TableImpl implements Table * invalid or deleted * @usage _advanced_method_ */ - public static ByteBuffer positionAtRowData(RowState rowState, RowId rowId) + public static ByteBuffer positionAtRowData(RowState rowState, + RowIdImpl rowId) throws IOException { positionAtRowHeader(rowState, rowId); @@ -850,7 +855,7 @@ public class TableImpl implements Table int overflowRowNum = ByteUtil.getUnsignedByte(rowBuffer, rowStart); int overflowPageNum = ByteUtil.get3ByteInt(rowBuffer, rowStart + 1); rowBuffer = rowState.setOverflowRow( - new RowId(overflowPageNum, overflowRowNum)); + new RowIdImpl(overflowPageNum, overflowRowNum)); rowNum = overflowRowNum; } else { @@ -1347,7 +1352,7 @@ public class TableImpl implements Table dataPage.put(rowData[i]); // update the indexes - RowId rowId = new RowId(pageNumber, rowNum); + RowIdImpl rowId = new RowIdImpl(pageNumber, rowNum); for(IndexData indexData : _indexDatas) { indexData.addRow(row, rowId); } @@ -1368,7 +1373,7 @@ public class TableImpl implements Table * {@link Cursor#setCurrentRowValue} and {@link Cursor#updateCurrentRow}. * @usage _advanced_method_ */ - public void updateRow(RowState rowState, RowId rowId, Object... row) + public void updateRow(RowState rowState, RowIdImpl rowId, Object... row) throws IOException { requireValidRowId(rowId); @@ -1453,7 +1458,7 @@ public class TableImpl implements Table PageChannel.INVALID_PAGE_NUMBER); pageNumber = _addRowBufferH.getPageNumber(); - RowId headerRowId = rowState.getHeaderRowId(); + RowIdImpl headerRowId = rowState.getHeaderRowId(); ByteBuffer headerPage = rowState.getHeaderPage(); if(pageNumber == headerRowId.getPageNumber()) { // new row is on the same page as header row, share page @@ -1945,7 +1950,7 @@ public class TableImpl implements Table /** * @throws IllegalStateException if the given rowId is invalid */ - private static void requireValidRowId(RowId rowId) { + private static void requireValidRowId(RowIdImpl rowId) { if(!rowId.isValid()) { throw new IllegalArgumentException("Given rowId is invalid: " + rowId); } @@ -1954,7 +1959,8 @@ public class TableImpl implements Table /** * @throws IllegalStateException if the given row is invalid or deleted */ - private static void requireNonDeletedRow(RowState rowState, RowId rowId) { + private static void requireNonDeletedRow(RowState rowState, RowIdImpl rowId) + { if(!rowState.isValid()) { throw new IllegalArgumentException( "Given rowId is invalid for this table: " + rowId); @@ -2084,7 +2090,7 @@ public class TableImpl implements Table /** Buffer used for reading the header row data pages */ private final TempPageHolder _headerRowBufferH; /** the header rowId */ - private RowId _headerRowId = RowId.FIRST_ROW_ID; + private RowIdImpl _headerRowId = RowIdImpl.FIRST_ROW_ID; /** the number of rows on the header page */ private int _rowsOnHeaderPage; /** the rowState status */ @@ -2099,7 +2105,7 @@ public class TableImpl implements Table private ByteBuffer _finalRowBuffer; /** the rowId which contains the final data (after following any overflow pointers) */ - private RowId _finalRowId = null; + private RowIdImpl _finalRowId = null; /** true if the row values array has data */ private boolean _haveRowValues; /** values read from the last row */ @@ -2171,7 +2177,7 @@ public class TableImpl implements Table return _finalRowBuffer; } - public RowId getFinalRowId() { + public RowIdImpl getFinalRowId() { if(_finalRowId == null) { _finalRowId = getHeaderRowId(); } @@ -2239,7 +2245,7 @@ public class TableImpl implements Table _varColOffsets = varColOffsets; } - public RowId getHeaderRowId() { + public RowIdImpl getHeaderRowId() { return _headerRowId; } @@ -2254,7 +2260,7 @@ public class TableImpl implements Table return _headerRowBufferH.getPage(getPageChannel()); } - private ByteBuffer setHeaderRow(RowId rowId) + private ByteBuffer setHeaderRow(RowIdImpl rowId) throws IOException { checkForModification(); @@ -2289,7 +2295,7 @@ public class TableImpl implements Table return _finalRowBuffer; } - private ByteBuffer setOverflowRow(RowId rowId) + private ByteBuffer setOverflowRow(RowIdImpl rowId) throws IOException { // this should never see modifications because it only happens within diff --git a/src/java/com/healthmarketscience/jackcess/impl/UsageMap.java b/src/java/com/healthmarketscience/jackcess/impl/UsageMap.java index 9361c87..ffc3904 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/UsageMap.java +++ b/src/java/com/healthmarketscience/jackcess/impl/UsageMap.java @@ -198,13 +198,14 @@ public class UsageMap } protected int getFirstPageNumber() { - return bitIndexToPageNumber(getNextBitIndex(-1), RowId.LAST_PAGE_NUMBER); + return bitIndexToPageNumber(getNextBitIndex(-1), + RowIdImpl.LAST_PAGE_NUMBER); } protected int getNextPageNumber(int curPage) { return bitIndexToPageNumber( getNextBitIndex(pageNumberToBitIndex(curPage)), - RowId.LAST_PAGE_NUMBER); + RowIdImpl.LAST_PAGE_NUMBER); } protected int getNextBitIndex(int curIndex) { @@ -213,13 +214,13 @@ public class UsageMap protected int getLastPageNumber() { return bitIndexToPageNumber(getPrevBitIndex(_pageNumbers.length()), - RowId.FIRST_PAGE_NUMBER); + RowIdImpl.FIRST_PAGE_NUMBER); } protected int getPrevPageNumber(int curPage) { return bitIndexToPageNumber( getPrevBitIndex(pageNumberToBitIndex(curPage)), - RowId.FIRST_PAGE_NUMBER); + RowIdImpl.FIRST_PAGE_NUMBER); } protected int getPrevBitIndex(int curIndex) { @@ -912,9 +913,9 @@ public class UsageMap private int updatePosition(int pageNumber) { if(pageNumber < UsageMap.this.getFirstPageNumber()) { - pageNumber = RowId.FIRST_PAGE_NUMBER; + pageNumber = RowIdImpl.FIRST_PAGE_NUMBER; } else if(pageNumber > UsageMap.this.getLastPageNumber()) { - pageNumber = RowId.LAST_PAGE_NUMBER; + pageNumber = RowIdImpl.LAST_PAGE_NUMBER; } return pageNumber; } @@ -949,11 +950,11 @@ public class UsageMap } @Override public int getBeginningPageNumber() { - return RowId.FIRST_PAGE_NUMBER; + return RowIdImpl.FIRST_PAGE_NUMBER; } @Override public int getEndPageNumber() { - return RowId.LAST_PAGE_NUMBER; + return RowIdImpl.LAST_PAGE_NUMBER; } } @@ -970,11 +971,11 @@ public class UsageMap } @Override public int getBeginningPageNumber() { - return RowId.LAST_PAGE_NUMBER; + return RowIdImpl.LAST_PAGE_NUMBER; } @Override public int getEndPageNumber() { - return RowId.FIRST_PAGE_NUMBER; + return RowIdImpl.FIRST_PAGE_NUMBER; } } diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java index ac83a5e..575e51f 100644 --- a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java @@ -42,6 +42,7 @@ import com.healthmarketscience.jackcess.util.RowFilterTest; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; import junit.framework.TestCase; import com.healthmarketscience.jackcess.impl.JetFormatTest; +import com.healthmarketscience.jackcess.impl.RowIdImpl; import com.healthmarketscience.jackcess.util.ColumnMatcher; import com.healthmarketscience.jackcess.util.SimpleColumnMatcher; import com.healthmarketscience.jackcess.util.CaseInsensitiveColumnMatcher; @@ -186,16 +187,17 @@ public class CursorTest extends TestCase { public void testRowId() throws Exception { // test special cases - RowId rowId1 = new RowId(1, 2); - RowId rowId2 = new RowId(1, 3); - RowId rowId3 = new RowId(2, 1); + RowIdImpl rowId1 = new RowIdImpl(1, 2); + RowIdImpl rowId2 = new RowIdImpl(1, 3); + RowIdImpl rowId3 = new RowIdImpl(2, 1); - List sortedRowIds = new ArrayList(new TreeSet( - Arrays.asList(rowId1, rowId2, rowId3, RowId.FIRST_ROW_ID, - RowId.LAST_ROW_ID))); + List sortedRowIds = + new ArrayList(new TreeSet( + Arrays.asList(rowId1, rowId2, rowId3, RowIdImpl.FIRST_ROW_ID, + RowIdImpl.LAST_ROW_ID))); - assertEquals(Arrays.asList(RowId.FIRST_ROW_ID, rowId1, rowId2, rowId3, - RowId.LAST_ROW_ID), + assertEquals(Arrays.asList(RowIdImpl.FIRST_ROW_ID, rowId1, rowId2, rowId3, + RowIdImpl.LAST_ROW_ID), sortedRowIds); } diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java index fda8ac5..8eb7cd1 100644 --- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java @@ -36,16 +36,16 @@ import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; -import junit.framework.TestCase; - import static com.healthmarketscience.jackcess.Database.*; import static com.healthmarketscience.jackcess.DatabaseTest.*; -import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; -import com.healthmarketscience.jackcess.impl.IndexImpl; import com.healthmarketscience.jackcess.impl.ByteUtil; +import com.healthmarketscience.jackcess.impl.IndexCodesTest; import com.healthmarketscience.jackcess.impl.IndexData; +import com.healthmarketscience.jackcess.impl.IndexImpl; +import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; +import com.healthmarketscience.jackcess.impl.RowIdImpl; import com.healthmarketscience.jackcess.impl.TableImpl; -import com.healthmarketscience.jackcess.impl.IndexCodesTest; +import junit.framework.TestCase; /** * @author James Ahlborn @@ -334,7 +334,7 @@ public class IndexTest extends TestCase { IOException failure = null; try { - ((IndexImpl)index).addRow(row, new RowId(400 + i, 0)); + ((IndexImpl)index).addRow(row, new RowIdImpl(400 + i, 0)); } catch(IOException e) { failure = e; } -- 2.39.5