From 30c880936a84e5649ac7ae83c9e4429bf04a0394 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Tue, 12 Mar 2013 12:11:26 +0000 Subject: [PATCH] clean up a bunch of loose ends in the interfaces; get unit tests compiling git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jackcess-2@677 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../healthmarketscience/jackcess/Column.java | 7 + .../jackcess/ColumnImpl.java | 5 - .../jackcess/CursorBuilder.java | 211 ++++++++++++++++-- .../jackcess/Database.java | 11 + .../jackcess/DatabaseImpl.java | 49 ++-- .../jackcess/ExportFilter.java | 2 +- .../jackcess/ExportUtil.java | 42 ++-- .../jackcess/FKEnforcer.java | 10 +- .../jackcess/ImportUtil.java | 36 +-- .../healthmarketscience/jackcess/Joiner.java | 32 +-- .../jackcess/RowFilter.java | 3 +- .../jackcess/SimpleExportFilter.java | 2 +- .../healthmarketscience/jackcess/Table.java | 24 +- .../jackcess/TableImpl.java | 82 +------ .../jackcess/complex/ComplexColumnInfo.java | 8 +- .../jackcess/BigIndexTest.java | 50 ++--- .../jackcess/CodecHandlerTest.java | 2 +- .../jackcess/ComplexColumnTest.java | 8 +- .../jackcess/CursorBuilderTest.java | 22 +- .../jackcess/CursorTest.java | 74 +++--- .../jackcess/DatabaseTest.java | 65 +++--- .../jackcess/ErrorHandlerTest.java | 12 +- .../jackcess/FKEnforcerTest.java | 12 +- .../jackcess/ImportTest.java | 6 +- .../jackcess/IndexCodesTest.java | 22 +- .../jackcess/IndexTest.java | 77 +++---- .../jackcess/JetFormatTest.java | 11 +- .../jackcess/PropertiesTest.java | 4 +- .../jackcess/RowFilterTest.java | 4 +- .../jackcess/TableTest.java | 59 ++--- .../jackcess/UsageMapTest.java | 4 +- 31 files changed, 544 insertions(+), 412 deletions(-) diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index f05b58d..7c90a78 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -137,6 +137,13 @@ public interface Column * @usage _general_method_ */ public PropertyMap getProperties() throws IOException; + + /** + * Returns the column which tracks the version history for an "append only" + * column. + * @usage _intermediate_method_ + */ + public Column getVersionHistoryColumn(); public Object setRowValue(Object[] rowArray, Object value); diff --git a/src/java/com/healthmarketscience/jackcess/ColumnImpl.java b/src/java/com/healthmarketscience/jackcess/ColumnImpl.java index e036db4..2abbad4 100644 --- a/src/java/com/healthmarketscience/jackcess/ColumnImpl.java +++ b/src/java/com/healthmarketscience/jackcess/ColumnImpl.java @@ -456,11 +456,6 @@ public class ColumnImpl implements Column, Comparable { return (getVersionHistoryColumn() != null); } - /** - * Returns the column which tracks the version history for an "append only" - * column. - * @usage _intermediate_method_ - */ public ColumnImpl getVersionHistoryColumn() { return _textInfo._versionHistoryCol; } diff --git a/src/java/com/healthmarketscience/jackcess/CursorBuilder.java b/src/java/com/healthmarketscience/jackcess/CursorBuilder.java index 5b84534..c7f985a 100644 --- a/src/java/com/healthmarketscience/jackcess/CursorBuilder.java +++ b/src/java/com/healthmarketscience/jackcess/CursorBuilder.java @@ -33,6 +33,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Map; /** @@ -58,7 +59,7 @@ public class CursorBuilder { /** whether to start at beginning or end of cursor */ private boolean _beforeFirst = true; /** optional save point to restore to the cursor */ - private CursorImpl.SavepointImpl _savepoint; + private Cursor.Savepoint _savepoint; /** ColumnMatcher to be used when matching column values */ private ColumnMatcher _columnMatcher; @@ -87,7 +88,7 @@ public class CursorBuilder { /** * Sets a savepoint to restore for the initial position of the cursor. */ - public CursorBuilder restoreSavepoint(CursorImpl.SavepointImpl savepoint) { + public CursorBuilder restoreSavepoint(Cursor.Savepoint savepoint) { _savepoint = savepoint; return this; } @@ -126,9 +127,9 @@ public class CursorBuilder { * @throws IllegalArgumentException if no index can be found on the table * with the given columns */ - public CursorBuilder setIndexByColumns(ColumnImpl... columns) { + public CursorBuilder setIndexByColumns(Column... columns) { List colNames = new ArrayList(); - for(ColumnImpl col : columns) { + for(Column col : columns) { colNames.add(col.getName()); } return setIndexByColumns(colNames); @@ -177,7 +178,7 @@ public class CursorBuilder { *

* A valid index must be specified before calling this method. */ - public CursorBuilder setSpecificRow(Object[] specificRow) { + public CursorBuilder setSpecificRow(Object... specificRow) { setStartRow(specificRow); setEndRow(specificRow); return this; @@ -202,7 +203,7 @@ public class CursorBuilder { *

* A valid index must be specified before calling this method. */ - public CursorBuilder setStartRow(Object[] startRow) { + public CursorBuilder setStartRow(Object... startRow) { _startRow = startRow; return this; } @@ -234,7 +235,7 @@ public class CursorBuilder { *

* A valid index must be specified before calling this method. */ - public CursorBuilder setEndRow(Object[] endRow) { + public CursorBuilder setEndRow(Object... endRow) { _endRow = endRow; return this; } @@ -273,16 +274,15 @@ public class CursorBuilder { * Returns a new cursor for the table, constructed to the given * specifications. */ - public CursorImpl toCursor() - throws IOException + public Cursor toCursor() throws IOException { CursorImpl cursor = null; if(_index == null) { cursor = CursorImpl.createCursor(_table); } else { cursor = CursorImpl.createIndexCursor(_table, _index, - _startRow, _startRowInclusive, - _endRow, _endRowInclusive); + _startRow, _startRowInclusive, + _endRow, _endRowInclusive); } cursor.setColumnMatcher(_columnMatcher); if(_savepoint == null) { @@ -299,10 +299,195 @@ public class CursorBuilder { * Returns a new index cursor for the table, constructed to the given * specifications. */ - public IndexCursorImpl toIndexCursor() - throws IOException + public IndexCursor toIndexCursor() throws IOException { return (IndexCursorImpl)toCursor(); } + /** + * Creates a normal, un-indexed cursor for the given table. + * @param table the table over which this cursor will traverse + */ + public static Cursor createCursor(Table table) throws IOException { + return new CursorBuilder(table).toCursor(); + } + + /** + * Creates an indexed cursor for the given table. + *

+ * Note, index based table traversal may not include all rows, as certain + * types of indexes do not include all entries (namely, some indexes ignore + * null entries, see {@link Index#shouldIgnoreNulls}). + * + * @param table the table over which this cursor will traverse + * @param index index for the table which will define traversal order as + * well as enhance certain lookups + */ + public static IndexCursor createCursor(Table table, Index index) + throws IOException + { + return new CursorBuilder(table).setIndex(index).toIndexCursor(); + } + + /** + * Creates an indexed cursor for the given table, narrowed to the given + * range. + *

+ * Note, index based table traversal may not include all rows, as certain + * types of indexes do not include all entries (namely, some indexes ignore + * null entries, see {@link Index#shouldIgnoreNulls}). + * + * @param table the table over which this cursor will traverse + * @param index index for the table which will define traversal order as + * well as enhance certain lookups + * @param startRow the first row of data for the cursor (inclusive), or + * {@code null} for the first entry + * @param endRow the last row of data for the cursor (inclusive), or + * {@code null} for the last entry + */ + public static IndexCursor createCursor(Table table, Index index, + Object[] startRow, Object[] endRow) + throws IOException + { + return new CursorBuilder(table).setIndex(index) + .setStartRow(startRow) + .setEndRow(endRow) + .toIndexCursor(); + } + + /** + * Creates an indexed cursor for the given table, narrowed to the given + * range. + *

+ * Note, index based table traversal may not include all rows, as certain + * types of indexes do not include all entries (namely, some indexes ignore + * null entries, see {@link Index#shouldIgnoreNulls}). + * + * @param table the table over which this cursor will traverse + * @param index index for the table which will define traversal order as + * well as enhance certain lookups + * @param startRow the first row of data for the cursor, or {@code null} for + * the first entry + * @param startInclusive whether or not startRow is inclusive or exclusive + * @param endRow the last row of data for the cursor, or {@code null} for + * the last entry + * @param endInclusive whether or not endRow is inclusive or exclusive + */ + public static IndexCursor createCursor(Table table, Index index, + Object[] startRow, + boolean startInclusive, + Object[] endRow, + boolean endInclusive) + throws IOException + { + return new CursorBuilder(table).setIndex(index) + .setStartRow(startRow) + .setStartRowInclusive(startInclusive) + .setEndRow(endRow) + .setEndRowInclusive(endInclusive) + .toIndexCursor(); + } + + /** + * Convenience method for finding a specific row in a table which matches a + * given row "pattern". See {@link Cursor#findFirstRow(Map)} for details on + * the rowPattern. + *

+ * Warning, this method always starts searching from the beginning of + * the Table (you cannot use it to find successive matches). + * + * @param table the table to search + * @param rowPattern pattern to be used to find the row + * @return the matching row or {@code null} if a match could not be found. + */ + public static Map findRow(Table table, Map rowPattern) + throws IOException + { + Cursor cursor = createCursor(table); + if(cursor.findFirstRow(rowPattern)) { + return cursor.getCurrentRow(); + } + return null; + } + + /** + * Convenience method for finding a specific row in a table which matches a + * given row "pattern". See {@link Cursor#findFirstRow(Column,Object)} for + * details on the pattern. + *

+ * Note, a {@code null} result value is ambiguous in that it could imply no + * match or a matching row with {@code null} for the desired value. If + * distinguishing this situation is important, you will need to use a Cursor + * directly instead of this convenience method. + * + * @param table the table to search + * @param column column whose value should be returned + * @param columnPattern column being matched by the valuePattern + * @param valuePattern value from the columnPattern which will match the + * desired row + * @return the matching row or {@code null} if a match could not be found. + */ + public static Object findValue(Table table, Column column, + Column columnPattern, Object valuePattern) + throws IOException + { + Cursor cursor = createCursor(table); + if(cursor.findFirstRow(columnPattern, valuePattern)) { + return cursor.getCurrentRowValue(column); + } + return null; + } + + /** + * Convenience method for finding a specific row in an indexed table which + * matches a given row "pattern". See {@link Cursor#findFirstRow(Map)} for + * details on the rowPattern. + *

+ * Warning, this method always starts searching from the beginning of + * the Table (you cannot use it to find successive matches). + * + * @param table the table to search + * @param index index to assist the search + * @param rowPattern pattern to be used to find the row + * @return the matching row or {@code null} if a match could not be found. + */ + public static Map findRow(Table table, Index index, + Map rowPattern) + throws IOException + { + Cursor cursor = createCursor(table, index); + if(cursor.findFirstRow(rowPattern)) { + return cursor.getCurrentRow(); + } + return null; + } + + /** + * Convenience method for finding a specific row in a table which matches a + * given row "pattern". See {@link Cursor#findFirstRow(Column,Object)} for + * details on the pattern. + *

+ * Note, a {@code null} result value is ambiguous in that it could imply no + * match or a matching row with {@code null} for the desired value. If + * distinguishing this situation is important, you will need to use a Cursor + * directly instead of this convenience method. + * + * @param table the table to search + * @param index index to assist the search + * @param column column whose value should be returned + * @param columnPattern column being matched by the valuePattern + * @param valuePattern value from the columnPattern which will match the + * desired row + * @return the matching row or {@code null} if a match could not be found. + */ + public static Object findValue(Table table, Index index, Column column, + Column columnPattern, Object valuePattern) + throws IOException + { + Cursor cursor = createCursor(table, index); + if(cursor.findFirstRow(columnPattern, valuePattern)) { + return cursor.getCurrentRowValue(column); + } + return null; + } } diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 84a75fb..40a6ee7 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -228,6 +228,17 @@ public interface Database extends Iterable, Closeable, Flushable */ public String getDatabasePassword() throws IOException; + /** + * Create a new table in this database + * @param name Name of the table to create in this database + * @param linkedDbName path to the linked database + * @param linkedTableName name of the table in the linked database + * @usage _general_method_ + */ + public void createLinkedTable(String name, String linkedDbName, + String linkedTableName) + throws IOException; + /** * Flushes any current changes to the database file (and any linked * databases) to disk. diff --git a/src/java/com/healthmarketscience/jackcess/DatabaseImpl.java b/src/java/com/healthmarketscience/jackcess/DatabaseImpl.java index 43cf0ee..e89948c 100644 --- a/src/java/com/healthmarketscience/jackcess/DatabaseImpl.java +++ b/src/java/com/healthmarketscience/jackcess/DatabaseImpl.java @@ -951,7 +951,6 @@ public class DatabaseImpl implements Database List indexes) throws IOException { - // FIXME, rework table creation if(lookupTable(name) != null) { throw new IllegalArgumentException( "Cannot create table with name of existing table"); @@ -960,16 +959,10 @@ public class DatabaseImpl implements Database new TableCreator(this, name, columns, indexes).createTable(); } - /** - * Create a new table in this database - * @param name Name of the table to create - * @usage _general_method_ - */ public void createLinkedTable(String name, String linkedDbName, String linkedTableName) throws IOException { - // FIXME, rework table creation if(lookupTable(name) != null) { throw new IllegalArgumentException( "Cannot create linked table with name of existing table"); @@ -1037,7 +1030,7 @@ public class DatabaseImpl implements Database List relationships = new ArrayList(); - CursorImpl cursor = createCursorWithOptionalIndex( + Cursor cursor = createCursorWithOptionalIndex( _relationships, REL_COL_FROM_TABLE, table1.getName()); collectRelationships(cursor, table1, table2, relationships); cursor = createCursorWithOptionalIndex( @@ -1216,7 +1209,7 @@ public class DatabaseImpl implements Database * given cursor and adds them to the given list. */ private static void collectRelationships( - CursorImpl cursor, TableImpl fromTable, TableImpl toTable, + Cursor cursor, TableImpl fromTable, TableImpl toTable, List relationships) { for(Map row : cursor) { @@ -1341,7 +1334,7 @@ public class DatabaseImpl implements Database { // search for ACEs matching the tableParentId. use the index on the // objectId column if found (should be there) - CursorImpl cursor = createCursorWithOptionalIndex( + Cursor cursor = createCursorWithOptionalIndex( getAccessControlEntries(), ACE_COL_OBJECT_ID, _tableParentId); for(Map row : cursor) { @@ -1390,7 +1383,7 @@ public class DatabaseImpl implements Database * Creates a Cursor restricted to the given column value if possible (using * an existing index), otherwise a simple table cursor. */ - private static CursorImpl createCursorWithOptionalIndex( + private static Cursor createCursorWithOptionalIndex( TableImpl table, String colName, Object colValue) throws IOException { @@ -1776,7 +1769,7 @@ public class DatabaseImpl implements Database public Integer findObjectId(Integer parentId, String name) throws IOException { - CursorImpl cur = findRow(parentId, name); + Cursor cur = findRow(parentId, name); if(cur == null) { return null; } @@ -1788,7 +1781,7 @@ public class DatabaseImpl implements Database Collection columns) throws IOException { - CursorImpl cur = findRow(parentId, name); + Cursor cur = findRow(parentId, name); return ((cur != null) ? cur.getCurrentRow(columns) : null); } @@ -1796,7 +1789,7 @@ public class DatabaseImpl implements Database Integer objectId, Collection columns) throws IOException { - CursorImpl cur = findRow(objectId); + Cursor cur = findRow(objectId); return ((cur != null) ? cur.getCurrentRow(columns) : null); } @@ -1819,13 +1812,13 @@ public class DatabaseImpl implements Database } } - protected abstract CursorImpl findRow(Integer parentId, String name) + protected abstract Cursor findRow(Integer parentId, String name) throws IOException; - protected abstract CursorImpl findRow(Integer objectId) + protected abstract Cursor findRow(Integer objectId) throws IOException; - protected abstract CursorImpl getTableNamesCursor() throws IOException; + protected abstract Cursor getTableNamesCursor() throws IOException; public abstract TableInfo lookupTable(String tableName) throws IOException; @@ -1848,10 +1841,10 @@ public class DatabaseImpl implements Database */ private final class DefaultTableFinder extends TableFinder { - private final IndexCursorImpl _systemCatalogCursor; - private IndexCursorImpl _systemCatalogIdCursor; + private final IndexCursor _systemCatalogCursor; + private IndexCursor _systemCatalogIdCursor; - private DefaultTableFinder(IndexCursorImpl systemCatalogCursor) { + private DefaultTableFinder(IndexCursor systemCatalogCursor) { _systemCatalogCursor = systemCatalogCursor; } @@ -1864,7 +1857,7 @@ public class DatabaseImpl implements Database } @Override - protected CursorImpl findRow(Integer parentId, String name) + protected Cursor findRow(Integer parentId, String name) throws IOException { return (_systemCatalogCursor.findFirstRowByEntry(parentId, name) ? @@ -1872,7 +1865,7 @@ public class DatabaseImpl implements Database } @Override - protected CursorImpl findRow(Integer objectId) throws IOException + protected Cursor findRow(Integer objectId) throws IOException { initIdCursor(); return (_systemCatalogIdCursor.findFirstRowByEntry(objectId) ? @@ -1905,7 +1898,7 @@ public class DatabaseImpl implements Database } @Override - protected CursorImpl getTableNamesCursor() throws IOException { + protected Cursor getTableNamesCursor() throws IOException { return new CursorBuilder(_systemCatalog) .setIndex(_systemCatalogCursor.getIndex()) .setStartEntry(_tableParentId, IndexData.MIN_VALUE) @@ -1934,14 +1927,14 @@ public class DatabaseImpl implements Database */ private final class FallbackTableFinder extends TableFinder { - private final CursorImpl _systemCatalogCursor; + private final Cursor _systemCatalogCursor; - private FallbackTableFinder(CursorImpl systemCatalogCursor) { + private FallbackTableFinder(Cursor systemCatalogCursor) { _systemCatalogCursor = systemCatalogCursor; } @Override - protected CursorImpl findRow(Integer parentId, String name) + protected Cursor findRow(Integer parentId, String name) throws IOException { Map rowPat = new HashMap(); @@ -1952,7 +1945,7 @@ public class DatabaseImpl implements Database } @Override - protected CursorImpl findRow(Integer objectId) throws IOException + protected Cursor findRow(Integer objectId) throws IOException { ColumnImpl idCol = _systemCatalog.getColumn(CAT_COL_ID); return (_systemCatalogCursor.findFirstRow(idCol, objectId) ? @@ -1993,7 +1986,7 @@ public class DatabaseImpl implements Database } @Override - protected CursorImpl getTableNamesCursor() throws IOException { + protected Cursor getTableNamesCursor() throws IOException { return _systemCatalogCursor; } diff --git a/src/java/com/healthmarketscience/jackcess/ExportFilter.java b/src/java/com/healthmarketscience/jackcess/ExportFilter.java index 47cc3bb..86600cc 100644 --- a/src/java/com/healthmarketscience/jackcess/ExportFilter.java +++ b/src/java/com/healthmarketscience/jackcess/ExportFilter.java @@ -56,7 +56,7 @@ public interface ExportFilter { * modified and returned * @return the columns to use when creating the export file */ - public List filterColumns(List columns) + public List filterColumns(List columns) throws IOException; /** diff --git a/src/java/com/healthmarketscience/jackcess/ExportUtil.java b/src/java/com/healthmarketscience/jackcess/ExportUtil.java index 69647fa..841fb2e 100644 --- a/src/java/com/healthmarketscience/jackcess/ExportUtil.java +++ b/src/java/com/healthmarketscience/jackcess/ExportUtil.java @@ -70,7 +70,7 @@ public class ExportUtil { * @see #exportAll(Database,File,String) * @see Builder */ - public static void exportAll(DatabaseImpl db, File dir) + public static void exportAll(Database db, File dir) throws IOException { exportAll(db, dir, DEFAULT_FILE_EXT); } @@ -90,7 +90,7 @@ public class ExportUtil { * @see #exportFile(Database,String,File,boolean,String,char,ExportFilter) * @see Builder */ - public static void exportAll(DatabaseImpl db, File dir, + public static void exportAll(Database db, File dir, String ext) throws IOException { for (String tableName : db.getTableNames()) { exportFile(db, tableName, new File(dir, tableName + "." + ext), false, @@ -115,7 +115,7 @@ public class ExportUtil { * @see #exportFile(Database,String,File,boolean,String,char,ExportFilter) * @see Builder */ - public static void exportAll(DatabaseImpl db, File dir, + public static void exportAll(Database db, File dir, String ext, boolean header) throws IOException { for (String tableName : db.getTableNames()) { @@ -147,7 +147,7 @@ public class ExportUtil { * @see #exportFile(Database,String,File,boolean,String,char,ExportFilter) * @see Builder */ - public static void exportAll(DatabaseImpl db, File dir, + public static void exportAll(Database db, File dir, String ext, boolean header, String delim, char quote, ExportFilter filter) throws IOException { @@ -172,7 +172,7 @@ public class ExportUtil { * @see #exportFile(Database,String,File,boolean,String,char,ExportFilter) * @see Builder */ - public static void exportFile(DatabaseImpl db, String tableName, + public static void exportFile(Database db, String tableName, File f) throws IOException { exportFile(db, tableName, f, false, DEFAULT_DELIMITER, DEFAULT_QUOTE_CHAR, SimpleExportFilter.INSTANCE); @@ -201,7 +201,7 @@ public class ExportUtil { * @see #exportWriter(Database,String,BufferedWriter,boolean,String,char,ExportFilter) * @see Builder */ - public static void exportFile(DatabaseImpl db, String tableName, + public static void exportFile(Database db, String tableName, File f, boolean header, String delim, char quote, ExportFilter filter) throws IOException { BufferedWriter out = null; @@ -235,7 +235,7 @@ public class ExportUtil { * @see #exportWriter(Database,String,BufferedWriter,boolean,String,char,ExportFilter) * @see Builder */ - public static void exportWriter(DatabaseImpl db, String tableName, + public static void exportWriter(Database db, String tableName, BufferedWriter out) throws IOException { exportWriter(db, tableName, out, false, DEFAULT_DELIMITER, DEFAULT_QUOTE_CHAR, SimpleExportFilter.INSTANCE); @@ -263,12 +263,12 @@ public class ExportUtil { * @see #exportWriter(Cursor,BufferedWriter,boolean,String,char,ExportFilter) * @see Builder */ - public static void exportWriter(DatabaseImpl db, String tableName, + public static void exportWriter(Database db, String tableName, BufferedWriter out, boolean header, String delim, char quote, ExportFilter filter) throws IOException { - exportWriter(CursorImpl.createCursor(db.getTable(tableName)), out, header, + exportWriter(CursorBuilder.createCursor(db.getTable(tableName)), out, header, delim, quote, filter); } @@ -290,7 +290,7 @@ public class ExportUtil { * * @see Builder */ - public static void exportWriter(CursorImpl cursor, + public static void exportWriter(Cursor cursor, BufferedWriter out, boolean header, String delim, char quote, ExportFilter filter) throws IOException @@ -306,8 +306,8 @@ public class ExportUtil { // allow filter to setup per-call state filter = filter.init(); - List origCols = cursor.getTable().getColumns(); - List columns = new ArrayList(origCols); + List origCols = cursor.getTable().getColumns(); + List columns = new ArrayList(origCols); columns = filter.filterColumns(columns); Collection columnNames = null; @@ -315,14 +315,14 @@ public class ExportUtil { // columns have been filtered columnNames = new HashSet(); - for (ColumnImpl c : columns) { + for (Column c : columns) { columnNames.add(c.getName()); } } // print the header row (if desired) if (header) { - for (Iterator iter = columns.iterator(); iter.hasNext();) { + for (Iterator iter = columns.iterator(); iter.hasNext();) { writeValue(out, iter.next().getName(), quote, needsQuotePattern); @@ -409,29 +409,29 @@ public class ExportUtil { */ public static class Builder { - private DatabaseImpl _db; + private Database _db; private String _tableName; private String _ext = DEFAULT_FILE_EXT; - private CursorImpl _cursor; + private Cursor _cursor; private String _delim = DEFAULT_DELIMITER; private char _quote = DEFAULT_QUOTE_CHAR; private ExportFilter _filter = SimpleExportFilter.INSTANCE; private boolean _header; - public Builder(DatabaseImpl db) { + public Builder(Database db) { this(db, null); } - public Builder(DatabaseImpl db, String tableName) { + public Builder(Database db, String tableName) { _db = db; _tableName = tableName; } - public Builder(CursorImpl cursor) { + public Builder(Cursor cursor) { _cursor = cursor; } - public Builder setDatabase(DatabaseImpl db) { + public Builder setDatabase(Database db) { _db = db; return this; } @@ -441,7 +441,7 @@ public class ExportUtil { return this; } - public Builder setCursor(CursorImpl cursor) { + public Builder setCursor(Cursor cursor) { _cursor = cursor; return this; } diff --git a/src/java/com/healthmarketscience/jackcess/FKEnforcer.java b/src/java/com/healthmarketscience/jackcess/FKEnforcer.java index e6f1e5f..a1a17aa 100644 --- a/src/java/com/healthmarketscience/jackcess/FKEnforcer.java +++ b/src/java/com/healthmarketscience/jackcess/FKEnforcer.java @@ -236,9 +236,9 @@ final class FKEnforcer Object[] newFromRow) throws IOException { - IndexCursorImpl toCursor = joiner.getToCursor(); - List fromCols = joiner.getColumns(); - List toCols = joiner.getToIndex().getColumns(); + IndexCursor toCursor = joiner.getToCursor(); + List fromCols = joiner.getColumns(); + List toCols = joiner.getToIndex().getColumns(); Object[] toRow = new Object[joiner.getToTable().getColumnCount()]; for(Iterator> iter = joiner.findRows( @@ -270,8 +270,8 @@ final class FKEnforcer Object[] newRow) { Table fromTable = joiner.getFromTable(); - for(IndexData.ColumnDescriptor iCol : joiner.getColumns()) { - ColumnImpl col = iCol.getColumn(); + for(Index.Column iCol : joiner.getColumns()) { + Column col = iCol.getColumn(); if(!MATCHER.matches(fromTable, col.getName(), col.getRowValue(oldRow), col.getRowValue(newRow))) { return true; diff --git a/src/java/com/healthmarketscience/jackcess/ImportUtil.java b/src/java/com/healthmarketscience/jackcess/ImportUtil.java index be41678..3468588 100644 --- a/src/java/com/healthmarketscience/jackcess/ImportUtil.java +++ b/src/java/com/healthmarketscience/jackcess/ImportUtil.java @@ -112,7 +112,7 @@ public class ImportUtil * @see #importResultSet(ResultSet,Database,String,ImportFilter) * @see Builder */ - public static String importResultSet(ResultSet source, DatabaseImpl db, + public static String importResultSet(ResultSet source, Database db, String name) throws SQLException, IOException { @@ -134,7 +134,7 @@ public class ImportUtil * @see #importResultSet(ResultSet,Database,String,ImportFilter,boolean) * @see Builder */ - public static String importResultSet(ResultSet source, DatabaseImpl db, + public static String importResultSet(ResultSet source, Database db, String name, ImportFilter filter) throws SQLException, IOException { @@ -156,7 +156,7 @@ public class ImportUtil * * @see Builder */ - public static String importResultSet(ResultSet source, DatabaseImpl db, + public static String importResultSet(ResultSet source, Database db, String name, ImportFilter filter, boolean useExistingTable) throws SQLException, IOException @@ -213,7 +213,7 @@ public class ImportUtil * @see #importFile(File,Database,String,String,ImportFilter) * @see Builder */ - public static String importFile(File f, DatabaseImpl db, String name, + public static String importFile(File f, Database db, String name, String delim) throws IOException { @@ -236,7 +236,7 @@ public class ImportUtil * @see #importReader(BufferedReader,Database,String,String,ImportFilter) * @see Builder */ - public static String importFile(File f, DatabaseImpl db, String name, + public static String importFile(File f, Database db, String name, String delim, ImportFilter filter) throws IOException { @@ -264,7 +264,7 @@ public class ImportUtil * @see #importReader(BufferedReader,Database,String,String,ImportFilter,boolean) * @see Builder */ - public static String importFile(File f, DatabaseImpl db, String name, + public static String importFile(File f, Database db, String name, String delim, char quote, ImportFilter filter, boolean useExistingTable) @@ -294,7 +294,7 @@ public class ImportUtil * @see #importReader(BufferedReader,Database,String,String,char,ImportFilter,boolean,boolean) * @see Builder */ - public static String importFile(File f, DatabaseImpl db, String name, + public static String importFile(File f, Database db, String name, String delim, char quote, ImportFilter filter, boolean useExistingTable, @@ -332,7 +332,7 @@ public class ImportUtil * @see #importReader(BufferedReader,Database,String,String,ImportFilter) * @see Builder */ - public static String importReader(BufferedReader in, DatabaseImpl db, + public static String importReader(BufferedReader in, Database db, String name, String delim) throws IOException { @@ -355,7 +355,7 @@ public class ImportUtil * @see #importReader(BufferedReader,Database,String,String,ImportFilter,boolean) * @see Builder */ - public static String importReader(BufferedReader in, DatabaseImpl db, + public static String importReader(BufferedReader in, Database db, String name, String delim, ImportFilter filter) throws IOException @@ -382,7 +382,7 @@ public class ImportUtil * * @see Builder */ - public static String importReader(BufferedReader in, DatabaseImpl db, + public static String importReader(BufferedReader in, Database db, String name, String delim, ImportFilter filter, boolean useExistingTable) @@ -412,7 +412,7 @@ public class ImportUtil * * @see Builder */ - public static String importReader(BufferedReader in, DatabaseImpl db, + public static String importReader(BufferedReader in, Database db, String name, String delim, char quote, ImportFilter filter, boolean useExistingTable) @@ -441,7 +441,7 @@ public class ImportUtil * * @see Builder */ - public static String importReader(BufferedReader in, DatabaseImpl db, + public static String importReader(BufferedReader in, Database db, String name, String delim, char quote, ImportFilter filter, boolean useExistingTable, boolean header) @@ -595,7 +595,7 @@ public class ImportUtil /** * Returns a new table with a unique name and the given table definition. */ - private static Table createUniqueTable(DatabaseImpl db, String name, + private static Table createUniqueTable(Database db, String name, List columns, ResultSetMetaData md, ImportFilter filter) @@ -608,7 +608,7 @@ public class ImportUtil name = baseName + (counter++); } - db.createTable(name, filter.filterColumns(columns, md)); + ((DatabaseImpl)db).createTable(name, filter.filterColumns(columns, md)); return db.getTable(name); } @@ -618,7 +618,7 @@ public class ImportUtil */ public static class Builder { - private DatabaseImpl _db; + private Database _db; private String _tableName; private String _delim = ExportUtil.DEFAULT_DELIMITER; private char _quote = ExportUtil.DEFAULT_QUOTE_CHAR; @@ -626,16 +626,16 @@ public class ImportUtil private boolean _useExistingTable; private boolean _header = true; - public Builder(DatabaseImpl db) { + public Builder(Database db) { this(db, null); } - public Builder(DatabaseImpl db, String tableName) { + public Builder(Database db, String tableName) { _db = db; _tableName = tableName; } - public Builder setDatabaseImpl(DatabaseImpl db) { + public Builder setDatabase(Database db) { _db = db; return this; } diff --git a/src/java/com/healthmarketscience/jackcess/Joiner.java b/src/java/com/healthmarketscience/jackcess/Joiner.java index 81820dc..63be33e 100644 --- a/src/java/com/healthmarketscience/jackcess/Joiner.java +++ b/src/java/com/healthmarketscience/jackcess/Joiner.java @@ -34,12 +34,12 @@ import java.util.Map; */ public class Joiner { - private final IndexImpl _fromIndex; - private final List _fromCols; - private final IndexCursorImpl _toCursor; + private final Index _fromIndex; + private final List _fromCols; + private final IndexCursor _toCursor; private final Object[] _entryValues; - private Joiner(IndexImpl fromIndex, IndexCursorImpl toCursor) + private Joiner(Index fromIndex, IndexCursor toCursor) { _fromIndex = fromIndex; _fromCols = _fromIndex.getColumns(); @@ -56,7 +56,7 @@ public class Joiner * @throws IllegalArgumentException if there is no relationship between the * given tables */ - public static Joiner create(TableImpl fromTable, TableImpl toTable) + public static Joiner create(Table fromTable, Table toTable) throws IOException { return create(fromTable.getForeignKeyIndex(toTable)); @@ -69,11 +69,11 @@ public class Joiner * * @param fromIndex the index backing one side of a foreign-key relationship */ - public static Joiner create(IndexImpl fromIndex) + public static Joiner create(Index fromIndex) throws IOException { - IndexImpl toIndex = fromIndex.getReferencedIndex(); - IndexCursorImpl toCursor = IndexCursorImpl.createCursor( + Index toIndex = fromIndex.getReferencedIndex(); + IndexCursor toCursor = CursorBuilder.createCursor( toIndex.getTable(), toIndex); // text lookups are always case-insensitive toCursor.setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE); @@ -90,27 +90,27 @@ public class Joiner return create(getToTable(), getFromTable()); } - public TableImpl getFromTable() { + public Table getFromTable() { return getFromIndex().getTable(); } - public IndexImpl getFromIndex() { + public Index getFromIndex() { return _fromIndex; } - public TableImpl getToTable() { + public Table getToTable() { return getToCursor().getTable(); } - public IndexImpl getToIndex() { + public Index getToIndex() { return getToCursor().getIndex(); } - public IndexCursorImpl getToCursor() { + public IndexCursor getToCursor() { return _toCursor; } - public List getColumns() { + public List getColumns() { // note, this list is already unmodifiable, no need to re-wrap return _fromCols; } @@ -310,7 +310,7 @@ public class Joiner String fromType = "] (primary)"; String toType = "] (secondary)"; - if(!_fromIndex.getReference().isPrimaryTable()) { + if(!((IndexImpl)_fromIndex).getReference().isPrimaryTable()) { fromType = "] (secondary)"; toType = "] (primary)"; } @@ -324,7 +324,7 @@ public class Joiner sb.append(fromType); sb.append(" to ").append(getToTable().getName()).append("["); - List toCols = _toCursor.getIndex().getColumns(); + List toCols = _toCursor.getIndex().getColumns(); sb.append(toCols.get(0).getName()); for(int i = 1; i < toCols.size(); ++i) { sb.append(",").append(toCols.get(i).getName()); diff --git a/src/java/com/healthmarketscience/jackcess/RowFilter.java b/src/java/com/healthmarketscience/jackcess/RowFilter.java index 3a537af..dc29047 100644 --- a/src/java/com/healthmarketscience/jackcess/RowFilter.java +++ b/src/java/com/healthmarketscience/jackcess/RowFilter.java @@ -101,7 +101,8 @@ public abstract class RowFilter * @return a filter which matches table rows which match the value in the * row pattern */ - public static RowFilter matchPattern(final Column columnPattern, final Object valuePattern) + public static RowFilter matchPattern(final Column columnPattern, + final Object valuePattern) { return new RowFilter() { @Override diff --git a/src/java/com/healthmarketscience/jackcess/SimpleExportFilter.java b/src/java/com/healthmarketscience/jackcess/SimpleExportFilter.java index ad04eef..644e5eb 100644 --- a/src/java/com/healthmarketscience/jackcess/SimpleExportFilter.java +++ b/src/java/com/healthmarketscience/jackcess/SimpleExportFilter.java @@ -47,7 +47,7 @@ public class SimpleExportFilter implements ExportFilter { return this; } - public List filterColumns(List columns) throws IOException { + public List filterColumns(List columns) throws IOException { return columns; } diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 8244c17..c743d8a 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -141,6 +141,11 @@ public interface Table extends Iterable> */ public Object[] asUpdateRow(Map rowMap); + /** + * @usage _general_method_ + */ + public int getRowCount(); + /** * Adds a single row to this table and writes it to disk. The values are * expected to be given in the order that the Columns are listed by the @@ -180,7 +185,24 @@ public interface Table extends Iterable> public void addRows(List rows) throws IOException; /** + * After calling this method, {@link #getNextRow} will return the first row + * in the table, see {@link Cursor#reset} (uses the default cursor). * @usage _general_method_ */ - public int getRowCount(); + public void reset(); + + /** + * @return The next row in this table (Column name -> Column value) (uses + * the default cursor) + * @usage _general_method_ + */ + public Map getNextRow() throws IOException; + + /** + * @return a simple Cursor, initialized on demand and held by this table. + * This cursor backs the row traversal methods available on the + * Table interface. For advanced Table traversal and manipulation, + * use the Cursor directly. + */ + public Cursor getDefaultCursor(); } diff --git a/src/java/com/healthmarketscience/jackcess/TableImpl.java b/src/java/com/healthmarketscience/jackcess/TableImpl.java index 26b8d9f..21c5e60 100644 --- a/src/java/com/healthmarketscience/jackcess/TableImpl.java +++ b/src/java/com/healthmarketscience/jackcess/TableImpl.java @@ -169,9 +169,9 @@ public class TableImpl implements Table /** foreign-key enforcer for this table */ private final FKEnforcer _fkEnforcer; - /** common cursor for iterating through the table, kept here for historic - reasons */ - private CursorImpl _cursor; + /** default cursor for iterating through the table, kept here for basic + table traversal */ + private CursorImpl _defaultCursor; /** * Only used by unit tests @@ -438,30 +438,15 @@ public class TableImpl implements Table return _logicalIndexCount; } - private CursorImpl getInternalCursor() { - if(_cursor == null) { - _cursor = CursorImpl.createCursor(this); + public CursorImpl getDefaultCursor() { + if(_defaultCursor == null) { + _defaultCursor = CursorImpl.createCursor(this); } - return _cursor; + return _defaultCursor; } - /** - * After calling this method, getNextRow will return the first row in the - * table, see {@link Cursor#reset}. - * @usage _general_method_ - */ public void reset() { - // FIXME remove internal cursor? - getInternalCursor().reset(); - } - - /** - * Delete the current row (retrieved by a call to {@link #getNextRow()}). - * @usage _general_method_ - */ - public void deleteCurrentRow() throws IOException { - // FIXME remove internal cursor? - getInternalCursor().deleteCurrentRow(); + getDefaultCursor().reset(); } /** @@ -521,25 +506,8 @@ public class TableImpl implements Table updateTableDefinition(-1); } - /** - * @return The next row in this table (Column name -> Column value) - * @usage _general_method_ - */ public Map getNextRow() throws IOException { - // FIXME remove internal cursor? - return getNextRow(null); - } - - /** - * @param columnNames Only column names in this collection will be returned - * @return The next row in this table (Column name -> Column value) - * @usage _general_method_ - */ - public Map getNextRow(Collection columnNames) - throws IOException - { - // FIXME remove internal cursor? - return getInternalCursor().getNextRow(columnNames); + return getDefaultCursor().getNextRow(); } /** @@ -889,24 +857,8 @@ public class TableImpl implements Table */ public Iterator> iterator() { - // FIXME remove internal cursor? - return iterator(null); - } - - /** - * Calls reset on this table and returns a modifiable - * Iterator which will iterate through all the rows of this table, returning - * only the given columns. Use of the Iterator follows the same - * restrictions as a call to getNextRow. - * @throws IllegalStateException if an IOException is thrown by one of the - * operations, the actual exception will be contained within - * @usage _general_method_ - */ - public Iterator> iterator(Collection columnNames) - { - // FIXME remove internal cursor? reset(); - return getInternalCursor().iterator(columnNames); + return getDefaultCursor().iterator(); } /** @@ -1390,20 +1342,6 @@ public class TableImpl implements Table // Update tdef page updateTableDefinition(rows.size()); } - - /** - * Updates the current row to the new values. - *

- * Note, if this table has an auto-number column(s), the existing value(s) - * will be maintained, unchanged. - * - * @param row new row values for the current row. - * @usage _general_method_ - */ - public void updateCurrentRow(Object... row) throws IOException { - // FIXME remove internal cursor? - getInternalCursor().updateCurrentRow(row); - } /** * Update the row on which the given rowState is currently positioned. diff --git a/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java index af80531..800d189 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java +++ b/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java @@ -33,7 +33,7 @@ import com.healthmarketscience.jackcess.ColumnImpl; import com.healthmarketscience.jackcess.CursorBuilder; import com.healthmarketscience.jackcess.DataType; import com.healthmarketscience.jackcess.DatabaseImpl; -import com.healthmarketscience.jackcess.IndexCursorImpl; +import com.healthmarketscience.jackcess.IndexCursor; import com.healthmarketscience.jackcess.JetFormat; import com.healthmarketscience.jackcess.PageChannel; import com.healthmarketscience.jackcess.TableImpl; @@ -63,8 +63,8 @@ public abstract class ComplexColumnInfo private final List _typeCols; private final ColumnImpl _pkCol; private final ColumnImpl _complexValFkCol; - private IndexCursorImpl _pkCursor; - private IndexCursorImpl _complexValIdCursor; + private IndexCursor _pkCursor; + private IndexCursor _complexValIdCursor; protected ComplexColumnInfo(ColumnImpl column, int complexTypeId, TableImpl typeObjTable, TableImpl flatTable) @@ -111,7 +111,7 @@ public abstract class ComplexColumnInfo DatabaseImpl db = column.getDatabase(); TableImpl complexColumns = db.getSystemComplexColumns(); - IndexCursorImpl cursor = IndexCursorImpl.createCursor( + IndexCursor cursor = CursorBuilder.createCursor( complexColumns, complexColumns.getPrimaryKeyIndex()); if(!cursor.findFirstRowByEntry(complexTypeId)) { throw new IOException( diff --git a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java index f6d1c0a..d8cb5cb 100644 --- a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java @@ -48,30 +48,14 @@ public class BigIndexTest extends TestCase { public BigIndexTest(String name) { super(name); } - - @Override - protected void setUp() { - _oldBigIndexValue = System.getProperty(Database.USE_BIG_INDEX_PROPERTY); - System.setProperty(Database.USE_BIG_INDEX_PROPERTY, - Boolean.TRUE.toString()); - } - - @Override - protected void tearDown() { - if (_oldBigIndexValue != null) { - System.setProperty(Database.USE_BIG_INDEX_PROPERTY, _oldBigIndexValue); - } else { - System.clearProperty(Database.USE_BIG_INDEX_PROPERTY); - } - } public void testComplexIndex() throws Exception { for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX, true)) { // this file has an index with "compressed" entries and node pages Database db = open(testDB); - Table t = db.getTable("Table1"); - Index index = t.getIndex("CD_AGENTE"); + TableImpl t = (TableImpl)db.getTable("Table1"); + IndexImpl index = t.getIndex("CD_AGENTE"); assertFalse(index.isInitialized()); assertEquals(512, countRows(t)); assertEquals(512, index.getIndexData().getEntryCount()); @@ -84,8 +68,8 @@ public class BigIndexTest extends TestCase { for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.BIG_INDEX)) { // this file has an index with "compressed" entries and node pages Database db = open(testDB); - Table t = db.getTable("Table1"); - Index index = t.getIndex("col1"); + TableImpl t = (TableImpl)db.getTable("Table1"); + IndexImpl index = t.getIndex("col1"); assertFalse(index.isInitialized()); assertEquals(0, countRows(t)); assertEquals(0, index.getIndexData().getEntryCount()); @@ -98,7 +82,7 @@ public class BigIndexTest extends TestCase { // copy to temp file and attempt to edit db = openCopy(testDB); - t = db.getTable("Table1"); + t = (TableImpl)db.getTable("Table1"); index = t.getIndex("col1"); System.out.println("BigIndexTest: Index type: " + @@ -131,10 +115,10 @@ public class BigIndexTest extends TestCase { } } - ((BigIndexData)index.getIndexData()).validate(); + index.getIndexData().validate(); db.flush(); - t = db.getTable("Table1"); + t = (TableImpl)db.getTable("Table1"); index = t.getIndex("col1"); // make sure all entries are there and correctly ordered @@ -142,7 +126,7 @@ public class BigIndexTest extends TestCase { String prevValue = firstValue; int rowCount = 0; List firstTwo = new ArrayList(); - for(Map row : Cursor.createIndexCursor(t, index)) { + for(Map row : CursorBuilder.createCursor(t, index)) { String origVal = (String)row.get("col1"); String val = origVal; if(val == null) { @@ -159,10 +143,10 @@ public class BigIndexTest extends TestCase { assertEquals(2000, rowCount); - ((BigIndexData)index.getIndexData()).validate(); + index.getIndexData().validate(); // delete an entry in the middle - Cursor cursor = Cursor.createIndexCursor(t, index); + Cursor cursor = CursorBuilder.createCursor(t, index); for(int i = 0; i < (rowCount / 2); ++i) { assertTrue(cursor.moveToNextRow()); } @@ -176,17 +160,17 @@ public class BigIndexTest extends TestCase { cursor.deleteCurrentRow(); } - ((BigIndexData)index.getIndexData()).validate(); + index.getIndexData().validate(); List found = new ArrayList(); - for(Map row : Cursor.createIndexCursor(t, index)) { + for(Map row : CursorBuilder.createCursor(t, index)) { found.add((String)row.get("col1")); } assertEquals(firstTwo, found); // remove remaining entries - cursor = Cursor.createCursor(t); + cursor = CursorBuilder.createCursor(t); for(int i = 0; i < 2; ++i) { assertTrue(cursor.moveToNextRow()); cursor.deleteCurrentRow(); @@ -195,7 +179,7 @@ public class BigIndexTest extends TestCase { assertFalse(cursor.moveToNextRow()); assertFalse(cursor.moveToPreviousRow()); - ((BigIndexData)index.getIndexData()).validate(); + index.getIndexData().validate(); // add 50 (pseudo) random entries to the table rand = new Random(42L); @@ -208,14 +192,14 @@ public class BigIndexTest extends TestCase { t.addRow(nextVal, "this is some row data " + nextInt); } - ((BigIndexData)index.getIndexData()).validate(); + index.getIndexData().validate(); - cursor = Cursor.createIndexCursor(t, index); + cursor = CursorBuilder.createCursor(t, index); while(cursor.moveToNextRow()) { cursor.deleteCurrentRow(); } - ((BigIndexData)index.getIndexData()).validate(); + index.getIndexData().validate(); db.close(); diff --git a/test/src/java/com/healthmarketscience/jackcess/CodecHandlerTest.java b/test/src/java/com/healthmarketscience/jackcess/CodecHandlerTest.java index edcbf09..4562e2a 100644 --- a/test/src/java/com/healthmarketscience/jackcess/CodecHandlerTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/CodecHandlerTest.java @@ -75,7 +75,7 @@ public class CodecHandlerTest extends TestCase { for(Database.FileFormat ff : SUPPORTED_FILEFORMATS) { Database db = DatabaseTest.create(ff); - int pageSize = db.getFormat().PAGE_SIZE; + int pageSize = ((DatabaseImpl)db).getFormat().PAGE_SIZE; File dbFile = db.getFile(); db.close(); diff --git a/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java b/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java index 019dd74..9b78b22 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java @@ -96,7 +96,7 @@ public class ComplexColumnTest extends TestCase checkVersions(row8ValFk.get(), row8ValFk, "row8-memo", "row8-memo", upTime); - Cursor cursor = Cursor.createCursor(t1); + Cursor cursor = CursorBuilder.createCursor(t1); assertTrue(cursor.findFirstRow(t1.getColumn("id"), "row3")); ComplexValueForeignKey row3ValFk = (ComplexValueForeignKey) cursor.getCurrentRowValue(verCol); @@ -190,7 +190,7 @@ public class ComplexColumnTest extends TestCase getFileBytes("test_data.txt"), null, null); checkAttachments(row8ValFk.get(), row8ValFk, "test_data.txt"); - Cursor cursor = Cursor.createCursor(t1); + Cursor cursor = CursorBuilder.createCursor(t1); assertTrue(cursor.findFirstRow(t1.getColumn("id"), "row4")); ComplexValueForeignKey row4ValFk = (ComplexValueForeignKey) cursor.getCurrentRowValue(col); @@ -266,7 +266,7 @@ public class ComplexColumnTest extends TestCase row8ValFk.addMultiValue("value2"); checkMultiValues(row8ValFk.get(), row8ValFk, "value1", "value2"); - Cursor cursor = Cursor.createCursor(t1); + Cursor cursor = CursorBuilder.createCursor(t1); assertTrue(cursor.findFirstRow(t1.getColumn("id"), "row2")); ComplexValueForeignKey row2ValFk = (ComplexValueForeignKey) cursor.getCurrentRowValue(col); @@ -413,7 +413,7 @@ public class ComplexColumnTest extends TestCase UnsupportedValue v = values.get(i); assertEquals(1, v.getValues().size()); Object rv = v.get("Value"); - assertTrue(Column.isRawData(rv)); + assertTrue(ColumnImpl.isRawData(rv)); assertEquals(value, rv.toString()); } } diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java index c1872fa..bf1b6ef 100644 --- a/test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/CursorBuilderTest.java @@ -59,20 +59,20 @@ public class CursorBuilderTest extends TestCase { Database db = CursorTest.createTestIndexTable(indexCursorDB); Table table = db.getTable("test"); - Index idx = table.getIndexes().get(0); + IndexImpl idx = (IndexImpl)table.getIndexes().get(0); - Cursor expected = Cursor.createCursor(table); + Cursor expected = CursorBuilder.createCursor(table); Cursor found = new CursorBuilder(table).toCursor(); assertCursor(expected, found); - expected = Cursor.createIndexCursor(table, idx); + expected = CursorBuilder.createCursor(table, idx); found = new CursorBuilder(table) .setIndex(idx) .toCursor(); assertCursor(expected, found); - expected = Cursor.createIndexCursor(table, idx); + expected = CursorBuilder.createCursor(table, idx); found = new CursorBuilder(table) .setIndexByName("id") .toCursor(); @@ -86,7 +86,7 @@ public class CursorBuilderTest extends TestCase { // success } - expected = Cursor.createIndexCursor(table, idx); + expected = CursorBuilder.createCursor(table, idx); found = new CursorBuilder(table) .setIndexByColumns(table.getColumn("id")) .toCursor(); @@ -108,21 +108,21 @@ public class CursorBuilderTest extends TestCase { // success } - expected = Cursor.createCursor(table); + expected = CursorBuilder.createCursor(table); expected.beforeFirst(); found = new CursorBuilder(table) .beforeFirst() .toCursor(); assertCursor(expected, found); - expected = Cursor.createCursor(table); + expected = CursorBuilder.createCursor(table); expected.afterLast(); found = new CursorBuilder(table) .afterLast() .toCursor(); assertCursor(expected, found); - expected = Cursor.createCursor(table); + expected = CursorBuilder.createCursor(table); expected.moveNextRows(2); Cursor.Savepoint sp = expected.getSavepoint(); found = new CursorBuilder(table) @@ -131,7 +131,7 @@ public class CursorBuilderTest extends TestCase { .toCursor(); assertCursor(expected, found); - expected = Cursor.createIndexCursor(table, idx); + expected = CursorBuilder.createCursor(table, idx); expected.moveNextRows(2); sp = expected.getSavepoint(); found = new CursorBuilder(table) @@ -141,7 +141,7 @@ public class CursorBuilderTest extends TestCase { .toCursor(); assertCursor(expected, found); - expected = Cursor.createIndexCursor(table, idx, + expected = CursorBuilder.createCursor(table, idx, idx.constructIndexRowFromEntry(3), null); found = new CursorBuilder(table) @@ -150,7 +150,7 @@ public class CursorBuilderTest extends TestCase { .toCursor(); assertCursor(expected, found); - expected = Cursor.createIndexCursor(table, idx, + expected = CursorBuilder.createCursor(table, idx, idx.constructIndexRowFromEntry(3), false, idx.constructIndexRowFromEntry(7), diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java index 897cf53..9f596db 100644 --- a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java @@ -199,7 +199,7 @@ public class CursorTest extends TestCase { Database db = createTestTable(fileFormat); Table table = db.getTable("test"); - Cursor cursor = Cursor.createCursor(table); + Cursor cursor = CursorBuilder.createCursor(table); doTestSimple(cursor, null); db.close(); } @@ -226,7 +226,7 @@ public class CursorTest extends TestCase { Database db = createTestTable(fileFormat); Table table = db.getTable("test"); - Cursor cursor = Cursor.createCursor(table); + Cursor cursor = CursorBuilder.createCursor(table); doTestMove(cursor, null); db.close(); @@ -285,7 +285,7 @@ public class CursorTest extends TestCase { Database db = createTestTable(fileFormat); Table table = db.getTable("test"); - Cursor cursor = Cursor.createCursor(table); + Cursor cursor = CursorBuilder.createCursor(table); doTestSearch(table, cursor, null, 42, -13); db.close(); @@ -338,28 +338,28 @@ public class CursorTest extends TestCase { } assertEquals("data" + 5, - Cursor.findValue(table, + CursorBuilder.findValue(table, table.getColumn("value"), table.getColumn("id"), 5)); assertEquals(createExpectedRow("id", 5, "value", "data" + 5), - Cursor.findRow(table, + CursorBuilder.findRow(table, createExpectedRow("id", 5))); if(index != null) { assertEquals("data" + 5, - Cursor.findValue(table, index, + CursorBuilder.findValue(table, index, table.getColumn("value"), table.getColumn("id"), 5)); assertEquals(createExpectedRow("id", 5, "value", "data" + 5), - Cursor.findRow(table, index, + CursorBuilder.findRow(table, index, createExpectedRow("id", 5))); - assertNull(Cursor.findValue(table, index, + assertNull(CursorBuilder.findValue(table, index, table.getColumn("value"), table.getColumn("id"), -17)); - assertNull(Cursor.findRow(table, index, + assertNull(CursorBuilder.findRow(table, index, createExpectedRow("id", 13))); } } @@ -369,7 +369,7 @@ public class CursorTest extends TestCase { Database db = createTestTable(fileFormat); Table table = db.getTable("test"); - Cursor cursor = Cursor.createCursor(table); + Cursor cursor = CursorBuilder.createCursor(table); doTestReverse(cursor, null); db.close(); @@ -399,8 +399,8 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); - Cursor cursor1 = Cursor.createCursor(table); - Cursor cursor2 = Cursor.createCursor(table); + Cursor cursor1 = CursorBuilder.createCursor(table); + Cursor cursor2 = CursorBuilder.createCursor(table); doTestLiveAddition(table, cursor1, cursor2, 11); db.close(); @@ -440,10 +440,10 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); - Cursor cursor1 = Cursor.createCursor(table); - Cursor cursor2 = Cursor.createCursor(table); - Cursor cursor3 = Cursor.createCursor(table); - Cursor cursor4 = Cursor.createCursor(table); + Cursor cursor1 = CursorBuilder.createCursor(table); + Cursor cursor2 = CursorBuilder.createCursor(table); + Cursor cursor3 = CursorBuilder.createCursor(table); + Cursor cursor4 = CursorBuilder.createCursor(table); doTestLiveDeletion(cursor1, cursor2, cursor3, cursor4, 1); db.close(); @@ -536,7 +536,7 @@ public class CursorTest extends TestCase { assertTable(createUnorderedTestTableData(), table); - Cursor cursor = Cursor.createIndexCursor(table, idx); + Cursor cursor = CursorBuilder.createCursor(table, idx); doTestSimple(cursor, null); db.close(); @@ -549,7 +549,7 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); Index idx = table.getIndexes().get(0); - Cursor cursor = Cursor.createIndexCursor(table, idx); + Cursor cursor = CursorBuilder.createCursor(table, idx); doTestMove(cursor, null); db.close(); @@ -562,7 +562,7 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); Index idx = table.getIndexes().get(0); - Cursor cursor = Cursor.createIndexCursor(table, idx); + Cursor cursor = CursorBuilder.createCursor(table, idx); doTestReverse(cursor, null); db.close(); @@ -575,7 +575,7 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); Index idx = table.getIndexes().get(0); - Cursor cursor = Cursor.createIndexCursor(table, idx); + Cursor cursor = CursorBuilder.createCursor(table, idx); doTestSearch(table, cursor, idx, 42, -13); db.close(); @@ -589,8 +589,8 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); Index idx = table.getIndexes().get(0); - Cursor cursor1 = Cursor.createIndexCursor(table, idx); - Cursor cursor2 = Cursor.createIndexCursor(table, idx); + Cursor cursor1 = CursorBuilder.createCursor(table, idx); + Cursor cursor2 = CursorBuilder.createCursor(table, idx); doTestLiveAddition(table, cursor1, cursor2, 11); db.close(); @@ -604,10 +604,10 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); Index idx = table.getIndexes().get(0); - Cursor cursor1 = Cursor.createIndexCursor(table, idx); - Cursor cursor2 = Cursor.createIndexCursor(table, idx); - Cursor cursor3 = Cursor.createIndexCursor(table, idx); - Cursor cursor4 = Cursor.createIndexCursor(table, idx); + Cursor cursor1 = CursorBuilder.createCursor(table, idx); + Cursor cursor2 = CursorBuilder.createCursor(table, idx); + Cursor cursor3 = CursorBuilder.createCursor(table, idx); + Cursor cursor4 = CursorBuilder.createCursor(table, idx); doTestLiveDeletion(cursor1, cursor2, cursor3, cursor4, 1); db.close(); @@ -734,7 +734,7 @@ public class CursorTest extends TestCase { Database db = createDupeTestTable(fileFormat); Table table = db.getTable("test"); - Cursor cursor = Cursor.createCursor(table); + Cursor cursor = CursorBuilder.createCursor(table); doTestFindAll(table, cursor, null); @@ -748,7 +748,7 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); Index idx = table.getIndexes().get(0); - Cursor cursor = Cursor.createIndexCursor(table, idx); + Cursor cursor = CursorBuilder.createCursor(table, idx); doTestFindAll(table, cursor, idx); @@ -859,8 +859,8 @@ public class CursorTest extends TestCase { Table table = db.getTable("test"); Index idx = table.getIndexes().get(0); - Cursor tCursor = Cursor.createCursor(table); - Cursor iCursor = Cursor.createIndexCursor(table, idx); + Cursor tCursor = CursorBuilder.createCursor(table); + Cursor iCursor = CursorBuilder.createCursor(table, idx); Cursor.Savepoint tSave = tCursor.getSavepoint(); Cursor.Savepoint iSave = iCursor.getSavepoint(); @@ -882,8 +882,8 @@ public class CursorTest extends TestCase { // success } - Cursor tCursor2 = Cursor.createCursor(table); - Cursor iCursor2 = Cursor.createIndexCursor(table, idx); + Cursor tCursor2 = CursorBuilder.createCursor(table); + Cursor iCursor2 = CursorBuilder.createCursor(table, idx); tCursor2.restoreSavepoint(tSave); iCursor2.restoreSavepoint(iSave); @@ -892,7 +892,7 @@ public class CursorTest extends TestCase { } } - public void testColmnMatcher() throws Exception { + public void testColumnMatcher() throws Exception { for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { @@ -903,7 +903,7 @@ public class CursorTest extends TestCase { doTestMatchers(table, SimpleColumnMatcher.INSTANCE, false); doTestMatchers(table, CaseInsensitiveColumnMatcher.INSTANCE, true); - Cursor cursor = Cursor.createCursor(table); + Cursor cursor = CursorBuilder.createCursor(table); doTestMatcher(table, cursor, SimpleColumnMatcher.INSTANCE, false); doTestMatcher(table, cursor, CaseInsensitiveColumnMatcher.INSTANCE, true); @@ -998,7 +998,7 @@ public class CursorTest extends TestCase { Database db = open(testDB); Table t1 = db.getTable("Table1"); Index idx = t1.getIndex(IndexBuilder.PRIMARY_KEY_NAME); - IndexCursor cursor = IndexCursor.createCursor(t1, idx); + IndexCursor cursor = CursorBuilder.createCursor(t1, idx); assertFalse(cursor.findFirstRowByEntry(-1)); cursor.findClosestRowByEntry(-1); @@ -1025,7 +1025,7 @@ public class CursorTest extends TestCase { Database db = openCopy(testDB); Table t1 = db.getTable("Table1"); Index idx = t1.getIndex("Table2Table1"); - IndexCursor cursor = IndexCursor.createCursor(t1, idx); + IndexCursor cursor = CursorBuilder.createCursor(t1, idx); List expectedData = new ArrayList(); for(Map row : cursor.entryIterable( @@ -1077,7 +1077,7 @@ public class CursorTest extends TestCase { Database db = openCopy(testDB); Table t1 = db.getTable("Table1"); - Cursor cursor = Cursor.createCursor(t1); + Cursor cursor = CursorBuilder.createCursor(t1); List expectedData = new ArrayList(); for(Map row : cursor.iterable( diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index e73661f..2d340af 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -90,8 +90,9 @@ public class DatabaseTest extends TestCase { : null); final Database db = new DatabaseBuilder(file).setReadOnly(true) .setAutoSync(_autoSync).setChannel(channel).open(); - assertEquals("Wrong JetFormat.", fileFormat.getJetFormat(), - db.getFormat()); + assertEquals("Wrong JetFormat.", + DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), + ((DatabaseImpl)db).getFormat()); assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat()); return db; } @@ -151,8 +152,9 @@ public class DatabaseTest extends TestCase { File tmp = createTempFile(keep); copyFile(file, tmp); Database db = new DatabaseBuilder(tmp).setAutoSync(_autoSync).open(); - assertEquals("Wrong JetFormat.", fileFormat.getJetFormat(), - db.getFormat()); + assertEquals("Wrong JetFormat.", + DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), + ((DatabaseImpl)db).getFormat()); assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat()); return db; } @@ -163,7 +165,7 @@ public class DatabaseTest extends TestCase { Database db = create(fileFormat); try { - db.createTable("test", Collections.emptyList()); + ((DatabaseImpl)db).createTable("test", Collections.emptyList()); fail("created table with no columns?"); } catch(IllegalArgumentException e) { // success @@ -231,7 +233,7 @@ public class DatabaseTest extends TestCase { public void testGetColumns() throws Exception { for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { - List columns = open(testDB).getTable("Table1").getColumns(); + List columns = open(testDB).getTable("Table1").getColumns(); assertEquals(9, columns.size()); checkColumn(columns, 0, "A", DataType.TEXT); checkColumn(columns, 1, "B", DataType.TEXT); @@ -245,8 +247,8 @@ public class DatabaseTest extends TestCase { } } - static void checkColumn(List columns, int columnNumber, String name, - DataType dataType) + static void checkColumn(List columns, int columnNumber, + String name, DataType dataType) throws Exception { Column column = columns.get(columnNumber); @@ -406,7 +408,7 @@ public class DatabaseTest extends TestCase { table.reset(); table.getNextRow(); table.getNextRow(); - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); table.reset(); @@ -429,17 +431,17 @@ public class DatabaseTest extends TestCase { assertRowCount(10, table); table.reset(); table.getNextRow(); - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); assertRowCount(9, table); table.reset(); table.getNextRow(); - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); assertRowCount(8, table); table.reset(); for (int i = 0; i < 8; i++) { table.getNextRow(); } - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); assertRowCount(7, table); table.addRow(row); assertRowCount(8, table); @@ -447,7 +449,7 @@ public class DatabaseTest extends TestCase { for (int i = 0; i < 3; i++) { table.getNextRow(); } - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); assertRowCount(7, table); table.reset(); assertEquals(2, table.getNextRow().get("D")); @@ -711,9 +713,9 @@ public class DatabaseTest extends TestCase { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - Column col = new ColumnBuilder("A", DataType.NUMERIC) + ColumnBuilder col = new ColumnBuilder("A", DataType.NUMERIC) .setScale(4).setPrecision(8).toColumn(); - assertTrue(col.isVariableLength()); + assertTrue(col.getType().isVariableLength()); Table table = new TableBuilder("test") .addColumn(col) @@ -809,7 +811,7 @@ public class DatabaseTest extends TestCase { public void testMultiPageTableDef() throws Exception { for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { - List columns = open(testDB).getTable("Table2").getColumns(); + List columns = open(testDB).getTable("Table2").getColumns(); assertEquals(89, columns.size()); } } @@ -875,7 +877,7 @@ public class DatabaseTest extends TestCase { Database db = openCopy(testDB); Table t = db.getTable("jobDB1"); - assertTrue(t.getOwnedPagesCursor().getUsageMap().toString() + assertTrue(((TableImpl)t).getOwnedPagesCursor().getUsageMap().toString() .startsWith("(InlineHandler)")); String lval = createNonAsciiString(255); // "--255 chars long text--"; @@ -890,7 +892,7 @@ public class DatabaseTest extends TestCase { } assertEquals(1000, ids.size()); - assertTrue(t.getOwnedPagesCursor().getUsageMap().toString() + assertTrue(((TableImpl)t).getOwnedPagesCursor().getUsageMap().toString() .startsWith("(ReferenceHandler)")); db.close(); @@ -904,7 +906,7 @@ public class DatabaseTest extends TestCase { final int numColumns = 90; - List columns = new ArrayList(); + List columns = new ArrayList(); List colNames = new ArrayList(); for(int i = 0; i < numColumns; ++i) { String colName = "MyColumnName" + i; @@ -912,7 +914,7 @@ public class DatabaseTest extends TestCase { columns.add(new ColumnBuilder(colName, DataType.TEXT).toColumn()); } - db.createTable("test", columns); + ((DatabaseImpl)db).createTable("test", columns); Table t = db.getTable("test"); @@ -1119,7 +1121,7 @@ public class DatabaseTest extends TestCase { t.addRow("row" + i, Column.AUTO_NUMBER, "initial data"); } - Cursor c = Cursor.createCursor(t); + Cursor c = CursorBuilder.createCursor(t); c.reset(); c.moveNextRows(2); Map row = c.getCurrentRow(); @@ -1222,8 +1224,8 @@ public class DatabaseTest extends TestCase { for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { Database db = open(testDB); - assertEquals(db.getFormat().DEFAULT_SORT_ORDER, - db.getDefaultSortOrder()); + assertEquals(((DatabaseImpl)db).getFormat().DEFAULT_SORT_ORDER, + ((DatabaseImpl)db).getDefaultSortOrder()); db.close(); } } @@ -1275,7 +1277,7 @@ public class DatabaseTest extends TestCase { public Database resolveLinkedDatabase(Database linkerdb, String dbName) throws IOException { assertEquals(linkeeDbName, dbName); - return Database.open(linkeeFile); + return DatabaseBuilder.open(linkeeFile); } }); @@ -1323,7 +1325,7 @@ public class DatabaseTest extends TestCase { private static void doTestTimeZone(final TimeZone tz) throws Exception { - Column col = new Column(true, null) { + ColumnImpl col = new ColumnImpl(null, DataType.SHORT_DATE_TIME, 0, 0, 0) { @Override Calendar getCalendar() { return Calendar.getInstance(tz); } }; @@ -1353,7 +1355,7 @@ public class DatabaseTest extends TestCase { private void checkRawValue(String expected, Object val) { if(expected != null) { - assertTrue(Column.isRawData(val)); + assertTrue(ColumnImpl.isRawData(val)); assertEquals(expected, val.toString()); } else { assertNull(val); @@ -1408,15 +1410,16 @@ public class DatabaseTest extends TestCase { static int countRows(Table table) throws Exception { int rtn = 0; - for(Map row : Cursor.createCursor(table)) { + for(Map row : CursorBuilder.createCursor(table)) { rtn++; } return rtn; } static void assertTable(List> expectedTable, Table table) + throws IOException { - assertCursor(expectedTable, Cursor.createCursor(table)); + assertCursor(expectedTable, CursorBuilder.createCursor(table)); } static void assertCursor(List> expectedTable, @@ -1475,7 +1478,7 @@ public class DatabaseTest extends TestCase { static void dumpTable(Table table, PrintWriter writer) throws Exception { // make sure all indexes are read for(Index index : table.getIndexes()) { - index.initialize(); + ((IndexImpl)index).initialize(); } writer.println("TABLE: " + table.getName()); @@ -1484,7 +1487,7 @@ public class DatabaseTest extends TestCase { colNames.add(col.getName()); } writer.println("COLUMNS: " + colNames); - for(Map row : Cursor.createCursor(table)) { + for(Map row : CursorBuilder.createCursor(table)) { writer.println(massageRow(row)); } } @@ -1515,7 +1518,7 @@ public class DatabaseTest extends TestCase { static void dumpIndex(Index index, PrintWriter writer) throws Exception { writer.println("INDEX: " + index); - IndexData.EntryCursor ec = index.cursor(); + IndexData.EntryCursor ec = ((IndexImpl)index).cursor(); IndexData.Entry lastE = ec.getLastEntry(); IndexData.Entry e = null; while((e = ec.getNextEntry()) != lastE) { diff --git a/test/src/java/com/healthmarketscience/jackcess/ErrorHandlerTest.java b/test/src/java/com/healthmarketscience/jackcess/ErrorHandlerTest.java index afffdd5..28c628e 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ErrorHandlerTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ErrorHandlerTest.java @@ -95,12 +95,12 @@ public class ErrorHandlerTest extends TestCase "val", null)), table); - Cursor c1 = Cursor.createCursor(table); - Cursor c2 = Cursor.createCursor(table); - Cursor c3 = Cursor.createCursor(table); + Cursor c1 = CursorBuilder.createCursor(table); + Cursor c2 = CursorBuilder.createCursor(table); + Cursor c3 = CursorBuilder.createCursor(table); c2.setErrorHandler(new DebugErrorHandler("#error")); - c3.setErrorHandler(Database.DEFAULT_ERROR_HANDLER); + c3.setErrorHandler(ErrorHandler.DEFAULT); assertCursor(createExpectedTable( createExpectedRow("col", "row1", @@ -169,10 +169,10 @@ public class ErrorHandlerTest extends TestCase } - private static class BogusColumn extends Column + private static class BogusColumn extends ColumnImpl { private BogusColumn(Table table) { - super(true, table); + super((TableImpl)table, DataType.TEXT, 0, 0, 0); } @Override diff --git a/test/src/java/com/healthmarketscience/jackcess/FKEnforcerTest.java b/test/src/java/com/healthmarketscience/jackcess/FKEnforcerTest.java index 9dd0c88..c640dbb 100644 --- a/test/src/java/com/healthmarketscience/jackcess/FKEnforcerTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/FKEnforcerTest.java @@ -49,11 +49,11 @@ public class FKEnforcerTest extends TestCase t1.addRow(20, 0, 20, "some data", 20); - Cursor c = Cursor.createCursor(t2); + Cursor c = CursorBuilder.createCursor(t2); c.moveToNextRow(); c.updateCurrentRow(30, "foo30"); - c = Cursor.createCursor(t3); + c = CursorBuilder.createCursor(t3); c.moveToNextRow(); c.deleteCurrentRow(); @@ -80,7 +80,7 @@ public class FKEnforcerTest extends TestCase } try { - Cursor c = Cursor.createCursor(t2); + Cursor c = CursorBuilder.createCursor(t2); c.moveToNextRow(); c.updateCurrentRow(30, "foo30"); fail("IOException should have been thrown"); @@ -90,7 +90,7 @@ public class FKEnforcerTest extends TestCase } try { - Cursor c = Cursor.createCursor(t3); + Cursor c = CursorBuilder.createCursor(t3); c.moveToNextRow(); c.deleteCurrentRow(); fail("IOException should have been thrown"); @@ -99,7 +99,7 @@ public class FKEnforcerTest extends TestCase assertTrue(ignored.getMessage().contains("Table3[id]")); } - Cursor c = Cursor.createCursor(t3); + Cursor c = CursorBuilder.createCursor(t3); Column col = t3.getColumn("id"); for(Map row : c) { int id = (Integer)row.get("id"); @@ -116,7 +116,7 @@ public class FKEnforcerTest extends TestCase assertTable(expectedRows, t1); - c = Cursor.createCursor(t2); + c = CursorBuilder.createCursor(t2); for(Iterator iter = c.iterator(); iter.hasNext(); ) { iter.next(); iter.remove(); diff --git a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java index 0be36e1..ba680b1 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java @@ -221,13 +221,13 @@ public class ImportTest extends TestCase rs.addColumn(Types.VARCHAR, "col7", Integer.MAX_VALUE, 0, 0); Database db = create(fileFormat); - db.copyTable("Test1", (ResultSet)Proxy.newProxyInstance( + ImportUtil.importResultSet((ResultSet)Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class[]{ResultSet.class}, - rs)); + rs), db, "Test1"); Table t = db.getTable("Test1"); - List columns = t.getColumns(); + List columns = t.getColumns(); assertEquals(7, columns.size()); Column c = columns.get(0); diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexCodesTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexCodesTest.java index ed71ebe..8dbc2c8 100644 --- a/test/src/java/com/healthmarketscience/jackcess/IndexCodesTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/IndexCodesTest.java @@ -86,7 +86,7 @@ public class IndexCodesTest extends TestCase { // index.initialize(); // System.out.println("Ind " + index); - Cursor cursor = Cursor.createIndexCursor(t, index); + Cursor cursor = CursorBuilder.createCursor(t, index); while(cursor.moveToNextRow()) { Map row = cursor.getCurrentRow(); @@ -111,8 +111,8 @@ public class IndexCodesTest extends TestCase { Cursor.Position expectedPos) throws Exception { - Object[] idxRow = index.constructIndexRow(expectedRow); - Cursor cursor = Cursor.createIndexCursor(t, index, idxRow, idxRow); + Object[] idxRow = ((IndexImpl)index).constructIndexRow(expectedRow); + Cursor cursor = CursorBuilder.createCursor(t, index, idxRow, idxRow); Cursor.Position startPos = cursor.getSavepoint().getCurrentPosition(); @@ -258,11 +258,11 @@ public class IndexCodesTest extends TestCase { Table t = db.getTable("Table5"); Index ind = t.getIndexes().iterator().next(); - ind.initialize(); + ((IndexImpl)ind).initialize(); System.out.println("Ind " + ind); - Cursor cursor = Cursor.createIndexCursor(t, ind); + Cursor cursor = CursorBuilder.createCursor(t, ind); while(cursor.moveToNextRow()) { System.out.println("======="); String entryStr = @@ -311,10 +311,10 @@ public class IndexCodesTest extends TestCase { Table t = db.getTable("Table1"); Index index = t.getIndex("B"); - index.initialize(); + ((IndexImpl)index).initialize(); System.out.println("Ind " + index); - Cursor cursor = Cursor.createIndexCursor(t, index); + Cursor cursor = CursorBuilder.createCursor(t, index); while(cursor.moveToNextRow()) { System.out.println("======="); System.out.println("Savepoint: " + cursor.getSavepoint()); @@ -330,7 +330,7 @@ public class IndexCodesTest extends TestCase { Table t = db.getTable("Table1"); Index index = t.getIndexes().iterator().next(); - index.initialize(); + ((IndexImpl)index).initialize(); System.out.println("Ind " + index); Pattern inlinePat = Pattern.compile("7F 0E 02 0E 02 (.*)0E 02 0E 02 01 00"); @@ -349,7 +349,7 @@ public class IndexCodesTest extends TestCase { Map inat2CrazyCodes = new TreeMap(); - Cursor cursor = Cursor.createIndexCursor(t, index); + Cursor cursor = CursorBuilder.createCursor(t, index); while(cursor.moveToNextRow()) { // System.out.println("======="); // System.out.println("Savepoint: " + cursor.getSavepoint()); @@ -509,7 +509,7 @@ public class IndexCodesTest extends TestCase { Table t = db.getTable("Table1"); Index index = t.getIndexes().iterator().next(); - index.initialize(); + ((IndexImpl)index).initialize(); System.out.println("Ind " + index); Pattern inlinePat = Pattern.compile("7F 4A 4A (.*)4A 4A 01 00"); @@ -528,7 +528,7 @@ public class IndexCodesTest extends TestCase { Map inat2CrazyCodes = new TreeMap(); - Cursor cursor = Cursor.createIndexCursor(t, index); + Cursor cursor = CursorBuilder.createCursor(t, index); while(cursor.moveToNextRow()) { // System.out.println("======="); // System.out.println("Savepoint: " + cursor.getSavepoint()); diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java index 8f078f6..d840fef 100644 --- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java @@ -110,8 +110,8 @@ public class IndexTest extends TestCase { for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { Database mdb = open(testDB); - Table table = mdb.getTable("Table1"); - for(Index idx : table.getIndexes()) { + TableImpl table = (TableImpl)mdb.getTable("Table1"); + for(IndexImpl idx : table.getIndexes()) { idx.initialize(); } assertEquals(4, table.getIndexes().size()); @@ -122,8 +122,8 @@ public class IndexTest extends TestCase { "Table2Table1", "otherfk1", "Table3Table1", "otherfk2"); - table = mdb.getTable("Table2"); - for(Index idx : table.getIndexes()) { + table = (TableImpl)mdb.getTable("Table2"); + for(IndexImpl idx : table.getIndexes()) { idx.initialize(); } assertEquals(3, table.getIndexes().size()); @@ -134,8 +134,8 @@ public class IndexTest extends TestCase { "PrimaryKey", "id", ".rC", "id"); - Index pkIdx = table.getIndex("PrimaryKey"); - Index fkIdx = table.getIndex(".rC"); + IndexImpl pkIdx = table.getIndex("PrimaryKey"); + IndexImpl fkIdx = table.getIndex(".rC"); assertNotSame(pkIdx, fkIdx); assertTrue(fkIdx.isForeignKey()); assertSame(pkIdx.getIndexData(), fkIdx.getIndexData()); @@ -143,8 +143,8 @@ public class IndexTest extends TestCase { assertEquals(Arrays.asList(pkIdx, fkIdx), indexData.getIndexes()); assertSame(pkIdx, indexData.getPrimaryIndex()); - table = mdb.getTable("Table3"); - for(Index idx : table.getIndexes()) { + table = (TableImpl)mdb.getTable("Table3"); + for(IndexImpl idx : table.getIndexes()) { idx.initialize(); } assertEquals(3, table.getIndexes().size()); @@ -171,8 +171,8 @@ public class IndexTest extends TestCase { for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX)) { // this file has an index with "compressed" entries and node pages Database db = open(testDB); - Table t = db.getTable("Table1"); - Index index = t.getIndexes().get(0); + TableImpl t = (TableImpl)db.getTable("Table1"); + IndexImpl index = t.getIndexes().get(0); assertFalse(index.isInitialized()); assertEquals(512, countRows(t)); assertEquals(512, index.getIndexData().getEntryCount()); @@ -180,23 +180,12 @@ public class IndexTest extends TestCase { // copy to temp file and attempt to edit db = openCopy(testDB); - t = db.getTable("Table1"); + t = (TableImpl)db.getTable("Table1"); index = t.getIndexes().get(0); System.out.println("IndexTest: Index type: " + index.getIndexData().getClass()); - try { - t.addRow(99, "abc", "def"); - if(index.getIndexData() instanceof SimpleIndexData) { - // SimpleIndex doesn't support writing these indexes - fail("Should have thrown UnsupportedOperationException"); - } - } catch(UnsupportedOperationException e) { - // success - if(index.getIndexData() instanceof BigIndexData) { - throw e; - } - } + t.addRow(99, "abc", "def"); } } @@ -212,28 +201,28 @@ public class IndexTest extends TestCase { assertRowCount(12, table); for(Index index : table.getIndexes()) { - assertEquals(12, index.getIndexData().getEntryCount()); + assertEquals(12, ((IndexImpl)index).getIndexData().getEntryCount()); } table.reset(); table.getNextRow(); table.getNextRow(); - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); table.getNextRow(); - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); table.getNextRow(); table.getNextRow(); - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); table.getNextRow(); table.getNextRow(); table.getNextRow(); - table.deleteCurrentRow(); + table.getDefaultCursor().deleteCurrentRow(); table.reset(); assertRowCount(8, table); for(Index index : table.getIndexes()) { - assertEquals(8, index.getIndexData().getEntryCount()); + assertEquals(8, ((IndexImpl)index).getIndexData().getEntryCount()); } } } @@ -254,9 +243,9 @@ public class IndexTest extends TestCase { throws Exception { Table orig = db.getTable(tableName); - Index origI = orig.getIndex("DataIndex"); + IndexImpl origI = (IndexImpl)orig.getIndex("DataIndex"); Table temp = db.getTable(tableName + "_temp"); - Index tempI = temp.getIndex("DataIndex"); + IndexImpl tempI = (IndexImpl)temp.getIndex("DataIndex"); // copy from orig table to temp table for(Map row : orig) { @@ -266,8 +255,8 @@ public class IndexTest extends TestCase { assertEquals(origI.getIndexData().getEntryCount(), tempI.getIndexData().getEntryCount()); - Cursor origC = Cursor.createIndexCursor(orig, origI); - Cursor tempC = Cursor.createIndexCursor(temp, tempI); + Cursor origC = CursorBuilder.createCursor(orig, origI); + Cursor tempC = CursorBuilder.createCursor(temp, tempI); while(true) { boolean origHasNext = origC.moveToNextRow(); @@ -340,7 +329,7 @@ public class IndexTest extends TestCase { IOException failure = null; try { - index.addRow(row, new RowId(400 + i, 0)); + ((IndexImpl)index).addRow(row, new RowId(400 + i, 0)); } catch(IOException e) { failure = e; } @@ -357,8 +346,8 @@ public class IndexTest extends TestCase { for (final TestDB testDB : SUPPORTED_DBS_TEST) { Database db = openCopy(testDB); Table table = db.getTable("Table1"); - Index indA = table.getIndex("PrimaryKey"); - Index indB = table.getIndex("B"); + IndexImpl indA = (IndexImpl)table.getIndex("PrimaryKey"); + IndexImpl indB = (IndexImpl)table.getIndex("B"); assertEquals(2, indA.getUniqueEntryCount()); assertEquals(2, indB.getUniqueEntryCount()); @@ -382,8 +371,8 @@ public class IndexTest extends TestCase { indB = null; table = db.getTable("Table1"); - indA = table.getIndex("PrimaryKey"); - indB = table.getIndex("B"); + indA = (IndexImpl)table.getIndex("PrimaryKey"); + indB = (IndexImpl)table.getIndex("B"); assertEquals(12, indA.getIndexData().getEntryCount()); assertEquals(12, indB.getIndexData().getEntryCount()); @@ -391,7 +380,7 @@ public class IndexTest extends TestCase { assertEquals(12, indA.getUniqueEntryCount()); assertEquals(8, indB.getUniqueEntryCount()); - Cursor c = Cursor.createCursor(table); + Cursor c = CursorBuilder.createCursor(table); assertTrue(c.moveToNextRow()); final Map row = c.getCurrentRow(); @@ -443,7 +432,7 @@ public class IndexTest extends TestCase { .toTable(db); assertEquals(1, t.getIndexes().size()); - Index idx = t.getIndexes().get(0); + IndexImpl idx = (IndexImpl)t.getIndexes().get(0); assertEquals(IndexBuilder.PRIMARY_KEY_NAME, idx.getName()); assertEquals(1, idx.getColumns().size()); @@ -478,8 +467,8 @@ public class IndexTest extends TestCase { Table t2 = db.getTable("Table2"); Table t3 = db.getTable("Table3"); - Index t2t1 = t1.getIndex("Table2Table1"); - Index t3t1 = t1.getIndex("Table3Table1"); + IndexImpl t2t1 = (IndexImpl)t1.getIndex("Table2Table1"); + IndexImpl t3t1 = (IndexImpl)t1.getIndex("Table3Table1"); assertTrue(t2t1.isForeignKey()); @@ -498,7 +487,7 @@ public class IndexTest extends TestCase { Index t1pk = t1.getIndex(IndexBuilder.PRIMARY_KEY_NAME); assertNotNull(t1pk); - assertNull(t1pk.getReference()); + assertNull(((IndexImpl)t1pk).getReference()); assertNull(t1pk.getReferencedIndex()); } } @@ -506,7 +495,7 @@ public class IndexTest extends TestCase { private void doCheckForeignKeyIndex(Table ta, Index ia, Table tb) throws Exception { - Index ib = ia.getReferencedIndex(); + IndexImpl ib = (IndexImpl)ia.getReferencedIndex(); assertNotNull(ib); assertSame(tb, ib.getTable()); diff --git a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java index 9c75b6d..71472fe 100644 --- a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java @@ -79,7 +79,8 @@ public class JetFormatTest extends TestCase { continue; } supportedForRead.add(ff); - if(ff.getJetFormat().READ_ONLY || (ff == FileFormat.MSISAM)) { + if(DatabaseImpl.getFileFormatDetails(ff).getFormat().READ_ONLY || + (ff == FileFormat.MSISAM)) { continue; } supported.add(ff); @@ -112,7 +113,7 @@ public class JetFormatTest extends TestCase { } public final JetFormat getExpectedFormat() { - return expectedFileFormat.getJetFormat(); + return DatabaseImpl.getFileFormatDetails(expectedFileFormat).getFormat(); } @Override @@ -139,7 +140,7 @@ public class JetFormatTest extends TestCase { // verify that the db is the file format expected try { - Database db = Database.open(testFile, true); + Database db = new DatabaseBuilder(testFile).setReadOnly(true).open(); FileFormat dbFileFormat = db.getFileFormat(); db.close(); if(dbFileFormat != fileFormat) { @@ -181,13 +182,13 @@ public class JetFormatTest extends TestCase { for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { - final FileChannel channel = Database.openChannel(testDB.dbFile, false); + final FileChannel channel = DatabaseImpl.openChannel(testDB.dbFile, false); try { JetFormat fmtActual = JetFormat.getFormat(channel); assertEquals("Unexpected JetFormat for dbFile: " + testDB.dbFile.getAbsolutePath(), - testDB.expectedFileFormat.getJetFormat(), fmtActual); + testDB.getExpectedFormat(), fmtActual); } finally { channel.close(); diff --git a/test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java b/test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java index fccbc67..c760e59 100644 --- a/test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/PropertiesTest.java @@ -105,7 +105,7 @@ public class PropertiesTest extends TestCase for(TestDB testDb : SUPPORTED_DBS_TEST_FOR_READ) { Database db = open(testDb); - Table t = db.getTable("Table1"); + TableImpl t = (TableImpl)db.getTable("Table1"); assertEquals(t.getTableDefPageNumber(), t.getPropertyMaps().getObjectId()); PropertyMap tProps = t.getProperties(); @@ -189,7 +189,7 @@ public class PropertiesTest extends TestCase for(Map row : db.getSystemCatalog()) { int id = (Integer)row.get("Id"); byte[] propBytes = (byte[])row.get("LvProp"); - PropertyMaps propMaps = db.getPropertiesForObject(id); + PropertyMaps propMaps = ((DatabaseImpl)db).getPropertiesForObject(id); int byteLen = ((propBytes != null) ? propBytes.length : 0); if(byteLen == 0) { assertTrue(propMaps.isEmpty()); diff --git a/test/src/java/com/healthmarketscience/jackcess/RowFilterTest.java b/test/src/java/com/healthmarketscience/jackcess/RowFilterTest.java index 586ad9a..5542049 100644 --- a/test/src/java/com/healthmarketscience/jackcess/RowFilterTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/RowFilterTest.java @@ -66,12 +66,12 @@ public class RowFilterTest extends TestCase assertEquals(Arrays.asList(row0, row2, row4), toList(RowFilter.matchPattern( - new ColumnBuilder(COL1, DataType.TEXT).toColumn(), + new ColumnImpl(null, DataType.TEXT, 0, 0, 0), "foo").apply(rows))); assertEquals(Arrays.asList(row1, row3, row5), toList(RowFilter.invert( RowFilter.matchPattern( - new ColumnBuilder(COL1, DataType.TEXT).toColumn(), + new ColumnImpl(null, DataType.TEXT, 0, 0, 0), "foo")).apply(rows))); assertEquals(Arrays.asList(row0, row2, row4), diff --git a/test/src/java/com/healthmarketscience/jackcess/TableTest.java b/test/src/java/com/healthmarketscience/jackcess/TableTest.java index b217ff2..63d3faa 100644 --- a/test/src/java/com/healthmarketscience/jackcess/TableTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/TableTest.java @@ -44,8 +44,8 @@ import junit.framework.TestCase; public class TableTest extends TestCase { private final PageChannel _pageChannel = new PageChannel(true); - private List _columns = new ArrayList(); - private Table _testTable; + private List _columns = new ArrayList(); + private TableImpl _testTable; private int _varLenIdx; private int _fixedOffset; @@ -53,17 +53,18 @@ public class TableTest extends TestCase { public TableTest(String name) { super(name); } + + private void reset() { + _testTable = null; + _columns = new ArrayList(); + _varLenIdx = 0; + _fixedOffset = 0; + } public void testCreateRow() throws Exception { - Column col = newTestColumn(); - col.setType(DataType.INT); - _columns.add(col); - col = newTestColumn(); - col.setType(DataType.TEXT); - _columns.add(col); - col = newTestColumn(); - col.setType(DataType.TEXT); - _columns.add(col); + newTestColumn(DataType.INT, false); + newTestColumn(DataType.TEXT, false); + newTestColumn(DataType.TEXT, false); newTestTable(); int colCount = _columns.size(); @@ -80,13 +81,8 @@ public class TableTest extends TestCase { } public void testUnicodeCompression() throws Exception { - Column col = newTestColumn(); - col = newTestColumn(); - col.setType(DataType.TEXT); - _columns.add(col); - col = newTestColumn(); - col.setType(DataType.MEMO); - _columns.add(col); + newTestColumn(DataType.TEXT, false); + newTestColumn(DataType.MEMO, false); newTestTable(); String small = "this is a string"; @@ -97,9 +93,10 @@ public class TableTest extends TestCase { ByteBuffer[] buf1 = encodeColumns(small, large); ByteBuffer[] buf2 = encodeColumns(smallNotAscii, largeNotAscii); - for(Column tmp : _columns) { - tmp.setCompressedUnicode(true); - } + reset(); + newTestColumn(DataType.TEXT, true); + newTestColumn(DataType.MEMO, true); + newTestTable(); ByteBuffer[] bufCmp1 = encodeColumns(small, large); ByteBuffer[] bufCmp2 = encodeColumns(smallNotAscii, largeNotAscii); @@ -132,7 +129,7 @@ public class TableTest extends TestCase { { ByteBuffer[] result = new ByteBuffer[_columns.size()]; for(int i = 0; i < _columns.size(); ++i) { - Column col = _columns.get(i); + ColumnImpl col = _columns.get(i); result[i] = col.write(row[i], _testTable.getFormat().MAX_ROW_SIZE); } return result; @@ -143,7 +140,7 @@ public class TableTest extends TestCase { { Object[] result = new Object[_columns.size()]; for(int i = 0; i < _columns.size(); ++i) { - Column col = _columns.get(i); + ColumnImpl col = _columns.get(i); result[i] = col.read(toBytes(buffers[i])); } return result; @@ -156,10 +153,10 @@ public class TableTest extends TestCase { return b; } - private Table newTestTable() + private TableImpl newTestTable() throws Exception { - _testTable = new Table(true, _columns) { + _testTable = new TableImpl(true, _columns) { @Override public PageChannel getPageChannel() { return _pageChannel; @@ -172,7 +169,7 @@ public class TableTest extends TestCase { return _testTable; } - private Column newTestColumn(DataType type) { + private void newTestColumn(DataType type, final boolean compressedUnicode) { int nextColIdx = _columns.size(); int nextVarLenIdx = 0; @@ -185,9 +182,9 @@ public class TableTest extends TestCase { _fixedOffset += type.getFixedSize(); } - return new Column(null, type, nextColIdx, nextFixedOff, nextVarLenIdx) { + ColumnImpl col = new ColumnImpl(null, type, nextColIdx, nextFixedOff, nextVarLenIdx) { @Override - public Table getTable() { + public TableImpl getTable() { return _testTable; } @Override @@ -206,7 +203,13 @@ public class TableTest extends TestCase { Calendar getCalendar() { return Calendar.getInstance(); } + @Override + public boolean isCompressedUnicode() { + return compressedUnicode; + } }; + + _columns.add(col); } } diff --git a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java b/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java index 87fa5c3..fe2ff54 100644 --- a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java @@ -42,8 +42,8 @@ public final class UsageMapTest extends TestCase { final int expectedFirstPage, final int expectedLastPage) throws IOException { - final Database db = Database.open(dbFile); - final UsageMap usageMap = UsageMap.read(db, + final Database db = DatabaseBuilder.open(dbFile); + final UsageMap usageMap = UsageMap.read((DatabaseImpl)db, PageChannel.PAGE_GLOBAL_USAGE_MAP, PageChannel.ROW_GLOBAL_USAGE_MAP, true); -- 2.39.5