summaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java57
-rw-r--r--src/java/com/healthmarketscience/jackcess/Table.java25
2 files changed, 72 insertions, 10 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java
index f49972d..ebc7809 100644
--- a/src/java/com/healthmarketscience/jackcess/Database.java
+++ b/src/java/com/healthmarketscience/jackcess/Database.java
@@ -81,6 +81,11 @@ public class Database
/** default value for the auto-sync value ({@code true}). this is slower,
but leaves more chance of a useable database in the face of failures. */
public static final boolean DEFAULT_AUTO_SYNC = true;
+
+ /** system property which can be used to make big index support the
+ default. */
+ public static final String USE_BIG_INDEX_PROPERTY =
+ "com.healthmarketscience.jackcess.bigIndex";
/** Batch commit size for copying other result sets into this database */
private static final int COPY_TABLE_BATCH_SIZE = 200;
@@ -225,6 +230,8 @@ public class Database
private Table _relationships;
/** SIDs to use for the ACEs added for new tables */
private final List<byte[]> _newTableSIDs = new ArrayList<byte[]>();
+ /** for now, "big index support" is optional */
+ private boolean _useBigIndex;
/**
* Open an existing Database. If the existing file is not writeable, the
@@ -355,12 +362,27 @@ public class Database
public Table getAccessControlEntries() {
return _accessControlEntries;
}
+
+ /**
+ * Whether or not big index support is enabled for tables.
+ */
+ public boolean doUseBigIndex() {
+ return _useBigIndex;
+ }
+
+ /**
+ * Set whether or not big index support is enabled for tables.
+ */
+ public void setUseBigIndex(boolean useBigIndex) {
+ _useBigIndex = useBigIndex;
+ }
/**
* Read the system catalog
*/
private void readSystemCatalog() throws IOException {
- _systemCatalog = readTable(TABLE_SYSTEM_CATALOG, PAGE_SYSTEM_CATALOG);
+ _systemCatalog = readTable(TABLE_SYSTEM_CATALOG, PAGE_SYSTEM_CATALOG,
+ defaultUseBigIndex());
for(Map<String,Object> row :
Cursor.createCursor(_systemCatalog).iterable(
SYSTEM_CATALOG_COLUMNS))
@@ -371,7 +393,8 @@ public class Database
addTable((String) row.get(CAT_COL_NAME), (Integer) row.get(CAT_COL_ID));
} else if(TABLE_SYSTEM_ACES.equals(name)) {
int pageNumber = (Integer)row.get(CAT_COL_ID);
- _accessControlEntries = readTable(TABLE_SYSTEM_ACES, pageNumber);
+ _accessControlEntries = readTable(TABLE_SYSTEM_ACES, pageNumber,
+ defaultUseBigIndex());
} else if(TABLE_SYSTEM_RELATIONSHIPS.equals(name)) {
_relationshipsPageNumber = (Integer)row.get(CAT_COL_ID);
}
@@ -418,12 +441,23 @@ public class Database
public Iterator<Table> iterator() {
return new TableIterator();
}
-
+
/**
* @param name Table name
* @return The table, or null if it doesn't exist
*/
public Table getTable(String name) throws IOException {
+ return getTable(name, defaultUseBigIndex());
+ }
+
+ /**
+ * @param name Table name
+ * @param useBigIndex whether or not "big index support" should be enabled
+ * for the table (this value will override any other
+ * settings)
+ * @return The table, or null if it doesn't exist
+ */
+ public Table getTable(String name, boolean useBigIndex) throws IOException {
TableInfo tableInfo = lookupTable(name);
@@ -431,7 +465,7 @@ public class Database
return null;
}
- return readTable(tableInfo.tableName, tableInfo.pageNumber);
+ return readTable(tableInfo.tableName, tableInfo.pageNumber, useBigIndex);
}
/**
@@ -490,7 +524,8 @@ public class Database
throw new IOException("Could not find system relationships table");
}
_relationships = readTable(TABLE_SYSTEM_RELATIONSHIPS,
- _relationshipsPageNumber);
+ _relationshipsPageNumber,
+ defaultUseBigIndex());
}
int nameCmp = table1.getName().compareTo(table2.getName());
@@ -661,7 +696,7 @@ public class Database
/**
* Reads a table with the given name from the given pageNumber.
*/
- private Table readTable(String name, int pageNumber)
+ private Table readTable(String name, int pageNumber, boolean useBigIndex)
throws IOException
{
_pageChannel.readPage(_buffer, pageNumber);
@@ -670,7 +705,7 @@ public class Database
throw new IOException("Looking for " + name + " at page " + pageNumber +
", but page type is " + pageType);
}
- return new Table(this, _buffer, pageNumber, name);
+ return new Table(this, _buffer, pageNumber, name, useBigIndex);
}
/**
@@ -929,6 +964,14 @@ public class Database
}
/**
+ * Returns {@code true} if "big index support" has been enabled explicity on
+ * the this Database or via a system property, {@code false} otherwise.
+ */
+ public boolean defaultUseBigIndex() {
+ return doUseBigIndex() || Boolean.getBoolean(USE_BIG_INDEX_PROPERTY);
+ }
+
+ /**
* Utility class for storing table page number and actual name.
*/
private static class TableInfo
diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java
index 511286e..5600d06 100644
--- a/src/java/com/healthmarketscience/jackcess/Table.java
+++ b/src/java/com/healthmarketscience/jackcess/Table.java
@@ -122,6 +122,8 @@ public class Table
every call) */
private final TempBufferHolder _multiRowBufferH =
TempBufferHolder.newHolder(TempBufferHolder.Type.NONE, true);
+ /** for now, "big index support" is optional */
+ private final boolean _useBigIndex;
/** common cursor for iterating through the table, kept here for historic
reasons */
@@ -137,6 +139,7 @@ public class Table
_database = null;
_tableDefPageNumber = PageChannel.INVALID_PAGE_NUMBER;
_name = null;
+ _useBigIndex = false;
setColumns(columns);
}
@@ -145,14 +148,17 @@ public class Table
* @param tableBuffer Buffer to read the table with
* @param pageNumber Page number of the table definition
* @param name Table name
+ * @param useBigIndex whether or not "big index support" should be enabled
+ * for the table
*/
protected Table(Database database, ByteBuffer tableBuffer,
- int pageNumber, String name)
+ int pageNumber, String name, boolean useBigIndex)
throws IOException
{
_database = database;
_tableDefPageNumber = pageNumber;
_name = name;
+ _useBigIndex = useBigIndex;
int nextPage = tableBuffer.getInt(getFormat().OFFSET_NEXT_TABLE_DEF_PAGE);
ByteBuffer nextPageBuffer = null;
while (nextPage != 0) {
@@ -182,6 +188,10 @@ public class Table
return _name;
}
+ public boolean doUseBigIndex() {
+ return _useBigIndex;
+ }
+
public int getMaxColumnCount() {
return _maxColumnCount;
}
@@ -958,8 +968,7 @@ public class Table
(getFormat().OFFSET_INDEX_DEF_BLOCK +
(i * getFormat().SIZE_INDEX_DEFINITION) + 4);
int uniqueEntryCount = tableBuffer.getInt(uniqueEntryCountOffset);
- _indexes.add(new SimpleIndex(this, uniqueEntryCount,
- uniqueEntryCountOffset));
+ _indexes.add(createIndex(uniqueEntryCount, uniqueEntryCountOffset));
}
int colOffset = getFormat().OFFSET_INDEX_DEF_BLOCK +
@@ -1045,6 +1054,16 @@ public class Table
// reset to end of index info
tableBuffer.position(idxEndOffset);
}
+
+ /**
+ * Creates an index with the given initial info.
+ */
+ private Index createIndex(int uniqueEntryCount, int uniqueEntryCountOffset)
+ {
+ return(_useBigIndex ?
+ new BigIndex(this, uniqueEntryCount, uniqueEntryCountOffset) :
+ new SimpleIndex(this, uniqueEntryCount, uniqueEntryCountOffset));
+ }
/**
* Writes the given page data to the given page number, clears any other