aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/healthmarketscience
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2009-11-17 01:33:30 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2009-11-17 01:33:30 +0000
commitefca0b593bc32e274b0923b87ecba989ca0406b4 (patch)
treebfed8b267c8e0a434a569eb902dd2e6c8b0f5b82 /src/java/com/healthmarketscience
parenta49de754bce849d94719a473567e78b595fbdc9a (diff)
downloadjackcess-efca0b593bc32e274b0923b87ecba989ca0406b4.tar.gz
jackcess-efca0b593bc32e274b0923b87ecba989ca0406b4.zip
add some more tests/utility code for row updates
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@410 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Cursor.java19
-rw-r--r--src/java/com/healthmarketscience/jackcess/Table.java18
2 files changed, 35 insertions, 2 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Cursor.java b/src/java/com/healthmarketscience/jackcess/Cursor.java
index 8e7f61f..f05c689 100644
--- a/src/java/com/healthmarketscience/jackcess/Cursor.java
+++ b/src/java/com/healthmarketscience/jackcess/Cursor.java
@@ -28,6 +28,7 @@ King of Prussia, PA 19406
package com.healthmarketscience.jackcess;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -885,6 +886,20 @@ public abstract class Cursor implements Iterable<Map<String, Object>>
}
/**
+ * Updates a single value in the current row.
+ * @throws IllegalStateException if the current row is not valid (at
+ * beginning or end of table), or deleted.
+ */
+ public void setCurrentRowValue(Column column, Object value)
+ throws IOException
+ {
+ Object[] row = new Object[_table.getColumnCount()];
+ Arrays.fill(row, Column.KEEP_VALUE);
+ row[column.getColumnIndex()] = value;
+ _table.updateRow(_rowState, _curPos.getRowId(), row);
+ }
+
+ /**
* Returns {@code true} if this cursor is up-to-date with respect to the
* relevant table and related table objects, {@code false} otherwise.
*/
@@ -902,8 +917,8 @@ public abstract class Cursor implements Iterable<Map<String, Object>>
* Finds the next non-deleted row after the given row (as defined by this
* cursor) and returns the id of the row, where "next" may be backwards if
* moveForward is {@code false}. If there are no more rows, the returned
- * rowId should equal the value returned by {@link #getLastPosition} if moving
- * forward and {@link #getFirstPosition} if moving backward.
+ * rowId should equal the value returned by {@link #getLastPosition} if
+ * moving forward and {@link #getFirstPosition} if moving backward.
*/
protected abstract Position findAnotherPosition(RowState rowState,
Position curPos,
diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java
index efc9a1a..a358406 100644
--- a/src/java/com/healthmarketscience/jackcess/Table.java
+++ b/src/java/com/healthmarketscience/jackcess/Table.java
@@ -1152,6 +1152,24 @@ public class Table
}
/**
+ * Converts a map of columnName -> columnValue to an array of row values
+ * appropriate for a call to {@link #updateCurrentRow(Object...)}.
+ */
+ public Object[] asUpdateRow(Map<String,Object> rowMap) {
+ Object[] row = new Object[_columns.size()];
+ Arrays.fill(row, Column.KEEP_VALUE);
+ if(rowMap == null) {
+ return row;
+ }
+ for(Column col : _columns) {
+ if(rowMap.containsKey(col.getName())) {
+ row[col.getColumnIndex()] = rowMap.get(col.getName());
+ }
+ }
+ return row;
+ }
+
+ /**
* Add a single row to this table and write it to disk
* <p>
* Note, if this table has an auto-number column, the value written will be