From f243a9931563d6912fde914709fc4c99a1263e2c Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Tue, 3 May 2016 03:57:33 +0000 Subject: [PATCH] actually write added column usage maps correctly git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@986 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/impl/LongValueColumnImpl.java | 1 + .../jackcess/impl/TableImpl.java | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java index 8a137ea..6caf27c 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java @@ -68,6 +68,7 @@ class LongValueColumnImpl extends ColumnImpl @Override void setUsageMaps(UsageMap ownedPages, UsageMap freeSpacePages) { + System.out.println("FOO setting col umaps " + ownedPages); _lvalBufferH = new UmapLongValueBufferHolder(ownedPages, freeSpacePages); } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java index a789404..18fee24 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java @@ -980,7 +980,6 @@ public class TableImpl implements Table // now, create the table definition - PageChannel pageChannel = creator.getPageChannel(); ByteBuffer buffer = PageChannel.createBuffer(Math.max(totalTableDefSize, format.PAGE_SIZE)); writeTableDefinitionHeader(creator, buffer, totalTableDefSize); @@ -1180,27 +1179,53 @@ public class TableImpl implements Table ByteUtil.forward(tableBuffer, tableBuffer.getShort()); } ByteUtil.insertEmptyData(tableBuffer, nameByteLen); + System.out.println("FOO pre name " + tableBuffer.position()); writeName(tableBuffer, column.getName(), mutator.getCharset()); + System.out.println("FOO post name " + tableBuffer.position()); int umapPos = -1; if(isLongVal) { // allocate usage maps for the long value col Map.Entry umapInfo = addUsageMaps(2); + System.out.println("FOO created umap " + umapInfo); int umapPageNum = umapInfo.getKey(); int umapRow1 = umapInfo.getValue(); int umapRow2 = umapRow1 + 1; // skip past index defs + System.out.println("FOO pre move " + tableBuffer.position()); ByteUtil.forward(tableBuffer, (_indexDatas.size() * - (format.SIZE_INDEX_DEFINITION + - format.SIZE_INDEX_COLUMN_BLOCK))); + format.SIZE_INDEX_COLUMN_BLOCK)); + System.out.println("FOO moved to " + tableBuffer.position()); ByteUtil.forward(tableBuffer, (_indexes.size() * format.SIZE_INDEX_INFO_BLOCK)); + System.out.println("FOO moved to " + tableBuffer.position()); for(int i = 0; i < _indexes.size(); ++i) { - ByteUtil.forward(tableBuffer, tableBuffer.getShort()); + short len = tableBuffer.getShort(); + System.out.println("FOO skipping " + len); + ByteUtil.forward(tableBuffer, len); } + // skip existing usage maps + while(tableBuffer.remaining() >= 2) { + if(tableBuffer.getShort() == IndexData.COLUMN_UNUSED) { + // found end of tdef, we want to insert before this + ByteUtil.forward(tableBuffer, -2); + break; + } + + ByteUtil.forward(tableBuffer, 8); + + // keep reading ... + } + + // write new column usage map info + System.out.println("FOO about to write " + tableBuffer.position()); + umapPos = tableBuffer.position(); + ByteUtil.insertEmptyData(tableBuffer, 10); + tableBuffer.putShort(column.getColumnNumber()); + // owned pages umap (both are on same page) tableBuffer.put((byte)umapRow1); ByteUtil.put3ByteInt(tableBuffer, umapPageNum); @@ -1212,7 +1237,7 @@ public class TableImpl implements Table // sanity check the updates if((origTdefLen + addedLen) != tableBuffer.limit()) { throw new IllegalStateException( - withErrorContext("Failed update table definition")); + withErrorContext("Failed update table definition (unexpected length)")); } // before writing the new table def, create the column @@ -1305,6 +1330,7 @@ public class TableImpl implements Table // numbers), so we sort in reverse order. Set knownPages = new TreeSet(Collections.reverseOrder()); collectUsageMapPages(knownPages); + System.out.println("FOO found umap pages " + knownPages); ByteBuffer umapBuf = pageChannel.createPageBuffer(); for(Integer pageNum : knownPages) { -- 2.39.5