From: James Ahlborn Date: Tue, 21 Jun 2016 02:30:17 +0000 (+0000) Subject: get add index def functional X-Git-Tag: jackcess-2.1.5~7^2~30 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=523a31dad217c71e70f759893fa36becdfe08f8e;p=jackcess.git get add index def functional git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@998 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DBMutator.java b/src/main/java/com/healthmarketscience/jackcess/impl/DBMutator.java index e599191..374af2b 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/DBMutator.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/DBMutator.java @@ -137,6 +137,8 @@ abstract class DBMutator return null; } + abstract String getTableName(); + public abstract int getTdefPageNumber(); abstract short getColumnNumber(String colName); diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java b/src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java index 3961a9b..ea6708d 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java @@ -549,11 +549,10 @@ public class IndexData { columnNumber = creator.getColumnNumber(idxCol.getName()); if(columnNumber == COLUMN_UNUSED) { // should never happen as this is validated before - // FIXME - // throw new IllegalArgumentException( - // withErrorContext( - // "Column with name " + idxCol.getName() + " not found", - // creator.getDatabase(), creator.getName(), idx.getName())); + throw new IllegalArgumentException( + withErrorContext( + "Column with name " + idxCol.getName() + " not found", + creator.getDatabase(), creator.getTableName(), idx.getName())); } } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/TableCreator.java b/src/main/java/com/healthmarketscience/jackcess/impl/TableCreator.java index 9234700..34765e8 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/TableCreator.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/TableCreator.java @@ -64,6 +64,11 @@ class TableCreator extends DBMutator return _name; } + @Override + String getTableName() { + return getName(); + } + @Override public int getTdefPageNumber() { return _tdefPageNumber; diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java index 925d465..62093c1 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java @@ -1177,7 +1177,7 @@ public class TableImpl implements Table if(isLongVal) { // allocate usage maps for the long value col - Map.Entry umapInfo = addUsageMaps(2); + Map.Entry umapInfo = addUsageMaps(2, null); System.out.println("FOO created umap " + umapInfo); DBMutator.ColumnState colState = mutator.getColumnState(column); colState.setUmapPageNumber(umapInfo.getKey()); @@ -1309,8 +1309,16 @@ public class TableImpl implements Table ByteUtil.forward(tableBuffer, (_indexCount * format.SIZE_INDEX_COLUMN_BLOCK)); - // write index data def + // allocate usage maps and root page DBMutator.IndexDataState idxDataState = mutator.getIndexDataState(index); + int rootPageNumber = getPageChannel().allocateNewPage(); + Map.Entry umapInfo = addUsageMaps(1, rootPageNumber); + System.out.println("FOO created umap " + umapInfo); + idxDataState.setRootPageNumber(rootPageNumber); + idxDataState.setUmapPageNumber(umapInfo.getKey()); + idxDataState.setUmapRowNumber(umapInfo.getValue().byteValue()); + + // write index data def int idxDataDefPos = tableBuffer.position(); ByteUtil.insertEmptyData(tableBuffer, format.SIZE_INDEX_COLUMN_BLOCK); IndexData.writeDefinition(mutator, tableBuffer, idxDataState, null); @@ -1388,6 +1396,7 @@ public class TableImpl implements Table format.SIZE_INDEX_INFO_BLOCK)); int idxDefPos = tableBuffer.position(); + ByteUtil.insertEmptyData(tableBuffer, format.SIZE_INDEX_INFO_BLOCK); IndexImpl.writeDefinition(mutator, index, tableBuffer); // skip existing index names and write new name @@ -1480,7 +1489,9 @@ public class TableImpl implements Table return tableBuffer; } - private Map.Entry addUsageMaps(int numMaps) throws IOException + private Map.Entry addUsageMaps( + int numMaps, Integer firstUsedPage) + throws IOException { JetFormat format = getFormat(); PageChannel pageChannel = getPageChannel(); @@ -1525,6 +1536,13 @@ public class TableImpl implements Table for(int i = 0; i < numMaps; ++i) { umapBuf.putShort(getRowStartOffset(umapRowNum, format), (short)rowStart); umapBuf.put(rowStart, UsageMap.MAP_TYPE_INLINE); + + if(firstUsedPage != null) { + // fill in the first used page of the usage map + umapBuf.putInt(rowStart + 1, firstUsedPage); + umapBuf.put(rowStart + 5, (byte)1); + } + rowStart -= umapRowLength; ++umapRowNum; } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java b/src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java index db672b9..478b55c 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java @@ -59,6 +59,11 @@ public class TableMutator extends DBMutator return _index; } + @Override + String getTableName() { + return _table.getName(); + } + @Override public int getTdefPageNumber() { return _table.getTableDefPageNumber(); @@ -100,6 +105,12 @@ public class TableMutator extends DBMutator return _nextPages; } + void resetTdefInfo() { + _addedTdefLen = 0; + _origTdefLen = 0; + _nextPages.clear(); + } + public ColumnImpl addColumn(ColumnBuilder column) throws IOException { _column = column; @@ -142,10 +153,13 @@ public class TableMutator extends DBMutator if(_idxDataState.getIndexDataNumber() == _table.getIndexCount()) { // we need a new backing index data _table.mutateAddIndexData(this); + resetTdefInfo(); } return _table.mutateAddIndex(this); + // FIXME, need to add data to index!!! + } finally { getPageChannel().finishWrite(); }