diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2013-03-15 15:37:28 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2013-03-15 15:37:28 +0000 |
commit | eacdc14c616146dac99507d98f339f13bff4775d (patch) | |
tree | 6810cf8ef33f3853f729d4f9d158348d6203e55a /src/java/com | |
parent | 812bc21edd99f56d79b4a20c3a1cd006450ca100 (diff) | |
download | jackcess-eacdc14c616146dac99507d98f339f13bff4775d.tar.gz jackcess-eacdc14c616146dac99507d98f339f13bff4775d.zip |
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
Diffstat (limited to 'src/java/com')
5 files changed, 47 insertions, 12 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<Row> 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); @@ -201,6 +201,16 @@ public interface Cursor extends Iterable<Row> 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<Row> columnMatchIterable( + Collection<String> columnNames, + Column columnPattern, Object valuePattern); + + /** * Calls <code>beforeFirst</code> on this table and returns a modifiable * Iterator which will iterate through all the rows of this table which * match the given column pattern, returning only the given columns. Use of 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<String,Object> { - + /** + * @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. + * </p> + * Note that the {@link #equals} and {@link #hashCode} methods work on the row + * contents <i>only</i> (i.e. they ignore the id). * * @author James Ahlborn */ @@ -32,17 +35,31 @@ public class RowImpl extends LinkedHashMap<String,Object> 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<String> 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); |