]> source.dussan.org Git - jackcess.git/commitdiff
actually write added column usage maps correctly
authorJames Ahlborn <jtahlborn@yahoo.com>
Tue, 3 May 2016 03:57:33 +0000 (03:57 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Tue, 3 May 2016 03:57:33 +0000 (03:57 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@986 f203690c-595d-4dc9-a70b-905162fa7fd2

src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java
src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java

index 8a137ea3dc5c93bee5395fec20745afc9c1c5ed6..6caf27c78939ac23783823a2e2d1f6a03911b38e 100644 (file)
@@ -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);
   }
 
index a789404dbcff841acb0f3bf724b6595e20be23da..18fee248a0ded1d548986580da70e7c289aa95bd 100644 (file)
@@ -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<Integer,Integer> 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<Integer> knownPages = new TreeSet<Integer>(Collections.reverseOrder());
     collectUsageMapPages(knownPages);
+    System.out.println("FOO found umap pages " + knownPages);
 
     ByteBuffer umapBuf = pageChannel.createPageBuffer();
     for(Integer pageNum : knownPages) {