diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2011-04-04 03:34:03 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2011-04-04 03:34:03 +0000 |
commit | d4c3d92452914c9c477c64ad443a890d0bf86156 (patch) | |
tree | c17cb0aee86c00e1511548b4a4c3e1b7af4a3a56 /src/java/com/healthmarketscience | |
parent | e287fba735a45589e5b413a4cffe629b403f7a21 (diff) | |
download | jackcess-d4c3d92452914c9c477c64ad443a890d0bf86156.tar.gz jackcess-d4c3d92452914c9c477c64ad443a890d0bf86156.zip |
add mostly functional support for access 2010 new general text sort order
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@544 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience')
4 files changed, 145 insertions, 39 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/GeneralIndexCodes.java b/src/java/com/healthmarketscience/jackcess/GeneralIndexCodes.java new file mode 100644 index 0000000..6e11c60 --- /dev/null +++ b/src/java/com/healthmarketscience/jackcess/GeneralIndexCodes.java @@ -0,0 +1,73 @@ +/* +Copyright (c) 2011 James Ahlborn + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA +*/ + +package com.healthmarketscience.jackcess; + + + +/** + * Various constants used for creating "general" (access 2010+) sort order + * text index entries. + * + * @author James Ahlborn + */ +public class GeneralIndexCodes extends GeneralLegacyIndexCodes { + + // stash the codes in some resource files + private static final String CODES_FILE = + Database.RESOURCE_PATH + "index_codes_gen.txt"; + private static final String EXT_CODES_FILE = + Database.RESOURCE_PATH + "index_codes_ext_gen.txt"; + + private static final class Codes + { + /** handlers for the first 256 chars. use nested class to lazy load the + handlers */ + private static final CharHandler[] _values = loadCodes( + CODES_FILE, FIRST_CHAR, LAST_CHAR); + } + + private static final class ExtCodes + { + /** handlers for the rest of the chars in BMP 0. use nested class to + lazy load the handlers */ + private static final CharHandler[] _values = loadCodes( + EXT_CODES_FILE, FIRST_EXT_CHAR, LAST_EXT_CHAR); + } + + static final GeneralIndexCodes GEN_INSTANCE = new GeneralIndexCodes(); + + GeneralIndexCodes() { + } + + /** + * Returns the CharHandler for the given character. + */ + @Override + CharHandler getCharHandler(char c) + { + if(c <= LAST_CHAR) { + return Codes._values[c]; + } + + int extOffset = asUnsignedChar(c) - asUnsignedChar(FIRST_EXT_CHAR); + return ExtCodes._values[extOffset]; + } + +} diff --git a/src/java/com/healthmarketscience/jackcess/GeneralLegacyIndexCodes.java b/src/java/com/healthmarketscience/jackcess/GeneralLegacyIndexCodes.java index 430942a..6206ba2 100644 --- a/src/java/com/healthmarketscience/jackcess/GeneralLegacyIndexCodes.java +++ b/src/java/com/healthmarketscience/jackcess/GeneralLegacyIndexCodes.java @@ -37,8 +37,8 @@ import java.util.Map; import static com.healthmarketscience.jackcess.ByteUtil.ByteStream; /** - * Various constants used for creating "general legacy" sort order text index - * entries. + * Various constants used for creating "general legacy" (access 2000-2007) + * sort order text index entries. * * @author James Ahlborn */ @@ -75,9 +75,9 @@ public class GeneralLegacyIndexCodes { // stash the codes in some resource files private static final String CODES_FILE = - Database.RESOURCE_PATH + "index_codes.txt"; + Database.RESOURCE_PATH + "index_codes_genleg.txt"; private static final String EXT_CODES_FILE = - Database.RESOURCE_PATH + "index_codes_ext.txt"; + Database.RESOURCE_PATH + "index_codes_ext_genleg.txt"; /** * Enum which classifies the types of char encoding strategies used when @@ -132,7 +132,7 @@ public class GeneralLegacyIndexCodes { * Base class for the handlers which hold the text index character encoding * information. */ - private abstract static class CharHandler { + abstract static class CharHandler { public abstract Type getType(); public byte[] getInlineBytes() { return null; @@ -266,10 +266,10 @@ public class GeneralLegacyIndexCodes { } }; - private static final char FIRST_CHAR = (char)0x0000; - private static final char LAST_CHAR = (char)0x00FF; - private static final char FIRST_EXT_CHAR = LAST_CHAR + 1; - private static final char LAST_EXT_CHAR = (char)0xFFFF; + static final char FIRST_CHAR = (char)0x0000; + static final char LAST_CHAR = (char)0x00FF; + static final char FIRST_EXT_CHAR = LAST_CHAR + 1; + static final char LAST_EXT_CHAR = (char)0xFFFF; private static final class Codes { @@ -286,14 +286,17 @@ public class GeneralLegacyIndexCodes { private static final CharHandler[] _values = loadCodes( EXT_CODES_FILE, FIRST_EXT_CHAR, LAST_EXT_CHAR); } + + static final GeneralLegacyIndexCodes GEN_LEG_INSTANCE = + new GeneralLegacyIndexCodes(); - private GeneralLegacyIndexCodes() { + GeneralLegacyIndexCodes() { } /** * Returns the CharHandler for the given character. */ - static CharHandler getCharHandler(char c) + CharHandler getCharHandler(char c) { if(c <= LAST_CHAR) { return Codes._values[c]; @@ -307,8 +310,8 @@ public class GeneralLegacyIndexCodes { * Loads the CharHandlers for the given range of characters from the * resource file with the given name. */ - private static CharHandler[] loadCodes(String codesFilePath, - char firstChar, char lastChar) + static CharHandler[] loadCodes(String codesFilePath, + char firstChar, char lastChar) { int numCodes = (asUnsignedChar(lastChar) - asUnsignedChar(firstChar)) + 1; CharHandler[] values = new CharHandler[numCodes]; @@ -474,7 +477,7 @@ public class GeneralLegacyIndexCodes { * think this is unnecessary (I think java treats chars as unsigned), but I * did this just to be on the safe side. */ - private static int asUnsignedChar(char c) + static int asUnsignedChar(char c) { return c & 0xFFFF; } @@ -483,7 +486,7 @@ public class GeneralLegacyIndexCodes { * Converts an index value for a text column into the entry value (which * is based on a variety of nifty codes). */ - static void writeNonNullIndexTextValue( + void writeNonNullIndexTextValue( Object value, ByteStream bout, boolean isAscending) throws IOException { diff --git a/src/java/com/healthmarketscience/jackcess/IndexData.java b/src/java/com/healthmarketscience/jackcess/IndexData.java index 6c918be..1540be7 100644 --- a/src/java/com/healthmarketscience/jackcess/IndexData.java +++ b/src/java/com/healthmarketscience/jackcess/IndexData.java @@ -1184,7 +1184,9 @@ public abstract class IndexData { setReadOnly(); return new ReadOnlyColumnDescriptor(col, flags); } - return new TextColumnDescriptor(col, flags); + return(col.getFormat().LEGACY_TEXT_INDEXES ? + new GenLegTextColumnDescriptor(col, flags) : + new GenTextColumnDescriptor(col, flags)); case INT: case LONG: case MONEY: @@ -1194,8 +1196,8 @@ public abstract class IndexData { case SHORT_DATE_TIME: return new FloatingPointColumnDescriptor(col, flags); case NUMERIC: - return (col.getFormat().REVERSE_FIRST_BYTE_IN_DESC_NUMERIC_INDEXES ? - new NewFixedPointColumnDescriptor(col, flags) : + return (col.getFormat().LEGACY_NUMERIC_INDEXES ? + new LegacyFixedPointColumnDescriptor(col, flags) : new FixedPointColumnDescriptor(col, flags)); case BYTE: return new ByteColumnDescriptor(col, flags); @@ -1381,12 +1383,12 @@ public abstract class IndexData { } /** - * ColumnDescriptor for fixed point based columns. + * ColumnDescriptor for fixed point based columns (legacy sort order). */ - private static class FixedPointColumnDescriptor + private static class LegacyFixedPointColumnDescriptor extends ColumnDescriptor { - private FixedPointColumnDescriptor(Column column, byte flags) + private LegacyFixedPointColumnDescriptor(Column column, byte flags) throws IOException { super(column, flags); @@ -1434,10 +1436,10 @@ public abstract class IndexData { /** * ColumnDescriptor for new-style fixed point based columns. */ - private static final class NewFixedPointColumnDescriptor - extends FixedPointColumnDescriptor + private static final class FixedPointColumnDescriptor + extends LegacyFixedPointColumnDescriptor { - private NewFixedPointColumnDescriptor(Column column, byte flags) + private FixedPointColumnDescriptor(Column column, byte flags) throws IOException { super(column, flags); @@ -1516,11 +1518,33 @@ public abstract class IndexData { } /** - * ColumnDescriptor for text based columns. + * ColumnDescriptor for "general legacy" sort order text based columns. + */ + private static final class GenLegTextColumnDescriptor + extends ColumnDescriptor + { + private GenLegTextColumnDescriptor(Column column, byte flags) + throws IOException + { + super(column, flags); + } + + @Override + protected void writeNonNullValue( + Object value, ByteStream bout) + throws IOException + { + GeneralLegacyIndexCodes.GEN_LEG_INSTANCE.writeNonNullIndexTextValue( + value, bout, isAscending()); + } + } + + /** + * ColumnDescriptor for "general" sort order (2010+) text based columns. */ - private static final class TextColumnDescriptor extends ColumnDescriptor + private static final class GenTextColumnDescriptor extends ColumnDescriptor { - private TextColumnDescriptor(Column column, byte flags) + private GenTextColumnDescriptor(Column column, byte flags) throws IOException { super(column, flags); @@ -1531,8 +1555,8 @@ public abstract class IndexData { Object value, ByteStream bout) throws IOException { - GeneralLegacyIndexCodes.writeNonNullIndexTextValue(value, bout, - isAscending()); + GeneralIndexCodes.GEN_INSTANCE.writeNonNullIndexTextValue( + value, bout, isAscending()); } } diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java index f319b24..0ce73ee 100644 --- a/src/java/com/healthmarketscience/jackcess/JetFormat.java +++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java @@ -249,7 +249,8 @@ public abstract class JetFormat { public final int MAX_COLUMN_NAME_LENGTH; public final int MAX_INDEX_NAME_LENGTH; - public final boolean REVERSE_FIRST_BYTE_IN_DESC_NUMERIC_INDEXES; + public final boolean LEGACY_NUMERIC_INDEXES; + public final boolean LEGACY_TEXT_INDEXES; public final Charset CHARSET; @@ -375,7 +376,8 @@ public abstract class JetFormat { MAX_COLUMN_NAME_LENGTH = defineMaxColumnNameLength(); MAX_INDEX_NAME_LENGTH = defineMaxIndexNameLength(); - REVERSE_FIRST_BYTE_IN_DESC_NUMERIC_INDEXES = defineReverseFirstByteInDescNumericIndexes(); + LEGACY_NUMERIC_INDEXES = defineLegacyNumericIndexes(); + LEGACY_TEXT_INDEXES = defineLegacyTextIndexes(); CHARSET = defineCharset(); } @@ -471,7 +473,8 @@ public abstract class JetFormat { protected abstract Charset defineCharset(); - protected abstract boolean defineReverseFirstByteInDescNumericIndexes(); + protected abstract boolean defineLegacyNumericIndexes(); + protected abstract boolean defineLegacyTextIndexes(); protected abstract Map<String,Database.FileFormat> getPossibleFileFormats(); @@ -662,7 +665,10 @@ public abstract class JetFormat { protected int defineMaxIndexNameLength() { return 64; } @Override - protected boolean defineReverseFirstByteInDescNumericIndexes() { return false; } + protected boolean defineLegacyNumericIndexes() { return true; } + + @Override + protected boolean defineLegacyTextIndexes() { return true; } @Override protected Charset defineCharset() { return Charset.defaultCharset(); } @@ -859,7 +865,10 @@ public abstract class JetFormat { protected int defineMaxIndexNameLength() { return 64; } @Override - protected boolean defineReverseFirstByteInDescNumericIndexes() { return false; } + protected boolean defineLegacyNumericIndexes() { return true; } + + @Override + protected boolean defineLegacyTextIndexes() { return true; } @Override protected Charset defineCharset() { return Charset.forName("UTF-16LE"); } @@ -900,7 +909,7 @@ public abstract class JetFormat { } @Override - protected boolean defineReverseFirstByteInDescNumericIndexes() { return true; } + protected boolean defineLegacyNumericIndexes() { return false; } @Override protected Map<String,Database.FileFormat> getPossibleFileFormats() { @@ -914,10 +923,7 @@ public abstract class JetFormat { } @Override - protected boolean defineIndexesSupported() { - // 2010 uses a new text index format (new "General" sort order)... - return false; - } + protected boolean defineLegacyTextIndexes() { return false; } @Override protected Map<String,Database.FileFormat> getPossibleFileFormats() { |