diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2016-06-18 14:36:55 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2016-06-18 14:36:55 +0000 |
commit | 01e9427fe979b0b2003399cccb9676cb6820c61d (patch) | |
tree | 65c15ef85614f34bd7a522fd5239241ca2a2c1a7 /src | |
parent | 8f482230a1bc1a459e20dabc42649e0adff27107 (diff) | |
download | jackcess-01e9427fe979b0b2003399cccb9676cb6820c61d.tar.gz jackcess-01e9427fe979b0b2003399cccb9676cb6820c61d.zip |
implement check for determining backing index data
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@997 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java | 4 | ||||
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java | 57 |
2 files changed, 56 insertions, 5 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java index 97e073c..925d465 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java @@ -496,6 +496,10 @@ public class TableImpl implements Table return _logicalIndexCount; } + int getIndexCount() { + return _indexCount; + } + List<ColumnImpl> getAutoNumberColumns() { return _autoNumColumns; } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java b/src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java index b9e508f..db672b9 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/TableMutator.java @@ -134,15 +134,15 @@ public class TableMutator extends DBMutator _index.setIndexNumber(indexNumber); // find backing index state - - // FIXME, writeme! - + findIndexDataState(); getPageChannel().startExclusiveWrite(); try { - // FIXME, maybe add index data - // _table.mutateAddIndexData(this); + if(_idxDataState.getIndexDataNumber() == _table.getIndexCount()) { + // we need a new backing index data + _table.mutateAddIndexData(this); + } return _table.mutateAddIndex(this); @@ -217,4 +217,51 @@ public class TableMutator extends DBMutator } return idxNames; } + + private void findIndexDataState() { + + _idxDataState = new IndexDataState(); + _idxDataState.addIndex(_index); + + // search for an existing index which matches the given index (in terms of + // the backing data) + for(IndexData idxData : _table.getIndexDatas()) { + if(sameIndexData(_index, idxData)) { + _idxDataState.setIndexDataNumber(idxData.getIndexDataNumber()); + return; + } + } + + // no matches found, need new index data state + _idxDataState.setIndexDataNumber(_table.getIndexCount()); + } + + private static boolean sameIndexData(IndexBuilder idx1, IndexData idx2) { + // index data can be combined if flags match and columns (and col flags) + // match + if(idx1.getFlags() != idx2.getIndexFlags()) { + return false; + } + + if(idx1.getColumns().size() != idx2.getColumns().size()) { + return false; + } + + for(int i = 0; i < idx1.getColumns().size(); ++i) { + IndexBuilder.Column col1 = idx1.getColumns().get(i); + IndexData.ColumnDescriptor col2 = idx2.getColumns().get(i); + + if(!sameIndexData(col1, col2)) { + return false; + } + } + + return true; + } + + private static boolean sameIndexData( + IndexBuilder.Column col1, IndexData.ColumnDescriptor col2) { + return (col1.getName().equals(col2.getName()) && + (col1.getFlags() == col2.getFlags())); + } } |