From: James Ahlborn Date: Sat, 15 Mar 2008 20:44:14 +0000 (+0000) Subject: no need to use maxColCount and colNumber when storing row results X-Git-Tag: rel_1_1_13~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=446e80d6960d05712272684d9c0ca40066317324;p=jackcess.git no need to use maxColCount and colNumber when storing row results git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@278 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/java/com/healthmarketscience/jackcess/Cursor.java b/src/java/com/healthmarketscience/jackcess/Cursor.java index 7835c93..58eb127 100644 --- a/src/java/com/healthmarketscience/jackcess/Cursor.java +++ b/src/java/com/healthmarketscience/jackcess/Cursor.java @@ -1200,7 +1200,7 @@ public abstract class Cursor implements Iterable> new LinkedHashMap(); for(Index.ColumnDescriptor idxCol : index.getColumns()) { indexRowPattern.put(idxCol.getName(), - rowValues[idxCol.getColumnNumber()]); + rowValues[idxCol.getColumnIndex()]); } } diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index fbf4390..d0431db 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -757,9 +757,9 @@ public class Index implements Comparable { ", expected " + _columns.size()); } int valIdx = 0; - Object[] idxRow = new Object[getTable().getMaxColumnCount()]; + Object[] idxRow = new Object[getTable().getColumnCount()]; for(ColumnDescriptor col : _columns) { - idxRow[col.getColumnNumber()] = values[valIdx++]; + idxRow[col.getColumnIndex()] = values[valIdx++]; } return idxRow; } @@ -789,9 +789,9 @@ public class Index implements Comparable { } } - Object[] idxRow = new Object[getTable().getMaxColumnCount()]; + Object[] idxRow = new Object[getTable().getColumnCount()]; for(ColumnDescriptor col : _columns) { - idxRow[col.getColumnNumber()] = row.get(col.getName()); + idxRow[col.getColumnIndex()] = row.get(col.getName()); } return idxRow; } @@ -833,11 +833,9 @@ public class Index implements Comparable { // annoyingly, the values array could come from different sources, one // of which will make it a different size than the other. we need to // handle both situations. - boolean useColNumber = (values.length >= _table.getMaxColumnCount()); int nullCount = 0; for(ColumnDescriptor col : _columns) { - Object value = values[ - useColNumber ? col.getColumnNumber() : col.getColumnIndex()]; + Object value = values[col.getColumnIndex()]; if(col.isNullValue(value)) { ++nullCount; } @@ -860,10 +858,8 @@ public class Index implements Comparable { // annoyingly, the values array could come from different sources, one // of which will make it a different size than the other. we need to // handle both situations. - boolean useColNumber = (values.length >= _table.getMaxColumnCount()); for(ColumnDescriptor col : _columns) { - Object value = values[ - useColNumber ? col.getColumnNumber() : col.getColumnIndex()]; + Object value = values[col.getColumnIndex()]; col.writeValue(value, bout); } @@ -1121,10 +1117,6 @@ public class Index implements Comparable { return((getFlags() & ASCENDING_COLUMN_FLAG) != 0); } - public int getColumnNumber() { - return getColumn().getColumnNumber(); - } - public int getColumnIndex() { return getColumn().getColumnIndex(); } diff --git a/src/java/com/healthmarketscience/jackcess/NullMask.java b/src/java/com/healthmarketscience/jackcess/NullMask.java index 4937f38..a2d2625 100644 --- a/src/java/com/healthmarketscience/jackcess/NullMask.java +++ b/src/java/com/healthmarketscience/jackcess/NullMask.java @@ -60,14 +60,15 @@ public class NullMask { public ByteBuffer wrap() { return ByteBuffer.wrap(_mask); } - + /** - * @param columnNumber 0-based column number in this mask's row + * @param column column to test for {@code null} * @return Whether or not the value for that column is null. For boolean * columns, returns the actual value of the column (where * non-{@code null} == {@code true}) */ - public boolean isNull(int columnNumber) { + public boolean isNull(Column column) { + int columnNumber = column.getColumnNumber(); int maskIndex = columnNumber / 8; // if new columns were added to the table, old null masks may not include // them (meaning the field is null) @@ -81,9 +82,10 @@ public class NullMask { /** * Indicate that the column with the given number is not {@code null} (or a * boolean value is {@code true}). - * @param columnNumber 0-based column number in this mask's row + * @param column column to be marked non-{@code null} */ - public void markNotNull(int columnNumber) { + public void markNotNull(Column column) { + int columnNumber = column.getColumnNumber(); int maskIndex = columnNumber / 8; _mask[maskIndex] = (byte) (_mask[maskIndex] | (byte) (1 << (columnNumber % 8))); } diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 9f07f36..73fe6d3 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -359,7 +359,7 @@ public class Table // deletion. note, most of the returned values are immutable, except // for binary data (returned as byte[]), but binary data shouldn't be // indexed anyway. - rowState.setRowValue(column.getColumnNumber(), value); + rowState.setRowValue(column.getColumnIndex(), value); return value; } @@ -407,7 +407,7 @@ public class Table // deletion. note, most of the returned values are immutable, except // for binary data (returned as byte[]), but binary data shouldn't be // indexed anyway. - rowState.setRowValue(column.getColumnNumber(), value); + rowState.setRowValue(column.getColumnIndex(), value); } } return rtn; @@ -421,7 +421,7 @@ public class Table Column column) throws IOException { - boolean isNull = nullMask.isNull(column.getColumnNumber()); + boolean isNull = nullMask.isNull(column); if(column.getType() == DataType.BOOLEAN) { return Boolean.valueOf(!isNull); //Boolean values are stored in the null mask } else if(isNull) { @@ -1244,7 +1244,7 @@ public class Table if(Column.toBooleanValue(rowValue)) { //Booleans are stored in the null mask - nullMask.markNotNull(col.getColumnNumber()); + nullMask.markNotNull(col); } } else { @@ -1257,7 +1257,7 @@ public class Table if(rowValue != null) { // we have a value - nullMask.markNotNull(col.getColumnNumber()); + nullMask.markNotNull(col); //remainingRowLength is ignored when writing fixed length data buffer.position(fixedDataStart + col.getFixedDataOffset()); @@ -1292,7 +1292,7 @@ public class Table Object rowValue = row.get(varCol.getColumnIndex()); if (rowValue != null) { // we have a value - nullMask.markNotNull(varCol.getColumnNumber()); + nullMask.markNotNull(varCol); ByteBuffer varDataBuf = varCol.write(rowValue, maxRowSize); maxRowSize -= varDataBuf.remaining(); @@ -1582,7 +1582,7 @@ public class Table private RowState(boolean hardRowBuffer) { _headerRowBufferH = TempPageHolder.newHolder(hardRowBuffer); - _rowValues = new Object[Table.this.getMaxColumnCount()]; + _rowValues = new Object[Table.this.getColumnCount()]; _lastModCount = Table.this._modCount; }