From eacdc14c616146dac99507d98f339f13bff4775d Mon Sep 17 00:00:00 2001
From: James Ahlborn
Date: Fri, 15 Mar 2013 15:37:28 +0000
Subject: [PATCH] add RowId to Row
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jackcess-2@686 f203690c-595d-4dc9-a70b-905162fa7fd2
---
.../healthmarketscience/jackcess/Cursor.java | 14 +++++++++++--
.../com/healthmarketscience/jackcess/Row.java | 5 ++++-
.../jackcess/impl/RowImpl.java | 21 +++++++++++++++++--
.../jackcess/impl/TableImpl.java | 2 +-
.../jackcess/query/Query.java | 17 +++++++++------
.../jackcess/DatabaseTest.java | 3 ++-
.../jackcess/query/QueryTest.java | 2 +-
7 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/src/java/com/healthmarketscience/jackcess/Cursor.java b/src/java/com/healthmarketscience/jackcess/Cursor.java
index 765685d..6d5787c 100644
--- a/src/java/com/healthmarketscience/jackcess/Cursor.java
+++ b/src/java/com/healthmarketscience/jackcess/Cursor.java
@@ -70,8 +70,8 @@ public interface Cursor extends Iterable
public ColumnMatcher getColumnMatcher();
/**
- * Sets a new ColumnMatcher. If {@code null}, resets to using the
- * default matcher, {@link SimpleColumnMatcher#INSTANCE}.
+ * Sets a new ColumnMatcher. If {@code null}, resets to using the default
+ * matcher (default depends on Cursor type).
*/
public void setColumnMatcher(ColumnMatcher columnMatcher);
@@ -200,6 +200,16 @@ public interface Cursor extends Iterable
public Iterator columnMatchIterator(
Column columnPattern, Object valuePattern);
+ /**
+ * Returns an Iterable whose iterator() method returns the result of a call
+ * to {@link #columnMatchIterator(Collection,Column,Object)}
+ * @throws IllegalStateException if an IOException is thrown by one of the
+ * operations, the actual exception will be contained within
+ */
+ public Iterable columnMatchIterable(
+ Collection columnNames,
+ Column columnPattern, Object valuePattern);
+
/**
* Calls beforeFirst
on this table and returns a modifiable
* Iterator which will iterate through all the rows of this table which
diff --git a/src/java/com/healthmarketscience/jackcess/Row.java b/src/java/com/healthmarketscience/jackcess/Row.java
index 1c5f985..00fa09f 100644
--- a/src/java/com/healthmarketscience/jackcess/Row.java
+++ b/src/java/com/healthmarketscience/jackcess/Row.java
@@ -28,5 +28,8 @@ import java.util.Map;
*/
public interface Row extends Map
{
-
+ /**
+ * @return the id of this row
+ */
+ public RowId getId();
}
diff --git a/src/java/com/healthmarketscience/jackcess/impl/RowImpl.java b/src/java/com/healthmarketscience/jackcess/impl/RowImpl.java
index 9ab06a9..f24327f 100644
--- a/src/java/com/healthmarketscience/jackcess/impl/RowImpl.java
+++ b/src/java/com/healthmarketscience/jackcess/impl/RowImpl.java
@@ -25,6 +25,9 @@ import com.healthmarketscience.jackcess.Row;
/**
* A row of data as column->value pairs.
+ *
+ * Note that the {@link #equals} and {@link #hashCode} methods work on the row
+ * contents only (i.e. they ignore the id).
*
* @author James Ahlborn
*/
@@ -32,17 +35,31 @@ public class RowImpl extends LinkedHashMap implements Row
{
private static final long serialVersionUID = 20130314L;
- public RowImpl()
+ private final RowIdImpl _id;
+
+ public RowImpl(RowIdImpl id)
{
+ _id = id;
}
- public RowImpl(int expectedSize)
+ public RowImpl(RowIdImpl id, int expectedSize)
{
super(expectedSize);
+ _id = id;
}
public RowImpl(Row row)
{
super(row);
+ _id = (RowIdImpl)row.getId();
+ }
+
+ public RowIdImpl getId() {
+ return _id;
+ }
+
+ @Override
+ public String toString() {
+ return "Row id=[" + _id + "], content=" + super.toString();
}
}
diff --git a/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java b/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java
index 382c755..7f99138 100644
--- a/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java
+++ b/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java
@@ -584,7 +584,7 @@ public class TableImpl implements Table
Collection columnNames)
throws IOException
{
- RowImpl rtn = new RowImpl(columns.size());
+ RowImpl rtn = new RowImpl(rowState.getHeaderRowId(), columns.size());
for(ColumnImpl column : columns) {
if((columnNames == null) || (columnNames.contains(column.getName()))) {
diff --git a/src/java/com/healthmarketscience/jackcess/query/Query.java b/src/java/com/healthmarketscience/jackcess/query/Query.java
index 4fb562c..642cf6e 100644
--- a/src/java/com/healthmarketscience/jackcess/query/Query.java
+++ b/src/java/com/healthmarketscience/jackcess/query/Query.java
@@ -35,12 +35,13 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import com.healthmarketscience.jackcess.RowId;
+import com.healthmarketscience.jackcess.impl.RowIdImpl;
+import com.healthmarketscience.jackcess.impl.RowImpl;
+import static com.healthmarketscience.jackcess.query.QueryFormat.*;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import com.healthmarketscience.jackcess.impl.RowImpl;
-
-import static com.healthmarketscience.jackcess.query.QueryFormat.*;
/**
@@ -583,6 +584,7 @@ public abstract class Query
*/
public static final class Row
{
+ private final RowId _id;
public final Byte attribute;
public final String expression;
public final Short flag;
@@ -593,6 +595,7 @@ public abstract class Query
public final byte[] order;
private Row() {
+ this._id = null;
this.attribute = null;
this.expression = null;
this.flag = null;
@@ -604,7 +607,8 @@ public abstract class Query
}
public Row(com.healthmarketscience.jackcess.Row tableRow) {
- this((Byte)tableRow.get(COL_ATTRIBUTE),
+ this(tableRow.getId(),
+ (Byte)tableRow.get(COL_ATTRIBUTE),
(String)tableRow.get(COL_EXPRESSION),
(Short)tableRow.get(COL_FLAG),
(Integer)tableRow.get(COL_EXTRA),
@@ -614,10 +618,11 @@ public abstract class Query
(byte[])tableRow.get(COL_ORDER));
}
- public Row(Byte attribute, String expression, Short flag,
+ public Row(RowId id, Byte attribute, String expression, Short flag,
Integer extra, String name1, String name2,
Integer objectId, byte[] order)
{
+ this._id = id;
this.attribute = attribute;
this.expression = expression;
this.flag = flag;
@@ -630,7 +635,7 @@ public abstract class Query
public com.healthmarketscience.jackcess.Row toTableRow()
{
- com.healthmarketscience.jackcess.Row tableRow = new RowImpl();
+ com.healthmarketscience.jackcess.Row tableRow = new RowImpl((RowIdImpl)_id);
tableRow.put(COL_ATTRIBUTE, attribute);
tableRow.put(COL_EXPRESSION, expression);
diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
index a3f2678..dc87617 100644
--- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
@@ -66,6 +66,7 @@ import com.healthmarketscience.jackcess.impl.IndexImpl;
import com.healthmarketscience.jackcess.impl.JetFormat;
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
import com.healthmarketscience.jackcess.impl.RowImpl;
+import com.healthmarketscience.jackcess.impl.RowIdImpl;
import com.healthmarketscience.jackcess.impl.TableImpl;
import com.healthmarketscience.jackcess.util.LinkResolver;
import com.healthmarketscience.jackcess.util.MemFileChannel;
@@ -1448,7 +1449,7 @@ public class DatabaseTest extends TestCase {
}
public static RowImpl createExpectedRow(Object... rowElements) {
- RowImpl row = new RowImpl();
+ RowImpl row = new RowImpl((RowIdImpl)null);
for(int i = 0; i < rowElements.length; i += 2) {
row.put((String)rowElements[i],
rowElements[i + 1]);
diff --git a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
index 13ae95f..a28ffcf 100644
--- a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
@@ -487,7 +487,7 @@ public class QueryTest extends TestCase
{
Short flag = ((flagNum != null) ? flagNum.shortValue() : null);
Integer extra = ((extraNum != null) ? extraNum.intValue() : null);
- return new Row(attr, expr, flag, extra, name1, name2, null, null);
+ return new Row(null, attr, expr, flag, extra, name1, name2, null, null);
}
private static void setFlag(Query query, Number newFlagNum)
--
2.39.5