Browse Source

add convenience methods to Row for getting values cast to specific types

git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@859 f203690c-595d-4dc9-a70b-905162fa7fd2
tags/jackcess-2.0.5
James Ahlborn 10 years ago
parent
commit
840ccbde0f

+ 71
- 0
src/main/java/com/healthmarketscience/jackcess/Row.java View File

@@ -19,7 +19,12 @@ USA

package com.healthmarketscience.jackcess;

import java.util.Date;
import java.util.Map;
import java.math.BigDecimal;

import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;


/**
* A row of data as column name->value pairs. Values are strongly typed, and
@@ -34,4 +39,70 @@ public interface Row extends Map<String,Object>
* @return the id of this row
*/
public RowId getId();

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a String.
*/
public String getString(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a Boolean.
*/
public Boolean getBoolean(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a Byte.
*/
public Byte getByte(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a Short.
*/
public Short getShort(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a Integer.
*/
public Integer getInt(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a BigDecimal.
*/
public BigDecimal getBigDecimal(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a Float.
*/
public Float getFloat(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a Double.
*/
public Double getDouble(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a Date.
*/
public Date getDate(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a byte[].
*/
public byte[] getBytes(String name);

/**
* Convenience method which gets the value for the row with the given name,
* casting it to a ComplexValueForeignKey.
*/
public ComplexValueForeignKey getForeignKey(String name);
}

+ 3
- 3
src/main/java/com/healthmarketscience/jackcess/impl/ComplexColumnSupport.java View File

@@ -79,14 +79,14 @@ public class ComplexColumnSupport
complexTypeId);
}
Row cColRow = cursor.getCurrentRow();
int tableId = (Integer)cColRow.get(COL_TABLE_ID);
int tableId = cColRow.getInt(COL_TABLE_ID);
if(tableId != column.getTable().getTableDefPageNumber()) {
throw new IOException(
"Found complex column for table " + tableId + " but expected table " +
column.getTable().getTableDefPageNumber());
}
int flatTableId = (Integer)cColRow.get(COL_FLAT_TABLE_ID);
int typeObjId = (Integer)cColRow.get(COL_COMPLEX_TYPE_OBJECT_ID);
int flatTableId = cColRow.getInt(COL_FLAT_TABLE_ID);
int typeObjId = cColRow.getInt(COL_COMPLEX_TYPE_OBJECT_ID);

TableImpl typeObjTable = db.getTable(typeObjId);
TableImpl flatTable = db.getTable(flatTableId);

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

@@ -874,8 +874,8 @@ public class DatabaseImpl implements Database
return null;
}

String name = (String)objectRow.get(CAT_COL_NAME);
int flags = (Integer)objectRow.get(CAT_COL_FLAGS);
String name = objectRow.getString(CAT_COL_NAME);
int flags = objectRow.getInt(CAT_COL_FLAGS);

return readTable(name, tableDefPageNumber, flags);
}
@@ -1093,10 +1093,10 @@ public class DatabaseImpl implements Database
CursorImpl.createCursor(_systemCatalog).newIterable().setColumnNames(
SYSTEM_CATALOG_COLUMNS))
{
String name = (String) row.get(CAT_COL_NAME);
String name = row.getString(CAT_COL_NAME);
if (name != null && TYPE_QUERY.equals(row.get(CAT_COL_TYPE))) {
queryInfo.add(row);
Integer id = (Integer)row.get(CAT_COL_ID);
Integer id = row.getInt(CAT_COL_ID);
queryRowMap.put(id, new ArrayList<QueryImpl.Row>());
}
}
@@ -1116,9 +1116,9 @@ public class DatabaseImpl implements Database
// lastly, generate all the queries
List<Query> queries = new ArrayList<Query>();
for(Row row : queryInfo) {
String name = (String) row.get(CAT_COL_NAME);
Integer id = (Integer)row.get(CAT_COL_ID);
int flags = (Integer)row.get(CAT_COL_FLAGS);
String name = row.getString(CAT_COL_NAME);
Integer id = row.getInt(CAT_COL_ID);
int flags = row.getInt(CAT_COL_FLAGS);
List<QueryImpl.Row> queryRows = queryRowMap.get(id);
queries.add(QueryImpl.create(flags, name, queryRows, id));
}
@@ -1164,7 +1164,7 @@ public class DatabaseImpl implements Database
byte[] propsBytes = null;
RowIdImpl rowId = null;
if(objectRow != null) {
propsBytes = (byte[])objectRow.get(CAT_COL_PROPS);
propsBytes = objectRow.getBytes(CAT_COL_PROPS);
rowId = (RowIdImpl)objectRow.getId();
}
return readProperties(propsBytes, objectId, rowId);
@@ -1191,8 +1191,8 @@ public class DatabaseImpl implements Database
int objectId = -1;
RowIdImpl rowId = null;
if(objectRow != null) {
propsBytes = (byte[])objectRow.get(CAT_COL_PROPS);
objectId = (Integer)objectRow.get(CAT_COL_ID);
propsBytes = objectRow.getBytes(CAT_COL_PROPS);
objectId = objectRow.getInt(CAT_COL_ID);
rowId = (RowIdImpl)objectRow.getId();
}
return readProperties(propsBytes, objectId, rowId);
@@ -1257,15 +1257,15 @@ public class DatabaseImpl implements Database
String toTableName = ((toTable != null) ? toTable.getName() : null);

for(Row row : cursor) {
String fromName = (String)row.get(REL_COL_FROM_TABLE);
String toName = (String)row.get(REL_COL_TO_TABLE);
String fromName = row.getString(REL_COL_FROM_TABLE);
String toName = row.getString(REL_COL_TO_TABLE);
if(((fromTableName == null) ||
fromTableName.equalsIgnoreCase(fromName)) &&
((toTableName == null) ||
toTableName.equalsIgnoreCase(toName))) {

String relName = (String)row.get(REL_COL_NAME);
String relName = row.getString(REL_COL_NAME);
// found more info for a relationship. see if we already have some
// info for this relationship
@@ -1296,19 +1296,19 @@ public class DatabaseImpl implements Database

if(rel == null) {
// new relationship
int numCols = (Integer)row.get(REL_COL_COLUMN_COUNT);
int flags = (Integer)row.get(REL_COL_FLAGS);
int numCols = row.getInt(REL_COL_COLUMN_COUNT);
int flags = row.getInt(REL_COL_FLAGS);
rel = new RelationshipImpl(relName, relFromTable, relToTable,
flags, numCols);
relationships.add(rel);
}

// add column info
int colIdx = (Integer)row.get(REL_COL_COLUMN_INDEX);
int colIdx = row.getInt(REL_COL_COLUMN_INDEX);
ColumnImpl fromCol = relFromTable.getColumn(
(String)row.get(REL_COL_FROM_COLUMN));
row.getString(REL_COL_FROM_COLUMN));
ColumnImpl toCol = relToTable.getColumn(
(String)row.get(REL_COL_TO_COLUMN));
row.getString(REL_COL_TO_COLUMN));

rel.getFromColumns().set(colIdx, fromCol);
rel.getToColumns().set(colIdx, toCol);
@@ -1400,9 +1400,9 @@ public class DatabaseImpl implements Database
getAccessControlEntries(), ACE_COL_OBJECT_ID, _tableParentId);
for(Row row : cursor) {
Integer objId = (Integer)row.get(ACE_COL_OBJECT_ID);
Integer objId = row.getInt(ACE_COL_OBJECT_ID);
if(_tableParentId.equals(objId)) {
_newTableSIDs.add((byte[])row.get(ACE_COL_SID));
_newTableSIDs.add(row.getBytes(ACE_COL_SID));
}
}

@@ -1842,10 +1842,10 @@ public class DatabaseImpl implements Database
for(Row row : getTableNamesCursor().newIterable().setColumnNames(
SYSTEM_CATALOG_TABLE_NAME_COLUMNS)) {

String tableName = (String)row.get(CAT_COL_NAME);
int flags = (Integer)row.get(CAT_COL_FLAGS);
Short type = (Short)row.get(CAT_COL_TYPE);
int parentId = (Integer)row.get(CAT_COL_PARENT_ID);
String tableName = row.getString(CAT_COL_NAME);
int flags = row.getInt(CAT_COL_FLAGS);
Short type = row.getShort(CAT_COL_TYPE);
int parentId = row.getInt(CAT_COL_PARENT_ID);

if((parentId == _tableParentId) && isTableType(type) &&
(isSystemObject(flags) == systemTables)) {
@@ -1923,17 +1923,17 @@ public class DatabaseImpl implements Database

Row row = _systemCatalogCursor.getCurrentRow(
SYSTEM_CATALOG_COLUMNS);
Integer pageNumber = (Integer)row.get(CAT_COL_ID);
String realName = (String)row.get(CAT_COL_NAME);
int flags = (Integer)row.get(CAT_COL_FLAGS);
Short type = (Short)row.get(CAT_COL_TYPE);
Integer pageNumber = row.getInt(CAT_COL_ID);
String realName = row.getString(CAT_COL_NAME);
int flags = row.getInt(CAT_COL_FLAGS);
Short type = row.getShort(CAT_COL_TYPE);

if(!isTableType(type)) {
return null;
}

String linkedDbName = (String)row.get(CAT_COL_DATABASE);
String linkedTableName = (String)row.get(CAT_COL_FOREIGN_NAME);
String linkedDbName = row.getString(CAT_COL_DATABASE);
String linkedTableName = row.getString(CAT_COL_FOREIGN_NAME);

return createTableInfo(realName, pageNumber, flags, type, linkedDbName,
linkedTableName);
@@ -1999,25 +1999,25 @@ public class DatabaseImpl implements Database
for(Row row : _systemCatalogCursor.newIterable().setColumnNames(
SYSTEM_CATALOG_TABLE_NAME_COLUMNS)) {

Short type = (Short)row.get(CAT_COL_TYPE);
Short type = row.getShort(CAT_COL_TYPE);
if(!isTableType(type)) {
continue;
}

int parentId = (Integer)row.get(CAT_COL_PARENT_ID);
int parentId = row.getInt(CAT_COL_PARENT_ID);
if(parentId != _tableParentId) {
continue;
}

String realName = (String)row.get(CAT_COL_NAME);
String realName = row.getString(CAT_COL_NAME);
if(!tableName.equalsIgnoreCase(realName)) {
continue;
}

Integer pageNumber = (Integer)row.get(CAT_COL_ID);
int flags = (Integer)row.get(CAT_COL_FLAGS);
String linkedDbName = (String)row.get(CAT_COL_DATABASE);
String linkedTableName = (String)row.get(CAT_COL_FOREIGN_NAME);
Integer pageNumber = row.getInt(CAT_COL_ID);
int flags = row.getInt(CAT_COL_FLAGS);
String linkedDbName = row.getString(CAT_COL_DATABASE);
String linkedTableName = row.getString(CAT_COL_FOREIGN_NAME);

return createTableInfo(realName, pageNumber, flags, type, linkedDbName,
linkedTableName);

+ 48
- 0
src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java View File

@@ -20,8 +20,12 @@ USA
package com.healthmarketscience.jackcess.impl;

import java.util.LinkedHashMap;
import java.util.Date;
import java.math.BigDecimal;

import com.healthmarketscience.jackcess.Row;
import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;


/**
* A row of data as column->value pairs.
@@ -55,6 +59,50 @@ public class RowImpl extends LinkedHashMap<String,Object> implements Row
return _id;
}

public String getString(String name) {
return (String)get(name);
}

public Boolean getBoolean(String name) {
return (Boolean)get(name);
}

public Byte getByte(String name) {
return (Byte)get(name);
}

public Short getShort(String name) {
return (Short)get(name);
}

public Integer getInt(String name) {
return (Integer)get(name);
}

public BigDecimal getBigDecimal(String name) {
return (BigDecimal)get(name);
}

public Float getFloat(String name) {
return (Float)get(name);
}

public Double getDouble(String name) {
return (Double)get(name);
}

public Date getDate(String name) {
return (Date)get(name);
}

public byte[] getBytes(String name) {
return (byte[])get(name);
}

public ComplexValueForeignKey getForeignKey(String name) {
return (ComplexValueForeignKey)get(name);
}

@Override
public String toString() {
return CustomToStringStyle.valueBuilder("Row[" + _id + "]")

+ 8
- 8
src/main/java/com/healthmarketscience/jackcess/impl/query/QueryImpl.java View File

@@ -582,14 +582,14 @@ public abstract class QueryImpl implements Query

public Row(com.healthmarketscience.jackcess.Row tableRow) {
this(tableRow.getId(),
(Byte)tableRow.get(COL_ATTRIBUTE),
(String)tableRow.get(COL_EXPRESSION),
(Short)tableRow.get(COL_FLAG),
(Integer)tableRow.get(COL_EXTRA),
(String)tableRow.get(COL_NAME1),
(String)tableRow.get(COL_NAME2),
(Integer)tableRow.get(COL_OBJECTID),
(byte[])tableRow.get(COL_ORDER));
tableRow.getByte(COL_ATTRIBUTE),
tableRow.getString(COL_EXPRESSION),
tableRow.getShort(COL_FLAG),
tableRow.getInt(COL_EXTRA),
tableRow.getString(COL_NAME1),
tableRow.getString(COL_NAME2),
tableRow.getInt(COL_OBJECTID),
tableRow.getBytes(COL_ORDER));
}

public Row(RowId id, Byte attribute, String expression, Short flag,

+ 1
- 1
src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java View File

@@ -56,7 +56,7 @@ import com.healthmarketscience.jackcess.impl.OleUtil;
* <p/>
* <b>Example for interpreting an existing OLE field:</b>
* <pre>
* byte[] oleBytes = (byte[])row.get("MyOleColumn");
* byte[] oleBytes = row.getBytes("MyOleColumn");
* OleBlob oleBlob = null;
* try {
* oleBlob = OleBlob.Builder.fromInternalData(oleBlob);

+ 4
- 4
src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java View File

@@ -125,8 +125,8 @@ public class BigIndexTest extends TestCase {
String prevValue = firstValue;
int rowCount = 0;
List<String> firstTwo = new ArrayList<String>();
for(Map<String,Object> row : CursorBuilder.createCursor(index)) {
String origVal = (String)row.get("col1");
for(Row row : CursorBuilder.createCursor(index)) {
String origVal = row.getString("col1");
String val = origVal;
if(val == null) {
val = firstValue;
@@ -162,8 +162,8 @@ public class BigIndexTest extends TestCase {
index.getIndexData().validate();

List<String> found = new ArrayList<String>();
for(Map<String,Object> row : CursorBuilder.createCursor(index)) {
found.add((String)row.get("col1"));
for(Row row : CursorBuilder.createCursor(index)) {
found.add(row.getString("col1"));
}

assertEquals(firstTwo, found);

+ 8
- 8
src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java View File

@@ -64,8 +64,8 @@ public class ComplexColumnTest extends TestCase
assertEquals(ComplexDataType.VERSION_HISTORY,
verCol.getComplexInfo().getType());

for(Map<String,Object> row : t1) {
String rowId = (String)row.get("id");
for(Row row : t1) {
String rowId = row.getString("id");
ComplexValueForeignKey complexValueFk =
(ComplexValueForeignKey)verCol.getRowValue(row);

@@ -166,8 +166,8 @@ public class ComplexColumnTest extends TestCase
assertEquals(ComplexDataType.ATTACHMENT,
col.getComplexInfo().getType());

for(Map<String,Object> row : t1) {
String rowId = (String)row.get("id");
for(Row row : t1) {
String rowId = row.getString("id");
ComplexValueForeignKey complexValueFk =
(ComplexValueForeignKey)col.getRowValue(row);

@@ -251,8 +251,8 @@ public class ComplexColumnTest extends TestCase
assertEquals(ComplexDataType.MULTI_VALUE,
col.getComplexInfo().getType());

for(Map<String,Object> row : t1) {
String rowId = (String)row.get("id");
for(Row row : t1) {
String rowId = row.getString("id");
ComplexValueForeignKey complexValueFk =
(ComplexValueForeignKey)col.getRowValue(row);

@@ -322,8 +322,8 @@ public class ComplexColumnTest extends TestCase
assertEquals(ComplexDataType.UNSUPPORTED,
col.getComplexInfo().getType());

for(Map<String,Object> row : t1) {
Integer rowId = (Integer)row.get("ID");
for(Row row : t1) {
Integer rowId = row.getInt("ID");
ComplexValueForeignKey complexValueFk =
(ComplexValueForeignKey)col.getRowValue(row);


+ 13
- 13
src/test/java/com/healthmarketscience/jackcess/CursorTest.java View File

@@ -1102,18 +1102,18 @@ public class CursorTest extends TestCase {
IndexCursor cursor = CursorBuilder.createCursor(idx);

List<String> expectedData = new ArrayList<String>();
for(Map<String,Object> row : cursor.newEntryIterable(1)
for(Row row : cursor.newEntryIterable(1)
.addColumnNames("data")) {
expectedData.add((String)row.get("data"));
expectedData.add(row.getString("data"));
}

assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);

expectedData = new ArrayList<String>();
for(Iterator<? extends Map<String,Object>> iter =
for(Iterator<? extends Row> iter =
cursor.newEntryIterable(1).iterator();
iter.hasNext(); ) {
expectedData.add((String)iter.next().get("data"));
expectedData.add(iter.next().getString("data"));
iter.remove();
try {
iter.remove();
@@ -1135,9 +1135,9 @@ public class CursorTest extends TestCase {
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
expectedData = new ArrayList<String>();
for(Map<String,Object> row : cursor.newEntryIterable(1)
for(Row row : cursor.newEntryIterable(1)
.addColumnNames("data")) {
expectedData.add((String)row.get("data"));
expectedData.add(row.getString("data"));
}

assertTrue(expectedData.isEmpty());
@@ -1155,21 +1155,21 @@ public class CursorTest extends TestCase {
Cursor cursor = CursorBuilder.createCursor(t1);

List<String> expectedData = new ArrayList<String>();
for(Map<String,Object> row : cursor.newIterable().setColumnNames(
for(Row row : cursor.newIterable().setColumnNames(
Arrays.asList("otherfk1", "data"))) {
if(row.get("otherfk1").equals(1)) {
expectedData.add((String)row.get("data"));
expectedData.add(row.getString("data"));
}
}

assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);

expectedData = new ArrayList<String>();
for(Iterator<? extends Map<String,Object>> iter = cursor.iterator();
for(Iterator<? extends Row> iter = cursor.iterator();
iter.hasNext(); ) {
Map<String,Object> row = iter.next();
Row row = iter.next();
if(row.get("otherfk1").equals(1)) {
expectedData.add((String)row.get("data"));
expectedData.add(row.getString("data"));
iter.remove();
try {
iter.remove();
@@ -1192,10 +1192,10 @@ public class CursorTest extends TestCase {
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
expectedData = new ArrayList<String>();
for(Map<String,Object> row : cursor.newIterable().setColumnNames(
for(Row row : cursor.newIterable().setColumnNames(
Arrays.asList("otherfk1", "data"))) {
if(row.get("otherfk1").equals(1)) {
expectedData.add((String)row.get("data"));
expectedData.add(row.getString("data"));
}
}


+ 15
- 15
src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java View File

@@ -278,11 +278,11 @@ public class DatabaseTest extends TestCase
assertEquals(4, db.getTableNames().size());
final Table table = db.getTable("Table1");

Map<String, Object> row1 = table.getNextRow();
Map<String, Object> row2 = table.getNextRow();
Row row1 = table.getNextRow();
Row row2 = table.getNextRow();

if(!"abcdefg".equals(row1.get("A"))) {
Map<String, Object> tmpRow = row1;
Row tmpRow = row1;
row1 = row2;
row2 = tmpRow;
}
@@ -294,7 +294,7 @@ public class DatabaseTest extends TestCase
}
}

static void checkTestDBTable1RowABCDEFG(final TestDB testDB, final Table table, final Map<String, Object> row)
static void checkTestDBTable1RowABCDEFG(final TestDB testDB, final Table table, final Row row)
throws IOException {
assertEquals("testDB: " + testDB + "; table: " + table, "abcdefg", row.get("A"));
assertEquals("hijklmnop", row.get("B"));
@@ -303,7 +303,7 @@ public class DatabaseTest extends TestCase
assertEquals(new Integer(333333333), row.get("E"));
assertEquals(new Double(444.555d), row.get("F"));
final Calendar cal = Calendar.getInstance();
cal.setTime((Date) row.get("G"));
cal.setTime(row.getDate("G"));
assertEquals(Calendar.SEPTEMBER, cal.get(Calendar.MONTH));
assertEquals(21, cal.get(Calendar.DAY_OF_MONTH));
assertEquals(1974, cal.get(Calendar.YEAR));
@@ -314,7 +314,7 @@ public class DatabaseTest extends TestCase
assertEquals(Boolean.TRUE, row.get("I"));
}

static void checkTestDBTable1RowA(final TestDB testDB, final Table table, final Map<String, Object> row)
static void checkTestDBTable1RowA(final TestDB testDB, final Table table, final Row row)
throws IOException {
assertEquals("testDB: " + testDB + "; table: " + table, "a", row.get("A"));
assertEquals("b", row.get("B"));
@@ -323,7 +323,7 @@ public class DatabaseTest extends TestCase
assertEquals(new Integer(0), row.get("E"));
assertEquals(new Double(0d), row.get("F"));
final Calendar cal = Calendar.getInstance();
cal.setTime((Date) row.get("G"));
cal.setTime(row.getDate("G"));
assertEquals(Calendar.DECEMBER, cal.get(Calendar.MONTH));
assertEquals(12, cal.get(Calendar.DAY_OF_MONTH));
assertEquals(1981, cal.get(Calendar.YEAR));
@@ -513,12 +513,12 @@ public class DatabaseTest extends TestCase
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.TEST2, true)) {
Database db = open(testDB);
Table table = db.getTable("MSP_PROJECTS");
Map<String, Object> row = table.getNextRow();
Row row = table.getNextRow();
assertEquals("Jon Iles this is a a vawesrasoih aksdkl fas dlkjflkasjd flkjaslkdjflkajlksj dfl lkasjdf lkjaskldfj lkas dlk lkjsjdfkl; aslkdf lkasjkldjf lka skldf lka sdkjfl;kasjd falksjdfljaslkdjf laskjdfk jalskjd flkj aslkdjflkjkjasljdflkjas jf;lkasjd fjkas dasdf asd fasdf asdf asdmhf lksaiyudfoi jasodfj902384jsdf9 aw90se fisajldkfj lkasj dlkfslkd jflksjadf as", row.get("PROJ_PROP_AUTHOR"));
assertEquals("T", row.get("PROJ_PROP_COMPANY"));
assertEquals("Standard", row.get("PROJ_INFO_CAL_NAME"));
assertEquals("Project1", row.get("PROJ_PROP_TITLE"));
byte[] foundBinaryData = (byte[])row.get("RESERVED_BINARY_DATA");
byte[] foundBinaryData = row.getBytes("RESERVED_BINARY_DATA");
byte[] expectedBinaryData =
toByteArray(new File("src/test/data/test2BinData.dat"));
assertTrue(Arrays.equals(expectedBinaryData, foundBinaryData));
@@ -549,7 +549,7 @@ public class DatabaseTest extends TestCase

table.reset();

Map<String, Object> row = table.getNextRow();
Row row = table.getNextRow();

assertEquals(testStr, row.get("A"));
assertEquals(testStr, row.get("B"));
@@ -559,7 +559,7 @@ public class DatabaseTest extends TestCase

assertEquals(testStr, row.get("A"));
assertEquals(longMemo, row.get("B"));
assertTrue(Arrays.equals(oleValue, (byte[])row.get("C")));
assertTrue(Arrays.equals(oleValue, row.getBytes("C")));

db.close();
}
@@ -937,8 +937,8 @@ public class DatabaseTest extends TestCase
}

Set<Integer> ids = new HashSet<Integer>();
for(Map<String,Object> row : t) {
ids.add((Integer)row.get("ID"));
for(Row row : t) {
ids.add(row.getInt("ID"));
}
assertEquals(1000, ids.size());

@@ -1103,8 +1103,8 @@ public class DatabaseTest extends TestCase
}

List<Date> foundDates = new ArrayList<Date>();
for(Map<String,Object> row : table) {
foundDates.add((Date)row.get("date"));
for(Row row : table) {
foundDates.add(row.getDate("date"));
}

assertEquals(dates.size(), foundDates.size());

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

@@ -387,7 +387,7 @@ public class IndexTest extends TestCase {
Cursor c = CursorBuilder.createCursor(table);
assertTrue(c.moveToNextRow());

final Map<String,Object> row = c.getCurrentRow();
final Row row = c.getCurrentRow();
// Row order is arbitrary, so v2007 row order difference is valid
if (testDB.getExpectedFileFormat().ordinal() >=
Database.FileFormat.V2007.ordinal()) {

+ 3
- 3
src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java View File

@@ -191,9 +191,9 @@ public class PropertiesTest extends TestCase
assertTrue(((String)dbProps.getValue(PropertyMap.ACCESS_VERSION_PROP))
.matches("[0-9]{2}[.][0-9]{2}"));

for(Map<String,Object> row : ((DatabaseImpl)db).getSystemCatalog()) {
int id = (Integer)row.get("Id");
byte[] propBytes = (byte[])row.get("LvProp");
for(Row row : ((DatabaseImpl)db).getSystemCatalog()) {
int id = row.getInt("Id");
byte[] propBytes = row.getBytes("LvProp");
PropertyMaps propMaps = ((DatabaseImpl)db).getPropertiesForObject(id);
int byteLen = ((propBytes != null) ? propBytes.length : 0);
if(byteLen == 0) {

+ 6
- 5
src/test/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java View File

@@ -45,6 +45,7 @@ import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.DatabaseTest;
import com.healthmarketscience.jackcess.DatabaseTest;
import com.healthmarketscience.jackcess.IndexBuilder;
import com.healthmarketscience.jackcess.Row;
import com.healthmarketscience.jackcess.Table;
import com.healthmarketscience.jackcess.TableBuilder;
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
@@ -134,8 +135,8 @@ public class CodecHandlerTest extends TestCase
Cursor c2 = t2.newCursor().setIndex(t2.getPrimaryKeyIndex())
.toCursor();

Iterator<? extends Map<String,Object>> i1 = c1.iterator();
Iterator<? extends Map<String,Object>> i2 = c2.newIterable().reverse().iterator();
Iterator<? extends Row> i1 = c1.iterator();
Iterator<? extends Row> i2 = c2.newIterable().reverse().iterator();

int t1rows = 0;
int t2rows = 0;
@@ -156,10 +157,10 @@ public class CodecHandlerTest extends TestCase
assertEquals(100, t2rows);
}

private static void checkRow(Map<String,Object> row)
private static void checkRow(Row row)
{
int id = (Integer)row.get("id");
String value = (String)row.get("data");
int id = row.getInt("id");
String value = row.getString("data");
String valuePrefix = "rowdata-" + id;
assertTrue(value.startsWith(valuePrefix));
assertEquals(valuePrefix.length() + 100, value.length());

+ 2
- 2
src/test/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java View File

@@ -107,8 +107,8 @@ public class FKEnforcerTest extends TestCase

Cursor c = CursorBuilder.createCursor(t3);
Column col = t3.getColumn("id");
for(Map<String,Object> row : c) {
int id = (Integer)row.get("id");
for(Row row : c) {
int id = row.getInt("id");
id += 20;
c.setCurrentRowValue(col, id);
}

+ 11
- 10
src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java View File

@@ -44,6 +44,7 @@ import com.healthmarketscience.jackcess.DataType;
import com.healthmarketscience.jackcess.Database;
import static com.healthmarketscience.jackcess.DatabaseTest.*;
import com.healthmarketscience.jackcess.Index;
import com.healthmarketscience.jackcess.Row;
import com.healthmarketscience.jackcess.Table;
import com.healthmarketscience.jackcess.TableBuilder;
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
@@ -95,7 +96,7 @@ public class IndexCodesTest extends TestCase {
Cursor cursor = CursorBuilder.createCursor(index);
while(cursor.moveToNextRow()) {

Map<String,Object> row = cursor.getCurrentRow();
Row row = cursor.getCurrentRow();
Cursor.Position curPos = cursor.getSavepoint().getCurrentPosition();
boolean success = false;
try {
@@ -113,7 +114,7 @@ public class IndexCodesTest extends TestCase {
}
private static void findRow(final TestDB testDB, Table t, Index index,
Map<String,Object> expectedRow,
Row expectedRow,
Cursor.Position expectedPos)
throws Exception
{
@@ -124,7 +125,7 @@ public class IndexCodesTest extends TestCase {
cursor.beforeFirst();
while(cursor.moveToNextRow()) {
Map<String,Object> row = cursor.getCurrentRow();
Row row = cursor.getCurrentRow();
if(expectedRow.equals(row)) {
// verify that the entries are indeed equal
Cursor.Position curPos = cursor.getSavepoint().getCurrentPosition();
@@ -136,7 +137,7 @@ public class IndexCodesTest extends TestCase {
// TODO long rows not handled completely yet in V2010
// seems to truncate entry at 508 bytes with some trailing 2 byte seq
if(testDB.getExpectedFileFormat() == Database.FileFormat.V2010) {
String rowId = (String)expectedRow.get("name");
String rowId = expectedRow.getString("name");
String tName = t.getName();
if(("Table11".equals(tName) || "Table11_desc".equals(tName)) &&
("row10".equals(rowId) || "row11".equals(rowId) ||
@@ -363,9 +364,9 @@ public class IndexCodesTest extends TestCase {
Cursor.Savepoint savepoint = cursor.getSavepoint();
String entryStr = entryToString(savepoint.getCurrentPosition());

Map<String,Object> row = cursor.getCurrentRow();
String value = (String)row.get("data");
String key = (String)row.get("key");
Row row = cursor.getCurrentRow();
String value = row.getString("data");
String key = row.getString("key");
char c = value.charAt(2);

System.out.println("=======");
@@ -542,9 +543,9 @@ public class IndexCodesTest extends TestCase {
Cursor.Savepoint savepoint = cursor.getSavepoint();
String entryStr = entryToString(savepoint.getCurrentPosition());

Map<String,Object> row = cursor.getCurrentRow();
String value = (String)row.get("data");
String key = (String)row.get("key");
Row row = cursor.getCurrentRow();
String value = row.getString("data");
String key = row.getString("key");
char c = value.charAt(2);
System.out.println("=======");
System.out.println("RowId: " +

+ 1
- 1
src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java View File

@@ -93,7 +93,7 @@ public class JoinerTest extends TestCase {

Joiner revJoin = join.createReverse();
for(Row row : join.getFromTable()) {
Integer id = (Integer)row.get("id");
Integer id = row.getInt("id");

List<Row> joinedRows =
new ArrayList<Row>();

+ 5
- 6
src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java View File

@@ -102,12 +102,12 @@ public class OleBlobTest extends TestCase
for(Row row : t) {
try {
blob = OleBlob.Builder.fromInternalData(
(byte[])row.get("ole"));
row.getBytes("ole"));
OleBlob.Content content = blob.getContent();
assertSame(blob, content.getBlob());
assertSame(content, blob.getContent());

switch((Integer)row.get("id")) {
switch(row.getInt("id")) {
case 1:
assertEquals(OleBlob.ContentType.SIMPLE_PACKAGE, content.getType());
OleBlob.SimplePackageContent spc = (OleBlob.SimplePackageContent)content;
@@ -170,13 +170,12 @@ public class OleBlobTest extends TestCase
OleBlob oleBlob = null;
try {

String name = (String)row.get("name");
oleBlob = OleBlob.Builder.fromInternalData((byte[])row.get("ole_data"));
String name = row.getString("name");
oleBlob = OleBlob.Builder.fromInternalData(row.getBytes("ole_data"));
OleBlob.Content content = oleBlob.getContent();
Attachment attach = null;
if(content.getType() != OleBlob.ContentType.LINK) {
attach = ((ComplexValueForeignKey)row.get("attach_data"))
.getAttachments().get(0);
attach = row.getForeignKey("attach_data").getAttachments().get(0);
}

switch(content.getType()) {

Loading…
Cancel
Save