From: James Ahlborn Date: Sat, 16 Mar 2013 01:23:35 +0000 (+0000) Subject: add more details to unsupported index exceptions X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=85a420ac034a513368adffba6185a97d858350a1;p=jackcess.git add more details to unsupported index exceptions git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jackcess-2@691 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java b/src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java index e477327..0407c15 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java +++ b/src/java/com/healthmarketscience/jackcess/impl/IndexCursorImpl.java @@ -146,10 +146,11 @@ public class IndexCursorImpl extends CursorImpl implements IndexCursor "JetFormat " + table.getFormat() + " does not currently support index lookups"); } - if(index.getIndexData().isReadOnly()) { + if(index.getIndexData().getUnsupportedReason() != null) { throw new IllegalArgumentException( "Given index " + index + - " is not usable for indexed lookups because it is read-only"); + " is not usable for indexed lookups due to " + + index.getIndexData().getUnsupportedReason()); } IndexCursorImpl cursor = new IndexCursorImpl(table, index, index.cursor(startRow, startInclusive, diff --git a/src/java/com/healthmarketscience/jackcess/impl/IndexData.java b/src/java/com/healthmarketscience/jackcess/impl/IndexData.java index 4533fa5..f4e95ee 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/IndexData.java +++ b/src/java/com/healthmarketscience/jackcess/impl/IndexData.java @@ -37,15 +37,13 @@ import java.util.Comparator; import java.util.List; import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import static com.healthmarketscience.jackcess.impl.IndexCodes.*; -import static com.healthmarketscience.jackcess.impl.ByteUtil.ByteStream; +import com.healthmarketscience.jackcess.ColumnBuilder; import com.healthmarketscience.jackcess.Index; -import com.healthmarketscience.jackcess.RowId; import com.healthmarketscience.jackcess.IndexBuilder; -import com.healthmarketscience.jackcess.ColumnBuilder; +import static com.healthmarketscience.jackcess.impl.ByteUtil.ByteStream; +import static com.healthmarketscience.jackcess.impl.IndexCodes.*; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * Access table index data. This is the actual data which backs a logical @@ -179,8 +177,8 @@ public class IndexData { private final int _maxPageEntrySize; /** whether or not this index data is backing a primary key logical index */ private boolean _primaryKey; - /** FIXME, for SimpleIndex, we can't write multi-page indexes or indexes using the entry compression scheme */ - private boolean _readOnly; + /** if non-null, the reason why we cannot create entries for this index */ + private String _unsupportedReason; /** Cache which manages the index pages */ private final IndexPageCache _pageCache; @@ -322,12 +320,13 @@ public class IndexData { return _rootPageNumber; } - protected void setReadOnly() { - _readOnly = true; + private void setUnsupportedReason(String reason) { + _unsupportedReason = reason; + LOG.warn(reason + ", making read-only"); } - protected boolean isReadOnly() { - return _readOnly; + String getUnsupportedReason() { + return _unsupportedReason; } protected int getMaxPageEntrySize() { @@ -395,9 +394,9 @@ public class IndexData { // make sure we've parsed the entries initialize(); - if(_readOnly) { + if(_unsupportedReason != null) { throw new UnsupportedOperationException( - "FIXME cannot write indexes of this type yet, see Database javadoc for info on enabling large index support"); + "Cannot write indexes of this type due to " + _unsupportedReason); } _pageCache.write(); } @@ -1205,9 +1204,8 @@ public class IndexData { return new GenTextColumnDescriptor(col, flags); } // unsupported sort order - LOG.warn("Unsupported collating sort order " + sortOrder + - " for text index, making read-only"); - setReadOnly(); + setUnsupportedReason("unsupported collating sort order " + sortOrder + + " for text index"); return new ReadOnlyColumnDescriptor(col, flags); case INT: case LONG: @@ -1230,10 +1228,9 @@ public class IndexData { return new GuidColumnDescriptor(col, flags); default: - // FIXME we can't modify this index at this point in time - LOG.warn("Unsupported data type " + col.getType() + - " for index, making read-only"); - setReadOnly(); + // we can't modify this index at this point in time + setUnsupportedReason("unsupported data type " + col.getType() + + " for index"); return new ReadOnlyColumnDescriptor(col, flags); } } @@ -1624,7 +1621,7 @@ public class IndexData { /** * ColumnDescriptor for columns which we cannot currently write. */ - private static final class ReadOnlyColumnDescriptor extends ColumnDescriptor + private final class ReadOnlyColumnDescriptor extends ColumnDescriptor { private ReadOnlyColumnDescriptor(ColumnImpl column, byte flags) throws IOException @@ -1636,7 +1633,8 @@ public class IndexData { protected void writeNonNullValue(Object value, ByteStream bout) throws IOException { - throw new UnsupportedOperationException("should not be called"); + throw new UnsupportedOperationException( + "Cannot write indexes of this type due to " + _unsupportedReason); } }