Browse Source

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
tags/jackcess-2.1.5
James Ahlborn 7 years ago
parent
commit
545c026985

+ 2
- 2
src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java View File

@@ -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");
}
/**

+ 5
- 0
src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java View File

@@ -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<Integer,Integer> 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);

+ 76
- 1
src/test/java/com/healthmarketscience/jackcess/TableUpdaterTest.java View File

@@ -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<String> colNames = new ArrayList<String>();
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<String> row = new ArrayList<String>();
Map<String,Object> expectedRowData = new LinkedHashMap<String, Object>();
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();
}
}
}

Loading…
Cancel
Save