From: James Ahlborn Date: Fri, 9 Sep 2016 11:58:37 +0000 (+0000) Subject: more update tests; fix minor bug with allocating new usage maps X-Git-Tag: jackcess-2.1.5~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=545c0269857a0be87823bdbe08b92309f2466c96;p=jackcess.git more update tests; fix minor bug with allocating new usage maps git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1032 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java index 8ed8f57..dc5ecbf 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java @@ -1716,12 +1716,12 @@ public class DatabaseImpl implements Database } public void validateNewTableName(String name) throws IOException { + validateIdentifierName(name, getFormat().MAX_TABLE_NAME_LENGTH, "table"); + if(lookupTable(name) != null) { throw new IllegalArgumentException(withErrorContext( "Cannot create table with name of existing table '" + name + "'")); } - - validateIdentifierName(name, getFormat().MAX_TABLE_NAME_LENGTH, "table"); } /** diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java index e1b0d1e..e5a6316 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java @@ -1560,6 +1560,10 @@ public class TableImpl implements Table return tableBuffer; } + /** + * Adds some usage maps for use with this table. This method is expected to + * be called with a small-ish number of requested usage maps. + */ private Map.Entry addUsageMaps( int numMaps, Integer firstUsedPage) throws IOException @@ -1595,6 +1599,7 @@ public class TableImpl implements Table if(umapPageNumber == PageChannel.INVALID_PAGE_NUMBER) { // didn't find any existing pages, need to create a new one + umapPageNumber = pageChannel.allocateNewPage(); freeSpace = format.DATA_PAGE_INITIAL_FREE_SPACE; firstRowNum = 0; umapBuf = createUsageMapDefPage(pageChannel, freeSpace); diff --git a/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java b/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java index 160f71c..2f3a1a8 100644 --- a/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java @@ -16,7 +16,11 @@ limitations under the License. package com.healthmarketscience.jackcess; +import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import com.healthmarketscience.jackcess.Database.FileFormat; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; @@ -51,7 +55,6 @@ public class TableUpdaterTest extends TestCase Database db = create(fileFormat); doTestUpdating(db, true, true); - // FIXME, add one-to-one, add no enforce rel db.close(); } @@ -174,4 +177,76 @@ public class TableUpdaterTest extends TestCase } } } + + public void testInvalidUpdate() throws Exception + { + for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + Database db = create(fileFormat); + + Table t1 = new TableBuilder("TestTable") + .addColumn(new ColumnBuilder("id", DataType.LONG)) + .toTable(db); + + try { + new ColumnBuilder("ID", DataType.TEXT) + .addToTable(t1); + fail("created table with no columns?"); + } catch(IllegalArgumentException e) { + // success + } + + new TableBuilder("TestTable2") + .addColumn(new ColumnBuilder("id2", DataType.LONG)) + .toTable(db); + + try { + new RelationshipBuilder("TestTable", "TestTable2") + .addColumns("id", "id") + .toRelationship(db); + fail("created rel with wrong columns?"); + } catch(IllegalArgumentException e) { + // success + } + + db.close(); + } + } + + public void testUpdateLargeTableDef() throws Exception + { + for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + Database db = create(fileFormat); + + final int numColumns = 89; + + Table t = new TableBuilder("test") + .addColumn(new ColumnBuilder("first", DataType.TEXT)) + .toTable(db); + + List colNames = new ArrayList(); + colNames.add("first"); + for(int i = 0; i < numColumns; ++i) { + String colName = "MyColumnName" + i; + colNames.add(colName); + DataType type = (((i % 3) == 0) ? DataType.MEMO : DataType.TEXT); + new ColumnBuilder(colName, type) + .addToTable(t); + } + + List row = new ArrayList(); + Map expectedRowData = new LinkedHashMap(); + for(int i = 0; i < colNames.size(); ++i) { + String value = "" + i + " some row data"; + row.add(value); + expectedRowData.put(colNames.get(i), value); + } + + t.addRow(row.toArray()); + + t.reset(); + assertEquals(expectedRowData, t.getNextRow()); + + db.close(); + } + } }