]> source.dussan.org Git - jackcess.git/commitdiff
get add index def functional
authorJames Ahlborn <jtahlborn@yahoo.com>
Tue, 21 Jun 2016 02:30:17 +0000 (02:30 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Tue, 21 Jun 2016 02:30:17 +0000 (02:30 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@998 f203690c-595d-4dc9-a70b-905162fa7fd2

src/main/java/com/healthmarketscience/jackcess/impl/DBMutator.java
src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java
src/main/java/com/healthmarketscience/jackcess/impl/TableCreator.java
src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java
src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java

index e5991918c6f35a8c177283b2f19dfdd04eba45c7..374af2b71fc409e9f7e013af5eaed1879158379e 100644 (file)
@@ -137,6 +137,8 @@ abstract class DBMutator
     return null;
   }
 
+  abstract String getTableName();
+
   public abstract int getTdefPageNumber();
 
   abstract short getColumnNumber(String colName);
index 3961a9b519f7c473406d828216eb4c23405eced8..ea6708dee938fffcce47ff7a368d8acf4895b506 100644 (file)
@@ -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()));
         }
       }
          
index 92347004c38f8a34507dd7e60c32f3c3effcc993..34765e84ae787df9a48237c0ee52adb3a090dba1 100644 (file)
@@ -64,6 +64,11 @@ class TableCreator extends DBMutator
     return _name;
   }
 
+  @Override
+  String getTableName() {
+    return getName();
+  }
+  
   @Override
   public int getTdefPageNumber() {
     return _tdefPageNumber;
index 925d465a1335ed555a4df796098cf9ae235622b4..62093c123e87bc5e7dec28d64e3ef9e273a92d65 100644 (file)
@@ -1177,7 +1177,7 @@ public class TableImpl implements Table
     if(isLongVal) {
 
       // allocate usage maps for the long value col
-      Map.Entry<Integer,Integer> umapInfo = addUsageMaps(2);
+      Map.Entry<Integer,Integer> 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<Integer,Integer> 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<Integer,Integer> addUsageMaps(int numMaps) throws IOException
+  private Map.Entry<Integer,Integer> 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;
     }
index db672b932fc7f41815f02c9d41c90fe7993339e3..478b55c201e863589e4a9668a018af29adf85ba4 100644 (file)
@@ -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();
     }