aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2016-06-21 02:30:17 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2016-06-21 02:30:17 +0000
commit523a31dad217c71e70f759893fa36becdfe08f8e (patch)
tree628e1d17bf07b0de0775e6f91ff0136bf9f5544e /src/main
parent01e9427fe979b0b2003399cccb9676cb6820c61d (diff)
downloadjackcess-523a31dad217c71e70f759893fa36becdfe08f8e.tar.gz
jackcess-523a31dad217c71e70f759893fa36becdfe08f8e.zip
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
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/DBMutator.java2
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java9
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/TableCreator.java5
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java24
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java14
5 files changed, 46 insertions, 8 deletions
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
@@ -65,6 +65,11 @@ class TableCreator extends DBMutator
}
@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<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;
}
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
@@ -60,6 +60,11 @@ public class TableMutator extends DBMutator
}
@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();
}